* cp-tree.h (lang_decl_flags): Remove comdat. Updated dummy.
[official-gcc.git] / gcc / function.c
blobe6fb7866378c7d1e3d7eedc50c441ef983f26059
1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 88, 89, 91-98, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles the generation of rtl code from tree structure
23 at the level of the function as a whole.
24 It creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 `expand_function_start' is called at the beginning of a function,
28 before the function body is parsed, and `expand_function_end' is
29 called after parsing the body.
31 Call `assign_stack_local' to allocate a stack slot for a local variable.
32 This is usually done during the RTL generation for the function body,
33 but it can also be done in the reload pass when a pseudo-register does
34 not get a hard register.
36 Call `put_var_into_stack' when you learn, belatedly, that a variable
37 previously given a pseudo-register must in fact go in the stack.
38 This function changes the DECL_RTL to be a stack slot instead of a reg
39 then scans all the RTL instructions so far generated to correct them. */
41 #include "config.h"
42 #include "system.h"
43 #include "rtl.h"
44 #include "tree.h"
45 #include "flags.h"
46 #include "except.h"
47 #include "function.h"
48 #include "insn-flags.h"
49 #include "expr.h"
50 #include "insn-codes.h"
51 #include "regs.h"
52 #include "hard-reg-set.h"
53 #include "insn-config.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "basic-block.h"
57 #include "obstack.h"
58 #include "toplev.h"
59 #include "hash.h"
61 #ifndef TRAMPOLINE_ALIGNMENT
62 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
63 #endif
65 #ifndef LOCAL_ALIGNMENT
66 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
67 #endif
69 /* Some systems use __main in a way incompatible with its use in gcc, in these
70 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
71 give the same symbol without quotes for an alternative entry point. You
72 must define both, or neither. */
73 #ifndef NAME__MAIN
74 #define NAME__MAIN "__main"
75 #define SYMBOL__MAIN __main
76 #endif
78 /* Round a value to the lowest integer less than it that is a multiple of
79 the required alignment. Avoid using division in case the value is
80 negative. Assume the alignment is a power of two. */
81 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
83 /* Similar, but round to the next highest integer that meets the
84 alignment. */
85 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
87 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
88 during rtl generation. If they are different register numbers, this is
89 always true. It may also be true if
90 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
91 generation. See fix_lexical_addr for details. */
93 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
94 #define NEED_SEPARATE_AP
95 #endif
97 /* Number of bytes of args popped by function being compiled on its return.
98 Zero if no bytes are to be popped.
99 May affect compilation of return insn or of function epilogue. */
101 int current_function_pops_args;
103 /* Nonzero if function being compiled needs to be given an address
104 where the value should be stored. */
106 int current_function_returns_struct;
108 /* Nonzero if function being compiled needs to
109 return the address of where it has put a structure value. */
111 int current_function_returns_pcc_struct;
113 /* Nonzero if function being compiled needs to be passed a static chain. */
115 int current_function_needs_context;
117 /* Nonzero if function being compiled can call setjmp. */
119 int current_function_calls_setjmp;
121 /* Nonzero if function being compiled can call longjmp. */
123 int current_function_calls_longjmp;
125 /* Nonzero if function being compiled receives nonlocal gotos
126 from nested functions. */
128 int current_function_has_nonlocal_label;
130 /* Nonzero if function being compiled has nonlocal gotos to parent
131 function. */
133 int current_function_has_nonlocal_goto;
135 /* Nonzero if function being compiled contains nested functions. */
137 int current_function_contains_functions;
139 /* Nonzero if function being compiled doesn't contain any calls
140 (ignoring the prologue and epilogue). This is set prior to
141 local register allocation and is valid for the remaining
142 compiler passes. */
144 int current_function_is_leaf;
146 /* Nonzero if function being compiled doesn't modify the stack pointer
147 (ignoring the prologue and epilogue). This is only valid after
148 life_analysis has run. */
150 int current_function_sp_is_unchanging;
152 /* Nonzero if the function being compiled is a leaf function which only
153 uses leaf registers. This is valid after reload (specifically after
154 sched2) and is useful only if the port defines LEAF_REGISTERS. */
156 int current_function_uses_only_leaf_regs;
158 /* Nonzero if the function being compiled issues a computed jump. */
160 int current_function_has_computed_jump;
162 /* Nonzero if the current function is a thunk (a lightweight function that
163 just adjusts one of its arguments and forwards to another function), so
164 we should try to cut corners where we can. */
165 int current_function_is_thunk;
167 /* Nonzero if function being compiled can call alloca,
168 either as a subroutine or builtin. */
170 int current_function_calls_alloca;
172 /* Nonzero if the current function returns a pointer type */
174 int current_function_returns_pointer;
176 /* If some insns can be deferred to the delay slots of the epilogue, the
177 delay list for them is recorded here. */
179 rtx current_function_epilogue_delay_list;
181 /* If function's args have a fixed size, this is that size, in bytes.
182 Otherwise, it is -1.
183 May affect compilation of return insn or of function epilogue. */
185 int current_function_args_size;
187 /* # bytes the prologue should push and pretend that the caller pushed them.
188 The prologue must do this, but only if parms can be passed in registers. */
190 int current_function_pretend_args_size;
192 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
193 defined, the needed space is pushed by the prologue. */
195 int current_function_outgoing_args_size;
197 /* This is the offset from the arg pointer to the place where the first
198 anonymous arg can be found, if there is one. */
200 rtx current_function_arg_offset_rtx;
202 /* Nonzero if current function uses varargs.h or equivalent.
203 Zero for functions that use stdarg.h. */
205 int current_function_varargs;
207 /* Nonzero if current function uses stdarg.h or equivalent.
208 Zero for functions that use varargs.h. */
210 int current_function_stdarg;
212 /* Quantities of various kinds of registers
213 used for the current function's args. */
215 CUMULATIVE_ARGS current_function_args_info;
217 /* Name of function now being compiled. */
219 char *current_function_name;
221 /* If non-zero, an RTL expression for the location at which the current
222 function returns its result. If the current function returns its
223 result in a register, current_function_return_rtx will always be
224 the hard register containing the result. */
226 rtx current_function_return_rtx;
228 /* Nonzero if the current function uses the constant pool. */
230 int current_function_uses_const_pool;
232 /* Nonzero if the current function uses pic_offset_table_rtx. */
233 int current_function_uses_pic_offset_table;
235 /* The arg pointer hard register, or the pseudo into which it was copied. */
236 rtx current_function_internal_arg_pointer;
238 /* Language-specific reason why the current function cannot be made inline. */
239 char *current_function_cannot_inline;
241 /* Nonzero if instrumentation calls for function entry and exit should be
242 generated. */
243 int current_function_instrument_entry_exit;
245 /* Nonzero if memory access checking be enabled in the current function. */
246 int current_function_check_memory_usage;
248 /* The FUNCTION_DECL for an inline function currently being expanded. */
249 tree inline_function_decl;
251 /* Number of function calls seen so far in current function. */
253 int function_call_count;
255 /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
256 (labels to which there can be nonlocal gotos from nested functions)
257 in this function. */
259 tree nonlocal_labels;
261 /* List (chain of EXPR_LIST) of stack slots that hold the current handlers
262 for nonlocal gotos. There is one for every nonlocal label in the function;
263 this list matches the one in nonlocal_labels.
264 Zero when function does not have nonlocal labels. */
266 rtx nonlocal_goto_handler_slots;
268 /* List (chain of EXPR_LIST) of labels heading the current handlers for
269 nonlocal gotos. */
271 rtx nonlocal_goto_handler_labels;
273 /* RTX for stack slot that holds the stack pointer value to restore
274 for a nonlocal goto.
275 Zero when function does not have nonlocal labels. */
277 rtx nonlocal_goto_stack_level;
279 /* Label that will go on parm cleanup code, if any.
280 Jumping to this label runs cleanup code for parameters, if
281 such code must be run. Following this code is the logical return label. */
283 rtx cleanup_label;
285 /* Label that will go on function epilogue.
286 Jumping to this label serves as a "return" instruction
287 on machines which require execution of the epilogue on all returns. */
289 rtx return_label;
291 /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
292 So we can mark them all live at the end of the function, if nonopt. */
293 rtx save_expr_regs;
295 /* List (chain of EXPR_LISTs) of all stack slots in this function.
296 Made for the sake of unshare_all_rtl. */
297 rtx stack_slot_list;
299 /* Chain of all RTL_EXPRs that have insns in them. */
300 tree rtl_expr_chain;
302 /* Label to jump back to for tail recursion, or 0 if we have
303 not yet needed one for this function. */
304 rtx tail_recursion_label;
306 /* Place after which to insert the tail_recursion_label if we need one. */
307 rtx tail_recursion_reentry;
309 /* Location at which to save the argument pointer if it will need to be
310 referenced. There are two cases where this is done: if nonlocal gotos
311 exist, or if vars stored at an offset from the argument pointer will be
312 needed by inner routines. */
314 rtx arg_pointer_save_area;
316 /* Offset to end of allocated area of stack frame.
317 If stack grows down, this is the address of the last stack slot allocated.
318 If stack grows up, this is the address for the next slot. */
319 HOST_WIDE_INT frame_offset;
321 /* List (chain of TREE_LISTs) of static chains for containing functions.
322 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
323 in an RTL_EXPR in the TREE_VALUE. */
324 static tree context_display;
326 /* List (chain of TREE_LISTs) of trampolines for nested functions.
327 The trampoline sets up the static chain and jumps to the function.
328 We supply the trampoline's address when the function's address is requested.
330 Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
331 in an RTL_EXPR in the TREE_VALUE. */
332 static tree trampoline_list;
334 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
335 static rtx parm_birth_insn;
337 #if 0
338 /* Nonzero if a stack slot has been generated whose address is not
339 actually valid. It means that the generated rtl must all be scanned
340 to detect and correct the invalid addresses where they occur. */
341 static int invalid_stack_slot;
342 #endif
344 /* Last insn of those whose job was to put parms into their nominal homes. */
345 static rtx last_parm_insn;
347 /* 1 + last pseudo register number possibly used for loading a copy
348 of a parameter of this function. */
349 int max_parm_reg;
351 /* Vector indexed by REGNO, containing location on stack in which
352 to put the parm which is nominally in pseudo register REGNO,
353 if we discover that that parm must go in the stack. The highest
354 element in this vector is one less than MAX_PARM_REG, above. */
355 rtx *parm_reg_stack_loc;
357 /* Nonzero once virtual register instantiation has been done.
358 assign_stack_local uses frame_pointer_rtx when this is nonzero. */
359 static int virtuals_instantiated;
361 /* These variables hold pointers to functions to
362 save and restore machine-specific data,
363 in push_function_context and pop_function_context. */
364 void (*save_machine_status) PROTO((struct function *));
365 void (*restore_machine_status) PROTO((struct function *));
367 /* Nonzero if we need to distinguish between the return value of this function
368 and the return value of a function called by this function. This helps
369 integrate.c */
371 extern int rtx_equal_function_value_matters;
372 extern tree sequence_rtl_expr;
374 /* In order to evaluate some expressions, such as function calls returning
375 structures in memory, we need to temporarily allocate stack locations.
376 We record each allocated temporary in the following structure.
378 Associated with each temporary slot is a nesting level. When we pop up
379 one level, all temporaries associated with the previous level are freed.
380 Normally, all temporaries are freed after the execution of the statement
381 in which they were created. However, if we are inside a ({...}) grouping,
382 the result may be in a temporary and hence must be preserved. If the
383 result could be in a temporary, we preserve it if we can determine which
384 one it is in. If we cannot determine which temporary may contain the
385 result, all temporaries are preserved. A temporary is preserved by
386 pretending it was allocated at the previous nesting level.
388 Automatic variables are also assigned temporary slots, at the nesting
389 level where they are defined. They are marked a "kept" so that
390 free_temp_slots will not free them. */
392 struct temp_slot
394 /* Points to next temporary slot. */
395 struct temp_slot *next;
396 /* The rtx to used to reference the slot. */
397 rtx slot;
398 /* The rtx used to represent the address if not the address of the
399 slot above. May be an EXPR_LIST if multiple addresses exist. */
400 rtx address;
401 /* The alignment (in bits) of the slot. */
402 int align;
403 /* The size, in units, of the slot. */
404 HOST_WIDE_INT size;
405 /* The alias set for the slot. If the alias set is zero, we don't
406 know anything about the alias set of the slot. We must only
407 reuse a slot if it is assigned an object of the same alias set.
408 Otherwise, the rest of the compiler may assume that the new use
409 of the slot cannot alias the old use of the slot, which is
410 false. If the slot has alias set zero, then we can't reuse the
411 slot at all, since we have no idea what alias set may have been
412 imposed on the memory. For example, if the stack slot is the
413 call frame for an inline functioned, we have no idea what alias
414 sets will be assigned to various pieces of the call frame. */
415 int alias_set;
416 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
417 tree rtl_expr;
418 /* Non-zero if this temporary is currently in use. */
419 char in_use;
420 /* Non-zero if this temporary has its address taken. */
421 char addr_taken;
422 /* Nesting level at which this slot is being used. */
423 int level;
424 /* Non-zero if this should survive a call to free_temp_slots. */
425 int keep;
426 /* The offset of the slot from the frame_pointer, including extra space
427 for alignment. This info is for combine_temp_slots. */
428 HOST_WIDE_INT base_offset;
429 /* The size of the slot, including extra space for alignment. This
430 info is for combine_temp_slots. */
431 HOST_WIDE_INT full_size;
434 /* List of all temporaries allocated, both available and in use. */
436 struct temp_slot *temp_slots;
438 /* Current nesting level for temporaries. */
440 int temp_slot_level;
442 /* Current nesting level for variables in a block. */
444 int var_temp_slot_level;
446 /* When temporaries are created by TARGET_EXPRs, they are created at
447 this level of temp_slot_level, so that they can remain allocated
448 until no longer needed. CLEANUP_POINT_EXPRs define the lifetime
449 of TARGET_EXPRs. */
450 int target_temp_slot_level;
452 /* This structure is used to record MEMs or pseudos used to replace VAR, any
453 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
454 maintain this list in case two operands of an insn were required to match;
455 in that case we must ensure we use the same replacement. */
457 struct fixup_replacement
459 rtx old;
460 rtx new;
461 struct fixup_replacement *next;
464 struct insns_for_mem_entry {
465 /* The KEY in HE will be a MEM. */
466 struct hash_entry he;
467 /* These are the INSNS which reference the MEM. */
468 rtx insns;
471 /* Forward declarations. */
473 static rtx assign_outer_stack_local PROTO ((enum machine_mode, HOST_WIDE_INT,
474 int, struct function *));
475 static rtx assign_stack_temp_for_type PROTO ((enum machine_mode, HOST_WIDE_INT,
476 int, tree));
477 static struct temp_slot *find_temp_slot_from_address PROTO((rtx));
478 static void put_reg_into_stack PROTO((struct function *, rtx, tree,
479 enum machine_mode, enum machine_mode,
480 int, int, int,
481 struct hash_table *));
482 static void fixup_var_refs PROTO((rtx, enum machine_mode, int,
483 struct hash_table *));
484 static struct fixup_replacement
485 *find_fixup_replacement PROTO((struct fixup_replacement **, rtx));
486 static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int,
487 rtx, int, struct hash_table *));
488 static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx,
489 struct fixup_replacement **));
490 static rtx fixup_memory_subreg PROTO((rtx, rtx, int));
491 static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int));
492 static rtx fixup_stack_1 PROTO((rtx, rtx));
493 static void optimize_bit_field PROTO((rtx, rtx, rtx *));
494 static void instantiate_decls PROTO((tree, int));
495 static void instantiate_decls_1 PROTO((tree, int));
496 static void instantiate_decl PROTO((rtx, int, int));
497 static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int));
498 static void delete_handlers PROTO((void));
499 static void pad_to_arg_alignment PROTO((struct args_size *, int));
500 #ifndef ARGS_GROW_DOWNWARD
501 static void pad_below PROTO((struct args_size *, enum machine_mode,
502 tree));
503 #endif
504 #ifdef ARGS_GROW_DOWNWARD
505 static tree round_down PROTO((tree, int));
506 #endif
507 static rtx round_trampoline_addr PROTO((rtx));
508 static tree blocks_nreverse PROTO((tree));
509 static int all_blocks PROTO((tree, tree *));
510 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
511 static int *record_insns PROTO((rtx));
512 static int contains PROTO((rtx, int *));
513 #endif /* HAVE_prologue || HAVE_epilogue */
514 static void put_addressof_into_stack PROTO((rtx, struct hash_table *));
515 static void purge_addressof_1 PROTO((rtx *, rtx, int, int,
516 struct hash_table *));
517 static struct hash_entry *insns_for_mem_newfunc PROTO((struct hash_entry *,
518 struct hash_table *,
519 hash_table_key));
520 static unsigned long insns_for_mem_hash PROTO ((hash_table_key));
521 static boolean insns_for_mem_comp PROTO ((hash_table_key, hash_table_key));
522 static int insns_for_mem_walk PROTO ((rtx *, void *));
523 static void compute_insns_for_mem PROTO ((rtx, rtx, struct hash_table *));
526 /* Pointer to chain of `struct function' for containing functions. */
527 struct function *outer_function_chain;
529 /* Given a function decl for a containing function,
530 return the `struct function' for it. */
532 struct function *
533 find_function_data (decl)
534 tree decl;
536 struct function *p;
538 for (p = outer_function_chain; p; p = p->next)
539 if (p->decl == decl)
540 return p;
542 abort ();
545 /* Save the current context for compilation of a nested function.
546 This is called from language-specific code.
547 The caller is responsible for saving any language-specific status,
548 since this function knows only about language-independent variables. */
550 void
551 push_function_context_to (context)
552 tree context;
554 struct function *p = (struct function *) xmalloc (sizeof (struct function));
556 p->next = outer_function_chain;
557 outer_function_chain = p;
559 p->name = current_function_name;
560 p->decl = current_function_decl;
561 p->pops_args = current_function_pops_args;
562 p->returns_struct = current_function_returns_struct;
563 p->returns_pcc_struct = current_function_returns_pcc_struct;
564 p->returns_pointer = current_function_returns_pointer;
565 p->needs_context = current_function_needs_context;
566 p->calls_setjmp = current_function_calls_setjmp;
567 p->calls_longjmp = current_function_calls_longjmp;
568 p->calls_alloca = current_function_calls_alloca;
569 p->has_nonlocal_label = current_function_has_nonlocal_label;
570 p->has_nonlocal_goto = current_function_has_nonlocal_goto;
571 p->contains_functions = current_function_contains_functions;
572 p->has_computed_jump = current_function_has_computed_jump;
573 p->is_thunk = current_function_is_thunk;
574 p->args_size = current_function_args_size;
575 p->pretend_args_size = current_function_pretend_args_size;
576 p->arg_offset_rtx = current_function_arg_offset_rtx;
577 p->varargs = current_function_varargs;
578 p->stdarg = current_function_stdarg;
579 p->uses_const_pool = current_function_uses_const_pool;
580 p->uses_pic_offset_table = current_function_uses_pic_offset_table;
581 p->internal_arg_pointer = current_function_internal_arg_pointer;
582 p->cannot_inline = current_function_cannot_inline;
583 p->max_parm_reg = max_parm_reg;
584 p->parm_reg_stack_loc = parm_reg_stack_loc;
585 p->outgoing_args_size = current_function_outgoing_args_size;
586 p->return_rtx = current_function_return_rtx;
587 p->nonlocal_goto_handler_slots = nonlocal_goto_handler_slots;
588 p->nonlocal_goto_handler_labels = nonlocal_goto_handler_labels;
589 p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
590 p->nonlocal_labels = nonlocal_labels;
591 p->cleanup_label = cleanup_label;
592 p->return_label = return_label;
593 p->save_expr_regs = save_expr_regs;
594 p->stack_slot_list = stack_slot_list;
595 p->parm_birth_insn = parm_birth_insn;
596 p->frame_offset = frame_offset;
597 p->tail_recursion_label = tail_recursion_label;
598 p->tail_recursion_reentry = tail_recursion_reentry;
599 p->arg_pointer_save_area = arg_pointer_save_area;
600 p->rtl_expr_chain = rtl_expr_chain;
601 p->last_parm_insn = last_parm_insn;
602 p->context_display = context_display;
603 p->trampoline_list = trampoline_list;
604 p->function_call_count = function_call_count;
605 p->temp_slots = temp_slots;
606 p->temp_slot_level = temp_slot_level;
607 p->target_temp_slot_level = target_temp_slot_level;
608 p->var_temp_slot_level = var_temp_slot_level;
609 p->fixup_var_refs_queue = 0;
610 p->epilogue_delay_list = current_function_epilogue_delay_list;
611 p->args_info = current_function_args_info;
612 p->check_memory_usage = current_function_check_memory_usage;
613 p->instrument_entry_exit = current_function_instrument_entry_exit;
615 save_tree_status (p, context);
616 save_storage_status (p);
617 save_emit_status (p);
618 save_expr_status (p);
619 save_stmt_status (p);
620 save_varasm_status (p, context);
621 if (save_machine_status)
622 (*save_machine_status) (p);
625 void
626 push_function_context ()
628 push_function_context_to (current_function_decl);
631 /* Restore the last saved context, at the end of a nested function.
632 This function is called from language-specific code. */
634 void
635 pop_function_context_from (context)
636 tree context;
638 struct function *p = outer_function_chain;
639 struct var_refs_queue *queue;
641 outer_function_chain = p->next;
643 current_function_contains_functions
644 = p->contains_functions || p->inline_obstacks
645 || context == current_function_decl;
646 current_function_has_computed_jump = p->has_computed_jump;
647 current_function_name = p->name;
648 current_function_decl = p->decl;
649 current_function_pops_args = p->pops_args;
650 current_function_returns_struct = p->returns_struct;
651 current_function_returns_pcc_struct = p->returns_pcc_struct;
652 current_function_returns_pointer = p->returns_pointer;
653 current_function_needs_context = p->needs_context;
654 current_function_calls_setjmp = p->calls_setjmp;
655 current_function_calls_longjmp = p->calls_longjmp;
656 current_function_calls_alloca = p->calls_alloca;
657 current_function_has_nonlocal_label = p->has_nonlocal_label;
658 current_function_has_nonlocal_goto = p->has_nonlocal_goto;
659 current_function_is_thunk = p->is_thunk;
660 current_function_args_size = p->args_size;
661 current_function_pretend_args_size = p->pretend_args_size;
662 current_function_arg_offset_rtx = p->arg_offset_rtx;
663 current_function_varargs = p->varargs;
664 current_function_stdarg = p->stdarg;
665 current_function_uses_const_pool = p->uses_const_pool;
666 current_function_uses_pic_offset_table = p->uses_pic_offset_table;
667 current_function_internal_arg_pointer = p->internal_arg_pointer;
668 current_function_cannot_inline = p->cannot_inline;
669 max_parm_reg = p->max_parm_reg;
670 parm_reg_stack_loc = p->parm_reg_stack_loc;
671 current_function_outgoing_args_size = p->outgoing_args_size;
672 current_function_return_rtx = p->return_rtx;
673 nonlocal_goto_handler_slots = p->nonlocal_goto_handler_slots;
674 nonlocal_goto_handler_labels = p->nonlocal_goto_handler_labels;
675 nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
676 nonlocal_labels = p->nonlocal_labels;
677 cleanup_label = p->cleanup_label;
678 return_label = p->return_label;
679 save_expr_regs = p->save_expr_regs;
680 stack_slot_list = p->stack_slot_list;
681 parm_birth_insn = p->parm_birth_insn;
682 frame_offset = p->frame_offset;
683 tail_recursion_label = p->tail_recursion_label;
684 tail_recursion_reentry = p->tail_recursion_reentry;
685 arg_pointer_save_area = p->arg_pointer_save_area;
686 rtl_expr_chain = p->rtl_expr_chain;
687 last_parm_insn = p->last_parm_insn;
688 context_display = p->context_display;
689 trampoline_list = p->trampoline_list;
690 function_call_count = p->function_call_count;
691 temp_slots = p->temp_slots;
692 temp_slot_level = p->temp_slot_level;
693 target_temp_slot_level = p->target_temp_slot_level;
694 var_temp_slot_level = p->var_temp_slot_level;
695 current_function_epilogue_delay_list = p->epilogue_delay_list;
696 reg_renumber = 0;
697 current_function_args_info = p->args_info;
698 current_function_check_memory_usage = p->check_memory_usage;
699 current_function_instrument_entry_exit = p->instrument_entry_exit;
701 restore_tree_status (p, context);
702 restore_storage_status (p);
703 restore_expr_status (p);
704 restore_emit_status (p);
705 restore_stmt_status (p);
706 restore_varasm_status (p);
708 if (restore_machine_status)
709 (*restore_machine_status) (p);
711 /* Finish doing put_var_into_stack for any of our variables
712 which became addressable during the nested function. */
713 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
714 fixup_var_refs (queue->modified, queue->promoted_mode,
715 queue->unsignedp, 0);
717 free (p);
719 /* Reset variables that have known state during rtx generation. */
720 rtx_equal_function_value_matters = 1;
721 virtuals_instantiated = 0;
724 void pop_function_context ()
726 pop_function_context_from (current_function_decl);
729 /* Allocate fixed slots in the stack frame of the current function. */
731 /* Return size needed for stack frame based on slots so far allocated.
732 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
733 the caller may have to do that. */
735 HOST_WIDE_INT
736 get_frame_size ()
738 #ifdef FRAME_GROWS_DOWNWARD
739 return -frame_offset;
740 #else
741 return frame_offset;
742 #endif
745 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
746 with machine mode MODE.
748 ALIGN controls the amount of alignment for the address of the slot:
749 0 means according to MODE,
750 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
751 positive specifies alignment boundary in bits.
753 We do not round to stack_boundary here. */
756 assign_stack_local (mode, size, align)
757 enum machine_mode mode;
758 HOST_WIDE_INT size;
759 int align;
761 register rtx x, addr;
762 int bigend_correction = 0;
763 int alignment;
765 if (align == 0)
767 tree type;
769 alignment = GET_MODE_ALIGNMENT (mode);
770 if (mode == BLKmode)
771 alignment = BIGGEST_ALIGNMENT;
773 /* Allow the target to (possibly) increase the alignment of this
774 stack slot. */
775 type = type_for_mode (mode, 0);
776 if (type)
777 alignment = LOCAL_ALIGNMENT (type, alignment);
779 alignment /= BITS_PER_UNIT;
781 else if (align == -1)
783 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
784 size = CEIL_ROUND (size, alignment);
786 else
787 alignment = align / BITS_PER_UNIT;
789 /* Round frame offset to that alignment.
790 We must be careful here, since FRAME_OFFSET might be negative and
791 division with a negative dividend isn't as well defined as we might
792 like. So we instead assume that ALIGNMENT is a power of two and
793 use logical operations which are unambiguous. */
794 #ifdef FRAME_GROWS_DOWNWARD
795 frame_offset = FLOOR_ROUND (frame_offset, alignment);
796 #else
797 frame_offset = CEIL_ROUND (frame_offset, alignment);
798 #endif
800 /* On a big-endian machine, if we are allocating more space than we will use,
801 use the least significant bytes of those that are allocated. */
802 if (BYTES_BIG_ENDIAN && mode != BLKmode)
803 bigend_correction = size - GET_MODE_SIZE (mode);
805 #ifdef FRAME_GROWS_DOWNWARD
806 frame_offset -= size;
807 #endif
809 /* If we have already instantiated virtual registers, return the actual
810 address relative to the frame pointer. */
811 if (virtuals_instantiated)
812 addr = plus_constant (frame_pointer_rtx,
813 (frame_offset + bigend_correction
814 + STARTING_FRAME_OFFSET));
815 else
816 addr = plus_constant (virtual_stack_vars_rtx,
817 frame_offset + bigend_correction);
819 #ifndef FRAME_GROWS_DOWNWARD
820 frame_offset += size;
821 #endif
823 x = gen_rtx_MEM (mode, addr);
825 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list);
827 return x;
830 /* Assign a stack slot in a containing function.
831 First three arguments are same as in preceding function.
832 The last argument specifies the function to allocate in. */
834 static rtx
835 assign_outer_stack_local (mode, size, align, function)
836 enum machine_mode mode;
837 HOST_WIDE_INT size;
838 int align;
839 struct function *function;
841 register rtx x, addr;
842 int bigend_correction = 0;
843 int alignment;
845 /* Allocate in the memory associated with the function in whose frame
846 we are assigning. */
847 push_obstacks (function->function_obstack,
848 function->function_maybepermanent_obstack);
850 if (align == 0)
852 tree type;
854 alignment = GET_MODE_ALIGNMENT (mode);
855 if (mode == BLKmode)
856 alignment = BIGGEST_ALIGNMENT;
858 /* Allow the target to (possibly) increase the alignment of this
859 stack slot. */
860 type = type_for_mode (mode, 0);
861 if (type)
862 alignment = LOCAL_ALIGNMENT (type, alignment);
864 alignment /= BITS_PER_UNIT;
866 else if (align == -1)
868 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
869 size = CEIL_ROUND (size, alignment);
871 else
872 alignment = align / BITS_PER_UNIT;
874 /* Round frame offset to that alignment. */
875 #ifdef FRAME_GROWS_DOWNWARD
876 function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment);
877 #else
878 function->frame_offset = CEIL_ROUND (function->frame_offset, alignment);
879 #endif
881 /* On a big-endian machine, if we are allocating more space than we will use,
882 use the least significant bytes of those that are allocated. */
883 if (BYTES_BIG_ENDIAN && mode != BLKmode)
884 bigend_correction = size - GET_MODE_SIZE (mode);
886 #ifdef FRAME_GROWS_DOWNWARD
887 function->frame_offset -= size;
888 #endif
889 addr = plus_constant (virtual_stack_vars_rtx,
890 function->frame_offset + bigend_correction);
891 #ifndef FRAME_GROWS_DOWNWARD
892 function->frame_offset += size;
893 #endif
895 x = gen_rtx_MEM (mode, addr);
897 function->stack_slot_list
898 = gen_rtx_EXPR_LIST (VOIDmode, x, function->stack_slot_list);
900 pop_obstacks ();
902 return x;
905 /* Allocate a temporary stack slot and record it for possible later
906 reuse.
908 MODE is the machine mode to be given to the returned rtx.
910 SIZE is the size in units of the space required. We do no rounding here
911 since assign_stack_local will do any required rounding.
913 KEEP is 1 if this slot is to be retained after a call to
914 free_temp_slots. Automatic variables for a block are allocated
915 with this flag. KEEP is 2 if we allocate a longer term temporary,
916 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
917 if we are to allocate something at an inner level to be treated as
918 a variable in the block (e.g., a SAVE_EXPR).
920 TYPE is the type that will be used for the stack slot. */
922 static rtx
923 assign_stack_temp_for_type (mode, size, keep, type)
924 enum machine_mode mode;
925 HOST_WIDE_INT size;
926 int keep;
927 tree type;
929 int align;
930 int alias_set;
931 struct temp_slot *p, *best_p = 0;
933 /* If SIZE is -1 it means that somebody tried to allocate a temporary
934 of a variable size. */
935 if (size == -1)
936 abort ();
938 /* If we know the alias set for the memory that will be used, use
939 it. If there's no TYPE, then we don't know anything about the
940 alias set for the memory. */
941 if (type)
942 alias_set = get_alias_set (type);
943 else
944 alias_set = 0;
946 align = GET_MODE_ALIGNMENT (mode);
947 if (mode == BLKmode)
948 align = BIGGEST_ALIGNMENT;
950 if (! type)
951 type = type_for_mode (mode, 0);
952 if (type)
953 align = LOCAL_ALIGNMENT (type, align);
955 /* Try to find an available, already-allocated temporary of the proper
956 mode which meets the size and alignment requirements. Choose the
957 smallest one with the closest alignment. */
958 for (p = temp_slots; p; p = p->next)
959 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
960 && ! p->in_use
961 && (!flag_strict_aliasing
962 || (alias_set && p->alias_set == alias_set))
963 && (best_p == 0 || best_p->size > p->size
964 || (best_p->size == p->size && best_p->align > p->align)))
966 if (p->align == align && p->size == size)
968 best_p = 0;
969 break;
971 best_p = p;
974 /* Make our best, if any, the one to use. */
975 if (best_p)
977 /* If there are enough aligned bytes left over, make them into a new
978 temp_slot so that the extra bytes don't get wasted. Do this only
979 for BLKmode slots, so that we can be sure of the alignment. */
980 if (GET_MODE (best_p->slot) == BLKmode
981 /* We can't split slots if -fstrict-aliasing because the
982 information about the alias set for the new slot will be
983 lost. */
984 && !flag_strict_aliasing)
986 int alignment = best_p->align / BITS_PER_UNIT;
987 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
989 if (best_p->size - rounded_size >= alignment)
991 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
992 p->in_use = p->addr_taken = 0;
993 p->size = best_p->size - rounded_size;
994 p->base_offset = best_p->base_offset + rounded_size;
995 p->full_size = best_p->full_size - rounded_size;
996 p->slot = gen_rtx_MEM (BLKmode,
997 plus_constant (XEXP (best_p->slot, 0),
998 rounded_size));
999 p->align = best_p->align;
1000 p->address = 0;
1001 p->rtl_expr = 0;
1002 p->next = temp_slots;
1003 temp_slots = p;
1005 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
1006 stack_slot_list);
1008 best_p->size = rounded_size;
1009 best_p->full_size = rounded_size;
1013 p = best_p;
1016 /* If we still didn't find one, make a new temporary. */
1017 if (p == 0)
1019 HOST_WIDE_INT frame_offset_old = frame_offset;
1021 p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
1023 /* We are passing an explicit alignment request to assign_stack_local.
1024 One side effect of that is assign_stack_local will not round SIZE
1025 to ensure the frame offset remains suitably aligned.
1027 So for requests which depended on the rounding of SIZE, we go ahead
1028 and round it now. We also make sure ALIGNMENT is at least
1029 BIGGEST_ALIGNMENT. */
1030 if (mode == BLKmode && align < (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
1031 abort();
1032 p->slot = assign_stack_local (mode,
1033 mode == BLKmode
1034 ? CEIL_ROUND (size, align) : size,
1035 align);
1037 p->align = align;
1038 p->alias_set = alias_set;
1040 /* The following slot size computation is necessary because we don't
1041 know the actual size of the temporary slot until assign_stack_local
1042 has performed all the frame alignment and size rounding for the
1043 requested temporary. Note that extra space added for alignment
1044 can be either above or below this stack slot depending on which
1045 way the frame grows. We include the extra space if and only if it
1046 is above this slot. */
1047 #ifdef FRAME_GROWS_DOWNWARD
1048 p->size = frame_offset_old - frame_offset;
1049 #else
1050 p->size = size;
1051 #endif
1053 /* Now define the fields used by combine_temp_slots. */
1054 #ifdef FRAME_GROWS_DOWNWARD
1055 p->base_offset = frame_offset;
1056 p->full_size = frame_offset_old - frame_offset;
1057 #else
1058 p->base_offset = frame_offset_old;
1059 p->full_size = frame_offset - frame_offset_old;
1060 #endif
1061 p->address = 0;
1062 p->next = temp_slots;
1063 temp_slots = p;
1066 p->in_use = 1;
1067 p->addr_taken = 0;
1068 p->rtl_expr = sequence_rtl_expr;
1070 if (keep == 2)
1072 p->level = target_temp_slot_level;
1073 p->keep = 0;
1075 else if (keep == 3)
1077 p->level = var_temp_slot_level;
1078 p->keep = 0;
1080 else
1082 p->level = temp_slot_level;
1083 p->keep = keep;
1086 /* We may be reusing an old slot, so clear any MEM flags that may have been
1087 set from before. */
1088 RTX_UNCHANGING_P (p->slot) = 0;
1089 MEM_IN_STRUCT_P (p->slot) = 0;
1090 MEM_SCALAR_P (p->slot) = 0;
1091 MEM_ALIAS_SET (p->slot) = 0;
1092 return p->slot;
1095 /* Allocate a temporary stack slot and record it for possible later
1096 reuse. First three arguments are same as in preceding function. */
1099 assign_stack_temp (mode, size, keep)
1100 enum machine_mode mode;
1101 HOST_WIDE_INT size;
1102 int keep;
1104 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
1107 /* Assign a temporary of given TYPE.
1108 KEEP is as for assign_stack_temp.
1109 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
1110 it is 0 if a register is OK.
1111 DONT_PROMOTE is 1 if we should not promote values in register
1112 to wider modes. */
1115 assign_temp (type, keep, memory_required, dont_promote)
1116 tree type;
1117 int keep;
1118 int memory_required;
1119 int dont_promote;
1121 enum machine_mode mode = TYPE_MODE (type);
1122 int unsignedp = TREE_UNSIGNED (type);
1124 if (mode == BLKmode || memory_required)
1126 HOST_WIDE_INT size = int_size_in_bytes (type);
1127 rtx tmp;
1129 /* Unfortunately, we don't yet know how to allocate variable-sized
1130 temporaries. However, sometimes we have a fixed upper limit on
1131 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
1132 instead. This is the case for Chill variable-sized strings. */
1133 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
1134 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
1135 && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST)
1136 size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type));
1138 tmp = assign_stack_temp_for_type (mode, size, keep, type);
1139 MEM_SET_IN_STRUCT_P (tmp, AGGREGATE_TYPE_P (type));
1140 return tmp;
1143 #ifndef PROMOTE_FOR_CALL_ONLY
1144 if (! dont_promote)
1145 mode = promote_mode (type, mode, &unsignedp, 0);
1146 #endif
1148 return gen_reg_rtx (mode);
1151 /* Combine temporary stack slots which are adjacent on the stack.
1153 This allows for better use of already allocated stack space. This is only
1154 done for BLKmode slots because we can be sure that we won't have alignment
1155 problems in this case. */
1157 void
1158 combine_temp_slots ()
1160 struct temp_slot *p, *q;
1161 struct temp_slot *prev_p, *prev_q;
1162 int num_slots;
1164 /* We can't combine slots, because the information about which slot
1165 is in which alias set will be lost. */
1166 if (flag_strict_aliasing)
1167 return;
1169 /* If there are a lot of temp slots, don't do anything unless
1170 high levels of optimizaton. */
1171 if (! flag_expensive_optimizations)
1172 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
1173 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
1174 return;
1176 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
1178 int delete_p = 0;
1180 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
1181 for (q = p->next, prev_q = p; q; q = prev_q->next)
1183 int delete_q = 0;
1184 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
1186 if (p->base_offset + p->full_size == q->base_offset)
1188 /* Q comes after P; combine Q into P. */
1189 p->size += q->size;
1190 p->full_size += q->full_size;
1191 delete_q = 1;
1193 else if (q->base_offset + q->full_size == p->base_offset)
1195 /* P comes after Q; combine P into Q. */
1196 q->size += p->size;
1197 q->full_size += p->full_size;
1198 delete_p = 1;
1199 break;
1202 /* Either delete Q or advance past it. */
1203 if (delete_q)
1204 prev_q->next = q->next;
1205 else
1206 prev_q = q;
1208 /* Either delete P or advance past it. */
1209 if (delete_p)
1211 if (prev_p)
1212 prev_p->next = p->next;
1213 else
1214 temp_slots = p->next;
1216 else
1217 prev_p = p;
1221 /* Find the temp slot corresponding to the object at address X. */
1223 static struct temp_slot *
1224 find_temp_slot_from_address (x)
1225 rtx x;
1227 struct temp_slot *p;
1228 rtx next;
1230 for (p = temp_slots; p; p = p->next)
1232 if (! p->in_use)
1233 continue;
1235 else if (XEXP (p->slot, 0) == x
1236 || p->address == x
1237 || (GET_CODE (x) == PLUS
1238 && XEXP (x, 0) == virtual_stack_vars_rtx
1239 && GET_CODE (XEXP (x, 1)) == CONST_INT
1240 && INTVAL (XEXP (x, 1)) >= p->base_offset
1241 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
1242 return p;
1244 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1245 for (next = p->address; next; next = XEXP (next, 1))
1246 if (XEXP (next, 0) == x)
1247 return p;
1250 return 0;
1253 /* Indicate that NEW is an alternate way of referring to the temp slot
1254 that previously was known by OLD. */
1256 void
1257 update_temp_slot_address (old, new)
1258 rtx old, new;
1260 struct temp_slot *p = find_temp_slot_from_address (old);
1262 /* If none, return. Else add NEW as an alias. */
1263 if (p == 0)
1264 return;
1265 else if (p->address == 0)
1266 p->address = new;
1267 else
1269 if (GET_CODE (p->address) != EXPR_LIST)
1270 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1272 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1276 /* If X could be a reference to a temporary slot, mark the fact that its
1277 address was taken. */
1279 void
1280 mark_temp_addr_taken (x)
1281 rtx x;
1283 struct temp_slot *p;
1285 if (x == 0)
1286 return;
1288 /* If X is not in memory or is at a constant address, it cannot be in
1289 a temporary slot. */
1290 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1291 return;
1293 p = find_temp_slot_from_address (XEXP (x, 0));
1294 if (p != 0)
1295 p->addr_taken = 1;
1298 /* If X could be a reference to a temporary slot, mark that slot as
1299 belonging to the to one level higher than the current level. If X
1300 matched one of our slots, just mark that one. Otherwise, we can't
1301 easily predict which it is, so upgrade all of them. Kept slots
1302 need not be touched.
1304 This is called when an ({...}) construct occurs and a statement
1305 returns a value in memory. */
1307 void
1308 preserve_temp_slots (x)
1309 rtx x;
1311 struct temp_slot *p = 0;
1313 /* If there is no result, we still might have some objects whose address
1314 were taken, so we need to make sure they stay around. */
1315 if (x == 0)
1317 for (p = temp_slots; p; p = p->next)
1318 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1319 p->level--;
1321 return;
1324 /* If X is a register that is being used as a pointer, see if we have
1325 a temporary slot we know it points to. To be consistent with
1326 the code below, we really should preserve all non-kept slots
1327 if we can't find a match, but that seems to be much too costly. */
1328 if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x)))
1329 p = find_temp_slot_from_address (x);
1331 /* If X is not in memory or is at a constant address, it cannot be in
1332 a temporary slot, but it can contain something whose address was
1333 taken. */
1334 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1336 for (p = temp_slots; p; p = p->next)
1337 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1338 p->level--;
1340 return;
1343 /* First see if we can find a match. */
1344 if (p == 0)
1345 p = find_temp_slot_from_address (XEXP (x, 0));
1347 if (p != 0)
1349 /* Move everything at our level whose address was taken to our new
1350 level in case we used its address. */
1351 struct temp_slot *q;
1353 if (p->level == temp_slot_level)
1355 for (q = temp_slots; q; q = q->next)
1356 if (q != p && q->addr_taken && q->level == p->level)
1357 q->level--;
1359 p->level--;
1360 p->addr_taken = 0;
1362 return;
1365 /* Otherwise, preserve all non-kept slots at this level. */
1366 for (p = temp_slots; p; p = p->next)
1367 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1368 p->level--;
1371 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1372 with that RTL_EXPR, promote it into a temporary slot at the present
1373 level so it will not be freed when we free slots made in the
1374 RTL_EXPR. */
1376 void
1377 preserve_rtl_expr_result (x)
1378 rtx x;
1380 struct temp_slot *p;
1382 /* If X is not in memory or is at a constant address, it cannot be in
1383 a temporary slot. */
1384 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1385 return;
1387 /* If we can find a match, move it to our level unless it is already at
1388 an upper level. */
1389 p = find_temp_slot_from_address (XEXP (x, 0));
1390 if (p != 0)
1392 p->level = MIN (p->level, temp_slot_level);
1393 p->rtl_expr = 0;
1396 return;
1399 /* Free all temporaries used so far. This is normally called at the end
1400 of generating code for a statement. Don't free any temporaries
1401 currently in use for an RTL_EXPR that hasn't yet been emitted.
1402 We could eventually do better than this since it can be reused while
1403 generating the same RTL_EXPR, but this is complex and probably not
1404 worthwhile. */
1406 void
1407 free_temp_slots ()
1409 struct temp_slot *p;
1411 for (p = temp_slots; p; p = p->next)
1412 if (p->in_use && p->level == temp_slot_level && ! p->keep
1413 && p->rtl_expr == 0)
1414 p->in_use = 0;
1416 combine_temp_slots ();
1419 /* Free all temporary slots used in T, an RTL_EXPR node. */
1421 void
1422 free_temps_for_rtl_expr (t)
1423 tree t;
1425 struct temp_slot *p;
1427 for (p = temp_slots; p; p = p->next)
1428 if (p->rtl_expr == t)
1429 p->in_use = 0;
1431 combine_temp_slots ();
1434 /* Mark all temporaries ever allocated in this function as not suitable
1435 for reuse until the current level is exited. */
1437 void
1438 mark_all_temps_used ()
1440 struct temp_slot *p;
1442 for (p = temp_slots; p; p = p->next)
1444 p->in_use = p->keep = 1;
1445 p->level = MIN (p->level, temp_slot_level);
1449 /* Push deeper into the nesting level for stack temporaries. */
1451 void
1452 push_temp_slots ()
1454 temp_slot_level++;
1457 /* Likewise, but save the new level as the place to allocate variables
1458 for blocks. */
1460 void
1461 push_temp_slots_for_block ()
1463 push_temp_slots ();
1465 var_temp_slot_level = temp_slot_level;
1468 /* Likewise, but save the new level as the place to allocate temporaries
1469 for TARGET_EXPRs. */
1471 void
1472 push_temp_slots_for_target ()
1474 push_temp_slots ();
1476 target_temp_slot_level = temp_slot_level;
1479 /* Set and get the value of target_temp_slot_level. The only
1480 permitted use of these functions is to save and restore this value. */
1483 get_target_temp_slot_level ()
1485 return target_temp_slot_level;
1488 void
1489 set_target_temp_slot_level (level)
1490 int level;
1492 target_temp_slot_level = level;
1495 /* Pop a temporary nesting level. All slots in use in the current level
1496 are freed. */
1498 void
1499 pop_temp_slots ()
1501 struct temp_slot *p;
1503 for (p = temp_slots; p; p = p->next)
1504 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1505 p->in_use = 0;
1507 combine_temp_slots ();
1509 temp_slot_level--;
1512 /* Initialize temporary slots. */
1514 void
1515 init_temp_slots ()
1517 /* We have not allocated any temporaries yet. */
1518 temp_slots = 0;
1519 temp_slot_level = 0;
1520 var_temp_slot_level = 0;
1521 target_temp_slot_level = 0;
1524 /* Retroactively move an auto variable from a register to a stack slot.
1525 This is done when an address-reference to the variable is seen. */
1527 void
1528 put_var_into_stack (decl)
1529 tree decl;
1531 register rtx reg;
1532 enum machine_mode promoted_mode, decl_mode;
1533 struct function *function = 0;
1534 tree context;
1535 int can_use_addressof;
1537 context = decl_function_context (decl);
1539 /* Get the current rtl used for this object and its original mode. */
1540 reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
1542 /* No need to do anything if decl has no rtx yet
1543 since in that case caller is setting TREE_ADDRESSABLE
1544 and a stack slot will be assigned when the rtl is made. */
1545 if (reg == 0)
1546 return;
1548 /* Get the declared mode for this object. */
1549 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1550 : DECL_MODE (decl));
1551 /* Get the mode it's actually stored in. */
1552 promoted_mode = GET_MODE (reg);
1554 /* If this variable comes from an outer function,
1555 find that function's saved context. */
1556 if (context != current_function_decl && context != inline_function_decl)
1557 for (function = outer_function_chain; function; function = function->next)
1558 if (function->decl == context)
1559 break;
1561 /* If this is a variable-size object with a pseudo to address it,
1562 put that pseudo into the stack, if the var is nonlocal. */
1563 if (DECL_NONLOCAL (decl)
1564 && GET_CODE (reg) == MEM
1565 && GET_CODE (XEXP (reg, 0)) == REG
1566 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1568 reg = XEXP (reg, 0);
1569 decl_mode = promoted_mode = GET_MODE (reg);
1572 can_use_addressof
1573 = (function == 0
1574 && optimize > 0
1575 /* FIXME make it work for promoted modes too */
1576 && decl_mode == promoted_mode
1577 #ifdef NON_SAVING_SETJMP
1578 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1579 #endif
1582 /* If we can't use ADDRESSOF, make sure we see through one we already
1583 generated. */
1584 if (! can_use_addressof && GET_CODE (reg) == MEM
1585 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1586 reg = XEXP (XEXP (reg, 0), 0);
1588 /* Now we should have a value that resides in one or more pseudo regs. */
1590 if (GET_CODE (reg) == REG)
1592 /* If this variable lives in the current function and we don't need
1593 to put things in the stack for the sake of setjmp, try to keep it
1594 in a register until we know we actually need the address. */
1595 if (can_use_addressof)
1596 gen_mem_addressof (reg, decl);
1597 else
1598 put_reg_into_stack (function, reg, TREE_TYPE (decl),
1599 promoted_mode, decl_mode,
1600 TREE_SIDE_EFFECTS (decl), 0,
1601 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1604 else if (GET_CODE (reg) == CONCAT)
1606 /* A CONCAT contains two pseudos; put them both in the stack.
1607 We do it so they end up consecutive. */
1608 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1609 tree part_type = TREE_TYPE (TREE_TYPE (decl));
1610 #ifdef FRAME_GROWS_DOWNWARD
1611 /* Since part 0 should have a lower address, do it second. */
1612 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1613 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1614 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1616 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1617 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1618 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1620 #else
1621 put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode,
1622 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1623 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1625 put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode,
1626 part_mode, TREE_SIDE_EFFECTS (decl), 0,
1627 TREE_USED (decl) || DECL_INITIAL (decl) != 0,
1629 #endif
1631 /* Change the CONCAT into a combined MEM for both parts. */
1632 PUT_CODE (reg, MEM);
1633 MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0));
1634 MEM_ALIAS_SET (reg) = get_alias_set (decl);
1636 /* The two parts are in memory order already.
1637 Use the lower parts address as ours. */
1638 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1639 /* Prevent sharing of rtl that might lose. */
1640 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1641 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1643 else
1644 return;
1646 if (current_function_check_memory_usage)
1647 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
1648 XEXP (reg, 0), Pmode,
1649 GEN_INT (GET_MODE_SIZE (GET_MODE (reg))),
1650 TYPE_MODE (sizetype),
1651 GEN_INT (MEMORY_USE_RW),
1652 TYPE_MODE (integer_type_node));
1655 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1656 into the stack frame of FUNCTION (0 means the current function).
1657 DECL_MODE is the machine mode of the user-level data type.
1658 PROMOTED_MODE is the machine mode of the register.
1659 VOLATILE_P is nonzero if this is for a "volatile" decl.
1660 USED_P is nonzero if this reg might have already been used in an insn. */
1662 static void
1663 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1664 original_regno, used_p, ht)
1665 struct function *function;
1666 rtx reg;
1667 tree type;
1668 enum machine_mode promoted_mode, decl_mode;
1669 int volatile_p;
1670 int original_regno;
1671 int used_p;
1672 struct hash_table *ht;
1674 rtx new = 0;
1675 int regno = original_regno;
1677 if (regno == 0)
1678 regno = REGNO (reg);
1680 if (function)
1682 if (regno < function->max_parm_reg)
1683 new = function->parm_reg_stack_loc[regno];
1684 if (new == 0)
1685 new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode),
1686 0, function);
1688 else
1690 if (regno < max_parm_reg)
1691 new = parm_reg_stack_loc[regno];
1692 if (new == 0)
1693 new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0);
1696 PUT_MODE (reg, decl_mode);
1697 XEXP (reg, 0) = XEXP (new, 0);
1698 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1699 MEM_VOLATILE_P (reg) = volatile_p;
1700 PUT_CODE (reg, MEM);
1702 /* If this is a memory ref that contains aggregate components,
1703 mark it as such for cse and loop optimize. If we are reusing a
1704 previously generated stack slot, then we need to copy the bit in
1705 case it was set for other reasons. For instance, it is set for
1706 __builtin_va_alist. */
1707 MEM_SET_IN_STRUCT_P (reg,
1708 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1709 MEM_ALIAS_SET (reg) = get_alias_set (type);
1711 /* Now make sure that all refs to the variable, previously made
1712 when it was a register, are fixed up to be valid again. */
1714 if (used_p && function != 0)
1716 struct var_refs_queue *temp;
1718 /* Variable is inherited; fix it up when we get back to its function. */
1719 push_obstacks (function->function_obstack,
1720 function->function_maybepermanent_obstack);
1722 /* See comment in restore_tree_status in tree.c for why this needs to be
1723 on saveable obstack. */
1724 temp
1725 = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue));
1726 temp->modified = reg;
1727 temp->promoted_mode = promoted_mode;
1728 temp->unsignedp = TREE_UNSIGNED (type);
1729 temp->next = function->fixup_var_refs_queue;
1730 function->fixup_var_refs_queue = temp;
1731 pop_obstacks ();
1733 else if (used_p)
1734 /* Variable is local; fix it up now. */
1735 fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type), ht);
1738 static void
1739 fixup_var_refs (var, promoted_mode, unsignedp, ht)
1740 rtx var;
1741 enum machine_mode promoted_mode;
1742 int unsignedp;
1743 struct hash_table *ht;
1745 tree pending;
1746 rtx first_insn = get_insns ();
1747 struct sequence_stack *stack = sequence_stack;
1748 tree rtl_exps = rtl_expr_chain;
1750 /* Must scan all insns for stack-refs that exceed the limit. */
1751 fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn,
1752 stack == 0, ht);
1753 /* If there's a hash table, it must record all uses of VAR. */
1754 if (ht)
1755 return;
1757 /* Scan all pending sequences too. */
1758 for (; stack; stack = stack->next)
1760 push_to_sequence (stack->first);
1761 fixup_var_refs_insns (var, promoted_mode, unsignedp,
1762 stack->first, stack->next != 0, 0);
1763 /* Update remembered end of sequence
1764 in case we added an insn at the end. */
1765 stack->last = get_last_insn ();
1766 end_sequence ();
1769 /* Scan all waiting RTL_EXPRs too. */
1770 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1772 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1773 if (seq != const0_rtx && seq != 0)
1775 push_to_sequence (seq);
1776 fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0,
1778 end_sequence ();
1782 /* Scan the catch clauses for exception handling too. */
1783 push_to_sequence (catch_clauses);
1784 fixup_var_refs_insns (var, promoted_mode, unsignedp, catch_clauses,
1785 0, 0);
1786 end_sequence ();
1789 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1790 some part of an insn. Return a struct fixup_replacement whose OLD
1791 value is equal to X. Allocate a new structure if no such entry exists. */
1793 static struct fixup_replacement *
1794 find_fixup_replacement (replacements, x)
1795 struct fixup_replacement **replacements;
1796 rtx x;
1798 struct fixup_replacement *p;
1800 /* See if we have already replaced this. */
1801 for (p = *replacements; p && p->old != x; p = p->next)
1804 if (p == 0)
1806 p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
1807 p->old = x;
1808 p->new = 0;
1809 p->next = *replacements;
1810 *replacements = p;
1813 return p;
1816 /* Scan the insn-chain starting with INSN for refs to VAR
1817 and fix them up. TOPLEVEL is nonzero if this chain is the
1818 main chain of insns for the current function. */
1820 static void
1821 fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel, ht)
1822 rtx var;
1823 enum machine_mode promoted_mode;
1824 int unsignedp;
1825 rtx insn;
1826 int toplevel;
1827 struct hash_table *ht;
1829 rtx call_dest = 0;
1830 rtx insn_list = NULL_RTX;
1832 /* If we already know which INSNs reference VAR there's no need
1833 to walk the entire instruction chain. */
1834 if (ht)
1836 insn_list = ((struct insns_for_mem_entry *)
1837 hash_lookup (ht, var, /*create=*/0, /*copy=*/0))->insns;
1838 insn = insn_list ? XEXP (insn_list, 0) : NULL_RTX;
1839 insn_list = XEXP (insn_list, 1);
1842 while (insn)
1844 rtx next = NEXT_INSN (insn);
1845 rtx set, prev, prev_set;
1846 rtx note;
1848 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
1850 /* If this is a CLOBBER of VAR, delete it.
1852 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1853 and REG_RETVAL notes too. */
1854 if (GET_CODE (PATTERN (insn)) == CLOBBER
1855 && (XEXP (PATTERN (insn), 0) == var
1856 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1857 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1858 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1860 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1861 /* The REG_LIBCALL note will go away since we are going to
1862 turn INSN into a NOTE, so just delete the
1863 corresponding REG_RETVAL note. */
1864 remove_note (XEXP (note, 0),
1865 find_reg_note (XEXP (note, 0), REG_RETVAL,
1866 NULL_RTX));
1868 /* In unoptimized compilation, we shouldn't call delete_insn
1869 except in jump.c doing warnings. */
1870 PUT_CODE (insn, NOTE);
1871 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1872 NOTE_SOURCE_FILE (insn) = 0;
1875 /* The insn to load VAR from a home in the arglist
1876 is now a no-op. When we see it, just delete it.
1877 Similarly if this is storing VAR from a register from which
1878 it was loaded in the previous insn. This will occur
1879 when an ADDRESSOF was made for an arglist slot. */
1880 else if (toplevel
1881 && (set = single_set (insn)) != 0
1882 && SET_DEST (set) == var
1883 /* If this represents the result of an insn group,
1884 don't delete the insn. */
1885 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1886 && (rtx_equal_p (SET_SRC (set), var)
1887 || (GET_CODE (SET_SRC (set)) == REG
1888 && (prev = prev_nonnote_insn (insn)) != 0
1889 && (prev_set = single_set (prev)) != 0
1890 && SET_DEST (prev_set) == SET_SRC (set)
1891 && rtx_equal_p (SET_SRC (prev_set), var))))
1893 /* In unoptimized compilation, we shouldn't call delete_insn
1894 except in jump.c doing warnings. */
1895 PUT_CODE (insn, NOTE);
1896 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
1897 NOTE_SOURCE_FILE (insn) = 0;
1898 if (insn == last_parm_insn)
1899 last_parm_insn = PREV_INSN (next);
1901 else
1903 struct fixup_replacement *replacements = 0;
1904 rtx next_insn = NEXT_INSN (insn);
1906 if (SMALL_REGISTER_CLASSES)
1908 /* If the insn that copies the results of a CALL_INSN
1909 into a pseudo now references VAR, we have to use an
1910 intermediate pseudo since we want the life of the
1911 return value register to be only a single insn.
1913 If we don't use an intermediate pseudo, such things as
1914 address computations to make the address of VAR valid
1915 if it is not can be placed between the CALL_INSN and INSN.
1917 To make sure this doesn't happen, we record the destination
1918 of the CALL_INSN and see if the next insn uses both that
1919 and VAR. */
1921 if (call_dest != 0 && GET_CODE (insn) == INSN
1922 && reg_mentioned_p (var, PATTERN (insn))
1923 && reg_mentioned_p (call_dest, PATTERN (insn)))
1925 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1927 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1929 PATTERN (insn) = replace_rtx (PATTERN (insn),
1930 call_dest, temp);
1933 if (GET_CODE (insn) == CALL_INSN
1934 && GET_CODE (PATTERN (insn)) == SET)
1935 call_dest = SET_DEST (PATTERN (insn));
1936 else if (GET_CODE (insn) == CALL_INSN
1937 && GET_CODE (PATTERN (insn)) == PARALLEL
1938 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1939 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1940 else
1941 call_dest = 0;
1944 /* See if we have to do anything to INSN now that VAR is in
1945 memory. If it needs to be loaded into a pseudo, use a single
1946 pseudo for the entire insn in case there is a MATCH_DUP
1947 between two operands. We pass a pointer to the head of
1948 a list of struct fixup_replacements. If fixup_var_refs_1
1949 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1950 it will record them in this list.
1952 If it allocated a pseudo for any replacement, we copy into
1953 it here. */
1955 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1956 &replacements);
1958 /* If this is last_parm_insn, and any instructions were output
1959 after it to fix it up, then we must set last_parm_insn to
1960 the last such instruction emitted. */
1961 if (insn == last_parm_insn)
1962 last_parm_insn = PREV_INSN (next_insn);
1964 while (replacements)
1966 if (GET_CODE (replacements->new) == REG)
1968 rtx insert_before;
1969 rtx seq;
1971 /* OLD might be a (subreg (mem)). */
1972 if (GET_CODE (replacements->old) == SUBREG)
1973 replacements->old
1974 = fixup_memory_subreg (replacements->old, insn, 0);
1975 else
1976 replacements->old
1977 = fixup_stack_1 (replacements->old, insn);
1979 insert_before = insn;
1981 /* If we are changing the mode, do a conversion.
1982 This might be wasteful, but combine.c will
1983 eliminate much of the waste. */
1985 if (GET_MODE (replacements->new)
1986 != GET_MODE (replacements->old))
1988 start_sequence ();
1989 convert_move (replacements->new,
1990 replacements->old, unsignedp);
1991 seq = gen_sequence ();
1992 end_sequence ();
1994 else
1995 seq = gen_move_insn (replacements->new,
1996 replacements->old);
1998 emit_insn_before (seq, insert_before);
2001 replacements = replacements->next;
2005 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
2006 But don't touch other insns referred to by reg-notes;
2007 we will get them elsewhere. */
2008 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2009 if (GET_CODE (note) != INSN_LIST)
2010 XEXP (note, 0)
2011 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1);
2014 if (!ht)
2015 insn = next;
2016 else if (insn_list)
2018 insn = XEXP (insn_list, 0);
2019 insn_list = XEXP (insn_list, 1);
2021 else
2022 insn = NULL_RTX;
2026 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
2027 See if the rtx expression at *LOC in INSN needs to be changed.
2029 REPLACEMENTS is a pointer to a list head that starts out zero, but may
2030 contain a list of original rtx's and replacements. If we find that we need
2031 to modify this insn by replacing a memory reference with a pseudo or by
2032 making a new MEM to implement a SUBREG, we consult that list to see if
2033 we have already chosen a replacement. If none has already been allocated,
2034 we allocate it and update the list. fixup_var_refs_insns will copy VAR
2035 or the SUBREG, as appropriate, to the pseudo. */
2037 static void
2038 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements)
2039 register rtx var;
2040 enum machine_mode promoted_mode;
2041 register rtx *loc;
2042 rtx insn;
2043 struct fixup_replacement **replacements;
2045 register int i;
2046 register rtx x = *loc;
2047 RTX_CODE code = GET_CODE (x);
2048 register char *fmt;
2049 register rtx tem, tem1;
2050 struct fixup_replacement *replacement;
2052 switch (code)
2054 case ADDRESSOF:
2055 if (XEXP (x, 0) == var)
2057 /* Prevent sharing of rtl that might lose. */
2058 rtx sub = copy_rtx (XEXP (var, 0));
2060 if (! validate_change (insn, loc, sub, 0))
2062 rtx y = gen_reg_rtx (GET_MODE (sub));
2063 rtx seq, new_insn;
2065 /* We should be able to replace with a register or all is lost.
2066 Note that we can't use validate_change to verify this, since
2067 we're not caring for replacing all dups simultaneously. */
2068 if (! validate_replace_rtx (*loc, y, insn))
2069 abort ();
2071 /* Careful! First try to recognize a direct move of the
2072 value, mimicking how things are done in gen_reload wrt
2073 PLUS. Consider what happens when insn is a conditional
2074 move instruction and addsi3 clobbers flags. */
2076 start_sequence ();
2077 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
2078 seq = gen_sequence ();
2079 end_sequence ();
2081 if (recog_memoized (new_insn) < 0)
2083 /* That failed. Fall back on force_operand and hope. */
2085 start_sequence ();
2086 force_operand (sub, y);
2087 seq = gen_sequence ();
2088 end_sequence ();
2091 #ifdef HAVE_cc0
2092 /* Don't separate setter from user. */
2093 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
2094 insn = PREV_INSN (insn);
2095 #endif
2097 emit_insn_before (seq, insn);
2100 return;
2102 case MEM:
2103 if (var == x)
2105 /* If we already have a replacement, use it. Otherwise,
2106 try to fix up this address in case it is invalid. */
2108 replacement = find_fixup_replacement (replacements, var);
2109 if (replacement->new)
2111 *loc = replacement->new;
2112 return;
2115 *loc = replacement->new = x = fixup_stack_1 (x, insn);
2117 /* Unless we are forcing memory to register or we changed the mode,
2118 we can leave things the way they are if the insn is valid. */
2120 INSN_CODE (insn) = -1;
2121 if (! flag_force_mem && GET_MODE (x) == promoted_mode
2122 && recog_memoized (insn) >= 0)
2123 return;
2125 *loc = replacement->new = gen_reg_rtx (promoted_mode);
2126 return;
2129 /* If X contains VAR, we need to unshare it here so that we update
2130 each occurrence separately. But all identical MEMs in one insn
2131 must be replaced with the same rtx because of the possibility of
2132 MATCH_DUPs. */
2134 if (reg_mentioned_p (var, x))
2136 replacement = find_fixup_replacement (replacements, x);
2137 if (replacement->new == 0)
2138 replacement->new = copy_most_rtx (x, var);
2140 *loc = x = replacement->new;
2142 break;
2144 case REG:
2145 case CC0:
2146 case PC:
2147 case CONST_INT:
2148 case CONST:
2149 case SYMBOL_REF:
2150 case LABEL_REF:
2151 case CONST_DOUBLE:
2152 return;
2154 case SIGN_EXTRACT:
2155 case ZERO_EXTRACT:
2156 /* Note that in some cases those types of expressions are altered
2157 by optimize_bit_field, and do not survive to get here. */
2158 if (XEXP (x, 0) == var
2159 || (GET_CODE (XEXP (x, 0)) == SUBREG
2160 && SUBREG_REG (XEXP (x, 0)) == var))
2162 /* Get TEM as a valid MEM in the mode presently in the insn.
2164 We don't worry about the possibility of MATCH_DUP here; it
2165 is highly unlikely and would be tricky to handle. */
2167 tem = XEXP (x, 0);
2168 if (GET_CODE (tem) == SUBREG)
2170 if (GET_MODE_BITSIZE (GET_MODE (tem))
2171 > GET_MODE_BITSIZE (GET_MODE (var)))
2173 replacement = find_fixup_replacement (replacements, var);
2174 if (replacement->new == 0)
2175 replacement->new = gen_reg_rtx (GET_MODE (var));
2176 SUBREG_REG (tem) = replacement->new;
2178 else
2179 tem = fixup_memory_subreg (tem, insn, 0);
2181 else
2182 tem = fixup_stack_1 (tem, insn);
2184 /* Unless we want to load from memory, get TEM into the proper mode
2185 for an extract from memory. This can only be done if the
2186 extract is at a constant position and length. */
2188 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2189 && GET_CODE (XEXP (x, 2)) == CONST_INT
2190 && ! mode_dependent_address_p (XEXP (tem, 0))
2191 && ! MEM_VOLATILE_P (tem))
2193 enum machine_mode wanted_mode = VOIDmode;
2194 enum machine_mode is_mode = GET_MODE (tem);
2195 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2197 #ifdef HAVE_extzv
2198 if (GET_CODE (x) == ZERO_EXTRACT)
2200 wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
2201 if (wanted_mode == VOIDmode)
2202 wanted_mode = word_mode;
2204 #endif
2205 #ifdef HAVE_extv
2206 if (GET_CODE (x) == SIGN_EXTRACT)
2208 wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
2209 if (wanted_mode == VOIDmode)
2210 wanted_mode = word_mode;
2212 #endif
2213 /* If we have a narrower mode, we can do something. */
2214 if (wanted_mode != VOIDmode
2215 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2217 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2218 rtx old_pos = XEXP (x, 2);
2219 rtx newmem;
2221 /* If the bytes and bits are counted differently, we
2222 must adjust the offset. */
2223 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2224 offset = (GET_MODE_SIZE (is_mode)
2225 - GET_MODE_SIZE (wanted_mode) - offset);
2227 pos %= GET_MODE_BITSIZE (wanted_mode);
2229 newmem = gen_rtx_MEM (wanted_mode,
2230 plus_constant (XEXP (tem, 0), offset));
2231 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2232 MEM_COPY_ATTRIBUTES (newmem, tem);
2234 /* Make the change and see if the insn remains valid. */
2235 INSN_CODE (insn) = -1;
2236 XEXP (x, 0) = newmem;
2237 XEXP (x, 2) = GEN_INT (pos);
2239 if (recog_memoized (insn) >= 0)
2240 return;
2242 /* Otherwise, restore old position. XEXP (x, 0) will be
2243 restored later. */
2244 XEXP (x, 2) = old_pos;
2248 /* If we get here, the bitfield extract insn can't accept a memory
2249 reference. Copy the input into a register. */
2251 tem1 = gen_reg_rtx (GET_MODE (tem));
2252 emit_insn_before (gen_move_insn (tem1, tem), insn);
2253 XEXP (x, 0) = tem1;
2254 return;
2256 break;
2258 case SUBREG:
2259 if (SUBREG_REG (x) == var)
2261 /* If this is a special SUBREG made because VAR was promoted
2262 from a wider mode, replace it with VAR and call ourself
2263 recursively, this time saying that the object previously
2264 had its current mode (by virtue of the SUBREG). */
2266 if (SUBREG_PROMOTED_VAR_P (x))
2268 *loc = var;
2269 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements);
2270 return;
2273 /* If this SUBREG makes VAR wider, it has become a paradoxical
2274 SUBREG with VAR in memory, but these aren't allowed at this
2275 stage of the compilation. So load VAR into a pseudo and take
2276 a SUBREG of that pseudo. */
2277 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2279 replacement = find_fixup_replacement (replacements, var);
2280 if (replacement->new == 0)
2281 replacement->new = gen_reg_rtx (GET_MODE (var));
2282 SUBREG_REG (x) = replacement->new;
2283 return;
2286 /* See if we have already found a replacement for this SUBREG.
2287 If so, use it. Otherwise, make a MEM and see if the insn
2288 is recognized. If not, or if we should force MEM into a register,
2289 make a pseudo for this SUBREG. */
2290 replacement = find_fixup_replacement (replacements, x);
2291 if (replacement->new)
2293 *loc = replacement->new;
2294 return;
2297 replacement->new = *loc = fixup_memory_subreg (x, insn, 0);
2299 INSN_CODE (insn) = -1;
2300 if (! flag_force_mem && recog_memoized (insn) >= 0)
2301 return;
2303 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2304 return;
2306 break;
2308 case SET:
2309 /* First do special simplification of bit-field references. */
2310 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2311 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2312 optimize_bit_field (x, insn, 0);
2313 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2314 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2315 optimize_bit_field (x, insn, NULL_PTR);
2317 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2318 into a register and then store it back out. */
2319 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2320 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2321 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2322 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2323 > GET_MODE_SIZE (GET_MODE (var))))
2325 replacement = find_fixup_replacement (replacements, var);
2326 if (replacement->new == 0)
2327 replacement->new = gen_reg_rtx (GET_MODE (var));
2329 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2330 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2333 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2334 insn into a pseudo and store the low part of the pseudo into VAR. */
2335 if (GET_CODE (SET_DEST (x)) == SUBREG
2336 && SUBREG_REG (SET_DEST (x)) == var
2337 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2338 > GET_MODE_SIZE (GET_MODE (var))))
2340 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2341 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2342 tem)),
2343 insn);
2344 break;
2348 rtx dest = SET_DEST (x);
2349 rtx src = SET_SRC (x);
2350 #ifdef HAVE_insv
2351 rtx outerdest = dest;
2352 #endif
2354 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2355 || GET_CODE (dest) == SIGN_EXTRACT
2356 || GET_CODE (dest) == ZERO_EXTRACT)
2357 dest = XEXP (dest, 0);
2359 if (GET_CODE (src) == SUBREG)
2360 src = XEXP (src, 0);
2362 /* If VAR does not appear at the top level of the SET
2363 just scan the lower levels of the tree. */
2365 if (src != var && dest != var)
2366 break;
2368 /* We will need to rerecognize this insn. */
2369 INSN_CODE (insn) = -1;
2371 #ifdef HAVE_insv
2372 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
2374 /* Since this case will return, ensure we fixup all the
2375 operands here. */
2376 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2377 insn, replacements);
2378 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2379 insn, replacements);
2380 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2381 insn, replacements);
2383 tem = XEXP (outerdest, 0);
2385 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2386 that may appear inside a ZERO_EXTRACT.
2387 This was legitimate when the MEM was a REG. */
2388 if (GET_CODE (tem) == SUBREG
2389 && SUBREG_REG (tem) == var)
2390 tem = fixup_memory_subreg (tem, insn, 0);
2391 else
2392 tem = fixup_stack_1 (tem, insn);
2394 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2395 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2396 && ! mode_dependent_address_p (XEXP (tem, 0))
2397 && ! MEM_VOLATILE_P (tem))
2399 enum machine_mode wanted_mode;
2400 enum machine_mode is_mode = GET_MODE (tem);
2401 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2403 wanted_mode = insn_operand_mode[(int) CODE_FOR_insv][0];
2404 if (wanted_mode == VOIDmode)
2405 wanted_mode = word_mode;
2407 /* If we have a narrower mode, we can do something. */
2408 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2410 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2411 rtx old_pos = XEXP (outerdest, 2);
2412 rtx newmem;
2414 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2415 offset = (GET_MODE_SIZE (is_mode)
2416 - GET_MODE_SIZE (wanted_mode) - offset);
2418 pos %= GET_MODE_BITSIZE (wanted_mode);
2420 newmem = gen_rtx_MEM (wanted_mode,
2421 plus_constant (XEXP (tem, 0), offset));
2422 RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
2423 MEM_COPY_ATTRIBUTES (newmem, tem);
2425 /* Make the change and see if the insn remains valid. */
2426 INSN_CODE (insn) = -1;
2427 XEXP (outerdest, 0) = newmem;
2428 XEXP (outerdest, 2) = GEN_INT (pos);
2430 if (recog_memoized (insn) >= 0)
2431 return;
2433 /* Otherwise, restore old position. XEXP (x, 0) will be
2434 restored later. */
2435 XEXP (outerdest, 2) = old_pos;
2439 /* If we get here, the bit-field store doesn't allow memory
2440 or isn't located at a constant position. Load the value into
2441 a register, do the store, and put it back into memory. */
2443 tem1 = gen_reg_rtx (GET_MODE (tem));
2444 emit_insn_before (gen_move_insn (tem1, tem), insn);
2445 emit_insn_after (gen_move_insn (tem, tem1), insn);
2446 XEXP (outerdest, 0) = tem1;
2447 return;
2449 #endif
2451 /* STRICT_LOW_PART is a no-op on memory references
2452 and it can cause combinations to be unrecognizable,
2453 so eliminate it. */
2455 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2456 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2458 /* A valid insn to copy VAR into or out of a register
2459 must be left alone, to avoid an infinite loop here.
2460 If the reference to VAR is by a subreg, fix that up,
2461 since SUBREG is not valid for a memref.
2462 Also fix up the address of the stack slot.
2464 Note that we must not try to recognize the insn until
2465 after we know that we have valid addresses and no
2466 (subreg (mem ...) ...) constructs, since these interfere
2467 with determining the validity of the insn. */
2469 if ((SET_SRC (x) == var
2470 || (GET_CODE (SET_SRC (x)) == SUBREG
2471 && SUBREG_REG (SET_SRC (x)) == var))
2472 && (GET_CODE (SET_DEST (x)) == REG
2473 || (GET_CODE (SET_DEST (x)) == SUBREG
2474 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2475 && GET_MODE (var) == promoted_mode
2476 && x == single_set (insn))
2478 rtx pat;
2480 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2481 if (replacement->new)
2482 SET_SRC (x) = replacement->new;
2483 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2484 SET_SRC (x) = replacement->new
2485 = fixup_memory_subreg (SET_SRC (x), insn, 0);
2486 else
2487 SET_SRC (x) = replacement->new
2488 = fixup_stack_1 (SET_SRC (x), insn);
2490 if (recog_memoized (insn) >= 0)
2491 return;
2493 /* INSN is not valid, but we know that we want to
2494 copy SET_SRC (x) to SET_DEST (x) in some way. So
2495 we generate the move and see whether it requires more
2496 than one insn. If it does, we emit those insns and
2497 delete INSN. Otherwise, we an just replace the pattern
2498 of INSN; we have already verified above that INSN has
2499 no other function that to do X. */
2501 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2502 if (GET_CODE (pat) == SEQUENCE)
2504 emit_insn_after (pat, insn);
2505 PUT_CODE (insn, NOTE);
2506 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2507 NOTE_SOURCE_FILE (insn) = 0;
2509 else
2510 PATTERN (insn) = pat;
2512 return;
2515 if ((SET_DEST (x) == var
2516 || (GET_CODE (SET_DEST (x)) == SUBREG
2517 && SUBREG_REG (SET_DEST (x)) == var))
2518 && (GET_CODE (SET_SRC (x)) == REG
2519 || (GET_CODE (SET_SRC (x)) == SUBREG
2520 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2521 && GET_MODE (var) == promoted_mode
2522 && x == single_set (insn))
2524 rtx pat;
2526 if (GET_CODE (SET_DEST (x)) == SUBREG)
2527 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0);
2528 else
2529 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2531 if (recog_memoized (insn) >= 0)
2532 return;
2534 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2535 if (GET_CODE (pat) == SEQUENCE)
2537 emit_insn_after (pat, insn);
2538 PUT_CODE (insn, NOTE);
2539 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
2540 NOTE_SOURCE_FILE (insn) = 0;
2542 else
2543 PATTERN (insn) = pat;
2545 return;
2548 /* Otherwise, storing into VAR must be handled specially
2549 by storing into a temporary and copying that into VAR
2550 with a new insn after this one. Note that this case
2551 will be used when storing into a promoted scalar since
2552 the insn will now have different modes on the input
2553 and output and hence will be invalid (except for the case
2554 of setting it to a constant, which does not need any
2555 change if it is valid). We generate extra code in that case,
2556 but combine.c will eliminate it. */
2558 if (dest == var)
2560 rtx temp;
2561 rtx fixeddest = SET_DEST (x);
2563 /* STRICT_LOW_PART can be discarded, around a MEM. */
2564 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2565 fixeddest = XEXP (fixeddest, 0);
2566 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2567 if (GET_CODE (fixeddest) == SUBREG)
2569 fixeddest = fixup_memory_subreg (fixeddest, insn, 0);
2570 promoted_mode = GET_MODE (fixeddest);
2572 else
2573 fixeddest = fixup_stack_1 (fixeddest, insn);
2575 temp = gen_reg_rtx (promoted_mode);
2577 emit_insn_after (gen_move_insn (fixeddest,
2578 gen_lowpart (GET_MODE (fixeddest),
2579 temp)),
2580 insn);
2582 SET_DEST (x) = temp;
2586 default:
2587 break;
2590 /* Nothing special about this RTX; fix its operands. */
2592 fmt = GET_RTX_FORMAT (code);
2593 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2595 if (fmt[i] == 'e')
2596 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements);
2597 if (fmt[i] == 'E')
2599 register int j;
2600 for (j = 0; j < XVECLEN (x, i); j++)
2601 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2602 insn, replacements);
2607 /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
2608 return an rtx (MEM:m1 newaddr) which is equivalent.
2609 If any insns must be emitted to compute NEWADDR, put them before INSN.
2611 UNCRITICAL nonzero means accept paradoxical subregs.
2612 This is used for subregs found inside REG_NOTES. */
2614 static rtx
2615 fixup_memory_subreg (x, insn, uncritical)
2616 rtx x;
2617 rtx insn;
2618 int uncritical;
2620 int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
2621 rtx addr = XEXP (SUBREG_REG (x), 0);
2622 enum machine_mode mode = GET_MODE (x);
2623 rtx result;
2625 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2626 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
2627 && ! uncritical)
2628 abort ();
2630 if (BYTES_BIG_ENDIAN)
2631 offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
2632 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
2633 addr = plus_constant (addr, offset);
2634 if (!flag_force_addr && memory_address_p (mode, addr))
2635 /* Shortcut if no insns need be emitted. */
2636 return change_address (SUBREG_REG (x), mode, addr);
2637 start_sequence ();
2638 result = change_address (SUBREG_REG (x), mode, addr);
2639 emit_insn_before (gen_sequence (), insn);
2640 end_sequence ();
2641 return result;
2644 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2645 Replace subexpressions of X in place.
2646 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2647 Otherwise return X, with its contents possibly altered.
2649 If any insns must be emitted to compute NEWADDR, put them before INSN.
2651 UNCRITICAL is as in fixup_memory_subreg. */
2653 static rtx
2654 walk_fixup_memory_subreg (x, insn, uncritical)
2655 register rtx x;
2656 rtx insn;
2657 int uncritical;
2659 register enum rtx_code code;
2660 register char *fmt;
2661 register int i;
2663 if (x == 0)
2664 return 0;
2666 code = GET_CODE (x);
2668 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2669 return fixup_memory_subreg (x, insn, uncritical);
2671 /* Nothing special about this RTX; fix its operands. */
2673 fmt = GET_RTX_FORMAT (code);
2674 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2676 if (fmt[i] == 'e')
2677 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical);
2678 if (fmt[i] == 'E')
2680 register int j;
2681 for (j = 0; j < XVECLEN (x, i); j++)
2682 XVECEXP (x, i, j)
2683 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical);
2686 return x;
2689 /* For each memory ref within X, if it refers to a stack slot
2690 with an out of range displacement, put the address in a temp register
2691 (emitting new insns before INSN to load these registers)
2692 and alter the memory ref to use that register.
2693 Replace each such MEM rtx with a copy, to avoid clobberage. */
2695 static rtx
2696 fixup_stack_1 (x, insn)
2697 rtx x;
2698 rtx insn;
2700 register int i;
2701 register RTX_CODE code = GET_CODE (x);
2702 register char *fmt;
2704 if (code == MEM)
2706 register rtx ad = XEXP (x, 0);
2707 /* If we have address of a stack slot but it's not valid
2708 (displacement is too large), compute the sum in a register. */
2709 if (GET_CODE (ad) == PLUS
2710 && GET_CODE (XEXP (ad, 0)) == REG
2711 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2712 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2713 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2714 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2715 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2716 #endif
2717 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2718 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2719 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2720 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2722 rtx temp, seq;
2723 if (memory_address_p (GET_MODE (x), ad))
2724 return x;
2726 start_sequence ();
2727 temp = copy_to_reg (ad);
2728 seq = gen_sequence ();
2729 end_sequence ();
2730 emit_insn_before (seq, insn);
2731 return change_address (x, VOIDmode, temp);
2733 return x;
2736 fmt = GET_RTX_FORMAT (code);
2737 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2739 if (fmt[i] == 'e')
2740 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2741 if (fmt[i] == 'E')
2743 register int j;
2744 for (j = 0; j < XVECLEN (x, i); j++)
2745 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2748 return x;
2751 /* Optimization: a bit-field instruction whose field
2752 happens to be a byte or halfword in memory
2753 can be changed to a move instruction.
2755 We call here when INSN is an insn to examine or store into a bit-field.
2756 BODY is the SET-rtx to be altered.
2758 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2759 (Currently this is called only from function.c, and EQUIV_MEM
2760 is always 0.) */
2762 static void
2763 optimize_bit_field (body, insn, equiv_mem)
2764 rtx body;
2765 rtx insn;
2766 rtx *equiv_mem;
2768 register rtx bitfield;
2769 int destflag;
2770 rtx seq = 0;
2771 enum machine_mode mode;
2773 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2774 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2775 bitfield = SET_DEST (body), destflag = 1;
2776 else
2777 bitfield = SET_SRC (body), destflag = 0;
2779 /* First check that the field being stored has constant size and position
2780 and is in fact a byte or halfword suitably aligned. */
2782 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2783 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2784 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2785 != BLKmode)
2786 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2788 register rtx memref = 0;
2790 /* Now check that the containing word is memory, not a register,
2791 and that it is safe to change the machine mode. */
2793 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2794 memref = XEXP (bitfield, 0);
2795 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2796 && equiv_mem != 0)
2797 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2798 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2799 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2800 memref = SUBREG_REG (XEXP (bitfield, 0));
2801 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2802 && equiv_mem != 0
2803 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2804 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2806 if (memref
2807 && ! mode_dependent_address_p (XEXP (memref, 0))
2808 && ! MEM_VOLATILE_P (memref))
2810 /* Now adjust the address, first for any subreg'ing
2811 that we are now getting rid of,
2812 and then for which byte of the word is wanted. */
2814 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2815 rtx insns;
2817 /* Adjust OFFSET to count bits from low-address byte. */
2818 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2819 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2820 - offset - INTVAL (XEXP (bitfield, 1)));
2822 /* Adjust OFFSET to count bytes from low-address byte. */
2823 offset /= BITS_PER_UNIT;
2824 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2826 offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
2827 if (BYTES_BIG_ENDIAN)
2828 offset -= (MIN (UNITS_PER_WORD,
2829 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2830 - MIN (UNITS_PER_WORD,
2831 GET_MODE_SIZE (GET_MODE (memref))));
2834 start_sequence ();
2835 memref = change_address (memref, mode,
2836 plus_constant (XEXP (memref, 0), offset));
2837 insns = get_insns ();
2838 end_sequence ();
2839 emit_insns_before (insns, insn);
2841 /* Store this memory reference where
2842 we found the bit field reference. */
2844 if (destflag)
2846 validate_change (insn, &SET_DEST (body), memref, 1);
2847 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2849 rtx src = SET_SRC (body);
2850 while (GET_CODE (src) == SUBREG
2851 && SUBREG_WORD (src) == 0)
2852 src = SUBREG_REG (src);
2853 if (GET_MODE (src) != GET_MODE (memref))
2854 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2855 validate_change (insn, &SET_SRC (body), src, 1);
2857 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2858 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2859 /* This shouldn't happen because anything that didn't have
2860 one of these modes should have got converted explicitly
2861 and then referenced through a subreg.
2862 This is so because the original bit-field was
2863 handled by agg_mode and so its tree structure had
2864 the same mode that memref now has. */
2865 abort ();
2867 else
2869 rtx dest = SET_DEST (body);
2871 while (GET_CODE (dest) == SUBREG
2872 && SUBREG_WORD (dest) == 0
2873 && (GET_MODE_CLASS (GET_MODE (dest))
2874 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2875 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2876 <= UNITS_PER_WORD))
2877 dest = SUBREG_REG (dest);
2879 validate_change (insn, &SET_DEST (body), dest, 1);
2881 if (GET_MODE (dest) == GET_MODE (memref))
2882 validate_change (insn, &SET_SRC (body), memref, 1);
2883 else
2885 /* Convert the mem ref to the destination mode. */
2886 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2888 start_sequence ();
2889 convert_move (newreg, memref,
2890 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2891 seq = get_insns ();
2892 end_sequence ();
2894 validate_change (insn, &SET_SRC (body), newreg, 1);
2898 /* See if we can convert this extraction or insertion into
2899 a simple move insn. We might not be able to do so if this
2900 was, for example, part of a PARALLEL.
2902 If we succeed, write out any needed conversions. If we fail,
2903 it is hard to guess why we failed, so don't do anything
2904 special; just let the optimization be suppressed. */
2906 if (apply_change_group () && seq)
2907 emit_insns_before (seq, insn);
2912 /* These routines are responsible for converting virtual register references
2913 to the actual hard register references once RTL generation is complete.
2915 The following four variables are used for communication between the
2916 routines. They contain the offsets of the virtual registers from their
2917 respective hard registers. */
2919 static int in_arg_offset;
2920 static int var_offset;
2921 static int dynamic_offset;
2922 static int out_arg_offset;
2923 static int cfa_offset;
2925 /* In most machines, the stack pointer register is equivalent to the bottom
2926 of the stack. */
2928 #ifndef STACK_POINTER_OFFSET
2929 #define STACK_POINTER_OFFSET 0
2930 #endif
2932 /* If not defined, pick an appropriate default for the offset of dynamically
2933 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2934 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2936 #ifndef STACK_DYNAMIC_OFFSET
2938 #ifdef ACCUMULATE_OUTGOING_ARGS
2939 /* The bottom of the stack points to the actual arguments. If
2940 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2941 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2942 stack space for register parameters is not pushed by the caller, but
2943 rather part of the fixed stack areas and hence not included in
2944 `current_function_outgoing_args_size'. Nevertheless, we must allow
2945 for it when allocating stack dynamic objects. */
2947 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2948 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2949 (current_function_outgoing_args_size \
2950 + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
2952 #else
2953 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2954 (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
2955 #endif
2957 #else
2958 #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
2959 #endif
2960 #endif
2962 /* On a few machines, the CFA coincides with the arg pointer. */
2964 #ifndef ARG_POINTER_CFA_OFFSET
2965 #define ARG_POINTER_CFA_OFFSET 0
2966 #endif
2969 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had
2970 its address taken. DECL is the decl for the object stored in the
2971 register, for later use if we do need to force REG into the stack.
2972 REG is overwritten by the MEM like in put_reg_into_stack. */
2975 gen_mem_addressof (reg, decl)
2976 rtx reg;
2977 tree decl;
2979 tree type = TREE_TYPE (decl);
2980 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)), REGNO (reg));
2981 SET_ADDRESSOF_DECL (r, decl);
2982 /* If the original REG was a user-variable, then so is the REG whose
2983 address is being taken. */
2984 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2986 XEXP (reg, 0) = r;
2987 PUT_CODE (reg, MEM);
2988 PUT_MODE (reg, DECL_MODE (decl));
2989 MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl);
2990 MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type));
2991 MEM_ALIAS_SET (reg) = get_alias_set (decl);
2993 if (TREE_USED (decl) || DECL_INITIAL (decl) != 0)
2994 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), 0);
2996 return reg;
2999 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
3001 void
3002 flush_addressof (decl)
3003 tree decl;
3005 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
3006 && DECL_RTL (decl) != 0
3007 && GET_CODE (DECL_RTL (decl)) == MEM
3008 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
3009 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
3010 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
3013 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
3015 static void
3016 put_addressof_into_stack (r, ht)
3017 rtx r;
3018 struct hash_table *ht;
3020 tree decl = ADDRESSOF_DECL (r);
3021 rtx reg = XEXP (r, 0);
3023 if (GET_CODE (reg) != REG)
3024 abort ();
3026 put_reg_into_stack (0, reg, TREE_TYPE (decl), GET_MODE (reg),
3027 DECL_MODE (decl), TREE_SIDE_EFFECTS (decl),
3028 ADDRESSOF_REGNO (r),
3029 TREE_USED (decl) || DECL_INITIAL (decl) != 0, ht);
3032 /* List of replacements made below in purge_addressof_1 when creating
3033 bitfield insertions. */
3034 static rtx purge_addressof_replacements;
3036 /* Helper function for purge_addressof. See if the rtx expression at *LOC
3037 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
3038 the stack. */
3040 static void
3041 purge_addressof_1 (loc, insn, force, store, ht)
3042 rtx *loc;
3043 rtx insn;
3044 int force, store;
3045 struct hash_table *ht;
3047 rtx x;
3048 RTX_CODE code;
3049 int i, j;
3050 char *fmt;
3052 /* Re-start here to avoid recursion in common cases. */
3053 restart:
3055 x = *loc;
3056 if (x == 0)
3057 return;
3059 code = GET_CODE (x);
3061 if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM)
3063 rtx insns;
3064 /* We must create a copy of the rtx because it was created by
3065 overwriting a REG rtx which is always shared. */
3066 rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3068 if (validate_change (insn, loc, sub, 0)
3069 || validate_replace_rtx (x, sub, insn))
3070 return;
3072 start_sequence ();
3073 sub = force_operand (sub, NULL_RTX);
3074 if (! validate_change (insn, loc, sub, 0)
3075 && ! validate_replace_rtx (x, sub, insn))
3076 abort ();
3078 insns = gen_sequence ();
3079 end_sequence ();
3080 emit_insn_before (insns, insn);
3081 return;
3083 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3085 rtx sub = XEXP (XEXP (x, 0), 0);
3086 rtx sub2;
3088 if (GET_CODE (sub) == MEM)
3090 sub2 = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0)));
3091 MEM_COPY_ATTRIBUTES (sub2, sub);
3092 RTX_UNCHANGING_P (sub2) = RTX_UNCHANGING_P (sub);
3093 sub = sub2;
3096 if (GET_CODE (sub) == REG
3097 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3099 put_addressof_into_stack (XEXP (x, 0), ht);
3100 return;
3102 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3104 int size_x, size_sub;
3106 if (!insn)
3108 /* When processing REG_NOTES look at the list of
3109 replacements done on the insn to find the register that X
3110 was replaced by. */
3111 rtx tem;
3113 for (tem = purge_addressof_replacements; tem != NULL_RTX;
3114 tem = XEXP (XEXP (tem, 1), 1))
3116 rtx y = XEXP (tem, 0);
3117 if (GET_CODE (y) == MEM
3118 && rtx_equal_p (XEXP (x, 0), XEXP (y, 0)))
3120 /* It can happen that the note may speak of things in
3121 a wider (or just different) mode than the code did.
3122 This is especially true of REG_RETVAL. */
3124 rtx z = XEXP (XEXP (tem, 1), 0);
3125 if (GET_MODE (x) != GET_MODE (y))
3127 if (GET_CODE (z) == SUBREG && SUBREG_WORD (z) == 0)
3128 z = SUBREG_REG (z);
3130 /* ??? If we'd gotten into any of the really complex
3131 cases below, I'm not sure we can do a proper
3132 replacement. Might we be able to delete the
3133 note in some cases? */
3134 if (GET_MODE_SIZE (GET_MODE (x))
3135 < GET_MODE_SIZE (GET_MODE (y)))
3136 abort ();
3138 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3139 && (GET_MODE_SIZE (GET_MODE (x))
3140 > GET_MODE_SIZE (GET_MODE (z))))
3142 /* This can occur as a result in invalid
3143 pointer casts, e.g. float f; ...
3144 *(long long int *)&f.
3145 ??? We could emit a warning here, but
3146 without a line number that wouldn't be
3147 very helpful. */
3148 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3150 else
3151 z = gen_lowpart (GET_MODE (x), z);
3154 *loc = z;
3155 return;
3159 /* There should always be such a replacement. */
3160 abort ();
3163 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3164 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3166 /* Don't even consider working with paradoxical subregs,
3167 or the moral equivalent seen here. */
3168 if (size_x <= size_sub
3169 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3171 /* Do a bitfield insertion to mirror what would happen
3172 in memory. */
3174 rtx val, seq;
3176 if (store)
3178 rtx p = PREV_INSN (insn);
3180 start_sequence ();
3181 val = gen_reg_rtx (GET_MODE (x));
3182 if (! validate_change (insn, loc, val, 0))
3184 /* Discard the current sequence and put the
3185 ADDRESSOF on stack. */
3186 end_sequence ();
3187 goto give_up;
3189 seq = gen_sequence ();
3190 end_sequence ();
3191 emit_insn_before (seq, insn);
3192 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3193 insn, ht);
3195 start_sequence ();
3196 store_bit_field (sub, size_x, 0, GET_MODE (x),
3197 val, GET_MODE_SIZE (GET_MODE (sub)),
3198 GET_MODE_SIZE (GET_MODE (sub)));
3200 /* Make sure to unshare any shared rtl that store_bit_field
3201 might have created. */
3202 for (p = get_insns(); p; p = NEXT_INSN (p))
3204 reset_used_flags (PATTERN (p));
3205 reset_used_flags (REG_NOTES (p));
3206 reset_used_flags (LOG_LINKS (p));
3208 unshare_all_rtl (get_insns ());
3210 seq = gen_sequence ();
3211 end_sequence ();
3212 p = emit_insn_after (seq, insn);
3213 if (NEXT_INSN (insn))
3214 compute_insns_for_mem (NEXT_INSN (insn),
3215 p ? NEXT_INSN (p) : NULL_RTX,
3216 ht);
3218 else
3220 rtx p = PREV_INSN (insn);
3222 start_sequence ();
3223 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3224 GET_MODE (x), GET_MODE (x),
3225 GET_MODE_SIZE (GET_MODE (sub)),
3226 GET_MODE_SIZE (GET_MODE (sub)));
3228 if (! validate_change (insn, loc, val, 0))
3230 /* Discard the current sequence and put the
3231 ADDRESSOF on stack. */
3232 end_sequence ();
3233 goto give_up;
3236 seq = gen_sequence ();
3237 end_sequence ();
3238 emit_insn_before (seq, insn);
3239 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3240 insn, ht);
3243 /* Remember the replacement so that the same one can be done
3244 on the REG_NOTES. */
3245 purge_addressof_replacements
3246 = gen_rtx_EXPR_LIST (VOIDmode, x,
3247 gen_rtx_EXPR_LIST (VOIDmode, val,
3248 purge_addressof_replacements));
3250 /* We replaced with a reg -- all done. */
3251 return;
3254 else if (validate_change (insn, loc, sub, 0))
3256 /* Remember the replacement so that the same one can be done
3257 on the REG_NOTES. */
3258 purge_addressof_replacements
3259 = gen_rtx_EXPR_LIST (VOIDmode, x,
3260 gen_rtx_EXPR_LIST (VOIDmode, sub,
3261 purge_addressof_replacements));
3262 goto restart;
3264 give_up:;
3265 /* else give up and put it into the stack */
3267 else if (code == ADDRESSOF)
3269 put_addressof_into_stack (x, ht);
3270 return;
3272 else if (code == SET)
3274 purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3275 purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3276 return;
3279 /* Scan all subexpressions. */
3280 fmt = GET_RTX_FORMAT (code);
3281 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3283 if (*fmt == 'e')
3284 purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3285 else if (*fmt == 'E')
3286 for (j = 0; j < XVECLEN (x, i); j++)
3287 purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
3291 /* Return a new hash table entry in HT. */
3293 static struct hash_entry *
3294 insns_for_mem_newfunc (he, ht, k)
3295 struct hash_entry *he;
3296 struct hash_table *ht;
3297 hash_table_key k ATTRIBUTE_UNUSED;
3299 struct insns_for_mem_entry *ifmhe;
3300 if (he)
3301 return he;
3303 ifmhe = ((struct insns_for_mem_entry *)
3304 hash_allocate (ht, sizeof (struct insns_for_mem_entry)));
3305 ifmhe->insns = NULL_RTX;
3307 return &ifmhe->he;
3310 /* Return a hash value for K, a REG. */
3312 static unsigned long
3313 insns_for_mem_hash (k)
3314 hash_table_key k;
3316 /* K is really a RTX. Just use the address as the hash value. */
3317 return (unsigned long) k;
3320 /* Return non-zero if K1 and K2 (two REGs) are the same. */
3322 static boolean
3323 insns_for_mem_comp (k1, k2)
3324 hash_table_key k1;
3325 hash_table_key k2;
3327 return k1 == k2;
3330 struct insns_for_mem_walk_info {
3331 /* The hash table that we are using to record which INSNs use which
3332 MEMs. */
3333 struct hash_table *ht;
3335 /* The INSN we are currently proessing. */
3336 rtx insn;
3338 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3339 to find the insns that use the REGs in the ADDRESSOFs. */
3340 int pass;
3343 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3344 that might be used in an ADDRESSOF expression, record this INSN in
3345 the hash table given by DATA (which is really a pointer to an
3346 insns_for_mem_walk_info structure). */
3348 static int
3349 insns_for_mem_walk (r, data)
3350 rtx *r;
3351 void *data;
3353 struct insns_for_mem_walk_info *ifmwi
3354 = (struct insns_for_mem_walk_info *) data;
3356 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3357 && GET_CODE (XEXP (*r, 0)) == REG)
3358 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0);
3359 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3361 /* Lookup this MEM in the hashtable, creating it if necessary. */
3362 struct insns_for_mem_entry *ifme
3363 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht,
3365 /*create=*/0,
3366 /*copy=*/0);
3368 /* If we have not already recorded this INSN, do so now. Since
3369 we process the INSNs in order, we know that if we have
3370 recorded it it must be at the front of the list. */
3371 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3373 /* We do the allocation on the same obstack as is used for
3374 the hash table since this memory will not be used once
3375 the hash table is deallocated. */
3376 push_obstacks (&ifmwi->ht->memory, &ifmwi->ht->memory);
3377 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3378 ifme->insns);
3379 pop_obstacks ();
3383 return 0;
3386 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3387 which REGs in HT. */
3389 static void
3390 compute_insns_for_mem (insns, last_insn, ht)
3391 rtx insns;
3392 rtx last_insn;
3393 struct hash_table *ht;
3395 rtx insn;
3396 struct insns_for_mem_walk_info ifmwi;
3397 ifmwi.ht = ht;
3399 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3400 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3401 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3403 ifmwi.insn = insn;
3404 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3408 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3409 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3410 stack. */
3412 void
3413 purge_addressof (insns)
3414 rtx insns;
3416 rtx insn;
3417 struct hash_table ht;
3419 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3420 requires a fixup pass over the instruction stream to correct
3421 INSNs that depended on the REG being a REG, and not a MEM. But,
3422 these fixup passes are slow. Furthermore, more MEMs are not
3423 mentioned in very many instructions. So, we speed up the process
3424 by pre-calculating which REGs occur in which INSNs; that allows
3425 us to perform the fixup passes much more quickly. */
3426 hash_table_init (&ht,
3427 insns_for_mem_newfunc,
3428 insns_for_mem_hash,
3429 insns_for_mem_comp);
3430 compute_insns_for_mem (insns, NULL_RTX, &ht);
3432 for (insn = insns; insn; insn = NEXT_INSN (insn))
3433 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3434 || GET_CODE (insn) == CALL_INSN)
3436 purge_addressof_1 (&PATTERN (insn), insn,
3437 asm_noperands (PATTERN (insn)) > 0, 0, &ht);
3438 purge_addressof_1 (&REG_NOTES (insn), NULL_RTX, 0, 0, &ht);
3441 /* Clean up. */
3442 hash_table_free (&ht);
3443 purge_addressof_replacements = 0;
3446 /* Pass through the INSNS of function FNDECL and convert virtual register
3447 references to hard register references. */
3449 void
3450 instantiate_virtual_regs (fndecl, insns)
3451 tree fndecl;
3452 rtx insns;
3454 rtx insn;
3455 int i;
3457 /* Compute the offsets to use for this function. */
3458 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3459 var_offset = STARTING_FRAME_OFFSET;
3460 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3461 out_arg_offset = STACK_POINTER_OFFSET;
3462 cfa_offset = ARG_POINTER_CFA_OFFSET;
3464 /* Scan all variables and parameters of this function. For each that is
3465 in memory, instantiate all virtual registers if the result is a valid
3466 address. If not, we do it later. That will handle most uses of virtual
3467 regs on many machines. */
3468 instantiate_decls (fndecl, 1);
3470 /* Initialize recognition, indicating that volatile is OK. */
3471 init_recog ();
3473 /* Scan through all the insns, instantiating every virtual register still
3474 present. */
3475 for (insn = insns; insn; insn = NEXT_INSN (insn))
3476 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3477 || GET_CODE (insn) == CALL_INSN)
3479 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3480 instantiate_virtual_regs_1 (&REG_NOTES (insn), NULL_RTX, 0);
3483 /* Instantiate the stack slots for the parm registers, for later use in
3484 addressof elimination. */
3485 for (i = 0; i < max_parm_reg; ++i)
3486 if (parm_reg_stack_loc[i])
3487 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3489 /* Now instantiate the remaining register equivalences for debugging info.
3490 These will not be valid addresses. */
3491 instantiate_decls (fndecl, 0);
3493 /* Indicate that, from now on, assign_stack_local should use
3494 frame_pointer_rtx. */
3495 virtuals_instantiated = 1;
3498 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3499 all virtual registers in their DECL_RTL's.
3501 If VALID_ONLY, do this only if the resulting address is still valid.
3502 Otherwise, always do it. */
3504 static void
3505 instantiate_decls (fndecl, valid_only)
3506 tree fndecl;
3507 int valid_only;
3509 tree decl;
3511 if (DECL_SAVED_INSNS (fndecl))
3512 /* When compiling an inline function, the obstack used for
3513 rtl allocation is the maybepermanent_obstack. Calling
3514 `resume_temporary_allocation' switches us back to that
3515 obstack while we process this function's parameters. */
3516 resume_temporary_allocation ();
3518 /* Process all parameters of the function. */
3519 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3521 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3523 instantiate_decl (DECL_RTL (decl), size, valid_only);
3525 /* If the parameter was promoted, then the incoming RTL mode may be
3526 larger than the declared type size. We must use the larger of
3527 the two sizes. */
3528 size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size);
3529 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3532 /* Now process all variables defined in the function or its subblocks. */
3533 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3535 if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl))
3537 /* Save all rtl allocated for this function by raising the
3538 high-water mark on the maybepermanent_obstack. */
3539 preserve_data ();
3540 /* All further rtl allocation is now done in the current_obstack. */
3541 rtl_in_current_obstack ();
3545 /* Subroutine of instantiate_decls: Process all decls in the given
3546 BLOCK node and all its subblocks. */
3548 static void
3549 instantiate_decls_1 (let, valid_only)
3550 tree let;
3551 int valid_only;
3553 tree t;
3555 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3556 instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)),
3557 valid_only);
3559 /* Process all subblocks. */
3560 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3561 instantiate_decls_1 (t, valid_only);
3564 /* Subroutine of the preceding procedures: Given RTL representing a
3565 decl and the size of the object, do any instantiation required.
3567 If VALID_ONLY is non-zero, it means that the RTL should only be
3568 changed if the new address is valid. */
3570 static void
3571 instantiate_decl (x, size, valid_only)
3572 rtx x;
3573 int size;
3574 int valid_only;
3576 enum machine_mode mode;
3577 rtx addr;
3579 /* If this is not a MEM, no need to do anything. Similarly if the
3580 address is a constant or a register that is not a virtual register. */
3582 if (x == 0 || GET_CODE (x) != MEM)
3583 return;
3585 addr = XEXP (x, 0);
3586 if (CONSTANT_P (addr)
3587 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3588 || (GET_CODE (addr) == REG
3589 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3590 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3591 return;
3593 /* If we should only do this if the address is valid, copy the address.
3594 We need to do this so we can undo any changes that might make the
3595 address invalid. This copy is unfortunate, but probably can't be
3596 avoided. */
3598 if (valid_only)
3599 addr = copy_rtx (addr);
3601 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3603 if (valid_only)
3605 /* Now verify that the resulting address is valid for every integer or
3606 floating-point mode up to and including SIZE bytes long. We do this
3607 since the object might be accessed in any mode and frame addresses
3608 are shared. */
3610 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3611 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3612 mode = GET_MODE_WIDER_MODE (mode))
3613 if (! memory_address_p (mode, addr))
3614 return;
3616 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3617 mode != VOIDmode && GET_MODE_SIZE (mode) <= size;
3618 mode = GET_MODE_WIDER_MODE (mode))
3619 if (! memory_address_p (mode, addr))
3620 return;
3623 /* Put back the address now that we have updated it and we either know
3624 it is valid or we don't care whether it is valid. */
3626 XEXP (x, 0) = addr;
3629 /* Given a pointer to a piece of rtx and an optional pointer to the
3630 containing object, instantiate any virtual registers present in it.
3632 If EXTRA_INSNS, we always do the replacement and generate
3633 any extra insns before OBJECT. If it zero, we do nothing if replacement
3634 is not valid.
3636 Return 1 if we either had nothing to do or if we were able to do the
3637 needed replacement. Return 0 otherwise; we only return zero if
3638 EXTRA_INSNS is zero.
3640 We first try some simple transformations to avoid the creation of extra
3641 pseudos. */
3643 static int
3644 instantiate_virtual_regs_1 (loc, object, extra_insns)
3645 rtx *loc;
3646 rtx object;
3647 int extra_insns;
3649 rtx x;
3650 RTX_CODE code;
3651 rtx new = 0;
3652 HOST_WIDE_INT offset = 0;
3653 rtx temp;
3654 rtx seq;
3655 int i, j;
3656 char *fmt;
3658 /* Re-start here to avoid recursion in common cases. */
3659 restart:
3661 x = *loc;
3662 if (x == 0)
3663 return 1;
3665 code = GET_CODE (x);
3667 /* Check for some special cases. */
3668 switch (code)
3670 case CONST_INT:
3671 case CONST_DOUBLE:
3672 case CONST:
3673 case SYMBOL_REF:
3674 case CODE_LABEL:
3675 case PC:
3676 case CC0:
3677 case ASM_INPUT:
3678 case ADDR_VEC:
3679 case ADDR_DIFF_VEC:
3680 case RETURN:
3681 return 1;
3683 case SET:
3684 /* We are allowed to set the virtual registers. This means that
3685 the actual register should receive the source minus the
3686 appropriate offset. This is used, for example, in the handling
3687 of non-local gotos. */
3688 if (SET_DEST (x) == virtual_incoming_args_rtx)
3689 new = arg_pointer_rtx, offset = - in_arg_offset;
3690 else if (SET_DEST (x) == virtual_stack_vars_rtx)
3691 new = frame_pointer_rtx, offset = - var_offset;
3692 else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
3693 new = stack_pointer_rtx, offset = - dynamic_offset;
3694 else if (SET_DEST (x) == virtual_outgoing_args_rtx)
3695 new = stack_pointer_rtx, offset = - out_arg_offset;
3696 else if (SET_DEST (x) == virtual_cfa_rtx)
3697 new = arg_pointer_rtx, offset = - cfa_offset;
3699 if (new)
3701 /* The only valid sources here are PLUS or REG. Just do
3702 the simplest possible thing to handle them. */
3703 if (GET_CODE (SET_SRC (x)) != REG
3704 && GET_CODE (SET_SRC (x)) != PLUS)
3705 abort ();
3707 start_sequence ();
3708 if (GET_CODE (SET_SRC (x)) != REG)
3709 temp = force_operand (SET_SRC (x), NULL_RTX);
3710 else
3711 temp = SET_SRC (x);
3712 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3713 seq = get_insns ();
3714 end_sequence ();
3716 emit_insns_before (seq, object);
3717 SET_DEST (x) = new;
3719 if (! validate_change (object, &SET_SRC (x), temp, 0)
3720 || ! extra_insns)
3721 abort ();
3723 return 1;
3726 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3727 loc = &SET_SRC (x);
3728 goto restart;
3730 case PLUS:
3731 /* Handle special case of virtual register plus constant. */
3732 if (CONSTANT_P (XEXP (x, 1)))
3734 rtx old, new_offset;
3736 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3737 if (GET_CODE (XEXP (x, 0)) == PLUS)
3739 rtx inner = XEXP (XEXP (x, 0), 0);
3741 if (inner == virtual_incoming_args_rtx)
3742 new = arg_pointer_rtx, offset = in_arg_offset;
3743 else if (inner == virtual_stack_vars_rtx)
3744 new = frame_pointer_rtx, offset = var_offset;
3745 else if (inner == virtual_stack_dynamic_rtx)
3746 new = stack_pointer_rtx, offset = dynamic_offset;
3747 else if (inner == virtual_outgoing_args_rtx)
3748 new = stack_pointer_rtx, offset = out_arg_offset;
3749 else if (inner == virtual_cfa_rtx)
3750 new = arg_pointer_rtx, offset = cfa_offset;
3751 else
3753 loc = &XEXP (x, 0);
3754 goto restart;
3757 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3758 extra_insns);
3759 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3762 else if (XEXP (x, 0) == virtual_incoming_args_rtx)
3763 new = arg_pointer_rtx, offset = in_arg_offset;
3764 else if (XEXP (x, 0) == virtual_stack_vars_rtx)
3765 new = frame_pointer_rtx, offset = var_offset;
3766 else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
3767 new = stack_pointer_rtx, offset = dynamic_offset;
3768 else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
3769 new = stack_pointer_rtx, offset = out_arg_offset;
3770 else if (XEXP (x, 0) == virtual_cfa_rtx)
3771 new = arg_pointer_rtx, offset = cfa_offset;
3772 else
3774 /* We know the second operand is a constant. Unless the
3775 first operand is a REG (which has been already checked),
3776 it needs to be checked. */
3777 if (GET_CODE (XEXP (x, 0)) != REG)
3779 loc = &XEXP (x, 0);
3780 goto restart;
3782 return 1;
3785 new_offset = plus_constant (XEXP (x, 1), offset);
3787 /* If the new constant is zero, try to replace the sum with just
3788 the register. */
3789 if (new_offset == const0_rtx
3790 && validate_change (object, loc, new, 0))
3791 return 1;
3793 /* Next try to replace the register and new offset.
3794 There are two changes to validate here and we can't assume that
3795 in the case of old offset equals new just changing the register
3796 will yield a valid insn. In the interests of a little efficiency,
3797 however, we only call validate change once (we don't queue up the
3798 changes and then call apply_change_group). */
3800 old = XEXP (x, 0);
3801 if (offset == 0
3802 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3803 : (XEXP (x, 0) = new,
3804 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3806 if (! extra_insns)
3808 XEXP (x, 0) = old;
3809 return 0;
3812 /* Otherwise copy the new constant into a register and replace
3813 constant with that register. */
3814 temp = gen_reg_rtx (Pmode);
3815 XEXP (x, 0) = new;
3816 if (validate_change (object, &XEXP (x, 1), temp, 0))
3817 emit_insn_before (gen_move_insn (temp, new_offset), object);
3818 else
3820 /* If that didn't work, replace this expression with a
3821 register containing the sum. */
3823 XEXP (x, 0) = old;
3824 new = gen_rtx_PLUS (Pmode, new, new_offset);
3826 start_sequence ();
3827 temp = force_operand (new, NULL_RTX);
3828 seq = get_insns ();
3829 end_sequence ();
3831 emit_insns_before (seq, object);
3832 if (! validate_change (object, loc, temp, 0)
3833 && ! validate_replace_rtx (x, temp, object))
3834 abort ();
3838 return 1;
3841 /* Fall through to generic two-operand expression case. */
3842 case EXPR_LIST:
3843 case CALL:
3844 case COMPARE:
3845 case MINUS:
3846 case MULT:
3847 case DIV: case UDIV:
3848 case MOD: case UMOD:
3849 case AND: case IOR: case XOR:
3850 case ROTATERT: case ROTATE:
3851 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3852 case NE: case EQ:
3853 case GE: case GT: case GEU: case GTU:
3854 case LE: case LT: case LEU: case LTU:
3855 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3856 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3857 loc = &XEXP (x, 0);
3858 goto restart;
3860 case MEM:
3861 /* Most cases of MEM that convert to valid addresses have already been
3862 handled by our scan of decls. The only special handling we
3863 need here is to make a copy of the rtx to ensure it isn't being
3864 shared if we have to change it to a pseudo.
3866 If the rtx is a simple reference to an address via a virtual register,
3867 it can potentially be shared. In such cases, first try to make it
3868 a valid address, which can also be shared. Otherwise, copy it and
3869 proceed normally.
3871 First check for common cases that need no processing. These are
3872 usually due to instantiation already being done on a previous instance
3873 of a shared rtx. */
3875 temp = XEXP (x, 0);
3876 if (CONSTANT_ADDRESS_P (temp)
3877 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3878 || temp == arg_pointer_rtx
3879 #endif
3880 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3881 || temp == hard_frame_pointer_rtx
3882 #endif
3883 || temp == frame_pointer_rtx)
3884 return 1;
3886 if (GET_CODE (temp) == PLUS
3887 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3888 && (XEXP (temp, 0) == frame_pointer_rtx
3889 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3890 || XEXP (temp, 0) == hard_frame_pointer_rtx
3891 #endif
3892 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3893 || XEXP (temp, 0) == arg_pointer_rtx
3894 #endif
3896 return 1;
3898 if (temp == virtual_stack_vars_rtx
3899 || temp == virtual_incoming_args_rtx
3900 || (GET_CODE (temp) == PLUS
3901 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3902 && (XEXP (temp, 0) == virtual_stack_vars_rtx
3903 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
3905 /* This MEM may be shared. If the substitution can be done without
3906 the need to generate new pseudos, we want to do it in place
3907 so all copies of the shared rtx benefit. The call below will
3908 only make substitutions if the resulting address is still
3909 valid.
3911 Note that we cannot pass X as the object in the recursive call
3912 since the insn being processed may not allow all valid
3913 addresses. However, if we were not passed on object, we can
3914 only modify X without copying it if X will have a valid
3915 address.
3917 ??? Also note that this can still lose if OBJECT is an insn that
3918 has less restrictions on an address that some other insn.
3919 In that case, we will modify the shared address. This case
3920 doesn't seem very likely, though. One case where this could
3921 happen is in the case of a USE or CLOBBER reference, but we
3922 take care of that below. */
3924 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
3925 object ? object : x, 0))
3926 return 1;
3928 /* Otherwise make a copy and process that copy. We copy the entire
3929 RTL expression since it might be a PLUS which could also be
3930 shared. */
3931 *loc = x = copy_rtx (x);
3934 /* Fall through to generic unary operation case. */
3935 case SUBREG:
3936 case STRICT_LOW_PART:
3937 case NEG: case NOT:
3938 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
3939 case SIGN_EXTEND: case ZERO_EXTEND:
3940 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
3941 case FLOAT: case FIX:
3942 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
3943 case ABS:
3944 case SQRT:
3945 case FFS:
3946 /* These case either have just one operand or we know that we need not
3947 check the rest of the operands. */
3948 loc = &XEXP (x, 0);
3949 goto restart;
3951 case USE:
3952 case CLOBBER:
3953 /* If the operand is a MEM, see if the change is a valid MEM. If not,
3954 go ahead and make the invalid one, but do it to a copy. For a REG,
3955 just make the recursive call, since there's no chance of a problem. */
3957 if ((GET_CODE (XEXP (x, 0)) == MEM
3958 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
3960 || (GET_CODE (XEXP (x, 0)) == REG
3961 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
3962 return 1;
3964 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
3965 loc = &XEXP (x, 0);
3966 goto restart;
3968 case REG:
3969 /* Try to replace with a PLUS. If that doesn't work, compute the sum
3970 in front of this insn and substitute the temporary. */
3971 if (x == virtual_incoming_args_rtx)
3972 new = arg_pointer_rtx, offset = in_arg_offset;
3973 else if (x == virtual_stack_vars_rtx)
3974 new = frame_pointer_rtx, offset = var_offset;
3975 else if (x == virtual_stack_dynamic_rtx)
3976 new = stack_pointer_rtx, offset = dynamic_offset;
3977 else if (x == virtual_outgoing_args_rtx)
3978 new = stack_pointer_rtx, offset = out_arg_offset;
3979 else if (x == virtual_cfa_rtx)
3980 new = arg_pointer_rtx, offset = cfa_offset;
3982 if (new)
3984 temp = plus_constant (new, offset);
3985 if (!validate_change (object, loc, temp, 0))
3987 if (! extra_insns)
3988 return 0;
3990 start_sequence ();
3991 temp = force_operand (temp, NULL_RTX);
3992 seq = get_insns ();
3993 end_sequence ();
3995 emit_insns_before (seq, object);
3996 if (! validate_change (object, loc, temp, 0)
3997 && ! validate_replace_rtx (x, temp, object))
3998 abort ();
4002 return 1;
4004 case ADDRESSOF:
4005 if (GET_CODE (XEXP (x, 0)) == REG)
4006 return 1;
4008 else if (GET_CODE (XEXP (x, 0)) == MEM)
4010 /* If we have a (addressof (mem ..)), do any instantiation inside
4011 since we know we'll be making the inside valid when we finally
4012 remove the ADDRESSOF. */
4013 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4014 return 1;
4016 break;
4018 default:
4019 break;
4022 /* Scan all subexpressions. */
4023 fmt = GET_RTX_FORMAT (code);
4024 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4025 if (*fmt == 'e')
4027 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4028 return 0;
4030 else if (*fmt == 'E')
4031 for (j = 0; j < XVECLEN (x, i); j++)
4032 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4033 extra_insns))
4034 return 0;
4036 return 1;
4039 /* Optimization: assuming this function does not receive nonlocal gotos,
4040 delete the handlers for such, as well as the insns to establish
4041 and disestablish them. */
4043 static void
4044 delete_handlers ()
4046 rtx insn;
4047 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4049 /* Delete the handler by turning off the flag that would
4050 prevent jump_optimize from deleting it.
4051 Also permit deletion of the nonlocal labels themselves
4052 if nothing local refers to them. */
4053 if (GET_CODE (insn) == CODE_LABEL)
4055 tree t, last_t;
4057 LABEL_PRESERVE_P (insn) = 0;
4059 /* Remove it from the nonlocal_label list, to avoid confusing
4060 flow. */
4061 for (t = nonlocal_labels, last_t = 0; t;
4062 last_t = t, t = TREE_CHAIN (t))
4063 if (DECL_RTL (TREE_VALUE (t)) == insn)
4064 break;
4065 if (t)
4067 if (! last_t)
4068 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4069 else
4070 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4073 if (GET_CODE (insn) == INSN)
4075 int can_delete = 0;
4076 rtx t;
4077 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4078 if (reg_mentioned_p (t, PATTERN (insn)))
4080 can_delete = 1;
4081 break;
4083 if (can_delete
4084 || (nonlocal_goto_stack_level != 0
4085 && reg_mentioned_p (nonlocal_goto_stack_level,
4086 PATTERN (insn))))
4087 delete_insn (insn);
4092 /* Output a USE for any register use in RTL.
4093 This is used with -noreg to mark the extent of lifespan
4094 of any registers used in a user-visible variable's DECL_RTL. */
4096 void
4097 use_variable (rtl)
4098 rtx rtl;
4100 if (GET_CODE (rtl) == REG)
4101 /* This is a register variable. */
4102 emit_insn (gen_rtx_USE (VOIDmode, rtl));
4103 else if (GET_CODE (rtl) == MEM
4104 && GET_CODE (XEXP (rtl, 0)) == REG
4105 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
4106 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
4107 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
4108 /* This is a variable-sized structure. */
4109 emit_insn (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)));
4112 /* Like use_variable except that it outputs the USEs after INSN
4113 instead of at the end of the insn-chain. */
4115 void
4116 use_variable_after (rtl, insn)
4117 rtx rtl, insn;
4119 if (GET_CODE (rtl) == REG)
4120 /* This is a register variable. */
4121 emit_insn_after (gen_rtx_USE (VOIDmode, rtl), insn);
4122 else if (GET_CODE (rtl) == MEM
4123 && GET_CODE (XEXP (rtl, 0)) == REG
4124 && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
4125 || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER)
4126 && XEXP (rtl, 0) != current_function_internal_arg_pointer)
4127 /* This is a variable-sized structure. */
4128 emit_insn_after (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)), insn);
4132 max_parm_reg_num ()
4134 return max_parm_reg;
4137 /* Return the first insn following those generated by `assign_parms'. */
4140 get_first_nonparm_insn ()
4142 if (last_parm_insn)
4143 return NEXT_INSN (last_parm_insn);
4144 return get_insns ();
4147 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4148 Crash if there is none. */
4151 get_first_block_beg ()
4153 register rtx searcher;
4154 register rtx insn = get_first_nonparm_insn ();
4156 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
4157 if (GET_CODE (searcher) == NOTE
4158 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
4159 return searcher;
4161 abort (); /* Invalid call to this function. (See comments above.) */
4162 return NULL_RTX;
4165 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4166 This means a type for which function calls must pass an address to the
4167 function or get an address back from the function.
4168 EXP may be a type node or an expression (whose type is tested). */
4171 aggregate_value_p (exp)
4172 tree exp;
4174 int i, regno, nregs;
4175 rtx reg;
4176 tree type;
4177 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't')
4178 type = exp;
4179 else
4180 type = TREE_TYPE (exp);
4182 if (RETURN_IN_MEMORY (type))
4183 return 1;
4184 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4185 and thus can't be returned in registers. */
4186 if (TREE_ADDRESSABLE (type))
4187 return 1;
4188 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4189 return 1;
4190 /* Make sure we have suitable call-clobbered regs to return
4191 the value in; if not, we must return it in memory. */
4192 reg = hard_function_value (type, 0);
4194 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4195 it is OK. */
4196 if (GET_CODE (reg) != REG)
4197 return 0;
4199 regno = REGNO (reg);
4200 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4201 for (i = 0; i < nregs; i++)
4202 if (! call_used_regs[regno + i])
4203 return 1;
4204 return 0;
4207 /* Assign RTL expressions to the function's parameters.
4208 This may involve copying them into registers and using
4209 those registers as the RTL for them.
4211 If SECOND_TIME is non-zero it means that this function is being
4212 called a second time. This is done by integrate.c when a function's
4213 compilation is deferred. We need to come back here in case the
4214 FUNCTION_ARG macro computes items needed for the rest of the compilation
4215 (such as changing which registers are fixed or caller-saved). But suppress
4216 writing any insns or setting DECL_RTL of anything in this case. */
4218 void
4219 assign_parms (fndecl, second_time)
4220 tree fndecl;
4221 int second_time;
4223 register tree parm;
4224 register rtx entry_parm = 0;
4225 register rtx stack_parm = 0;
4226 CUMULATIVE_ARGS args_so_far;
4227 enum machine_mode promoted_mode, passed_mode;
4228 enum machine_mode nominal_mode, promoted_nominal_mode;
4229 int unsignedp;
4230 /* Total space needed so far for args on the stack,
4231 given as a constant and a tree-expression. */
4232 struct args_size stack_args_size;
4233 tree fntype = TREE_TYPE (fndecl);
4234 tree fnargs = DECL_ARGUMENTS (fndecl);
4235 /* This is used for the arg pointer when referring to stack args. */
4236 rtx internal_arg_pointer;
4237 /* This is a dummy PARM_DECL that we used for the function result if
4238 the function returns a structure. */
4239 tree function_result_decl = 0;
4240 #ifdef SETUP_INCOMING_VARARGS
4241 int varargs_setup = 0;
4242 #endif
4243 rtx conversion_insns = 0;
4245 /* Nonzero if the last arg is named `__builtin_va_alist',
4246 which is used on some machines for old-fashioned non-ANSI varargs.h;
4247 this should be stuck onto the stack as if it had arrived there. */
4248 int hide_last_arg
4249 = (current_function_varargs
4250 && fnargs
4251 && (parm = tree_last (fnargs)) != 0
4252 && DECL_NAME (parm)
4253 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
4254 "__builtin_va_alist")));
4256 /* Nonzero if function takes extra anonymous args.
4257 This means the last named arg must be on the stack
4258 right before the anonymous ones. */
4259 int stdarg
4260 = (TYPE_ARG_TYPES (fntype) != 0
4261 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4262 != void_type_node));
4264 current_function_stdarg = stdarg;
4266 /* If the reg that the virtual arg pointer will be translated into is
4267 not a fixed reg or is the stack pointer, make a copy of the virtual
4268 arg pointer, and address parms via the copy. The frame pointer is
4269 considered fixed even though it is not marked as such.
4271 The second time through, simply use ap to avoid generating rtx. */
4273 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4274 || ! (fixed_regs[ARG_POINTER_REGNUM]
4275 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
4276 && ! second_time)
4277 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4278 else
4279 internal_arg_pointer = virtual_incoming_args_rtx;
4280 current_function_internal_arg_pointer = internal_arg_pointer;
4282 stack_args_size.constant = 0;
4283 stack_args_size.var = 0;
4285 /* If struct value address is treated as the first argument, make it so. */
4286 if (aggregate_value_p (DECL_RESULT (fndecl))
4287 && ! current_function_returns_pcc_struct
4288 && struct_value_incoming_rtx == 0)
4290 tree type = build_pointer_type (TREE_TYPE (fntype));
4292 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4294 DECL_ARG_TYPE (function_result_decl) = type;
4295 TREE_CHAIN (function_result_decl) = fnargs;
4296 fnargs = function_result_decl;
4299 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4300 parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
4301 bzero ((char *) parm_reg_stack_loc, max_parm_reg * sizeof (rtx));
4303 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4304 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4305 #else
4306 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
4307 #endif
4309 /* We haven't yet found an argument that we must push and pretend the
4310 caller did. */
4311 current_function_pretend_args_size = 0;
4313 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4315 int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm));
4316 struct args_size stack_offset;
4317 struct args_size arg_size;
4318 int passed_pointer = 0;
4319 int did_conversion = 0;
4320 tree passed_type = DECL_ARG_TYPE (parm);
4321 tree nominal_type = TREE_TYPE (parm);
4322 int pretend_named;
4324 /* Set LAST_NAMED if this is last named arg before some
4325 anonymous args. */
4326 int last_named = ((TREE_CHAIN (parm) == 0
4327 || DECL_NAME (TREE_CHAIN (parm)) == 0)
4328 && (stdarg || current_function_varargs));
4329 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4330 most machines, if this is a varargs/stdarg function, then we treat
4331 the last named arg as if it were anonymous too. */
4332 int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4334 if (TREE_TYPE (parm) == error_mark_node
4335 /* This can happen after weird syntax errors
4336 or if an enum type is defined among the parms. */
4337 || TREE_CODE (parm) != PARM_DECL
4338 || passed_type == NULL)
4340 DECL_INCOMING_RTL (parm) = DECL_RTL (parm)
4341 = gen_rtx_MEM (BLKmode, const0_rtx);
4342 TREE_USED (parm) = 1;
4343 continue;
4346 /* For varargs.h function, save info about regs and stack space
4347 used by the individual args, not including the va_alist arg. */
4348 if (hide_last_arg && last_named)
4349 current_function_args_info = args_so_far;
4351 /* Find mode of arg as it is passed, and mode of arg
4352 as it should be during execution of this function. */
4353 passed_mode = TYPE_MODE (passed_type);
4354 nominal_mode = TYPE_MODE (nominal_type);
4356 /* If the parm's mode is VOID, its value doesn't matter,
4357 and avoid the usual things like emit_move_insn that could crash. */
4358 if (nominal_mode == VOIDmode)
4360 DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx;
4361 continue;
4364 /* If the parm is to be passed as a transparent union, use the
4365 type of the first field for the tests below. We have already
4366 verified that the modes are the same. */
4367 if (DECL_TRANSPARENT_UNION (parm)
4368 || TYPE_TRANSPARENT_UNION (passed_type))
4369 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4371 /* See if this arg was passed by invisible reference. It is if
4372 it is an object whose size depends on the contents of the
4373 object itself or if the machine requires these objects be passed
4374 that way. */
4376 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4377 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4378 || TREE_ADDRESSABLE (passed_type)
4379 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4380 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4381 passed_type, named_arg)
4382 #endif
4385 passed_type = nominal_type = build_pointer_type (passed_type);
4386 passed_pointer = 1;
4387 passed_mode = nominal_mode = Pmode;
4390 promoted_mode = passed_mode;
4392 #ifdef PROMOTE_FUNCTION_ARGS
4393 /* Compute the mode in which the arg is actually extended to. */
4394 unsignedp = TREE_UNSIGNED (passed_type);
4395 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4396 #endif
4398 /* Let machine desc say which reg (if any) the parm arrives in.
4399 0 means it arrives on the stack. */
4400 #ifdef FUNCTION_INCOMING_ARG
4401 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4402 passed_type, named_arg);
4403 #else
4404 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4405 passed_type, named_arg);
4406 #endif
4408 if (entry_parm == 0)
4409 promoted_mode = passed_mode;
4411 #ifdef SETUP_INCOMING_VARARGS
4412 /* If this is the last named parameter, do any required setup for
4413 varargs or stdargs. We need to know about the case of this being an
4414 addressable type, in which case we skip the registers it
4415 would have arrived in.
4417 For stdargs, LAST_NAMED will be set for two parameters, the one that
4418 is actually the last named, and the dummy parameter. We only
4419 want to do this action once.
4421 Also, indicate when RTL generation is to be suppressed. */
4422 if (last_named && !varargs_setup)
4424 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4425 current_function_pretend_args_size,
4426 second_time);
4427 varargs_setup = 1;
4429 #endif
4431 /* Determine parm's home in the stack,
4432 in case it arrives in the stack or we should pretend it did.
4434 Compute the stack position and rtx where the argument arrives
4435 and its size.
4437 There is one complexity here: If this was a parameter that would
4438 have been passed in registers, but wasn't only because it is
4439 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4440 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4441 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4442 0 as it was the previous time. */
4444 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4445 locate_and_pad_parm (promoted_mode, passed_type,
4446 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4448 #else
4449 #ifdef FUNCTION_INCOMING_ARG
4450 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4451 passed_type,
4452 pretend_named) != 0,
4453 #else
4454 FUNCTION_ARG (args_so_far, promoted_mode,
4455 passed_type,
4456 pretend_named) != 0,
4457 #endif
4458 #endif
4459 fndecl, &stack_args_size, &stack_offset, &arg_size);
4461 if (! second_time)
4463 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4465 if (offset_rtx == const0_rtx)
4466 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4467 else
4468 stack_parm = gen_rtx_MEM (promoted_mode,
4469 gen_rtx_PLUS (Pmode,
4470 internal_arg_pointer,
4471 offset_rtx));
4473 /* If this is a memory ref that contains aggregate components,
4474 mark it as such for cse and loop optimize. Likewise if it
4475 is readonly. */
4476 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4477 RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm);
4478 MEM_ALIAS_SET (stack_parm) = get_alias_set (parm);
4481 /* If this parameter was passed both in registers and in the stack,
4482 use the copy on the stack. */
4483 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4484 entry_parm = 0;
4486 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4487 /* If this parm was passed part in regs and part in memory,
4488 pretend it arrived entirely in memory
4489 by pushing the register-part onto the stack.
4491 In the special case of a DImode or DFmode that is split,
4492 we could put it together in a pseudoreg directly,
4493 but for now that's not worth bothering with. */
4495 if (entry_parm)
4497 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4498 passed_type, named_arg);
4500 if (nregs > 0)
4502 current_function_pretend_args_size
4503 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4504 / (PARM_BOUNDARY / BITS_PER_UNIT)
4505 * (PARM_BOUNDARY / BITS_PER_UNIT));
4507 if (! second_time)
4509 /* Handle calls that pass values in multiple non-contiguous
4510 locations. The Irix 6 ABI has examples of this. */
4511 if (GET_CODE (entry_parm) == PARALLEL)
4512 emit_group_store (validize_mem (stack_parm), entry_parm,
4513 int_size_in_bytes (TREE_TYPE (parm)),
4514 (TYPE_ALIGN (TREE_TYPE (parm))
4515 / BITS_PER_UNIT));
4516 else
4517 move_block_from_reg (REGNO (entry_parm),
4518 validize_mem (stack_parm), nregs,
4519 int_size_in_bytes (TREE_TYPE (parm)));
4521 entry_parm = stack_parm;
4524 #endif
4526 /* If we didn't decide this parm came in a register,
4527 by default it came on the stack. */
4528 if (entry_parm == 0)
4529 entry_parm = stack_parm;
4531 /* Record permanently how this parm was passed. */
4532 if (! second_time)
4533 DECL_INCOMING_RTL (parm) = entry_parm;
4535 /* If there is actually space on the stack for this parm,
4536 count it in stack_args_size; otherwise set stack_parm to 0
4537 to indicate there is no preallocated stack slot for the parm. */
4539 if (entry_parm == stack_parm
4540 || (GET_CODE (entry_parm) == PARALLEL
4541 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4542 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4543 /* On some machines, even if a parm value arrives in a register
4544 there is still an (uninitialized) stack slot allocated for it.
4546 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4547 whether this parameter already has a stack slot allocated,
4548 because an arg block exists only if current_function_args_size
4549 is larger than some threshold, and we haven't calculated that
4550 yet. So, for now, we just assume that stack slots never exist
4551 in this case. */
4552 || REG_PARM_STACK_SPACE (fndecl) > 0
4553 #endif
4556 stack_args_size.constant += arg_size.constant;
4557 if (arg_size.var)
4558 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4560 else
4561 /* No stack slot was pushed for this parm. */
4562 stack_parm = 0;
4564 /* Update info on where next arg arrives in registers. */
4566 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4567 passed_type, named_arg);
4569 /* If this is our second time through, we are done with this parm. */
4570 if (second_time)
4571 continue;
4573 /* If we can't trust the parm stack slot to be aligned enough
4574 for its ultimate type, don't use that slot after entry.
4575 We'll make another stack slot, if we need one. */
4577 int thisparm_boundary
4578 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4580 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4581 stack_parm = 0;
4584 /* If parm was passed in memory, and we need to convert it on entry,
4585 don't store it back in that same slot. */
4586 if (entry_parm != 0
4587 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4588 stack_parm = 0;
4590 #if 0
4591 /* Now adjust STACK_PARM to the mode and precise location
4592 where this parameter should live during execution,
4593 if we discover that it must live in the stack during execution.
4594 To make debuggers happier on big-endian machines, we store
4595 the value in the last bytes of the space available. */
4597 if (nominal_mode != BLKmode && nominal_mode != passed_mode
4598 && stack_parm != 0)
4600 rtx offset_rtx;
4602 if (BYTES_BIG_ENDIAN
4603 && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
4604 stack_offset.constant += (GET_MODE_SIZE (passed_mode)
4605 - GET_MODE_SIZE (nominal_mode));
4607 offset_rtx = ARGS_SIZE_RTX (stack_offset);
4608 if (offset_rtx == const0_rtx)
4609 stack_parm = gen_rtx_MEM (nominal_mode, internal_arg_pointer);
4610 else
4611 stack_parm = gen_rtx_MEM (nominal_mode,
4612 gen_rtx_PLUS (Pmode,
4613 internal_arg_pointer,
4614 offset_rtx));
4616 /* If this is a memory ref that contains aggregate components,
4617 mark it as such for cse and loop optimize. */
4618 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4620 #endif /* 0 */
4622 #ifdef STACK_REGS
4623 /* We need this "use" info, because the gcc-register->stack-register
4624 converter in reg-stack.c needs to know which registers are active
4625 at the start of the function call. The actual parameter loading
4626 instructions are not always available then anymore, since they might
4627 have been optimised away. */
4629 if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named))
4630 emit_insn (gen_rtx_USE (GET_MODE (entry_parm), entry_parm));
4631 #endif
4633 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4634 in the mode in which it arrives.
4635 STACK_PARM is an RTX for a stack slot where the parameter can live
4636 during the function (in case we want to put it there).
4637 STACK_PARM is 0 if no stack slot was pushed for it.
4639 Now output code if necessary to convert ENTRY_PARM to
4640 the type in which this function declares it,
4641 and store that result in an appropriate place,
4642 which may be a pseudo reg, may be STACK_PARM,
4643 or may be a local stack slot if STACK_PARM is 0.
4645 Set DECL_RTL to that place. */
4647 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4649 /* If a BLKmode arrives in registers, copy it to a stack slot.
4650 Handle calls that pass values in multiple non-contiguous
4651 locations. The Irix 6 ABI has examples of this. */
4652 if (GET_CODE (entry_parm) == REG
4653 || GET_CODE (entry_parm) == PARALLEL)
4655 int size_stored
4656 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4657 UNITS_PER_WORD);
4659 /* Note that we will be storing an integral number of words.
4660 So we have to be careful to ensure that we allocate an
4661 integral number of words. We do this below in the
4662 assign_stack_local if space was not allocated in the argument
4663 list. If it was, this will not work if PARM_BOUNDARY is not
4664 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4665 if it becomes a problem. */
4667 if (stack_parm == 0)
4669 stack_parm
4670 = assign_stack_local (GET_MODE (entry_parm),
4671 size_stored, 0);
4673 /* If this is a memory ref that contains aggregate
4674 components, mark it as such for cse and loop optimize. */
4675 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4678 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4679 abort ();
4681 if (TREE_READONLY (parm))
4682 RTX_UNCHANGING_P (stack_parm) = 1;
4684 /* Handle calls that pass values in multiple non-contiguous
4685 locations. The Irix 6 ABI has examples of this. */
4686 if (GET_CODE (entry_parm) == PARALLEL)
4687 emit_group_store (validize_mem (stack_parm), entry_parm,
4688 int_size_in_bytes (TREE_TYPE (parm)),
4689 (TYPE_ALIGN (TREE_TYPE (parm))
4690 / BITS_PER_UNIT));
4691 else
4692 move_block_from_reg (REGNO (entry_parm),
4693 validize_mem (stack_parm),
4694 size_stored / UNITS_PER_WORD,
4695 int_size_in_bytes (TREE_TYPE (parm)));
4697 DECL_RTL (parm) = stack_parm;
4699 else if (! ((obey_regdecls && ! DECL_REGISTER (parm)
4700 && ! DECL_INLINE (fndecl))
4701 /* layout_decl may set this. */
4702 || TREE_ADDRESSABLE (parm)
4703 || TREE_SIDE_EFFECTS (parm)
4704 /* If -ffloat-store specified, don't put explicit
4705 float variables into registers. */
4706 || (flag_float_store
4707 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4708 /* Always assign pseudo to structure return or item passed
4709 by invisible reference. */
4710 || passed_pointer || parm == function_result_decl)
4712 /* Store the parm in a pseudoregister during the function, but we
4713 may need to do it in a wider mode. */
4715 register rtx parmreg;
4716 int regno, regnoi = 0, regnor = 0;
4718 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4720 promoted_nominal_mode
4721 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4723 parmreg = gen_reg_rtx (promoted_nominal_mode);
4724 mark_user_reg (parmreg);
4726 /* If this was an item that we received a pointer to, set DECL_RTL
4727 appropriately. */
4728 if (passed_pointer)
4730 DECL_RTL (parm)
4731 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
4732 MEM_SET_IN_STRUCT_P (DECL_RTL (parm), aggregate);
4734 else
4735 DECL_RTL (parm) = parmreg;
4737 /* Copy the value into the register. */
4738 if (nominal_mode != passed_mode
4739 || promoted_nominal_mode != promoted_mode)
4741 int save_tree_used;
4742 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4743 mode, by the caller. We now have to convert it to
4744 NOMINAL_MODE, if different. However, PARMREG may be in
4745 a different mode than NOMINAL_MODE if it is being stored
4746 promoted.
4748 If ENTRY_PARM is a hard register, it might be in a register
4749 not valid for operating in its mode (e.g., an odd-numbered
4750 register for a DFmode). In that case, moves are the only
4751 thing valid, so we can't do a convert from there. This
4752 occurs when the calling sequence allow such misaligned
4753 usages.
4755 In addition, the conversion may involve a call, which could
4756 clobber parameters which haven't been copied to pseudo
4757 registers yet. Therefore, we must first copy the parm to
4758 a pseudo reg here, and save the conversion until after all
4759 parameters have been moved. */
4761 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4763 emit_move_insn (tempreg, validize_mem (entry_parm));
4765 push_to_sequence (conversion_insns);
4766 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4768 /* TREE_USED gets set erroneously during expand_assignment. */
4769 save_tree_used = TREE_USED (parm);
4770 expand_assignment (parm,
4771 make_tree (nominal_type, tempreg), 0, 0);
4772 TREE_USED (parm) = save_tree_used;
4773 conversion_insns = get_insns ();
4774 did_conversion = 1;
4775 end_sequence ();
4777 else
4778 emit_move_insn (parmreg, validize_mem (entry_parm));
4780 /* If we were passed a pointer but the actual value
4781 can safely live in a register, put it in one. */
4782 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4783 && ! ((obey_regdecls && ! DECL_REGISTER (parm)
4784 && ! DECL_INLINE (fndecl))
4785 /* layout_decl may set this. */
4786 || TREE_ADDRESSABLE (parm)
4787 || TREE_SIDE_EFFECTS (parm)
4788 /* If -ffloat-store specified, don't put explicit
4789 float variables into registers. */
4790 || (flag_float_store
4791 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
4793 /* We can't use nominal_mode, because it will have been set to
4794 Pmode above. We must use the actual mode of the parm. */
4795 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4796 mark_user_reg (parmreg);
4797 emit_move_insn (parmreg, DECL_RTL (parm));
4798 DECL_RTL (parm) = parmreg;
4799 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4800 now the parm. */
4801 stack_parm = 0;
4803 #ifdef FUNCTION_ARG_CALLEE_COPIES
4804 /* If we are passed an arg by reference and it is our responsibility
4805 to make a copy, do it now.
4806 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4807 original argument, so we must recreate them in the call to
4808 FUNCTION_ARG_CALLEE_COPIES. */
4809 /* ??? Later add code to handle the case that if the argument isn't
4810 modified, don't do the copy. */
4812 else if (passed_pointer
4813 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4814 TYPE_MODE (DECL_ARG_TYPE (parm)),
4815 DECL_ARG_TYPE (parm),
4816 named_arg)
4817 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4819 rtx copy;
4820 tree type = DECL_ARG_TYPE (parm);
4822 /* This sequence may involve a library call perhaps clobbering
4823 registers that haven't been copied to pseudos yet. */
4825 push_to_sequence (conversion_insns);
4827 if (TYPE_SIZE (type) == 0
4828 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4829 /* This is a variable sized object. */
4830 copy = gen_rtx_MEM (BLKmode,
4831 allocate_dynamic_stack_space
4832 (expr_size (parm), NULL_RTX,
4833 TYPE_ALIGN (type)));
4834 else
4835 copy = assign_stack_temp (TYPE_MODE (type),
4836 int_size_in_bytes (type), 1);
4837 MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type));
4838 RTX_UNCHANGING_P (copy) = TREE_READONLY (parm);
4840 store_expr (parm, copy, 0);
4841 emit_move_insn (parmreg, XEXP (copy, 0));
4842 if (current_function_check_memory_usage)
4843 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
4844 XEXP (copy, 0), Pmode,
4845 GEN_INT (int_size_in_bytes (type)),
4846 TYPE_MODE (sizetype),
4847 GEN_INT (MEMORY_USE_RW),
4848 TYPE_MODE (integer_type_node));
4849 conversion_insns = get_insns ();
4850 did_conversion = 1;
4851 end_sequence ();
4853 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4855 /* In any case, record the parm's desired stack location
4856 in case we later discover it must live in the stack.
4858 If it is a COMPLEX value, store the stack location for both
4859 halves. */
4861 if (GET_CODE (parmreg) == CONCAT)
4862 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4863 else
4864 regno = REGNO (parmreg);
4866 if (regno >= max_parm_reg)
4868 rtx *new;
4869 int old_max_parm_reg = max_parm_reg;
4871 /* It's slow to expand this one register at a time,
4872 but it's also rare and we need max_parm_reg to be
4873 precisely correct. */
4874 max_parm_reg = regno + 1;
4875 new = (rtx *) savealloc (max_parm_reg * sizeof (rtx));
4876 bcopy ((char *) parm_reg_stack_loc, (char *) new,
4877 old_max_parm_reg * sizeof (rtx));
4878 bzero ((char *) (new + old_max_parm_reg),
4879 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4880 parm_reg_stack_loc = new;
4883 if (GET_CODE (parmreg) == CONCAT)
4885 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4887 regnor = REGNO (gen_realpart (submode, parmreg));
4888 regnoi = REGNO (gen_imagpart (submode, parmreg));
4890 if (stack_parm != 0)
4892 parm_reg_stack_loc[regnor]
4893 = gen_realpart (submode, stack_parm);
4894 parm_reg_stack_loc[regnoi]
4895 = gen_imagpart (submode, stack_parm);
4897 else
4899 parm_reg_stack_loc[regnor] = 0;
4900 parm_reg_stack_loc[regnoi] = 0;
4903 else
4904 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4906 /* Mark the register as eliminable if we did no conversion
4907 and it was copied from memory at a fixed offset,
4908 and the arg pointer was not copied to a pseudo-reg.
4909 If the arg pointer is a pseudo reg or the offset formed
4910 an invalid address, such memory-equivalences
4911 as we make here would screw up life analysis for it. */
4912 if (nominal_mode == passed_mode
4913 && ! did_conversion
4914 && stack_parm != 0
4915 && GET_CODE (stack_parm) == MEM
4916 && stack_offset.var == 0
4917 && reg_mentioned_p (virtual_incoming_args_rtx,
4918 XEXP (stack_parm, 0)))
4920 rtx linsn = get_last_insn ();
4921 rtx sinsn, set;
4923 /* Mark complex types separately. */
4924 if (GET_CODE (parmreg) == CONCAT)
4925 /* Scan backwards for the set of the real and
4926 imaginary parts. */
4927 for (sinsn = linsn; sinsn != 0;
4928 sinsn = prev_nonnote_insn (sinsn))
4930 set = single_set (sinsn);
4931 if (set != 0
4932 && SET_DEST (set) == regno_reg_rtx [regnoi])
4933 REG_NOTES (sinsn)
4934 = gen_rtx_EXPR_LIST (REG_EQUIV,
4935 parm_reg_stack_loc[regnoi],
4936 REG_NOTES (sinsn));
4937 else if (set != 0
4938 && SET_DEST (set) == regno_reg_rtx [regnor])
4939 REG_NOTES (sinsn)
4940 = gen_rtx_EXPR_LIST (REG_EQUIV,
4941 parm_reg_stack_loc[regnor],
4942 REG_NOTES (sinsn));
4944 else if ((set = single_set (linsn)) != 0
4945 && SET_DEST (set) == parmreg)
4946 REG_NOTES (linsn)
4947 = gen_rtx_EXPR_LIST (REG_EQUIV,
4948 stack_parm, REG_NOTES (linsn));
4951 /* For pointer data type, suggest pointer register. */
4952 if (POINTER_TYPE_P (TREE_TYPE (parm)))
4953 mark_reg_pointer (parmreg,
4954 (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))
4955 / BITS_PER_UNIT));
4957 else
4959 /* Value must be stored in the stack slot STACK_PARM
4960 during function execution. */
4962 if (promoted_mode != nominal_mode)
4964 /* Conversion is required. */
4965 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4967 emit_move_insn (tempreg, validize_mem (entry_parm));
4969 push_to_sequence (conversion_insns);
4970 entry_parm = convert_to_mode (nominal_mode, tempreg,
4971 TREE_UNSIGNED (TREE_TYPE (parm)));
4972 if (stack_parm)
4974 /* ??? This may need a big-endian conversion on sparc64. */
4975 stack_parm = change_address (stack_parm, nominal_mode,
4976 NULL_RTX);
4978 conversion_insns = get_insns ();
4979 did_conversion = 1;
4980 end_sequence ();
4983 if (entry_parm != stack_parm)
4985 if (stack_parm == 0)
4987 stack_parm
4988 = assign_stack_local (GET_MODE (entry_parm),
4989 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
4990 /* If this is a memory ref that contains aggregate components,
4991 mark it as such for cse and loop optimize. */
4992 MEM_SET_IN_STRUCT_P (stack_parm, aggregate);
4995 if (promoted_mode != nominal_mode)
4997 push_to_sequence (conversion_insns);
4998 emit_move_insn (validize_mem (stack_parm),
4999 validize_mem (entry_parm));
5000 conversion_insns = get_insns ();
5001 end_sequence ();
5003 else
5004 emit_move_insn (validize_mem (stack_parm),
5005 validize_mem (entry_parm));
5007 if (current_function_check_memory_usage)
5009 push_to_sequence (conversion_insns);
5010 emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3,
5011 XEXP (stack_parm, 0), Pmode,
5012 GEN_INT (GET_MODE_SIZE (GET_MODE
5013 (entry_parm))),
5014 TYPE_MODE (sizetype),
5015 GEN_INT (MEMORY_USE_RW),
5016 TYPE_MODE (integer_type_node));
5018 conversion_insns = get_insns ();
5019 end_sequence ();
5021 DECL_RTL (parm) = stack_parm;
5024 /* If this "parameter" was the place where we are receiving the
5025 function's incoming structure pointer, set up the result. */
5026 if (parm == function_result_decl)
5028 tree result = DECL_RESULT (fndecl);
5029 tree restype = TREE_TYPE (result);
5031 DECL_RTL (result)
5032 = gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm));
5034 MEM_SET_IN_STRUCT_P (DECL_RTL (result),
5035 AGGREGATE_TYPE_P (restype));
5038 if (TREE_THIS_VOLATILE (parm))
5039 MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
5040 if (TREE_READONLY (parm))
5041 RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
5044 /* Output all parameter conversion instructions (possibly including calls)
5045 now that all parameters have been copied out of hard registers. */
5046 emit_insns (conversion_insns);
5048 last_parm_insn = get_last_insn ();
5050 current_function_args_size = stack_args_size.constant;
5052 /* Adjust function incoming argument size for alignment and
5053 minimum length. */
5055 #ifdef REG_PARM_STACK_SPACE
5056 #ifndef MAYBE_REG_PARM_STACK_SPACE
5057 current_function_args_size = MAX (current_function_args_size,
5058 REG_PARM_STACK_SPACE (fndecl));
5059 #endif
5060 #endif
5062 #ifdef STACK_BOUNDARY
5063 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5065 current_function_args_size
5066 = ((current_function_args_size + STACK_BYTES - 1)
5067 / STACK_BYTES) * STACK_BYTES;
5068 #endif
5070 #ifdef ARGS_GROW_DOWNWARD
5071 current_function_arg_offset_rtx
5072 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5073 : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var,
5074 size_int (-stack_args_size.constant)),
5075 NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD));
5076 #else
5077 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5078 #endif
5080 /* See how many bytes, if any, of its args a function should try to pop
5081 on return. */
5083 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5084 current_function_args_size);
5086 /* For stdarg.h function, save info about
5087 regs and stack space used by the named args. */
5089 if (!hide_last_arg)
5090 current_function_args_info = args_so_far;
5092 /* Set the rtx used for the function return value. Put this in its
5093 own variable so any optimizers that need this information don't have
5094 to include tree.h. Do this here so it gets done when an inlined
5095 function gets output. */
5097 current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl));
5100 /* Indicate whether REGNO is an incoming argument to the current function
5101 that was promoted to a wider mode. If so, return the RTX for the
5102 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5103 that REGNO is promoted from and whether the promotion was signed or
5104 unsigned. */
5106 #ifdef PROMOTE_FUNCTION_ARGS
5109 promoted_input_arg (regno, pmode, punsignedp)
5110 int regno;
5111 enum machine_mode *pmode;
5112 int *punsignedp;
5114 tree arg;
5116 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5117 arg = TREE_CHAIN (arg))
5118 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5119 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5120 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5122 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5123 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5125 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5126 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5127 && mode != DECL_MODE (arg))
5129 *pmode = DECL_MODE (arg);
5130 *punsignedp = unsignedp;
5131 return DECL_INCOMING_RTL (arg);
5135 return 0;
5138 #endif
5140 /* Compute the size and offset from the start of the stacked arguments for a
5141 parm passed in mode PASSED_MODE and with type TYPE.
5143 INITIAL_OFFSET_PTR points to the current offset into the stacked
5144 arguments.
5146 The starting offset and size for this parm are returned in *OFFSET_PTR
5147 and *ARG_SIZE_PTR, respectively.
5149 IN_REGS is non-zero if the argument will be passed in registers. It will
5150 never be set if REG_PARM_STACK_SPACE is not defined.
5152 FNDECL is the function in which the argument was defined.
5154 There are two types of rounding that are done. The first, controlled by
5155 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5156 list to be aligned to the specific boundary (in bits). This rounding
5157 affects the initial and starting offsets, but not the argument size.
5159 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5160 optionally rounds the size of the parm to PARM_BOUNDARY. The
5161 initial offset is not affected by this rounding, while the size always
5162 is and the starting offset may be. */
5164 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5165 initial_offset_ptr is positive because locate_and_pad_parm's
5166 callers pass in the total size of args so far as
5167 initial_offset_ptr. arg_size_ptr is always positive.*/
5169 void
5170 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5171 initial_offset_ptr, offset_ptr, arg_size_ptr)
5172 enum machine_mode passed_mode;
5173 tree type;
5174 int in_regs;
5175 tree fndecl ATTRIBUTE_UNUSED;
5176 struct args_size *initial_offset_ptr;
5177 struct args_size *offset_ptr;
5178 struct args_size *arg_size_ptr;
5180 tree sizetree
5181 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5182 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5183 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5185 #ifdef REG_PARM_STACK_SPACE
5186 /* If we have found a stack parm before we reach the end of the
5187 area reserved for registers, skip that area. */
5188 if (! in_regs)
5190 int reg_parm_stack_space = 0;
5192 #ifdef MAYBE_REG_PARM_STACK_SPACE
5193 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5194 #else
5195 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5196 #endif
5197 if (reg_parm_stack_space > 0)
5199 if (initial_offset_ptr->var)
5201 initial_offset_ptr->var
5202 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5203 size_int (reg_parm_stack_space));
5204 initial_offset_ptr->constant = 0;
5206 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5207 initial_offset_ptr->constant = reg_parm_stack_space;
5210 #endif /* REG_PARM_STACK_SPACE */
5212 arg_size_ptr->var = 0;
5213 arg_size_ptr->constant = 0;
5215 #ifdef ARGS_GROW_DOWNWARD
5216 if (initial_offset_ptr->var)
5218 offset_ptr->constant = 0;
5219 offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node,
5220 initial_offset_ptr->var);
5222 else
5224 offset_ptr->constant = - initial_offset_ptr->constant;
5225 offset_ptr->var = 0;
5227 if (where_pad != none
5228 && (TREE_CODE (sizetree) != INTEGER_CST
5229 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
5230 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5231 SUB_PARM_SIZE (*offset_ptr, sizetree);
5232 if (where_pad != downward)
5233 pad_to_arg_alignment (offset_ptr, boundary);
5234 if (initial_offset_ptr->var)
5236 arg_size_ptr->var = size_binop (MINUS_EXPR,
5237 size_binop (MINUS_EXPR,
5238 integer_zero_node,
5239 initial_offset_ptr->var),
5240 offset_ptr->var);
5242 else
5244 arg_size_ptr->constant = (- initial_offset_ptr->constant
5245 - offset_ptr->constant);
5247 #else /* !ARGS_GROW_DOWNWARD */
5248 pad_to_arg_alignment (initial_offset_ptr, boundary);
5249 *offset_ptr = *initial_offset_ptr;
5251 #ifdef PUSH_ROUNDING
5252 if (passed_mode != BLKmode)
5253 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5254 #endif
5256 /* Pad_below needs the pre-rounded size to know how much to pad below
5257 so this must be done before rounding up. */
5258 if (where_pad == downward
5259 /* However, BLKmode args passed in regs have their padding done elsewhere.
5260 The stack slot must be able to hold the entire register. */
5261 && !(in_regs && passed_mode == BLKmode))
5262 pad_below (offset_ptr, passed_mode, sizetree);
5264 if (where_pad != none
5265 && (TREE_CODE (sizetree) != INTEGER_CST
5266 || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
5267 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5269 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5270 #endif /* ARGS_GROW_DOWNWARD */
5273 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5274 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5276 static void
5277 pad_to_arg_alignment (offset_ptr, boundary)
5278 struct args_size *offset_ptr;
5279 int boundary;
5281 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5283 if (boundary > BITS_PER_UNIT)
5285 if (offset_ptr->var)
5287 offset_ptr->var =
5288 #ifdef ARGS_GROW_DOWNWARD
5289 round_down
5290 #else
5291 round_up
5292 #endif
5293 (ARGS_SIZE_TREE (*offset_ptr),
5294 boundary / BITS_PER_UNIT);
5295 offset_ptr->constant = 0; /*?*/
5297 else
5298 offset_ptr->constant =
5299 #ifdef ARGS_GROW_DOWNWARD
5300 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5301 #else
5302 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5303 #endif
5307 #ifndef ARGS_GROW_DOWNWARD
5308 static void
5309 pad_below (offset_ptr, passed_mode, sizetree)
5310 struct args_size *offset_ptr;
5311 enum machine_mode passed_mode;
5312 tree sizetree;
5314 if (passed_mode != BLKmode)
5316 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5317 offset_ptr->constant
5318 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5319 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5320 - GET_MODE_SIZE (passed_mode));
5322 else
5324 if (TREE_CODE (sizetree) != INTEGER_CST
5325 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5327 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5328 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5329 /* Add it in. */
5330 ADD_PARM_SIZE (*offset_ptr, s2);
5331 SUB_PARM_SIZE (*offset_ptr, sizetree);
5335 #endif
5337 #ifdef ARGS_GROW_DOWNWARD
5338 static tree
5339 round_down (value, divisor)
5340 tree value;
5341 int divisor;
5343 return size_binop (MULT_EXPR,
5344 size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)),
5345 size_int (divisor));
5347 #endif
5349 /* Walk the tree of blocks describing the binding levels within a function
5350 and warn about uninitialized variables.
5351 This is done after calling flow_analysis and before global_alloc
5352 clobbers the pseudo-regs to hard regs. */
5354 void
5355 uninitialized_vars_warning (block)
5356 tree block;
5358 register tree decl, sub;
5359 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5361 if (TREE_CODE (decl) == VAR_DECL
5362 /* These warnings are unreliable for and aggregates
5363 because assigning the fields one by one can fail to convince
5364 flow.c that the entire aggregate was initialized.
5365 Unions are troublesome because members may be shorter. */
5366 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5367 && DECL_RTL (decl) != 0
5368 && GET_CODE (DECL_RTL (decl)) == REG
5369 /* Global optimizations can make it difficult to determine if a
5370 particular variable has been initialized. However, a VAR_DECL
5371 with a nonzero DECL_INITIAL had an initializer, so do not
5372 claim it is potentially uninitialized.
5374 We do not care about the actual value in DECL_INITIAL, so we do
5375 not worry that it may be a dangling pointer. */
5376 && DECL_INITIAL (decl) == NULL_TREE
5377 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5378 warning_with_decl (decl,
5379 "`%s' might be used uninitialized in this function");
5380 if (TREE_CODE (decl) == VAR_DECL
5381 && DECL_RTL (decl) != 0
5382 && GET_CODE (DECL_RTL (decl)) == REG
5383 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5384 warning_with_decl (decl,
5385 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5387 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5388 uninitialized_vars_warning (sub);
5391 /* Do the appropriate part of uninitialized_vars_warning
5392 but for arguments instead of local variables. */
5394 void
5395 setjmp_args_warning ()
5397 register tree decl;
5398 for (decl = DECL_ARGUMENTS (current_function_decl);
5399 decl; decl = TREE_CHAIN (decl))
5400 if (DECL_RTL (decl) != 0
5401 && GET_CODE (DECL_RTL (decl)) == REG
5402 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5403 warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'");
5406 /* If this function call setjmp, put all vars into the stack
5407 unless they were declared `register'. */
5409 void
5410 setjmp_protect (block)
5411 tree block;
5413 register tree decl, sub;
5414 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5415 if ((TREE_CODE (decl) == VAR_DECL
5416 || TREE_CODE (decl) == PARM_DECL)
5417 && DECL_RTL (decl) != 0
5418 && (GET_CODE (DECL_RTL (decl)) == REG
5419 || (GET_CODE (DECL_RTL (decl)) == MEM
5420 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5421 /* If this variable came from an inline function, it must be
5422 that its life doesn't overlap the setjmp. If there was a
5423 setjmp in the function, it would already be in memory. We
5424 must exclude such variable because their DECL_RTL might be
5425 set to strange things such as virtual_stack_vars_rtx. */
5426 && ! DECL_FROM_INLINE (decl)
5427 && (
5428 #ifdef NON_SAVING_SETJMP
5429 /* If longjmp doesn't restore the registers,
5430 don't put anything in them. */
5431 NON_SAVING_SETJMP
5433 #endif
5434 ! DECL_REGISTER (decl)))
5435 put_var_into_stack (decl);
5436 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5437 setjmp_protect (sub);
5440 /* Like the previous function, but for args instead of local variables. */
5442 void
5443 setjmp_protect_args ()
5445 register tree decl;
5446 for (decl = DECL_ARGUMENTS (current_function_decl);
5447 decl; decl = TREE_CHAIN (decl))
5448 if ((TREE_CODE (decl) == VAR_DECL
5449 || TREE_CODE (decl) == PARM_DECL)
5450 && DECL_RTL (decl) != 0
5451 && (GET_CODE (DECL_RTL (decl)) == REG
5452 || (GET_CODE (DECL_RTL (decl)) == MEM
5453 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5454 && (
5455 /* If longjmp doesn't restore the registers,
5456 don't put anything in them. */
5457 #ifdef NON_SAVING_SETJMP
5458 NON_SAVING_SETJMP
5460 #endif
5461 ! DECL_REGISTER (decl)))
5462 put_var_into_stack (decl);
5465 /* Return the context-pointer register corresponding to DECL,
5466 or 0 if it does not need one. */
5469 lookup_static_chain (decl)
5470 tree decl;
5472 tree context = decl_function_context (decl);
5473 tree link;
5475 if (context == 0
5476 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5477 return 0;
5479 /* We treat inline_function_decl as an alias for the current function
5480 because that is the inline function whose vars, types, etc.
5481 are being merged into the current function.
5482 See expand_inline_function. */
5483 if (context == current_function_decl || context == inline_function_decl)
5484 return virtual_stack_vars_rtx;
5486 for (link = context_display; link; link = TREE_CHAIN (link))
5487 if (TREE_PURPOSE (link) == context)
5488 return RTL_EXPR_RTL (TREE_VALUE (link));
5490 abort ();
5493 /* Convert a stack slot address ADDR for variable VAR
5494 (from a containing function)
5495 into an address valid in this function (using a static chain). */
5498 fix_lexical_addr (addr, var)
5499 rtx addr;
5500 tree var;
5502 rtx basereg;
5503 HOST_WIDE_INT displacement;
5504 tree context = decl_function_context (var);
5505 struct function *fp;
5506 rtx base = 0;
5508 /* If this is the present function, we need not do anything. */
5509 if (context == current_function_decl || context == inline_function_decl)
5510 return addr;
5512 for (fp = outer_function_chain; fp; fp = fp->next)
5513 if (fp->decl == context)
5514 break;
5516 if (fp == 0)
5517 abort ();
5519 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5520 addr = XEXP (XEXP (addr, 0), 0);
5522 /* Decode given address as base reg plus displacement. */
5523 if (GET_CODE (addr) == REG)
5524 basereg = addr, displacement = 0;
5525 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5526 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5527 else
5528 abort ();
5530 /* We accept vars reached via the containing function's
5531 incoming arg pointer and via its stack variables pointer. */
5532 if (basereg == fp->internal_arg_pointer)
5534 /* If reached via arg pointer, get the arg pointer value
5535 out of that function's stack frame.
5537 There are two cases: If a separate ap is needed, allocate a
5538 slot in the outer function for it and dereference it that way.
5539 This is correct even if the real ap is actually a pseudo.
5540 Otherwise, just adjust the offset from the frame pointer to
5541 compensate. */
5543 #ifdef NEED_SEPARATE_AP
5544 rtx addr;
5546 if (fp->arg_pointer_save_area == 0)
5547 fp->arg_pointer_save_area
5548 = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
5550 addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var);
5551 addr = memory_address (Pmode, addr);
5553 base = copy_to_reg (gen_rtx_MEM (Pmode, addr));
5554 #else
5555 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5556 base = lookup_static_chain (var);
5557 #endif
5560 else if (basereg == virtual_stack_vars_rtx)
5562 /* This is the same code as lookup_static_chain, duplicated here to
5563 avoid an extra call to decl_function_context. */
5564 tree link;
5566 for (link = context_display; link; link = TREE_CHAIN (link))
5567 if (TREE_PURPOSE (link) == context)
5569 base = RTL_EXPR_RTL (TREE_VALUE (link));
5570 break;
5574 if (base == 0)
5575 abort ();
5577 /* Use same offset, relative to appropriate static chain or argument
5578 pointer. */
5579 return plus_constant (base, displacement);
5582 /* Return the address of the trampoline for entering nested fn FUNCTION.
5583 If necessary, allocate a trampoline (in the stack frame)
5584 and emit rtl to initialize its contents (at entry to this function). */
5587 trampoline_address (function)
5588 tree function;
5590 tree link;
5591 tree rtlexp;
5592 rtx tramp;
5593 struct function *fp;
5594 tree fn_context;
5596 /* Find an existing trampoline and return it. */
5597 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5598 if (TREE_PURPOSE (link) == function)
5599 return
5600 round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5602 for (fp = outer_function_chain; fp; fp = fp->next)
5603 for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
5604 if (TREE_PURPOSE (link) == function)
5606 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5607 function);
5608 return round_trampoline_addr (tramp);
5611 /* None exists; we must make one. */
5613 /* Find the `struct function' for the function containing FUNCTION. */
5614 fp = 0;
5615 fn_context = decl_function_context (function);
5616 if (fn_context != current_function_decl
5617 && fn_context != inline_function_decl)
5618 for (fp = outer_function_chain; fp; fp = fp->next)
5619 if (fp->decl == fn_context)
5620 break;
5622 /* Allocate run-time space for this trampoline
5623 (usually in the defining function's stack frame). */
5624 #ifdef ALLOCATE_TRAMPOLINE
5625 tramp = ALLOCATE_TRAMPOLINE (fp);
5626 #else
5627 /* If rounding needed, allocate extra space
5628 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5629 #ifdef TRAMPOLINE_ALIGNMENT
5630 #define TRAMPOLINE_REAL_SIZE \
5631 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5632 #else
5633 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5634 #endif
5635 if (fp != 0)
5636 tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
5637 else
5638 tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
5639 #endif
5641 /* Record the trampoline for reuse and note it for later initialization
5642 by expand_function_end. */
5643 if (fp != 0)
5645 push_obstacks (fp->function_maybepermanent_obstack,
5646 fp->function_maybepermanent_obstack);
5647 rtlexp = make_node (RTL_EXPR);
5648 RTL_EXPR_RTL (rtlexp) = tramp;
5649 fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
5650 pop_obstacks ();
5652 else
5654 /* Make the RTL_EXPR node temporary, not momentary, so that the
5655 trampoline_list doesn't become garbage. */
5656 int momentary = suspend_momentary ();
5657 rtlexp = make_node (RTL_EXPR);
5658 resume_momentary (momentary);
5660 RTL_EXPR_RTL (rtlexp) = tramp;
5661 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5664 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5665 return round_trampoline_addr (tramp);
5668 /* Given a trampoline address,
5669 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5671 static rtx
5672 round_trampoline_addr (tramp)
5673 rtx tramp;
5675 #ifdef TRAMPOLINE_ALIGNMENT
5676 /* Round address up to desired boundary. */
5677 rtx temp = gen_reg_rtx (Pmode);
5678 temp = expand_binop (Pmode, add_optab, tramp,
5679 GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1),
5680 temp, 0, OPTAB_LIB_WIDEN);
5681 tramp = expand_binop (Pmode, and_optab, temp,
5682 GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT),
5683 temp, 0, OPTAB_LIB_WIDEN);
5684 #endif
5685 return tramp;
5688 /* The functions identify_blocks and reorder_blocks provide a way to
5689 reorder the tree of BLOCK nodes, for optimizers that reshuffle or
5690 duplicate portions of the RTL code. Call identify_blocks before
5691 changing the RTL, and call reorder_blocks after. */
5693 /* Put all this function's BLOCK nodes including those that are chained
5694 onto the first block into a vector, and return it.
5695 Also store in each NOTE for the beginning or end of a block
5696 the index of that block in the vector.
5697 The arguments are BLOCK, the chain of top-level blocks of the function,
5698 and INSNS, the insn chain of the function. */
5700 tree *
5701 identify_blocks (block, insns)
5702 tree block;
5703 rtx insns;
5705 int n_blocks;
5706 tree *block_vector;
5707 int *block_stack;
5708 int depth = 0;
5709 int next_block_number = 1;
5710 int current_block_number = 1;
5711 rtx insn;
5713 if (block == 0)
5714 return 0;
5716 n_blocks = all_blocks (block, 0);
5717 block_vector = (tree *) xmalloc (n_blocks * sizeof (tree));
5718 block_stack = (int *) alloca (n_blocks * sizeof (int));
5720 all_blocks (block, block_vector);
5722 for (insn = insns; insn; insn = NEXT_INSN (insn))
5723 if (GET_CODE (insn) == NOTE)
5725 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5727 block_stack[depth++] = current_block_number;
5728 current_block_number = next_block_number;
5729 NOTE_BLOCK_NUMBER (insn) = next_block_number++;
5731 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5733 NOTE_BLOCK_NUMBER (insn) = current_block_number;
5734 current_block_number = block_stack[--depth];
5738 if (n_blocks != next_block_number)
5739 abort ();
5741 return block_vector;
5744 /* Given BLOCK_VECTOR which was returned by identify_blocks,
5745 and a revised instruction chain, rebuild the tree structure
5746 of BLOCK nodes to correspond to the new order of RTL.
5747 The new block tree is inserted below TOP_BLOCK.
5748 Returns the current top-level block. */
5750 tree
5751 reorder_blocks (block_vector, block, insns)
5752 tree *block_vector;
5753 tree block;
5754 rtx insns;
5756 tree current_block = block;
5757 rtx insn;
5759 if (block_vector == 0)
5760 return block;
5762 /* Prune the old trees away, so that it doesn't get in the way. */
5763 BLOCK_SUBBLOCKS (current_block) = 0;
5764 BLOCK_CHAIN (current_block) = 0;
5766 for (insn = insns; insn; insn = NEXT_INSN (insn))
5767 if (GET_CODE (insn) == NOTE)
5769 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5771 tree block = block_vector[NOTE_BLOCK_NUMBER (insn)];
5772 /* If we have seen this block before, copy it. */
5773 if (TREE_ASM_WRITTEN (block))
5774 block = copy_node (block);
5775 BLOCK_SUBBLOCKS (block) = 0;
5776 TREE_ASM_WRITTEN (block) = 1;
5777 BLOCK_SUPERCONTEXT (block) = current_block;
5778 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5779 BLOCK_SUBBLOCKS (current_block) = block;
5780 current_block = block;
5781 NOTE_SOURCE_FILE (insn) = 0;
5783 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5785 BLOCK_SUBBLOCKS (current_block)
5786 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5787 current_block = BLOCK_SUPERCONTEXT (current_block);
5788 NOTE_SOURCE_FILE (insn) = 0;
5792 BLOCK_SUBBLOCKS (current_block)
5793 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5794 return current_block;
5797 /* Reverse the order of elements in the chain T of blocks,
5798 and return the new head of the chain (old last element). */
5800 static tree
5801 blocks_nreverse (t)
5802 tree t;
5804 register tree prev = 0, decl, next;
5805 for (decl = t; decl; decl = next)
5807 next = BLOCK_CHAIN (decl);
5808 BLOCK_CHAIN (decl) = prev;
5809 prev = decl;
5811 return prev;
5814 /* Count the subblocks of the list starting with BLOCK, and list them
5815 all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all
5816 blocks. */
5818 static int
5819 all_blocks (block, vector)
5820 tree block;
5821 tree *vector;
5823 int n_blocks = 0;
5825 while (block)
5827 TREE_ASM_WRITTEN (block) = 0;
5829 /* Record this block. */
5830 if (vector)
5831 vector[n_blocks] = block;
5833 ++n_blocks;
5835 /* Record the subblocks, and their subblocks... */
5836 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
5837 vector ? vector + n_blocks : 0);
5838 block = BLOCK_CHAIN (block);
5841 return n_blocks;
5844 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
5845 and initialize static variables for generating RTL for the statements
5846 of the function. */
5848 void
5849 init_function_start (subr, filename, line)
5850 tree subr;
5851 char *filename;
5852 int line;
5854 init_stmt_for_function ();
5856 cse_not_expected = ! optimize;
5858 /* Caller save not needed yet. */
5859 caller_save_needed = 0;
5861 /* No stack slots have been made yet. */
5862 stack_slot_list = 0;
5864 /* There is no stack slot for handling nonlocal gotos. */
5865 nonlocal_goto_handler_slots = 0;
5866 nonlocal_goto_stack_level = 0;
5868 /* No labels have been declared for nonlocal use. */
5869 nonlocal_labels = 0;
5870 nonlocal_goto_handler_labels = 0;
5872 /* No function calls so far in this function. */
5873 function_call_count = 0;
5875 /* No parm regs have been allocated.
5876 (This is important for output_inline_function.) */
5877 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
5879 /* Initialize the RTL mechanism. */
5880 init_emit ();
5882 /* Initialize the queue of pending postincrement and postdecrements,
5883 and some other info in expr.c. */
5884 init_expr ();
5886 /* We haven't done register allocation yet. */
5887 reg_renumber = 0;
5889 init_const_rtx_hash_table ();
5891 current_function_name = (*decl_printable_name) (subr, 2);
5893 /* Nonzero if this is a nested function that uses a static chain. */
5895 current_function_needs_context
5896 = (decl_function_context (current_function_decl) != 0
5897 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
5899 /* Set if a call to setjmp is seen. */
5900 current_function_calls_setjmp = 0;
5902 /* Set if a call to longjmp is seen. */
5903 current_function_calls_longjmp = 0;
5905 current_function_calls_alloca = 0;
5906 current_function_has_nonlocal_label = 0;
5907 current_function_has_nonlocal_goto = 0;
5908 current_function_contains_functions = 0;
5909 current_function_is_leaf = 0;
5910 current_function_sp_is_unchanging = 0;
5911 current_function_uses_only_leaf_regs = 0;
5912 current_function_has_computed_jump = 0;
5913 current_function_is_thunk = 0;
5915 current_function_returns_pcc_struct = 0;
5916 current_function_returns_struct = 0;
5917 current_function_epilogue_delay_list = 0;
5918 current_function_uses_const_pool = 0;
5919 current_function_uses_pic_offset_table = 0;
5920 current_function_cannot_inline = 0;
5922 /* We have not yet needed to make a label to jump to for tail-recursion. */
5923 tail_recursion_label = 0;
5925 /* We haven't had a need to make a save area for ap yet. */
5927 arg_pointer_save_area = 0;
5929 /* No stack slots allocated yet. */
5930 frame_offset = 0;
5932 /* No SAVE_EXPRs in this function yet. */
5933 save_expr_regs = 0;
5935 /* No RTL_EXPRs in this function yet. */
5936 rtl_expr_chain = 0;
5938 /* Set up to allocate temporaries. */
5939 init_temp_slots ();
5941 /* Within function body, compute a type's size as soon it is laid out. */
5942 immediate_size_expand++;
5944 /* We haven't made any trampolines for this function yet. */
5945 trampoline_list = 0;
5947 init_pending_stack_adjust ();
5948 inhibit_defer_pop = 0;
5950 current_function_outgoing_args_size = 0;
5952 /* Prevent ever trying to delete the first instruction of a function.
5953 Also tell final how to output a linenum before the function prologue.
5954 Note linenums could be missing, e.g. when compiling a Java .class file. */
5955 if (line > 0)
5956 emit_line_note (filename, line);
5958 /* Make sure first insn is a note even if we don't want linenums.
5959 This makes sure the first insn will never be deleted.
5960 Also, final expects a note to appear there. */
5961 emit_note (NULL_PTR, NOTE_INSN_DELETED);
5963 /* Set flags used by final.c. */
5964 if (aggregate_value_p (DECL_RESULT (subr)))
5966 #ifdef PCC_STATIC_STRUCT_RETURN
5967 current_function_returns_pcc_struct = 1;
5968 #endif
5969 current_function_returns_struct = 1;
5972 /* Warn if this value is an aggregate type,
5973 regardless of which calling convention we are using for it. */
5974 if (warn_aggregate_return
5975 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
5976 warning ("function returns an aggregate");
5978 current_function_returns_pointer
5979 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
5981 /* Indicate that we need to distinguish between the return value of the
5982 present function and the return value of a function being called. */
5983 rtx_equal_function_value_matters = 1;
5985 /* Indicate that we have not instantiated virtual registers yet. */
5986 virtuals_instantiated = 0;
5988 /* Indicate we have no need of a frame pointer yet. */
5989 frame_pointer_needed = 0;
5991 /* By default assume not varargs or stdarg. */
5992 current_function_varargs = 0;
5993 current_function_stdarg = 0;
5996 /* Indicate that the current function uses extra args
5997 not explicitly mentioned in the argument list in any fashion. */
5999 void
6000 mark_varargs ()
6002 current_function_varargs = 1;
6005 /* Expand a call to __main at the beginning of a possible main function. */
6007 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6008 #undef HAS_INIT_SECTION
6009 #define HAS_INIT_SECTION
6010 #endif
6012 void
6013 expand_main_function ()
6015 #if !defined (HAS_INIT_SECTION)
6016 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), 0,
6017 VOIDmode, 0);
6018 #endif /* not HAS_INIT_SECTION */
6021 extern struct obstack permanent_obstack;
6023 /* Start the RTL for a new function, and set variables used for
6024 emitting RTL.
6025 SUBR is the FUNCTION_DECL node.
6026 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6027 the function's parameters, which must be run at any return statement. */
6029 void
6030 expand_function_start (subr, parms_have_cleanups)
6031 tree subr;
6032 int parms_have_cleanups;
6034 register int i;
6035 tree tem;
6036 rtx last_ptr = NULL_RTX;
6038 /* Make sure volatile mem refs aren't considered
6039 valid operands of arithmetic insns. */
6040 init_recog_no_volatile ();
6042 /* Set this before generating any memory accesses. */
6043 current_function_check_memory_usage
6044 = (flag_check_memory_usage
6045 && ! DECL_NO_CHECK_MEMORY_USAGE (current_function_decl));
6047 current_function_instrument_entry_exit
6048 = (flag_instrument_function_entry_exit
6049 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6051 /* If function gets a static chain arg, store it in the stack frame.
6052 Do this first, so it gets the first stack slot offset. */
6053 if (current_function_needs_context)
6055 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6057 /* Delay copying static chain if it is not a register to avoid
6058 conflicts with regs used for parameters. */
6059 if (! SMALL_REGISTER_CLASSES
6060 || GET_CODE (static_chain_incoming_rtx) == REG)
6061 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6064 /* If the parameters of this function need cleaning up, get a label
6065 for the beginning of the code which executes those cleanups. This must
6066 be done before doing anything with return_label. */
6067 if (parms_have_cleanups)
6068 cleanup_label = gen_label_rtx ();
6069 else
6070 cleanup_label = 0;
6072 /* Make the label for return statements to jump to, if this machine
6073 does not have a one-instruction return and uses an epilogue,
6074 or if it returns a structure, or if it has parm cleanups. */
6075 #ifdef HAVE_return
6076 if (cleanup_label == 0 && HAVE_return
6077 && ! current_function_instrument_entry_exit
6078 && ! current_function_returns_pcc_struct
6079 && ! (current_function_returns_struct && ! optimize))
6080 return_label = 0;
6081 else
6082 return_label = gen_label_rtx ();
6083 #else
6084 return_label = gen_label_rtx ();
6085 #endif
6087 /* Initialize rtx used to return the value. */
6088 /* Do this before assign_parms so that we copy the struct value address
6089 before any library calls that assign parms might generate. */
6091 /* Decide whether to return the value in memory or in a register. */
6092 if (aggregate_value_p (DECL_RESULT (subr)))
6094 /* Returning something that won't go in a register. */
6095 register rtx value_address = 0;
6097 #ifdef PCC_STATIC_STRUCT_RETURN
6098 if (current_function_returns_pcc_struct)
6100 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6101 value_address = assemble_static_space (size);
6103 else
6104 #endif
6106 /* Expect to be passed the address of a place to store the value.
6107 If it is passed as an argument, assign_parms will take care of
6108 it. */
6109 if (struct_value_incoming_rtx)
6111 value_address = gen_reg_rtx (Pmode);
6112 emit_move_insn (value_address, struct_value_incoming_rtx);
6115 if (value_address)
6117 DECL_RTL (DECL_RESULT (subr))
6118 = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6119 MEM_SET_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)),
6120 AGGREGATE_TYPE_P (TREE_TYPE
6121 (DECL_RESULT
6122 (subr))));
6125 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6126 /* If return mode is void, this decl rtl should not be used. */
6127 DECL_RTL (DECL_RESULT (subr)) = 0;
6128 else if (parms_have_cleanups || current_function_instrument_entry_exit)
6130 /* If function will end with cleanup code for parms,
6131 compute the return values into a pseudo reg,
6132 which we will copy into the true return register
6133 after the cleanups are done. */
6135 enum machine_mode mode = DECL_MODE (DECL_RESULT (subr));
6137 #ifdef PROMOTE_FUNCTION_RETURN
6138 tree type = TREE_TYPE (DECL_RESULT (subr));
6139 int unsignedp = TREE_UNSIGNED (type);
6141 mode = promote_mode (type, mode, &unsignedp, 1);
6142 #endif
6144 DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode);
6146 else
6147 /* Scalar, returned in a register. */
6149 #ifdef FUNCTION_OUTGOING_VALUE
6150 DECL_RTL (DECL_RESULT (subr))
6151 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
6152 #else
6153 DECL_RTL (DECL_RESULT (subr))
6154 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
6155 #endif
6157 /* Mark this reg as the function's return value. */
6158 if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
6160 REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
6161 /* Needed because we may need to move this to memory
6162 in case it's a named return value whose address is taken. */
6163 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6167 /* Initialize rtx for parameters and local variables.
6168 In some cases this requires emitting insns. */
6170 assign_parms (subr, 0);
6172 /* Copy the static chain now if it wasn't a register. The delay is to
6173 avoid conflicts with the parameter passing registers. */
6175 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6176 if (GET_CODE (static_chain_incoming_rtx) != REG)
6177 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6179 /* The following was moved from init_function_start.
6180 The move is supposed to make sdb output more accurate. */
6181 /* Indicate the beginning of the function body,
6182 as opposed to parm setup. */
6183 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG);
6185 /* If doing stupid allocation, mark parms as born here. */
6187 if (GET_CODE (get_last_insn ()) != NOTE)
6188 emit_note (NULL_PTR, NOTE_INSN_DELETED);
6189 parm_birth_insn = get_last_insn ();
6191 if (obey_regdecls)
6193 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
6194 use_variable (regno_reg_rtx[i]);
6196 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
6197 use_variable (current_function_internal_arg_pointer);
6200 context_display = 0;
6201 if (current_function_needs_context)
6203 /* Fetch static chain values for containing functions. */
6204 tem = decl_function_context (current_function_decl);
6205 /* If not doing stupid register allocation copy the static chain
6206 pointer into a pseudo. If we have small register classes, copy
6207 the value from memory if static_chain_incoming_rtx is a REG. If
6208 we do stupid register allocation, we use the stack address
6209 generated above. */
6210 if (tem && ! obey_regdecls)
6212 /* If the static chain originally came in a register, put it back
6213 there, then move it out in the next insn. The reason for
6214 this peculiar code is to satisfy function integration. */
6215 if (SMALL_REGISTER_CLASSES
6216 && GET_CODE (static_chain_incoming_rtx) == REG)
6217 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6218 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6221 while (tem)
6223 tree rtlexp = make_node (RTL_EXPR);
6225 RTL_EXPR_RTL (rtlexp) = last_ptr;
6226 context_display = tree_cons (tem, rtlexp, context_display);
6227 tem = decl_function_context (tem);
6228 if (tem == 0)
6229 break;
6230 /* Chain thru stack frames, assuming pointer to next lexical frame
6231 is found at the place we always store it. */
6232 #ifdef FRAME_GROWS_DOWNWARD
6233 last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
6234 #endif
6235 last_ptr = copy_to_reg (gen_rtx_MEM (Pmode,
6236 memory_address (Pmode, last_ptr)));
6238 /* If we are not optimizing, ensure that we know that this
6239 piece of context is live over the entire function. */
6240 if (! optimize)
6241 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6242 save_expr_regs);
6246 if (current_function_instrument_entry_exit)
6248 rtx fun = DECL_RTL (current_function_decl);
6249 if (GET_CODE (fun) == MEM)
6250 fun = XEXP (fun, 0);
6251 else
6252 abort ();
6253 emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2,
6254 fun, Pmode,
6255 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6257 hard_frame_pointer_rtx),
6258 Pmode);
6261 /* After the display initializations is where the tail-recursion label
6262 should go, if we end up needing one. Ensure we have a NOTE here
6263 since some things (like trampolines) get placed before this. */
6264 tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED);
6266 /* Evaluate now the sizes of any types declared among the arguments. */
6267 for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem))
6269 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode,
6270 EXPAND_MEMORY_USE_BAD);
6271 /* Flush the queue in case this parameter declaration has
6272 side-effects. */
6273 emit_queue ();
6276 /* Make sure there is a line number after the function entry setup code. */
6277 force_next_line_note ();
6280 /* Generate RTL for the end of the current function.
6281 FILENAME and LINE are the current position in the source file.
6283 It is up to language-specific callers to do cleanups for parameters--
6284 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6286 void
6287 expand_function_end (filename, line, end_bindings)
6288 char *filename;
6289 int line;
6290 int end_bindings;
6292 register int i;
6293 tree link;
6295 #ifdef TRAMPOLINE_TEMPLATE
6296 static rtx initial_trampoline;
6297 #endif
6299 #ifdef NON_SAVING_SETJMP
6300 /* Don't put any variables in registers if we call setjmp
6301 on a machine that fails to restore the registers. */
6302 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6304 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6305 setjmp_protect (DECL_INITIAL (current_function_decl));
6307 setjmp_protect_args ();
6309 #endif
6311 /* Save the argument pointer if a save area was made for it. */
6312 if (arg_pointer_save_area)
6314 /* arg_pointer_save_area may not be a valid memory address, so we
6315 have to check it and fix it if necessary. */
6316 rtx seq;
6317 start_sequence ();
6318 emit_move_insn (validize_mem (arg_pointer_save_area),
6319 virtual_incoming_args_rtx);
6320 seq = gen_sequence ();
6321 end_sequence ();
6322 emit_insn_before (seq, tail_recursion_reentry);
6325 /* Initialize any trampolines required by this function. */
6326 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6328 tree function = TREE_PURPOSE (link);
6329 rtx context = lookup_static_chain (function);
6330 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6331 #ifdef TRAMPOLINE_TEMPLATE
6332 rtx blktramp;
6333 #endif
6334 rtx seq;
6336 #ifdef TRAMPOLINE_TEMPLATE
6337 /* First make sure this compilation has a template for
6338 initializing trampolines. */
6339 if (initial_trampoline == 0)
6341 end_temporary_allocation ();
6342 initial_trampoline
6343 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6344 resume_temporary_allocation ();
6346 #endif
6348 /* Generate insns to initialize the trampoline. */
6349 start_sequence ();
6350 tramp = round_trampoline_addr (XEXP (tramp, 0));
6351 #ifdef TRAMPOLINE_TEMPLATE
6352 blktramp = change_address (initial_trampoline, BLKmode, tramp);
6353 emit_block_move (blktramp, initial_trampoline,
6354 GEN_INT (TRAMPOLINE_SIZE),
6355 TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
6356 #endif
6357 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6358 seq = get_insns ();
6359 end_sequence ();
6361 /* Put those insns at entry to the containing function (this one). */
6362 emit_insns_before (seq, tail_recursion_reentry);
6365 /* If we are doing stack checking and this function makes calls,
6366 do a stack probe at the start of the function to ensure we have enough
6367 space for another stack frame. */
6368 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6370 rtx insn, seq;
6372 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6373 if (GET_CODE (insn) == CALL_INSN)
6375 start_sequence ();
6376 probe_stack_range (STACK_CHECK_PROTECT,
6377 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6378 seq = get_insns ();
6379 end_sequence ();
6380 emit_insns_before (seq, tail_recursion_reentry);
6381 break;
6385 /* Warn about unused parms if extra warnings were specified. */
6386 if (warn_unused && extra_warnings)
6388 tree decl;
6390 for (decl = DECL_ARGUMENTS (current_function_decl);
6391 decl; decl = TREE_CHAIN (decl))
6392 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6393 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6394 warning_with_decl (decl, "unused parameter `%s'");
6397 /* Delete handlers for nonlocal gotos if nothing uses them. */
6398 if (nonlocal_goto_handler_slots != 0
6399 && ! current_function_has_nonlocal_label)
6400 delete_handlers ();
6402 /* End any sequences that failed to be closed due to syntax errors. */
6403 while (in_sequence_p ())
6404 end_sequence ();
6406 /* Outside function body, can't compute type's actual size
6407 until next function's body starts. */
6408 immediate_size_expand--;
6410 /* If doing stupid register allocation,
6411 mark register parms as dying here. */
6413 if (obey_regdecls)
6415 rtx tem;
6416 for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
6417 use_variable (regno_reg_rtx[i]);
6419 /* Likewise for the regs of all the SAVE_EXPRs in the function. */
6421 for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
6423 use_variable (XEXP (tem, 0));
6424 use_variable_after (XEXP (tem, 0), parm_birth_insn);
6427 if (current_function_internal_arg_pointer != virtual_incoming_args_rtx)
6428 use_variable (current_function_internal_arg_pointer);
6431 clear_pending_stack_adjust ();
6432 do_pending_stack_adjust ();
6434 /* Mark the end of the function body.
6435 If control reaches this insn, the function can drop through
6436 without returning a value. */
6437 emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END);
6439 /* Must mark the last line number note in the function, so that the test
6440 coverage code can avoid counting the last line twice. This just tells
6441 the code to ignore the immediately following line note, since there
6442 already exists a copy of this note somewhere above. This line number
6443 note is still needed for debugging though, so we can't delete it. */
6444 if (flag_test_coverage)
6445 emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER);
6447 /* Output a linenumber for the end of the function.
6448 SDB depends on this. */
6449 emit_line_note_force (filename, line);
6451 /* Output the label for the actual return from the function,
6452 if one is expected. This happens either because a function epilogue
6453 is used instead of a return instruction, or because a return was done
6454 with a goto in order to run local cleanups, or because of pcc-style
6455 structure returning. */
6457 if (return_label)
6458 emit_label (return_label);
6460 /* C++ uses this. */
6461 if (end_bindings)
6462 expand_end_bindings (0, 0, 0);
6464 /* Now handle any leftover exception regions that may have been
6465 created for the parameters. */
6467 rtx last = get_last_insn ();
6468 rtx label;
6470 expand_leftover_cleanups ();
6472 /* If the above emitted any code, may sure we jump around it. */
6473 if (last != get_last_insn ())
6475 label = gen_label_rtx ();
6476 last = emit_jump_insn_after (gen_jump (label), last);
6477 last = emit_barrier_after (last);
6478 emit_label (label);
6482 if (current_function_instrument_entry_exit)
6484 rtx fun = DECL_RTL (current_function_decl);
6485 if (GET_CODE (fun) == MEM)
6486 fun = XEXP (fun, 0);
6487 else
6488 abort ();
6489 emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2,
6490 fun, Pmode,
6491 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6493 hard_frame_pointer_rtx),
6494 Pmode);
6497 /* If we had calls to alloca, and this machine needs
6498 an accurate stack pointer to exit the function,
6499 insert some code to save and restore the stack pointer. */
6500 #ifdef EXIT_IGNORE_STACK
6501 if (! EXIT_IGNORE_STACK)
6502 #endif
6503 if (current_function_calls_alloca)
6505 rtx tem = 0;
6507 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6508 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6511 /* If scalar return value was computed in a pseudo-reg,
6512 copy that to the hard return register. */
6513 if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
6514 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
6515 && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
6516 >= FIRST_PSEUDO_REGISTER))
6518 rtx real_decl_result;
6520 #ifdef FUNCTION_OUTGOING_VALUE
6521 real_decl_result
6522 = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
6523 current_function_decl);
6524 #else
6525 real_decl_result
6526 = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
6527 current_function_decl);
6528 #endif
6529 REG_FUNCTION_VALUE_P (real_decl_result) = 1;
6530 /* If this is a BLKmode structure being returned in registers, then use
6531 the mode computed in expand_return. */
6532 if (GET_MODE (real_decl_result) == BLKmode)
6533 PUT_MODE (real_decl_result,
6534 GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl))));
6535 emit_move_insn (real_decl_result,
6536 DECL_RTL (DECL_RESULT (current_function_decl)));
6537 emit_insn (gen_rtx_USE (VOIDmode, real_decl_result));
6539 /* The delay slot scheduler assumes that current_function_return_rtx
6540 holds the hard register containing the return value, not a temporary
6541 pseudo. */
6542 current_function_return_rtx = real_decl_result;
6545 /* If returning a structure, arrange to return the address of the value
6546 in a place where debuggers expect to find it.
6548 If returning a structure PCC style,
6549 the caller also depends on this value.
6550 And current_function_returns_pcc_struct is not necessarily set. */
6551 if (current_function_returns_struct
6552 || current_function_returns_pcc_struct)
6554 rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
6555 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
6556 #ifdef FUNCTION_OUTGOING_VALUE
6557 rtx outgoing
6558 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
6559 current_function_decl);
6560 #else
6561 rtx outgoing
6562 = FUNCTION_VALUE (build_pointer_type (type),
6563 current_function_decl);
6564 #endif
6566 /* Mark this as a function return value so integrate will delete the
6567 assignment and USE below when inlining this function. */
6568 REG_FUNCTION_VALUE_P (outgoing) = 1;
6570 emit_move_insn (outgoing, value_address);
6571 use_variable (outgoing);
6574 /* If this is an implementation of __throw, do what's necessary to
6575 communicate between __builtin_eh_return and the epilogue. */
6576 expand_eh_return ();
6578 /* Output a return insn if we are using one.
6579 Otherwise, let the rtl chain end here, to drop through
6580 into the epilogue. */
6582 #ifdef HAVE_return
6583 if (HAVE_return)
6585 emit_jump_insn (gen_return ());
6586 emit_barrier ();
6588 #endif
6590 /* Fix up any gotos that jumped out to the outermost
6591 binding level of the function.
6592 Must follow emitting RETURN_LABEL. */
6594 /* If you have any cleanups to do at this point,
6595 and they need to create temporary variables,
6596 then you will lose. */
6597 expand_fixups (get_insns ());
6600 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
6602 static int *prologue;
6603 static int *epilogue;
6605 /* Create an array that records the INSN_UIDs of INSNS (either a sequence
6606 or a single insn). */
6608 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6609 static int *
6610 record_insns (insns)
6611 rtx insns;
6613 int *vec;
6615 if (GET_CODE (insns) == SEQUENCE)
6617 int len = XVECLEN (insns, 0);
6618 vec = (int *) oballoc ((len + 1) * sizeof (int));
6619 vec[len] = 0;
6620 while (--len >= 0)
6621 vec[len] = INSN_UID (XVECEXP (insns, 0, len));
6623 else
6625 vec = (int *) oballoc (2 * sizeof (int));
6626 vec[0] = INSN_UID (insns);
6627 vec[1] = 0;
6629 return vec;
6632 /* Determine how many INSN_UIDs in VEC are part of INSN. */
6634 static int
6635 contains (insn, vec)
6636 rtx insn;
6637 int *vec;
6639 register int i, j;
6641 if (GET_CODE (insn) == INSN
6642 && GET_CODE (PATTERN (insn)) == SEQUENCE)
6644 int count = 0;
6645 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
6646 for (j = 0; vec[j]; j++)
6647 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j])
6648 count++;
6649 return count;
6651 else
6653 for (j = 0; vec[j]; j++)
6654 if (INSN_UID (insn) == vec[j])
6655 return 1;
6657 return 0;
6659 #endif /* HAVE_prologue || HAVE_epilogue */
6661 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
6662 this into place with notes indicating where the prologue ends and where
6663 the epilogue begins. Update the basic block information when possible. */
6665 void
6666 thread_prologue_and_epilogue_insns (f)
6667 rtx f ATTRIBUTE_UNUSED;
6669 int insertted = 0;
6671 prologue = 0;
6672 #ifdef HAVE_prologue
6673 if (HAVE_prologue)
6675 rtx seq;
6677 start_sequence ();
6678 seq = gen_prologue();
6679 emit_insn (seq);
6681 /* Retain a map of the prologue insns. */
6682 if (GET_CODE (seq) != SEQUENCE)
6683 seq = get_insns ();
6684 prologue = record_insns (seq);
6686 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
6687 seq = gen_sequence ();
6688 end_sequence ();
6690 /* If optimization is off, and perhaps in an empty function,
6691 the entry block will have no successors. */
6692 if (ENTRY_BLOCK_PTR->succ)
6694 /* Can't deal with multiple successsors of the entry block. */
6695 if (ENTRY_BLOCK_PTR->succ->succ_next)
6696 abort ();
6698 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
6699 insertted = 1;
6701 else
6702 emit_insn_after (seq, f);
6704 #endif
6706 epilogue = 0;
6707 #ifdef HAVE_epilogue
6708 if (HAVE_epilogue)
6710 edge e;
6711 basic_block bb = 0;
6712 rtx tail = get_last_insn ();
6714 /* ??? This is gastly. If function returns were not done via uses,
6715 but via mark_regs_live_at_end, we could use insert_insn_on_edge
6716 and all of this uglyness would go away. */
6718 switch (optimize)
6720 default:
6721 /* If the exit block has no non-fake predecessors, we don't
6722 need an epilogue. Furthermore, only pay attention to the
6723 fallthru predecessors; if (conditional) return insns were
6724 generated, by definition we do not need to emit epilogue
6725 insns. */
6727 for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
6728 if ((e->flags & EDGE_FAKE) == 0
6729 && (e->flags & EDGE_FALLTHRU) != 0)
6730 break;
6731 if (e == NULL)
6732 break;
6734 /* We can't handle multiple epilogues -- if one is needed,
6735 we won't be able to place it multiple times.
6737 ??? Fix epilogue expanders to not assume they are the
6738 last thing done compiling the function. Either that
6739 or copy_rtx each insn.
6741 ??? Blah, it's not a simple expression to assert that
6742 we've exactly one fallthru exit edge. */
6744 bb = e->src;
6745 tail = bb->end;
6747 /* ??? If the last insn of the basic block is a jump, then we
6748 are creating a new basic block. Wimp out and leave these
6749 insns outside any block. */
6750 if (GET_CODE (tail) == JUMP_INSN)
6751 bb = 0;
6753 /* FALLTHRU */
6754 case 0:
6756 rtx prev, seq, first_use;
6758 /* Move the USE insns at the end of a function onto a list. */
6759 prev = tail;
6760 if (GET_CODE (prev) == BARRIER
6761 || GET_CODE (prev) == NOTE)
6762 prev = prev_nonnote_insn (prev);
6764 first_use = 0;
6765 if (prev
6766 && GET_CODE (prev) == INSN
6767 && GET_CODE (PATTERN (prev)) == USE)
6769 /* If the end of the block is the use, grab hold of something
6770 else so that we emit barriers etc in the right place. */
6771 if (prev == tail)
6774 tail = PREV_INSN (tail);
6775 while (GET_CODE (tail) == INSN
6776 && GET_CODE (PATTERN (tail)) == USE);
6781 rtx use = prev;
6782 prev = prev_nonnote_insn (prev);
6784 remove_insn (use);
6785 if (first_use)
6787 NEXT_INSN (use) = first_use;
6788 PREV_INSN (first_use) = use;
6790 else
6791 NEXT_INSN (use) = NULL_RTX;
6792 first_use = use;
6794 while (prev
6795 && GET_CODE (prev) == INSN
6796 && GET_CODE (PATTERN (prev)) == USE);
6799 /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
6800 epilogue insns, the USE insns at the end of a function,
6801 the jump insn that returns, and then a BARRIER. */
6803 if (GET_CODE (tail) != BARRIER)
6805 prev = next_nonnote_insn (tail);
6806 if (!prev || GET_CODE (prev) != BARRIER)
6807 emit_barrier_after (tail);
6810 seq = gen_epilogue ();
6811 prev = tail;
6812 tail = emit_jump_insn_after (seq, tail);
6814 /* Insert the USE insns immediately before the return insn, which
6815 must be the last instruction emitted in the sequence. */
6816 if (first_use)
6817 emit_insns_before (first_use, tail);
6818 emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
6820 /* Update the tail of the basic block. */
6821 if (bb)
6822 bb->end = tail;
6824 /* Retain a map of the epilogue insns. */
6825 epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
6829 #endif
6831 if (insertted)
6832 commit_edge_insertions ();
6835 /* Reposition the prologue-end and epilogue-begin notes after instruction
6836 scheduling and delayed branch scheduling. */
6838 void
6839 reposition_prologue_and_epilogue_notes (f)
6840 rtx f ATTRIBUTE_UNUSED;
6842 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
6843 /* Reposition the prologue and epilogue notes. */
6844 if (n_basic_blocks)
6846 int len;
6848 if (prologue)
6850 register rtx insn, note = 0;
6852 /* Scan from the beginning until we reach the last prologue insn.
6853 We apparently can't depend on basic_block_{head,end} after
6854 reorg has run. */
6855 for (len = 0; prologue[len]; len++)
6857 for (insn = f; len && insn; insn = NEXT_INSN (insn))
6859 if (GET_CODE (insn) == NOTE)
6861 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
6862 note = insn;
6864 else if ((len -= contains (insn, prologue)) == 0)
6866 rtx next;
6867 /* Find the prologue-end note if we haven't already, and
6868 move it to just after the last prologue insn. */
6869 if (note == 0)
6871 for (note = insn; (note = NEXT_INSN (note));)
6872 if (GET_CODE (note) == NOTE
6873 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
6874 break;
6877 next = NEXT_INSN (note);
6879 /* Whether or not we can depend on BLOCK_HEAD,
6880 attempt to keep it up-to-date. */
6881 if (BLOCK_HEAD (0) == note)
6882 BLOCK_HEAD (0) = next;
6884 remove_insn (note);
6885 add_insn_after (note, insn);
6890 if (epilogue)
6892 register rtx insn, note = 0;
6894 /* Scan from the end until we reach the first epilogue insn.
6895 We apparently can't depend on basic_block_{head,end} after
6896 reorg has run. */
6897 for (len = 0; epilogue[len]; len++)
6899 for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn))
6901 if (GET_CODE (insn) == NOTE)
6903 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
6904 note = insn;
6906 else if ((len -= contains (insn, epilogue)) == 0)
6908 /* Find the epilogue-begin note if we haven't already, and
6909 move it to just before the first epilogue insn. */
6910 if (note == 0)
6912 for (note = insn; (note = PREV_INSN (note));)
6913 if (GET_CODE (note) == NOTE
6914 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
6915 break;
6918 /* Whether or not we can depend on BLOCK_HEAD,
6919 attempt to keep it up-to-date. */
6920 if (n_basic_blocks
6921 && BLOCK_HEAD (n_basic_blocks-1) == insn)
6922 BLOCK_HEAD (n_basic_blocks-1) = note;
6924 remove_insn (note);
6925 add_insn_before (note, insn);
6930 #endif /* HAVE_prologue or HAVE_epilogue */