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"
80 /* Round a value to the lowest integer less than it that is a multiple of
81 the required alignment. Avoid using division in case the value is
82 negative. Assume the alignment is a power of two. */
83 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
85 /* Similar, but round to the next highest integer that meets the
87 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
89 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
90 during rtl generation. If they are different register numbers, this is
91 always true. It may also be true if
92 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
93 generation. See fix_lexical_addr for details. */
95 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
96 #define NEED_SEPARATE_AP
99 /* Nonzero if function being compiled doesn't contain any calls
100 (ignoring the prologue and epilogue). This is set prior to
101 local register allocation and is valid for the remaining
103 int current_function_is_leaf;
105 /* Nonzero if function being compiled doesn't contain any instructions
106 that can throw an exception. This is set prior to final. */
108 int current_function_nothrow;
110 /* Nonzero if function being compiled doesn't modify the stack pointer
111 (ignoring the prologue and epilogue). This is only valid after
112 life_analysis has run. */
113 int current_function_sp_is_unchanging;
115 /* Nonzero if the function being compiled is a leaf function which only
116 uses leaf registers. This is valid after reload (specifically after
117 sched2) and is useful only if the port defines LEAF_REGISTERS. */
118 int current_function_uses_only_leaf_regs;
120 /* Nonzero once virtual register instantiation has been done.
121 assign_stack_local uses frame_pointer_rtx when this is nonzero.
122 calls.c:emit_library_call_value_1 uses it to set up
123 post-instantiation libcalls. */
124 int virtuals_instantiated;
126 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
127 static int funcdef_no;
129 /* These variables hold pointers to functions to create and destroy
130 target specific, per-function data structures. */
131 struct machine_function * (*init_machine_status) PARAMS ((void));
133 /* The FUNCTION_DECL for an inline function currently being expanded. */
134 tree inline_function_decl;
136 /* The currently compiled function. */
137 struct function *cfun = 0;
139 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
140 static GTY(()) varray_type prologue;
141 static GTY(()) varray_type epilogue;
143 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
145 static GTY(()) varray_type sibcall_epilogue;
147 /* In order to evaluate some expressions, such as function calls returning
148 structures in memory, we need to temporarily allocate stack locations.
149 We record each allocated temporary in the following structure.
151 Associated with each temporary slot is a nesting level. When we pop up
152 one level, all temporaries associated with the previous level are freed.
153 Normally, all temporaries are freed after the execution of the statement
154 in which they were created. However, if we are inside a ({...}) grouping,
155 the result may be in a temporary and hence must be preserved. If the
156 result could be in a temporary, we preserve it if we can determine which
157 one it is in. If we cannot determine which temporary may contain the
158 result, all temporaries are preserved. A temporary is preserved by
159 pretending it was allocated at the previous nesting level.
161 Automatic variables are also assigned temporary slots, at the nesting
162 level where they are defined. They are marked a "kept" so that
163 free_temp_slots will not free them. */
165 struct temp_slot GTY(())
167 /* Points to next temporary slot. */
168 struct temp_slot *next;
169 /* The rtx to used to reference the slot. */
171 /* The rtx used to represent the address if not the address of the
172 slot above. May be an EXPR_LIST if multiple addresses exist. */
174 /* The alignment (in bits) of the slot. */
176 /* The size, in units, of the slot. */
178 /* The type of the object in the slot, or zero if it doesn't correspond
179 to a type. We use this to determine whether a slot can be reused.
180 It can be reused if objects of the type of the new slot will always
181 conflict with objects of the type of the old slot. */
183 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
185 /* Non-zero if this temporary is currently in use. */
187 /* Non-zero if this temporary has its address taken. */
189 /* Nesting level at which this slot is being used. */
191 /* Non-zero if this should survive a call to free_temp_slots. */
193 /* The offset of the slot from the frame_pointer, including extra space
194 for alignment. This info is for combine_temp_slots. */
195 HOST_WIDE_INT base_offset;
196 /* The size of the slot, including extra space for alignment. This
197 info is for combine_temp_slots. */
198 HOST_WIDE_INT full_size;
201 /* This structure is used to record MEMs or pseudos used to replace VAR, any
202 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
203 maintain this list in case two operands of an insn were required to match;
204 in that case we must ensure we use the same replacement. */
206 struct fixup_replacement GTY(())
210 struct fixup_replacement *next;
213 struct insns_for_mem_entry
217 /* These are the INSNs which reference the MEM. */
221 /* Forward declarations. */
223 static rtx assign_stack_local_1 PARAMS ((enum machine_mode, HOST_WIDE_INT,
224 int, struct function *));
225 static struct temp_slot *find_temp_slot_from_address PARAMS ((rtx));
226 static void put_reg_into_stack PARAMS ((struct function *, rtx, tree,
227 enum machine_mode, enum machine_mode,
228 int, unsigned int, int,
230 static void schedule_fixup_var_refs PARAMS ((struct function *, rtx, tree,
233 static void fixup_var_refs PARAMS ((rtx, enum machine_mode, int, rtx,
235 static struct fixup_replacement
236 *find_fixup_replacement PARAMS ((struct fixup_replacement **, rtx));
237 static void fixup_var_refs_insns PARAMS ((rtx, rtx, enum machine_mode,
239 static void fixup_var_refs_insns_with_hash
240 PARAMS ((htab_t, rtx,
241 enum machine_mode, int, rtx));
242 static void fixup_var_refs_insn PARAMS ((rtx, rtx, enum machine_mode,
244 static void fixup_var_refs_1 PARAMS ((rtx, enum machine_mode, rtx *, rtx,
245 struct fixup_replacement **, rtx));
246 static rtx fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode, int));
247 static rtx walk_fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode,
249 static rtx fixup_stack_1 PARAMS ((rtx, rtx));
250 static void optimize_bit_field PARAMS ((rtx, rtx, rtx *));
251 static void instantiate_decls PARAMS ((tree, int));
252 static void instantiate_decls_1 PARAMS ((tree, int));
253 static void instantiate_decl PARAMS ((rtx, HOST_WIDE_INT, int));
254 static rtx instantiate_new_reg PARAMS ((rtx, HOST_WIDE_INT *));
255 static int instantiate_virtual_regs_1 PARAMS ((rtx *, rtx, int));
256 static void delete_handlers PARAMS ((void));
257 static void pad_to_arg_alignment PARAMS ((struct args_size *, int,
258 struct args_size *));
259 #ifndef ARGS_GROW_DOWNWARD
260 static void pad_below PARAMS ((struct args_size *, enum machine_mode,
263 static rtx round_trampoline_addr PARAMS ((rtx));
264 static rtx adjust_trampoline_addr PARAMS ((rtx));
265 static tree *identify_blocks_1 PARAMS ((rtx, tree *, tree *, tree *));
266 static void reorder_blocks_0 PARAMS ((tree));
267 static void reorder_blocks_1 PARAMS ((rtx, tree, varray_type *));
268 static void reorder_fix_fragments PARAMS ((tree));
269 static tree blocks_nreverse PARAMS ((tree));
270 static int all_blocks PARAMS ((tree, tree *));
271 static tree *get_block_vector PARAMS ((tree, int *));
272 extern tree debug_find_var_in_block_tree PARAMS ((tree, tree));
273 /* We always define `record_insns' even if its not used so that we
274 can always export `prologue_epilogue_contains'. */
275 static void record_insns PARAMS ((rtx, varray_type *)) ATTRIBUTE_UNUSED;
276 static int contains PARAMS ((rtx, varray_type));
278 static void emit_return_into_block PARAMS ((basic_block, rtx));
280 static void put_addressof_into_stack PARAMS ((rtx, htab_t));
281 static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
283 static void purge_single_hard_subreg_set PARAMS ((rtx));
284 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
285 static rtx keep_stack_depressed PARAMS ((rtx));
287 static int is_addressof PARAMS ((rtx *, void *));
288 static hashval_t insns_for_mem_hash PARAMS ((const void *));
289 static int insns_for_mem_comp PARAMS ((const void *, const void *));
290 static int insns_for_mem_walk PARAMS ((rtx *, void *));
291 static void compute_insns_for_mem PARAMS ((rtx, rtx, htab_t));
292 static void prepare_function_start PARAMS ((void));
293 static void do_clobber_return_reg PARAMS ((rtx, void *));
294 static void do_use_return_reg PARAMS ((rtx, void *));
296 /* Pointer to chain of `struct function' for containing functions. */
297 static GTY(()) struct function *outer_function_chain;
299 /* Given a function decl for a containing function,
300 return the `struct function' for it. */
303 find_function_data (decl)
308 for (p = outer_function_chain; p; p = p->outer)
315 /* Save the current context for compilation of a nested function.
316 This is called from language-specific code. The caller should use
317 the enter_nested langhook to save any language-specific state,
318 since this function knows only about language-independent
322 push_function_context_to (context)
329 if (context == current_function_decl)
330 cfun->contains_functions = 1;
333 struct function *containing = find_function_data (context);
334 containing->contains_functions = 1;
339 init_dummy_function_start ();
342 p->outer = outer_function_chain;
343 outer_function_chain = p;
344 p->fixup_var_refs_queue = 0;
346 (*lang_hooks.function.enter_nested) (p);
352 push_function_context ()
354 push_function_context_to (current_function_decl);
357 /* Restore the last saved context, at the end of a nested function.
358 This function is called from language-specific code. */
361 pop_function_context_from (context)
362 tree context ATTRIBUTE_UNUSED;
364 struct function *p = outer_function_chain;
365 struct var_refs_queue *queue;
368 outer_function_chain = p->outer;
370 current_function_decl = p->decl;
373 restore_emit_status (p);
375 (*lang_hooks.function.leave_nested) (p);
377 /* Finish doing put_var_into_stack for any of our variables which became
378 addressable during the nested function. If only one entry has to be
379 fixed up, just do that one. Otherwise, first make a list of MEMs that
380 are not to be unshared. */
381 if (p->fixup_var_refs_queue == 0)
383 else if (p->fixup_var_refs_queue->next == 0)
384 fixup_var_refs (p->fixup_var_refs_queue->modified,
385 p->fixup_var_refs_queue->promoted_mode,
386 p->fixup_var_refs_queue->unsignedp,
387 p->fixup_var_refs_queue->modified, 0);
392 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
393 list = gen_rtx_EXPR_LIST (VOIDmode, queue->modified, list);
395 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
396 fixup_var_refs (queue->modified, queue->promoted_mode,
397 queue->unsignedp, list, 0);
401 p->fixup_var_refs_queue = 0;
403 /* Reset variables that have known state during rtx generation. */
404 rtx_equal_function_value_matters = 1;
405 virtuals_instantiated = 0;
406 generating_concat_p = 1;
410 pop_function_context ()
412 pop_function_context_from (current_function_decl);
415 /* Clear out all parts of the state in F that can safely be discarded
416 after the function has been parsed, but not compiled, to let
417 garbage collection reclaim the memory. */
420 free_after_parsing (f)
423 /* f->expr->forced_labels is used by code generation. */
424 /* f->emit->regno_reg_rtx is used by code generation. */
425 /* f->varasm is used by code generation. */
426 /* f->eh->eh_return_stub_label is used by code generation. */
428 (*lang_hooks.function.final) (f);
432 /* Clear out all parts of the state in F that can safely be discarded
433 after the function has been compiled, to let garbage collection
434 reclaim the memory. */
437 free_after_compilation (f)
446 f->x_temp_slots = NULL;
447 f->arg_offset_rtx = NULL;
448 f->return_rtx = NULL;
449 f->internal_arg_pointer = NULL;
450 f->x_nonlocal_labels = NULL;
451 f->x_nonlocal_goto_handler_slots = NULL;
452 f->x_nonlocal_goto_handler_labels = NULL;
453 f->x_nonlocal_goto_stack_level = NULL;
454 f->x_cleanup_label = NULL;
455 f->x_return_label = NULL;
456 f->x_save_expr_regs = NULL;
457 f->x_stack_slot_list = NULL;
458 f->x_rtl_expr_chain = NULL;
459 f->x_tail_recursion_label = NULL;
460 f->x_tail_recursion_reentry = NULL;
461 f->x_arg_pointer_save_area = NULL;
462 f->x_clobber_return_insn = NULL;
463 f->x_context_display = NULL;
464 f->x_trampoline_list = NULL;
465 f->x_parm_birth_insn = NULL;
466 f->x_last_parm_insn = NULL;
467 f->x_parm_reg_stack_loc = NULL;
468 f->fixup_var_refs_queue = NULL;
469 f->original_arg_vector = NULL;
470 f->original_decl_initial = NULL;
471 f->inl_last_parm_insn = NULL;
472 f->epilogue_delay_list = NULL;
475 /* Allocate fixed slots in the stack frame of the current function. */
477 /* Return size needed for stack frame based on slots so far allocated in
479 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
480 the caller may have to do that. */
483 get_func_frame_size (f)
486 #ifdef FRAME_GROWS_DOWNWARD
487 return -f->x_frame_offset;
489 return f->x_frame_offset;
493 /* Return size needed for stack frame based on slots so far allocated.
494 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
495 the caller may have to do that. */
499 return get_func_frame_size (cfun);
502 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
503 with machine mode MODE.
505 ALIGN controls the amount of alignment for the address of the slot:
506 0 means according to MODE,
507 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
508 positive specifies alignment boundary in bits.
510 We do not round to stack_boundary here.
512 FUNCTION specifies the function to allocate in. */
515 assign_stack_local_1 (mode, size, align, function)
516 enum machine_mode mode;
519 struct function *function;
522 int bigend_correction = 0;
524 int frame_off, frame_alignment, frame_phase;
531 alignment = BIGGEST_ALIGNMENT;
533 alignment = GET_MODE_ALIGNMENT (mode);
535 /* Allow the target to (possibly) increase the alignment of this
537 type = (*lang_hooks.types.type_for_mode) (mode, 0);
539 alignment = LOCAL_ALIGNMENT (type, alignment);
541 alignment /= BITS_PER_UNIT;
543 else if (align == -1)
545 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
546 size = CEIL_ROUND (size, alignment);
549 alignment = align / BITS_PER_UNIT;
551 #ifdef FRAME_GROWS_DOWNWARD
552 function->x_frame_offset -= size;
555 /* Ignore alignment we can't do with expected alignment of the boundary. */
556 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
557 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
559 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
560 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
562 /* Calculate how many bytes the start of local variables is off from
564 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
565 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
566 frame_phase = frame_off ? frame_alignment - frame_off : 0;
568 /* Round frame offset to that alignment.
569 We must be careful here, since FRAME_OFFSET might be negative and
570 division with a negative dividend isn't as well defined as we might
571 like. So we instead assume that ALIGNMENT is a power of two and
572 use logical operations which are unambiguous. */
573 #ifdef FRAME_GROWS_DOWNWARD
574 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
576 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
579 /* On a big-endian machine, if we are allocating more space than we will use,
580 use the least significant bytes of those that are allocated. */
581 if (BYTES_BIG_ENDIAN && mode != BLKmode)
582 bigend_correction = size - GET_MODE_SIZE (mode);
584 /* If we have already instantiated virtual registers, return the actual
585 address relative to the frame pointer. */
586 if (function == cfun && virtuals_instantiated)
587 addr = plus_constant (frame_pointer_rtx,
588 (frame_offset + bigend_correction
589 + STARTING_FRAME_OFFSET));
591 addr = plus_constant (virtual_stack_vars_rtx,
592 function->x_frame_offset + bigend_correction);
594 #ifndef FRAME_GROWS_DOWNWARD
595 function->x_frame_offset += size;
598 x = gen_rtx_MEM (mode, addr);
600 function->x_stack_slot_list
601 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
606 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
610 assign_stack_local (mode, size, align)
611 enum machine_mode mode;
615 return assign_stack_local_1 (mode, size, align, cfun);
618 /* Allocate a temporary stack slot and record it for possible later
621 MODE is the machine mode to be given to the returned rtx.
623 SIZE is the size in units of the space required. We do no rounding here
624 since assign_stack_local will do any required rounding.
626 KEEP is 1 if this slot is to be retained after a call to
627 free_temp_slots. Automatic variables for a block are allocated
628 with this flag. KEEP is 2 if we allocate a longer term temporary,
629 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
630 if we are to allocate something at an inner level to be treated as
631 a variable in the block (e.g., a SAVE_EXPR).
633 TYPE is the type that will be used for the stack slot. */
636 assign_stack_temp_for_type (mode, size, keep, type)
637 enum machine_mode mode;
643 struct temp_slot *p, *best_p = 0;
646 /* If SIZE is -1 it means that somebody tried to allocate a temporary
647 of a variable size. */
652 align = BIGGEST_ALIGNMENT;
654 align = GET_MODE_ALIGNMENT (mode);
657 type = (*lang_hooks.types.type_for_mode) (mode, 0);
660 align = LOCAL_ALIGNMENT (type, align);
662 /* Try to find an available, already-allocated temporary of the proper
663 mode which meets the size and alignment requirements. Choose the
664 smallest one with the closest alignment. */
665 for (p = temp_slots; p; p = p->next)
666 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
668 && objects_must_conflict_p (p->type, type)
669 && (best_p == 0 || best_p->size > p->size
670 || (best_p->size == p->size && best_p->align > p->align)))
672 if (p->align == align && p->size == size)
680 /* Make our best, if any, the one to use. */
683 /* If there are enough aligned bytes left over, make them into a new
684 temp_slot so that the extra bytes don't get wasted. Do this only
685 for BLKmode slots, so that we can be sure of the alignment. */
686 if (GET_MODE (best_p->slot) == BLKmode)
688 int alignment = best_p->align / BITS_PER_UNIT;
689 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
691 if (best_p->size - rounded_size >= alignment)
693 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
694 p->in_use = p->addr_taken = 0;
695 p->size = best_p->size - rounded_size;
696 p->base_offset = best_p->base_offset + rounded_size;
697 p->full_size = best_p->full_size - rounded_size;
698 p->slot = gen_rtx_MEM (BLKmode,
699 plus_constant (XEXP (best_p->slot, 0),
701 p->align = best_p->align;
704 p->type = best_p->type;
705 p->next = temp_slots;
708 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
711 best_p->size = rounded_size;
712 best_p->full_size = rounded_size;
719 /* If we still didn't find one, make a new temporary. */
722 HOST_WIDE_INT frame_offset_old = frame_offset;
724 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
726 /* We are passing an explicit alignment request to assign_stack_local.
727 One side effect of that is assign_stack_local will not round SIZE
728 to ensure the frame offset remains suitably aligned.
730 So for requests which depended on the rounding of SIZE, we go ahead
731 and round it now. We also make sure ALIGNMENT is at least
732 BIGGEST_ALIGNMENT. */
733 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
735 p->slot = assign_stack_local (mode,
737 ? CEIL_ROUND (size, align / BITS_PER_UNIT)
743 /* The following slot size computation is necessary because we don't
744 know the actual size of the temporary slot until assign_stack_local
745 has performed all the frame alignment and size rounding for the
746 requested temporary. Note that extra space added for alignment
747 can be either above or below this stack slot depending on which
748 way the frame grows. We include the extra space if and only if it
749 is above this slot. */
750 #ifdef FRAME_GROWS_DOWNWARD
751 p->size = frame_offset_old - frame_offset;
756 /* Now define the fields used by combine_temp_slots. */
757 #ifdef FRAME_GROWS_DOWNWARD
758 p->base_offset = frame_offset;
759 p->full_size = frame_offset_old - frame_offset;
761 p->base_offset = frame_offset_old;
762 p->full_size = frame_offset - frame_offset_old;
765 p->next = temp_slots;
771 p->rtl_expr = seq_rtl_expr;
776 p->level = target_temp_slot_level;
781 p->level = var_temp_slot_level;
786 p->level = temp_slot_level;
791 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
792 slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
793 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
795 /* If we know the alias set for the memory that will be used, use
796 it. If there's no TYPE, then we don't know anything about the
797 alias set for the memory. */
798 set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
799 set_mem_align (slot, align);
801 /* If a type is specified, set the relevant flags. */
804 RTX_UNCHANGING_P (slot) = TYPE_READONLY (type);
805 MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
806 MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type));
812 /* Allocate a temporary stack slot and record it for possible later
813 reuse. First three arguments are same as in preceding function. */
816 assign_stack_temp (mode, size, keep)
817 enum machine_mode mode;
821 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
824 /* Assign a temporary.
825 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
826 and so that should be used in error messages. In either case, we
827 allocate of the given type.
828 KEEP is as for assign_stack_temp.
829 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
830 it is 0 if a register is OK.
831 DONT_PROMOTE is 1 if we should not promote values in register
835 assign_temp (type_or_decl, keep, memory_required, dont_promote)
839 int dont_promote ATTRIBUTE_UNUSED;
842 enum machine_mode mode;
843 #ifndef PROMOTE_FOR_CALL_ONLY
847 if (DECL_P (type_or_decl))
848 decl = type_or_decl, type = TREE_TYPE (decl);
850 decl = NULL, type = type_or_decl;
852 mode = TYPE_MODE (type);
853 #ifndef PROMOTE_FOR_CALL_ONLY
854 unsignedp = TREE_UNSIGNED (type);
857 if (mode == BLKmode || memory_required)
859 HOST_WIDE_INT size = int_size_in_bytes (type);
862 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
863 problems with allocating the stack space. */
867 /* Unfortunately, we don't yet know how to allocate variable-sized
868 temporaries. However, sometimes we have a fixed upper limit on
869 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
870 instead. This is the case for Chill variable-sized strings. */
871 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
872 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
873 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
874 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
876 /* The size of the temporary may be too large to fit into an integer. */
877 /* ??? Not sure this should happen except for user silliness, so limit
878 this to things that aren't compiler-generated temporaries. The
879 rest of the time we'll abort in assign_stack_temp_for_type. */
880 if (decl && size == -1
881 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
883 error_with_decl (decl, "size of variable `%s' is too large");
887 tmp = assign_stack_temp_for_type (mode, size, keep, type);
891 #ifndef PROMOTE_FOR_CALL_ONLY
893 mode = promote_mode (type, mode, &unsignedp, 0);
896 return gen_reg_rtx (mode);
899 /* Combine temporary stack slots which are adjacent on the stack.
901 This allows for better use of already allocated stack space. This is only
902 done for BLKmode slots because we can be sure that we won't have alignment
903 problems in this case. */
906 combine_temp_slots ()
908 struct temp_slot *p, *q;
909 struct temp_slot *prev_p, *prev_q;
912 /* We can't combine slots, because the information about which slot
913 is in which alias set will be lost. */
914 if (flag_strict_aliasing)
917 /* If there are a lot of temp slots, don't do anything unless
918 high levels of optimization. */
919 if (! flag_expensive_optimizations)
920 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
921 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
924 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
928 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
929 for (q = p->next, prev_q = p; q; q = prev_q->next)
932 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
934 if (p->base_offset + p->full_size == q->base_offset)
936 /* Q comes after P; combine Q into P. */
938 p->full_size += q->full_size;
941 else if (q->base_offset + q->full_size == p->base_offset)
943 /* P comes after Q; combine P into Q. */
945 q->full_size += p->full_size;
950 /* Either delete Q or advance past it. */
952 prev_q->next = q->next;
956 /* Either delete P or advance past it. */
960 prev_p->next = p->next;
962 temp_slots = p->next;
969 /* Find the temp slot corresponding to the object at address X. */
971 static struct temp_slot *
972 find_temp_slot_from_address (x)
978 for (p = temp_slots; p; p = p->next)
983 else if (XEXP (p->slot, 0) == x
985 || (GET_CODE (x) == PLUS
986 && XEXP (x, 0) == virtual_stack_vars_rtx
987 && GET_CODE (XEXP (x, 1)) == CONST_INT
988 && INTVAL (XEXP (x, 1)) >= p->base_offset
989 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
992 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
993 for (next = p->address; next; next = XEXP (next, 1))
994 if (XEXP (next, 0) == x)
998 /* If we have a sum involving a register, see if it points to a temp
1000 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
1001 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
1003 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG
1004 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
1010 /* Indicate that NEW is an alternate way of referring to the temp slot
1011 that previously was known by OLD. */
1014 update_temp_slot_address (old, new)
1017 struct temp_slot *p;
1019 if (rtx_equal_p (old, new))
1022 p = find_temp_slot_from_address (old);
1024 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1025 is a register, see if one operand of the PLUS is a temporary
1026 location. If so, NEW points into it. Otherwise, if both OLD and
1027 NEW are a PLUS and if there is a register in common between them.
1028 If so, try a recursive call on those values. */
1031 if (GET_CODE (old) != PLUS)
1034 if (GET_CODE (new) == REG)
1036 update_temp_slot_address (XEXP (old, 0), new);
1037 update_temp_slot_address (XEXP (old, 1), new);
1040 else if (GET_CODE (new) != PLUS)
1043 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1044 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1045 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1046 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1047 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1048 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1049 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1050 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1055 /* Otherwise add an alias for the temp's address. */
1056 else if (p->address == 0)
1060 if (GET_CODE (p->address) != EXPR_LIST)
1061 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1063 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1067 /* If X could be a reference to a temporary slot, mark the fact that its
1068 address was taken. */
1071 mark_temp_addr_taken (x)
1074 struct temp_slot *p;
1079 /* If X is not in memory or is at a constant address, it cannot be in
1080 a temporary slot. */
1081 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1084 p = find_temp_slot_from_address (XEXP (x, 0));
1089 /* If X could be a reference to a temporary slot, mark that slot as
1090 belonging to the to one level higher than the current level. If X
1091 matched one of our slots, just mark that one. Otherwise, we can't
1092 easily predict which it is, so upgrade all of them. Kept slots
1093 need not be touched.
1095 This is called when an ({...}) construct occurs and a statement
1096 returns a value in memory. */
1099 preserve_temp_slots (x)
1102 struct temp_slot *p = 0;
1104 /* If there is no result, we still might have some objects whose address
1105 were taken, so we need to make sure they stay around. */
1108 for (p = temp_slots; p; p = p->next)
1109 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1115 /* If X is a register that is being used as a pointer, see if we have
1116 a temporary slot we know it points to. To be consistent with
1117 the code below, we really should preserve all non-kept slots
1118 if we can't find a match, but that seems to be much too costly. */
1119 if (GET_CODE (x) == REG && REG_POINTER (x))
1120 p = find_temp_slot_from_address (x);
1122 /* If X is not in memory or is at a constant address, it cannot be in
1123 a temporary slot, but it can contain something whose address was
1125 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1127 for (p = temp_slots; p; p = p->next)
1128 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1134 /* First see if we can find a match. */
1136 p = find_temp_slot_from_address (XEXP (x, 0));
1140 /* Move everything at our level whose address was taken to our new
1141 level in case we used its address. */
1142 struct temp_slot *q;
1144 if (p->level == temp_slot_level)
1146 for (q = temp_slots; q; q = q->next)
1147 if (q != p && q->addr_taken && q->level == p->level)
1156 /* Otherwise, preserve all non-kept slots at this level. */
1157 for (p = temp_slots; p; p = p->next)
1158 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1162 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1163 with that RTL_EXPR, promote it into a temporary slot at the present
1164 level so it will not be freed when we free slots made in the
1168 preserve_rtl_expr_result (x)
1171 struct temp_slot *p;
1173 /* If X is not in memory or is at a constant address, it cannot be in
1174 a temporary slot. */
1175 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1178 /* If we can find a match, move it to our level unless it is already at
1180 p = find_temp_slot_from_address (XEXP (x, 0));
1183 p->level = MIN (p->level, temp_slot_level);
1190 /* Free all temporaries used so far. This is normally called at the end
1191 of generating code for a statement. Don't free any temporaries
1192 currently in use for an RTL_EXPR that hasn't yet been emitted.
1193 We could eventually do better than this since it can be reused while
1194 generating the same RTL_EXPR, but this is complex and probably not
1200 struct temp_slot *p;
1202 for (p = temp_slots; p; p = p->next)
1203 if (p->in_use && p->level == temp_slot_level && ! p->keep
1204 && p->rtl_expr == 0)
1207 combine_temp_slots ();
1210 /* Free all temporary slots used in T, an RTL_EXPR node. */
1213 free_temps_for_rtl_expr (t)
1216 struct temp_slot *p;
1218 for (p = temp_slots; p; p = p->next)
1219 if (p->rtl_expr == t)
1221 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1222 needs to be preserved. This can happen if a temporary in
1223 the RTL_EXPR was addressed; preserve_temp_slots will move
1224 the temporary into a higher level. */
1225 if (temp_slot_level <= p->level)
1228 p->rtl_expr = NULL_TREE;
1231 combine_temp_slots ();
1234 /* Mark all temporaries ever allocated in this function as not suitable
1235 for reuse until the current level is exited. */
1238 mark_all_temps_used ()
1240 struct temp_slot *p;
1242 for (p = temp_slots; p; p = p->next)
1244 p->in_use = p->keep = 1;
1245 p->level = MIN (p->level, temp_slot_level);
1249 /* Push deeper into the nesting level for stack temporaries. */
1257 /* Likewise, but save the new level as the place to allocate variables
1262 push_temp_slots_for_block ()
1266 var_temp_slot_level = temp_slot_level;
1269 /* Likewise, but save the new level as the place to allocate temporaries
1270 for TARGET_EXPRs. */
1273 push_temp_slots_for_target ()
1277 target_temp_slot_level = temp_slot_level;
1280 /* Set and get the value of target_temp_slot_level. The only
1281 permitted use of these functions is to save and restore this value. */
1284 get_target_temp_slot_level ()
1286 return target_temp_slot_level;
1290 set_target_temp_slot_level (level)
1293 target_temp_slot_level = level;
1297 /* Pop a temporary nesting level. All slots in use in the current level
1303 struct temp_slot *p;
1305 for (p = temp_slots; p; p = p->next)
1306 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1309 combine_temp_slots ();
1314 /* Initialize temporary slots. */
1319 /* We have not allocated any temporaries yet. */
1321 temp_slot_level = 0;
1322 var_temp_slot_level = 0;
1323 target_temp_slot_level = 0;
1326 /* Retroactively move an auto variable from a register to a stack slot.
1327 This is done when an address-reference to the variable is seen. */
1330 put_var_into_stack (decl)
1334 enum machine_mode promoted_mode, decl_mode;
1335 struct function *function = 0;
1337 int can_use_addressof;
1338 int volatilep = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl);
1339 int usedp = (TREE_USED (decl)
1340 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0));
1342 context = decl_function_context (decl);
1344 /* Get the current rtl used for this object and its original mode. */
1345 reg = (TREE_CODE (decl) == SAVE_EXPR
1346 ? SAVE_EXPR_RTL (decl)
1347 : DECL_RTL_IF_SET (decl));
1349 /* No need to do anything if decl has no rtx yet
1350 since in that case caller is setting TREE_ADDRESSABLE
1351 and a stack slot will be assigned when the rtl is made. */
1355 /* Get the declared mode for this object. */
1356 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1357 : DECL_MODE (decl));
1358 /* Get the mode it's actually stored in. */
1359 promoted_mode = GET_MODE (reg);
1361 /* If this variable comes from an outer function, find that
1362 function's saved context. Don't use find_function_data here,
1363 because it might not be in any active function.
1364 FIXME: Is that really supposed to happen?
1365 It does in ObjC at least. */
1366 if (context != current_function_decl && context != inline_function_decl)
1367 for (function = outer_function_chain; function; function = function->outer)
1368 if (function->decl == context)
1371 /* If this is a variable-size object with a pseudo to address it,
1372 put that pseudo into the stack, if the var is nonlocal. */
1373 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl)
1374 && GET_CODE (reg) == MEM
1375 && GET_CODE (XEXP (reg, 0)) == REG
1376 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1378 reg = XEXP (reg, 0);
1379 decl_mode = promoted_mode = GET_MODE (reg);
1385 /* FIXME make it work for promoted modes too */
1386 && decl_mode == promoted_mode
1387 #ifdef NON_SAVING_SETJMP
1388 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1392 /* If we can't use ADDRESSOF, make sure we see through one we already
1394 if (! can_use_addressof && GET_CODE (reg) == MEM
1395 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1396 reg = XEXP (XEXP (reg, 0), 0);
1398 /* Now we should have a value that resides in one or more pseudo regs. */
1400 if (GET_CODE (reg) == REG)
1402 /* If this variable lives in the current function and we don't need
1403 to put things in the stack for the sake of setjmp, try to keep it
1404 in a register until we know we actually need the address. */
1405 if (can_use_addressof)
1406 gen_mem_addressof (reg, decl);
1408 put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode,
1409 decl_mode, volatilep, 0, usedp, 0);
1411 else if (GET_CODE (reg) == CONCAT)
1413 /* A CONCAT contains two pseudos; put them both in the stack.
1414 We do it so they end up consecutive.
1415 We fixup references to the parts only after we fixup references
1416 to the whole CONCAT, lest we do double fixups for the latter
1418 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1419 tree part_type = (*lang_hooks.types.type_for_mode) (part_mode, 0);
1420 rtx lopart = XEXP (reg, 0);
1421 rtx hipart = XEXP (reg, 1);
1422 #ifdef FRAME_GROWS_DOWNWARD
1423 /* Since part 0 should have a lower address, do it second. */
1424 put_reg_into_stack (function, hipart, part_type, part_mode,
1425 part_mode, volatilep, 0, 0, 0);
1426 put_reg_into_stack (function, lopart, part_type, part_mode,
1427 part_mode, volatilep, 0, 0, 0);
1429 put_reg_into_stack (function, lopart, part_type, part_mode,
1430 part_mode, volatilep, 0, 0, 0);
1431 put_reg_into_stack (function, hipart, part_type, part_mode,
1432 part_mode, volatilep, 0, 0, 0);
1435 /* Change the CONCAT into a combined MEM for both parts. */
1436 PUT_CODE (reg, MEM);
1437 MEM_ATTRS (reg) = 0;
1439 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1440 already computed alias sets. Here we want to re-generate. */
1442 SET_DECL_RTL (decl, NULL);
1443 set_mem_attributes (reg, decl, 1);
1445 SET_DECL_RTL (decl, reg);
1447 /* The two parts are in memory order already.
1448 Use the lower parts address as ours. */
1449 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1450 /* Prevent sharing of rtl that might lose. */
1451 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1452 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1455 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl),
1457 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0);
1458 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0);
1465 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1466 into the stack frame of FUNCTION (0 means the current function).
1467 DECL_MODE is the machine mode of the user-level data type.
1468 PROMOTED_MODE is the machine mode of the register.
1469 VOLATILE_P is nonzero if this is for a "volatile" decl.
1470 USED_P is nonzero if this reg might have already been used in an insn. */
1473 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1474 original_regno, used_p, ht)
1475 struct function *function;
1478 enum machine_mode promoted_mode, decl_mode;
1480 unsigned int original_regno;
1484 struct function *func = function ? function : cfun;
1486 unsigned int regno = original_regno;
1489 regno = REGNO (reg);
1491 if (regno < func->x_max_parm_reg)
1492 new = func->x_parm_reg_stack_loc[regno];
1495 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func);
1497 PUT_CODE (reg, MEM);
1498 PUT_MODE (reg, decl_mode);
1499 XEXP (reg, 0) = XEXP (new, 0);
1500 MEM_ATTRS (reg) = 0;
1501 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1502 MEM_VOLATILE_P (reg) = volatile_p;
1504 /* If this is a memory ref that contains aggregate components,
1505 mark it as such for cse and loop optimize. If we are reusing a
1506 previously generated stack slot, then we need to copy the bit in
1507 case it was set for other reasons. For instance, it is set for
1508 __builtin_va_alist. */
1511 MEM_SET_IN_STRUCT_P (reg,
1512 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1513 set_mem_alias_set (reg, get_alias_set (type));
1517 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht);
1520 /* Make sure that all refs to the variable, previously made
1521 when it was a register, are fixed up to be valid again.
1522 See function above for meaning of arguments. */
1525 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht)
1526 struct function *function;
1529 enum machine_mode promoted_mode;
1532 int unsigned_p = type ? TREE_UNSIGNED (type) : 0;
1536 struct var_refs_queue *temp;
1539 = (struct var_refs_queue *) ggc_alloc (sizeof (struct var_refs_queue));
1540 temp->modified = reg;
1541 temp->promoted_mode = promoted_mode;
1542 temp->unsignedp = unsigned_p;
1543 temp->next = function->fixup_var_refs_queue;
1544 function->fixup_var_refs_queue = temp;
1547 /* Variable is local; fix it up now. */
1548 fixup_var_refs (reg, promoted_mode, unsigned_p, reg, ht);
1552 fixup_var_refs (var, promoted_mode, unsignedp, may_share, ht)
1554 enum machine_mode promoted_mode;
1560 rtx first_insn = get_insns ();
1561 struct sequence_stack *stack = seq_stack;
1562 tree rtl_exps = rtl_expr_chain;
1564 /* If there's a hash table, it must record all uses of VAR. */
1569 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp,
1574 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp,
1575 stack == 0, may_share);
1577 /* Scan all pending sequences too. */
1578 for (; stack; stack = stack->next)
1580 push_to_full_sequence (stack->first, stack->last);
1581 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp,
1582 stack->next != 0, may_share);
1583 /* Update remembered end of sequence
1584 in case we added an insn at the end. */
1585 stack->last = get_last_insn ();
1589 /* Scan all waiting RTL_EXPRs too. */
1590 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1592 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1593 if (seq != const0_rtx && seq != 0)
1595 push_to_sequence (seq);
1596 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1603 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1604 some part of an insn. Return a struct fixup_replacement whose OLD
1605 value is equal to X. Allocate a new structure if no such entry exists. */
1607 static struct fixup_replacement *
1608 find_fixup_replacement (replacements, x)
1609 struct fixup_replacement **replacements;
1612 struct fixup_replacement *p;
1614 /* See if we have already replaced this. */
1615 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1620 p = (struct fixup_replacement *) xmalloc (sizeof (struct fixup_replacement));
1623 p->next = *replacements;
1630 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1631 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1632 for the current function. MAY_SHARE is either a MEM that is not
1633 to be unshared or a list of them. */
1636 fixup_var_refs_insns (insn, var, promoted_mode, unsignedp, toplevel, may_share)
1639 enum machine_mode promoted_mode;
1646 /* fixup_var_refs_insn might modify insn, so save its next
1648 rtx next = NEXT_INSN (insn);
1650 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1651 the three sequences they (potentially) contain, and process
1652 them recursively. The CALL_INSN itself is not interesting. */
1654 if (GET_CODE (insn) == CALL_INSN
1655 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1659 /* Look at the Normal call, sibling call and tail recursion
1660 sequences attached to the CALL_PLACEHOLDER. */
1661 for (i = 0; i < 3; i++)
1663 rtx seq = XEXP (PATTERN (insn), i);
1666 push_to_sequence (seq);
1667 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1669 XEXP (PATTERN (insn), i) = get_insns ();
1675 else if (INSN_P (insn))
1676 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel,
1683 /* Look up the insns which reference VAR in HT and fix them up. Other
1684 arguments are the same as fixup_var_refs_insns.
1686 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1687 because the hash table will point straight to the interesting insn
1688 (inside the CALL_PLACEHOLDER). */
1691 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp, may_share)
1694 enum machine_mode promoted_mode;
1698 struct insns_for_mem_entry tmp;
1699 struct insns_for_mem_entry *ime;
1703 ime = (struct insns_for_mem_entry *) htab_find (ht, &tmp);
1704 for (insn_list = ime->insns; insn_list != 0; insn_list = XEXP (insn_list, 1))
1705 if (INSN_P (XEXP (insn_list, 0)))
1706 fixup_var_refs_insn (XEXP (insn_list, 0), var, promoted_mode,
1707 unsignedp, 1, may_share);
1711 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1712 the insn under examination, VAR is the variable to fix up
1713 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1714 TOPLEVEL is nonzero if this is the main insn chain for this
1718 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel, no_share)
1721 enum machine_mode promoted_mode;
1727 rtx set, prev, prev_set;
1730 /* Remember the notes in case we delete the insn. */
1731 note = REG_NOTES (insn);
1733 /* If this is a CLOBBER of VAR, delete it.
1735 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1736 and REG_RETVAL notes too. */
1737 if (GET_CODE (PATTERN (insn)) == CLOBBER
1738 && (XEXP (PATTERN (insn), 0) == var
1739 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1740 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1741 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1743 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1744 /* The REG_LIBCALL note will go away since we are going to
1745 turn INSN into a NOTE, so just delete the
1746 corresponding REG_RETVAL note. */
1747 remove_note (XEXP (note, 0),
1748 find_reg_note (XEXP (note, 0), REG_RETVAL,
1754 /* The insn to load VAR from a home in the arglist
1755 is now a no-op. When we see it, just delete it.
1756 Similarly if this is storing VAR from a register from which
1757 it was loaded in the previous insn. This will occur
1758 when an ADDRESSOF was made for an arglist slot. */
1760 && (set = single_set (insn)) != 0
1761 && SET_DEST (set) == var
1762 /* If this represents the result of an insn group,
1763 don't delete the insn. */
1764 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1765 && (rtx_equal_p (SET_SRC (set), var)
1766 || (GET_CODE (SET_SRC (set)) == REG
1767 && (prev = prev_nonnote_insn (insn)) != 0
1768 && (prev_set = single_set (prev)) != 0
1769 && SET_DEST (prev_set) == SET_SRC (set)
1770 && rtx_equal_p (SET_SRC (prev_set), var))))
1776 struct fixup_replacement *replacements = 0;
1777 rtx next_insn = NEXT_INSN (insn);
1779 if (SMALL_REGISTER_CLASSES)
1781 /* If the insn that copies the results of a CALL_INSN
1782 into a pseudo now references VAR, we have to use an
1783 intermediate pseudo since we want the life of the
1784 return value register to be only a single insn.
1786 If we don't use an intermediate pseudo, such things as
1787 address computations to make the address of VAR valid
1788 if it is not can be placed between the CALL_INSN and INSN.
1790 To make sure this doesn't happen, we record the destination
1791 of the CALL_INSN and see if the next insn uses both that
1794 if (call_dest != 0 && GET_CODE (insn) == INSN
1795 && reg_mentioned_p (var, PATTERN (insn))
1796 && reg_mentioned_p (call_dest, PATTERN (insn)))
1798 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1800 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1802 PATTERN (insn) = replace_rtx (PATTERN (insn),
1806 if (GET_CODE (insn) == CALL_INSN
1807 && GET_CODE (PATTERN (insn)) == SET)
1808 call_dest = SET_DEST (PATTERN (insn));
1809 else if (GET_CODE (insn) == CALL_INSN
1810 && GET_CODE (PATTERN (insn)) == PARALLEL
1811 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1812 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1817 /* See if we have to do anything to INSN now that VAR is in
1818 memory. If it needs to be loaded into a pseudo, use a single
1819 pseudo for the entire insn in case there is a MATCH_DUP
1820 between two operands. We pass a pointer to the head of
1821 a list of struct fixup_replacements. If fixup_var_refs_1
1822 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1823 it will record them in this list.
1825 If it allocated a pseudo for any replacement, we copy into
1828 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1829 &replacements, no_share);
1831 /* If this is last_parm_insn, and any instructions were output
1832 after it to fix it up, then we must set last_parm_insn to
1833 the last such instruction emitted. */
1834 if (insn == last_parm_insn)
1835 last_parm_insn = PREV_INSN (next_insn);
1837 while (replacements)
1839 struct fixup_replacement *next;
1841 if (GET_CODE (replacements->new) == REG)
1846 /* OLD might be a (subreg (mem)). */
1847 if (GET_CODE (replacements->old) == SUBREG)
1849 = fixup_memory_subreg (replacements->old, insn,
1853 = fixup_stack_1 (replacements->old, insn);
1855 insert_before = insn;
1857 /* If we are changing the mode, do a conversion.
1858 This might be wasteful, but combine.c will
1859 eliminate much of the waste. */
1861 if (GET_MODE (replacements->new)
1862 != GET_MODE (replacements->old))
1865 convert_move (replacements->new,
1866 replacements->old, unsignedp);
1871 seq = gen_move_insn (replacements->new,
1874 emit_insn_before (seq, insert_before);
1877 next = replacements->next;
1878 free (replacements);
1879 replacements = next;
1883 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1884 But don't touch other insns referred to by reg-notes;
1885 we will get them elsewhere. */
1888 if (GET_CODE (note) != INSN_LIST)
1890 = walk_fixup_memory_subreg (XEXP (note, 0), insn,
1892 note = XEXP (note, 1);
1896 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1897 See if the rtx expression at *LOC in INSN needs to be changed.
1899 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1900 contain a list of original rtx's and replacements. If we find that we need
1901 to modify this insn by replacing a memory reference with a pseudo or by
1902 making a new MEM to implement a SUBREG, we consult that list to see if
1903 we have already chosen a replacement. If none has already been allocated,
1904 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1905 or the SUBREG, as appropriate, to the pseudo. */
1908 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements, no_share)
1910 enum machine_mode promoted_mode;
1913 struct fixup_replacement **replacements;
1918 RTX_CODE code = GET_CODE (x);
1921 struct fixup_replacement *replacement;
1926 if (XEXP (x, 0) == var)
1928 /* Prevent sharing of rtl that might lose. */
1929 rtx sub = copy_rtx (XEXP (var, 0));
1931 if (! validate_change (insn, loc, sub, 0))
1933 rtx y = gen_reg_rtx (GET_MODE (sub));
1936 /* We should be able to replace with a register or all is lost.
1937 Note that we can't use validate_change to verify this, since
1938 we're not caring for replacing all dups simultaneously. */
1939 if (! validate_replace_rtx (*loc, y, insn))
1942 /* Careful! First try to recognize a direct move of the
1943 value, mimicking how things are done in gen_reload wrt
1944 PLUS. Consider what happens when insn is a conditional
1945 move instruction and addsi3 clobbers flags. */
1948 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1952 if (recog_memoized (new_insn) < 0)
1954 /* That failed. Fall back on force_operand and hope. */
1957 sub = force_operand (sub, y);
1959 emit_insn (gen_move_insn (y, sub));
1965 /* Don't separate setter from user. */
1966 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1967 insn = PREV_INSN (insn);
1970 emit_insn_before (seq, insn);
1978 /* If we already have a replacement, use it. Otherwise,
1979 try to fix up this address in case it is invalid. */
1981 replacement = find_fixup_replacement (replacements, var);
1982 if (replacement->new)
1984 *loc = replacement->new;
1988 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1990 /* Unless we are forcing memory to register or we changed the mode,
1991 we can leave things the way they are if the insn is valid. */
1993 INSN_CODE (insn) = -1;
1994 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1995 && recog_memoized (insn) >= 0)
1998 *loc = replacement->new = gen_reg_rtx (promoted_mode);
2002 /* If X contains VAR, we need to unshare it here so that we update
2003 each occurrence separately. But all identical MEMs in one insn
2004 must be replaced with the same rtx because of the possibility of
2007 if (reg_mentioned_p (var, x))
2009 replacement = find_fixup_replacement (replacements, x);
2010 if (replacement->new == 0)
2011 replacement->new = copy_most_rtx (x, no_share);
2013 *loc = x = replacement->new;
2014 code = GET_CODE (x);
2031 /* Note that in some cases those types of expressions are altered
2032 by optimize_bit_field, and do not survive to get here. */
2033 if (XEXP (x, 0) == var
2034 || (GET_CODE (XEXP (x, 0)) == SUBREG
2035 && SUBREG_REG (XEXP (x, 0)) == var))
2037 /* Get TEM as a valid MEM in the mode presently in the insn.
2039 We don't worry about the possibility of MATCH_DUP here; it
2040 is highly unlikely and would be tricky to handle. */
2043 if (GET_CODE (tem) == SUBREG)
2045 if (GET_MODE_BITSIZE (GET_MODE (tem))
2046 > GET_MODE_BITSIZE (GET_MODE (var)))
2048 replacement = find_fixup_replacement (replacements, var);
2049 if (replacement->new == 0)
2050 replacement->new = gen_reg_rtx (GET_MODE (var));
2051 SUBREG_REG (tem) = replacement->new;
2053 /* The following code works only if we have a MEM, so we
2054 need to handle the subreg here. We directly substitute
2055 it assuming that a subreg must be OK here. We already
2056 scheduled a replacement to copy the mem into the
2062 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2065 tem = fixup_stack_1 (tem, insn);
2067 /* Unless we want to load from memory, get TEM into the proper mode
2068 for an extract from memory. This can only be done if the
2069 extract is at a constant position and length. */
2071 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2072 && GET_CODE (XEXP (x, 2)) == CONST_INT
2073 && ! mode_dependent_address_p (XEXP (tem, 0))
2074 && ! MEM_VOLATILE_P (tem))
2076 enum machine_mode wanted_mode = VOIDmode;
2077 enum machine_mode is_mode = GET_MODE (tem);
2078 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2080 if (GET_CODE (x) == ZERO_EXTRACT)
2082 enum machine_mode new_mode
2083 = mode_for_extraction (EP_extzv, 1);
2084 if (new_mode != MAX_MACHINE_MODE)
2085 wanted_mode = new_mode;
2087 else if (GET_CODE (x) == SIGN_EXTRACT)
2089 enum machine_mode new_mode
2090 = mode_for_extraction (EP_extv, 1);
2091 if (new_mode != MAX_MACHINE_MODE)
2092 wanted_mode = new_mode;
2095 /* If we have a narrower mode, we can do something. */
2096 if (wanted_mode != VOIDmode
2097 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2099 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2100 rtx old_pos = XEXP (x, 2);
2103 /* If the bytes and bits are counted differently, we
2104 must adjust the offset. */
2105 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2106 offset = (GET_MODE_SIZE (is_mode)
2107 - GET_MODE_SIZE (wanted_mode) - offset);
2109 pos %= GET_MODE_BITSIZE (wanted_mode);
2111 newmem = adjust_address_nv (tem, wanted_mode, offset);
2113 /* Make the change and see if the insn remains valid. */
2114 INSN_CODE (insn) = -1;
2115 XEXP (x, 0) = newmem;
2116 XEXP (x, 2) = GEN_INT (pos);
2118 if (recog_memoized (insn) >= 0)
2121 /* Otherwise, restore old position. XEXP (x, 0) will be
2123 XEXP (x, 2) = old_pos;
2127 /* If we get here, the bitfield extract insn can't accept a memory
2128 reference. Copy the input into a register. */
2130 tem1 = gen_reg_rtx (GET_MODE (tem));
2131 emit_insn_before (gen_move_insn (tem1, tem), insn);
2138 if (SUBREG_REG (x) == var)
2140 /* If this is a special SUBREG made because VAR was promoted
2141 from a wider mode, replace it with VAR and call ourself
2142 recursively, this time saying that the object previously
2143 had its current mode (by virtue of the SUBREG). */
2145 if (SUBREG_PROMOTED_VAR_P (x))
2148 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements,
2153 /* If this SUBREG makes VAR wider, it has become a paradoxical
2154 SUBREG with VAR in memory, but these aren't allowed at this
2155 stage of the compilation. So load VAR into a pseudo and take
2156 a SUBREG of that pseudo. */
2157 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2159 replacement = find_fixup_replacement (replacements, var);
2160 if (replacement->new == 0)
2161 replacement->new = gen_reg_rtx (promoted_mode);
2162 SUBREG_REG (x) = replacement->new;
2166 /* See if we have already found a replacement for this SUBREG.
2167 If so, use it. Otherwise, make a MEM and see if the insn
2168 is recognized. If not, or if we should force MEM into a register,
2169 make a pseudo for this SUBREG. */
2170 replacement = find_fixup_replacement (replacements, x);
2171 if (replacement->new)
2173 *loc = replacement->new;
2177 replacement->new = *loc = fixup_memory_subreg (x, insn,
2180 INSN_CODE (insn) = -1;
2181 if (! flag_force_mem && recog_memoized (insn) >= 0)
2184 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2190 /* First do special simplification of bit-field references. */
2191 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2192 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2193 optimize_bit_field (x, insn, 0);
2194 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2195 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2196 optimize_bit_field (x, insn, 0);
2198 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2199 into a register and then store it back out. */
2200 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2201 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2202 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2203 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2204 > GET_MODE_SIZE (GET_MODE (var))))
2206 replacement = find_fixup_replacement (replacements, var);
2207 if (replacement->new == 0)
2208 replacement->new = gen_reg_rtx (GET_MODE (var));
2210 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2211 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2214 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2215 insn into a pseudo and store the low part of the pseudo into VAR. */
2216 if (GET_CODE (SET_DEST (x)) == SUBREG
2217 && SUBREG_REG (SET_DEST (x)) == var
2218 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2219 > GET_MODE_SIZE (GET_MODE (var))))
2221 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2222 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2229 rtx dest = SET_DEST (x);
2230 rtx src = SET_SRC (x);
2231 rtx outerdest = dest;
2233 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2234 || GET_CODE (dest) == SIGN_EXTRACT
2235 || GET_CODE (dest) == ZERO_EXTRACT)
2236 dest = XEXP (dest, 0);
2238 if (GET_CODE (src) == SUBREG)
2239 src = SUBREG_REG (src);
2241 /* If VAR does not appear at the top level of the SET
2242 just scan the lower levels of the tree. */
2244 if (src != var && dest != var)
2247 /* We will need to rerecognize this insn. */
2248 INSN_CODE (insn) = -1;
2250 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var
2251 && mode_for_extraction (EP_insv, -1) != MAX_MACHINE_MODE)
2253 /* Since this case will return, ensure we fixup all the
2255 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2256 insn, replacements, no_share);
2257 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2258 insn, replacements, no_share);
2259 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2260 insn, replacements, no_share);
2262 tem = XEXP (outerdest, 0);
2264 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2265 that may appear inside a ZERO_EXTRACT.
2266 This was legitimate when the MEM was a REG. */
2267 if (GET_CODE (tem) == SUBREG
2268 && SUBREG_REG (tem) == var)
2269 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2271 tem = fixup_stack_1 (tem, insn);
2273 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2274 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2275 && ! mode_dependent_address_p (XEXP (tem, 0))
2276 && ! MEM_VOLATILE_P (tem))
2278 enum machine_mode wanted_mode;
2279 enum machine_mode is_mode = GET_MODE (tem);
2280 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2282 wanted_mode = mode_for_extraction (EP_insv, 0);
2284 /* If we have a narrower mode, we can do something. */
2285 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2287 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2288 rtx old_pos = XEXP (outerdest, 2);
2291 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2292 offset = (GET_MODE_SIZE (is_mode)
2293 - GET_MODE_SIZE (wanted_mode) - offset);
2295 pos %= GET_MODE_BITSIZE (wanted_mode);
2297 newmem = adjust_address_nv (tem, wanted_mode, offset);
2299 /* Make the change and see if the insn remains valid. */
2300 INSN_CODE (insn) = -1;
2301 XEXP (outerdest, 0) = newmem;
2302 XEXP (outerdest, 2) = GEN_INT (pos);
2304 if (recog_memoized (insn) >= 0)
2307 /* Otherwise, restore old position. XEXP (x, 0) will be
2309 XEXP (outerdest, 2) = old_pos;
2313 /* If we get here, the bit-field store doesn't allow memory
2314 or isn't located at a constant position. Load the value into
2315 a register, do the store, and put it back into memory. */
2317 tem1 = gen_reg_rtx (GET_MODE (tem));
2318 emit_insn_before (gen_move_insn (tem1, tem), insn);
2319 emit_insn_after (gen_move_insn (tem, tem1), insn);
2320 XEXP (outerdest, 0) = tem1;
2324 /* STRICT_LOW_PART is a no-op on memory references
2325 and it can cause combinations to be unrecognizable,
2328 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2329 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2331 /* A valid insn to copy VAR into or out of a register
2332 must be left alone, to avoid an infinite loop here.
2333 If the reference to VAR is by a subreg, fix that up,
2334 since SUBREG is not valid for a memref.
2335 Also fix up the address of the stack slot.
2337 Note that we must not try to recognize the insn until
2338 after we know that we have valid addresses and no
2339 (subreg (mem ...) ...) constructs, since these interfere
2340 with determining the validity of the insn. */
2342 if ((SET_SRC (x) == var
2343 || (GET_CODE (SET_SRC (x)) == SUBREG
2344 && SUBREG_REG (SET_SRC (x)) == var))
2345 && (GET_CODE (SET_DEST (x)) == REG
2346 || (GET_CODE (SET_DEST (x)) == SUBREG
2347 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2348 && GET_MODE (var) == promoted_mode
2349 && x == single_set (insn))
2353 if (GET_CODE (SET_SRC (x)) == SUBREG
2354 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
2355 > GET_MODE_SIZE (GET_MODE (var))))
2357 /* This (subreg VAR) is now a paradoxical subreg. We need
2358 to replace VAR instead of the subreg. */
2359 replacement = find_fixup_replacement (replacements, var);
2360 if (replacement->new == NULL_RTX)
2361 replacement->new = gen_reg_rtx (GET_MODE (var));
2362 SUBREG_REG (SET_SRC (x)) = replacement->new;
2366 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2367 if (replacement->new)
2368 SET_SRC (x) = replacement->new;
2369 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2370 SET_SRC (x) = replacement->new
2371 = fixup_memory_subreg (SET_SRC (x), insn, promoted_mode,
2374 SET_SRC (x) = replacement->new
2375 = fixup_stack_1 (SET_SRC (x), insn);
2378 if (recog_memoized (insn) >= 0)
2381 /* INSN is not valid, but we know that we want to
2382 copy SET_SRC (x) to SET_DEST (x) in some way. So
2383 we generate the move and see whether it requires more
2384 than one insn. If it does, we emit those insns and
2385 delete INSN. Otherwise, we an just replace the pattern
2386 of INSN; we have already verified above that INSN has
2387 no other function that to do X. */
2389 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2390 if (NEXT_INSN (pat) != NULL_RTX)
2392 last = emit_insn_before (pat, insn);
2394 /* INSN might have REG_RETVAL or other important notes, so
2395 we need to store the pattern of the last insn in the
2396 sequence into INSN similarly to the normal case. LAST
2397 should not have REG_NOTES, but we allow them if INSN has
2399 if (REG_NOTES (last) && REG_NOTES (insn))
2401 if (REG_NOTES (last))
2402 REG_NOTES (insn) = REG_NOTES (last);
2403 PATTERN (insn) = PATTERN (last);
2408 PATTERN (insn) = PATTERN (pat);
2413 if ((SET_DEST (x) == var
2414 || (GET_CODE (SET_DEST (x)) == SUBREG
2415 && SUBREG_REG (SET_DEST (x)) == var))
2416 && (GET_CODE (SET_SRC (x)) == REG
2417 || (GET_CODE (SET_SRC (x)) == SUBREG
2418 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2419 && GET_MODE (var) == promoted_mode
2420 && x == single_set (insn))
2424 if (GET_CODE (SET_DEST (x)) == SUBREG)
2425 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn,
2428 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2430 if (recog_memoized (insn) >= 0)
2433 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2434 if (NEXT_INSN (pat) != NULL_RTX)
2436 last = emit_insn_before (pat, insn);
2438 /* INSN might have REG_RETVAL or other important notes, so
2439 we need to store the pattern of the last insn in the
2440 sequence into INSN similarly to the normal case. LAST
2441 should not have REG_NOTES, but we allow them if INSN has
2443 if (REG_NOTES (last) && REG_NOTES (insn))
2445 if (REG_NOTES (last))
2446 REG_NOTES (insn) = REG_NOTES (last);
2447 PATTERN (insn) = PATTERN (last);
2452 PATTERN (insn) = PATTERN (pat);
2457 /* Otherwise, storing into VAR must be handled specially
2458 by storing into a temporary and copying that into VAR
2459 with a new insn after this one. Note that this case
2460 will be used when storing into a promoted scalar since
2461 the insn will now have different modes on the input
2462 and output and hence will be invalid (except for the case
2463 of setting it to a constant, which does not need any
2464 change if it is valid). We generate extra code in that case,
2465 but combine.c will eliminate it. */
2470 rtx fixeddest = SET_DEST (x);
2471 enum machine_mode temp_mode;
2473 /* STRICT_LOW_PART can be discarded, around a MEM. */
2474 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2475 fixeddest = XEXP (fixeddest, 0);
2476 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2477 if (GET_CODE (fixeddest) == SUBREG)
2479 fixeddest = fixup_memory_subreg (fixeddest, insn,
2481 temp_mode = GET_MODE (fixeddest);
2485 fixeddest = fixup_stack_1 (fixeddest, insn);
2486 temp_mode = promoted_mode;
2489 temp = gen_reg_rtx (temp_mode);
2491 emit_insn_after (gen_move_insn (fixeddest,
2492 gen_lowpart (GET_MODE (fixeddest),
2496 SET_DEST (x) = temp;
2504 /* Nothing special about this RTX; fix its operands. */
2506 fmt = GET_RTX_FORMAT (code);
2507 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2510 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements,
2512 else if (fmt[i] == 'E')
2515 for (j = 0; j < XVECLEN (x, i); j++)
2516 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2517 insn, replacements, no_share);
2522 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2523 The REG was placed on the stack, so X now has the form (SUBREG:m1
2526 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2527 must be emitted to compute NEWADDR, put them before INSN.
2529 UNCRITICAL nonzero means accept paradoxical subregs.
2530 This is used for subregs found inside REG_NOTES. */
2533 fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2536 enum machine_mode promoted_mode;
2540 rtx mem = SUBREG_REG (x);
2541 rtx addr = XEXP (mem, 0);
2542 enum machine_mode mode = GET_MODE (x);
2545 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2546 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (mem)) && ! uncritical)
2549 offset = SUBREG_BYTE (x);
2550 if (BYTES_BIG_ENDIAN)
2551 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2552 the offset so that it points to the right location within the
2554 offset -= (GET_MODE_SIZE (promoted_mode) - GET_MODE_SIZE (GET_MODE (mem)));
2556 if (!flag_force_addr
2557 && memory_address_p (mode, plus_constant (addr, offset)))
2558 /* Shortcut if no insns need be emitted. */
2559 return adjust_address (mem, mode, offset);
2562 result = adjust_address (mem, mode, offset);
2566 emit_insn_before (seq, insn);
2570 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2571 Replace subexpressions of X in place.
2572 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2573 Otherwise return X, with its contents possibly altered.
2575 INSN, PROMOTED_MODE and UNCRITICAL are as for
2576 fixup_memory_subreg. */
2579 walk_fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2582 enum machine_mode promoted_mode;
2592 code = GET_CODE (x);
2594 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2595 return fixup_memory_subreg (x, insn, promoted_mode, uncritical);
2597 /* Nothing special about this RTX; fix its operands. */
2599 fmt = GET_RTX_FORMAT (code);
2600 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2603 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn,
2604 promoted_mode, uncritical);
2605 else if (fmt[i] == 'E')
2608 for (j = 0; j < XVECLEN (x, i); j++)
2610 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn,
2611 promoted_mode, uncritical);
2617 /* For each memory ref within X, if it refers to a stack slot
2618 with an out of range displacement, put the address in a temp register
2619 (emitting new insns before INSN to load these registers)
2620 and alter the memory ref to use that register.
2621 Replace each such MEM rtx with a copy, to avoid clobberage. */
2624 fixup_stack_1 (x, insn)
2629 RTX_CODE code = GET_CODE (x);
2634 rtx ad = XEXP (x, 0);
2635 /* If we have address of a stack slot but it's not valid
2636 (displacement is too large), compute the sum in a register. */
2637 if (GET_CODE (ad) == PLUS
2638 && GET_CODE (XEXP (ad, 0)) == REG
2639 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2640 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2641 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2642 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2643 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2645 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2646 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2647 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2648 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2651 if (memory_address_p (GET_MODE (x), ad))
2655 temp = copy_to_reg (ad);
2658 emit_insn_before (seq, insn);
2659 return replace_equiv_address (x, temp);
2664 fmt = GET_RTX_FORMAT (code);
2665 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2668 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2669 else if (fmt[i] == 'E')
2672 for (j = 0; j < XVECLEN (x, i); j++)
2673 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2679 /* Optimization: a bit-field instruction whose field
2680 happens to be a byte or halfword in memory
2681 can be changed to a move instruction.
2683 We call here when INSN is an insn to examine or store into a bit-field.
2684 BODY is the SET-rtx to be altered.
2686 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2687 (Currently this is called only from function.c, and EQUIV_MEM
2691 optimize_bit_field (body, insn, equiv_mem)
2699 enum machine_mode mode;
2701 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2702 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2703 bitfield = SET_DEST (body), destflag = 1;
2705 bitfield = SET_SRC (body), destflag = 0;
2707 /* First check that the field being stored has constant size and position
2708 and is in fact a byte or halfword suitably aligned. */
2710 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2711 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2712 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2714 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2718 /* Now check that the containing word is memory, not a register,
2719 and that it is safe to change the machine mode. */
2721 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2722 memref = XEXP (bitfield, 0);
2723 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2725 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2726 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2727 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2728 memref = SUBREG_REG (XEXP (bitfield, 0));
2729 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2731 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2732 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2735 && ! mode_dependent_address_p (XEXP (memref, 0))
2736 && ! MEM_VOLATILE_P (memref))
2738 /* Now adjust the address, first for any subreg'ing
2739 that we are now getting rid of,
2740 and then for which byte of the word is wanted. */
2742 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2745 /* Adjust OFFSET to count bits from low-address byte. */
2746 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2747 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2748 - offset - INTVAL (XEXP (bitfield, 1)));
2750 /* Adjust OFFSET to count bytes from low-address byte. */
2751 offset /= BITS_PER_UNIT;
2752 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2754 offset += (SUBREG_BYTE (XEXP (bitfield, 0))
2755 / UNITS_PER_WORD) * UNITS_PER_WORD;
2756 if (BYTES_BIG_ENDIAN)
2757 offset -= (MIN (UNITS_PER_WORD,
2758 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2759 - MIN (UNITS_PER_WORD,
2760 GET_MODE_SIZE (GET_MODE (memref))));
2764 memref = adjust_address (memref, mode, offset);
2765 insns = get_insns ();
2767 emit_insn_before (insns, insn);
2769 /* Store this memory reference where
2770 we found the bit field reference. */
2774 validate_change (insn, &SET_DEST (body), memref, 1);
2775 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2777 rtx src = SET_SRC (body);
2778 while (GET_CODE (src) == SUBREG
2779 && SUBREG_BYTE (src) == 0)
2780 src = SUBREG_REG (src);
2781 if (GET_MODE (src) != GET_MODE (memref))
2782 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2783 validate_change (insn, &SET_SRC (body), src, 1);
2785 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2786 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2787 /* This shouldn't happen because anything that didn't have
2788 one of these modes should have got converted explicitly
2789 and then referenced through a subreg.
2790 This is so because the original bit-field was
2791 handled by agg_mode and so its tree structure had
2792 the same mode that memref now has. */
2797 rtx dest = SET_DEST (body);
2799 while (GET_CODE (dest) == SUBREG
2800 && SUBREG_BYTE (dest) == 0
2801 && (GET_MODE_CLASS (GET_MODE (dest))
2802 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2803 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2805 dest = SUBREG_REG (dest);
2807 validate_change (insn, &SET_DEST (body), dest, 1);
2809 if (GET_MODE (dest) == GET_MODE (memref))
2810 validate_change (insn, &SET_SRC (body), memref, 1);
2813 /* Convert the mem ref to the destination mode. */
2814 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2817 convert_move (newreg, memref,
2818 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2822 validate_change (insn, &SET_SRC (body), newreg, 1);
2826 /* See if we can convert this extraction or insertion into
2827 a simple move insn. We might not be able to do so if this
2828 was, for example, part of a PARALLEL.
2830 If we succeed, write out any needed conversions. If we fail,
2831 it is hard to guess why we failed, so don't do anything
2832 special; just let the optimization be suppressed. */
2834 if (apply_change_group () && seq)
2835 emit_insn_before (seq, insn);
2840 /* These routines are responsible for converting virtual register references
2841 to the actual hard register references once RTL generation is complete.
2843 The following four variables are used for communication between the
2844 routines. They contain the offsets of the virtual registers from their
2845 respective hard registers. */
2847 static int in_arg_offset;
2848 static int var_offset;
2849 static int dynamic_offset;
2850 static int out_arg_offset;
2851 static int cfa_offset;
2853 /* In most machines, the stack pointer register is equivalent to the bottom
2856 #ifndef STACK_POINTER_OFFSET
2857 #define STACK_POINTER_OFFSET 0
2860 /* If not defined, pick an appropriate default for the offset of dynamically
2861 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2862 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2864 #ifndef STACK_DYNAMIC_OFFSET
2866 /* The bottom of the stack points to the actual arguments. If
2867 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2868 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2869 stack space for register parameters is not pushed by the caller, but
2870 rather part of the fixed stack areas and hence not included in
2871 `current_function_outgoing_args_size'. Nevertheless, we must allow
2872 for it when allocating stack dynamic objects. */
2874 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2875 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2876 ((ACCUMULATE_OUTGOING_ARGS \
2877 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2878 + (STACK_POINTER_OFFSET)) \
2881 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2882 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2883 + (STACK_POINTER_OFFSET))
2887 /* On most machines, the CFA coincides with the first incoming parm. */
2889 #ifndef ARG_POINTER_CFA_OFFSET
2890 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2893 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2894 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2895 register, for later use if we do need to force REG into the stack. REG is
2896 overwritten by the MEM like in put_reg_into_stack. */
2899 gen_mem_addressof (reg, decl)
2903 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2906 /* Calculate this before we start messing with decl's RTL. */
2907 HOST_WIDE_INT set = decl ? get_alias_set (decl) : 0;
2909 /* If the original REG was a user-variable, then so is the REG whose
2910 address is being taken. Likewise for unchanging. */
2911 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2912 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg);
2914 PUT_CODE (reg, MEM);
2915 MEM_ATTRS (reg) = 0;
2920 tree type = TREE_TYPE (decl);
2921 enum machine_mode decl_mode
2922 = (DECL_P (decl) ? DECL_MODE (decl) : TYPE_MODE (TREE_TYPE (decl)));
2923 rtx decl_rtl = (TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl)
2924 : DECL_RTL_IF_SET (decl));
2926 PUT_MODE (reg, decl_mode);
2928 /* Clear DECL_RTL momentarily so functions below will work
2929 properly, then set it again. */
2930 if (DECL_P (decl) && decl_rtl == reg)
2931 SET_DECL_RTL (decl, 0);
2933 set_mem_attributes (reg, decl, 1);
2934 set_mem_alias_set (reg, set);
2936 if (DECL_P (decl) && decl_rtl == reg)
2937 SET_DECL_RTL (decl, reg);
2939 if (TREE_USED (decl) || (DECL_P (decl) && DECL_INITIAL (decl) != 0))
2940 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), reg, 0);
2943 fixup_var_refs (reg, GET_MODE (reg), 0, reg, 0);
2948 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2951 flush_addressof (decl)
2954 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2955 && DECL_RTL (decl) != 0
2956 && GET_CODE (DECL_RTL (decl)) == MEM
2957 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2958 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2959 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2962 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2965 put_addressof_into_stack (r, ht)
2970 int volatile_p, used_p;
2972 rtx reg = XEXP (r, 0);
2974 if (GET_CODE (reg) != REG)
2977 decl = ADDRESSOF_DECL (r);
2980 type = TREE_TYPE (decl);
2981 volatile_p = (TREE_CODE (decl) != SAVE_EXPR
2982 && TREE_THIS_VOLATILE (decl));
2983 used_p = (TREE_USED (decl)
2984 || (DECL_P (decl) && DECL_INITIAL (decl) != 0));
2993 put_reg_into_stack (0, reg, type, GET_MODE (reg), GET_MODE (reg),
2994 volatile_p, ADDRESSOF_REGNO (r), used_p, ht);
2997 /* List of replacements made below in purge_addressof_1 when creating
2998 bitfield insertions. */
2999 static rtx purge_bitfield_addressof_replacements;
3001 /* List of replacements made below in purge_addressof_1 for patterns
3002 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
3003 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
3004 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
3005 enough in complex cases, e.g. when some field values can be
3006 extracted by usage MEM with narrower mode. */
3007 static rtx purge_addressof_replacements;
3009 /* Helper function for purge_addressof. See if the rtx expression at *LOC
3010 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
3011 the stack. If the function returns FALSE then the replacement could not
3015 purge_addressof_1 (loc, insn, force, store, ht)
3027 /* Re-start here to avoid recursion in common cases. */
3034 code = GET_CODE (x);
3036 /* If we don't return in any of the cases below, we will recurse inside
3037 the RTX, which will normally result in any ADDRESSOF being forced into
3041 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3042 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3045 else if (code == ADDRESSOF)
3049 if (GET_CODE (XEXP (x, 0)) != MEM)
3051 put_addressof_into_stack (x, ht);
3055 /* We must create a copy of the rtx because it was created by
3056 overwriting a REG rtx which is always shared. */
3057 sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3058 if (validate_change (insn, loc, sub, 0)
3059 || validate_replace_rtx (x, sub, insn))
3063 sub = force_operand (sub, NULL_RTX);
3064 if (! validate_change (insn, loc, sub, 0)
3065 && ! validate_replace_rtx (x, sub, insn))
3068 insns = get_insns ();
3070 emit_insn_before (insns, insn);
3074 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3076 rtx sub = XEXP (XEXP (x, 0), 0);
3078 if (GET_CODE (sub) == MEM)
3079 sub = adjust_address_nv (sub, GET_MODE (x), 0);
3080 else if (GET_CODE (sub) == REG
3081 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3083 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3085 int size_x, size_sub;
3089 /* When processing REG_NOTES look at the list of
3090 replacements done on the insn to find the register that X
3094 for (tem = purge_bitfield_addressof_replacements;
3096 tem = XEXP (XEXP (tem, 1), 1))
3097 if (rtx_equal_p (x, XEXP (tem, 0)))
3099 *loc = XEXP (XEXP (tem, 1), 0);
3103 /* See comment for purge_addressof_replacements. */
3104 for (tem = purge_addressof_replacements;
3106 tem = XEXP (XEXP (tem, 1), 1))
3107 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3109 rtx z = XEXP (XEXP (tem, 1), 0);
3111 if (GET_MODE (x) == GET_MODE (z)
3112 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3113 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3116 /* It can happen that the note may speak of things
3117 in a wider (or just different) mode than the
3118 code did. This is especially true of
3121 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0)
3124 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3125 && (GET_MODE_SIZE (GET_MODE (x))
3126 > GET_MODE_SIZE (GET_MODE (z))))
3128 /* This can occur as a result in invalid
3129 pointer casts, e.g. float f; ...
3130 *(long long int *)&f.
3131 ??? We could emit a warning here, but
3132 without a line number that wouldn't be
3134 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3137 z = gen_lowpart (GET_MODE (x), z);
3143 /* Sometimes we may not be able to find the replacement. For
3144 example when the original insn was a MEM in a wider mode,
3145 and the note is part of a sign extension of a narrowed
3146 version of that MEM. Gcc testcase compile/990829-1.c can
3147 generate an example of this situation. Rather than complain
3148 we return false, which will prompt our caller to remove the
3153 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3154 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3156 /* Don't even consider working with paradoxical subregs,
3157 or the moral equivalent seen here. */
3158 if (size_x <= size_sub
3159 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3161 /* Do a bitfield insertion to mirror what would happen
3168 rtx p = PREV_INSN (insn);
3171 val = gen_reg_rtx (GET_MODE (x));
3172 if (! validate_change (insn, loc, val, 0))
3174 /* Discard the current sequence and put the
3175 ADDRESSOF on stack. */
3181 emit_insn_before (seq, insn);
3182 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3186 store_bit_field (sub, size_x, 0, GET_MODE (x),
3187 val, GET_MODE_SIZE (GET_MODE (sub)));
3189 /* Make sure to unshare any shared rtl that store_bit_field
3190 might have created. */
3191 unshare_all_rtl_again (get_insns ());
3195 p = emit_insn_after (seq, insn);
3196 if (NEXT_INSN (insn))
3197 compute_insns_for_mem (NEXT_INSN (insn),
3198 p ? NEXT_INSN (p) : NULL_RTX,
3203 rtx p = PREV_INSN (insn);
3206 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3207 GET_MODE (x), GET_MODE (x),
3208 GET_MODE_SIZE (GET_MODE (sub)));
3210 if (! validate_change (insn, loc, val, 0))
3212 /* Discard the current sequence and put the
3213 ADDRESSOF on stack. */
3220 emit_insn_before (seq, insn);
3221 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3225 /* Remember the replacement so that the same one can be done
3226 on the REG_NOTES. */
3227 purge_bitfield_addressof_replacements
3228 = gen_rtx_EXPR_LIST (VOIDmode, x,
3231 purge_bitfield_addressof_replacements));
3233 /* We replaced with a reg -- all done. */
3238 else if (validate_change (insn, loc, sub, 0))
3240 /* Remember the replacement so that the same one can be done
3241 on the REG_NOTES. */
3242 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3246 for (tem = purge_addressof_replacements;
3248 tem = XEXP (XEXP (tem, 1), 1))
3249 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3251 XEXP (XEXP (tem, 1), 0) = sub;
3254 purge_addressof_replacements
3255 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3256 gen_rtx_EXPR_LIST (VOIDmode, sub,
3257 purge_addressof_replacements));
3265 /* Scan all subexpressions. */
3266 fmt = GET_RTX_FORMAT (code);
3267 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3270 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3271 else if (*fmt == 'E')
3272 for (j = 0; j < XVECLEN (x, i); j++)
3273 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
3279 /* Return a hash value for K, a REG. */
3282 insns_for_mem_hash (k)
3285 /* Use the address of the key for the hash value. */
3286 struct insns_for_mem_entry *m = (struct insns_for_mem_entry *) k;
3287 return (hashval_t) m->key;
3290 /* Return non-zero if K1 and K2 (two REGs) are the same. */
3293 insns_for_mem_comp (k1, k2)
3297 struct insns_for_mem_entry *m1 = (struct insns_for_mem_entry *) k1;
3298 struct insns_for_mem_entry *m2 = (struct insns_for_mem_entry *) k2;
3299 return m1->key == m2->key;
3302 struct insns_for_mem_walk_info
3304 /* The hash table that we are using to record which INSNs use which
3308 /* The INSN we are currently processing. */
3311 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3312 to find the insns that use the REGs in the ADDRESSOFs. */
3316 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3317 that might be used in an ADDRESSOF expression, record this INSN in
3318 the hash table given by DATA (which is really a pointer to an
3319 insns_for_mem_walk_info structure). */
3322 insns_for_mem_walk (r, data)
3326 struct insns_for_mem_walk_info *ifmwi
3327 = (struct insns_for_mem_walk_info *) data;
3328 struct insns_for_mem_entry tmp;
3329 tmp.insns = NULL_RTX;
3331 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3332 && GET_CODE (XEXP (*r, 0)) == REG)
3335 tmp.key = XEXP (*r, 0);
3336 e = htab_find_slot (ifmwi->ht, &tmp, INSERT);
3339 *e = ggc_alloc (sizeof (tmp));
3340 memcpy (*e, &tmp, sizeof (tmp));
3343 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3345 struct insns_for_mem_entry *ifme;
3347 ifme = (struct insns_for_mem_entry *) htab_find (ifmwi->ht, &tmp);
3349 /* If we have not already recorded this INSN, do so now. Since
3350 we process the INSNs in order, we know that if we have
3351 recorded it it must be at the front of the list. */
3352 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3353 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3360 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3361 which REGs in HT. */
3364 compute_insns_for_mem (insns, last_insn, ht)
3370 struct insns_for_mem_walk_info ifmwi;
3373 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3374 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3378 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3382 /* Helper function for purge_addressof called through for_each_rtx.
3383 Returns true iff the rtl is an ADDRESSOF. */
3386 is_addressof (rtl, data)
3388 void *data ATTRIBUTE_UNUSED;
3390 return GET_CODE (*rtl) == ADDRESSOF;
3393 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3394 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3398 purge_addressof (insns)
3404 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3405 requires a fixup pass over the instruction stream to correct
3406 INSNs that depended on the REG being a REG, and not a MEM. But,
3407 these fixup passes are slow. Furthermore, most MEMs are not
3408 mentioned in very many instructions. So, we speed up the process
3409 by pre-calculating which REGs occur in which INSNs; that allows
3410 us to perform the fixup passes much more quickly. */
3411 ht = htab_create_ggc (1000, insns_for_mem_hash, insns_for_mem_comp, NULL);
3412 compute_insns_for_mem (insns, NULL_RTX, ht);
3414 for (insn = insns; insn; insn = NEXT_INSN (insn))
3415 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3416 || GET_CODE (insn) == CALL_INSN)
3418 if (! purge_addressof_1 (&PATTERN (insn), insn,
3419 asm_noperands (PATTERN (insn)) > 0, 0, ht))
3420 /* If we could not replace the ADDRESSOFs in the insn,
3421 something is wrong. */
3424 if (! purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, ht))
3426 /* If we could not replace the ADDRESSOFs in the insn's notes,
3427 we can just remove the offending notes instead. */
3430 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3432 /* If we find a REG_RETVAL note then the insn is a libcall.
3433 Such insns must have REG_EQUAL notes as well, in order
3434 for later passes of the compiler to work. So it is not
3435 safe to delete the notes here, and instead we abort. */
3436 if (REG_NOTE_KIND (note) == REG_RETVAL)
3438 if (for_each_rtx (¬e, is_addressof, NULL))
3439 remove_note (insn, note);
3445 purge_bitfield_addressof_replacements = 0;
3446 purge_addressof_replacements = 0;
3448 /* REGs are shared. purge_addressof will destructively replace a REG
3449 with a MEM, which creates shared MEMs.
3451 Unfortunately, the children of put_reg_into_stack assume that MEMs
3452 referring to the same stack slot are shared (fixup_var_refs and
3453 the associated hash table code).
3455 So, we have to do another unsharing pass after we have flushed any
3456 REGs that had their address taken into the stack.
3458 It may be worth tracking whether or not we converted any REGs into
3459 MEMs to avoid this overhead when it is not needed. */
3460 unshare_all_rtl_again (get_insns ());
3463 /* Convert a SET of a hard subreg to a set of the appropriate hard
3464 register. A subroutine of purge_hard_subreg_sets. */
3467 purge_single_hard_subreg_set (pattern)
3470 rtx reg = SET_DEST (pattern);
3471 enum machine_mode mode = GET_MODE (SET_DEST (pattern));
3474 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG
3475 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER)
3477 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)),
3478 GET_MODE (SUBREG_REG (reg)),
3481 reg = SUBREG_REG (reg);
3485 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER)
3487 reg = gen_rtx_REG (mode, REGNO (reg) + offset);
3488 SET_DEST (pattern) = reg;
3492 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3493 only such SETs that we expect to see are those left in because
3494 integrate can't handle sets of parts of a return value register.
3496 We don't use alter_subreg because we only want to eliminate subregs
3497 of hard registers. */
3500 purge_hard_subreg_sets (insn)
3503 for (; insn; insn = NEXT_INSN (insn))
3507 rtx pattern = PATTERN (insn);
3508 switch (GET_CODE (pattern))
3511 if (GET_CODE (SET_DEST (pattern)) == SUBREG)
3512 purge_single_hard_subreg_set (pattern);
3517 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--)
3519 rtx inner_pattern = XVECEXP (pattern, 0, j);
3520 if (GET_CODE (inner_pattern) == SET
3521 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG)
3522 purge_single_hard_subreg_set (inner_pattern);
3533 /* Pass through the INSNS of function FNDECL and convert virtual register
3534 references to hard register references. */
3537 instantiate_virtual_regs (fndecl, insns)
3544 /* Compute the offsets to use for this function. */
3545 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3546 var_offset = STARTING_FRAME_OFFSET;
3547 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3548 out_arg_offset = STACK_POINTER_OFFSET;
3549 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl);
3551 /* Scan all variables and parameters of this function. For each that is
3552 in memory, instantiate all virtual registers if the result is a valid
3553 address. If not, we do it later. That will handle most uses of virtual
3554 regs on many machines. */
3555 instantiate_decls (fndecl, 1);
3557 /* Initialize recognition, indicating that volatile is OK. */
3560 /* Scan through all the insns, instantiating every virtual register still
3562 for (insn = insns; insn; insn = NEXT_INSN (insn))
3563 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3564 || GET_CODE (insn) == CALL_INSN)
3566 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3567 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
3568 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3569 if (GET_CODE (insn) == CALL_INSN)
3570 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn),
3574 /* Instantiate the stack slots for the parm registers, for later use in
3575 addressof elimination. */
3576 for (i = 0; i < max_parm_reg; ++i)
3577 if (parm_reg_stack_loc[i])
3578 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3580 /* Now instantiate the remaining register equivalences for debugging info.
3581 These will not be valid addresses. */
3582 instantiate_decls (fndecl, 0);
3584 /* Indicate that, from now on, assign_stack_local should use
3585 frame_pointer_rtx. */
3586 virtuals_instantiated = 1;
3589 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3590 all virtual registers in their DECL_RTL's.
3592 If VALID_ONLY, do this only if the resulting address is still valid.
3593 Otherwise, always do it. */
3596 instantiate_decls (fndecl, valid_only)
3602 /* Process all parameters of the function. */
3603 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3605 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3606 HOST_WIDE_INT size_rtl;
3608 instantiate_decl (DECL_RTL (decl), size, valid_only);
3610 /* If the parameter was promoted, then the incoming RTL mode may be
3611 larger than the declared type size. We must use the larger of
3613 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl)));
3614 size = MAX (size_rtl, size);
3615 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3618 /* Now process all variables defined in the function or its subblocks. */
3619 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3622 /* Subroutine of instantiate_decls: Process all decls in the given
3623 BLOCK node and all its subblocks. */
3626 instantiate_decls_1 (let, valid_only)
3632 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3633 if (DECL_RTL_SET_P (t))
3634 instantiate_decl (DECL_RTL (t),
3635 int_size_in_bytes (TREE_TYPE (t)),
3638 /* Process all subblocks. */
3639 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3640 instantiate_decls_1 (t, valid_only);
3643 /* Subroutine of the preceding procedures: Given RTL representing a
3644 decl and the size of the object, do any instantiation required.
3646 If VALID_ONLY is non-zero, it means that the RTL should only be
3647 changed if the new address is valid. */
3650 instantiate_decl (x, size, valid_only)
3655 enum machine_mode mode;
3658 /* If this is not a MEM, no need to do anything. Similarly if the
3659 address is a constant or a register that is not a virtual register. */
3661 if (x == 0 || GET_CODE (x) != MEM)
3665 if (CONSTANT_P (addr)
3666 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3667 || (GET_CODE (addr) == REG
3668 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3669 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3672 /* If we should only do this if the address is valid, copy the address.
3673 We need to do this so we can undo any changes that might make the
3674 address invalid. This copy is unfortunate, but probably can't be
3678 addr = copy_rtx (addr);
3680 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3682 if (valid_only && size >= 0)
3684 unsigned HOST_WIDE_INT decl_size = size;
3686 /* Now verify that the resulting address is valid for every integer or
3687 floating-point mode up to and including SIZE bytes long. We do this
3688 since the object might be accessed in any mode and frame addresses
3691 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3692 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3693 mode = GET_MODE_WIDER_MODE (mode))
3694 if (! memory_address_p (mode, addr))
3697 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3698 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3699 mode = GET_MODE_WIDER_MODE (mode))
3700 if (! memory_address_p (mode, addr))
3704 /* Put back the address now that we have updated it and we either know
3705 it is valid or we don't care whether it is valid. */
3710 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3711 is a virtual register, return the equivalent hard register and set the
3712 offset indirectly through the pointer. Otherwise, return 0. */
3715 instantiate_new_reg (x, poffset)
3717 HOST_WIDE_INT *poffset;
3720 HOST_WIDE_INT offset;
3722 if (x == virtual_incoming_args_rtx)
3723 new = arg_pointer_rtx, offset = in_arg_offset;
3724 else if (x == virtual_stack_vars_rtx)
3725 new = frame_pointer_rtx, offset = var_offset;
3726 else if (x == virtual_stack_dynamic_rtx)
3727 new = stack_pointer_rtx, offset = dynamic_offset;
3728 else if (x == virtual_outgoing_args_rtx)
3729 new = stack_pointer_rtx, offset = out_arg_offset;
3730 else if (x == virtual_cfa_rtx)
3731 new = arg_pointer_rtx, offset = cfa_offset;
3739 /* Given a pointer to a piece of rtx and an optional pointer to the
3740 containing object, instantiate any virtual registers present in it.
3742 If EXTRA_INSNS, we always do the replacement and generate
3743 any extra insns before OBJECT. If it zero, we do nothing if replacement
3746 Return 1 if we either had nothing to do or if we were able to do the
3747 needed replacement. Return 0 otherwise; we only return zero if
3748 EXTRA_INSNS is zero.
3750 We first try some simple transformations to avoid the creation of extra
3754 instantiate_virtual_regs_1 (loc, object, extra_insns)
3762 HOST_WIDE_INT offset = 0;
3768 /* Re-start here to avoid recursion in common cases. */
3775 code = GET_CODE (x);
3777 /* Check for some special cases. */
3795 /* We are allowed to set the virtual registers. This means that
3796 the actual register should receive the source minus the
3797 appropriate offset. This is used, for example, in the handling
3798 of non-local gotos. */
3799 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0)
3801 rtx src = SET_SRC (x);
3803 /* We are setting the register, not using it, so the relevant
3804 offset is the negative of the offset to use were we using
3807 instantiate_virtual_regs_1 (&src, NULL_RTX, 0);
3809 /* The only valid sources here are PLUS or REG. Just do
3810 the simplest possible thing to handle them. */
3811 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS)
3815 if (GET_CODE (src) != REG)
3816 temp = force_operand (src, NULL_RTX);
3819 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3823 emit_insn_before (seq, object);
3826 if (! validate_change (object, &SET_SRC (x), temp, 0)
3833 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3838 /* Handle special case of virtual register plus constant. */
3839 if (CONSTANT_P (XEXP (x, 1)))
3841 rtx old, new_offset;
3843 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3844 if (GET_CODE (XEXP (x, 0)) == PLUS)
3846 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset)))
3848 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3850 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3859 #ifdef POINTERS_EXTEND_UNSIGNED
3860 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3861 we can commute the PLUS and SUBREG because pointers into the
3862 frame are well-behaved. */
3863 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode
3864 && GET_CODE (XEXP (x, 1)) == CONST_INT
3866 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)),
3868 && validate_change (object, loc,
3869 plus_constant (gen_lowpart (ptr_mode,
3872 + INTVAL (XEXP (x, 1))),
3876 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0)
3878 /* We know the second operand is a constant. Unless the
3879 first operand is a REG (which has been already checked),
3880 it needs to be checked. */
3881 if (GET_CODE (XEXP (x, 0)) != REG)
3889 new_offset = plus_constant (XEXP (x, 1), offset);
3891 /* If the new constant is zero, try to replace the sum with just
3893 if (new_offset == const0_rtx
3894 && validate_change (object, loc, new, 0))
3897 /* Next try to replace the register and new offset.
3898 There are two changes to validate here and we can't assume that
3899 in the case of old offset equals new just changing the register
3900 will yield a valid insn. In the interests of a little efficiency,
3901 however, we only call validate change once (we don't queue up the
3902 changes and then call apply_change_group). */
3906 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3907 : (XEXP (x, 0) = new,
3908 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3916 /* Otherwise copy the new constant into a register and replace
3917 constant with that register. */
3918 temp = gen_reg_rtx (Pmode);
3920 if (validate_change (object, &XEXP (x, 1), temp, 0))
3921 emit_insn_before (gen_move_insn (temp, new_offset), object);
3924 /* If that didn't work, replace this expression with a
3925 register containing the sum. */
3928 new = gen_rtx_PLUS (Pmode, new, new_offset);
3931 temp = force_operand (new, NULL_RTX);
3935 emit_insn_before (seq, object);
3936 if (! validate_change (object, loc, temp, 0)
3937 && ! validate_replace_rtx (x, temp, object))
3945 /* Fall through to generic two-operand expression case. */
3951 case DIV: case UDIV:
3952 case MOD: case UMOD:
3953 case AND: case IOR: case XOR:
3954 case ROTATERT: case ROTATE:
3955 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3957 case GE: case GT: case GEU: case GTU:
3958 case LE: case LT: case LEU: case LTU:
3959 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3960 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
3965 /* Most cases of MEM that convert to valid addresses have already been
3966 handled by our scan of decls. The only special handling we
3967 need here is to make a copy of the rtx to ensure it isn't being
3968 shared if we have to change it to a pseudo.
3970 If the rtx is a simple reference to an address via a virtual register,
3971 it can potentially be shared. In such cases, first try to make it
3972 a valid address, which can also be shared. Otherwise, copy it and
3975 First check for common cases that need no processing. These are
3976 usually due to instantiation already being done on a previous instance
3980 if (CONSTANT_ADDRESS_P (temp)
3981 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3982 || temp == arg_pointer_rtx
3984 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3985 || temp == hard_frame_pointer_rtx
3987 || temp == frame_pointer_rtx)
3990 if (GET_CODE (temp) == PLUS
3991 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
3992 && (XEXP (temp, 0) == frame_pointer_rtx
3993 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3994 || XEXP (temp, 0) == hard_frame_pointer_rtx
3996 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3997 || XEXP (temp, 0) == arg_pointer_rtx
4002 if (temp == virtual_stack_vars_rtx
4003 || temp == virtual_incoming_args_rtx
4004 || (GET_CODE (temp) == PLUS
4005 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4006 && (XEXP (temp, 0) == virtual_stack_vars_rtx
4007 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
4009 /* This MEM may be shared. If the substitution can be done without
4010 the need to generate new pseudos, we want to do it in place
4011 so all copies of the shared rtx benefit. The call below will
4012 only make substitutions if the resulting address is still
4015 Note that we cannot pass X as the object in the recursive call
4016 since the insn being processed may not allow all valid
4017 addresses. However, if we were not passed on object, we can
4018 only modify X without copying it if X will have a valid
4021 ??? Also note that this can still lose if OBJECT is an insn that
4022 has less restrictions on an address that some other insn.
4023 In that case, we will modify the shared address. This case
4024 doesn't seem very likely, though. One case where this could
4025 happen is in the case of a USE or CLOBBER reference, but we
4026 take care of that below. */
4028 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
4029 object ? object : x, 0))
4032 /* Otherwise make a copy and process that copy. We copy the entire
4033 RTL expression since it might be a PLUS which could also be
4035 *loc = x = copy_rtx (x);
4038 /* Fall through to generic unary operation case. */
4041 case STRICT_LOW_PART:
4043 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
4044 case SIGN_EXTEND: case ZERO_EXTEND:
4045 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
4046 case FLOAT: case FIX:
4047 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
4051 /* These case either have just one operand or we know that we need not
4052 check the rest of the operands. */
4058 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4059 go ahead and make the invalid one, but do it to a copy. For a REG,
4060 just make the recursive call, since there's no chance of a problem. */
4062 if ((GET_CODE (XEXP (x, 0)) == MEM
4063 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
4065 || (GET_CODE (XEXP (x, 0)) == REG
4066 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4069 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
4074 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4075 in front of this insn and substitute the temporary. */
4076 if ((new = instantiate_new_reg (x, &offset)) != 0)
4078 temp = plus_constant (new, offset);
4079 if (!validate_change (object, loc, temp, 0))
4085 temp = force_operand (temp, NULL_RTX);
4089 emit_insn_before (seq, object);
4090 if (! validate_change (object, loc, temp, 0)
4091 && ! validate_replace_rtx (x, temp, object))
4099 if (GET_CODE (XEXP (x, 0)) == REG)
4102 else if (GET_CODE (XEXP (x, 0)) == MEM)
4104 /* If we have a (addressof (mem ..)), do any instantiation inside
4105 since we know we'll be making the inside valid when we finally
4106 remove the ADDRESSOF. */
4107 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4116 /* Scan all subexpressions. */
4117 fmt = GET_RTX_FORMAT (code);
4118 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4121 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4124 else if (*fmt == 'E')
4125 for (j = 0; j < XVECLEN (x, i); j++)
4126 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4133 /* Optimization: assuming this function does not receive nonlocal gotos,
4134 delete the handlers for such, as well as the insns to establish
4135 and disestablish them. */
4141 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4143 /* Delete the handler by turning off the flag that would
4144 prevent jump_optimize from deleting it.
4145 Also permit deletion of the nonlocal labels themselves
4146 if nothing local refers to them. */
4147 if (GET_CODE (insn) == CODE_LABEL)
4151 LABEL_PRESERVE_P (insn) = 0;
4153 /* Remove it from the nonlocal_label list, to avoid confusing
4155 for (t = nonlocal_labels, last_t = 0; t;
4156 last_t = t, t = TREE_CHAIN (t))
4157 if (DECL_RTL (TREE_VALUE (t)) == insn)
4162 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4164 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4167 if (GET_CODE (insn) == INSN)
4171 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4172 if (reg_mentioned_p (t, PATTERN (insn)))
4178 || (nonlocal_goto_stack_level != 0
4179 && reg_mentioned_p (nonlocal_goto_stack_level,
4181 delete_related_insns (insn);
4189 return max_parm_reg;
4192 /* Return the first insn following those generated by `assign_parms'. */
4195 get_first_nonparm_insn ()
4198 return NEXT_INSN (last_parm_insn);
4199 return get_insns ();
4202 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4203 Crash if there is none. */
4206 get_first_block_beg ()
4209 rtx insn = get_first_nonparm_insn ();
4211 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
4212 if (GET_CODE (searcher) == NOTE
4213 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
4216 abort (); /* Invalid call to this function. (See comments above.) */
4220 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4221 This means a type for which function calls must pass an address to the
4222 function or get an address back from the function.
4223 EXP may be a type node or an expression (whose type is tested). */
4226 aggregate_value_p (exp)
4229 int i, regno, nregs;
4232 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
4234 if (TREE_CODE (type) == VOID_TYPE)
4236 if (RETURN_IN_MEMORY (type))
4238 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4239 and thus can't be returned in registers. */
4240 if (TREE_ADDRESSABLE (type))
4242 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4244 /* Make sure we have suitable call-clobbered regs to return
4245 the value in; if not, we must return it in memory. */
4246 reg = hard_function_value (type, 0, 0);
4248 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4250 if (GET_CODE (reg) != REG)
4253 regno = REGNO (reg);
4254 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4255 for (i = 0; i < nregs; i++)
4256 if (! call_used_regs[regno + i])
4261 /* Assign RTL expressions to the function's parameters.
4262 This may involve copying them into registers and using
4263 those registers as the RTL for them. */
4266 assign_parms (fndecl)
4272 CUMULATIVE_ARGS args_so_far;
4273 enum machine_mode promoted_mode, passed_mode;
4274 enum machine_mode nominal_mode, promoted_nominal_mode;
4276 /* Total space needed so far for args on the stack,
4277 given as a constant and a tree-expression. */
4278 struct args_size stack_args_size;
4279 tree fntype = TREE_TYPE (fndecl);
4280 tree fnargs = DECL_ARGUMENTS (fndecl);
4281 /* This is used for the arg pointer when referring to stack args. */
4282 rtx internal_arg_pointer;
4283 /* This is a dummy PARM_DECL that we used for the function result if
4284 the function returns a structure. */
4285 tree function_result_decl = 0;
4286 #ifdef SETUP_INCOMING_VARARGS
4287 int varargs_setup = 0;
4289 rtx conversion_insns = 0;
4290 struct args_size alignment_pad;
4292 /* Nonzero if function takes extra anonymous args.
4293 This means the last named arg must be on the stack
4294 right before the anonymous ones. */
4296 = (TYPE_ARG_TYPES (fntype) != 0
4297 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4298 != void_type_node));
4300 current_function_stdarg = stdarg;
4302 /* If the reg that the virtual arg pointer will be translated into is
4303 not a fixed reg or is the stack pointer, make a copy of the virtual
4304 arg pointer, and address parms via the copy. The frame pointer is
4305 considered fixed even though it is not marked as such.
4307 The second time through, simply use ap to avoid generating rtx. */
4309 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4310 || ! (fixed_regs[ARG_POINTER_REGNUM]
4311 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
4312 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4314 internal_arg_pointer = virtual_incoming_args_rtx;
4315 current_function_internal_arg_pointer = internal_arg_pointer;
4317 stack_args_size.constant = 0;
4318 stack_args_size.var = 0;
4320 /* If struct value address is treated as the first argument, make it so. */
4321 if (aggregate_value_p (DECL_RESULT (fndecl))
4322 && ! current_function_returns_pcc_struct
4323 && struct_value_incoming_rtx == 0)
4325 tree type = build_pointer_type (TREE_TYPE (fntype));
4327 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4329 DECL_ARG_TYPE (function_result_decl) = type;
4330 TREE_CHAIN (function_result_decl) = fnargs;
4331 fnargs = function_result_decl;
4334 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4335 parm_reg_stack_loc = (rtx *) ggc_alloc_cleared (max_parm_reg * sizeof (rtx));
4337 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4338 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4340 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
4343 /* We haven't yet found an argument that we must push and pretend the
4345 current_function_pretend_args_size = 0;
4347 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4349 struct args_size stack_offset;
4350 struct args_size arg_size;
4351 int passed_pointer = 0;
4352 int did_conversion = 0;
4353 tree passed_type = DECL_ARG_TYPE (parm);
4354 tree nominal_type = TREE_TYPE (parm);
4356 int last_named = 0, named_arg;
4358 /* Set LAST_NAMED if this is last named arg before last
4364 for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem))
4365 if (DECL_NAME (tem))
4371 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4372 most machines, if this is a varargs/stdarg function, then we treat
4373 the last named arg as if it were anonymous too. */
4374 named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4376 if (TREE_TYPE (parm) == error_mark_node
4377 /* This can happen after weird syntax errors
4378 or if an enum type is defined among the parms. */
4379 || TREE_CODE (parm) != PARM_DECL
4380 || passed_type == NULL)
4382 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx));
4383 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4384 TREE_USED (parm) = 1;
4388 /* Find mode of arg as it is passed, and mode of arg
4389 as it should be during execution of this function. */
4390 passed_mode = TYPE_MODE (passed_type);
4391 nominal_mode = TYPE_MODE (nominal_type);
4393 /* If the parm's mode is VOID, its value doesn't matter,
4394 and avoid the usual things like emit_move_insn that could crash. */
4395 if (nominal_mode == VOIDmode)
4397 SET_DECL_RTL (parm, const0_rtx);
4398 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4402 /* If the parm is to be passed as a transparent union, use the
4403 type of the first field for the tests below. We have already
4404 verified that the modes are the same. */
4405 if (DECL_TRANSPARENT_UNION (parm)
4406 || (TREE_CODE (passed_type) == UNION_TYPE
4407 && TYPE_TRANSPARENT_UNION (passed_type)))
4408 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4410 /* See if this arg was passed by invisible reference. It is if
4411 it is an object whose size depends on the contents of the
4412 object itself or if the machine requires these objects be passed
4415 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4416 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4417 || TREE_ADDRESSABLE (passed_type)
4418 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4419 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4420 passed_type, named_arg)
4424 passed_type = nominal_type = build_pointer_type (passed_type);
4426 passed_mode = nominal_mode = Pmode;
4429 promoted_mode = passed_mode;
4431 #ifdef PROMOTE_FUNCTION_ARGS
4432 /* Compute the mode in which the arg is actually extended to. */
4433 unsignedp = TREE_UNSIGNED (passed_type);
4434 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4437 /* Let machine desc say which reg (if any) the parm arrives in.
4438 0 means it arrives on the stack. */
4439 #ifdef FUNCTION_INCOMING_ARG
4440 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4441 passed_type, named_arg);
4443 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4444 passed_type, named_arg);
4447 if (entry_parm == 0)
4448 promoted_mode = passed_mode;
4450 #ifdef SETUP_INCOMING_VARARGS
4451 /* If this is the last named parameter, do any required setup for
4452 varargs or stdargs. We need to know about the case of this being an
4453 addressable type, in which case we skip the registers it
4454 would have arrived in.
4456 For stdargs, LAST_NAMED will be set for two parameters, the one that
4457 is actually the last named, and the dummy parameter. We only
4458 want to do this action once.
4460 Also, indicate when RTL generation is to be suppressed. */
4461 if (last_named && !varargs_setup)
4463 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4464 current_function_pretend_args_size, 0);
4469 /* Determine parm's home in the stack,
4470 in case it arrives in the stack or we should pretend it did.
4472 Compute the stack position and rtx where the argument arrives
4475 There is one complexity here: If this was a parameter that would
4476 have been passed in registers, but wasn't only because it is
4477 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4478 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4479 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4480 0 as it was the previous time. */
4482 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4483 locate_and_pad_parm (promoted_mode, passed_type,
4484 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4487 #ifdef FUNCTION_INCOMING_ARG
4488 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4490 pretend_named) != 0,
4492 FUNCTION_ARG (args_so_far, promoted_mode,
4494 pretend_named) != 0,
4497 fndecl, &stack_args_size, &stack_offset, &arg_size,
4501 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4503 if (offset_rtx == const0_rtx)
4504 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4506 stack_parm = gen_rtx_MEM (promoted_mode,
4507 gen_rtx_PLUS (Pmode,
4508 internal_arg_pointer,
4511 set_mem_attributes (stack_parm, parm, 1);
4514 /* If this parameter was passed both in registers and in the stack,
4515 use the copy on the stack. */
4516 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4519 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4520 /* If this parm was passed part in regs and part in memory,
4521 pretend it arrived entirely in memory
4522 by pushing the register-part onto the stack.
4524 In the special case of a DImode or DFmode that is split,
4525 we could put it together in a pseudoreg directly,
4526 but for now that's not worth bothering with. */
4530 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4531 passed_type, named_arg);
4535 current_function_pretend_args_size
4536 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4537 / (PARM_BOUNDARY / BITS_PER_UNIT)
4538 * (PARM_BOUNDARY / BITS_PER_UNIT));
4540 /* Handle calls that pass values in multiple non-contiguous
4541 locations. The Irix 6 ABI has examples of this. */
4542 if (GET_CODE (entry_parm) == PARALLEL)
4543 emit_group_store (validize_mem (stack_parm), entry_parm,
4544 int_size_in_bytes (TREE_TYPE (parm)));
4547 move_block_from_reg (REGNO (entry_parm),
4548 validize_mem (stack_parm), nregs,
4549 int_size_in_bytes (TREE_TYPE (parm)));
4551 entry_parm = stack_parm;
4556 /* If we didn't decide this parm came in a register,
4557 by default it came on the stack. */
4558 if (entry_parm == 0)
4559 entry_parm = stack_parm;
4561 /* Record permanently how this parm was passed. */
4562 DECL_INCOMING_RTL (parm) = entry_parm;
4564 /* If there is actually space on the stack for this parm,
4565 count it in stack_args_size; otherwise set stack_parm to 0
4566 to indicate there is no preallocated stack slot for the parm. */
4568 if (entry_parm == stack_parm
4569 || (GET_CODE (entry_parm) == PARALLEL
4570 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4571 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4572 /* On some machines, even if a parm value arrives in a register
4573 there is still an (uninitialized) stack slot allocated for it.
4575 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4576 whether this parameter already has a stack slot allocated,
4577 because an arg block exists only if current_function_args_size
4578 is larger than some threshold, and we haven't calculated that
4579 yet. So, for now, we just assume that stack slots never exist
4581 || REG_PARM_STACK_SPACE (fndecl) > 0
4585 stack_args_size.constant += arg_size.constant;
4587 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4590 /* No stack slot was pushed for this parm. */
4593 /* Update info on where next arg arrives in registers. */
4595 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4596 passed_type, named_arg);
4598 /* If we can't trust the parm stack slot to be aligned enough
4599 for its ultimate type, don't use that slot after entry.
4600 We'll make another stack slot, if we need one. */
4602 unsigned int thisparm_boundary
4603 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4605 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4609 /* If parm was passed in memory, and we need to convert it on entry,
4610 don't store it back in that same slot. */
4612 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4615 /* When an argument is passed in multiple locations, we can't
4616 make use of this information, but we can save some copying if
4617 the whole argument is passed in a single register. */
4618 if (GET_CODE (entry_parm) == PARALLEL
4619 && nominal_mode != BLKmode && passed_mode != BLKmode)
4621 int i, len = XVECLEN (entry_parm, 0);
4623 for (i = 0; i < len; i++)
4624 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
4625 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG
4626 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
4628 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
4630 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
4631 DECL_INCOMING_RTL (parm) = entry_parm;
4636 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4637 in the mode in which it arrives.
4638 STACK_PARM is an RTX for a stack slot where the parameter can live
4639 during the function (in case we want to put it there).
4640 STACK_PARM is 0 if no stack slot was pushed for it.
4642 Now output code if necessary to convert ENTRY_PARM to
4643 the type in which this function declares it,
4644 and store that result in an appropriate place,
4645 which may be a pseudo reg, may be STACK_PARM,
4646 or may be a local stack slot if STACK_PARM is 0.
4648 Set DECL_RTL to that place. */
4650 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4652 /* If a BLKmode arrives in registers, copy it to a stack slot.
4653 Handle calls that pass values in multiple non-contiguous
4654 locations. The Irix 6 ABI has examples of this. */
4655 if (GET_CODE (entry_parm) == REG
4656 || GET_CODE (entry_parm) == PARALLEL)
4659 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4662 /* Note that we will be storing an integral number of words.
4663 So we have to be careful to ensure that we allocate an
4664 integral number of words. We do this below in the
4665 assign_stack_local if space was not allocated in the argument
4666 list. If it was, this will not work if PARM_BOUNDARY is not
4667 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4668 if it becomes a problem. */
4670 if (stack_parm == 0)
4673 = assign_stack_local (GET_MODE (entry_parm),
4675 set_mem_attributes (stack_parm, parm, 1);
4678 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4681 /* Handle calls that pass values in multiple non-contiguous
4682 locations. The Irix 6 ABI has examples of this. */
4683 if (GET_CODE (entry_parm) == PARALLEL)
4684 emit_group_store (validize_mem (stack_parm), entry_parm,
4685 int_size_in_bytes (TREE_TYPE (parm)));
4687 move_block_from_reg (REGNO (entry_parm),
4688 validize_mem (stack_parm),
4689 size_stored / UNITS_PER_WORD,
4690 int_size_in_bytes (TREE_TYPE (parm)));
4692 SET_DECL_RTL (parm, stack_parm);
4694 else if (! ((! optimize
4695 && ! DECL_REGISTER (parm))
4696 || TREE_SIDE_EFFECTS (parm)
4697 /* If -ffloat-store specified, don't put explicit
4698 float variables into registers. */
4699 || (flag_float_store
4700 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4701 /* Always assign pseudo to structure return or item passed
4702 by invisible reference. */
4703 || passed_pointer || parm == function_result_decl)
4705 /* Store the parm in a pseudoregister during the function, but we
4706 may need to do it in a wider mode. */
4709 unsigned int regno, regnoi = 0, regnor = 0;
4711 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4713 promoted_nominal_mode
4714 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4716 parmreg = gen_reg_rtx (promoted_nominal_mode);
4717 mark_user_reg (parmreg);
4719 /* If this was an item that we received a pointer to, set DECL_RTL
4723 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)),
4725 set_mem_attributes (x, parm, 1);
4726 SET_DECL_RTL (parm, x);
4730 SET_DECL_RTL (parm, parmreg);
4731 maybe_set_unchanging (DECL_RTL (parm), parm);
4734 /* Copy the value into the register. */
4735 if (nominal_mode != passed_mode
4736 || promoted_nominal_mode != promoted_mode)
4739 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4740 mode, by the caller. We now have to convert it to
4741 NOMINAL_MODE, if different. However, PARMREG may be in
4742 a different mode than NOMINAL_MODE if it is being stored
4745 If ENTRY_PARM is a hard register, it might be in a register
4746 not valid for operating in its mode (e.g., an odd-numbered
4747 register for a DFmode). In that case, moves are the only
4748 thing valid, so we can't do a convert from there. This
4749 occurs when the calling sequence allow such misaligned
4752 In addition, the conversion may involve a call, which could
4753 clobber parameters which haven't been copied to pseudo
4754 registers yet. Therefore, we must first copy the parm to
4755 a pseudo reg here, and save the conversion until after all
4756 parameters have been moved. */
4758 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4760 emit_move_insn (tempreg, validize_mem (entry_parm));
4762 push_to_sequence (conversion_insns);
4763 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4765 if (GET_CODE (tempreg) == SUBREG
4766 && GET_MODE (tempreg) == nominal_mode
4767 && GET_CODE (SUBREG_REG (tempreg)) == REG
4768 && nominal_mode == passed_mode
4769 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm)
4770 && GET_MODE_SIZE (GET_MODE (tempreg))
4771 < GET_MODE_SIZE (GET_MODE (entry_parm)))
4773 /* The argument is already sign/zero extended, so note it
4775 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
4776 SUBREG_PROMOTED_UNSIGNED_SET (tempreg, unsignedp);
4779 /* TREE_USED gets set erroneously during expand_assignment. */
4780 save_tree_used = TREE_USED (parm);
4781 expand_assignment (parm,
4782 make_tree (nominal_type, tempreg), 0, 0);
4783 TREE_USED (parm) = save_tree_used;
4784 conversion_insns = get_insns ();
4789 emit_move_insn (parmreg, validize_mem (entry_parm));
4791 /* If we were passed a pointer but the actual value
4792 can safely live in a register, put it in one. */
4793 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4794 /* If by-reference argument was promoted, demote it. */
4795 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm))
4797 && ! DECL_REGISTER (parm))
4798 || TREE_SIDE_EFFECTS (parm)
4799 /* If -ffloat-store specified, don't put explicit
4800 float variables into registers. */
4801 || (flag_float_store
4802 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))))
4804 /* We can't use nominal_mode, because it will have been set to
4805 Pmode above. We must use the actual mode of the parm. */
4806 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4807 mark_user_reg (parmreg);
4808 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
4810 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
4811 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm));
4812 push_to_sequence (conversion_insns);
4813 emit_move_insn (tempreg, DECL_RTL (parm));
4815 convert_to_mode (GET_MODE (parmreg),
4818 emit_move_insn (parmreg, DECL_RTL (parm));
4819 conversion_insns = get_insns();
4824 emit_move_insn (parmreg, DECL_RTL (parm));
4825 SET_DECL_RTL (parm, parmreg);
4826 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4830 #ifdef FUNCTION_ARG_CALLEE_COPIES
4831 /* If we are passed an arg by reference and it is our responsibility
4832 to make a copy, do it now.
4833 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4834 original argument, so we must recreate them in the call to
4835 FUNCTION_ARG_CALLEE_COPIES. */
4836 /* ??? Later add code to handle the case that if the argument isn't
4837 modified, don't do the copy. */
4839 else if (passed_pointer
4840 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4841 TYPE_MODE (DECL_ARG_TYPE (parm)),
4842 DECL_ARG_TYPE (parm),
4844 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4847 tree type = DECL_ARG_TYPE (parm);
4849 /* This sequence may involve a library call perhaps clobbering
4850 registers that haven't been copied to pseudos yet. */
4852 push_to_sequence (conversion_insns);
4854 if (!COMPLETE_TYPE_P (type)
4855 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4856 /* This is a variable sized object. */
4857 copy = gen_rtx_MEM (BLKmode,
4858 allocate_dynamic_stack_space
4859 (expr_size (parm), NULL_RTX,
4860 TYPE_ALIGN (type)));
4862 copy = assign_stack_temp (TYPE_MODE (type),
4863 int_size_in_bytes (type), 1);
4864 set_mem_attributes (copy, parm, 1);
4866 store_expr (parm, copy, 0);
4867 emit_move_insn (parmreg, XEXP (copy, 0));
4868 conversion_insns = get_insns ();
4872 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4874 /* In any case, record the parm's desired stack location
4875 in case we later discover it must live in the stack.
4877 If it is a COMPLEX value, store the stack location for both
4880 if (GET_CODE (parmreg) == CONCAT)
4881 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4883 regno = REGNO (parmreg);
4885 if (regno >= max_parm_reg)
4888 int old_max_parm_reg = max_parm_reg;
4890 /* It's slow to expand this one register at a time,
4891 but it's also rare and we need max_parm_reg to be
4892 precisely correct. */
4893 max_parm_reg = regno + 1;
4894 new = (rtx *) ggc_realloc (parm_reg_stack_loc,
4895 max_parm_reg * sizeof (rtx));
4896 memset ((char *) (new + old_max_parm_reg), 0,
4897 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4898 parm_reg_stack_loc = new;
4901 if (GET_CODE (parmreg) == CONCAT)
4903 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4905 regnor = REGNO (gen_realpart (submode, parmreg));
4906 regnoi = REGNO (gen_imagpart (submode, parmreg));
4908 if (stack_parm != 0)
4910 parm_reg_stack_loc[regnor]
4911 = gen_realpart (submode, stack_parm);
4912 parm_reg_stack_loc[regnoi]
4913 = gen_imagpart (submode, stack_parm);
4917 parm_reg_stack_loc[regnor] = 0;
4918 parm_reg_stack_loc[regnoi] = 0;
4922 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4924 /* Mark the register as eliminable if we did no conversion
4925 and it was copied from memory at a fixed offset,
4926 and the arg pointer was not copied to a pseudo-reg.
4927 If the arg pointer is a pseudo reg or the offset formed
4928 an invalid address, such memory-equivalences
4929 as we make here would screw up life analysis for it. */
4930 if (nominal_mode == passed_mode
4933 && GET_CODE (stack_parm) == MEM
4934 && stack_offset.var == 0
4935 && reg_mentioned_p (virtual_incoming_args_rtx,
4936 XEXP (stack_parm, 0)))
4938 rtx linsn = get_last_insn ();
4941 /* Mark complex types separately. */
4942 if (GET_CODE (parmreg) == CONCAT)
4943 /* Scan backwards for the set of the real and
4945 for (sinsn = linsn; sinsn != 0;
4946 sinsn = prev_nonnote_insn (sinsn))
4948 set = single_set (sinsn);
4950 && SET_DEST (set) == regno_reg_rtx [regnoi])
4952 = gen_rtx_EXPR_LIST (REG_EQUIV,
4953 parm_reg_stack_loc[regnoi],
4956 && SET_DEST (set) == regno_reg_rtx [regnor])
4958 = gen_rtx_EXPR_LIST (REG_EQUIV,
4959 parm_reg_stack_loc[regnor],
4962 else if ((set = single_set (linsn)) != 0
4963 && SET_DEST (set) == parmreg)
4965 = gen_rtx_EXPR_LIST (REG_EQUIV,
4966 stack_parm, REG_NOTES (linsn));
4969 /* For pointer data type, suggest pointer register. */
4970 if (POINTER_TYPE_P (TREE_TYPE (parm)))
4971 mark_reg_pointer (parmreg,
4972 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
4974 /* If something wants our address, try to use ADDRESSOF. */
4975 if (TREE_ADDRESSABLE (parm))
4977 /* If we end up putting something into the stack,
4978 fixup_var_refs_insns will need to make a pass over
4979 all the instructions. It looks through the pending
4980 sequences -- but it can't see the ones in the
4981 CONVERSION_INSNS, if they're not on the sequence
4982 stack. So, we go back to that sequence, just so that
4983 the fixups will happen. */
4984 push_to_sequence (conversion_insns);
4985 put_var_into_stack (parm);
4986 conversion_insns = get_insns ();
4992 /* Value must be stored in the stack slot STACK_PARM
4993 during function execution. */
4995 if (promoted_mode != nominal_mode)
4997 /* Conversion is required. */
4998 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
5000 emit_move_insn (tempreg, validize_mem (entry_parm));
5002 push_to_sequence (conversion_insns);
5003 entry_parm = convert_to_mode (nominal_mode, tempreg,
5004 TREE_UNSIGNED (TREE_TYPE (parm)));
5006 /* ??? This may need a big-endian conversion on sparc64. */
5007 stack_parm = adjust_address (stack_parm, nominal_mode, 0);
5009 conversion_insns = get_insns ();
5014 if (entry_parm != stack_parm)
5016 if (stack_parm == 0)
5019 = assign_stack_local (GET_MODE (entry_parm),
5020 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
5021 set_mem_attributes (stack_parm, parm, 1);
5024 if (promoted_mode != nominal_mode)
5026 push_to_sequence (conversion_insns);
5027 emit_move_insn (validize_mem (stack_parm),
5028 validize_mem (entry_parm));
5029 conversion_insns = get_insns ();
5033 emit_move_insn (validize_mem (stack_parm),
5034 validize_mem (entry_parm));
5037 SET_DECL_RTL (parm, stack_parm);
5040 /* If this "parameter" was the place where we are receiving the
5041 function's incoming structure pointer, set up the result. */
5042 if (parm == function_result_decl)
5044 tree result = DECL_RESULT (fndecl);
5045 rtx addr = DECL_RTL (parm);
5048 #ifdef POINTERS_EXTEND_UNSIGNED
5049 if (GET_MODE (addr) != Pmode)
5050 addr = convert_memory_address (Pmode, addr);
5053 x = gen_rtx_MEM (DECL_MODE (result), addr);
5054 set_mem_attributes (x, result, 1);
5055 SET_DECL_RTL (result, x);
5058 if (GET_CODE (DECL_RTL (parm)) == REG)
5059 REGNO_DECL (REGNO (DECL_RTL (parm))) = parm;
5060 else if (GET_CODE (DECL_RTL (parm)) == CONCAT)
5062 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 0))) = parm;
5063 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 1))) = parm;
5068 /* Output all parameter conversion instructions (possibly including calls)
5069 now that all parameters have been copied out of hard registers. */
5070 emit_insn (conversion_insns);
5072 last_parm_insn = get_last_insn ();
5074 current_function_args_size = stack_args_size.constant;
5076 /* Adjust function incoming argument size for alignment and
5079 #ifdef REG_PARM_STACK_SPACE
5080 #ifndef MAYBE_REG_PARM_STACK_SPACE
5081 current_function_args_size = MAX (current_function_args_size,
5082 REG_PARM_STACK_SPACE (fndecl));
5086 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5088 current_function_args_size
5089 = ((current_function_args_size + STACK_BYTES - 1)
5090 / STACK_BYTES) * STACK_BYTES;
5092 #ifdef ARGS_GROW_DOWNWARD
5093 current_function_arg_offset_rtx
5094 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5095 : expand_expr (size_diffop (stack_args_size.var,
5096 size_int (-stack_args_size.constant)),
5097 NULL_RTX, VOIDmode, 0));
5099 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5102 /* See how many bytes, if any, of its args a function should try to pop
5105 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5106 current_function_args_size);
5108 /* For stdarg.h function, save info about
5109 regs and stack space used by the named args. */
5111 current_function_args_info = args_so_far;
5113 /* Set the rtx used for the function return value. Put this in its
5114 own variable so any optimizers that need this information don't have
5115 to include tree.h. Do this here so it gets done when an inlined
5116 function gets output. */
5118 current_function_return_rtx
5119 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
5120 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
5122 /* If scalar return value was computed in a pseudo-reg, or was a named
5123 return value that got dumped to the stack, copy that to the hard
5125 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
5127 tree decl_result = DECL_RESULT (fndecl);
5128 rtx decl_rtl = DECL_RTL (decl_result);
5130 if (REG_P (decl_rtl)
5131 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5132 : DECL_REGISTER (decl_result))
5136 #ifdef FUNCTION_OUTGOING_VALUE
5137 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
5140 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
5143 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
5144 /* The delay slot scheduler assumes that current_function_return_rtx
5145 holds the hard register containing the return value, not a
5146 temporary pseudo. */
5147 current_function_return_rtx = real_decl_rtl;
5152 /* Indicate whether REGNO is an incoming argument to the current function
5153 that was promoted to a wider mode. If so, return the RTX for the
5154 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5155 that REGNO is promoted from and whether the promotion was signed or
5158 #ifdef PROMOTE_FUNCTION_ARGS
5161 promoted_input_arg (regno, pmode, punsignedp)
5163 enum machine_mode *pmode;
5168 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5169 arg = TREE_CHAIN (arg))
5170 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5171 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5172 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5174 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5175 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5177 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5178 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5179 && mode != DECL_MODE (arg))
5181 *pmode = DECL_MODE (arg);
5182 *punsignedp = unsignedp;
5183 return DECL_INCOMING_RTL (arg);
5192 /* Compute the size and offset from the start of the stacked arguments for a
5193 parm passed in mode PASSED_MODE and with type TYPE.
5195 INITIAL_OFFSET_PTR points to the current offset into the stacked
5198 The starting offset and size for this parm are returned in *OFFSET_PTR
5199 and *ARG_SIZE_PTR, respectively.
5201 IN_REGS is non-zero if the argument will be passed in registers. It will
5202 never be set if REG_PARM_STACK_SPACE is not defined.
5204 FNDECL is the function in which the argument was defined.
5206 There are two types of rounding that are done. The first, controlled by
5207 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5208 list to be aligned to the specific boundary (in bits). This rounding
5209 affects the initial and starting offsets, but not the argument size.
5211 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5212 optionally rounds the size of the parm to PARM_BOUNDARY. The
5213 initial offset is not affected by this rounding, while the size always
5214 is and the starting offset may be. */
5216 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5217 initial_offset_ptr is positive because locate_and_pad_parm's
5218 callers pass in the total size of args so far as
5219 initial_offset_ptr. arg_size_ptr is always positive. */
5222 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5223 initial_offset_ptr, offset_ptr, arg_size_ptr,
5225 enum machine_mode passed_mode;
5227 int in_regs ATTRIBUTE_UNUSED;
5228 tree fndecl ATTRIBUTE_UNUSED;
5229 struct args_size *initial_offset_ptr;
5230 struct args_size *offset_ptr;
5231 struct args_size *arg_size_ptr;
5232 struct args_size *alignment_pad;
5236 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5237 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5238 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5240 #ifdef REG_PARM_STACK_SPACE
5241 /* If we have found a stack parm before we reach the end of the
5242 area reserved for registers, skip that area. */
5245 int reg_parm_stack_space = 0;
5247 #ifdef MAYBE_REG_PARM_STACK_SPACE
5248 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5250 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5252 if (reg_parm_stack_space > 0)
5254 if (initial_offset_ptr->var)
5256 initial_offset_ptr->var
5257 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5258 ssize_int (reg_parm_stack_space));
5259 initial_offset_ptr->constant = 0;
5261 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5262 initial_offset_ptr->constant = reg_parm_stack_space;
5265 #endif /* REG_PARM_STACK_SPACE */
5267 arg_size_ptr->var = 0;
5268 arg_size_ptr->constant = 0;
5269 alignment_pad->var = 0;
5270 alignment_pad->constant = 0;
5272 #ifdef ARGS_GROW_DOWNWARD
5273 if (initial_offset_ptr->var)
5275 offset_ptr->constant = 0;
5276 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0),
5277 initial_offset_ptr->var);
5281 offset_ptr->constant = -initial_offset_ptr->constant;
5282 offset_ptr->var = 0;
5284 if (where_pad != none
5285 && (!host_integerp (sizetree, 1)
5286 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5287 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5288 SUB_PARM_SIZE (*offset_ptr, sizetree);
5289 if (where_pad != downward)
5290 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad);
5291 if (initial_offset_ptr->var)
5292 arg_size_ptr->var = size_binop (MINUS_EXPR,
5293 size_binop (MINUS_EXPR,
5295 initial_offset_ptr->var),
5299 arg_size_ptr->constant = (-initial_offset_ptr->constant
5300 - offset_ptr->constant);
5302 #else /* !ARGS_GROW_DOWNWARD */
5304 #ifdef REG_PARM_STACK_SPACE
5305 || REG_PARM_STACK_SPACE (fndecl) > 0
5308 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad);
5309 *offset_ptr = *initial_offset_ptr;
5311 #ifdef PUSH_ROUNDING
5312 if (passed_mode != BLKmode)
5313 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5316 /* Pad_below needs the pre-rounded size to know how much to pad below
5317 so this must be done before rounding up. */
5318 if (where_pad == downward
5319 /* However, BLKmode args passed in regs have their padding done elsewhere.
5320 The stack slot must be able to hold the entire register. */
5321 && !(in_regs && passed_mode == BLKmode))
5322 pad_below (offset_ptr, passed_mode, sizetree);
5324 if (where_pad != none
5325 && (!host_integerp (sizetree, 1)
5326 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5327 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5329 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5330 #endif /* ARGS_GROW_DOWNWARD */
5333 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5334 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5337 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad)
5338 struct args_size *offset_ptr;
5340 struct args_size *alignment_pad;
5342 tree save_var = NULL_TREE;
5343 HOST_WIDE_INT save_constant = 0;
5345 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5347 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5349 save_var = offset_ptr->var;
5350 save_constant = offset_ptr->constant;
5353 alignment_pad->var = NULL_TREE;
5354 alignment_pad->constant = 0;
5356 if (boundary > BITS_PER_UNIT)
5358 if (offset_ptr->var)
5361 #ifdef ARGS_GROW_DOWNWARD
5366 (ARGS_SIZE_TREE (*offset_ptr),
5367 boundary / BITS_PER_UNIT);
5368 offset_ptr->constant = 0; /*?*/
5369 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5370 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
5375 offset_ptr->constant =
5376 #ifdef ARGS_GROW_DOWNWARD
5377 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5379 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5381 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5382 alignment_pad->constant = offset_ptr->constant - save_constant;
5387 #ifndef ARGS_GROW_DOWNWARD
5389 pad_below (offset_ptr, passed_mode, sizetree)
5390 struct args_size *offset_ptr;
5391 enum machine_mode passed_mode;
5394 if (passed_mode != BLKmode)
5396 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5397 offset_ptr->constant
5398 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5399 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5400 - GET_MODE_SIZE (passed_mode));
5404 if (TREE_CODE (sizetree) != INTEGER_CST
5405 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5407 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5408 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5410 ADD_PARM_SIZE (*offset_ptr, s2);
5411 SUB_PARM_SIZE (*offset_ptr, sizetree);
5417 /* Walk the tree of blocks describing the binding levels within a function
5418 and warn about uninitialized variables.
5419 This is done after calling flow_analysis and before global_alloc
5420 clobbers the pseudo-regs to hard regs. */
5423 uninitialized_vars_warning (block)
5427 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5429 if (warn_uninitialized
5430 && TREE_CODE (decl) == VAR_DECL
5431 /* These warnings are unreliable for and aggregates
5432 because assigning the fields one by one can fail to convince
5433 flow.c that the entire aggregate was initialized.
5434 Unions are troublesome because members may be shorter. */
5435 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5436 && DECL_RTL (decl) != 0
5437 && GET_CODE (DECL_RTL (decl)) == REG
5438 /* Global optimizations can make it difficult to determine if a
5439 particular variable has been initialized. However, a VAR_DECL
5440 with a nonzero DECL_INITIAL had an initializer, so do not
5441 claim it is potentially uninitialized.
5443 We do not care about the actual value in DECL_INITIAL, so we do
5444 not worry that it may be a dangling pointer. */
5445 && DECL_INITIAL (decl) == NULL_TREE
5446 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5447 warning_with_decl (decl,
5448 "`%s' might be used uninitialized in this function");
5450 && TREE_CODE (decl) == VAR_DECL
5451 && DECL_RTL (decl) != 0
5452 && GET_CODE (DECL_RTL (decl)) == REG
5453 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5454 warning_with_decl (decl,
5455 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5457 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5458 uninitialized_vars_warning (sub);
5461 /* Do the appropriate part of uninitialized_vars_warning
5462 but for arguments instead of local variables. */
5465 setjmp_args_warning ()
5468 for (decl = DECL_ARGUMENTS (current_function_decl);
5469 decl; decl = TREE_CHAIN (decl))
5470 if (DECL_RTL (decl) != 0
5471 && GET_CODE (DECL_RTL (decl)) == REG
5472 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5473 warning_with_decl (decl,
5474 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5477 /* If this function call setjmp, put all vars into the stack
5478 unless they were declared `register'. */
5481 setjmp_protect (block)
5485 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5486 if ((TREE_CODE (decl) == VAR_DECL
5487 || TREE_CODE (decl) == PARM_DECL)
5488 && DECL_RTL (decl) != 0
5489 && (GET_CODE (DECL_RTL (decl)) == REG
5490 || (GET_CODE (DECL_RTL (decl)) == MEM
5491 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5492 /* If this variable came from an inline function, it must be
5493 that its life doesn't overlap the setjmp. If there was a
5494 setjmp in the function, it would already be in memory. We
5495 must exclude such variable because their DECL_RTL might be
5496 set to strange things such as virtual_stack_vars_rtx. */
5497 && ! DECL_FROM_INLINE (decl)
5499 #ifdef NON_SAVING_SETJMP
5500 /* If longjmp doesn't restore the registers,
5501 don't put anything in them. */
5505 ! DECL_REGISTER (decl)))
5506 put_var_into_stack (decl);
5507 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5508 setjmp_protect (sub);
5511 /* Like the previous function, but for args instead of local variables. */
5514 setjmp_protect_args ()
5517 for (decl = DECL_ARGUMENTS (current_function_decl);
5518 decl; decl = TREE_CHAIN (decl))
5519 if ((TREE_CODE (decl) == VAR_DECL
5520 || TREE_CODE (decl) == PARM_DECL)
5521 && DECL_RTL (decl) != 0
5522 && (GET_CODE (DECL_RTL (decl)) == REG
5523 || (GET_CODE (DECL_RTL (decl)) == MEM
5524 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5526 /* If longjmp doesn't restore the registers,
5527 don't put anything in them. */
5528 #ifdef NON_SAVING_SETJMP
5532 ! DECL_REGISTER (decl)))
5533 put_var_into_stack (decl);
5536 /* Return the context-pointer register corresponding to DECL,
5537 or 0 if it does not need one. */
5540 lookup_static_chain (decl)
5543 tree context = decl_function_context (decl);
5547 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5550 /* We treat inline_function_decl as an alias for the current function
5551 because that is the inline function whose vars, types, etc.
5552 are being merged into the current function.
5553 See expand_inline_function. */
5554 if (context == current_function_decl || context == inline_function_decl)
5555 return virtual_stack_vars_rtx;
5557 for (link = context_display; link; link = TREE_CHAIN (link))
5558 if (TREE_PURPOSE (link) == context)
5559 return RTL_EXPR_RTL (TREE_VALUE (link));
5564 /* Convert a stack slot address ADDR for variable VAR
5565 (from a containing function)
5566 into an address valid in this function (using a static chain). */
5569 fix_lexical_addr (addr, var)
5574 HOST_WIDE_INT displacement;
5575 tree context = decl_function_context (var);
5576 struct function *fp;
5579 /* If this is the present function, we need not do anything. */
5580 if (context == current_function_decl || context == inline_function_decl)
5583 fp = find_function_data (context);
5585 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5586 addr = XEXP (XEXP (addr, 0), 0);
5588 /* Decode given address as base reg plus displacement. */
5589 if (GET_CODE (addr) == REG)
5590 basereg = addr, displacement = 0;
5591 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5592 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5596 /* We accept vars reached via the containing function's
5597 incoming arg pointer and via its stack variables pointer. */
5598 if (basereg == fp->internal_arg_pointer)
5600 /* If reached via arg pointer, get the arg pointer value
5601 out of that function's stack frame.
5603 There are two cases: If a separate ap is needed, allocate a
5604 slot in the outer function for it and dereference it that way.
5605 This is correct even if the real ap is actually a pseudo.
5606 Otherwise, just adjust the offset from the frame pointer to
5609 #ifdef NEED_SEPARATE_AP
5612 addr = get_arg_pointer_save_area (fp);
5613 addr = fix_lexical_addr (XEXP (addr, 0), var);
5614 addr = memory_address (Pmode, addr);
5616 base = gen_rtx_MEM (Pmode, addr);
5617 set_mem_alias_set (base, get_frame_alias_set ());
5618 base = copy_to_reg (base);
5620 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5621 base = lookup_static_chain (var);
5625 else if (basereg == virtual_stack_vars_rtx)
5627 /* This is the same code as lookup_static_chain, duplicated here to
5628 avoid an extra call to decl_function_context. */
5631 for (link = context_display; link; link = TREE_CHAIN (link))
5632 if (TREE_PURPOSE (link) == context)
5634 base = RTL_EXPR_RTL (TREE_VALUE (link));
5642 /* Use same offset, relative to appropriate static chain or argument
5644 return plus_constant (base, displacement);
5647 /* Return the address of the trampoline for entering nested fn FUNCTION.
5648 If necessary, allocate a trampoline (in the stack frame)
5649 and emit rtl to initialize its contents (at entry to this function). */
5652 trampoline_address (function)
5658 struct function *fp;
5661 /* Find an existing trampoline and return it. */
5662 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5663 if (TREE_PURPOSE (link) == function)
5665 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5667 for (fp = outer_function_chain; fp; fp = fp->outer)
5668 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5669 if (TREE_PURPOSE (link) == function)
5671 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5673 return adjust_trampoline_addr (tramp);
5676 /* None exists; we must make one. */
5678 /* Find the `struct function' for the function containing FUNCTION. */
5680 fn_context = decl_function_context (function);
5681 if (fn_context != current_function_decl
5682 && fn_context != inline_function_decl)
5683 fp = find_function_data (fn_context);
5685 /* Allocate run-time space for this trampoline
5686 (usually in the defining function's stack frame). */
5687 #ifdef ALLOCATE_TRAMPOLINE
5688 tramp = ALLOCATE_TRAMPOLINE (fp);
5690 /* If rounding needed, allocate extra space
5691 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5692 #ifdef TRAMPOLINE_ALIGNMENT
5693 #define TRAMPOLINE_REAL_SIZE \
5694 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5696 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5698 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5702 /* Record the trampoline for reuse and note it for later initialization
5703 by expand_function_end. */
5706 rtlexp = make_node (RTL_EXPR);
5707 RTL_EXPR_RTL (rtlexp) = tramp;
5708 fp->x_trampoline_list = tree_cons (function, rtlexp,
5709 fp->x_trampoline_list);
5713 /* Make the RTL_EXPR node temporary, not momentary, so that the
5714 trampoline_list doesn't become garbage. */
5715 rtlexp = make_node (RTL_EXPR);
5717 RTL_EXPR_RTL (rtlexp) = tramp;
5718 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5721 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5722 return adjust_trampoline_addr (tramp);
5725 /* Given a trampoline address,
5726 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5729 round_trampoline_addr (tramp)
5732 #ifdef TRAMPOLINE_ALIGNMENT
5733 /* Round address up to desired boundary. */
5734 rtx temp = gen_reg_rtx (Pmode);
5735 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1);
5736 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
5738 temp = expand_simple_binop (Pmode, PLUS, tramp, addend,
5739 temp, 0, OPTAB_LIB_WIDEN);
5740 tramp = expand_simple_binop (Pmode, AND, temp, mask,
5741 temp, 0, OPTAB_LIB_WIDEN);
5746 /* Given a trampoline address, round it then apply any
5747 platform-specific adjustments so that the result can be used for a
5751 adjust_trampoline_addr (tramp)
5754 tramp = round_trampoline_addr (tramp);
5755 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5756 TRAMPOLINE_ADJUST_ADDRESS (tramp);
5761 /* Put all this function's BLOCK nodes including those that are chained
5762 onto the first block into a vector, and return it.
5763 Also store in each NOTE for the beginning or end of a block
5764 the index of that block in the vector.
5765 The arguments are BLOCK, the chain of top-level blocks of the function,
5766 and INSNS, the insn chain of the function. */
5772 tree *block_vector, *last_block_vector;
5774 tree block = DECL_INITIAL (current_function_decl);
5779 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5780 depth-first order. */
5781 block_vector = get_block_vector (block, &n_blocks);
5782 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree));
5784 last_block_vector = identify_blocks_1 (get_insns (),
5786 block_vector + n_blocks,
5789 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5790 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5791 if (0 && last_block_vector != block_vector + n_blocks)
5794 free (block_vector);
5798 /* Subroutine of identify_blocks. Do the block substitution on the
5799 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5801 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5802 BLOCK_VECTOR is incremented for each block seen. */
5805 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack)
5808 tree *end_block_vector;
5809 tree *orig_block_stack;
5812 tree *block_stack = orig_block_stack;
5814 for (insn = insns; insn; insn = NEXT_INSN (insn))
5816 if (GET_CODE (insn) == NOTE)
5818 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5822 /* If there are more block notes than BLOCKs, something
5824 if (block_vector == end_block_vector)
5827 b = *block_vector++;
5828 NOTE_BLOCK (insn) = b;
5831 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5833 /* If there are more NOTE_INSN_BLOCK_ENDs than
5834 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5835 if (block_stack == orig_block_stack)
5838 NOTE_BLOCK (insn) = *--block_stack;
5841 else if (GET_CODE (insn) == CALL_INSN
5842 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5844 rtx cp = PATTERN (insn);
5846 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector,
5847 end_block_vector, block_stack);
5849 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector,
5850 end_block_vector, block_stack);
5852 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector,
5853 end_block_vector, block_stack);
5857 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5858 something is badly wrong. */
5859 if (block_stack != orig_block_stack)
5862 return block_vector;
5865 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5866 and create duplicate blocks. */
5867 /* ??? Need an option to either create block fragments or to create
5868 abstract origin duplicates of a source block. It really depends
5869 on what optimization has been performed. */
5874 tree block = DECL_INITIAL (current_function_decl);
5875 varray_type block_stack;
5877 if (block == NULL_TREE)
5880 VARRAY_TREE_INIT (block_stack, 10, "block_stack");
5882 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5883 reorder_blocks_0 (block);
5885 /* Prune the old trees away, so that they don't get in the way. */
5886 BLOCK_SUBBLOCKS (block) = NULL_TREE;
5887 BLOCK_CHAIN (block) = NULL_TREE;
5889 /* Recreate the block tree from the note nesting. */
5890 reorder_blocks_1 (get_insns (), block, &block_stack);
5891 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
5893 /* Remove deleted blocks from the block fragment chains. */
5894 reorder_fix_fragments (block);
5897 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5900 reorder_blocks_0 (block)
5905 TREE_ASM_WRITTEN (block) = 0;
5906 reorder_blocks_0 (BLOCK_SUBBLOCKS (block));
5907 block = BLOCK_CHAIN (block);
5912 reorder_blocks_1 (insns, current_block, p_block_stack)
5915 varray_type *p_block_stack;
5919 for (insn = insns; insn; insn = NEXT_INSN (insn))
5921 if (GET_CODE (insn) == NOTE)
5923 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5925 tree block = NOTE_BLOCK (insn);
5927 /* If we have seen this block before, that means it now
5928 spans multiple address regions. Create a new fragment. */
5929 if (TREE_ASM_WRITTEN (block))
5931 tree new_block = copy_node (block);
5934 origin = (BLOCK_FRAGMENT_ORIGIN (block)
5935 ? BLOCK_FRAGMENT_ORIGIN (block)
5937 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
5938 BLOCK_FRAGMENT_CHAIN (new_block)
5939 = BLOCK_FRAGMENT_CHAIN (origin);
5940 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
5942 NOTE_BLOCK (insn) = new_block;
5946 BLOCK_SUBBLOCKS (block) = 0;
5947 TREE_ASM_WRITTEN (block) = 1;
5948 BLOCK_SUPERCONTEXT (block) = current_block;
5949 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
5950 BLOCK_SUBBLOCKS (current_block) = block;
5951 current_block = block;
5952 VARRAY_PUSH_TREE (*p_block_stack, block);
5954 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5956 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack);
5957 VARRAY_POP (*p_block_stack);
5958 BLOCK_SUBBLOCKS (current_block)
5959 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
5960 current_block = BLOCK_SUPERCONTEXT (current_block);
5963 else if (GET_CODE (insn) == CALL_INSN
5964 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5966 rtx cp = PATTERN (insn);
5967 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack);
5969 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack);
5971 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
5976 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
5977 appears in the block tree, select one of the fragments to become
5978 the new origin block. */
5981 reorder_fix_fragments (block)
5986 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
5987 tree new_origin = NULL_TREE;
5991 if (! TREE_ASM_WRITTEN (dup_origin))
5993 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
5995 /* Find the first of the remaining fragments. There must
5996 be at least one -- the current block. */
5997 while (! TREE_ASM_WRITTEN (new_origin))
5998 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
5999 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
6002 else if (! dup_origin)
6005 /* Re-root the rest of the fragments to the new origin. In the
6006 case that DUP_ORIGIN was null, that means BLOCK was the origin
6007 of a chain of fragments and we want to remove those fragments
6008 that didn't make it to the output. */
6011 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
6016 if (TREE_ASM_WRITTEN (chain))
6018 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
6020 pp = &BLOCK_FRAGMENT_CHAIN (chain);
6022 chain = BLOCK_FRAGMENT_CHAIN (chain);
6027 reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
6028 block = BLOCK_CHAIN (block);
6032 /* Reverse the order of elements in the chain T of blocks,
6033 and return the new head of the chain (old last element). */
6039 tree prev = 0, decl, next;
6040 for (decl = t; decl; decl = next)
6042 next = BLOCK_CHAIN (decl);
6043 BLOCK_CHAIN (decl) = prev;
6049 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6050 non-NULL, list them all into VECTOR, in a depth-first preorder
6051 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6055 all_blocks (block, vector)
6063 TREE_ASM_WRITTEN (block) = 0;
6065 /* Record this block. */
6067 vector[n_blocks] = block;
6071 /* Record the subblocks, and their subblocks... */
6072 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
6073 vector ? vector + n_blocks : 0);
6074 block = BLOCK_CHAIN (block);
6080 /* Return a vector containing all the blocks rooted at BLOCK. The
6081 number of elements in the vector is stored in N_BLOCKS_P. The
6082 vector is dynamically allocated; it is the caller's responsibility
6083 to call `free' on the pointer returned. */
6086 get_block_vector (block, n_blocks_p)
6092 *n_blocks_p = all_blocks (block, NULL);
6093 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree));
6094 all_blocks (block, block_vector);
6096 return block_vector;
6099 static int next_block_index = 2;
6101 /* Set BLOCK_NUMBER for all the blocks in FN. */
6111 /* For SDB and XCOFF debugging output, we start numbering the blocks
6112 from 1 within each function, rather than keeping a running
6114 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6115 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
6116 next_block_index = 1;
6119 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
6121 /* The top-level BLOCK isn't numbered at all. */
6122 for (i = 1; i < n_blocks; ++i)
6123 /* We number the blocks from two. */
6124 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
6126 free (block_vector);
6131 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6134 debug_find_var_in_block_tree (var, block)
6140 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
6144 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
6146 tree ret = debug_find_var_in_block_tree (var, t);
6154 /* Allocate a function structure and reset its contents to the defaults. */
6157 prepare_function_start ()
6159 cfun = (struct function *) ggc_alloc_cleared (sizeof (struct function));
6161 init_stmt_for_function ();
6162 init_eh_for_function ();
6164 cse_not_expected = ! optimize;
6166 /* Caller save not needed yet. */
6167 caller_save_needed = 0;
6169 /* No stack slots have been made yet. */
6170 stack_slot_list = 0;
6172 current_function_has_nonlocal_label = 0;
6173 current_function_has_nonlocal_goto = 0;
6175 /* There is no stack slot for handling nonlocal gotos. */
6176 nonlocal_goto_handler_slots = 0;
6177 nonlocal_goto_stack_level = 0;
6179 /* No labels have been declared for nonlocal use. */
6180 nonlocal_labels = 0;
6181 nonlocal_goto_handler_labels = 0;
6183 /* No function calls so far in this function. */
6184 function_call_count = 0;
6186 /* No parm regs have been allocated.
6187 (This is important for output_inline_function.) */
6188 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
6190 /* Initialize the RTL mechanism. */
6193 /* Initialize the queue of pending postincrement and postdecrements,
6194 and some other info in expr.c. */
6197 /* We haven't done register allocation yet. */
6200 init_varasm_status (cfun);
6202 /* Clear out data used for inlining. */
6203 cfun->inlinable = 0;
6204 cfun->original_decl_initial = 0;
6205 cfun->original_arg_vector = 0;
6207 cfun->stack_alignment_needed = STACK_BOUNDARY;
6208 cfun->preferred_stack_boundary = STACK_BOUNDARY;
6210 /* Set if a call to setjmp is seen. */
6211 current_function_calls_setjmp = 0;
6213 /* Set if a call to longjmp is seen. */
6214 current_function_calls_longjmp = 0;
6216 current_function_calls_alloca = 0;
6217 current_function_contains_functions = 0;
6218 current_function_is_leaf = 0;
6219 current_function_nothrow = 0;
6220 current_function_sp_is_unchanging = 0;
6221 current_function_uses_only_leaf_regs = 0;
6222 current_function_has_computed_jump = 0;
6223 current_function_is_thunk = 0;
6225 current_function_returns_pcc_struct = 0;
6226 current_function_returns_struct = 0;
6227 current_function_epilogue_delay_list = 0;
6228 current_function_uses_const_pool = 0;
6229 current_function_uses_pic_offset_table = 0;
6230 current_function_cannot_inline = 0;
6232 /* We have not yet needed to make a label to jump to for tail-recursion. */
6233 tail_recursion_label = 0;
6235 /* We haven't had a need to make a save area for ap yet. */
6236 arg_pointer_save_area = 0;
6238 /* No stack slots allocated yet. */
6241 /* No SAVE_EXPRs in this function yet. */
6244 /* No RTL_EXPRs in this function yet. */
6247 /* Set up to allocate temporaries. */
6250 /* Indicate that we need to distinguish between the return value of the
6251 present function and the return value of a function being called. */
6252 rtx_equal_function_value_matters = 1;
6254 /* Indicate that we have not instantiated virtual registers yet. */
6255 virtuals_instantiated = 0;
6257 /* Indicate that we want CONCATs now. */
6258 generating_concat_p = 1;
6260 /* Indicate we have no need of a frame pointer yet. */
6261 frame_pointer_needed = 0;
6263 /* By default assume not stdarg. */
6264 current_function_stdarg = 0;
6266 /* We haven't made any trampolines for this function yet. */
6267 trampoline_list = 0;
6269 init_pending_stack_adjust ();
6270 inhibit_defer_pop = 0;
6272 current_function_outgoing_args_size = 0;
6274 current_function_funcdef_no = funcdef_no++;
6276 cfun->arc_profile = profile_arc_flag || flag_test_coverage;
6278 cfun->arc_profile = profile_arc_flag || flag_test_coverage;
6280 cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
6282 (*lang_hooks.function.init) (cfun);
6283 if (init_machine_status)
6284 cfun->machine = (*init_machine_status) ();
6287 /* Initialize the rtl expansion mechanism so that we can do simple things
6288 like generate sequences. This is used to provide a context during global
6289 initialization of some passes. */
6291 init_dummy_function_start ()
6293 prepare_function_start ();
6296 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6297 and initialize static variables for generating RTL for the statements
6301 init_function_start (subr, filename, line)
6303 const char *filename;
6306 prepare_function_start ();
6308 current_function_name = (*lang_hooks.decl_printable_name) (subr, 2);
6311 /* Nonzero if this is a nested function that uses a static chain. */
6313 current_function_needs_context
6314 = (decl_function_context (current_function_decl) != 0
6315 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6317 /* Within function body, compute a type's size as soon it is laid out. */
6318 immediate_size_expand++;
6320 /* Prevent ever trying to delete the first instruction of a function.
6321 Also tell final how to output a linenum before the function prologue.
6322 Note linenums could be missing, e.g. when compiling a Java .class file. */
6324 emit_line_note (filename, line);
6326 /* Make sure first insn is a note even if we don't want linenums.
6327 This makes sure the first insn will never be deleted.
6328 Also, final expects a note to appear there. */
6329 emit_note (NULL, NOTE_INSN_DELETED);
6331 /* Set flags used by final.c. */
6332 if (aggregate_value_p (DECL_RESULT (subr)))
6334 #ifdef PCC_STATIC_STRUCT_RETURN
6335 current_function_returns_pcc_struct = 1;
6337 current_function_returns_struct = 1;
6340 /* Warn if this value is an aggregate type,
6341 regardless of which calling convention we are using for it. */
6342 if (warn_aggregate_return
6343 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6344 warning ("function returns an aggregate");
6346 current_function_returns_pointer
6347 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6350 /* Make sure all values used by the optimization passes have sane
6353 init_function_for_compilation ()
6357 /* No prologue/epilogue insns yet. */
6358 VARRAY_GROW (prologue, 0);
6359 VARRAY_GROW (epilogue, 0);
6360 VARRAY_GROW (sibcall_epilogue, 0);
6363 /* Expand a call to __main at the beginning of a possible main function. */
6365 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6366 #undef HAS_INIT_SECTION
6367 #define HAS_INIT_SECTION
6371 expand_main_function ()
6373 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6374 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
6376 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
6380 /* Forcibly align the stack. */
6381 #ifdef STACK_GROWS_DOWNWARD
6382 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
6383 stack_pointer_rtx, 1, OPTAB_WIDEN);
6385 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
6386 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN);
6387 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align),
6388 stack_pointer_rtx, 1, OPTAB_WIDEN);
6390 if (tmp != stack_pointer_rtx)
6391 emit_move_insn (stack_pointer_rtx, tmp);
6393 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6394 tmp = force_reg (Pmode, const0_rtx);
6395 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
6399 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp))
6400 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG)
6403 emit_insn_before (seq, tmp);
6409 #ifndef HAS_INIT_SECTION
6410 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), LCT_NORMAL,
6415 extern struct obstack permanent_obstack;
6417 /* The PENDING_SIZES represent the sizes of variable-sized types.
6418 Create RTL for the various sizes now (using temporary variables),
6419 so that we can refer to the sizes from the RTL we are generating
6420 for the current function. The PENDING_SIZES are a TREE_LIST. The
6421 TREE_VALUE of each node is a SAVE_EXPR. */
6424 expand_pending_sizes (pending_sizes)
6429 /* Evaluate now the sizes of any types declared among the arguments. */
6430 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem))
6432 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
6433 /* Flush the queue in case this parameter declaration has
6439 /* Start the RTL for a new function, and set variables used for
6441 SUBR is the FUNCTION_DECL node.
6442 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6443 the function's parameters, which must be run at any return statement. */
6446 expand_function_start (subr, parms_have_cleanups)
6448 int parms_have_cleanups;
6451 rtx last_ptr = NULL_RTX;
6453 /* Make sure volatile mem refs aren't considered
6454 valid operands of arithmetic insns. */
6455 init_recog_no_volatile ();
6457 current_function_instrument_entry_exit
6458 = (flag_instrument_function_entry_exit
6459 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6461 current_function_profile
6463 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6465 current_function_limit_stack
6466 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
6468 /* If function gets a static chain arg, store it in the stack frame.
6469 Do this first, so it gets the first stack slot offset. */
6470 if (current_function_needs_context)
6472 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6474 /* Delay copying static chain if it is not a register to avoid
6475 conflicts with regs used for parameters. */
6476 if (! SMALL_REGISTER_CLASSES
6477 || GET_CODE (static_chain_incoming_rtx) == REG)
6478 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6481 /* If the parameters of this function need cleaning up, get a label
6482 for the beginning of the code which executes those cleanups. This must
6483 be done before doing anything with return_label. */
6484 if (parms_have_cleanups)
6485 cleanup_label = gen_label_rtx ();
6489 /* Make the label for return statements to jump to. Do not special
6490 case machines with special return instructions -- they will be
6491 handled later during jump, ifcvt, or epilogue creation. */
6492 return_label = gen_label_rtx ();
6494 /* Initialize rtx used to return the value. */
6495 /* Do this before assign_parms so that we copy the struct value address
6496 before any library calls that assign parms might generate. */
6498 /* Decide whether to return the value in memory or in a register. */
6499 if (aggregate_value_p (DECL_RESULT (subr)))
6501 /* Returning something that won't go in a register. */
6502 rtx value_address = 0;
6504 #ifdef PCC_STATIC_STRUCT_RETURN
6505 if (current_function_returns_pcc_struct)
6507 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6508 value_address = assemble_static_space (size);
6513 /* Expect to be passed the address of a place to store the value.
6514 If it is passed as an argument, assign_parms will take care of
6516 if (struct_value_incoming_rtx)
6518 value_address = gen_reg_rtx (Pmode);
6519 emit_move_insn (value_address, struct_value_incoming_rtx);
6524 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6525 set_mem_attributes (x, DECL_RESULT (subr), 1);
6526 SET_DECL_RTL (DECL_RESULT (subr), x);
6529 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6530 /* If return mode is void, this decl rtl should not be used. */
6531 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
6534 /* Compute the return values into a pseudo reg, which we will copy
6535 into the true return register after the cleanups are done. */
6537 /* In order to figure out what mode to use for the pseudo, we
6538 figure out what the mode of the eventual return register will
6539 actually be, and use that. */
6541 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)),
6544 /* Structures that are returned in registers are not aggregate_value_p,
6545 so we may see a PARALLEL. Don't play pseudo games with this. */
6546 if (! REG_P (hard_reg))
6547 SET_DECL_RTL (DECL_RESULT (subr), hard_reg);
6550 /* Create the pseudo. */
6551 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg)));
6553 /* Needed because we may need to move this to memory
6554 in case it's a named return value whose address is taken. */
6555 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6559 /* Initialize rtx for parameters and local variables.
6560 In some cases this requires emitting insns. */
6562 assign_parms (subr);
6564 /* Copy the static chain now if it wasn't a register. The delay is to
6565 avoid conflicts with the parameter passing registers. */
6567 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6568 if (GET_CODE (static_chain_incoming_rtx) != REG)
6569 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6571 /* The following was moved from init_function_start.
6572 The move is supposed to make sdb output more accurate. */
6573 /* Indicate the beginning of the function body,
6574 as opposed to parm setup. */
6575 emit_note (NULL, NOTE_INSN_FUNCTION_BEG);
6577 if (GET_CODE (get_last_insn ()) != NOTE)
6578 emit_note (NULL, NOTE_INSN_DELETED);
6579 parm_birth_insn = get_last_insn ();
6581 context_display = 0;
6582 if (current_function_needs_context)
6584 /* Fetch static chain values for containing functions. */
6585 tem = decl_function_context (current_function_decl);
6586 /* Copy the static chain pointer into a pseudo. If we have
6587 small register classes, copy the value from memory if
6588 static_chain_incoming_rtx is a REG. */
6591 /* If the static chain originally came in a register, put it back
6592 there, then move it out in the next insn. The reason for
6593 this peculiar code is to satisfy function integration. */
6594 if (SMALL_REGISTER_CLASSES
6595 && GET_CODE (static_chain_incoming_rtx) == REG)
6596 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6597 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6602 tree rtlexp = make_node (RTL_EXPR);
6604 RTL_EXPR_RTL (rtlexp) = last_ptr;
6605 context_display = tree_cons (tem, rtlexp, context_display);
6606 tem = decl_function_context (tem);
6609 /* Chain thru stack frames, assuming pointer to next lexical frame
6610 is found at the place we always store it. */
6611 #ifdef FRAME_GROWS_DOWNWARD
6612 last_ptr = plus_constant (last_ptr,
6613 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode));
6615 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr));
6616 set_mem_alias_set (last_ptr, get_frame_alias_set ());
6617 last_ptr = copy_to_reg (last_ptr);
6619 /* If we are not optimizing, ensure that we know that this
6620 piece of context is live over the entire function. */
6622 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6627 if (current_function_instrument_entry_exit)
6629 rtx fun = DECL_RTL (current_function_decl);
6630 if (GET_CODE (fun) == MEM)
6631 fun = XEXP (fun, 0);
6634 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode,
6636 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6638 hard_frame_pointer_rtx),
6642 if (current_function_profile)
6645 PROFILE_HOOK (current_function_funcdef_no);
6649 /* After the display initializations is where the tail-recursion label
6650 should go, if we end up needing one. Ensure we have a NOTE here
6651 since some things (like trampolines) get placed before this. */
6652 tail_recursion_reentry = emit_note (NULL, NOTE_INSN_DELETED);
6654 /* Evaluate now the sizes of any types declared among the arguments. */
6655 expand_pending_sizes (nreverse (get_pending_sizes ()));
6657 /* Make sure there is a line number after the function entry setup code. */
6658 force_next_line_note ();
6661 /* Undo the effects of init_dummy_function_start. */
6663 expand_dummy_function_end ()
6665 /* End any sequences that failed to be closed due to syntax errors. */
6666 while (in_sequence_p ())
6669 /* Outside function body, can't compute type's actual size
6670 until next function's body starts. */
6672 free_after_parsing (cfun);
6673 free_after_compilation (cfun);
6677 /* Call DOIT for each hard register used as a return value from
6678 the current function. */
6681 diddle_return_value (doit, arg)
6682 void (*doit) PARAMS ((rtx, void *));
6685 rtx outgoing = current_function_return_rtx;
6690 if (GET_CODE (outgoing) == REG)
6691 (*doit) (outgoing, arg);
6692 else if (GET_CODE (outgoing) == PARALLEL)
6696 for (i = 0; i < XVECLEN (outgoing, 0); i++)
6698 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
6700 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6707 do_clobber_return_reg (reg, arg)
6709 void *arg ATTRIBUTE_UNUSED;
6711 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
6715 clobber_return_register ()
6717 diddle_return_value (do_clobber_return_reg, NULL);
6719 /* In case we do use pseudo to return value, clobber it too. */
6720 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6722 tree decl_result = DECL_RESULT (current_function_decl);
6723 rtx decl_rtl = DECL_RTL (decl_result);
6724 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
6726 do_clobber_return_reg (decl_rtl, NULL);
6732 do_use_return_reg (reg, arg)
6734 void *arg ATTRIBUTE_UNUSED;
6736 emit_insn (gen_rtx_USE (VOIDmode, reg));
6740 use_return_register ()
6742 diddle_return_value (do_use_return_reg, NULL);
6745 static GTY(()) rtx initial_trampoline;
6747 /* Generate RTL for the end of the current function.
6748 FILENAME and LINE are the current position in the source file.
6750 It is up to language-specific callers to do cleanups for parameters--
6751 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6754 expand_function_end (filename, line, end_bindings)
6755 const char *filename;
6762 finish_expr_for_function ();
6764 /* If arg_pointer_save_area was referenced only from a nested
6765 function, we will not have initialized it yet. Do that now. */
6766 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init)
6767 get_arg_pointer_save_area (cfun);
6769 #ifdef NON_SAVING_SETJMP
6770 /* Don't put any variables in registers if we call setjmp
6771 on a machine that fails to restore the registers. */
6772 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6774 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6775 setjmp_protect (DECL_INITIAL (current_function_decl));
6777 setjmp_protect_args ();
6781 /* Initialize any trampolines required by this function. */
6782 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6784 tree function = TREE_PURPOSE (link);
6785 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function);
6786 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6787 #ifdef TRAMPOLINE_TEMPLATE
6792 #ifdef TRAMPOLINE_TEMPLATE
6793 /* First make sure this compilation has a template for
6794 initializing trampolines. */
6795 if (initial_trampoline == 0)
6798 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6799 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
6803 /* Generate insns to initialize the trampoline. */
6805 tramp = round_trampoline_addr (XEXP (tramp, 0));
6806 #ifdef TRAMPOLINE_TEMPLATE
6807 blktramp = replace_equiv_address (initial_trampoline, tramp);
6808 emit_block_move (blktramp, initial_trampoline,
6809 GEN_INT (TRAMPOLINE_SIZE));
6811 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6815 /* Put those insns at entry to the containing function (this one). */
6816 emit_insn_before (seq, tail_recursion_reentry);
6819 /* If we are doing stack checking and this function makes calls,
6820 do a stack probe at the start of the function to ensure we have enough
6821 space for another stack frame. */
6822 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6826 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6827 if (GET_CODE (insn) == CALL_INSN)
6830 probe_stack_range (STACK_CHECK_PROTECT,
6831 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6834 emit_insn_before (seq, tail_recursion_reentry);
6839 /* Warn about unused parms if extra warnings were specified. */
6840 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
6841 warning. WARN_UNUSED_PARAMETER is negative when set by
6843 if (warn_unused_parameter > 0
6844 || (warn_unused_parameter < 0 && extra_warnings))
6848 for (decl = DECL_ARGUMENTS (current_function_decl);
6849 decl; decl = TREE_CHAIN (decl))
6850 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6851 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6852 warning_with_decl (decl, "unused parameter `%s'");
6855 /* Delete handlers for nonlocal gotos if nothing uses them. */
6856 if (nonlocal_goto_handler_slots != 0
6857 && ! current_function_has_nonlocal_label)
6860 /* End any sequences that failed to be closed due to syntax errors. */
6861 while (in_sequence_p ())
6864 /* Outside function body, can't compute type's actual size
6865 until next function's body starts. */
6866 immediate_size_expand--;
6868 clear_pending_stack_adjust ();
6869 do_pending_stack_adjust ();
6871 /* Mark the end of the function body.
6872 If control reaches this insn, the function can drop through
6873 without returning a value. */
6874 emit_note (NULL, NOTE_INSN_FUNCTION_END);
6876 /* Must mark the last line number note in the function, so that the test
6877 coverage code can avoid counting the last line twice. This just tells
6878 the code to ignore the immediately following line note, since there
6879 already exists a copy of this note somewhere above. This line number
6880 note is still needed for debugging though, so we can't delete it. */
6881 if (flag_test_coverage)
6882 emit_note (NULL, NOTE_INSN_REPEATED_LINE_NUMBER);
6884 /* Output a linenumber for the end of the function.
6885 SDB depends on this. */
6886 emit_line_note_force (filename, line);
6888 /* Before the return label (if any), clobber the return
6889 registers so that they are not propagated live to the rest of
6890 the function. This can only happen with functions that drop
6891 through; if there had been a return statement, there would
6892 have either been a return rtx, or a jump to the return label.
6894 We delay actual code generation after the current_function_value_rtx
6896 clobber_after = get_last_insn ();
6898 /* Output the label for the actual return from the function,
6899 if one is expected. This happens either because a function epilogue
6900 is used instead of a return instruction, or because a return was done
6901 with a goto in order to run local cleanups, or because of pcc-style
6902 structure returning. */
6904 emit_label (return_label);
6906 /* C++ uses this. */
6908 expand_end_bindings (0, 0, 0);
6910 if (current_function_instrument_entry_exit)
6912 rtx fun = DECL_RTL (current_function_decl);
6913 if (GET_CODE (fun) == MEM)
6914 fun = XEXP (fun, 0);
6917 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode,
6919 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6921 hard_frame_pointer_rtx),
6925 /* Let except.c know where it should emit the call to unregister
6926 the function context for sjlj exceptions. */
6927 if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
6928 sjlj_emit_function_exit_after (get_last_insn ());
6930 /* If we had calls to alloca, and this machine needs
6931 an accurate stack pointer to exit the function,
6932 insert some code to save and restore the stack pointer. */
6933 #ifdef EXIT_IGNORE_STACK
6934 if (! EXIT_IGNORE_STACK)
6936 if (current_function_calls_alloca)
6940 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
6941 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
6944 /* If scalar return value was computed in a pseudo-reg, or was a named
6945 return value that got dumped to the stack, copy that to the hard
6947 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6949 tree decl_result = DECL_RESULT (current_function_decl);
6950 rtx decl_rtl = DECL_RTL (decl_result);
6952 if (REG_P (decl_rtl)
6953 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
6954 : DECL_REGISTER (decl_result))
6956 rtx real_decl_rtl = current_function_return_rtx;
6958 /* This should be set in assign_parms. */
6959 if (! REG_FUNCTION_VALUE_P (real_decl_rtl))
6962 /* If this is a BLKmode structure being returned in registers,
6963 then use the mode computed in expand_return. Note that if
6964 decl_rtl is memory, then its mode may have been changed,
6965 but that current_function_return_rtx has not. */
6966 if (GET_MODE (real_decl_rtl) == BLKmode)
6967 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
6969 /* If a named return value dumped decl_return to memory, then
6970 we may need to re-do the PROMOTE_MODE signed/unsigned
6972 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
6974 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result));
6976 #ifdef PROMOTE_FUNCTION_RETURN
6977 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
6981 convert_move (real_decl_rtl, decl_rtl, unsignedp);
6983 else if (GET_CODE (real_decl_rtl) == PARALLEL)
6984 emit_group_load (real_decl_rtl, decl_rtl,
6985 int_size_in_bytes (TREE_TYPE (decl_result)));
6987 emit_move_insn (real_decl_rtl, decl_rtl);
6991 /* If returning a structure, arrange to return the address of the value
6992 in a place where debuggers expect to find it.
6994 If returning a structure PCC style,
6995 the caller also depends on this value.
6996 And current_function_returns_pcc_struct is not necessarily set. */
6997 if (current_function_returns_struct
6998 || current_function_returns_pcc_struct)
7001 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
7002 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
7003 #ifdef FUNCTION_OUTGOING_VALUE
7005 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
7006 current_function_decl);
7009 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl);
7012 /* Mark this as a function return value so integrate will delete the
7013 assignment and USE below when inlining this function. */
7014 REG_FUNCTION_VALUE_P (outgoing) = 1;
7016 #ifdef POINTERS_EXTEND_UNSIGNED
7017 /* The address may be ptr_mode and OUTGOING may be Pmode. */
7018 if (GET_MODE (outgoing) != GET_MODE (value_address))
7019 value_address = convert_memory_address (GET_MODE (outgoing),
7023 emit_move_insn (outgoing, value_address);
7025 /* Show return register used to hold result (in this case the address
7027 current_function_return_rtx = outgoing;
7030 /* If this is an implementation of throw, do what's necessary to
7031 communicate between __builtin_eh_return and the epilogue. */
7032 expand_eh_return ();
7034 /* Emit the actual code to clobber return register. */
7039 clobber_return_register ();
7043 after = emit_insn_after (seq, clobber_after);
7045 if (clobber_after != after)
7046 cfun->x_clobber_return_insn = after;
7049 /* ??? This should no longer be necessary since stupid is no longer with
7050 us, but there are some parts of the compiler (eg reload_combine, and
7051 sh mach_dep_reorg) that still try and compute their own lifetime info
7052 instead of using the general framework. */
7053 use_return_register ();
7055 /* Fix up any gotos that jumped out to the outermost
7056 binding level of the function.
7057 Must follow emitting RETURN_LABEL. */
7059 /* If you have any cleanups to do at this point,
7060 and they need to create temporary variables,
7061 then you will lose. */
7062 expand_fixups (get_insns ());
7066 get_arg_pointer_save_area (f)
7069 rtx ret = f->x_arg_pointer_save_area;
7073 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f);
7074 f->x_arg_pointer_save_area = ret;
7077 if (f == cfun && ! f->arg_pointer_save_area_init)
7081 /* Save the arg pointer at the beginning of the function. The
7082 generated stack slot may not be a valid memory address, so we
7083 have to check it and fix it if necessary. */
7085 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx);
7089 push_topmost_sequence ();
7090 emit_insn_after (seq, get_insns ());
7091 pop_topmost_sequence ();
7097 /* Extend a vector that records the INSN_UIDs of INSNS
7098 (a list of one or more insns). */
7101 record_insns (insns, vecp)
7110 while (tmp != NULL_RTX)
7113 tmp = NEXT_INSN (tmp);
7116 i = VARRAY_SIZE (*vecp);
7117 VARRAY_GROW (*vecp, i + len);
7119 while (tmp != NULL_RTX)
7121 VARRAY_INT (*vecp, i) = INSN_UID (tmp);
7123 tmp = NEXT_INSN (tmp);
7127 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
7128 be running after reorg, SEQUENCE rtl is possible. */
7131 contains (insn, vec)
7137 if (GET_CODE (insn) == INSN
7138 && GET_CODE (PATTERN (insn)) == SEQUENCE)
7141 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
7142 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7143 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
7149 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7150 if (INSN_UID (insn) == VARRAY_INT (vec, j))
7157 prologue_epilogue_contains (insn)
7160 if (contains (insn, prologue))
7162 if (contains (insn, epilogue))
7168 sibcall_epilogue_contains (insn)
7171 if (sibcall_epilogue)
7172 return contains (insn, sibcall_epilogue);
7177 /* Insert gen_return at the end of block BB. This also means updating
7178 block_for_insn appropriately. */
7181 emit_return_into_block (bb, line_note)
7187 p = NEXT_INSN (bb->end);
7188 end = emit_jump_insn_after (gen_return (), bb->end);
7190 emit_line_note_after (NOTE_SOURCE_FILE (line_note),
7191 NOTE_LINE_NUMBER (line_note), PREV_INSN (bb->end));
7193 #endif /* HAVE_return */
7195 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7197 /* These functions convert the epilogue into a variant that does not modify the
7198 stack pointer. This is used in cases where a function returns an object
7199 whose size is not known until it is computed. The called function leaves the
7200 object on the stack, leaves the stack depressed, and returns a pointer to
7203 What we need to do is track all modifications and references to the stack
7204 pointer, deleting the modifications and changing the references to point to
7205 the location the stack pointer would have pointed to had the modifications
7208 These functions need to be portable so we need to make as few assumptions
7209 about the epilogue as we can. However, the epilogue basically contains
7210 three things: instructions to reset the stack pointer, instructions to
7211 reload registers, possibly including the frame pointer, and an
7212 instruction to return to the caller.
7214 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7215 We also make no attempt to validate the insns we make since if they are
7216 invalid, we probably can't do anything valid. The intent is that these
7217 routines get "smarter" as more and more machines start to use them and
7218 they try operating on different epilogues.
7220 We use the following structure to track what the part of the epilogue that
7221 we've already processed has done. We keep two copies of the SP equivalence,
7222 one for use during the insn we are processing and one for use in the next
7223 insn. The difference is because one part of a PARALLEL may adjust SP
7224 and the other may use it. */
7228 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */
7229 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */
7230 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */
7231 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */
7232 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG
7233 should be set to once we no longer need
7237 static void handle_epilogue_set PARAMS ((rtx, struct epi_info *));
7238 static void emit_equiv_load PARAMS ((struct epi_info *));
7240 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
7241 no modifications to the stack pointer. Return the new list of insns. */
7244 keep_stack_depressed (insns)
7248 struct epi_info info;
7251 /* If the epilogue is just a single instruction, it ust be OK as is. */
7253 if (NEXT_INSN (insns) == NULL_RTX)
7256 /* Otherwise, start a sequence, initialize the information we have, and
7257 process all the insns we were given. */
7260 info.sp_equiv_reg = stack_pointer_rtx;
7262 info.equiv_reg_src = 0;
7266 while (insn != NULL_RTX)
7268 next = NEXT_INSN (insn);
7277 /* If this insn references the register that SP is equivalent to and
7278 we have a pending load to that register, we must force out the load
7279 first and then indicate we no longer know what SP's equivalent is. */
7280 if (info.equiv_reg_src != 0
7281 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn)))
7283 emit_equiv_load (&info);
7284 info.sp_equiv_reg = 0;
7287 info.new_sp_equiv_reg = info.sp_equiv_reg;
7288 info.new_sp_offset = info.sp_offset;
7290 /* If this is a (RETURN) and the return address is on the stack,
7291 update the address and change to an indirect jump. */
7292 if (GET_CODE (PATTERN (insn)) == RETURN
7293 || (GET_CODE (PATTERN (insn)) == PARALLEL
7294 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
7296 rtx retaddr = INCOMING_RETURN_ADDR_RTX;
7298 HOST_WIDE_INT offset = 0;
7299 rtx jump_insn, jump_set;
7301 /* If the return address is in a register, we can emit the insn
7302 unchanged. Otherwise, it must be a MEM and we see what the
7303 base register and offset are. In any case, we have to emit any
7304 pending load to the equivalent reg of SP, if any. */
7305 if (GET_CODE (retaddr) == REG)
7307 emit_equiv_load (&info);
7312 else if (GET_CODE (retaddr) == MEM
7313 && GET_CODE (XEXP (retaddr, 0)) == REG)
7314 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0;
7315 else if (GET_CODE (retaddr) == MEM
7316 && GET_CODE (XEXP (retaddr, 0)) == PLUS
7317 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG
7318 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT)
7320 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0)));
7321 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1));
7326 /* If the base of the location containing the return pointer
7327 is SP, we must update it with the replacement address. Otherwise,
7328 just build the necessary MEM. */
7329 retaddr = plus_constant (base, offset);
7330 if (base == stack_pointer_rtx)
7331 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx,
7332 plus_constant (info.sp_equiv_reg,
7335 retaddr = gen_rtx_MEM (Pmode, retaddr);
7337 /* If there is a pending load to the equivalent register for SP
7338 and we reference that register, we must load our address into
7339 a scratch register and then do that load. */
7340 if (info.equiv_reg_src
7341 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr))
7346 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7347 if (HARD_REGNO_MODE_OK (regno, Pmode)
7348 && !fixed_regs[regno]
7349 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
7350 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start,
7352 && !refers_to_regno_p (regno,
7353 regno + HARD_REGNO_NREGS (regno,
7355 info.equiv_reg_src, NULL))
7358 if (regno == FIRST_PSEUDO_REGISTER)
7361 reg = gen_rtx_REG (Pmode, regno);
7362 emit_move_insn (reg, retaddr);
7366 emit_equiv_load (&info);
7367 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr));
7369 /* Show the SET in the above insn is a RETURN. */
7370 jump_set = single_set (jump_insn);
7374 SET_IS_RETURN_P (jump_set) = 1;
7377 /* If SP is not mentioned in the pattern and its equivalent register, if
7378 any, is not modified, just emit it. Otherwise, if neither is set,
7379 replace the reference to SP and emit the insn. If none of those are
7380 true, handle each SET individually. */
7381 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))
7382 && (info.sp_equiv_reg == stack_pointer_rtx
7383 || !reg_set_p (info.sp_equiv_reg, insn)))
7385 else if (! reg_set_p (stack_pointer_rtx, insn)
7386 && (info.sp_equiv_reg == stack_pointer_rtx
7387 || !reg_set_p (info.sp_equiv_reg, insn)))
7389 if (! validate_replace_rtx (stack_pointer_rtx,
7390 plus_constant (info.sp_equiv_reg,
7397 else if (GET_CODE (PATTERN (insn)) == SET)
7398 handle_epilogue_set (PATTERN (insn), &info);
7399 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
7401 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++)
7402 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
7403 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info);
7408 info.sp_equiv_reg = info.new_sp_equiv_reg;
7409 info.sp_offset = info.new_sp_offset;
7414 insns = get_insns ();
7419 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7420 structure that contains information about what we've seen so far. We
7421 process this SET by either updating that data or by emitting one or
7425 handle_epilogue_set (set, p)
7429 /* First handle the case where we are setting SP. Record what it is being
7430 set from. If unknown, abort. */
7431 if (reg_set_p (stack_pointer_rtx, set))
7433 if (SET_DEST (set) != stack_pointer_rtx)
7436 if (GET_CODE (SET_SRC (set)) == PLUS
7437 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
7439 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0);
7440 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1));
7443 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0;
7445 /* If we are adjusting SP, we adjust from the old data. */
7446 if (p->new_sp_equiv_reg == stack_pointer_rtx)
7448 p->new_sp_equiv_reg = p->sp_equiv_reg;
7449 p->new_sp_offset += p->sp_offset;
7452 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG)
7458 /* Next handle the case where we are setting SP's equivalent register.
7459 If we already have a value to set it to, abort. We could update, but
7460 there seems little point in handling that case. Note that we have
7461 to allow for the case where we are setting the register set in
7462 the previous part of a PARALLEL inside a single insn. But use the
7463 old offset for any updates within this insn. */
7464 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set))
7466 if (!rtx_equal_p (p->new_sp_equiv_reg, SET_DEST (set))
7467 || p->equiv_reg_src != 0)
7471 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7472 plus_constant (p->sp_equiv_reg,
7476 /* Otherwise, replace any references to SP in the insn to its new value
7477 and emit the insn. */
7480 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7481 plus_constant (p->sp_equiv_reg,
7483 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx,
7484 plus_constant (p->sp_equiv_reg,
7490 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7496 if (p->equiv_reg_src != 0)
7497 emit_move_insn (p->sp_equiv_reg, p->equiv_reg_src);
7499 p->equiv_reg_src = 0;
7503 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7504 this into place with notes indicating where the prologue ends and where
7505 the epilogue begins. Update the basic block information when possible. */
7508 thread_prologue_and_epilogue_insns (f)
7509 rtx f ATTRIBUTE_UNUSED;
7513 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7516 #ifdef HAVE_prologue
7517 rtx prologue_end = NULL_RTX;
7519 #if defined (HAVE_epilogue) || defined(HAVE_return)
7520 rtx epilogue_end = NULL_RTX;
7523 #ifdef HAVE_prologue
7527 seq = gen_prologue ();
7530 /* Retain a map of the prologue insns. */
7531 record_insns (seq, &prologue);
7532 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END);
7537 /* Can't deal with multiple successors of the entry block
7538 at the moment. Function should always have at least one
7540 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next)
7543 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
7548 /* If the exit block has no non-fake predecessors, we don't need
7550 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7551 if ((e->flags & EDGE_FAKE) == 0)
7557 if (optimize && HAVE_return)
7559 /* If we're allowed to generate a simple return instruction,
7560 then by definition we don't need a full epilogue. Examine
7561 the block that falls through to EXIT. If it does not
7562 contain any code, examine its predecessors and try to
7563 emit (conditional) return instructions. */
7569 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7570 if (e->flags & EDGE_FALLTHRU)
7576 /* Verify that there are no active instructions in the last block. */
7578 while (label && GET_CODE (label) != CODE_LABEL)
7580 if (active_insn_p (label))
7582 label = PREV_INSN (label);
7585 if (last->head == label && GET_CODE (label) == CODE_LABEL)
7587 rtx epilogue_line_note = NULL_RTX;
7589 /* Locate the line number associated with the closing brace,
7590 if we can find one. */
7591 for (seq = get_last_insn ();
7592 seq && ! active_insn_p (seq);
7593 seq = PREV_INSN (seq))
7594 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0)
7596 epilogue_line_note = seq;
7600 for (e = last->pred; e; e = e_next)
7602 basic_block bb = e->src;
7605 e_next = e->pred_next;
7606 if (bb == ENTRY_BLOCK_PTR)
7610 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label)
7613 /* If we have an unconditional jump, we can replace that
7614 with a simple return instruction. */
7615 if (simplejump_p (jump))
7617 emit_return_into_block (bb, epilogue_line_note);
7621 /* If we have a conditional jump, we can try to replace
7622 that with a conditional return instruction. */
7623 else if (condjump_p (jump))
7627 ret = SET_SRC (PATTERN (jump));
7628 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF)
7629 loc = &XEXP (ret, 1);
7631 loc = &XEXP (ret, 2);
7632 ret = gen_rtx_RETURN (VOIDmode);
7634 if (! validate_change (jump, loc, ret, 0))
7636 if (JUMP_LABEL (jump))
7637 LABEL_NUSES (JUMP_LABEL (jump))--;
7639 /* If this block has only one successor, it both jumps
7640 and falls through to the fallthru block, so we can't
7642 if (bb->succ->succ_next == NULL)
7648 /* Fix up the CFG for the successful change we just made. */
7649 redirect_edge_succ (e, EXIT_BLOCK_PTR);
7652 /* Emit a return insn for the exit fallthru block. Whether
7653 this is still reachable will be determined later. */
7655 emit_barrier_after (last->end);
7656 emit_return_into_block (last, epilogue_line_note);
7657 epilogue_end = last->end;
7658 last->succ->flags &= ~EDGE_FALLTHRU;
7663 #ifdef HAVE_epilogue
7666 /* Find the edge that falls through to EXIT. Other edges may exist
7667 due to RETURN instructions, but those don't need epilogues.
7668 There really shouldn't be a mixture -- either all should have
7669 been converted or none, however... */
7671 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7672 if (e->flags & EDGE_FALLTHRU)
7678 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG);
7680 seq = gen_epilogue ();
7682 #ifdef INCOMING_RETURN_ADDR_RTX
7683 /* If this function returns with the stack depressed and we can support
7684 it, massage the epilogue to actually do that. */
7685 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
7686 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
7687 seq = keep_stack_depressed (seq);
7690 emit_jump_insn (seq);
7692 /* Retain a map of the epilogue insns. */
7693 record_insns (seq, &epilogue);
7698 insert_insn_on_edge (seq, e);
7705 commit_edge_insertions ();
7707 #ifdef HAVE_sibcall_epilogue
7708 /* Emit sibling epilogues before any sibling call sites. */
7709 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7711 basic_block bb = e->src;
7716 if (GET_CODE (insn) != CALL_INSN
7717 || ! SIBLING_CALL_P (insn))
7721 emit_insn (gen_sibcall_epilogue ());
7725 /* Retain a map of the epilogue insns. Used in life analysis to
7726 avoid getting rid of sibcall epilogue insns. Do this before we
7727 actually emit the sequence. */
7728 record_insns (seq, &sibcall_epilogue);
7730 i = PREV_INSN (insn);
7731 newinsn = emit_insn_before (seq, insn);
7735 #ifdef HAVE_prologue
7740 /* GDB handles `break f' by setting a breakpoint on the first
7741 line note after the prologue. Which means (1) that if
7742 there are line number notes before where we inserted the
7743 prologue we should move them, and (2) we should generate a
7744 note before the end of the first basic block, if there isn't
7747 ??? This behaviour is completely broken when dealing with
7748 multiple entry functions. We simply place the note always
7749 into first basic block and let alternate entry points
7753 for (insn = prologue_end; insn; insn = prev)
7755 prev = PREV_INSN (insn);
7756 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7758 /* Note that we cannot reorder the first insn in the
7759 chain, since rest_of_compilation relies on that
7760 remaining constant. */
7763 reorder_insns (insn, insn, prologue_end);
7767 /* Find the last line number note in the first block. */
7768 for (insn = ENTRY_BLOCK_PTR->next_bb->end;
7769 insn != prologue_end && insn;
7770 insn = PREV_INSN (insn))
7771 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7774 /* If we didn't find one, make a copy of the first line number
7778 for (insn = next_active_insn (prologue_end);
7780 insn = PREV_INSN (insn))
7781 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7783 emit_line_note_after (NOTE_SOURCE_FILE (insn),
7784 NOTE_LINE_NUMBER (insn),
7791 #ifdef HAVE_epilogue
7796 /* Similarly, move any line notes that appear after the epilogue.
7797 There is no need, however, to be quite so anal about the existence
7799 for (insn = epilogue_end; insn; insn = next)
7801 next = NEXT_INSN (insn);
7802 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7803 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
7809 /* Reposition the prologue-end and epilogue-begin notes after instruction
7810 scheduling and delayed branch scheduling. */
7813 reposition_prologue_and_epilogue_notes (f)
7814 rtx f ATTRIBUTE_UNUSED;
7816 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7817 rtx insn, last, note;
7820 if ((len = VARRAY_SIZE (prologue)) > 0)
7824 /* Scan from the beginning until we reach the last prologue insn.
7825 We apparently can't depend on basic_block_{head,end} after
7827 for (insn = f; insn; insn = NEXT_INSN (insn))
7829 if (GET_CODE (insn) == NOTE)
7831 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
7834 else if (contains (insn, prologue))
7846 /* Find the prologue-end note if we haven't already, and
7847 move it to just after the last prologue insn. */
7850 for (note = last; (note = NEXT_INSN (note));)
7851 if (GET_CODE (note) == NOTE
7852 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
7856 next = NEXT_INSN (note);
7858 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7859 if (GET_CODE (last) == CODE_LABEL)
7860 last = NEXT_INSN (last);
7861 reorder_insns (note, note, last);
7865 if ((len = VARRAY_SIZE (epilogue)) > 0)
7869 /* Scan from the end until we reach the first epilogue insn.
7870 We apparently can't depend on basic_block_{head,end} after
7872 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
7874 if (GET_CODE (insn) == NOTE)
7876 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
7879 else if (contains (insn, epilogue))
7889 /* Find the epilogue-begin note if we haven't already, and
7890 move it to just before the first epilogue insn. */
7893 for (note = insn; (note = PREV_INSN (note));)
7894 if (GET_CODE (note) == NOTE
7895 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
7899 if (PREV_INSN (last) != note)
7900 reorder_insns (note, note, PREV_INSN (last));
7903 #endif /* HAVE_prologue or HAVE_epilogue */
7906 /* Called once, at initialization, to initialize function.c. */
7909 init_function_once ()
7911 VARRAY_INT_INIT (prologue, 0, "prologue");
7912 VARRAY_INT_INIT (epilogue, 0, "epilogue");
7913 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");
7916 #include "gt-function.h"