1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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. */
51 #include "hard-reg-set.h"
52 #include "insn-config.h"
55 #include "basic-block.h"
61 #include "integrate.h"
62 #include "langhooks.h"
64 #ifndef TRAMPOLINE_ALIGNMENT
65 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
68 #ifndef LOCAL_ALIGNMENT
69 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
72 /* Some systems use __main in a way incompatible with its use in gcc, in these
73 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
74 give the same symbol without quotes for an alternative entry point. You
75 must define both, or neither. */
77 #define NAME__MAIN "__main"
78 #define SYMBOL__MAIN __main
81 /* Round a value to the lowest integer less than it that is a multiple of
82 the required alignment. Avoid using division in case the value is
83 negative. Assume the alignment is a power of two. */
84 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
86 /* Similar, but round to the next highest integer that meets the
88 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
90 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
91 during rtl generation. If they are different register numbers, this is
92 always true. It may also be true if
93 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
94 generation. See fix_lexical_addr for details. */
96 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
97 #define NEED_SEPARATE_AP
100 /* Nonzero if function being compiled doesn't contain any calls
101 (ignoring the prologue and epilogue). This is set prior to
102 local register allocation and is valid for the remaining
104 int current_function_is_leaf;
106 /* Nonzero if function being compiled doesn't contain any instructions
107 that can throw an exception. This is set prior to final. */
109 int current_function_nothrow;
111 /* Nonzero if function being compiled doesn't modify the stack pointer
112 (ignoring the prologue and epilogue). This is only valid after
113 life_analysis has run. */
114 int current_function_sp_is_unchanging;
116 /* Nonzero if the function being compiled is a leaf function which only
117 uses leaf registers. This is valid after reload (specifically after
118 sched2) and is useful only if the port defines LEAF_REGISTERS. */
119 int current_function_uses_only_leaf_regs;
121 /* Nonzero once virtual register instantiation has been done.
122 assign_stack_local uses frame_pointer_rtx when this is nonzero.
123 calls.c:emit_library_call_value_1 uses it to set up
124 post-instantiation libcalls. */
125 int virtuals_instantiated;
127 /* These variables hold pointers to functions to create and destroy
128 target specific, per-function data structures. */
129 void (*init_machine_status) PARAMS ((struct function *));
130 void (*free_machine_status) PARAMS ((struct function *));
131 /* This variable holds a pointer to a function to register any
132 data items in the target specific, per-function data structure
133 that will need garbage collection. */
134 void (*mark_machine_status) PARAMS ((struct function *));
136 /* The FUNCTION_DECL for an inline function currently being expanded. */
137 tree inline_function_decl;
139 /* The currently compiled function. */
140 struct function *cfun = 0;
142 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
143 static varray_type prologue;
144 static varray_type epilogue;
146 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
148 static varray_type sibcall_epilogue;
150 /* In order to evaluate some expressions, such as function calls returning
151 structures in memory, we need to temporarily allocate stack locations.
152 We record each allocated temporary in the following structure.
154 Associated with each temporary slot is a nesting level. When we pop up
155 one level, all temporaries associated with the previous level are freed.
156 Normally, all temporaries are freed after the execution of the statement
157 in which they were created. However, if we are inside a ({...}) grouping,
158 the result may be in a temporary and hence must be preserved. If the
159 result could be in a temporary, we preserve it if we can determine which
160 one it is in. If we cannot determine which temporary may contain the
161 result, all temporaries are preserved. A temporary is preserved by
162 pretending it was allocated at the previous nesting level.
164 Automatic variables are also assigned temporary slots, at the nesting
165 level where they are defined. They are marked a "kept" so that
166 free_temp_slots will not free them. */
170 /* Points to next temporary slot. */
171 struct temp_slot *next;
172 /* The rtx to used to reference the slot. */
174 /* The rtx used to represent the address if not the address of the
175 slot above. May be an EXPR_LIST if multiple addresses exist. */
177 /* The alignment (in bits) of the slot. */
179 /* The size, in units, of the slot. */
181 /* The type of the object in the slot, or zero if it doesn't correspond
182 to a type. We use this to determine whether a slot can be reused.
183 It can be reused if objects of the type of the new slot will always
184 conflict with objects of the type of the old slot. */
186 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
188 /* Non-zero if this temporary is currently in use. */
190 /* Non-zero if this temporary has its address taken. */
192 /* Nesting level at which this slot is being used. */
194 /* Non-zero if this should survive a call to free_temp_slots. */
196 /* The offset of the slot from the frame_pointer, including extra space
197 for alignment. This info is for combine_temp_slots. */
198 HOST_WIDE_INT base_offset;
199 /* The size of the slot, including extra space for alignment. This
200 info is for combine_temp_slots. */
201 HOST_WIDE_INT full_size;
204 /* This structure is used to record MEMs or pseudos used to replace VAR, any
205 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
206 maintain this list in case two operands of an insn were required to match;
207 in that case we must ensure we use the same replacement. */
209 struct fixup_replacement
213 struct fixup_replacement *next;
216 struct insns_for_mem_entry
218 /* The KEY in HE will be a MEM. */
219 struct hash_entry he;
220 /* These are the INSNS which reference the MEM. */
224 /* Forward declarations. */
226 static rtx assign_stack_local_1 PARAMS ((enum machine_mode, HOST_WIDE_INT,
227 int, struct function *));
228 static struct temp_slot *find_temp_slot_from_address PARAMS ((rtx));
229 static void put_reg_into_stack PARAMS ((struct function *, rtx, tree,
230 enum machine_mode, enum machine_mode,
231 int, unsigned int, int,
232 struct hash_table *));
233 static void schedule_fixup_var_refs PARAMS ((struct function *, rtx, tree,
235 struct hash_table *));
236 static void fixup_var_refs PARAMS ((rtx, enum machine_mode, int, rtx,
237 struct hash_table *));
238 static struct fixup_replacement
239 *find_fixup_replacement PARAMS ((struct fixup_replacement **, rtx));
240 static void fixup_var_refs_insns PARAMS ((rtx, rtx, enum machine_mode,
242 static void fixup_var_refs_insns_with_hash
243 PARAMS ((struct hash_table *, rtx,
244 enum machine_mode, int, rtx));
245 static void fixup_var_refs_insn PARAMS ((rtx, rtx, enum machine_mode,
247 static void fixup_var_refs_1 PARAMS ((rtx, enum machine_mode, rtx *, rtx,
248 struct fixup_replacement **, rtx));
249 static rtx fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode, int));
250 static rtx walk_fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode,
252 static rtx fixup_stack_1 PARAMS ((rtx, rtx));
253 static void optimize_bit_field PARAMS ((rtx, rtx, rtx *));
254 static void instantiate_decls PARAMS ((tree, int));
255 static void instantiate_decls_1 PARAMS ((tree, int));
256 static void instantiate_decl PARAMS ((rtx, HOST_WIDE_INT, int));
257 static rtx instantiate_new_reg PARAMS ((rtx, HOST_WIDE_INT *));
258 static int instantiate_virtual_regs_1 PARAMS ((rtx *, rtx, int));
259 static void delete_handlers PARAMS ((void));
260 static void pad_to_arg_alignment PARAMS ((struct args_size *, int,
261 struct args_size *));
262 #ifndef ARGS_GROW_DOWNWARD
263 static void pad_below PARAMS ((struct args_size *, enum machine_mode,
266 static rtx round_trampoline_addr PARAMS ((rtx));
267 static rtx adjust_trampoline_addr PARAMS ((rtx));
268 static tree *identify_blocks_1 PARAMS ((rtx, tree *, tree *, tree *));
269 static void reorder_blocks_0 PARAMS ((tree));
270 static void reorder_blocks_1 PARAMS ((rtx, tree, varray_type *));
271 static void reorder_fix_fragments PARAMS ((tree));
272 static tree blocks_nreverse PARAMS ((tree));
273 static int all_blocks PARAMS ((tree, tree *));
274 static tree *get_block_vector PARAMS ((tree, int *));
275 extern tree debug_find_var_in_block_tree PARAMS ((tree, tree));
276 /* We always define `record_insns' even if its not used so that we
277 can always export `prologue_epilogue_contains'. */
278 static void record_insns PARAMS ((rtx, varray_type *)) ATTRIBUTE_UNUSED;
279 static int contains PARAMS ((rtx, varray_type));
281 static void emit_return_into_block PARAMS ((basic_block, rtx));
283 static void put_addressof_into_stack PARAMS ((rtx, struct hash_table *));
284 static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
285 struct hash_table *));
286 static void purge_single_hard_subreg_set PARAMS ((rtx));
287 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
288 static rtx keep_stack_depressed PARAMS ((rtx));
290 static int is_addressof PARAMS ((rtx *, void *));
291 static struct hash_entry *insns_for_mem_newfunc PARAMS ((struct hash_entry *,
294 static unsigned long insns_for_mem_hash PARAMS ((hash_table_key));
295 static bool insns_for_mem_comp PARAMS ((hash_table_key, hash_table_key));
296 static int insns_for_mem_walk PARAMS ((rtx *, void *));
297 static void compute_insns_for_mem PARAMS ((rtx, rtx, struct hash_table *));
298 static void mark_function_status PARAMS ((struct function *));
299 static void maybe_mark_struct_function PARAMS ((void *));
300 static void prepare_function_start PARAMS ((void));
301 static void do_clobber_return_reg PARAMS ((rtx, void *));
302 static void do_use_return_reg PARAMS ((rtx, void *));
304 /* Pointer to chain of `struct function' for containing functions. */
305 static struct function *outer_function_chain;
307 /* Given a function decl for a containing function,
308 return the `struct function' for it. */
311 find_function_data (decl)
316 for (p = outer_function_chain; p; p = p->outer)
323 /* Save the current context for compilation of a nested function.
324 This is called from language-specific code. The caller should use
325 the enter_nested langhook to save any language-specific state,
326 since this function knows only about language-independent
330 push_function_context_to (context)
337 if (context == current_function_decl)
338 cfun->contains_functions = 1;
341 struct function *containing = find_function_data (context);
342 containing->contains_functions = 1;
347 init_dummy_function_start ();
350 p->outer = outer_function_chain;
351 outer_function_chain = p;
352 p->fixup_var_refs_queue = 0;
354 (*lang_hooks.function.enter_nested) (p);
360 push_function_context ()
362 push_function_context_to (current_function_decl);
365 /* Restore the last saved context, at the end of a nested function.
366 This function is called from language-specific code. */
369 pop_function_context_from (context)
370 tree context ATTRIBUTE_UNUSED;
372 struct function *p = outer_function_chain;
373 struct var_refs_queue *queue;
376 outer_function_chain = p->outer;
378 current_function_decl = p->decl;
381 restore_emit_status (p);
383 (*lang_hooks.function.leave_nested) (p);
385 /* Finish doing put_var_into_stack for any of our variables which became
386 addressable during the nested function. If only one entry has to be
387 fixed up, just do that one. Otherwise, first make a list of MEMs that
388 are not to be unshared. */
389 if (p->fixup_var_refs_queue == 0)
391 else if (p->fixup_var_refs_queue->next == 0)
392 fixup_var_refs (p->fixup_var_refs_queue->modified,
393 p->fixup_var_refs_queue->promoted_mode,
394 p->fixup_var_refs_queue->unsignedp,
395 p->fixup_var_refs_queue->modified, 0);
400 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
401 list = gen_rtx_EXPR_LIST (VOIDmode, queue->modified, list);
403 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
404 fixup_var_refs (queue->modified, queue->promoted_mode,
405 queue->unsignedp, list, 0);
409 p->fixup_var_refs_queue = 0;
411 /* Reset variables that have known state during rtx generation. */
412 rtx_equal_function_value_matters = 1;
413 virtuals_instantiated = 0;
414 generating_concat_p = 1;
418 pop_function_context ()
420 pop_function_context_from (current_function_decl);
423 /* Clear out all parts of the state in F that can safely be discarded
424 after the function has been parsed, but not compiled, to let
425 garbage collection reclaim the memory. */
428 free_after_parsing (f)
431 /* f->expr->forced_labels is used by code generation. */
432 /* f->emit->regno_reg_rtx is used by code generation. */
433 /* f->varasm is used by code generation. */
434 /* f->eh->eh_return_stub_label is used by code generation. */
436 (*lang_hooks.function.free) (f);
437 free_stmt_status (f);
440 /* Clear out all parts of the state in F that can safely be discarded
441 after the function has been compiled, to let garbage collection
442 reclaim the memory. */
445 free_after_compilation (f)
449 free_expr_status (f);
450 free_emit_status (f);
451 free_varasm_status (f);
453 if (free_machine_status)
454 (*free_machine_status) (f);
456 if (f->x_parm_reg_stack_loc)
457 free (f->x_parm_reg_stack_loc);
459 f->x_temp_slots = NULL;
460 f->arg_offset_rtx = NULL;
461 f->return_rtx = NULL;
462 f->internal_arg_pointer = NULL;
463 f->x_nonlocal_labels = NULL;
464 f->x_nonlocal_goto_handler_slots = NULL;
465 f->x_nonlocal_goto_handler_labels = NULL;
466 f->x_nonlocal_goto_stack_level = NULL;
467 f->x_cleanup_label = NULL;
468 f->x_return_label = NULL;
469 f->x_save_expr_regs = NULL;
470 f->x_stack_slot_list = NULL;
471 f->x_rtl_expr_chain = NULL;
472 f->x_tail_recursion_label = NULL;
473 f->x_tail_recursion_reentry = NULL;
474 f->x_arg_pointer_save_area = NULL;
475 f->x_clobber_return_insn = NULL;
476 f->x_context_display = NULL;
477 f->x_trampoline_list = NULL;
478 f->x_parm_birth_insn = NULL;
479 f->x_last_parm_insn = NULL;
480 f->x_parm_reg_stack_loc = NULL;
481 f->fixup_var_refs_queue = NULL;
482 f->original_arg_vector = NULL;
483 f->original_decl_initial = NULL;
484 f->inl_last_parm_insn = NULL;
485 f->epilogue_delay_list = NULL;
488 /* Allocate fixed slots in the stack frame of the current function. */
490 /* Return size needed for stack frame based on slots so far allocated in
492 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
493 the caller may have to do that. */
496 get_func_frame_size (f)
499 #ifdef FRAME_GROWS_DOWNWARD
500 return -f->x_frame_offset;
502 return f->x_frame_offset;
506 /* Return size needed for stack frame based on slots so far allocated.
507 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
508 the caller may have to do that. */
512 return get_func_frame_size (cfun);
515 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
516 with machine mode MODE.
518 ALIGN controls the amount of alignment for the address of the slot:
519 0 means according to MODE,
520 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
521 positive specifies alignment boundary in bits.
523 We do not round to stack_boundary here.
525 FUNCTION specifies the function to allocate in. */
528 assign_stack_local_1 (mode, size, align, function)
529 enum machine_mode mode;
532 struct function *function;
535 int bigend_correction = 0;
537 int frame_off, frame_alignment, frame_phase;
544 alignment = BIGGEST_ALIGNMENT;
546 alignment = GET_MODE_ALIGNMENT (mode);
548 /* Allow the target to (possibly) increase the alignment of this
550 type = (*lang_hooks.types.type_for_mode) (mode, 0);
552 alignment = LOCAL_ALIGNMENT (type, alignment);
554 alignment /= BITS_PER_UNIT;
556 else if (align == -1)
558 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
559 size = CEIL_ROUND (size, alignment);
562 alignment = align / BITS_PER_UNIT;
564 #ifdef FRAME_GROWS_DOWNWARD
565 function->x_frame_offset -= size;
568 /* Ignore alignment we can't do with expected alignment of the boundary. */
569 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
570 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
572 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
573 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
575 /* Calculate how many bytes the start of local variables is off from
577 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
578 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
579 frame_phase = frame_off ? frame_alignment - frame_off : 0;
581 /* Round frame offset to that alignment.
582 We must be careful here, since FRAME_OFFSET might be negative and
583 division with a negative dividend isn't as well defined as we might
584 like. So we instead assume that ALIGNMENT is a power of two and
585 use logical operations which are unambiguous. */
586 #ifdef FRAME_GROWS_DOWNWARD
587 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
589 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
592 /* On a big-endian machine, if we are allocating more space than we will use,
593 use the least significant bytes of those that are allocated. */
594 if (BYTES_BIG_ENDIAN && mode != BLKmode)
595 bigend_correction = size - GET_MODE_SIZE (mode);
597 /* If we have already instantiated virtual registers, return the actual
598 address relative to the frame pointer. */
599 if (function == cfun && virtuals_instantiated)
600 addr = plus_constant (frame_pointer_rtx,
601 (frame_offset + bigend_correction
602 + STARTING_FRAME_OFFSET));
604 addr = plus_constant (virtual_stack_vars_rtx,
605 function->x_frame_offset + bigend_correction);
607 #ifndef FRAME_GROWS_DOWNWARD
608 function->x_frame_offset += size;
611 x = gen_rtx_MEM (mode, addr);
613 function->x_stack_slot_list
614 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
619 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
623 assign_stack_local (mode, size, align)
624 enum machine_mode mode;
628 return assign_stack_local_1 (mode, size, align, cfun);
631 /* Allocate a temporary stack slot and record it for possible later
634 MODE is the machine mode to be given to the returned rtx.
636 SIZE is the size in units of the space required. We do no rounding here
637 since assign_stack_local will do any required rounding.
639 KEEP is 1 if this slot is to be retained after a call to
640 free_temp_slots. Automatic variables for a block are allocated
641 with this flag. KEEP is 2 if we allocate a longer term temporary,
642 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
643 if we are to allocate something at an inner level to be treated as
644 a variable in the block (e.g., a SAVE_EXPR).
646 TYPE is the type that will be used for the stack slot. */
649 assign_stack_temp_for_type (mode, size, keep, type)
650 enum machine_mode mode;
656 struct temp_slot *p, *best_p = 0;
658 /* If SIZE is -1 it means that somebody tried to allocate a temporary
659 of a variable size. */
664 align = BIGGEST_ALIGNMENT;
666 align = GET_MODE_ALIGNMENT (mode);
669 type = (*lang_hooks.types.type_for_mode) (mode, 0);
672 align = LOCAL_ALIGNMENT (type, align);
674 /* Try to find an available, already-allocated temporary of the proper
675 mode which meets the size and alignment requirements. Choose the
676 smallest one with the closest alignment. */
677 for (p = temp_slots; p; p = p->next)
678 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
680 && objects_must_conflict_p (p->type, type)
681 && (best_p == 0 || best_p->size > p->size
682 || (best_p->size == p->size && best_p->align > p->align)))
684 if (p->align == align && p->size == size)
692 /* Make our best, if any, the one to use. */
695 /* If there are enough aligned bytes left over, make them into a new
696 temp_slot so that the extra bytes don't get wasted. Do this only
697 for BLKmode slots, so that we can be sure of the alignment. */
698 if (GET_MODE (best_p->slot) == BLKmode)
700 int alignment = best_p->align / BITS_PER_UNIT;
701 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
703 if (best_p->size - rounded_size >= alignment)
705 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
706 p->in_use = p->addr_taken = 0;
707 p->size = best_p->size - rounded_size;
708 p->base_offset = best_p->base_offset + rounded_size;
709 p->full_size = best_p->full_size - rounded_size;
710 p->slot = gen_rtx_MEM (BLKmode,
711 plus_constant (XEXP (best_p->slot, 0),
713 p->align = best_p->align;
716 p->type = best_p->type;
717 p->next = temp_slots;
720 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
723 best_p->size = rounded_size;
724 best_p->full_size = rounded_size;
731 /* If we still didn't find one, make a new temporary. */
734 HOST_WIDE_INT frame_offset_old = frame_offset;
736 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
738 /* We are passing an explicit alignment request to assign_stack_local.
739 One side effect of that is assign_stack_local will not round SIZE
740 to ensure the frame offset remains suitably aligned.
742 So for requests which depended on the rounding of SIZE, we go ahead
743 and round it now. We also make sure ALIGNMENT is at least
744 BIGGEST_ALIGNMENT. */
745 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
747 p->slot = assign_stack_local (mode,
749 ? CEIL_ROUND (size, align / BITS_PER_UNIT)
755 /* The following slot size computation is necessary because we don't
756 know the actual size of the temporary slot until assign_stack_local
757 has performed all the frame alignment and size rounding for the
758 requested temporary. Note that extra space added for alignment
759 can be either above or below this stack slot depending on which
760 way the frame grows. We include the extra space if and only if it
761 is above this slot. */
762 #ifdef FRAME_GROWS_DOWNWARD
763 p->size = frame_offset_old - frame_offset;
768 /* Now define the fields used by combine_temp_slots. */
769 #ifdef FRAME_GROWS_DOWNWARD
770 p->base_offset = frame_offset;
771 p->full_size = frame_offset_old - frame_offset;
773 p->base_offset = frame_offset_old;
774 p->full_size = frame_offset - frame_offset_old;
777 p->next = temp_slots;
783 p->rtl_expr = seq_rtl_expr;
788 p->level = target_temp_slot_level;
793 p->level = var_temp_slot_level;
798 p->level = temp_slot_level;
802 /* We may be reusing an old slot, so clear any MEM flags that may have been
804 RTX_UNCHANGING_P (p->slot) = 0;
805 MEM_IN_STRUCT_P (p->slot) = 0;
806 MEM_SCALAR_P (p->slot) = 0;
807 MEM_VOLATILE_P (p->slot) = 0;
808 set_mem_alias_set (p->slot, 0);
810 /* If we know the alias set for the memory that will be used, use
811 it. If there's no TYPE, then we don't know anything about the
812 alias set for the memory. */
813 set_mem_alias_set (p->slot, type ? get_alias_set (type) : 0);
814 set_mem_align (p->slot, align);
816 /* If a type is specified, set the relevant flags. */
819 RTX_UNCHANGING_P (p->slot) = TYPE_READONLY (type);
820 MEM_VOLATILE_P (p->slot) = TYPE_VOLATILE (type);
821 MEM_SET_IN_STRUCT_P (p->slot, AGGREGATE_TYPE_P (type));
827 /* Allocate a temporary stack slot and record it for possible later
828 reuse. First three arguments are same as in preceding function. */
831 assign_stack_temp (mode, size, keep)
832 enum machine_mode mode;
836 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
839 /* Assign a temporary.
840 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
841 and so that should be used in error messages. In either case, we
842 allocate of the given type.
843 KEEP is as for assign_stack_temp.
844 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
845 it is 0 if a register is OK.
846 DONT_PROMOTE is 1 if we should not promote values in register
850 assign_temp (type_or_decl, keep, memory_required, dont_promote)
854 int dont_promote ATTRIBUTE_UNUSED;
857 enum machine_mode mode;
858 #ifndef PROMOTE_FOR_CALL_ONLY
862 if (DECL_P (type_or_decl))
863 decl = type_or_decl, type = TREE_TYPE (decl);
865 decl = NULL, type = type_or_decl;
867 mode = TYPE_MODE (type);
868 #ifndef PROMOTE_FOR_CALL_ONLY
869 unsignedp = TREE_UNSIGNED (type);
872 if (mode == BLKmode || memory_required)
874 HOST_WIDE_INT size = int_size_in_bytes (type);
877 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
878 problems with allocating the stack space. */
882 /* Unfortunately, we don't yet know how to allocate variable-sized
883 temporaries. However, sometimes we have a fixed upper limit on
884 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
885 instead. This is the case for Chill variable-sized strings. */
886 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
887 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
888 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
889 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
891 /* The size of the temporary may be too large to fit into an integer. */
892 /* ??? Not sure this should happen except for user silliness, so limit
893 this to things that aren't compiler-generated temporaries. The
894 rest of the time we'll abort in assign_stack_temp_for_type. */
895 if (decl && size == -1
896 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
898 error_with_decl (decl, "size of variable `%s' is too large");
902 tmp = assign_stack_temp_for_type (mode, size, keep, type);
906 #ifndef PROMOTE_FOR_CALL_ONLY
908 mode = promote_mode (type, mode, &unsignedp, 0);
911 return gen_reg_rtx (mode);
914 /* Combine temporary stack slots which are adjacent on the stack.
916 This allows for better use of already allocated stack space. This is only
917 done for BLKmode slots because we can be sure that we won't have alignment
918 problems in this case. */
921 combine_temp_slots ()
923 struct temp_slot *p, *q;
924 struct temp_slot *prev_p, *prev_q;
927 /* We can't combine slots, because the information about which slot
928 is in which alias set will be lost. */
929 if (flag_strict_aliasing)
932 /* If there are a lot of temp slots, don't do anything unless
933 high levels of optimization. */
934 if (! flag_expensive_optimizations)
935 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
936 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
939 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
943 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
944 for (q = p->next, prev_q = p; q; q = prev_q->next)
947 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
949 if (p->base_offset + p->full_size == q->base_offset)
951 /* Q comes after P; combine Q into P. */
953 p->full_size += q->full_size;
956 else if (q->base_offset + q->full_size == p->base_offset)
958 /* P comes after Q; combine P into Q. */
960 q->full_size += p->full_size;
965 /* Either delete Q or advance past it. */
967 prev_q->next = q->next;
971 /* Either delete P or advance past it. */
975 prev_p->next = p->next;
977 temp_slots = p->next;
984 /* Find the temp slot corresponding to the object at address X. */
986 static struct temp_slot *
987 find_temp_slot_from_address (x)
993 for (p = temp_slots; p; p = p->next)
998 else if (XEXP (p->slot, 0) == x
1000 || (GET_CODE (x) == PLUS
1001 && XEXP (x, 0) == virtual_stack_vars_rtx
1002 && GET_CODE (XEXP (x, 1)) == CONST_INT
1003 && INTVAL (XEXP (x, 1)) >= p->base_offset
1004 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
1007 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1008 for (next = p->address; next; next = XEXP (next, 1))
1009 if (XEXP (next, 0) == x)
1013 /* If we have a sum involving a register, see if it points to a temp
1015 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
1016 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
1018 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG
1019 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
1025 /* Indicate that NEW is an alternate way of referring to the temp slot
1026 that previously was known by OLD. */
1029 update_temp_slot_address (old, new)
1032 struct temp_slot *p;
1034 if (rtx_equal_p (old, new))
1037 p = find_temp_slot_from_address (old);
1039 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1040 is a register, see if one operand of the PLUS is a temporary
1041 location. If so, NEW points into it. Otherwise, if both OLD and
1042 NEW are a PLUS and if there is a register in common between them.
1043 If so, try a recursive call on those values. */
1046 if (GET_CODE (old) != PLUS)
1049 if (GET_CODE (new) == REG)
1051 update_temp_slot_address (XEXP (old, 0), new);
1052 update_temp_slot_address (XEXP (old, 1), new);
1055 else if (GET_CODE (new) != PLUS)
1058 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1059 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1060 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1061 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1062 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1063 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1064 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1065 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1070 /* Otherwise add an alias for the temp's address. */
1071 else if (p->address == 0)
1075 if (GET_CODE (p->address) != EXPR_LIST)
1076 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1078 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1082 /* If X could be a reference to a temporary slot, mark the fact that its
1083 address was taken. */
1086 mark_temp_addr_taken (x)
1089 struct temp_slot *p;
1094 /* If X is not in memory or is at a constant address, it cannot be in
1095 a temporary slot. */
1096 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1099 p = find_temp_slot_from_address (XEXP (x, 0));
1104 /* If X could be a reference to a temporary slot, mark that slot as
1105 belonging to the to one level higher than the current level. If X
1106 matched one of our slots, just mark that one. Otherwise, we can't
1107 easily predict which it is, so upgrade all of them. Kept slots
1108 need not be touched.
1110 This is called when an ({...}) construct occurs and a statement
1111 returns a value in memory. */
1114 preserve_temp_slots (x)
1117 struct temp_slot *p = 0;
1119 /* If there is no result, we still might have some objects whose address
1120 were taken, so we need to make sure they stay around. */
1123 for (p = temp_slots; p; p = p->next)
1124 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1130 /* If X is a register that is being used as a pointer, see if we have
1131 a temporary slot we know it points to. To be consistent with
1132 the code below, we really should preserve all non-kept slots
1133 if we can't find a match, but that seems to be much too costly. */
1134 if (GET_CODE (x) == REG && REG_POINTER (x))
1135 p = find_temp_slot_from_address (x);
1137 /* If X is not in memory or is at a constant address, it cannot be in
1138 a temporary slot, but it can contain something whose address was
1140 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1142 for (p = temp_slots; p; p = p->next)
1143 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1149 /* First see if we can find a match. */
1151 p = find_temp_slot_from_address (XEXP (x, 0));
1155 /* Move everything at our level whose address was taken to our new
1156 level in case we used its address. */
1157 struct temp_slot *q;
1159 if (p->level == temp_slot_level)
1161 for (q = temp_slots; q; q = q->next)
1162 if (q != p && q->addr_taken && q->level == p->level)
1171 /* Otherwise, preserve all non-kept slots at this level. */
1172 for (p = temp_slots; p; p = p->next)
1173 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1177 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1178 with that RTL_EXPR, promote it into a temporary slot at the present
1179 level so it will not be freed when we free slots made in the
1183 preserve_rtl_expr_result (x)
1186 struct temp_slot *p;
1188 /* If X is not in memory or is at a constant address, it cannot be in
1189 a temporary slot. */
1190 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1193 /* If we can find a match, move it to our level unless it is already at
1195 p = find_temp_slot_from_address (XEXP (x, 0));
1198 p->level = MIN (p->level, temp_slot_level);
1205 /* Free all temporaries used so far. This is normally called at the end
1206 of generating code for a statement. Don't free any temporaries
1207 currently in use for an RTL_EXPR that hasn't yet been emitted.
1208 We could eventually do better than this since it can be reused while
1209 generating the same RTL_EXPR, but this is complex and probably not
1215 struct temp_slot *p;
1217 for (p = temp_slots; p; p = p->next)
1218 if (p->in_use && p->level == temp_slot_level && ! p->keep
1219 && p->rtl_expr == 0)
1222 combine_temp_slots ();
1225 /* Free all temporary slots used in T, an RTL_EXPR node. */
1228 free_temps_for_rtl_expr (t)
1231 struct temp_slot *p;
1233 for (p = temp_slots; p; p = p->next)
1234 if (p->rtl_expr == t)
1236 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1237 needs to be preserved. This can happen if a temporary in
1238 the RTL_EXPR was addressed; preserve_temp_slots will move
1239 the temporary into a higher level. */
1240 if (temp_slot_level <= p->level)
1243 p->rtl_expr = NULL_TREE;
1246 combine_temp_slots ();
1249 /* Mark all temporaries ever allocated in this function as not suitable
1250 for reuse until the current level is exited. */
1253 mark_all_temps_used ()
1255 struct temp_slot *p;
1257 for (p = temp_slots; p; p = p->next)
1259 p->in_use = p->keep = 1;
1260 p->level = MIN (p->level, temp_slot_level);
1264 /* Push deeper into the nesting level for stack temporaries. */
1272 /* Likewise, but save the new level as the place to allocate variables
1277 push_temp_slots_for_block ()
1281 var_temp_slot_level = temp_slot_level;
1284 /* Likewise, but save the new level as the place to allocate temporaries
1285 for TARGET_EXPRs. */
1288 push_temp_slots_for_target ()
1292 target_temp_slot_level = temp_slot_level;
1295 /* Set and get the value of target_temp_slot_level. The only
1296 permitted use of these functions is to save and restore this value. */
1299 get_target_temp_slot_level ()
1301 return target_temp_slot_level;
1305 set_target_temp_slot_level (level)
1308 target_temp_slot_level = level;
1312 /* Pop a temporary nesting level. All slots in use in the current level
1318 struct temp_slot *p;
1320 for (p = temp_slots; p; p = p->next)
1321 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1324 combine_temp_slots ();
1329 /* Initialize temporary slots. */
1334 /* We have not allocated any temporaries yet. */
1336 temp_slot_level = 0;
1337 var_temp_slot_level = 0;
1338 target_temp_slot_level = 0;
1341 /* Retroactively move an auto variable from a register to a stack slot.
1342 This is done when an address-reference to the variable is seen. */
1345 put_var_into_stack (decl)
1349 enum machine_mode promoted_mode, decl_mode;
1350 struct function *function = 0;
1352 int can_use_addressof;
1353 int volatilep = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl);
1354 int usedp = (TREE_USED (decl)
1355 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0));
1357 context = decl_function_context (decl);
1359 /* Get the current rtl used for this object and its original mode. */
1360 reg = (TREE_CODE (decl) == SAVE_EXPR
1361 ? SAVE_EXPR_RTL (decl)
1362 : DECL_RTL_IF_SET (decl));
1364 /* No need to do anything if decl has no rtx yet
1365 since in that case caller is setting TREE_ADDRESSABLE
1366 and a stack slot will be assigned when the rtl is made. */
1370 /* Get the declared mode for this object. */
1371 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1372 : DECL_MODE (decl));
1373 /* Get the mode it's actually stored in. */
1374 promoted_mode = GET_MODE (reg);
1376 /* If this variable comes from an outer function, find that
1377 function's saved context. Don't use find_function_data here,
1378 because it might not be in any active function.
1379 FIXME: Is that really supposed to happen?
1380 It does in ObjC at least. */
1381 if (context != current_function_decl && context != inline_function_decl)
1382 for (function = outer_function_chain; function; function = function->outer)
1383 if (function->decl == context)
1386 /* If this is a variable-size object with a pseudo to address it,
1387 put that pseudo into the stack, if the var is nonlocal. */
1388 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl)
1389 && GET_CODE (reg) == MEM
1390 && GET_CODE (XEXP (reg, 0)) == REG
1391 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1393 reg = XEXP (reg, 0);
1394 decl_mode = promoted_mode = GET_MODE (reg);
1400 /* FIXME make it work for promoted modes too */
1401 && decl_mode == promoted_mode
1402 #ifdef NON_SAVING_SETJMP
1403 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1407 /* If we can't use ADDRESSOF, make sure we see through one we already
1409 if (! can_use_addressof && GET_CODE (reg) == MEM
1410 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1411 reg = XEXP (XEXP (reg, 0), 0);
1413 /* Now we should have a value that resides in one or more pseudo regs. */
1415 if (GET_CODE (reg) == REG)
1417 /* If this variable lives in the current function and we don't need
1418 to put things in the stack for the sake of setjmp, try to keep it
1419 in a register until we know we actually need the address. */
1420 if (can_use_addressof)
1421 gen_mem_addressof (reg, decl);
1423 put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode,
1424 decl_mode, volatilep, 0, usedp, 0);
1426 else if (GET_CODE (reg) == CONCAT)
1428 /* A CONCAT contains two pseudos; put them both in the stack.
1429 We do it so they end up consecutive.
1430 We fixup references to the parts only after we fixup references
1431 to the whole CONCAT, lest we do double fixups for the latter
1433 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1434 tree part_type = (*lang_hooks.types.type_for_mode) (part_mode, 0);
1435 rtx lopart = XEXP (reg, 0);
1436 rtx hipart = XEXP (reg, 1);
1437 #ifdef FRAME_GROWS_DOWNWARD
1438 /* Since part 0 should have a lower address, do it second. */
1439 put_reg_into_stack (function, hipart, part_type, part_mode,
1440 part_mode, volatilep, 0, 0, 0);
1441 put_reg_into_stack (function, lopart, part_type, part_mode,
1442 part_mode, volatilep, 0, 0, 0);
1444 put_reg_into_stack (function, lopart, part_type, part_mode,
1445 part_mode, volatilep, 0, 0, 0);
1446 put_reg_into_stack (function, hipart, part_type, part_mode,
1447 part_mode, volatilep, 0, 0, 0);
1450 /* Change the CONCAT into a combined MEM for both parts. */
1451 PUT_CODE (reg, MEM);
1452 MEM_ATTRS (reg) = 0;
1454 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1455 already computed alias sets. Here we want to re-generate. */
1457 SET_DECL_RTL (decl, NULL);
1458 set_mem_attributes (reg, decl, 1);
1460 SET_DECL_RTL (decl, reg);
1462 /* The two parts are in memory order already.
1463 Use the lower parts address as ours. */
1464 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1465 /* Prevent sharing of rtl that might lose. */
1466 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1467 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1470 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl),
1472 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0);
1473 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0);
1480 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1481 into the stack frame of FUNCTION (0 means the current function).
1482 DECL_MODE is the machine mode of the user-level data type.
1483 PROMOTED_MODE is the machine mode of the register.
1484 VOLATILE_P is nonzero if this is for a "volatile" decl.
1485 USED_P is nonzero if this reg might have already been used in an insn. */
1488 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1489 original_regno, used_p, ht)
1490 struct function *function;
1493 enum machine_mode promoted_mode, decl_mode;
1495 unsigned int original_regno;
1497 struct hash_table *ht;
1499 struct function *func = function ? function : cfun;
1501 unsigned int regno = original_regno;
1504 regno = REGNO (reg);
1506 if (regno < func->x_max_parm_reg)
1507 new = func->x_parm_reg_stack_loc[regno];
1510 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func);
1512 PUT_CODE (reg, MEM);
1513 PUT_MODE (reg, decl_mode);
1514 XEXP (reg, 0) = XEXP (new, 0);
1515 MEM_ATTRS (reg) = 0;
1516 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1517 MEM_VOLATILE_P (reg) = volatile_p;
1519 /* If this is a memory ref that contains aggregate components,
1520 mark it as such for cse and loop optimize. If we are reusing a
1521 previously generated stack slot, then we need to copy the bit in
1522 case it was set for other reasons. For instance, it is set for
1523 __builtin_va_alist. */
1526 MEM_SET_IN_STRUCT_P (reg,
1527 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1528 set_mem_alias_set (reg, get_alias_set (type));
1532 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht);
1535 /* Make sure that all refs to the variable, previously made
1536 when it was a register, are fixed up to be valid again.
1537 See function above for meaning of arguments. */
1540 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht)
1541 struct function *function;
1544 enum machine_mode promoted_mode;
1545 struct hash_table *ht;
1547 int unsigned_p = type ? TREE_UNSIGNED (type) : 0;
1551 struct var_refs_queue *temp;
1554 = (struct var_refs_queue *) ggc_alloc (sizeof (struct var_refs_queue));
1555 temp->modified = reg;
1556 temp->promoted_mode = promoted_mode;
1557 temp->unsignedp = unsigned_p;
1558 temp->next = function->fixup_var_refs_queue;
1559 function->fixup_var_refs_queue = temp;
1562 /* Variable is local; fix it up now. */
1563 fixup_var_refs (reg, promoted_mode, unsigned_p, reg, ht);
1567 fixup_var_refs (var, promoted_mode, unsignedp, may_share, ht)
1569 enum machine_mode promoted_mode;
1571 struct hash_table *ht;
1575 rtx first_insn = get_insns ();
1576 struct sequence_stack *stack = seq_stack;
1577 tree rtl_exps = rtl_expr_chain;
1579 /* If there's a hash table, it must record all uses of VAR. */
1584 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp,
1589 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp,
1590 stack == 0, may_share);
1592 /* Scan all pending sequences too. */
1593 for (; stack; stack = stack->next)
1595 push_to_full_sequence (stack->first, stack->last);
1596 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp,
1597 stack->next != 0, may_share);
1598 /* Update remembered end of sequence
1599 in case we added an insn at the end. */
1600 stack->last = get_last_insn ();
1604 /* Scan all waiting RTL_EXPRs too. */
1605 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1607 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1608 if (seq != const0_rtx && seq != 0)
1610 push_to_sequence (seq);
1611 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1618 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1619 some part of an insn. Return a struct fixup_replacement whose OLD
1620 value is equal to X. Allocate a new structure if no such entry exists. */
1622 static struct fixup_replacement *
1623 find_fixup_replacement (replacements, x)
1624 struct fixup_replacement **replacements;
1627 struct fixup_replacement *p;
1629 /* See if we have already replaced this. */
1630 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1635 p = (struct fixup_replacement *) xmalloc (sizeof (struct fixup_replacement));
1638 p->next = *replacements;
1645 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1646 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1647 for the current function. MAY_SHARE is either a MEM that is not
1648 to be unshared or a list of them. */
1651 fixup_var_refs_insns (insn, var, promoted_mode, unsignedp, toplevel, may_share)
1654 enum machine_mode promoted_mode;
1661 /* fixup_var_refs_insn might modify insn, so save its next
1663 rtx next = NEXT_INSN (insn);
1665 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1666 the three sequences they (potentially) contain, and process
1667 them recursively. The CALL_INSN itself is not interesting. */
1669 if (GET_CODE (insn) == CALL_INSN
1670 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1674 /* Look at the Normal call, sibling call and tail recursion
1675 sequences attached to the CALL_PLACEHOLDER. */
1676 for (i = 0; i < 3; i++)
1678 rtx seq = XEXP (PATTERN (insn), i);
1681 push_to_sequence (seq);
1682 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1684 XEXP (PATTERN (insn), i) = get_insns ();
1690 else if (INSN_P (insn))
1691 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel,
1698 /* Look up the insns which reference VAR in HT and fix them up. Other
1699 arguments are the same as fixup_var_refs_insns.
1701 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1702 because the hash table will point straight to the interesting insn
1703 (inside the CALL_PLACEHOLDER). */
1706 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp, may_share)
1707 struct hash_table *ht;
1709 enum machine_mode promoted_mode;
1713 struct insns_for_mem_entry *ime
1714 = (struct insns_for_mem_entry *) hash_lookup (ht, var,
1715 /*create=*/0, /*copy=*/0);
1718 for (insn_list = ime->insns; insn_list != 0; insn_list = XEXP (insn_list, 1))
1719 if (INSN_P (XEXP (insn_list, 0)))
1720 fixup_var_refs_insn (XEXP (insn_list, 0), var, promoted_mode,
1721 unsignedp, 1, may_share);
1725 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1726 the insn under examination, VAR is the variable to fix up
1727 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1728 TOPLEVEL is nonzero if this is the main insn chain for this
1732 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel, no_share)
1735 enum machine_mode promoted_mode;
1741 rtx set, prev, prev_set;
1744 /* Remember the notes in case we delete the insn. */
1745 note = REG_NOTES (insn);
1747 /* If this is a CLOBBER of VAR, delete it.
1749 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1750 and REG_RETVAL notes too. */
1751 if (GET_CODE (PATTERN (insn)) == CLOBBER
1752 && (XEXP (PATTERN (insn), 0) == var
1753 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1754 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1755 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1757 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1758 /* The REG_LIBCALL note will go away since we are going to
1759 turn INSN into a NOTE, so just delete the
1760 corresponding REG_RETVAL note. */
1761 remove_note (XEXP (note, 0),
1762 find_reg_note (XEXP (note, 0), REG_RETVAL,
1768 /* The insn to load VAR from a home in the arglist
1769 is now a no-op. When we see it, just delete it.
1770 Similarly if this is storing VAR from a register from which
1771 it was loaded in the previous insn. This will occur
1772 when an ADDRESSOF was made for an arglist slot. */
1774 && (set = single_set (insn)) != 0
1775 && SET_DEST (set) == var
1776 /* If this represents the result of an insn group,
1777 don't delete the insn. */
1778 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1779 && (rtx_equal_p (SET_SRC (set), var)
1780 || (GET_CODE (SET_SRC (set)) == REG
1781 && (prev = prev_nonnote_insn (insn)) != 0
1782 && (prev_set = single_set (prev)) != 0
1783 && SET_DEST (prev_set) == SET_SRC (set)
1784 && rtx_equal_p (SET_SRC (prev_set), var))))
1790 struct fixup_replacement *replacements = 0;
1791 rtx next_insn = NEXT_INSN (insn);
1793 if (SMALL_REGISTER_CLASSES)
1795 /* If the insn that copies the results of a CALL_INSN
1796 into a pseudo now references VAR, we have to use an
1797 intermediate pseudo since we want the life of the
1798 return value register to be only a single insn.
1800 If we don't use an intermediate pseudo, such things as
1801 address computations to make the address of VAR valid
1802 if it is not can be placed between the CALL_INSN and INSN.
1804 To make sure this doesn't happen, we record the destination
1805 of the CALL_INSN and see if the next insn uses both that
1808 if (call_dest != 0 && GET_CODE (insn) == INSN
1809 && reg_mentioned_p (var, PATTERN (insn))
1810 && reg_mentioned_p (call_dest, PATTERN (insn)))
1812 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1814 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1816 PATTERN (insn) = replace_rtx (PATTERN (insn),
1820 if (GET_CODE (insn) == CALL_INSN
1821 && GET_CODE (PATTERN (insn)) == SET)
1822 call_dest = SET_DEST (PATTERN (insn));
1823 else if (GET_CODE (insn) == CALL_INSN
1824 && GET_CODE (PATTERN (insn)) == PARALLEL
1825 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1826 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1831 /* See if we have to do anything to INSN now that VAR is in
1832 memory. If it needs to be loaded into a pseudo, use a single
1833 pseudo for the entire insn in case there is a MATCH_DUP
1834 between two operands. We pass a pointer to the head of
1835 a list of struct fixup_replacements. If fixup_var_refs_1
1836 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1837 it will record them in this list.
1839 If it allocated a pseudo for any replacement, we copy into
1842 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1843 &replacements, no_share);
1845 /* If this is last_parm_insn, and any instructions were output
1846 after it to fix it up, then we must set last_parm_insn to
1847 the last such instruction emitted. */
1848 if (insn == last_parm_insn)
1849 last_parm_insn = PREV_INSN (next_insn);
1851 while (replacements)
1853 struct fixup_replacement *next;
1855 if (GET_CODE (replacements->new) == REG)
1860 /* OLD might be a (subreg (mem)). */
1861 if (GET_CODE (replacements->old) == SUBREG)
1863 = fixup_memory_subreg (replacements->old, insn,
1867 = fixup_stack_1 (replacements->old, insn);
1869 insert_before = insn;
1871 /* If we are changing the mode, do a conversion.
1872 This might be wasteful, but combine.c will
1873 eliminate much of the waste. */
1875 if (GET_MODE (replacements->new)
1876 != GET_MODE (replacements->old))
1879 convert_move (replacements->new,
1880 replacements->old, unsignedp);
1881 seq = gen_sequence ();
1885 seq = gen_move_insn (replacements->new,
1888 emit_insn_before (seq, insert_before);
1891 next = replacements->next;
1892 free (replacements);
1893 replacements = next;
1897 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1898 But don't touch other insns referred to by reg-notes;
1899 we will get them elsewhere. */
1902 if (GET_CODE (note) != INSN_LIST)
1904 = walk_fixup_memory_subreg (XEXP (note, 0), insn,
1906 note = XEXP (note, 1);
1910 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1911 See if the rtx expression at *LOC in INSN needs to be changed.
1913 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1914 contain a list of original rtx's and replacements. If we find that we need
1915 to modify this insn by replacing a memory reference with a pseudo or by
1916 making a new MEM to implement a SUBREG, we consult that list to see if
1917 we have already chosen a replacement. If none has already been allocated,
1918 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1919 or the SUBREG, as appropriate, to the pseudo. */
1922 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements, no_share)
1924 enum machine_mode promoted_mode;
1927 struct fixup_replacement **replacements;
1932 RTX_CODE code = GET_CODE (x);
1935 struct fixup_replacement *replacement;
1940 if (XEXP (x, 0) == var)
1942 /* Prevent sharing of rtl that might lose. */
1943 rtx sub = copy_rtx (XEXP (var, 0));
1945 if (! validate_change (insn, loc, sub, 0))
1947 rtx y = gen_reg_rtx (GET_MODE (sub));
1950 /* We should be able to replace with a register or all is lost.
1951 Note that we can't use validate_change to verify this, since
1952 we're not caring for replacing all dups simultaneously. */
1953 if (! validate_replace_rtx (*loc, y, insn))
1956 /* Careful! First try to recognize a direct move of the
1957 value, mimicking how things are done in gen_reload wrt
1958 PLUS. Consider what happens when insn is a conditional
1959 move instruction and addsi3 clobbers flags. */
1962 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1963 seq = gen_sequence ();
1966 if (recog_memoized (new_insn) < 0)
1968 /* That failed. Fall back on force_operand and hope. */
1971 sub = force_operand (sub, y);
1973 emit_insn (gen_move_insn (y, sub));
1974 seq = gen_sequence ();
1979 /* Don't separate setter from user. */
1980 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1981 insn = PREV_INSN (insn);
1984 emit_insn_before (seq, insn);
1992 /* If we already have a replacement, use it. Otherwise,
1993 try to fix up this address in case it is invalid. */
1995 replacement = find_fixup_replacement (replacements, var);
1996 if (replacement->new)
1998 *loc = replacement->new;
2002 *loc = replacement->new = x = fixup_stack_1 (x, insn);
2004 /* Unless we are forcing memory to register or we changed the mode,
2005 we can leave things the way they are if the insn is valid. */
2007 INSN_CODE (insn) = -1;
2008 if (! flag_force_mem && GET_MODE (x) == promoted_mode
2009 && recog_memoized (insn) >= 0)
2012 *loc = replacement->new = gen_reg_rtx (promoted_mode);
2016 /* If X contains VAR, we need to unshare it here so that we update
2017 each occurrence separately. But all identical MEMs in one insn
2018 must be replaced with the same rtx because of the possibility of
2021 if (reg_mentioned_p (var, x))
2023 replacement = find_fixup_replacement (replacements, x);
2024 if (replacement->new == 0)
2025 replacement->new = copy_most_rtx (x, no_share);
2027 *loc = x = replacement->new;
2028 code = GET_CODE (x);
2045 /* Note that in some cases those types of expressions are altered
2046 by optimize_bit_field, and do not survive to get here. */
2047 if (XEXP (x, 0) == var
2048 || (GET_CODE (XEXP (x, 0)) == SUBREG
2049 && SUBREG_REG (XEXP (x, 0)) == var))
2051 /* Get TEM as a valid MEM in the mode presently in the insn.
2053 We don't worry about the possibility of MATCH_DUP here; it
2054 is highly unlikely and would be tricky to handle. */
2057 if (GET_CODE (tem) == SUBREG)
2059 if (GET_MODE_BITSIZE (GET_MODE (tem))
2060 > GET_MODE_BITSIZE (GET_MODE (var)))
2062 replacement = find_fixup_replacement (replacements, var);
2063 if (replacement->new == 0)
2064 replacement->new = gen_reg_rtx (GET_MODE (var));
2065 SUBREG_REG (tem) = replacement->new;
2067 /* The following code works only if we have a MEM, so we
2068 need to handle the subreg here. We directly substitute
2069 it assuming that a subreg must be OK here. We already
2070 scheduled a replacement to copy the mem into the
2076 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2079 tem = fixup_stack_1 (tem, insn);
2081 /* Unless we want to load from memory, get TEM into the proper mode
2082 for an extract from memory. This can only be done if the
2083 extract is at a constant position and length. */
2085 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2086 && GET_CODE (XEXP (x, 2)) == CONST_INT
2087 && ! mode_dependent_address_p (XEXP (tem, 0))
2088 && ! MEM_VOLATILE_P (tem))
2090 enum machine_mode wanted_mode = VOIDmode;
2091 enum machine_mode is_mode = GET_MODE (tem);
2092 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2094 if (GET_CODE (x) == ZERO_EXTRACT)
2096 enum machine_mode new_mode
2097 = mode_for_extraction (EP_extzv, 1);
2098 if (new_mode != MAX_MACHINE_MODE)
2099 wanted_mode = new_mode;
2101 else if (GET_CODE (x) == SIGN_EXTRACT)
2103 enum machine_mode new_mode
2104 = mode_for_extraction (EP_extv, 1);
2105 if (new_mode != MAX_MACHINE_MODE)
2106 wanted_mode = new_mode;
2109 /* If we have a narrower mode, we can do something. */
2110 if (wanted_mode != VOIDmode
2111 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2113 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2114 rtx old_pos = XEXP (x, 2);
2117 /* If the bytes and bits are counted differently, we
2118 must adjust the offset. */
2119 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2120 offset = (GET_MODE_SIZE (is_mode)
2121 - GET_MODE_SIZE (wanted_mode) - offset);
2123 pos %= GET_MODE_BITSIZE (wanted_mode);
2125 newmem = adjust_address_nv (tem, wanted_mode, offset);
2127 /* Make the change and see if the insn remains valid. */
2128 INSN_CODE (insn) = -1;
2129 XEXP (x, 0) = newmem;
2130 XEXP (x, 2) = GEN_INT (pos);
2132 if (recog_memoized (insn) >= 0)
2135 /* Otherwise, restore old position. XEXP (x, 0) will be
2137 XEXP (x, 2) = old_pos;
2141 /* If we get here, the bitfield extract insn can't accept a memory
2142 reference. Copy the input into a register. */
2144 tem1 = gen_reg_rtx (GET_MODE (tem));
2145 emit_insn_before (gen_move_insn (tem1, tem), insn);
2152 if (SUBREG_REG (x) == var)
2154 /* If this is a special SUBREG made because VAR was promoted
2155 from a wider mode, replace it with VAR and call ourself
2156 recursively, this time saying that the object previously
2157 had its current mode (by virtue of the SUBREG). */
2159 if (SUBREG_PROMOTED_VAR_P (x))
2162 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements,
2167 /* If this SUBREG makes VAR wider, it has become a paradoxical
2168 SUBREG with VAR in memory, but these aren't allowed at this
2169 stage of the compilation. So load VAR into a pseudo and take
2170 a SUBREG of that pseudo. */
2171 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2173 replacement = find_fixup_replacement (replacements, var);
2174 if (replacement->new == 0)
2175 replacement->new = gen_reg_rtx (promoted_mode);
2176 SUBREG_REG (x) = replacement->new;
2180 /* See if we have already found a replacement for this SUBREG.
2181 If so, use it. Otherwise, make a MEM and see if the insn
2182 is recognized. If not, or if we should force MEM into a register,
2183 make a pseudo for this SUBREG. */
2184 replacement = find_fixup_replacement (replacements, x);
2185 if (replacement->new)
2187 *loc = replacement->new;
2191 replacement->new = *loc = fixup_memory_subreg (x, insn,
2194 INSN_CODE (insn) = -1;
2195 if (! flag_force_mem && recog_memoized (insn) >= 0)
2198 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2204 /* First do special simplification of bit-field references. */
2205 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2206 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2207 optimize_bit_field (x, insn, 0);
2208 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2209 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2210 optimize_bit_field (x, insn, 0);
2212 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2213 into a register and then store it back out. */
2214 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2215 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2216 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2217 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2218 > GET_MODE_SIZE (GET_MODE (var))))
2220 replacement = find_fixup_replacement (replacements, var);
2221 if (replacement->new == 0)
2222 replacement->new = gen_reg_rtx (GET_MODE (var));
2224 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2225 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2228 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2229 insn into a pseudo and store the low part of the pseudo into VAR. */
2230 if (GET_CODE (SET_DEST (x)) == SUBREG
2231 && SUBREG_REG (SET_DEST (x)) == var
2232 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2233 > GET_MODE_SIZE (GET_MODE (var))))
2235 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2236 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2243 rtx dest = SET_DEST (x);
2244 rtx src = SET_SRC (x);
2245 rtx outerdest = dest;
2247 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2248 || GET_CODE (dest) == SIGN_EXTRACT
2249 || GET_CODE (dest) == ZERO_EXTRACT)
2250 dest = XEXP (dest, 0);
2252 if (GET_CODE (src) == SUBREG)
2253 src = SUBREG_REG (src);
2255 /* If VAR does not appear at the top level of the SET
2256 just scan the lower levels of the tree. */
2258 if (src != var && dest != var)
2261 /* We will need to rerecognize this insn. */
2262 INSN_CODE (insn) = -1;
2264 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var
2265 && mode_for_extraction (EP_insv, -1) != MAX_MACHINE_MODE)
2267 /* Since this case will return, ensure we fixup all the
2269 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2270 insn, replacements, no_share);
2271 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2272 insn, replacements, no_share);
2273 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2274 insn, replacements, no_share);
2276 tem = XEXP (outerdest, 0);
2278 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2279 that may appear inside a ZERO_EXTRACT.
2280 This was legitimate when the MEM was a REG. */
2281 if (GET_CODE (tem) == SUBREG
2282 && SUBREG_REG (tem) == var)
2283 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2285 tem = fixup_stack_1 (tem, insn);
2287 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2288 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2289 && ! mode_dependent_address_p (XEXP (tem, 0))
2290 && ! MEM_VOLATILE_P (tem))
2292 enum machine_mode wanted_mode;
2293 enum machine_mode is_mode = GET_MODE (tem);
2294 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2296 wanted_mode = mode_for_extraction (EP_insv, 0);
2298 /* If we have a narrower mode, we can do something. */
2299 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2301 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2302 rtx old_pos = XEXP (outerdest, 2);
2305 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2306 offset = (GET_MODE_SIZE (is_mode)
2307 - GET_MODE_SIZE (wanted_mode) - offset);
2309 pos %= GET_MODE_BITSIZE (wanted_mode);
2311 newmem = adjust_address_nv (tem, wanted_mode, offset);
2313 /* Make the change and see if the insn remains valid. */
2314 INSN_CODE (insn) = -1;
2315 XEXP (outerdest, 0) = newmem;
2316 XEXP (outerdest, 2) = GEN_INT (pos);
2318 if (recog_memoized (insn) >= 0)
2321 /* Otherwise, restore old position. XEXP (x, 0) will be
2323 XEXP (outerdest, 2) = old_pos;
2327 /* If we get here, the bit-field store doesn't allow memory
2328 or isn't located at a constant position. Load the value into
2329 a register, do the store, and put it back into memory. */
2331 tem1 = gen_reg_rtx (GET_MODE (tem));
2332 emit_insn_before (gen_move_insn (tem1, tem), insn);
2333 emit_insn_after (gen_move_insn (tem, tem1), insn);
2334 XEXP (outerdest, 0) = tem1;
2338 /* STRICT_LOW_PART is a no-op on memory references
2339 and it can cause combinations to be unrecognizable,
2342 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2343 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2345 /* A valid insn to copy VAR into or out of a register
2346 must be left alone, to avoid an infinite loop here.
2347 If the reference to VAR is by a subreg, fix that up,
2348 since SUBREG is not valid for a memref.
2349 Also fix up the address of the stack slot.
2351 Note that we must not try to recognize the insn until
2352 after we know that we have valid addresses and no
2353 (subreg (mem ...) ...) constructs, since these interfere
2354 with determining the validity of the insn. */
2356 if ((SET_SRC (x) == var
2357 || (GET_CODE (SET_SRC (x)) == SUBREG
2358 && SUBREG_REG (SET_SRC (x)) == var))
2359 && (GET_CODE (SET_DEST (x)) == REG
2360 || (GET_CODE (SET_DEST (x)) == SUBREG
2361 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2362 && GET_MODE (var) == promoted_mode
2363 && x == single_set (insn))
2367 if (GET_CODE (SET_SRC (x)) == SUBREG
2368 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
2369 > GET_MODE_SIZE (GET_MODE (var))))
2371 /* This (subreg VAR) is now a paradoxical subreg. We need
2372 to replace VAR instead of the subreg. */
2373 replacement = find_fixup_replacement (replacements, var);
2374 if (replacement->new == NULL_RTX)
2375 replacement->new = gen_reg_rtx (GET_MODE (var));
2376 SUBREG_REG (SET_SRC (x)) = replacement->new;
2380 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2381 if (replacement->new)
2382 SET_SRC (x) = replacement->new;
2383 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2384 SET_SRC (x) = replacement->new
2385 = fixup_memory_subreg (SET_SRC (x), insn, promoted_mode,
2388 SET_SRC (x) = replacement->new
2389 = fixup_stack_1 (SET_SRC (x), insn);
2392 if (recog_memoized (insn) >= 0)
2395 /* INSN is not valid, but we know that we want to
2396 copy SET_SRC (x) to SET_DEST (x) in some way. So
2397 we generate the move and see whether it requires more
2398 than one insn. If it does, we emit those insns and
2399 delete INSN. Otherwise, we an just replace the pattern
2400 of INSN; we have already verified above that INSN has
2401 no other function that to do X. */
2403 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2404 if (GET_CODE (pat) == SEQUENCE)
2406 last = emit_insn_before (pat, insn);
2408 /* INSN might have REG_RETVAL or other important notes, so
2409 we need to store the pattern of the last insn in the
2410 sequence into INSN similarly to the normal case. LAST
2411 should not have REG_NOTES, but we allow them if INSN has
2413 if (REG_NOTES (last) && REG_NOTES (insn))
2415 if (REG_NOTES (last))
2416 REG_NOTES (insn) = REG_NOTES (last);
2417 PATTERN (insn) = PATTERN (last);
2422 PATTERN (insn) = pat;
2427 if ((SET_DEST (x) == var
2428 || (GET_CODE (SET_DEST (x)) == SUBREG
2429 && SUBREG_REG (SET_DEST (x)) == var))
2430 && (GET_CODE (SET_SRC (x)) == REG
2431 || (GET_CODE (SET_SRC (x)) == SUBREG
2432 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2433 && GET_MODE (var) == promoted_mode
2434 && x == single_set (insn))
2438 if (GET_CODE (SET_DEST (x)) == SUBREG)
2439 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn,
2442 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2444 if (recog_memoized (insn) >= 0)
2447 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2448 if (GET_CODE (pat) == SEQUENCE)
2450 last = emit_insn_before (pat, insn);
2452 /* INSN might have REG_RETVAL or other important notes, so
2453 we need to store the pattern of the last insn in the
2454 sequence into INSN similarly to the normal case. LAST
2455 should not have REG_NOTES, but we allow them if INSN has
2457 if (REG_NOTES (last) && REG_NOTES (insn))
2459 if (REG_NOTES (last))
2460 REG_NOTES (insn) = REG_NOTES (last);
2461 PATTERN (insn) = PATTERN (last);
2466 PATTERN (insn) = pat;
2471 /* Otherwise, storing into VAR must be handled specially
2472 by storing into a temporary and copying that into VAR
2473 with a new insn after this one. Note that this case
2474 will be used when storing into a promoted scalar since
2475 the insn will now have different modes on the input
2476 and output and hence will be invalid (except for the case
2477 of setting it to a constant, which does not need any
2478 change if it is valid). We generate extra code in that case,
2479 but combine.c will eliminate it. */
2484 rtx fixeddest = SET_DEST (x);
2485 enum machine_mode temp_mode;
2487 /* STRICT_LOW_PART can be discarded, around a MEM. */
2488 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2489 fixeddest = XEXP (fixeddest, 0);
2490 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2491 if (GET_CODE (fixeddest) == SUBREG)
2493 fixeddest = fixup_memory_subreg (fixeddest, insn,
2495 temp_mode = GET_MODE (fixeddest);
2499 fixeddest = fixup_stack_1 (fixeddest, insn);
2500 temp_mode = promoted_mode;
2503 temp = gen_reg_rtx (temp_mode);
2505 emit_insn_after (gen_move_insn (fixeddest,
2506 gen_lowpart (GET_MODE (fixeddest),
2510 SET_DEST (x) = temp;
2518 /* Nothing special about this RTX; fix its operands. */
2520 fmt = GET_RTX_FORMAT (code);
2521 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2524 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements,
2526 else if (fmt[i] == 'E')
2529 for (j = 0; j < XVECLEN (x, i); j++)
2530 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2531 insn, replacements, no_share);
2536 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2537 The REG was placed on the stack, so X now has the form (SUBREG:m1
2540 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2541 must be emitted to compute NEWADDR, put them before INSN.
2543 UNCRITICAL nonzero means accept paradoxical subregs.
2544 This is used for subregs found inside REG_NOTES. */
2547 fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2550 enum machine_mode promoted_mode;
2554 rtx mem = SUBREG_REG (x);
2555 rtx addr = XEXP (mem, 0);
2556 enum machine_mode mode = GET_MODE (x);
2559 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2560 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (mem)) && ! uncritical)
2563 offset = SUBREG_BYTE (x);
2564 if (BYTES_BIG_ENDIAN)
2565 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2566 the offset so that it points to the right location within the
2568 offset -= (GET_MODE_SIZE (promoted_mode) - GET_MODE_SIZE (GET_MODE (mem)));
2570 if (!flag_force_addr
2571 && memory_address_p (mode, plus_constant (addr, offset)))
2572 /* Shortcut if no insns need be emitted. */
2573 return adjust_address (mem, mode, offset);
2576 result = adjust_address (mem, mode, offset);
2577 emit_insn_before (gen_sequence (), insn);
2582 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2583 Replace subexpressions of X in place.
2584 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2585 Otherwise return X, with its contents possibly altered.
2587 INSN, PROMOTED_MODE and UNCRITICAL are as for
2588 fixup_memory_subreg. */
2591 walk_fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2594 enum machine_mode promoted_mode;
2604 code = GET_CODE (x);
2606 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2607 return fixup_memory_subreg (x, insn, promoted_mode, uncritical);
2609 /* Nothing special about this RTX; fix its operands. */
2611 fmt = GET_RTX_FORMAT (code);
2612 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2615 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn,
2616 promoted_mode, uncritical);
2617 else if (fmt[i] == 'E')
2620 for (j = 0; j < XVECLEN (x, i); j++)
2622 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn,
2623 promoted_mode, uncritical);
2629 /* For each memory ref within X, if it refers to a stack slot
2630 with an out of range displacement, put the address in a temp register
2631 (emitting new insns before INSN to load these registers)
2632 and alter the memory ref to use that register.
2633 Replace each such MEM rtx with a copy, to avoid clobberage. */
2636 fixup_stack_1 (x, insn)
2641 RTX_CODE code = GET_CODE (x);
2646 rtx ad = XEXP (x, 0);
2647 /* If we have address of a stack slot but it's not valid
2648 (displacement is too large), compute the sum in a register. */
2649 if (GET_CODE (ad) == PLUS
2650 && GET_CODE (XEXP (ad, 0)) == REG
2651 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2652 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2653 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2654 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2655 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2657 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2658 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2659 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2660 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2663 if (memory_address_p (GET_MODE (x), ad))
2667 temp = copy_to_reg (ad);
2668 seq = gen_sequence ();
2670 emit_insn_before (seq, insn);
2671 return replace_equiv_address (x, temp);
2676 fmt = GET_RTX_FORMAT (code);
2677 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2680 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2681 else if (fmt[i] == 'E')
2684 for (j = 0; j < XVECLEN (x, i); j++)
2685 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2691 /* Optimization: a bit-field instruction whose field
2692 happens to be a byte or halfword in memory
2693 can be changed to a move instruction.
2695 We call here when INSN is an insn to examine or store into a bit-field.
2696 BODY is the SET-rtx to be altered.
2698 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2699 (Currently this is called only from function.c, and EQUIV_MEM
2703 optimize_bit_field (body, insn, equiv_mem)
2711 enum machine_mode mode;
2713 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2714 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2715 bitfield = SET_DEST (body), destflag = 1;
2717 bitfield = SET_SRC (body), destflag = 0;
2719 /* First check that the field being stored has constant size and position
2720 and is in fact a byte or halfword suitably aligned. */
2722 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2723 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2724 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2726 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2730 /* Now check that the containing word is memory, not a register,
2731 and that it is safe to change the machine mode. */
2733 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2734 memref = XEXP (bitfield, 0);
2735 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2737 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2738 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2739 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2740 memref = SUBREG_REG (XEXP (bitfield, 0));
2741 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2743 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2744 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2747 && ! mode_dependent_address_p (XEXP (memref, 0))
2748 && ! MEM_VOLATILE_P (memref))
2750 /* Now adjust the address, first for any subreg'ing
2751 that we are now getting rid of,
2752 and then for which byte of the word is wanted. */
2754 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2757 /* Adjust OFFSET to count bits from low-address byte. */
2758 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2759 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2760 - offset - INTVAL (XEXP (bitfield, 1)));
2762 /* Adjust OFFSET to count bytes from low-address byte. */
2763 offset /= BITS_PER_UNIT;
2764 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2766 offset += (SUBREG_BYTE (XEXP (bitfield, 0))
2767 / UNITS_PER_WORD) * UNITS_PER_WORD;
2768 if (BYTES_BIG_ENDIAN)
2769 offset -= (MIN (UNITS_PER_WORD,
2770 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2771 - MIN (UNITS_PER_WORD,
2772 GET_MODE_SIZE (GET_MODE (memref))));
2776 memref = adjust_address (memref, mode, offset);
2777 insns = get_insns ();
2779 emit_insns_before (insns, insn);
2781 /* Store this memory reference where
2782 we found the bit field reference. */
2786 validate_change (insn, &SET_DEST (body), memref, 1);
2787 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2789 rtx src = SET_SRC (body);
2790 while (GET_CODE (src) == SUBREG
2791 && SUBREG_BYTE (src) == 0)
2792 src = SUBREG_REG (src);
2793 if (GET_MODE (src) != GET_MODE (memref))
2794 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2795 validate_change (insn, &SET_SRC (body), src, 1);
2797 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2798 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2799 /* This shouldn't happen because anything that didn't have
2800 one of these modes should have got converted explicitly
2801 and then referenced through a subreg.
2802 This is so because the original bit-field was
2803 handled by agg_mode and so its tree structure had
2804 the same mode that memref now has. */
2809 rtx dest = SET_DEST (body);
2811 while (GET_CODE (dest) == SUBREG
2812 && SUBREG_BYTE (dest) == 0
2813 && (GET_MODE_CLASS (GET_MODE (dest))
2814 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2815 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2817 dest = SUBREG_REG (dest);
2819 validate_change (insn, &SET_DEST (body), dest, 1);
2821 if (GET_MODE (dest) == GET_MODE (memref))
2822 validate_change (insn, &SET_SRC (body), memref, 1);
2825 /* Convert the mem ref to the destination mode. */
2826 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2829 convert_move (newreg, memref,
2830 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2834 validate_change (insn, &SET_SRC (body), newreg, 1);
2838 /* See if we can convert this extraction or insertion into
2839 a simple move insn. We might not be able to do so if this
2840 was, for example, part of a PARALLEL.
2842 If we succeed, write out any needed conversions. If we fail,
2843 it is hard to guess why we failed, so don't do anything
2844 special; just let the optimization be suppressed. */
2846 if (apply_change_group () && seq)
2847 emit_insns_before (seq, insn);
2852 /* These routines are responsible for converting virtual register references
2853 to the actual hard register references once RTL generation is complete.
2855 The following four variables are used for communication between the
2856 routines. They contain the offsets of the virtual registers from their
2857 respective hard registers. */
2859 static int in_arg_offset;
2860 static int var_offset;
2861 static int dynamic_offset;
2862 static int out_arg_offset;
2863 static int cfa_offset;
2865 /* In most machines, the stack pointer register is equivalent to the bottom
2868 #ifndef STACK_POINTER_OFFSET
2869 #define STACK_POINTER_OFFSET 0
2872 /* If not defined, pick an appropriate default for the offset of dynamically
2873 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2874 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2876 #ifndef STACK_DYNAMIC_OFFSET
2878 /* The bottom of the stack points to the actual arguments. If
2879 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2880 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2881 stack space for register parameters is not pushed by the caller, but
2882 rather part of the fixed stack areas and hence not included in
2883 `current_function_outgoing_args_size'. Nevertheless, we must allow
2884 for it when allocating stack dynamic objects. */
2886 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2887 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2888 ((ACCUMULATE_OUTGOING_ARGS \
2889 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2890 + (STACK_POINTER_OFFSET)) \
2893 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2894 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2895 + (STACK_POINTER_OFFSET))
2899 /* On most machines, the CFA coincides with the first incoming parm. */
2901 #ifndef ARG_POINTER_CFA_OFFSET
2902 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2905 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2906 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2907 register, for later use if we do need to force REG into the stack. REG is
2908 overwritten by the MEM like in put_reg_into_stack. */
2911 gen_mem_addressof (reg, decl)
2915 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2918 /* Calculate this before we start messing with decl's RTL. */
2919 HOST_WIDE_INT set = decl ? get_alias_set (decl) : 0;
2921 /* If the original REG was a user-variable, then so is the REG whose
2922 address is being taken. Likewise for unchanging. */
2923 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2924 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg);
2926 PUT_CODE (reg, MEM);
2927 MEM_ATTRS (reg) = 0;
2932 tree type = TREE_TYPE (decl);
2933 enum machine_mode decl_mode
2934 = (DECL_P (decl) ? DECL_MODE (decl) : TYPE_MODE (TREE_TYPE (decl)));
2935 rtx decl_rtl = (TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl)
2936 : DECL_RTL_IF_SET (decl));
2938 PUT_MODE (reg, decl_mode);
2940 /* Clear DECL_RTL momentarily so functions below will work
2941 properly, then set it again. */
2942 if (DECL_P (decl) && decl_rtl == reg)
2943 SET_DECL_RTL (decl, 0);
2945 set_mem_attributes (reg, decl, 1);
2946 set_mem_alias_set (reg, set);
2948 if (DECL_P (decl) && decl_rtl == reg)
2949 SET_DECL_RTL (decl, reg);
2951 if (TREE_USED (decl) || (DECL_P (decl) && DECL_INITIAL (decl) != 0))
2952 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), reg, 0);
2955 fixup_var_refs (reg, GET_MODE (reg), 0, reg, 0);
2960 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2963 flush_addressof (decl)
2966 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2967 && DECL_RTL (decl) != 0
2968 && GET_CODE (DECL_RTL (decl)) == MEM
2969 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2970 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2971 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2974 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2977 put_addressof_into_stack (r, ht)
2979 struct hash_table *ht;
2982 int volatile_p, used_p;
2984 rtx reg = XEXP (r, 0);
2986 if (GET_CODE (reg) != REG)
2989 decl = ADDRESSOF_DECL (r);
2992 type = TREE_TYPE (decl);
2993 volatile_p = (TREE_CODE (decl) != SAVE_EXPR
2994 && TREE_THIS_VOLATILE (decl));
2995 used_p = (TREE_USED (decl)
2996 || (DECL_P (decl) && DECL_INITIAL (decl) != 0));
3005 put_reg_into_stack (0, reg, type, GET_MODE (reg), GET_MODE (reg),
3006 volatile_p, ADDRESSOF_REGNO (r), used_p, ht);
3009 /* List of replacements made below in purge_addressof_1 when creating
3010 bitfield insertions. */
3011 static rtx purge_bitfield_addressof_replacements;
3013 /* List of replacements made below in purge_addressof_1 for patterns
3014 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
3015 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
3016 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
3017 enough in complex cases, e.g. when some field values can be
3018 extracted by usage MEM with narrower mode. */
3019 static rtx purge_addressof_replacements;
3021 /* Helper function for purge_addressof. See if the rtx expression at *LOC
3022 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
3023 the stack. If the function returns FALSE then the replacement could not
3027 purge_addressof_1 (loc, insn, force, store, ht)
3031 struct hash_table *ht;
3039 /* Re-start here to avoid recursion in common cases. */
3046 code = GET_CODE (x);
3048 /* If we don't return in any of the cases below, we will recurse inside
3049 the RTX, which will normally result in any ADDRESSOF being forced into
3053 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3054 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3057 else if (code == ADDRESSOF)
3061 if (GET_CODE (XEXP (x, 0)) != MEM)
3063 put_addressof_into_stack (x, ht);
3067 /* We must create a copy of the rtx because it was created by
3068 overwriting a REG rtx which is always shared. */
3069 sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3070 if (validate_change (insn, loc, sub, 0)
3071 || validate_replace_rtx (x, sub, insn))
3075 sub = force_operand (sub, NULL_RTX);
3076 if (! validate_change (insn, loc, sub, 0)
3077 && ! validate_replace_rtx (x, sub, insn))
3080 insns = gen_sequence ();
3082 emit_insn_before (insns, insn);
3086 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3088 rtx sub = XEXP (XEXP (x, 0), 0);
3090 if (GET_CODE (sub) == MEM)
3091 sub = adjust_address_nv (sub, GET_MODE (x), 0);
3092 else if (GET_CODE (sub) == REG
3093 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3095 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3097 int size_x, size_sub;
3101 /* When processing REG_NOTES look at the list of
3102 replacements done on the insn to find the register that X
3106 for (tem = purge_bitfield_addressof_replacements;
3108 tem = XEXP (XEXP (tem, 1), 1))
3109 if (rtx_equal_p (x, XEXP (tem, 0)))
3111 *loc = XEXP (XEXP (tem, 1), 0);
3115 /* See comment for purge_addressof_replacements. */
3116 for (tem = purge_addressof_replacements;
3118 tem = XEXP (XEXP (tem, 1), 1))
3119 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3121 rtx z = XEXP (XEXP (tem, 1), 0);
3123 if (GET_MODE (x) == GET_MODE (z)
3124 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3125 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3128 /* It can happen that the note may speak of things
3129 in a wider (or just different) mode than the
3130 code did. This is especially true of
3133 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0)
3136 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3137 && (GET_MODE_SIZE (GET_MODE (x))
3138 > GET_MODE_SIZE (GET_MODE (z))))
3140 /* This can occur as a result in invalid
3141 pointer casts, e.g. float f; ...
3142 *(long long int *)&f.
3143 ??? We could emit a warning here, but
3144 without a line number that wouldn't be
3146 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3149 z = gen_lowpart (GET_MODE (x), z);
3155 /* Sometimes we may not be able to find the replacement. For
3156 example when the original insn was a MEM in a wider mode,
3157 and the note is part of a sign extension of a narrowed
3158 version of that MEM. Gcc testcase compile/990829-1.c can
3159 generate an example of this situation. Rather than complain
3160 we return false, which will prompt our caller to remove the
3165 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3166 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3168 /* Don't even consider working with paradoxical subregs,
3169 or the moral equivalent seen here. */
3170 if (size_x <= size_sub
3171 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3173 /* Do a bitfield insertion to mirror what would happen
3180 rtx p = PREV_INSN (insn);
3183 val = gen_reg_rtx (GET_MODE (x));
3184 if (! validate_change (insn, loc, val, 0))
3186 /* Discard the current sequence and put the
3187 ADDRESSOF on stack. */
3191 seq = gen_sequence ();
3193 emit_insn_before (seq, insn);
3194 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3198 store_bit_field (sub, size_x, 0, GET_MODE (x),
3199 val, GET_MODE_SIZE (GET_MODE (sub)));
3201 /* Make sure to unshare any shared rtl that store_bit_field
3202 might have created. */
3203 unshare_all_rtl_again (get_insns ());
3205 seq = gen_sequence ();
3207 p = emit_insn_after (seq, insn);
3208 if (NEXT_INSN (insn))
3209 compute_insns_for_mem (NEXT_INSN (insn),
3210 p ? NEXT_INSN (p) : NULL_RTX,
3215 rtx p = PREV_INSN (insn);
3218 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3219 GET_MODE (x), GET_MODE (x),
3220 GET_MODE_SIZE (GET_MODE (sub)));
3222 if (! validate_change (insn, loc, val, 0))
3224 /* Discard the current sequence and put the
3225 ADDRESSOF on stack. */
3230 seq = gen_sequence ();
3232 emit_insn_before (seq, insn);
3233 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3237 /* Remember the replacement so that the same one can be done
3238 on the REG_NOTES. */
3239 purge_bitfield_addressof_replacements
3240 = gen_rtx_EXPR_LIST (VOIDmode, x,
3243 purge_bitfield_addressof_replacements));
3245 /* We replaced with a reg -- all done. */
3250 else if (validate_change (insn, loc, sub, 0))
3252 /* Remember the replacement so that the same one can be done
3253 on the REG_NOTES. */
3254 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3258 for (tem = purge_addressof_replacements;
3260 tem = XEXP (XEXP (tem, 1), 1))
3261 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3263 XEXP (XEXP (tem, 1), 0) = sub;
3266 purge_addressof_replacements
3267 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3268 gen_rtx_EXPR_LIST (VOIDmode, sub,
3269 purge_addressof_replacements));
3277 /* Scan all subexpressions. */
3278 fmt = GET_RTX_FORMAT (code);
3279 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3282 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3283 else if (*fmt == 'E')
3284 for (j = 0; j < XVECLEN (x, i); j++)
3285 result &= 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;
3303 ifmhe = ((struct insns_for_mem_entry *)
3304 hash_allocate (ht, sizeof (struct insns_for_mem_entry)));
3305 ifmhe->insns = NULL_RTX;
3310 /* Return a hash value for K, a REG. */
3312 static unsigned long
3313 insns_for_mem_hash (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. */
3323 insns_for_mem_comp (k1, k2)
3330 struct insns_for_mem_walk_info
3332 /* The hash table that we are using to record which INSNs use which
3334 struct hash_table *ht;
3336 /* The INSN we are currently processing. */
3339 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3340 to find the insns that use the REGs in the ADDRESSOFs. */
3344 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3345 that might be used in an ADDRESSOF expression, record this INSN in
3346 the hash table given by DATA (which is really a pointer to an
3347 insns_for_mem_walk_info structure). */
3350 insns_for_mem_walk (r, data)
3354 struct insns_for_mem_walk_info *ifmwi
3355 = (struct insns_for_mem_walk_info *) data;
3357 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3358 && GET_CODE (XEXP (*r, 0)) == REG)
3359 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0);
3360 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3362 /* Lookup this MEM in the hashtable, creating it if necessary. */
3363 struct insns_for_mem_entry *ifme
3364 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht,
3369 /* If we have not already recorded this INSN, do so now. Since
3370 we process the INSNs in order, we know that if we have
3371 recorded it it must be at the front of the list. */
3372 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3373 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3380 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3381 which REGs in HT. */
3384 compute_insns_for_mem (insns, last_insn, ht)
3387 struct hash_table *ht;
3390 struct insns_for_mem_walk_info ifmwi;
3393 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3394 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3398 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3402 /* Helper function for purge_addressof called through for_each_rtx.
3403 Returns true iff the rtl is an ADDRESSOF. */
3406 is_addressof (rtl, data)
3408 void *data ATTRIBUTE_UNUSED;
3410 return GET_CODE (*rtl) == ADDRESSOF;
3413 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3414 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3418 purge_addressof (insns)
3422 struct hash_table ht;
3424 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3425 requires a fixup pass over the instruction stream to correct
3426 INSNs that depended on the REG being a REG, and not a MEM. But,
3427 these fixup passes are slow. Furthermore, most MEMs are not
3428 mentioned in very many instructions. So, we speed up the process
3429 by pre-calculating which REGs occur in which INSNs; that allows
3430 us to perform the fixup passes much more quickly. */
3431 hash_table_init (&ht,
3432 insns_for_mem_newfunc,
3434 insns_for_mem_comp);
3435 compute_insns_for_mem (insns, NULL_RTX, &ht);
3437 for (insn = insns; insn; insn = NEXT_INSN (insn))
3438 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3439 || GET_CODE (insn) == CALL_INSN)
3441 if (! purge_addressof_1 (&PATTERN (insn), insn,
3442 asm_noperands (PATTERN (insn)) > 0, 0, &ht))
3443 /* If we could not replace the ADDRESSOFs in the insn,
3444 something is wrong. */
3447 if (! purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, &ht))
3449 /* If we could not replace the ADDRESSOFs in the insn's notes,
3450 we can just remove the offending notes instead. */
3453 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3455 /* If we find a REG_RETVAL note then the insn is a libcall.
3456 Such insns must have REG_EQUAL notes as well, in order
3457 for later passes of the compiler to work. So it is not
3458 safe to delete the notes here, and instead we abort. */
3459 if (REG_NOTE_KIND (note) == REG_RETVAL)
3461 if (for_each_rtx (¬e, is_addressof, NULL))
3462 remove_note (insn, note);
3468 hash_table_free (&ht);
3469 purge_bitfield_addressof_replacements = 0;
3470 purge_addressof_replacements = 0;
3472 /* REGs are shared. purge_addressof will destructively replace a REG
3473 with a MEM, which creates shared MEMs.
3475 Unfortunately, the children of put_reg_into_stack assume that MEMs
3476 referring to the same stack slot are shared (fixup_var_refs and
3477 the associated hash table code).
3479 So, we have to do another unsharing pass after we have flushed any
3480 REGs that had their address taken into the stack.
3482 It may be worth tracking whether or not we converted any REGs into
3483 MEMs to avoid this overhead when it is not needed. */
3484 unshare_all_rtl_again (get_insns ());
3487 /* Convert a SET of a hard subreg to a set of the appropriate hard
3488 register. A subroutine of purge_hard_subreg_sets. */
3491 purge_single_hard_subreg_set (pattern)
3494 rtx reg = SET_DEST (pattern);
3495 enum machine_mode mode = GET_MODE (SET_DEST (pattern));
3498 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG
3499 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER)
3501 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)),
3502 GET_MODE (SUBREG_REG (reg)),
3505 reg = SUBREG_REG (reg);
3509 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER)
3511 reg = gen_rtx_REG (mode, REGNO (reg) + offset);
3512 SET_DEST (pattern) = reg;
3516 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3517 only such SETs that we expect to see are those left in because
3518 integrate can't handle sets of parts of a return value register.
3520 We don't use alter_subreg because we only want to eliminate subregs
3521 of hard registers. */
3524 purge_hard_subreg_sets (insn)
3527 for (; insn; insn = NEXT_INSN (insn))
3531 rtx pattern = PATTERN (insn);
3532 switch (GET_CODE (pattern))
3535 if (GET_CODE (SET_DEST (pattern)) == SUBREG)
3536 purge_single_hard_subreg_set (pattern);
3541 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--)
3543 rtx inner_pattern = XVECEXP (pattern, 0, j);
3544 if (GET_CODE (inner_pattern) == SET
3545 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG)
3546 purge_single_hard_subreg_set (inner_pattern);
3557 /* Pass through the INSNS of function FNDECL and convert virtual register
3558 references to hard register references. */
3561 instantiate_virtual_regs (fndecl, insns)
3568 /* Compute the offsets to use for this function. */
3569 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3570 var_offset = STARTING_FRAME_OFFSET;
3571 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3572 out_arg_offset = STACK_POINTER_OFFSET;
3573 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl);
3575 /* Scan all variables and parameters of this function. For each that is
3576 in memory, instantiate all virtual registers if the result is a valid
3577 address. If not, we do it later. That will handle most uses of virtual
3578 regs on many machines. */
3579 instantiate_decls (fndecl, 1);
3581 /* Initialize recognition, indicating that volatile is OK. */
3584 /* Scan through all the insns, instantiating every virtual register still
3586 for (insn = insns; insn; insn = NEXT_INSN (insn))
3587 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3588 || GET_CODE (insn) == CALL_INSN)
3590 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3591 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
3592 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3593 if (GET_CODE (insn) == CALL_INSN)
3594 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn),
3598 /* Instantiate the stack slots for the parm registers, for later use in
3599 addressof elimination. */
3600 for (i = 0; i < max_parm_reg; ++i)
3601 if (parm_reg_stack_loc[i])
3602 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3604 /* Now instantiate the remaining register equivalences for debugging info.
3605 These will not be valid addresses. */
3606 instantiate_decls (fndecl, 0);
3608 /* Indicate that, from now on, assign_stack_local should use
3609 frame_pointer_rtx. */
3610 virtuals_instantiated = 1;
3613 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3614 all virtual registers in their DECL_RTL's.
3616 If VALID_ONLY, do this only if the resulting address is still valid.
3617 Otherwise, always do it. */
3620 instantiate_decls (fndecl, valid_only)
3626 /* Process all parameters of the function. */
3627 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3629 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3630 HOST_WIDE_INT size_rtl;
3632 instantiate_decl (DECL_RTL (decl), size, valid_only);
3634 /* If the parameter was promoted, then the incoming RTL mode may be
3635 larger than the declared type size. We must use the larger of
3637 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl)));
3638 size = MAX (size_rtl, size);
3639 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3642 /* Now process all variables defined in the function or its subblocks. */
3643 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3646 /* Subroutine of instantiate_decls: Process all decls in the given
3647 BLOCK node and all its subblocks. */
3650 instantiate_decls_1 (let, valid_only)
3656 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3657 if (DECL_RTL_SET_P (t))
3658 instantiate_decl (DECL_RTL (t),
3659 int_size_in_bytes (TREE_TYPE (t)),
3662 /* Process all subblocks. */
3663 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3664 instantiate_decls_1 (t, valid_only);
3667 /* Subroutine of the preceding procedures: Given RTL representing a
3668 decl and the size of the object, do any instantiation required.
3670 If VALID_ONLY is non-zero, it means that the RTL should only be
3671 changed if the new address is valid. */
3674 instantiate_decl (x, size, valid_only)
3679 enum machine_mode mode;
3682 /* If this is not a MEM, no need to do anything. Similarly if the
3683 address is a constant or a register that is not a virtual register. */
3685 if (x == 0 || GET_CODE (x) != MEM)
3689 if (CONSTANT_P (addr)
3690 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3691 || (GET_CODE (addr) == REG
3692 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3693 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3696 /* If we should only do this if the address is valid, copy the address.
3697 We need to do this so we can undo any changes that might make the
3698 address invalid. This copy is unfortunate, but probably can't be
3702 addr = copy_rtx (addr);
3704 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3706 if (valid_only && size >= 0)
3708 unsigned HOST_WIDE_INT decl_size = size;
3710 /* Now verify that the resulting address is valid for every integer or
3711 floating-point mode up to and including SIZE bytes long. We do this
3712 since the object might be accessed in any mode and frame addresses
3715 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3716 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3717 mode = GET_MODE_WIDER_MODE (mode))
3718 if (! memory_address_p (mode, addr))
3721 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3722 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3723 mode = GET_MODE_WIDER_MODE (mode))
3724 if (! memory_address_p (mode, addr))
3728 /* Put back the address now that we have updated it and we either know
3729 it is valid or we don't care whether it is valid. */
3734 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3735 is a virtual register, return the equivalent hard register and set the
3736 offset indirectly through the pointer. Otherwise, return 0. */
3739 instantiate_new_reg (x, poffset)
3741 HOST_WIDE_INT *poffset;
3744 HOST_WIDE_INT offset;
3746 if (x == virtual_incoming_args_rtx)
3747 new = arg_pointer_rtx, offset = in_arg_offset;
3748 else if (x == virtual_stack_vars_rtx)
3749 new = frame_pointer_rtx, offset = var_offset;
3750 else if (x == virtual_stack_dynamic_rtx)
3751 new = stack_pointer_rtx, offset = dynamic_offset;
3752 else if (x == virtual_outgoing_args_rtx)
3753 new = stack_pointer_rtx, offset = out_arg_offset;
3754 else if (x == virtual_cfa_rtx)
3755 new = arg_pointer_rtx, offset = cfa_offset;
3763 /* Given a pointer to a piece of rtx and an optional pointer to the
3764 containing object, instantiate any virtual registers present in it.
3766 If EXTRA_INSNS, we always do the replacement and generate
3767 any extra insns before OBJECT. If it zero, we do nothing if replacement
3770 Return 1 if we either had nothing to do or if we were able to do the
3771 needed replacement. Return 0 otherwise; we only return zero if
3772 EXTRA_INSNS is zero.
3774 We first try some simple transformations to avoid the creation of extra
3778 instantiate_virtual_regs_1 (loc, object, extra_insns)
3786 HOST_WIDE_INT offset = 0;
3792 /* Re-start here to avoid recursion in common cases. */
3799 code = GET_CODE (x);
3801 /* Check for some special cases. */
3819 /* We are allowed to set the virtual registers. This means that
3820 the actual register should receive the source minus the
3821 appropriate offset. This is used, for example, in the handling
3822 of non-local gotos. */
3823 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0)
3825 rtx src = SET_SRC (x);
3827 /* We are setting the register, not using it, so the relevant
3828 offset is the negative of the offset to use were we using
3831 instantiate_virtual_regs_1 (&src, NULL_RTX, 0);
3833 /* The only valid sources here are PLUS or REG. Just do
3834 the simplest possible thing to handle them. */
3835 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS)
3839 if (GET_CODE (src) != REG)
3840 temp = force_operand (src, NULL_RTX);
3843 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3847 emit_insns_before (seq, object);
3850 if (! validate_change (object, &SET_SRC (x), temp, 0)
3857 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3862 /* Handle special case of virtual register plus constant. */
3863 if (CONSTANT_P (XEXP (x, 1)))
3865 rtx old, new_offset;
3867 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3868 if (GET_CODE (XEXP (x, 0)) == PLUS)
3870 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset)))
3872 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3874 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3883 #ifdef POINTERS_EXTEND_UNSIGNED
3884 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3885 we can commute the PLUS and SUBREG because pointers into the
3886 frame are well-behaved. */
3887 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode
3888 && GET_CODE (XEXP (x, 1)) == CONST_INT
3890 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)),
3892 && validate_change (object, loc,
3893 plus_constant (gen_lowpart (ptr_mode,
3896 + INTVAL (XEXP (x, 1))),
3900 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0)
3902 /* We know the second operand is a constant. Unless the
3903 first operand is a REG (which has been already checked),
3904 it needs to be checked. */
3905 if (GET_CODE (XEXP (x, 0)) != REG)
3913 new_offset = plus_constant (XEXP (x, 1), offset);
3915 /* If the new constant is zero, try to replace the sum with just
3917 if (new_offset == const0_rtx
3918 && validate_change (object, loc, new, 0))
3921 /* Next try to replace the register and new offset.
3922 There are two changes to validate here and we can't assume that
3923 in the case of old offset equals new just changing the register
3924 will yield a valid insn. In the interests of a little efficiency,
3925 however, we only call validate change once (we don't queue up the
3926 changes and then call apply_change_group). */
3930 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3931 : (XEXP (x, 0) = new,
3932 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3940 /* Otherwise copy the new constant into a register and replace
3941 constant with that register. */
3942 temp = gen_reg_rtx (Pmode);
3944 if (validate_change (object, &XEXP (x, 1), temp, 0))
3945 emit_insn_before (gen_move_insn (temp, new_offset), object);
3948 /* If that didn't work, replace this expression with a
3949 register containing the sum. */
3952 new = gen_rtx_PLUS (Pmode, new, new_offset);
3955 temp = force_operand (new, NULL_RTX);
3959 emit_insns_before (seq, object);
3960 if (! validate_change (object, loc, temp, 0)
3961 && ! validate_replace_rtx (x, temp, object))
3969 /* Fall through to generic two-operand expression case. */
3975 case DIV: case UDIV:
3976 case MOD: case UMOD:
3977 case AND: case IOR: case XOR:
3978 case ROTATERT: case ROTATE:
3979 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3981 case GE: case GT: case GEU: case GTU:
3982 case LE: case LT: case LEU: case LTU:
3983 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3984 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3989 /* Most cases of MEM that convert to valid addresses have already been
3990 handled by our scan of decls. The only special handling we
3991 need here is to make a copy of the rtx to ensure it isn't being
3992 shared if we have to change it to a pseudo.
3994 If the rtx is a simple reference to an address via a virtual register,
3995 it can potentially be shared. In such cases, first try to make it
3996 a valid address, which can also be shared. Otherwise, copy it and
3999 First check for common cases that need no processing. These are
4000 usually due to instantiation already being done on a previous instance
4004 if (CONSTANT_ADDRESS_P (temp)
4005 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4006 || temp == arg_pointer_rtx
4008 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4009 || temp == hard_frame_pointer_rtx
4011 || temp == frame_pointer_rtx)
4014 if (GET_CODE (temp) == PLUS
4015 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4016 && (XEXP (temp, 0) == frame_pointer_rtx
4017 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4018 || XEXP (temp, 0) == hard_frame_pointer_rtx
4020 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4021 || XEXP (temp, 0) == arg_pointer_rtx
4026 if (temp == virtual_stack_vars_rtx
4027 || temp == virtual_incoming_args_rtx
4028 || (GET_CODE (temp) == PLUS
4029 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4030 && (XEXP (temp, 0) == virtual_stack_vars_rtx
4031 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
4033 /* This MEM may be shared. If the substitution can be done without
4034 the need to generate new pseudos, we want to do it in place
4035 so all copies of the shared rtx benefit. The call below will
4036 only make substitutions if the resulting address is still
4039 Note that we cannot pass X as the object in the recursive call
4040 since the insn being processed may not allow all valid
4041 addresses. However, if we were not passed on object, we can
4042 only modify X without copying it if X will have a valid
4045 ??? Also note that this can still lose if OBJECT is an insn that
4046 has less restrictions on an address that some other insn.
4047 In that case, we will modify the shared address. This case
4048 doesn't seem very likely, though. One case where this could
4049 happen is in the case of a USE or CLOBBER reference, but we
4050 take care of that below. */
4052 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
4053 object ? object : x, 0))
4056 /* Otherwise make a copy and process that copy. We copy the entire
4057 RTL expression since it might be a PLUS which could also be
4059 *loc = x = copy_rtx (x);
4062 /* Fall through to generic unary operation case. */
4065 case STRICT_LOW_PART:
4067 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
4068 case SIGN_EXTEND: case ZERO_EXTEND:
4069 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
4070 case FLOAT: case FIX:
4071 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
4075 /* These case either have just one operand or we know that we need not
4076 check the rest of the operands. */
4082 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4083 go ahead and make the invalid one, but do it to a copy. For a REG,
4084 just make the recursive call, since there's no chance of a problem. */
4086 if ((GET_CODE (XEXP (x, 0)) == MEM
4087 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
4089 || (GET_CODE (XEXP (x, 0)) == REG
4090 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4093 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
4098 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4099 in front of this insn and substitute the temporary. */
4100 if ((new = instantiate_new_reg (x, &offset)) != 0)
4102 temp = plus_constant (new, offset);
4103 if (!validate_change (object, loc, temp, 0))
4109 temp = force_operand (temp, NULL_RTX);
4113 emit_insns_before (seq, object);
4114 if (! validate_change (object, loc, temp, 0)
4115 && ! validate_replace_rtx (x, temp, object))
4123 if (GET_CODE (XEXP (x, 0)) == REG)
4126 else if (GET_CODE (XEXP (x, 0)) == MEM)
4128 /* If we have a (addressof (mem ..)), do any instantiation inside
4129 since we know we'll be making the inside valid when we finally
4130 remove the ADDRESSOF. */
4131 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4140 /* Scan all subexpressions. */
4141 fmt = GET_RTX_FORMAT (code);
4142 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4145 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4148 else if (*fmt == 'E')
4149 for (j = 0; j < XVECLEN (x, i); j++)
4150 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4157 /* Optimization: assuming this function does not receive nonlocal gotos,
4158 delete the handlers for such, as well as the insns to establish
4159 and disestablish them. */
4165 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4167 /* Delete the handler by turning off the flag that would
4168 prevent jump_optimize from deleting it.
4169 Also permit deletion of the nonlocal labels themselves
4170 if nothing local refers to them. */
4171 if (GET_CODE (insn) == CODE_LABEL)
4175 LABEL_PRESERVE_P (insn) = 0;
4177 /* Remove it from the nonlocal_label list, to avoid confusing
4179 for (t = nonlocal_labels, last_t = 0; t;
4180 last_t = t, t = TREE_CHAIN (t))
4181 if (DECL_RTL (TREE_VALUE (t)) == insn)
4186 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4188 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4191 if (GET_CODE (insn) == INSN)
4195 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4196 if (reg_mentioned_p (t, PATTERN (insn)))
4202 || (nonlocal_goto_stack_level != 0
4203 && reg_mentioned_p (nonlocal_goto_stack_level,
4205 delete_related_insns (insn);
4213 return max_parm_reg;
4216 /* Return the first insn following those generated by `assign_parms'. */
4219 get_first_nonparm_insn ()
4222 return NEXT_INSN (last_parm_insn);
4223 return get_insns ();
4226 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4227 Crash if there is none. */
4230 get_first_block_beg ()
4233 rtx insn = get_first_nonparm_insn ();
4235 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
4236 if (GET_CODE (searcher) == NOTE
4237 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
4240 abort (); /* Invalid call to this function. (See comments above.) */
4244 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4245 This means a type for which function calls must pass an address to the
4246 function or get an address back from the function.
4247 EXP may be a type node or an expression (whose type is tested). */
4250 aggregate_value_p (exp)
4253 int i, regno, nregs;
4256 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
4258 if (TREE_CODE (type) == VOID_TYPE)
4260 if (RETURN_IN_MEMORY (type))
4262 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4263 and thus can't be returned in registers. */
4264 if (TREE_ADDRESSABLE (type))
4266 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4268 /* Make sure we have suitable call-clobbered regs to return
4269 the value in; if not, we must return it in memory. */
4270 reg = hard_function_value (type, 0, 0);
4272 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4274 if (GET_CODE (reg) != REG)
4277 regno = REGNO (reg);
4278 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4279 for (i = 0; i < nregs; i++)
4280 if (! call_used_regs[regno + i])
4285 /* Assign RTL expressions to the function's parameters.
4286 This may involve copying them into registers and using
4287 those registers as the RTL for them. */
4290 assign_parms (fndecl)
4296 CUMULATIVE_ARGS args_so_far;
4297 enum machine_mode promoted_mode, passed_mode;
4298 enum machine_mode nominal_mode, promoted_nominal_mode;
4300 /* Total space needed so far for args on the stack,
4301 given as a constant and a tree-expression. */
4302 struct args_size stack_args_size;
4303 tree fntype = TREE_TYPE (fndecl);
4304 tree fnargs = DECL_ARGUMENTS (fndecl);
4305 /* This is used for the arg pointer when referring to stack args. */
4306 rtx internal_arg_pointer;
4307 /* This is a dummy PARM_DECL that we used for the function result if
4308 the function returns a structure. */
4309 tree function_result_decl = 0;
4310 #ifdef SETUP_INCOMING_VARARGS
4311 int varargs_setup = 0;
4313 rtx conversion_insns = 0;
4314 struct args_size alignment_pad;
4316 /* Nonzero if the last arg is named `__builtin_va_alist',
4317 which is used on some machines for old-fashioned non-ANSI varargs.h;
4318 this should be stuck onto the stack as if it had arrived there. */
4320 = (current_function_varargs
4322 && (parm = tree_last (fnargs)) != 0
4324 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
4325 "__builtin_va_alist")));
4327 /* Nonzero if function takes extra anonymous args.
4328 This means the last named arg must be on the stack
4329 right before the anonymous ones. */
4331 = (TYPE_ARG_TYPES (fntype) != 0
4332 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4333 != void_type_node));
4335 current_function_stdarg = stdarg;
4337 /* If the reg that the virtual arg pointer will be translated into is
4338 not a fixed reg or is the stack pointer, make a copy of the virtual
4339 arg pointer, and address parms via the copy. The frame pointer is
4340 considered fixed even though it is not marked as such.
4342 The second time through, simply use ap to avoid generating rtx. */
4344 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4345 || ! (fixed_regs[ARG_POINTER_REGNUM]
4346 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
4347 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4349 internal_arg_pointer = virtual_incoming_args_rtx;
4350 current_function_internal_arg_pointer = internal_arg_pointer;
4352 stack_args_size.constant = 0;
4353 stack_args_size.var = 0;
4355 /* If struct value address is treated as the first argument, make it so. */
4356 if (aggregate_value_p (DECL_RESULT (fndecl))
4357 && ! current_function_returns_pcc_struct
4358 && struct_value_incoming_rtx == 0)
4360 tree type = build_pointer_type (TREE_TYPE (fntype));
4362 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4364 DECL_ARG_TYPE (function_result_decl) = type;
4365 TREE_CHAIN (function_result_decl) = fnargs;
4366 fnargs = function_result_decl;
4369 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4370 parm_reg_stack_loc = (rtx *) xcalloc (max_parm_reg, sizeof (rtx));
4372 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4373 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4375 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
4378 /* We haven't yet found an argument that we must push and pretend the
4380 current_function_pretend_args_size = 0;
4382 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4384 struct args_size stack_offset;
4385 struct args_size arg_size;
4386 int passed_pointer = 0;
4387 int did_conversion = 0;
4388 tree passed_type = DECL_ARG_TYPE (parm);
4389 tree nominal_type = TREE_TYPE (parm);
4391 int last_named = 0, named_arg;
4393 /* Set LAST_NAMED if this is last named arg before last
4395 if (stdarg || current_function_varargs)
4399 for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem))
4400 if (DECL_NAME (tem))
4406 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4407 most machines, if this is a varargs/stdarg function, then we treat
4408 the last named arg as if it were anonymous too. */
4409 named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4411 if (TREE_TYPE (parm) == error_mark_node
4412 /* This can happen after weird syntax errors
4413 or if an enum type is defined among the parms. */
4414 || TREE_CODE (parm) != PARM_DECL
4415 || passed_type == NULL)
4417 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx));
4418 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4419 TREE_USED (parm) = 1;
4423 /* For varargs.h function, save info about regs and stack space
4424 used by the individual args, not including the va_alist arg. */
4425 if (hide_last_arg && last_named)
4426 current_function_args_info = args_so_far;
4428 /* Find mode of arg as it is passed, and mode of arg
4429 as it should be during execution of this function. */
4430 passed_mode = TYPE_MODE (passed_type);
4431 nominal_mode = TYPE_MODE (nominal_type);
4433 /* If the parm's mode is VOID, its value doesn't matter,
4434 and avoid the usual things like emit_move_insn that could crash. */
4435 if (nominal_mode == VOIDmode)
4437 SET_DECL_RTL (parm, const0_rtx);
4438 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4442 /* If the parm is to be passed as a transparent union, use the
4443 type of the first field for the tests below. We have already
4444 verified that the modes are the same. */
4445 if (DECL_TRANSPARENT_UNION (parm)
4446 || (TREE_CODE (passed_type) == UNION_TYPE
4447 && TYPE_TRANSPARENT_UNION (passed_type)))
4448 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4450 /* See if this arg was passed by invisible reference. It is if
4451 it is an object whose size depends on the contents of the
4452 object itself or if the machine requires these objects be passed
4455 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4456 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4457 || TREE_ADDRESSABLE (passed_type)
4458 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4459 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4460 passed_type, named_arg)
4464 passed_type = nominal_type = build_pointer_type (passed_type);
4466 passed_mode = nominal_mode = Pmode;
4469 promoted_mode = passed_mode;
4471 #ifdef PROMOTE_FUNCTION_ARGS
4472 /* Compute the mode in which the arg is actually extended to. */
4473 unsignedp = TREE_UNSIGNED (passed_type);
4474 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4477 /* Let machine desc say which reg (if any) the parm arrives in.
4478 0 means it arrives on the stack. */
4479 #ifdef FUNCTION_INCOMING_ARG
4480 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4481 passed_type, named_arg);
4483 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4484 passed_type, named_arg);
4487 if (entry_parm == 0)
4488 promoted_mode = passed_mode;
4490 #ifdef SETUP_INCOMING_VARARGS
4491 /* If this is the last named parameter, do any required setup for
4492 varargs or stdargs. We need to know about the case of this being an
4493 addressable type, in which case we skip the registers it
4494 would have arrived in.
4496 For stdargs, LAST_NAMED will be set for two parameters, the one that
4497 is actually the last named, and the dummy parameter. We only
4498 want to do this action once.
4500 Also, indicate when RTL generation is to be suppressed. */
4501 if (last_named && !varargs_setup)
4503 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4504 current_function_pretend_args_size, 0);
4509 /* Determine parm's home in the stack,
4510 in case it arrives in the stack or we should pretend it did.
4512 Compute the stack position and rtx where the argument arrives
4515 There is one complexity here: If this was a parameter that would
4516 have been passed in registers, but wasn't only because it is
4517 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4518 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4519 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4520 0 as it was the previous time. */
4522 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4523 locate_and_pad_parm (promoted_mode, passed_type,
4524 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4527 #ifdef FUNCTION_INCOMING_ARG
4528 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4530 pretend_named) != 0,
4532 FUNCTION_ARG (args_so_far, promoted_mode,
4534 pretend_named) != 0,
4537 fndecl, &stack_args_size, &stack_offset, &arg_size,
4541 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4543 if (offset_rtx == const0_rtx)
4544 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4546 stack_parm = gen_rtx_MEM (promoted_mode,
4547 gen_rtx_PLUS (Pmode,
4548 internal_arg_pointer,
4551 set_mem_attributes (stack_parm, parm, 1);
4554 /* If this parameter was passed both in registers and in the stack,
4555 use the copy on the stack. */
4556 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4559 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4560 /* If this parm was passed part in regs and part in memory,
4561 pretend it arrived entirely in memory
4562 by pushing the register-part onto the stack.
4564 In the special case of a DImode or DFmode that is split,
4565 we could put it together in a pseudoreg directly,
4566 but for now that's not worth bothering with. */
4570 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4571 passed_type, named_arg);
4575 current_function_pretend_args_size
4576 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4577 / (PARM_BOUNDARY / BITS_PER_UNIT)
4578 * (PARM_BOUNDARY / BITS_PER_UNIT));
4580 /* Handle calls that pass values in multiple non-contiguous
4581 locations. The Irix 6 ABI has examples of this. */
4582 if (GET_CODE (entry_parm) == PARALLEL)
4583 emit_group_store (validize_mem (stack_parm), entry_parm,
4584 int_size_in_bytes (TREE_TYPE (parm)));
4587 move_block_from_reg (REGNO (entry_parm),
4588 validize_mem (stack_parm), nregs,
4589 int_size_in_bytes (TREE_TYPE (parm)));
4591 entry_parm = stack_parm;
4596 /* If we didn't decide this parm came in a register,
4597 by default it came on the stack. */
4598 if (entry_parm == 0)
4599 entry_parm = stack_parm;
4601 /* Record permanently how this parm was passed. */
4602 DECL_INCOMING_RTL (parm) = entry_parm;
4604 /* If there is actually space on the stack for this parm,
4605 count it in stack_args_size; otherwise set stack_parm to 0
4606 to indicate there is no preallocated stack slot for the parm. */
4608 if (entry_parm == stack_parm
4609 || (GET_CODE (entry_parm) == PARALLEL
4610 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4611 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4612 /* On some machines, even if a parm value arrives in a register
4613 there is still an (uninitialized) stack slot allocated for it.
4615 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4616 whether this parameter already has a stack slot allocated,
4617 because an arg block exists only if current_function_args_size
4618 is larger than some threshold, and we haven't calculated that
4619 yet. So, for now, we just assume that stack slots never exist
4621 || REG_PARM_STACK_SPACE (fndecl) > 0
4625 stack_args_size.constant += arg_size.constant;
4627 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4630 /* No stack slot was pushed for this parm. */
4633 /* Update info on where next arg arrives in registers. */
4635 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4636 passed_type, named_arg);
4638 /* If we can't trust the parm stack slot to be aligned enough
4639 for its ultimate type, don't use that slot after entry.
4640 We'll make another stack slot, if we need one. */
4642 unsigned int thisparm_boundary
4643 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4645 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4649 /* If parm was passed in memory, and we need to convert it on entry,
4650 don't store it back in that same slot. */
4652 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4655 /* When an argument is passed in multiple locations, we can't
4656 make use of this information, but we can save some copying if
4657 the whole argument is passed in a single register. */
4658 if (GET_CODE (entry_parm) == PARALLEL
4659 && nominal_mode != BLKmode && passed_mode != BLKmode)
4661 int i, len = XVECLEN (entry_parm, 0);
4663 for (i = 0; i < len; i++)
4664 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
4665 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG
4666 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
4668 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
4670 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
4671 DECL_INCOMING_RTL (parm) = entry_parm;
4676 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4677 in the mode in which it arrives.
4678 STACK_PARM is an RTX for a stack slot where the parameter can live
4679 during the function (in case we want to put it there).
4680 STACK_PARM is 0 if no stack slot was pushed for it.
4682 Now output code if necessary to convert ENTRY_PARM to
4683 the type in which this function declares it,
4684 and store that result in an appropriate place,
4685 which may be a pseudo reg, may be STACK_PARM,
4686 or may be a local stack slot if STACK_PARM is 0.
4688 Set DECL_RTL to that place. */
4690 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4692 /* If a BLKmode arrives in registers, copy it to a stack slot.
4693 Handle calls that pass values in multiple non-contiguous
4694 locations. The Irix 6 ABI has examples of this. */
4695 if (GET_CODE (entry_parm) == REG
4696 || GET_CODE (entry_parm) == PARALLEL)
4699 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4702 /* Note that we will be storing an integral number of words.
4703 So we have to be careful to ensure that we allocate an
4704 integral number of words. We do this below in the
4705 assign_stack_local if space was not allocated in the argument
4706 list. If it was, this will not work if PARM_BOUNDARY is not
4707 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4708 if it becomes a problem. */
4710 if (stack_parm == 0)
4713 = assign_stack_local (GET_MODE (entry_parm),
4715 set_mem_attributes (stack_parm, parm, 1);
4718 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4721 /* Handle calls that pass values in multiple non-contiguous
4722 locations. The Irix 6 ABI has examples of this. */
4723 if (GET_CODE (entry_parm) == PARALLEL)
4724 emit_group_store (validize_mem (stack_parm), entry_parm,
4725 int_size_in_bytes (TREE_TYPE (parm)));
4727 move_block_from_reg (REGNO (entry_parm),
4728 validize_mem (stack_parm),
4729 size_stored / UNITS_PER_WORD,
4730 int_size_in_bytes (TREE_TYPE (parm)));
4732 SET_DECL_RTL (parm, stack_parm);
4734 else if (! ((! optimize
4735 && ! DECL_REGISTER (parm))
4736 || TREE_SIDE_EFFECTS (parm)
4737 /* If -ffloat-store specified, don't put explicit
4738 float variables into registers. */
4739 || (flag_float_store
4740 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4741 /* Always assign pseudo to structure return or item passed
4742 by invisible reference. */
4743 || passed_pointer || parm == function_result_decl)
4745 /* Store the parm in a pseudoregister during the function, but we
4746 may need to do it in a wider mode. */
4749 unsigned int regno, regnoi = 0, regnor = 0;
4751 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4753 promoted_nominal_mode
4754 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4756 parmreg = gen_reg_rtx (promoted_nominal_mode);
4757 mark_user_reg (parmreg);
4759 /* If this was an item that we received a pointer to, set DECL_RTL
4763 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)),
4765 set_mem_attributes (x, parm, 1);
4766 SET_DECL_RTL (parm, x);
4770 SET_DECL_RTL (parm, parmreg);
4771 maybe_set_unchanging (DECL_RTL (parm), parm);
4774 /* Copy the value into the register. */
4775 if (nominal_mode != passed_mode
4776 || promoted_nominal_mode != promoted_mode)
4779 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4780 mode, by the caller. We now have to convert it to
4781 NOMINAL_MODE, if different. However, PARMREG may be in
4782 a different mode than NOMINAL_MODE if it is being stored
4785 If ENTRY_PARM is a hard register, it might be in a register
4786 not valid for operating in its mode (e.g., an odd-numbered
4787 register for a DFmode). In that case, moves are the only
4788 thing valid, so we can't do a convert from there. This
4789 occurs when the calling sequence allow such misaligned
4792 In addition, the conversion may involve a call, which could
4793 clobber parameters which haven't been copied to pseudo
4794 registers yet. Therefore, we must first copy the parm to
4795 a pseudo reg here, and save the conversion until after all
4796 parameters have been moved. */
4798 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4800 emit_move_insn (tempreg, validize_mem (entry_parm));
4802 push_to_sequence (conversion_insns);
4803 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4805 if (GET_CODE (tempreg) == SUBREG
4806 && GET_MODE (tempreg) == nominal_mode
4807 && GET_CODE (SUBREG_REG (tempreg)) == REG
4808 && nominal_mode == passed_mode
4809 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm)
4810 && GET_MODE_SIZE (GET_MODE (tempreg))
4811 < GET_MODE_SIZE (GET_MODE (entry_parm)))
4813 /* The argument is already sign/zero extended, so note it
4815 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
4816 SUBREG_PROMOTED_UNSIGNED_SET (tempreg, unsignedp);
4819 /* TREE_USED gets set erroneously during expand_assignment. */
4820 save_tree_used = TREE_USED (parm);
4821 expand_assignment (parm,
4822 make_tree (nominal_type, tempreg), 0, 0);
4823 TREE_USED (parm) = save_tree_used;
4824 conversion_insns = get_insns ();
4829 emit_move_insn (parmreg, validize_mem (entry_parm));
4831 /* If we were passed a pointer but the actual value
4832 can safely live in a register, put it in one. */
4833 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4834 /* If by-reference argument was promoted, demote it. */
4835 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm))
4837 && ! DECL_REGISTER (parm))
4838 || TREE_SIDE_EFFECTS (parm)
4839 /* If -ffloat-store specified, don't put explicit
4840 float variables into registers. */
4841 || (flag_float_store
4842 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))))
4844 /* We can't use nominal_mode, because it will have been set to
4845 Pmode above. We must use the actual mode of the parm. */
4846 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4847 mark_user_reg (parmreg);
4848 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
4850 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
4851 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm));
4852 push_to_sequence (conversion_insns);
4853 emit_move_insn (tempreg, DECL_RTL (parm));
4855 convert_to_mode (GET_MODE (parmreg),
4858 emit_move_insn (parmreg, DECL_RTL (parm));
4859 conversion_insns = get_insns();
4864 emit_move_insn (parmreg, DECL_RTL (parm));
4865 SET_DECL_RTL (parm, parmreg);
4866 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4870 #ifdef FUNCTION_ARG_CALLEE_COPIES
4871 /* If we are passed an arg by reference and it is our responsibility
4872 to make a copy, do it now.
4873 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4874 original argument, so we must recreate them in the call to
4875 FUNCTION_ARG_CALLEE_COPIES. */
4876 /* ??? Later add code to handle the case that if the argument isn't
4877 modified, don't do the copy. */
4879 else if (passed_pointer
4880 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4881 TYPE_MODE (DECL_ARG_TYPE (parm)),
4882 DECL_ARG_TYPE (parm),
4884 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4887 tree type = DECL_ARG_TYPE (parm);
4889 /* This sequence may involve a library call perhaps clobbering
4890 registers that haven't been copied to pseudos yet. */
4892 push_to_sequence (conversion_insns);
4894 if (!COMPLETE_TYPE_P (type)
4895 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4896 /* This is a variable sized object. */
4897 copy = gen_rtx_MEM (BLKmode,
4898 allocate_dynamic_stack_space
4899 (expr_size (parm), NULL_RTX,
4900 TYPE_ALIGN (type)));
4902 copy = assign_stack_temp (TYPE_MODE (type),
4903 int_size_in_bytes (type), 1);
4904 set_mem_attributes (copy, parm, 1);
4906 store_expr (parm, copy, 0);
4907 emit_move_insn (parmreg, XEXP (copy, 0));
4908 conversion_insns = get_insns ();
4912 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4914 /* In any case, record the parm's desired stack location
4915 in case we later discover it must live in the stack.
4917 If it is a COMPLEX value, store the stack location for both
4920 if (GET_CODE (parmreg) == CONCAT)
4921 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4923 regno = REGNO (parmreg);
4925 if (regno >= max_parm_reg)
4928 int old_max_parm_reg = max_parm_reg;
4930 /* It's slow to expand this one register at a time,
4931 but it's also rare and we need max_parm_reg to be
4932 precisely correct. */
4933 max_parm_reg = regno + 1;
4934 new = (rtx *) xrealloc (parm_reg_stack_loc,
4935 max_parm_reg * sizeof (rtx));
4936 memset ((char *) (new + old_max_parm_reg), 0,
4937 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4938 parm_reg_stack_loc = new;
4941 if (GET_CODE (parmreg) == CONCAT)
4943 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4945 regnor = REGNO (gen_realpart (submode, parmreg));
4946 regnoi = REGNO (gen_imagpart (submode, parmreg));
4948 if (stack_parm != 0)
4950 parm_reg_stack_loc[regnor]
4951 = gen_realpart (submode, stack_parm);
4952 parm_reg_stack_loc[regnoi]
4953 = gen_imagpart (submode, stack_parm);
4957 parm_reg_stack_loc[regnor] = 0;
4958 parm_reg_stack_loc[regnoi] = 0;
4962 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4964 /* Mark the register as eliminable if we did no conversion
4965 and it was copied from memory at a fixed offset,
4966 and the arg pointer was not copied to a pseudo-reg.
4967 If the arg pointer is a pseudo reg or the offset formed
4968 an invalid address, such memory-equivalences
4969 as we make here would screw up life analysis for it. */
4970 if (nominal_mode == passed_mode
4973 && GET_CODE (stack_parm) == MEM
4974 && stack_offset.var == 0
4975 && reg_mentioned_p (virtual_incoming_args_rtx,
4976 XEXP (stack_parm, 0)))
4978 rtx linsn = get_last_insn ();
4981 /* Mark complex types separately. */
4982 if (GET_CODE (parmreg) == CONCAT)
4983 /* Scan backwards for the set of the real and
4985 for (sinsn = linsn; sinsn != 0;
4986 sinsn = prev_nonnote_insn (sinsn))
4988 set = single_set (sinsn);
4990 && SET_DEST (set) == regno_reg_rtx [regnoi])
4992 = gen_rtx_EXPR_LIST (REG_EQUIV,
4993 parm_reg_stack_loc[regnoi],
4996 && SET_DEST (set) == regno_reg_rtx [regnor])
4998 = gen_rtx_EXPR_LIST (REG_EQUIV,
4999 parm_reg_stack_loc[regnor],
5002 else if ((set = single_set (linsn)) != 0
5003 && SET_DEST (set) == parmreg)
5005 = gen_rtx_EXPR_LIST (REG_EQUIV,
5006 stack_parm, REG_NOTES (linsn));
5009 /* For pointer data type, suggest pointer register. */
5010 if (POINTER_TYPE_P (TREE_TYPE (parm)))
5011 mark_reg_pointer (parmreg,
5012 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
5014 /* If something wants our address, try to use ADDRESSOF. */
5015 if (TREE_ADDRESSABLE (parm))
5017 /* If we end up putting something into the stack,
5018 fixup_var_refs_insns will need to make a pass over
5019 all the instructions. It looks through the pending
5020 sequences -- but it can't see the ones in the
5021 CONVERSION_INSNS, if they're not on the sequence
5022 stack. So, we go back to that sequence, just so that
5023 the fixups will happen. */
5024 push_to_sequence (conversion_insns);
5025 put_var_into_stack (parm);
5026 conversion_insns = get_insns ();
5032 /* Value must be stored in the stack slot STACK_PARM
5033 during function execution. */
5035 if (promoted_mode != nominal_mode)
5037 /* Conversion is required. */
5038 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
5040 emit_move_insn (tempreg, validize_mem (entry_parm));
5042 push_to_sequence (conversion_insns);
5043 entry_parm = convert_to_mode (nominal_mode, tempreg,
5044 TREE_UNSIGNED (TREE_TYPE (parm)));
5046 /* ??? This may need a big-endian conversion on sparc64. */
5047 stack_parm = adjust_address (stack_parm, nominal_mode, 0);
5049 conversion_insns = get_insns ();
5054 if (entry_parm != stack_parm)
5056 if (stack_parm == 0)
5059 = assign_stack_local (GET_MODE (entry_parm),
5060 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
5061 set_mem_attributes (stack_parm, parm, 1);
5064 if (promoted_mode != nominal_mode)
5066 push_to_sequence (conversion_insns);
5067 emit_move_insn (validize_mem (stack_parm),
5068 validize_mem (entry_parm));
5069 conversion_insns = get_insns ();
5073 emit_move_insn (validize_mem (stack_parm),
5074 validize_mem (entry_parm));
5077 SET_DECL_RTL (parm, stack_parm);
5080 /* If this "parameter" was the place where we are receiving the
5081 function's incoming structure pointer, set up the result. */
5082 if (parm == function_result_decl)
5084 tree result = DECL_RESULT (fndecl);
5085 rtx addr = DECL_RTL (parm);
5088 #ifdef POINTERS_EXTEND_UNSIGNED
5089 if (GET_MODE (addr) != Pmode)
5090 addr = convert_memory_address (Pmode, addr);
5093 x = gen_rtx_MEM (DECL_MODE (result), addr);
5094 set_mem_attributes (x, result, 1);
5095 SET_DECL_RTL (result, x);
5098 if (GET_CODE (DECL_RTL (parm)) == REG)
5099 REGNO_DECL (REGNO (DECL_RTL (parm))) = parm;
5100 else if (GET_CODE (DECL_RTL (parm)) == CONCAT)
5102 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 0))) = parm;
5103 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 1))) = parm;
5108 /* Output all parameter conversion instructions (possibly including calls)
5109 now that all parameters have been copied out of hard registers. */
5110 emit_insns (conversion_insns);
5112 last_parm_insn = get_last_insn ();
5114 current_function_args_size = stack_args_size.constant;
5116 /* Adjust function incoming argument size for alignment and
5119 #ifdef REG_PARM_STACK_SPACE
5120 #ifndef MAYBE_REG_PARM_STACK_SPACE
5121 current_function_args_size = MAX (current_function_args_size,
5122 REG_PARM_STACK_SPACE (fndecl));
5126 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5128 current_function_args_size
5129 = ((current_function_args_size + STACK_BYTES - 1)
5130 / STACK_BYTES) * STACK_BYTES;
5132 #ifdef ARGS_GROW_DOWNWARD
5133 current_function_arg_offset_rtx
5134 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5135 : expand_expr (size_diffop (stack_args_size.var,
5136 size_int (-stack_args_size.constant)),
5137 NULL_RTX, VOIDmode, 0));
5139 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5142 /* See how many bytes, if any, of its args a function should try to pop
5145 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5146 current_function_args_size);
5148 /* For stdarg.h function, save info about
5149 regs and stack space used by the named args. */
5152 current_function_args_info = args_so_far;
5154 /* Set the rtx used for the function return value. Put this in its
5155 own variable so any optimizers that need this information don't have
5156 to include tree.h. Do this here so it gets done when an inlined
5157 function gets output. */
5159 current_function_return_rtx
5160 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
5161 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
5163 /* If scalar return value was computed in a pseudo-reg, or was a named
5164 return value that got dumped to the stack, copy that to the hard
5166 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
5168 tree decl_result = DECL_RESULT (fndecl);
5169 rtx decl_rtl = DECL_RTL (decl_result);
5171 if (REG_P (decl_rtl)
5172 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5173 : DECL_REGISTER (decl_result))
5177 #ifdef FUNCTION_OUTGOING_VALUE
5178 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
5181 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
5184 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
5185 /* The delay slot scheduler assumes that current_function_return_rtx
5186 holds the hard register containing the return value, not a
5187 temporary pseudo. */
5188 current_function_return_rtx = real_decl_rtl;
5193 /* Indicate whether REGNO is an incoming argument to the current function
5194 that was promoted to a wider mode. If so, return the RTX for the
5195 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5196 that REGNO is promoted from and whether the promotion was signed or
5199 #ifdef PROMOTE_FUNCTION_ARGS
5202 promoted_input_arg (regno, pmode, punsignedp)
5204 enum machine_mode *pmode;
5209 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5210 arg = TREE_CHAIN (arg))
5211 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5212 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5213 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5215 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5216 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5218 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5219 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5220 && mode != DECL_MODE (arg))
5222 *pmode = DECL_MODE (arg);
5223 *punsignedp = unsignedp;
5224 return DECL_INCOMING_RTL (arg);
5233 /* Compute the size and offset from the start of the stacked arguments for a
5234 parm passed in mode PASSED_MODE and with type TYPE.
5236 INITIAL_OFFSET_PTR points to the current offset into the stacked
5239 The starting offset and size for this parm are returned in *OFFSET_PTR
5240 and *ARG_SIZE_PTR, respectively.
5242 IN_REGS is non-zero if the argument will be passed in registers. It will
5243 never be set if REG_PARM_STACK_SPACE is not defined.
5245 FNDECL is the function in which the argument was defined.
5247 There are two types of rounding that are done. The first, controlled by
5248 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5249 list to be aligned to the specific boundary (in bits). This rounding
5250 affects the initial and starting offsets, but not the argument size.
5252 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5253 optionally rounds the size of the parm to PARM_BOUNDARY. The
5254 initial offset is not affected by this rounding, while the size always
5255 is and the starting offset may be. */
5257 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5258 initial_offset_ptr is positive because locate_and_pad_parm's
5259 callers pass in the total size of args so far as
5260 initial_offset_ptr. arg_size_ptr is always positive. */
5263 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5264 initial_offset_ptr, offset_ptr, arg_size_ptr,
5266 enum machine_mode passed_mode;
5268 int in_regs ATTRIBUTE_UNUSED;
5269 tree fndecl ATTRIBUTE_UNUSED;
5270 struct args_size *initial_offset_ptr;
5271 struct args_size *offset_ptr;
5272 struct args_size *arg_size_ptr;
5273 struct args_size *alignment_pad;
5277 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5278 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5279 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5281 #ifdef REG_PARM_STACK_SPACE
5282 /* If we have found a stack parm before we reach the end of the
5283 area reserved for registers, skip that area. */
5286 int reg_parm_stack_space = 0;
5288 #ifdef MAYBE_REG_PARM_STACK_SPACE
5289 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5291 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5293 if (reg_parm_stack_space > 0)
5295 if (initial_offset_ptr->var)
5297 initial_offset_ptr->var
5298 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5299 ssize_int (reg_parm_stack_space));
5300 initial_offset_ptr->constant = 0;
5302 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5303 initial_offset_ptr->constant = reg_parm_stack_space;
5306 #endif /* REG_PARM_STACK_SPACE */
5308 arg_size_ptr->var = 0;
5309 arg_size_ptr->constant = 0;
5310 alignment_pad->var = 0;
5311 alignment_pad->constant = 0;
5313 #ifdef ARGS_GROW_DOWNWARD
5314 if (initial_offset_ptr->var)
5316 offset_ptr->constant = 0;
5317 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0),
5318 initial_offset_ptr->var);
5322 offset_ptr->constant = -initial_offset_ptr->constant;
5323 offset_ptr->var = 0;
5325 if (where_pad != none
5326 && (!host_integerp (sizetree, 1)
5327 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5328 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5329 SUB_PARM_SIZE (*offset_ptr, sizetree);
5330 if (where_pad != downward)
5331 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad);
5332 if (initial_offset_ptr->var)
5333 arg_size_ptr->var = size_binop (MINUS_EXPR,
5334 size_binop (MINUS_EXPR,
5336 initial_offset_ptr->var),
5340 arg_size_ptr->constant = (-initial_offset_ptr->constant
5341 - offset_ptr->constant);
5343 #else /* !ARGS_GROW_DOWNWARD */
5345 #ifdef REG_PARM_STACK_SPACE
5346 || REG_PARM_STACK_SPACE (fndecl) > 0
5349 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad);
5350 *offset_ptr = *initial_offset_ptr;
5352 #ifdef PUSH_ROUNDING
5353 if (passed_mode != BLKmode)
5354 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5357 /* Pad_below needs the pre-rounded size to know how much to pad below
5358 so this must be done before rounding up. */
5359 if (where_pad == downward
5360 /* However, BLKmode args passed in regs have their padding done elsewhere.
5361 The stack slot must be able to hold the entire register. */
5362 && !(in_regs && passed_mode == BLKmode))
5363 pad_below (offset_ptr, passed_mode, sizetree);
5365 if (where_pad != none
5366 && (!host_integerp (sizetree, 1)
5367 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5368 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5370 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5371 #endif /* ARGS_GROW_DOWNWARD */
5374 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5375 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5378 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad)
5379 struct args_size *offset_ptr;
5381 struct args_size *alignment_pad;
5383 tree save_var = NULL_TREE;
5384 HOST_WIDE_INT save_constant = 0;
5386 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5388 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5390 save_var = offset_ptr->var;
5391 save_constant = offset_ptr->constant;
5394 alignment_pad->var = NULL_TREE;
5395 alignment_pad->constant = 0;
5397 if (boundary > BITS_PER_UNIT)
5399 if (offset_ptr->var)
5402 #ifdef ARGS_GROW_DOWNWARD
5407 (ARGS_SIZE_TREE (*offset_ptr),
5408 boundary / BITS_PER_UNIT);
5409 offset_ptr->constant = 0; /*?*/
5410 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5411 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
5416 offset_ptr->constant =
5417 #ifdef ARGS_GROW_DOWNWARD
5418 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5420 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5422 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5423 alignment_pad->constant = offset_ptr->constant - save_constant;
5428 #ifndef ARGS_GROW_DOWNWARD
5430 pad_below (offset_ptr, passed_mode, sizetree)
5431 struct args_size *offset_ptr;
5432 enum machine_mode passed_mode;
5435 if (passed_mode != BLKmode)
5437 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5438 offset_ptr->constant
5439 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5440 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5441 - GET_MODE_SIZE (passed_mode));
5445 if (TREE_CODE (sizetree) != INTEGER_CST
5446 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5448 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5449 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5451 ADD_PARM_SIZE (*offset_ptr, s2);
5452 SUB_PARM_SIZE (*offset_ptr, sizetree);
5458 /* Walk the tree of blocks describing the binding levels within a function
5459 and warn about uninitialized variables.
5460 This is done after calling flow_analysis and before global_alloc
5461 clobbers the pseudo-regs to hard regs. */
5464 uninitialized_vars_warning (block)
5468 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5470 if (warn_uninitialized
5471 && TREE_CODE (decl) == VAR_DECL
5472 /* These warnings are unreliable for and aggregates
5473 because assigning the fields one by one can fail to convince
5474 flow.c that the entire aggregate was initialized.
5475 Unions are troublesome because members may be shorter. */
5476 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5477 && DECL_RTL (decl) != 0
5478 && GET_CODE (DECL_RTL (decl)) == REG
5479 /* Global optimizations can make it difficult to determine if a
5480 particular variable has been initialized. However, a VAR_DECL
5481 with a nonzero DECL_INITIAL had an initializer, so do not
5482 claim it is potentially uninitialized.
5484 We do not care about the actual value in DECL_INITIAL, so we do
5485 not worry that it may be a dangling pointer. */
5486 && DECL_INITIAL (decl) == NULL_TREE
5487 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5488 warning_with_decl (decl,
5489 "`%s' might be used uninitialized in this function");
5491 && TREE_CODE (decl) == VAR_DECL
5492 && DECL_RTL (decl) != 0
5493 && GET_CODE (DECL_RTL (decl)) == REG
5494 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5495 warning_with_decl (decl,
5496 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5498 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5499 uninitialized_vars_warning (sub);
5502 /* Do the appropriate part of uninitialized_vars_warning
5503 but for arguments instead of local variables. */
5506 setjmp_args_warning ()
5509 for (decl = DECL_ARGUMENTS (current_function_decl);
5510 decl; decl = TREE_CHAIN (decl))
5511 if (DECL_RTL (decl) != 0
5512 && GET_CODE (DECL_RTL (decl)) == REG
5513 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5514 warning_with_decl (decl,
5515 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5518 /* If this function call setjmp, put all vars into the stack
5519 unless they were declared `register'. */
5522 setjmp_protect (block)
5526 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5527 if ((TREE_CODE (decl) == VAR_DECL
5528 || TREE_CODE (decl) == PARM_DECL)
5529 && DECL_RTL (decl) != 0
5530 && (GET_CODE (DECL_RTL (decl)) == REG
5531 || (GET_CODE (DECL_RTL (decl)) == MEM
5532 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5533 /* If this variable came from an inline function, it must be
5534 that its life doesn't overlap the setjmp. If there was a
5535 setjmp in the function, it would already be in memory. We
5536 must exclude such variable because their DECL_RTL might be
5537 set to strange things such as virtual_stack_vars_rtx. */
5538 && ! DECL_FROM_INLINE (decl)
5540 #ifdef NON_SAVING_SETJMP
5541 /* If longjmp doesn't restore the registers,
5542 don't put anything in them. */
5546 ! DECL_REGISTER (decl)))
5547 put_var_into_stack (decl);
5548 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5549 setjmp_protect (sub);
5552 /* Like the previous function, but for args instead of local variables. */
5555 setjmp_protect_args ()
5558 for (decl = DECL_ARGUMENTS (current_function_decl);
5559 decl; decl = TREE_CHAIN (decl))
5560 if ((TREE_CODE (decl) == VAR_DECL
5561 || TREE_CODE (decl) == PARM_DECL)
5562 && DECL_RTL (decl) != 0
5563 && (GET_CODE (DECL_RTL (decl)) == REG
5564 || (GET_CODE (DECL_RTL (decl)) == MEM
5565 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5567 /* If longjmp doesn't restore the registers,
5568 don't put anything in them. */
5569 #ifdef NON_SAVING_SETJMP
5573 ! DECL_REGISTER (decl)))
5574 put_var_into_stack (decl);
5577 /* Return the context-pointer register corresponding to DECL,
5578 or 0 if it does not need one. */
5581 lookup_static_chain (decl)
5584 tree context = decl_function_context (decl);
5588 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5591 /* We treat inline_function_decl as an alias for the current function
5592 because that is the inline function whose vars, types, etc.
5593 are being merged into the current function.
5594 See expand_inline_function. */
5595 if (context == current_function_decl || context == inline_function_decl)
5596 return virtual_stack_vars_rtx;
5598 for (link = context_display; link; link = TREE_CHAIN (link))
5599 if (TREE_PURPOSE (link) == context)
5600 return RTL_EXPR_RTL (TREE_VALUE (link));
5605 /* Convert a stack slot address ADDR for variable VAR
5606 (from a containing function)
5607 into an address valid in this function (using a static chain). */
5610 fix_lexical_addr (addr, var)
5615 HOST_WIDE_INT displacement;
5616 tree context = decl_function_context (var);
5617 struct function *fp;
5620 /* If this is the present function, we need not do anything. */
5621 if (context == current_function_decl || context == inline_function_decl)
5624 fp = find_function_data (context);
5626 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5627 addr = XEXP (XEXP (addr, 0), 0);
5629 /* Decode given address as base reg plus displacement. */
5630 if (GET_CODE (addr) == REG)
5631 basereg = addr, displacement = 0;
5632 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5633 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5637 /* We accept vars reached via the containing function's
5638 incoming arg pointer and via its stack variables pointer. */
5639 if (basereg == fp->internal_arg_pointer)
5641 /* If reached via arg pointer, get the arg pointer value
5642 out of that function's stack frame.
5644 There are two cases: If a separate ap is needed, allocate a
5645 slot in the outer function for it and dereference it that way.
5646 This is correct even if the real ap is actually a pseudo.
5647 Otherwise, just adjust the offset from the frame pointer to
5650 #ifdef NEED_SEPARATE_AP
5653 addr = get_arg_pointer_save_area (fp);
5654 addr = fix_lexical_addr (XEXP (addr, 0), var);
5655 addr = memory_address (Pmode, addr);
5657 base = gen_rtx_MEM (Pmode, addr);
5658 set_mem_alias_set (base, get_frame_alias_set ());
5659 base = copy_to_reg (base);
5661 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5662 base = lookup_static_chain (var);
5666 else if (basereg == virtual_stack_vars_rtx)
5668 /* This is the same code as lookup_static_chain, duplicated here to
5669 avoid an extra call to decl_function_context. */
5672 for (link = context_display; link; link = TREE_CHAIN (link))
5673 if (TREE_PURPOSE (link) == context)
5675 base = RTL_EXPR_RTL (TREE_VALUE (link));
5683 /* Use same offset, relative to appropriate static chain or argument
5685 return plus_constant (base, displacement);
5688 /* Return the address of the trampoline for entering nested fn FUNCTION.
5689 If necessary, allocate a trampoline (in the stack frame)
5690 and emit rtl to initialize its contents (at entry to this function). */
5693 trampoline_address (function)
5699 struct function *fp;
5702 /* Find an existing trampoline and return it. */
5703 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5704 if (TREE_PURPOSE (link) == function)
5706 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5708 for (fp = outer_function_chain; fp; fp = fp->outer)
5709 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5710 if (TREE_PURPOSE (link) == function)
5712 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5714 return adjust_trampoline_addr (tramp);
5717 /* None exists; we must make one. */
5719 /* Find the `struct function' for the function containing FUNCTION. */
5721 fn_context = decl_function_context (function);
5722 if (fn_context != current_function_decl
5723 && fn_context != inline_function_decl)
5724 fp = find_function_data (fn_context);
5726 /* Allocate run-time space for this trampoline
5727 (usually in the defining function's stack frame). */
5728 #ifdef ALLOCATE_TRAMPOLINE
5729 tramp = ALLOCATE_TRAMPOLINE (fp);
5731 /* If rounding needed, allocate extra space
5732 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5733 #ifdef TRAMPOLINE_ALIGNMENT
5734 #define TRAMPOLINE_REAL_SIZE \
5735 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5737 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5739 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5743 /* Record the trampoline for reuse and note it for later initialization
5744 by expand_function_end. */
5747 rtlexp = make_node (RTL_EXPR);
5748 RTL_EXPR_RTL (rtlexp) = tramp;
5749 fp->x_trampoline_list = tree_cons (function, rtlexp,
5750 fp->x_trampoline_list);
5754 /* Make the RTL_EXPR node temporary, not momentary, so that the
5755 trampoline_list doesn't become garbage. */
5756 rtlexp = make_node (RTL_EXPR);
5758 RTL_EXPR_RTL (rtlexp) = tramp;
5759 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5762 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5763 return adjust_trampoline_addr (tramp);
5766 /* Given a trampoline address,
5767 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5770 round_trampoline_addr (tramp)
5773 #ifdef TRAMPOLINE_ALIGNMENT
5774 /* Round address up to desired boundary. */
5775 rtx temp = gen_reg_rtx (Pmode);
5776 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1);
5777 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
5779 temp = expand_simple_binop (Pmode, PLUS, tramp, addend,
5780 temp, 0, OPTAB_LIB_WIDEN);
5781 tramp = expand_simple_binop (Pmode, AND, temp, mask,
5782 temp, 0, OPTAB_LIB_WIDEN);
5787 /* Given a trampoline address, round it then apply any
5788 platform-specific adjustments so that the result can be used for a
5792 adjust_trampoline_addr (tramp)
5795 tramp = round_trampoline_addr (tramp);
5796 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5797 TRAMPOLINE_ADJUST_ADDRESS (tramp);
5802 /* Put all this function's BLOCK nodes including those that are chained
5803 onto the first block into a vector, and return it.
5804 Also store in each NOTE for the beginning or end of a block
5805 the index of that block in the vector.
5806 The arguments are BLOCK, the chain of top-level blocks of the function,
5807 and INSNS, the insn chain of the function. */
5813 tree *block_vector, *last_block_vector;
5815 tree block = DECL_INITIAL (current_function_decl);
5820 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5821 depth-first order. */
5822 block_vector = get_block_vector (block, &n_blocks);
5823 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree));
5825 last_block_vector = identify_blocks_1 (get_insns (),
5827 block_vector + n_blocks,
5830 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5831 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5832 if (0 && last_block_vector != block_vector + n_blocks)
5835 free (block_vector);
5839 /* Subroutine of identify_blocks. Do the block substitution on the
5840 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5842 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5843 BLOCK_VECTOR is incremented for each block seen. */
5846 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack)
5849 tree *end_block_vector;
5850 tree *orig_block_stack;
5853 tree *block_stack = orig_block_stack;
5855 for (insn = insns; insn; insn = NEXT_INSN (insn))
5857 if (GET_CODE (insn) == NOTE)
5859 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5863 /* If there are more block notes than BLOCKs, something
5865 if (block_vector == end_block_vector)
5868 b = *block_vector++;
5869 NOTE_BLOCK (insn) = b;
5872 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5874 /* If there are more NOTE_INSN_BLOCK_ENDs than
5875 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5876 if (block_stack == orig_block_stack)
5879 NOTE_BLOCK (insn) = *--block_stack;
5882 else if (GET_CODE (insn) == CALL_INSN
5883 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5885 rtx cp = PATTERN (insn);
5887 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector,
5888 end_block_vector, block_stack);
5890 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector,
5891 end_block_vector, block_stack);
5893 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector,
5894 end_block_vector, block_stack);
5898 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5899 something is badly wrong. */
5900 if (block_stack != orig_block_stack)
5903 return block_vector;
5906 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5907 and create duplicate blocks. */
5908 /* ??? Need an option to either create block fragments or to create
5909 abstract origin duplicates of a source block. It really depends
5910 on what optimization has been performed. */
5915 tree block = DECL_INITIAL (current_function_decl);
5916 varray_type block_stack;
5918 if (block == NULL_TREE)
5921 VARRAY_TREE_INIT (block_stack, 10, "block_stack");
5923 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5924 reorder_blocks_0 (block);
5926 /* Prune the old trees away, so that they don't get in the way. */
5927 BLOCK_SUBBLOCKS (block) = NULL_TREE;
5928 BLOCK_CHAIN (block) = NULL_TREE;
5930 /* Recreate the block tree from the note nesting. */
5931 reorder_blocks_1 (get_insns (), block, &block_stack);
5932 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
5934 /* Remove deleted blocks from the block fragment chains. */
5935 reorder_fix_fragments (block);
5937 VARRAY_FREE (block_stack);
5940 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5943 reorder_blocks_0 (block)
5948 TREE_ASM_WRITTEN (block) = 0;
5949 reorder_blocks_0 (BLOCK_SUBBLOCKS (block));
5950 block = BLOCK_CHAIN (block);
5955 reorder_blocks_1 (insns, current_block, p_block_stack)
5958 varray_type *p_block_stack;
5962 for (insn = insns; insn; insn = NEXT_INSN (insn))
5964 if (GET_CODE (insn) == NOTE)
5966 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5968 tree block = NOTE_BLOCK (insn);
5970 /* If we have seen this block before, that means it now
5971 spans multiple address regions. Create a new fragment. */
5972 if (TREE_ASM_WRITTEN (block))
5974 tree new_block = copy_node (block);
5977 origin = (BLOCK_FRAGMENT_ORIGIN (block)
5978 ? BLOCK_FRAGMENT_ORIGIN (block)
5980 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
5981 BLOCK_FRAGMENT_CHAIN (new_block)
5982 = BLOCK_FRAGMENT_CHAIN (origin);
5983 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
5985 NOTE_BLOCK (insn) = new_block;
5989 BLOCK_SUBBLOCKS (block) = 0;
5990 TREE_ASM_WRITTEN (block) = 1;
5991 BLOCK_SUPERCONTEXT (block) = current_block;
5992 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5993 BLOCK_SUBBLOCKS (current_block) = block;
5994 current_block = block;
5995 VARRAY_PUSH_TREE (*p_block_stack, block);
5997 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5999 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack);
6000 VARRAY_POP (*p_block_stack);
6001 BLOCK_SUBBLOCKS (current_block)
6002 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
6003 current_block = BLOCK_SUPERCONTEXT (current_block);
6006 else if (GET_CODE (insn) == CALL_INSN
6007 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
6009 rtx cp = PATTERN (insn);
6010 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack);
6012 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack);
6014 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
6019 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
6020 appears in the block tree, select one of the fragments to become
6021 the new origin block. */
6024 reorder_fix_fragments (block)
6029 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
6030 tree new_origin = NULL_TREE;
6034 if (! TREE_ASM_WRITTEN (dup_origin))
6036 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
6038 /* Find the first of the remaining fragments. There must
6039 be at least one -- the current block. */
6040 while (! TREE_ASM_WRITTEN (new_origin))
6041 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
6042 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
6045 else if (! dup_origin)
6048 /* Re-root the rest of the fragments to the new origin. In the
6049 case that DUP_ORIGIN was null, that means BLOCK was the origin
6050 of a chain of fragments and we want to remove those fragments
6051 that didn't make it to the output. */
6054 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
6059 if (TREE_ASM_WRITTEN (chain))
6061 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
6063 pp = &BLOCK_FRAGMENT_CHAIN (chain);
6065 chain = BLOCK_FRAGMENT_CHAIN (chain);
6070 reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
6071 block = BLOCK_CHAIN (block);
6075 /* Reverse the order of elements in the chain T of blocks,
6076 and return the new head of the chain (old last element). */
6082 tree prev = 0, decl, next;
6083 for (decl = t; decl; decl = next)
6085 next = BLOCK_CHAIN (decl);
6086 BLOCK_CHAIN (decl) = prev;
6092 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6093 non-NULL, list them all into VECTOR, in a depth-first preorder
6094 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6098 all_blocks (block, vector)
6106 TREE_ASM_WRITTEN (block) = 0;
6108 /* Record this block. */
6110 vector[n_blocks] = block;
6114 /* Record the subblocks, and their subblocks... */
6115 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
6116 vector ? vector + n_blocks : 0);
6117 block = BLOCK_CHAIN (block);
6123 /* Return a vector containing all the blocks rooted at BLOCK. The
6124 number of elements in the vector is stored in N_BLOCKS_P. The
6125 vector is dynamically allocated; it is the caller's responsibility
6126 to call `free' on the pointer returned. */
6129 get_block_vector (block, n_blocks_p)
6135 *n_blocks_p = all_blocks (block, NULL);
6136 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree));
6137 all_blocks (block, block_vector);
6139 return block_vector;
6142 static int next_block_index = 2;
6144 /* Set BLOCK_NUMBER for all the blocks in FN. */
6154 /* For SDB and XCOFF debugging output, we start numbering the blocks
6155 from 1 within each function, rather than keeping a running
6157 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6158 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
6159 next_block_index = 1;
6162 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
6164 /* The top-level BLOCK isn't numbered at all. */
6165 for (i = 1; i < n_blocks; ++i)
6166 /* We number the blocks from two. */
6167 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
6169 free (block_vector);
6174 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6177 debug_find_var_in_block_tree (var, block)
6183 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
6187 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
6189 tree ret = debug_find_var_in_block_tree (var, t);
6197 /* Allocate a function structure and reset its contents to the defaults. */
6200 prepare_function_start ()
6202 cfun = (struct function *) ggc_alloc_cleared (sizeof (struct function));
6204 init_stmt_for_function ();
6205 init_eh_for_function ();
6207 cse_not_expected = ! optimize;
6209 /* Caller save not needed yet. */
6210 caller_save_needed = 0;
6212 /* No stack slots have been made yet. */
6213 stack_slot_list = 0;
6215 current_function_has_nonlocal_label = 0;
6216 current_function_has_nonlocal_goto = 0;
6218 /* There is no stack slot for handling nonlocal gotos. */
6219 nonlocal_goto_handler_slots = 0;
6220 nonlocal_goto_stack_level = 0;
6222 /* No labels have been declared for nonlocal use. */
6223 nonlocal_labels = 0;
6224 nonlocal_goto_handler_labels = 0;
6226 /* No function calls so far in this function. */
6227 function_call_count = 0;
6229 /* No parm regs have been allocated.
6230 (This is important for output_inline_function.) */
6231 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
6233 /* Initialize the RTL mechanism. */
6236 /* Initialize the queue of pending postincrement and postdecrements,
6237 and some other info in expr.c. */
6240 /* We haven't done register allocation yet. */
6243 init_varasm_status (cfun);
6245 /* Clear out data used for inlining. */
6246 cfun->inlinable = 0;
6247 cfun->original_decl_initial = 0;
6248 cfun->original_arg_vector = 0;
6250 cfun->stack_alignment_needed = STACK_BOUNDARY;
6251 cfun->preferred_stack_boundary = STACK_BOUNDARY;
6253 /* Set if a call to setjmp is seen. */
6254 current_function_calls_setjmp = 0;
6256 /* Set if a call to longjmp is seen. */
6257 current_function_calls_longjmp = 0;
6259 current_function_calls_alloca = 0;
6260 current_function_contains_functions = 0;
6261 current_function_is_leaf = 0;
6262 current_function_nothrow = 0;
6263 current_function_sp_is_unchanging = 0;
6264 current_function_uses_only_leaf_regs = 0;
6265 current_function_has_computed_jump = 0;
6266 current_function_is_thunk = 0;
6268 current_function_returns_pcc_struct = 0;
6269 current_function_returns_struct = 0;
6270 current_function_epilogue_delay_list = 0;
6271 current_function_uses_const_pool = 0;
6272 current_function_uses_pic_offset_table = 0;
6273 current_function_cannot_inline = 0;
6275 /* We have not yet needed to make a label to jump to for tail-recursion. */
6276 tail_recursion_label = 0;
6278 /* We haven't had a need to make a save area for ap yet. */
6279 arg_pointer_save_area = 0;
6281 /* No stack slots allocated yet. */
6284 /* No SAVE_EXPRs in this function yet. */
6287 /* No RTL_EXPRs in this function yet. */
6290 /* Set up to allocate temporaries. */
6293 /* Indicate that we need to distinguish between the return value of the
6294 present function and the return value of a function being called. */
6295 rtx_equal_function_value_matters = 1;
6297 /* Indicate that we have not instantiated virtual registers yet. */
6298 virtuals_instantiated = 0;
6300 /* Indicate that we want CONCATs now. */
6301 generating_concat_p = 1;
6303 /* Indicate we have no need of a frame pointer yet. */
6304 frame_pointer_needed = 0;
6306 /* By default assume not varargs or stdarg. */
6307 current_function_varargs = 0;
6308 current_function_stdarg = 0;
6310 /* We haven't made any trampolines for this function yet. */
6311 trampoline_list = 0;
6313 init_pending_stack_adjust ();
6314 inhibit_defer_pop = 0;
6316 current_function_outgoing_args_size = 0;
6318 (*lang_hooks.function.init) (cfun);
6319 if (init_machine_status)
6320 (*init_machine_status) (cfun);
6323 /* Initialize the rtl expansion mechanism so that we can do simple things
6324 like generate sequences. This is used to provide a context during global
6325 initialization of some passes. */
6327 init_dummy_function_start ()
6329 prepare_function_start ();
6332 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6333 and initialize static variables for generating RTL for the statements
6337 init_function_start (subr, filename, line)
6339 const char *filename;
6342 prepare_function_start ();
6344 current_function_name = (*lang_hooks.decl_printable_name) (subr, 2);
6347 /* Nonzero if this is a nested function that uses a static chain. */
6349 current_function_needs_context
6350 = (decl_function_context (current_function_decl) != 0
6351 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6353 /* Within function body, compute a type's size as soon it is laid out. */
6354 immediate_size_expand++;
6356 /* Prevent ever trying to delete the first instruction of a function.
6357 Also tell final how to output a linenum before the function prologue.
6358 Note linenums could be missing, e.g. when compiling a Java .class file. */
6360 emit_line_note (filename, line);
6362 /* Make sure first insn is a note even if we don't want linenums.
6363 This makes sure the first insn will never be deleted.
6364 Also, final expects a note to appear there. */
6365 emit_note (NULL, NOTE_INSN_DELETED);
6367 /* Set flags used by final.c. */
6368 if (aggregate_value_p (DECL_RESULT (subr)))
6370 #ifdef PCC_STATIC_STRUCT_RETURN
6371 current_function_returns_pcc_struct = 1;
6373 current_function_returns_struct = 1;
6376 /* Warn if this value is an aggregate type,
6377 regardless of which calling convention we are using for it. */
6378 if (warn_aggregate_return
6379 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6380 warning ("function returns an aggregate");
6382 current_function_returns_pointer
6383 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6386 /* Make sure all values used by the optimization passes have sane
6389 init_function_for_compilation ()
6393 /* No prologue/epilogue insns yet. */
6394 VARRAY_GROW (prologue, 0);
6395 VARRAY_GROW (epilogue, 0);
6396 VARRAY_GROW (sibcall_epilogue, 0);
6399 /* Indicate that the current function uses extra args
6400 not explicitly mentioned in the argument list in any fashion. */
6405 current_function_varargs = 1;
6408 /* Expand a call to __main at the beginning of a possible main function. */
6410 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6411 #undef HAS_INIT_SECTION
6412 #define HAS_INIT_SECTION
6416 expand_main_function ()
6418 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6419 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
6421 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
6425 /* Forcibly align the stack. */
6426 #ifdef STACK_GROWS_DOWNWARD
6427 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
6428 stack_pointer_rtx, 1, OPTAB_WIDEN);
6430 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
6431 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN);
6432 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align),
6433 stack_pointer_rtx, 1, OPTAB_WIDEN);
6435 if (tmp != stack_pointer_rtx)
6436 emit_move_insn (stack_pointer_rtx, tmp);
6438 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6439 tmp = force_reg (Pmode, const0_rtx);
6440 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
6441 seq = gen_sequence ();
6444 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp))
6445 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG)
6448 emit_insn_before (seq, tmp);
6454 #ifndef HAS_INIT_SECTION
6455 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), LCT_NORMAL,
6460 extern struct obstack permanent_obstack;
6462 /* The PENDING_SIZES represent the sizes of variable-sized types.
6463 Create RTL for the various sizes now (using temporary variables),
6464 so that we can refer to the sizes from the RTL we are generating
6465 for the current function. The PENDING_SIZES are a TREE_LIST. The
6466 TREE_VALUE of each node is a SAVE_EXPR. */
6469 expand_pending_sizes (pending_sizes)
6474 /* Evaluate now the sizes of any types declared among the arguments. */
6475 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem))
6477 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
6478 /* Flush the queue in case this parameter declaration has
6484 /* Start the RTL for a new function, and set variables used for
6486 SUBR is the FUNCTION_DECL node.
6487 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6488 the function's parameters, which must be run at any return statement. */
6491 expand_function_start (subr, parms_have_cleanups)
6493 int parms_have_cleanups;
6496 rtx last_ptr = NULL_RTX;
6498 /* Make sure volatile mem refs aren't considered
6499 valid operands of arithmetic insns. */
6500 init_recog_no_volatile ();
6502 current_function_instrument_entry_exit
6503 = (flag_instrument_function_entry_exit
6504 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6506 current_function_profile
6508 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6510 current_function_limit_stack
6511 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
6513 /* If function gets a static chain arg, store it in the stack frame.
6514 Do this first, so it gets the first stack slot offset. */
6515 if (current_function_needs_context)
6517 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6519 /* Delay copying static chain if it is not a register to avoid
6520 conflicts with regs used for parameters. */
6521 if (! SMALL_REGISTER_CLASSES
6522 || GET_CODE (static_chain_incoming_rtx) == REG)
6523 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6526 /* If the parameters of this function need cleaning up, get a label
6527 for the beginning of the code which executes those cleanups. This must
6528 be done before doing anything with return_label. */
6529 if (parms_have_cleanups)
6530 cleanup_label = gen_label_rtx ();
6534 /* Make the label for return statements to jump to. Do not special
6535 case machines with special return instructions -- they will be
6536 handled later during jump, ifcvt, or epilogue creation. */
6537 return_label = gen_label_rtx ();
6539 /* Initialize rtx used to return the value. */
6540 /* Do this before assign_parms so that we copy the struct value address
6541 before any library calls that assign parms might generate. */
6543 /* Decide whether to return the value in memory or in a register. */
6544 if (aggregate_value_p (DECL_RESULT (subr)))
6546 /* Returning something that won't go in a register. */
6547 rtx value_address = 0;
6549 #ifdef PCC_STATIC_STRUCT_RETURN
6550 if (current_function_returns_pcc_struct)
6552 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6553 value_address = assemble_static_space (size);
6558 /* Expect to be passed the address of a place to store the value.
6559 If it is passed as an argument, assign_parms will take care of
6561 if (struct_value_incoming_rtx)
6563 value_address = gen_reg_rtx (Pmode);
6564 emit_move_insn (value_address, struct_value_incoming_rtx);
6569 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6570 set_mem_attributes (x, DECL_RESULT (subr), 1);
6571 SET_DECL_RTL (DECL_RESULT (subr), x);
6574 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6575 /* If return mode is void, this decl rtl should not be used. */
6576 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
6579 /* Compute the return values into a pseudo reg, which we will copy
6580 into the true return register after the cleanups are done. */
6582 /* In order to figure out what mode to use for the pseudo, we
6583 figure out what the mode of the eventual return register will
6584 actually be, and use that. */
6586 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)),
6589 /* Structures that are returned in registers are not aggregate_value_p,
6590 so we may see a PARALLEL. Don't play pseudo games with this. */
6591 if (! REG_P (hard_reg))
6592 SET_DECL_RTL (DECL_RESULT (subr), hard_reg);
6595 /* Create the pseudo. */
6596 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg)));
6598 /* Needed because we may need to move this to memory
6599 in case it's a named return value whose address is taken. */
6600 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6604 /* Initialize rtx for parameters and local variables.
6605 In some cases this requires emitting insns. */
6607 assign_parms (subr);
6609 /* Copy the static chain now if it wasn't a register. The delay is to
6610 avoid conflicts with the parameter passing registers. */
6612 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6613 if (GET_CODE (static_chain_incoming_rtx) != REG)
6614 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6616 /* The following was moved from init_function_start.
6617 The move is supposed to make sdb output more accurate. */
6618 /* Indicate the beginning of the function body,
6619 as opposed to parm setup. */
6620 emit_note (NULL, NOTE_INSN_FUNCTION_BEG);
6622 if (GET_CODE (get_last_insn ()) != NOTE)
6623 emit_note (NULL, NOTE_INSN_DELETED);
6624 parm_birth_insn = get_last_insn ();
6626 context_display = 0;
6627 if (current_function_needs_context)
6629 /* Fetch static chain values for containing functions. */
6630 tem = decl_function_context (current_function_decl);
6631 /* Copy the static chain pointer into a pseudo. If we have
6632 small register classes, copy the value from memory if
6633 static_chain_incoming_rtx is a REG. */
6636 /* If the static chain originally came in a register, put it back
6637 there, then move it out in the next insn. The reason for
6638 this peculiar code is to satisfy function integration. */
6639 if (SMALL_REGISTER_CLASSES
6640 && GET_CODE (static_chain_incoming_rtx) == REG)
6641 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6642 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6647 tree rtlexp = make_node (RTL_EXPR);
6649 RTL_EXPR_RTL (rtlexp) = last_ptr;
6650 context_display = tree_cons (tem, rtlexp, context_display);
6651 tem = decl_function_context (tem);
6654 /* Chain thru stack frames, assuming pointer to next lexical frame
6655 is found at the place we always store it. */
6656 #ifdef FRAME_GROWS_DOWNWARD
6657 last_ptr = plus_constant (last_ptr,
6658 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode));
6660 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr));
6661 set_mem_alias_set (last_ptr, get_frame_alias_set ());
6662 last_ptr = copy_to_reg (last_ptr);
6664 /* If we are not optimizing, ensure that we know that this
6665 piece of context is live over the entire function. */
6667 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6672 if (current_function_instrument_entry_exit)
6674 rtx fun = DECL_RTL (current_function_decl);
6675 if (GET_CODE (fun) == MEM)
6676 fun = XEXP (fun, 0);
6679 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode,
6681 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6683 hard_frame_pointer_rtx),
6688 if (current_function_profile)
6689 PROFILE_HOOK (profile_label_no);
6692 /* After the display initializations is where the tail-recursion label
6693 should go, if we end up needing one. Ensure we have a NOTE here
6694 since some things (like trampolines) get placed before this. */
6695 tail_recursion_reentry = emit_note (NULL, NOTE_INSN_DELETED);
6697 /* Evaluate now the sizes of any types declared among the arguments. */
6698 expand_pending_sizes (nreverse (get_pending_sizes ()));
6700 /* Make sure there is a line number after the function entry setup code. */
6701 force_next_line_note ();
6704 /* Undo the effects of init_dummy_function_start. */
6706 expand_dummy_function_end ()
6708 /* End any sequences that failed to be closed due to syntax errors. */
6709 while (in_sequence_p ())
6712 /* Outside function body, can't compute type's actual size
6713 until next function's body starts. */
6715 free_after_parsing (cfun);
6716 free_after_compilation (cfun);
6720 /* Call DOIT for each hard register used as a return value from
6721 the current function. */
6724 diddle_return_value (doit, arg)
6725 void (*doit) PARAMS ((rtx, void *));
6728 rtx outgoing = current_function_return_rtx;
6733 if (GET_CODE (outgoing) == REG)
6734 (*doit) (outgoing, arg);
6735 else if (GET_CODE (outgoing) == PARALLEL)
6739 for (i = 0; i < XVECLEN (outgoing, 0); i++)
6741 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
6743 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6750 do_clobber_return_reg (reg, arg)
6752 void *arg ATTRIBUTE_UNUSED;
6754 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
6758 clobber_return_register ()
6760 diddle_return_value (do_clobber_return_reg, NULL);
6762 /* In case we do use pseudo to return value, clobber it too. */
6763 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6765 tree decl_result = DECL_RESULT (current_function_decl);
6766 rtx decl_rtl = DECL_RTL (decl_result);
6767 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
6769 do_clobber_return_reg (decl_rtl, NULL);
6775 do_use_return_reg (reg, arg)
6777 void *arg ATTRIBUTE_UNUSED;
6779 emit_insn (gen_rtx_USE (VOIDmode, reg));
6783 use_return_register ()
6785 diddle_return_value (do_use_return_reg, NULL);
6788 /* Generate RTL for the end of the current function.
6789 FILENAME and LINE are the current position in the source file.
6791 It is up to language-specific callers to do cleanups for parameters--
6792 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6795 expand_function_end (filename, line, end_bindings)
6796 const char *filename;
6803 #ifdef TRAMPOLINE_TEMPLATE
6804 static rtx initial_trampoline;
6807 finish_expr_for_function ();
6809 /* If arg_pointer_save_area was referenced only from a nested
6810 function, we will not have initialized it yet. Do that now. */
6811 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init)
6812 get_arg_pointer_save_area (cfun);
6814 #ifdef NON_SAVING_SETJMP
6815 /* Don't put any variables in registers if we call setjmp
6816 on a machine that fails to restore the registers. */
6817 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6819 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6820 setjmp_protect (DECL_INITIAL (current_function_decl));
6822 setjmp_protect_args ();
6826 /* Initialize any trampolines required by this function. */
6827 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6829 tree function = TREE_PURPOSE (link);
6830 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function);
6831 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6832 #ifdef TRAMPOLINE_TEMPLATE
6837 #ifdef TRAMPOLINE_TEMPLATE
6838 /* First make sure this compilation has a template for
6839 initializing trampolines. */
6840 if (initial_trampoline == 0)
6843 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6844 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
6846 ggc_add_rtx_root (&initial_trampoline, 1);
6850 /* Generate insns to initialize the trampoline. */
6852 tramp = round_trampoline_addr (XEXP (tramp, 0));
6853 #ifdef TRAMPOLINE_TEMPLATE
6854 blktramp = replace_equiv_address (initial_trampoline, tramp);
6855 emit_block_move (blktramp, initial_trampoline,
6856 GEN_INT (TRAMPOLINE_SIZE));
6858 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6862 /* Put those insns at entry to the containing function (this one). */
6863 emit_insns_before (seq, tail_recursion_reentry);
6866 /* If we are doing stack checking and this function makes calls,
6867 do a stack probe at the start of the function to ensure we have enough
6868 space for another stack frame. */
6869 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6873 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6874 if (GET_CODE (insn) == CALL_INSN)
6877 probe_stack_range (STACK_CHECK_PROTECT,
6878 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6881 emit_insns_before (seq, tail_recursion_reentry);
6886 /* Warn about unused parms if extra warnings were specified. */
6887 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
6888 warning. WARN_UNUSED_PARAMETER is negative when set by
6890 if (warn_unused_parameter > 0
6891 || (warn_unused_parameter < 0 && extra_warnings))
6895 for (decl = DECL_ARGUMENTS (current_function_decl);
6896 decl; decl = TREE_CHAIN (decl))
6897 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6898 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6899 warning_with_decl (decl, "unused parameter `%s'");
6902 /* Delete handlers for nonlocal gotos if nothing uses them. */
6903 if (nonlocal_goto_handler_slots != 0
6904 && ! current_function_has_nonlocal_label)
6907 /* End any sequences that failed to be closed due to syntax errors. */
6908 while (in_sequence_p ())
6911 /* Outside function body, can't compute type's actual size
6912 until next function's body starts. */
6913 immediate_size_expand--;
6915 clear_pending_stack_adjust ();
6916 do_pending_stack_adjust ();
6918 /* Mark the end of the function body.
6919 If control reaches this insn, the function can drop through
6920 without returning a value. */
6921 emit_note (NULL, NOTE_INSN_FUNCTION_END);
6923 /* Must mark the last line number note in the function, so that the test
6924 coverage code can avoid counting the last line twice. This just tells
6925 the code to ignore the immediately following line note, since there
6926 already exists a copy of this note somewhere above. This line number
6927 note is still needed for debugging though, so we can't delete it. */
6928 if (flag_test_coverage)
6929 emit_note (NULL, NOTE_INSN_REPEATED_LINE_NUMBER);
6931 /* Output a linenumber for the end of the function.
6932 SDB depends on this. */
6933 emit_line_note_force (filename, line);
6935 /* Before the return label (if any), clobber the return
6936 registers so that they are not propagated live to the rest of
6937 the function. This can only happen with functions that drop
6938 through; if there had been a return statement, there would
6939 have either been a return rtx, or a jump to the return label.
6941 We delay actual code generation after the current_function_value_rtx
6943 clobber_after = get_last_insn ();
6945 /* Output the label for the actual return from the function,
6946 if one is expected. This happens either because a function epilogue
6947 is used instead of a return instruction, or because a return was done
6948 with a goto in order to run local cleanups, or because of pcc-style
6949 structure returning. */
6951 emit_label (return_label);
6953 /* C++ uses this. */
6955 expand_end_bindings (0, 0, 0);
6957 if (current_function_instrument_entry_exit)
6959 rtx fun = DECL_RTL (current_function_decl);
6960 if (GET_CODE (fun) == MEM)
6961 fun = XEXP (fun, 0);
6964 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode,
6966 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6968 hard_frame_pointer_rtx),
6972 /* Let except.c know where it should emit the call to unregister
6973 the function context for sjlj exceptions. */
6974 if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
6975 sjlj_emit_function_exit_after (get_last_insn ());
6977 /* If we had calls to alloca, and this machine needs
6978 an accurate stack pointer to exit the function,
6979 insert some code to save and restore the stack pointer. */
6980 #ifdef EXIT_IGNORE_STACK
6981 if (! EXIT_IGNORE_STACK)
6983 if (current_function_calls_alloca)
6987 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6988 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6991 /* If scalar return value was computed in a pseudo-reg, or was a named
6992 return value that got dumped to the stack, copy that to the hard
6994 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6996 tree decl_result = DECL_RESULT (current_function_decl);
6997 rtx decl_rtl = DECL_RTL (decl_result);
6999 if (REG_P (decl_rtl)
7000 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
7001 : DECL_REGISTER (decl_result))
7003 rtx real_decl_rtl = current_function_return_rtx;
7005 /* This should be set in assign_parms. */
7006 if (! REG_FUNCTION_VALUE_P (real_decl_rtl))
7009 /* If this is a BLKmode structure being returned in registers,
7010 then use the mode computed in expand_return. Note that if
7011 decl_rtl is memory, then its mode may have been changed,
7012 but that current_function_return_rtx has not. */
7013 if (GET_MODE (real_decl_rtl) == BLKmode)
7014 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
7016 /* If a named return value dumped decl_return to memory, then
7017 we may need to re-do the PROMOTE_MODE signed/unsigned
7019 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
7021 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result));
7023 #ifdef PROMOTE_FUNCTION_RETURN
7024 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
7028 convert_move (real_decl_rtl, decl_rtl, unsignedp);
7030 else if (GET_CODE (real_decl_rtl) == PARALLEL)
7031 emit_group_load (real_decl_rtl, decl_rtl,
7032 int_size_in_bytes (TREE_TYPE (decl_result)));
7034 emit_move_insn (real_decl_rtl, decl_rtl);
7038 /* If returning a structure, arrange to return the address of the value
7039 in a place where debuggers expect to find it.
7041 If returning a structure PCC style,
7042 the caller also depends on this value.
7043 And current_function_returns_pcc_struct is not necessarily set. */
7044 if (current_function_returns_struct
7045 || current_function_returns_pcc_struct)
7048 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
7049 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
7050 #ifdef FUNCTION_OUTGOING_VALUE
7052 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
7053 current_function_decl);
7056 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl);
7059 /* Mark this as a function return value so integrate will delete the
7060 assignment and USE below when inlining this function. */
7061 REG_FUNCTION_VALUE_P (outgoing) = 1;
7063 #ifdef POINTERS_EXTEND_UNSIGNED
7064 /* The address may be ptr_mode and OUTGOING may be Pmode. */
7065 if (GET_MODE (outgoing) != GET_MODE (value_address))
7066 value_address = convert_memory_address (GET_MODE (outgoing),
7070 emit_move_insn (outgoing, value_address);
7072 /* Show return register used to hold result (in this case the address
7074 current_function_return_rtx = outgoing;
7077 /* If this is an implementation of throw, do what's necessary to
7078 communicate between __builtin_eh_return and the epilogue. */
7079 expand_eh_return ();
7081 /* Emit the actual code to clobber return register. */
7086 clobber_return_register ();
7087 seq = gen_sequence ();
7090 after = emit_insn_after (seq, clobber_after);
7092 if (clobber_after != after)
7093 cfun->x_clobber_return_insn = after;
7096 /* ??? This should no longer be necessary since stupid is no longer with
7097 us, but there are some parts of the compiler (eg reload_combine, and
7098 sh mach_dep_reorg) that still try and compute their own lifetime info
7099 instead of using the general framework. */
7100 use_return_register ();
7102 /* Fix up any gotos that jumped out to the outermost
7103 binding level of the function.
7104 Must follow emitting RETURN_LABEL. */
7106 /* If you have any cleanups to do at this point,
7107 and they need to create temporary variables,
7108 then you will lose. */
7109 expand_fixups (get_insns ());
7113 get_arg_pointer_save_area (f)
7116 rtx ret = f->x_arg_pointer_save_area;
7120 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f);
7121 f->x_arg_pointer_save_area = ret;
7124 if (f == cfun && ! f->arg_pointer_save_area_init)
7128 /* Save the arg pointer at the beginning of the function. The
7129 generated stack slot may not be a valid memory address, so we
7130 have to check it and fix it if necessary. */
7132 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx);
7133 seq = gen_sequence ();
7136 push_topmost_sequence ();
7137 emit_insn_after (seq, get_insns ());
7138 pop_topmost_sequence ();
7144 /* Extend a vector that records the INSN_UIDs of INSNS (either a
7145 sequence or a single insn). */
7148 record_insns (insns, vecp)
7152 if (GET_CODE (insns) == SEQUENCE)
7154 int len = XVECLEN (insns, 0);
7155 int i = VARRAY_SIZE (*vecp);
7157 VARRAY_GROW (*vecp, i + len);
7160 VARRAY_INT (*vecp, i) = INSN_UID (XVECEXP (insns, 0, len));
7166 int i = VARRAY_SIZE (*vecp);
7167 VARRAY_GROW (*vecp, i + 1);
7168 VARRAY_INT (*vecp, i) = INSN_UID (insns);
7172 /* Determine how many INSN_UIDs in VEC are part of INSN. */
7175 contains (insn, vec)
7181 if (GET_CODE (insn) == INSN
7182 && GET_CODE (PATTERN (insn)) == SEQUENCE)
7185 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
7186 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7187 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
7193 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7194 if (INSN_UID (insn) == VARRAY_INT (vec, j))
7201 prologue_epilogue_contains (insn)
7204 if (contains (insn, prologue))
7206 if (contains (insn, epilogue))
7212 sibcall_epilogue_contains (insn)
7215 if (sibcall_epilogue)
7216 return contains (insn, sibcall_epilogue);
7221 /* Insert gen_return at the end of block BB. This also means updating
7222 block_for_insn appropriately. */
7225 emit_return_into_block (bb, line_note)
7231 p = NEXT_INSN (bb->end);
7232 end = emit_jump_insn_after (gen_return (), bb->end);
7234 emit_line_note_after (NOTE_SOURCE_FILE (line_note),
7235 NOTE_LINE_NUMBER (line_note), PREV_INSN (bb->end));
7237 #endif /* HAVE_return */
7239 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7241 /* These functions convert the epilogue into a variant that does not modify the
7242 stack pointer. This is used in cases where a function returns an object
7243 whose size is not known until it is computed. The called function leaves the
7244 object on the stack, leaves the stack depressed, and returns a pointer to
7247 What we need to do is track all modifications and references to the stack
7248 pointer, deleting the modifications and changing the references to point to
7249 the location the stack pointer would have pointed to had the modifications
7252 These functions need to be portable so we need to make as few assumptions
7253 about the epilogue as we can. However, the epilogue basically contains
7254 three things: instructions to reset the stack pointer, instructions to
7255 reload registers, possibly including the frame pointer, and an
7256 instruction to return to the caller.
7258 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7259 We also make no attempt to validate the insns we make since if they are
7260 invalid, we probably can't do anything valid. The intent is that these
7261 routines get "smarter" as more and more machines start to use them and
7262 they try operating on different epilogues.
7264 We use the following structure to track what the part of the epilogue that
7265 we've already processed has done. We keep two copies of the SP equivalence,
7266 one for use during the insn we are processing and one for use in the next
7267 insn. The difference is because one part of a PARALLEL may adjust SP
7268 and the other may use it. */
7272 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */
7273 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */
7274 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */
7275 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */
7276 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG
7277 should be set to once we no longer need
7281 static void handle_epilogue_set PARAMS ((rtx, struct epi_info *));
7282 static void emit_equiv_load PARAMS ((struct epi_info *));
7284 /* Modify SEQ, a SEQUENCE that is part of the epilogue, to no modifications
7285 to the stack pointer. Return the new sequence. */
7288 keep_stack_depressed (seq)
7292 struct epi_info info;
7294 /* If the epilogue is just a single instruction, it ust be OK as is. */
7296 if (GET_CODE (seq) != SEQUENCE)
7299 /* Otherwise, start a sequence, initialize the information we have, and
7300 process all the insns we were given. */
7303 info.sp_equiv_reg = stack_pointer_rtx;
7305 info.equiv_reg_src = 0;
7307 for (i = 0; i < XVECLEN (seq, 0); i++)
7309 rtx insn = XVECEXP (seq, 0, i);
7317 /* If this insn references the register that SP is equivalent to and
7318 we have a pending load to that register, we must force out the load
7319 first and then indicate we no longer know what SP's equivalent is. */
7320 if (info.equiv_reg_src != 0
7321 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn)))
7323 emit_equiv_load (&info);
7324 info.sp_equiv_reg = 0;
7327 info.new_sp_equiv_reg = info.sp_equiv_reg;
7328 info.new_sp_offset = info.sp_offset;
7330 /* If this is a (RETURN) and the return address is on the stack,
7331 update the address and change to an indirect jump. */
7332 if (GET_CODE (PATTERN (insn)) == RETURN
7333 || (GET_CODE (PATTERN (insn)) == PARALLEL
7334 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
7336 rtx retaddr = INCOMING_RETURN_ADDR_RTX;
7338 HOST_WIDE_INT offset = 0;
7339 rtx jump_insn, jump_set;
7341 /* If the return address is in a register, we can emit the insn
7342 unchanged. Otherwise, it must be a MEM and we see what the
7343 base register and offset are. In any case, we have to emit any
7344 pending load to the equivalent reg of SP, if any. */
7345 if (GET_CODE (retaddr) == REG)
7347 emit_equiv_load (&info);
7351 else if (GET_CODE (retaddr) == MEM
7352 && GET_CODE (XEXP (retaddr, 0)) == REG)
7353 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0;
7354 else if (GET_CODE (retaddr) == MEM
7355 && GET_CODE (XEXP (retaddr, 0)) == PLUS
7356 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG
7357 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT)
7359 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0)));
7360 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1));
7365 /* If the base of the location containing the return pointer
7366 is SP, we must update it with the replacement address. Otherwise,
7367 just build the necessary MEM. */
7368 retaddr = plus_constant (base, offset);
7369 if (base == stack_pointer_rtx)
7370 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx,
7371 plus_constant (info.sp_equiv_reg,
7374 retaddr = gen_rtx_MEM (Pmode, retaddr);
7376 /* If there is a pending load to the equivalent register for SP
7377 and we reference that register, we must load our address into
7378 a scratch register and then do that load. */
7379 if (info.equiv_reg_src
7380 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr))
7385 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7386 if (HARD_REGNO_MODE_OK (regno, Pmode)
7387 && !fixed_regs[regno]
7388 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
7389 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start,
7391 && !refers_to_regno_p (regno,
7392 regno + HARD_REGNO_NREGS (regno,
7394 info.equiv_reg_src, NULL))
7397 if (regno == FIRST_PSEUDO_REGISTER)
7400 reg = gen_rtx_REG (Pmode, regno);
7401 emit_move_insn (reg, retaddr);
7405 emit_equiv_load (&info);
7406 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr));
7408 /* Show the SET in the above insn is a RETURN. */
7409 jump_set = single_set (jump_insn);
7413 SET_IS_RETURN_P (jump_set) = 1;
7416 /* If SP is not mentioned in the pattern and its equivalent register, if
7417 any, is not modified, just emit it. Otherwise, if neither is set,
7418 replace the reference to SP and emit the insn. If none of those are
7419 true, handle each SET individually. */
7420 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))
7421 && (info.sp_equiv_reg == stack_pointer_rtx
7422 || !reg_set_p (info.sp_equiv_reg, insn)))
7424 else if (! reg_set_p (stack_pointer_rtx, insn)
7425 && (info.sp_equiv_reg == stack_pointer_rtx
7426 || !reg_set_p (info.sp_equiv_reg, insn)))
7428 if (! validate_replace_rtx (stack_pointer_rtx,
7429 plus_constant (info.sp_equiv_reg,
7436 else if (GET_CODE (PATTERN (insn)) == SET)
7437 handle_epilogue_set (PATTERN (insn), &info);
7438 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
7440 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++)
7441 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
7442 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info);
7447 info.sp_equiv_reg = info.new_sp_equiv_reg;
7448 info.sp_offset = info.new_sp_offset;
7451 seq = gen_sequence ();
7456 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7457 structure that contains information about what we've seen so far. We
7458 process this SET by either updating that data or by emitting one or
7462 handle_epilogue_set (set, p)
7466 /* First handle the case where we are setting SP. Record what it is being
7467 set from. If unknown, abort. */
7468 if (reg_set_p (stack_pointer_rtx, set))
7470 if (SET_DEST (set) != stack_pointer_rtx)
7473 if (GET_CODE (SET_SRC (set)) == PLUS
7474 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
7476 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0);
7477 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1));
7480 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0;
7482 /* If we are adjusting SP, we adjust from the old data. */
7483 if (p->new_sp_equiv_reg == stack_pointer_rtx)
7485 p->new_sp_equiv_reg = p->sp_equiv_reg;
7486 p->new_sp_offset += p->sp_offset;
7489 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG)
7495 /* Next handle the case where we are setting SP's equivalent register.
7496 If we already have a value to set it to, abort. We could update, but
7497 there seems little point in handling that case. Note that we have
7498 to allow for the case where we are setting the register set in
7499 the previous part of a PARALLEL inside a single insn. But use the
7500 old offset for any updates within this insn. */
7501 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set))
7503 if (!rtx_equal_p (p->new_sp_equiv_reg, SET_DEST (set))
7504 || p->equiv_reg_src != 0)
7508 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7509 plus_constant (p->sp_equiv_reg,
7513 /* Otherwise, replace any references to SP in the insn to its new value
7514 and emit the insn. */
7517 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7518 plus_constant (p->sp_equiv_reg,
7520 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx,
7521 plus_constant (p->sp_equiv_reg,
7527 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7533 if (p->equiv_reg_src != 0)
7534 emit_move_insn (p->sp_equiv_reg, p->equiv_reg_src);
7536 p->equiv_reg_src = 0;
7540 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7541 this into place with notes indicating where the prologue ends and where
7542 the epilogue begins. Update the basic block information when possible. */
7545 thread_prologue_and_epilogue_insns (f)
7546 rtx f ATTRIBUTE_UNUSED;
7550 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7553 #ifdef HAVE_prologue
7554 rtx prologue_end = NULL_RTX;
7556 #if defined (HAVE_epilogue) || defined(HAVE_return)
7557 rtx epilogue_end = NULL_RTX;
7560 #ifdef HAVE_prologue
7564 seq = gen_prologue ();
7567 /* Retain a map of the prologue insns. */
7568 if (GET_CODE (seq) != SEQUENCE)
7570 record_insns (seq, &prologue);
7571 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END);
7573 seq = gen_sequence ();
7576 /* Can't deal with multiple successors of the entry block
7577 at the moment. Function should always have at least one
7579 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next)
7582 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
7587 /* If the exit block has no non-fake predecessors, we don't need
7589 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7590 if ((e->flags & EDGE_FAKE) == 0)
7596 if (optimize && HAVE_return)
7598 /* If we're allowed to generate a simple return instruction,
7599 then by definition we don't need a full epilogue. Examine
7600 the block that falls through to EXIT. If it does not
7601 contain any code, examine its predecessors and try to
7602 emit (conditional) return instructions. */
7608 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7609 if (e->flags & EDGE_FALLTHRU)
7615 /* Verify that there are no active instructions in the last block. */
7617 while (label && GET_CODE (label) != CODE_LABEL)
7619 if (active_insn_p (label))
7621 label = PREV_INSN (label);
7624 if (last->head == label && GET_CODE (label) == CODE_LABEL)
7626 rtx epilogue_line_note = NULL_RTX;
7628 /* Locate the line number associated with the closing brace,
7629 if we can find one. */
7630 for (seq = get_last_insn ();
7631 seq && ! active_insn_p (seq);
7632 seq = PREV_INSN (seq))
7633 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0)
7635 epilogue_line_note = seq;
7639 for (e = last->pred; e; e = e_next)
7641 basic_block bb = e->src;
7644 e_next = e->pred_next;
7645 if (bb == ENTRY_BLOCK_PTR)
7649 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label)
7652 /* If we have an unconditional jump, we can replace that
7653 with a simple return instruction. */
7654 if (simplejump_p (jump))
7656 emit_return_into_block (bb, epilogue_line_note);
7660 /* If we have a conditional jump, we can try to replace
7661 that with a conditional return instruction. */
7662 else if (condjump_p (jump))
7666 ret = SET_SRC (PATTERN (jump));
7667 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF)
7668 loc = &XEXP (ret, 1);
7670 loc = &XEXP (ret, 2);
7671 ret = gen_rtx_RETURN (VOIDmode);
7673 if (! validate_change (jump, loc, ret, 0))
7675 if (JUMP_LABEL (jump))
7676 LABEL_NUSES (JUMP_LABEL (jump))--;
7678 /* If this block has only one successor, it both jumps
7679 and falls through to the fallthru block, so we can't
7681 if (bb->succ->succ_next == NULL)
7687 /* Fix up the CFG for the successful change we just made. */
7688 redirect_edge_succ (e, EXIT_BLOCK_PTR);
7691 /* Emit a return insn for the exit fallthru block. Whether
7692 this is still reachable will be determined later. */
7694 emit_barrier_after (last->end);
7695 emit_return_into_block (last, epilogue_line_note);
7696 epilogue_end = last->end;
7697 last->succ->flags &= ~EDGE_FALLTHRU;
7702 #ifdef HAVE_epilogue
7705 /* Find the edge that falls through to EXIT. Other edges may exist
7706 due to RETURN instructions, but those don't need epilogues.
7707 There really shouldn't be a mixture -- either all should have
7708 been converted or none, however... */
7710 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7711 if (e->flags & EDGE_FALLTHRU)
7717 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG);
7719 seq = gen_epilogue ();
7721 #ifdef INCOMING_RETURN_ADDR_RTX
7722 /* If this function returns with the stack depressed and we can support
7723 it, massage the epilogue to actually do that. */
7724 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
7725 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
7726 seq = keep_stack_depressed (seq);
7729 emit_jump_insn (seq);
7731 /* Retain a map of the epilogue insns. */
7732 if (GET_CODE (seq) != SEQUENCE)
7734 record_insns (seq, &epilogue);
7736 seq = gen_sequence ();
7739 insert_insn_on_edge (seq, e);
7746 commit_edge_insertions ();
7748 #ifdef HAVE_sibcall_epilogue
7749 /* Emit sibling epilogues before any sibling call sites. */
7750 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7752 basic_block bb = e->src;
7757 if (GET_CODE (insn) != CALL_INSN
7758 || ! SIBLING_CALL_P (insn))
7762 seq = gen_sibcall_epilogue ();
7765 i = PREV_INSN (insn);
7766 newinsn = emit_insn_before (seq, insn);
7768 /* Retain a map of the epilogue insns. Used in life analysis to
7769 avoid getting rid of sibcall epilogue insns. */
7770 record_insns (GET_CODE (seq) == SEQUENCE
7771 ? seq : newinsn, &sibcall_epilogue);
7775 #ifdef HAVE_prologue
7780 /* GDB handles `break f' by setting a breakpoint on the first
7781 line note after the prologue. Which means (1) that if
7782 there are line number notes before where we inserted the
7783 prologue we should move them, and (2) we should generate a
7784 note before the end of the first basic block, if there isn't
7787 ??? This behaviour is completely broken when dealing with
7788 multiple entry functions. We simply place the note always
7789 into first basic block and let alternate entry points
7793 for (insn = prologue_end; insn; insn = prev)
7795 prev = PREV_INSN (insn);
7796 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7798 /* Note that we cannot reorder the first insn in the
7799 chain, since rest_of_compilation relies on that
7800 remaining constant. */
7803 reorder_insns (insn, insn, prologue_end);
7807 /* Find the last line number note in the first block. */
7808 for (insn = BASIC_BLOCK (0)->end;
7809 insn != prologue_end && insn;
7810 insn = PREV_INSN (insn))
7811 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7814 /* If we didn't find one, make a copy of the first line number
7818 for (insn = next_active_insn (prologue_end);
7820 insn = PREV_INSN (insn))
7821 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7823 emit_line_note_after (NOTE_SOURCE_FILE (insn),
7824 NOTE_LINE_NUMBER (insn),
7831 #ifdef HAVE_epilogue
7836 /* Similarly, move any line notes that appear after the epilogue.
7837 There is no need, however, to be quite so anal about the existence
7839 for (insn = epilogue_end; insn; insn = next)
7841 next = NEXT_INSN (insn);
7842 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7843 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
7849 /* Reposition the prologue-end and epilogue-begin notes after instruction
7850 scheduling and delayed branch scheduling. */
7853 reposition_prologue_and_epilogue_notes (f)
7854 rtx f ATTRIBUTE_UNUSED;
7856 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7857 rtx insn, last, note;
7860 if ((len = VARRAY_SIZE (prologue)) > 0)
7864 /* Scan from the beginning until we reach the last prologue insn.
7865 We apparently can't depend on basic_block_{head,end} after
7867 for (insn = f; insn; insn = NEXT_INSN (insn))
7869 if (GET_CODE (insn) == NOTE)
7871 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
7874 else if (contains (insn, prologue))
7886 /* Find the prologue-end note if we haven't already, and
7887 move it to just after the last prologue insn. */
7890 for (note = last; (note = NEXT_INSN (note));)
7891 if (GET_CODE (note) == NOTE
7892 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
7896 next = NEXT_INSN (note);
7898 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7899 if (GET_CODE (last) == CODE_LABEL)
7900 last = NEXT_INSN (last);
7901 reorder_insns (note, note, last);
7905 if ((len = VARRAY_SIZE (epilogue)) > 0)
7909 /* Scan from the end until we reach the first epilogue insn.
7910 We apparently can't depend on basic_block_{head,end} after
7912 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
7914 if (GET_CODE (insn) == NOTE)
7916 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
7919 else if (contains (insn, epilogue))
7929 /* Find the epilogue-begin note if we haven't already, and
7930 move it to just before the first epilogue insn. */
7933 for (note = insn; (note = PREV_INSN (note));)
7934 if (GET_CODE (note) == NOTE
7935 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
7939 if (PREV_INSN (last) != note)
7940 reorder_insns (note, note, PREV_INSN (last));
7943 #endif /* HAVE_prologue or HAVE_epilogue */
7946 /* Mark P for GC. */
7949 mark_function_status (p)
7952 struct var_refs_queue *q;
7953 struct temp_slot *t;
7960 ggc_mark_rtx (p->arg_offset_rtx);
7962 if (p->x_parm_reg_stack_loc)
7963 for (i = p->x_max_parm_reg, r = p->x_parm_reg_stack_loc;
7967 ggc_mark_rtx (p->return_rtx);
7968 ggc_mark_rtx (p->x_cleanup_label);
7969 ggc_mark_rtx (p->x_return_label);
7970 ggc_mark_rtx (p->x_save_expr_regs);
7971 ggc_mark_rtx (p->x_stack_slot_list);
7972 ggc_mark_rtx (p->x_parm_birth_insn);
7973 ggc_mark_rtx (p->x_tail_recursion_label);
7974 ggc_mark_rtx (p->x_tail_recursion_reentry);
7975 ggc_mark_rtx (p->internal_arg_pointer);
7976 ggc_mark_rtx (p->x_arg_pointer_save_area);
7977 ggc_mark_tree (p->x_rtl_expr_chain);
7978 ggc_mark_rtx (p->x_last_parm_insn);
7979 ggc_mark_tree (p->x_context_display);
7980 ggc_mark_tree (p->x_trampoline_list);
7981 ggc_mark_rtx (p->epilogue_delay_list);
7982 ggc_mark_rtx (p->x_clobber_return_insn);
7984 for (t = p->x_temp_slots; t != 0; t = t->next)
7987 ggc_mark_rtx (t->slot);
7988 ggc_mark_rtx (t->address);
7989 ggc_mark_tree (t->rtl_expr);
7990 ggc_mark_tree (t->type);
7993 for (q = p->fixup_var_refs_queue; q != 0; q = q->next)
7996 ggc_mark_rtx (q->modified);
7999 ggc_mark_rtx (p->x_nonlocal_goto_handler_slots);
8000 ggc_mark_rtx (p->x_nonlocal_goto_handler_labels);
8001 ggc_mark_rtx (p->x_nonlocal_goto_stack_level);
8002 ggc_mark_tree (p->x_nonlocal_labels);
8004 mark_hard_reg_initial_vals (p);
8007 /* Mark the struct function pointed to by *ARG for GC, if it is not
8008 NULL. This is used to mark the current function and the outer
8012 maybe_mark_struct_function (arg)
8015 struct function *f = *(struct function **) arg;
8020 ggc_mark_struct_function (f);
8023 /* Mark a struct function * for GC. This is called from ggc-common.c. */
8026 ggc_mark_struct_function (f)
8030 ggc_mark_tree (f->decl);
8032 mark_function_status (f);
8033 mark_eh_status (f->eh);
8034 mark_stmt_status (f->stmt);
8035 mark_expr_status (f->expr);
8036 mark_emit_status (f->emit);
8037 mark_varasm_status (f->varasm);
8039 if (mark_machine_status)
8040 (*mark_machine_status) (f);
8041 (*lang_hooks.function.mark) (f);
8043 if (f->original_arg_vector)
8044 ggc_mark_rtvec ((rtvec) f->original_arg_vector);
8045 if (f->original_decl_initial)
8046 ggc_mark_tree (f->original_decl_initial);
8048 ggc_mark_struct_function (f->outer);
8051 /* Called once, at initialization, to initialize function.c. */
8054 init_function_once ()
8056 ggc_add_root (&cfun, 1, sizeof cfun, maybe_mark_struct_function);
8057 ggc_add_root (&outer_function_chain, 1, sizeof outer_function_chain,
8058 maybe_mark_struct_function);
8060 VARRAY_INT_INIT (prologue, 0, "prologue");
8061 VARRAY_INT_INIT (epilogue, 0, "epilogue");
8062 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");