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"
63 #ifndef TRAMPOLINE_ALIGNMENT
64 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
67 #ifndef LOCAL_ALIGNMENT
68 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
71 /* Some systems use __main in a way incompatible with its use in gcc, in these
72 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
73 give the same symbol without quotes for an alternative entry point. You
74 must define both, or neither. */
76 #define NAME__MAIN "__main"
77 #define SYMBOL__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. */
127 static int profile_label_no;
129 /* These variables hold pointers to functions to create and destroy
130 target specific, per-function data structures. */
131 void (*init_machine_status) PARAMS ((struct function *));
132 void (*free_machine_status) PARAMS ((struct function *));
133 /* This variable holds a pointer to a function to register any
134 data items in the target specific, per-function data structure
135 that will need garbage collection. */
136 void (*mark_machine_status) PARAMS ((struct function *));
138 /* Likewise, but for language-specific data. */
139 void (*init_lang_status) PARAMS ((struct function *));
140 void (*save_lang_status) PARAMS ((struct function *));
141 void (*restore_lang_status) PARAMS ((struct function *));
142 void (*mark_lang_status) PARAMS ((struct function *));
143 void (*free_lang_status) PARAMS ((struct function *));
145 /* The FUNCTION_DECL for an inline function currently being expanded. */
146 tree inline_function_decl;
148 /* The currently compiled function. */
149 struct function *cfun = 0;
151 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
152 static varray_type prologue;
153 static varray_type epilogue;
155 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
157 static varray_type sibcall_epilogue;
159 /* In order to evaluate some expressions, such as function calls returning
160 structures in memory, we need to temporarily allocate stack locations.
161 We record each allocated temporary in the following structure.
163 Associated with each temporary slot is a nesting level. When we pop up
164 one level, all temporaries associated with the previous level are freed.
165 Normally, all temporaries are freed after the execution of the statement
166 in which they were created. However, if we are inside a ({...}) grouping,
167 the result may be in a temporary and hence must be preserved. If the
168 result could be in a temporary, we preserve it if we can determine which
169 one it is in. If we cannot determine which temporary may contain the
170 result, all temporaries are preserved. A temporary is preserved by
171 pretending it was allocated at the previous nesting level.
173 Automatic variables are also assigned temporary slots, at the nesting
174 level where they are defined. They are marked a "kept" so that
175 free_temp_slots will not free them. */
179 /* Points to next temporary slot. */
180 struct temp_slot *next;
181 /* The rtx to used to reference the slot. */
183 /* The rtx used to represent the address if not the address of the
184 slot above. May be an EXPR_LIST if multiple addresses exist. */
186 /* The alignment (in bits) of the slot. */
188 /* The size, in units, of the slot. */
190 /* The type of the object in the slot, or zero if it doesn't correspond
191 to a type. We use this to determine whether a slot can be reused.
192 It can be reused if objects of the type of the new slot will always
193 conflict with objects of the type of the old slot. */
195 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
197 /* Non-zero if this temporary is currently in use. */
199 /* Non-zero if this temporary has its address taken. */
201 /* Nesting level at which this slot is being used. */
203 /* Non-zero if this should survive a call to free_temp_slots. */
205 /* The offset of the slot from the frame_pointer, including extra space
206 for alignment. This info is for combine_temp_slots. */
207 HOST_WIDE_INT base_offset;
208 /* The size of the slot, including extra space for alignment. This
209 info is for combine_temp_slots. */
210 HOST_WIDE_INT full_size;
213 /* This structure is used to record MEMs or pseudos used to replace VAR, any
214 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
215 maintain this list in case two operands of an insn were required to match;
216 in that case we must ensure we use the same replacement. */
218 struct fixup_replacement
222 struct fixup_replacement *next;
225 struct insns_for_mem_entry
227 /* The KEY in HE will be a MEM. */
228 struct hash_entry he;
229 /* These are the INSNS which reference the MEM. */
233 /* Forward declarations. */
235 static rtx assign_stack_local_1 PARAMS ((enum machine_mode, HOST_WIDE_INT,
236 int, struct function *));
237 static struct temp_slot *find_temp_slot_from_address PARAMS ((rtx));
238 static void put_reg_into_stack PARAMS ((struct function *, rtx, tree,
239 enum machine_mode, enum machine_mode,
240 int, unsigned int, int,
241 struct hash_table *));
242 static void schedule_fixup_var_refs PARAMS ((struct function *, rtx, tree,
244 struct hash_table *));
245 static void fixup_var_refs PARAMS ((rtx, enum machine_mode, int, rtx,
246 struct hash_table *));
247 static struct fixup_replacement
248 *find_fixup_replacement PARAMS ((struct fixup_replacement **, rtx));
249 static void fixup_var_refs_insns PARAMS ((rtx, rtx, enum machine_mode,
251 static void fixup_var_refs_insns_with_hash
252 PARAMS ((struct hash_table *, rtx,
253 enum machine_mode, int, rtx));
254 static void fixup_var_refs_insn PARAMS ((rtx, rtx, enum machine_mode,
256 static void fixup_var_refs_1 PARAMS ((rtx, enum machine_mode, rtx *, rtx,
257 struct fixup_replacement **, rtx));
258 static rtx fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode, int));
259 static rtx walk_fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode,
261 static rtx fixup_stack_1 PARAMS ((rtx, rtx));
262 static void optimize_bit_field PARAMS ((rtx, rtx, rtx *));
263 static void instantiate_decls PARAMS ((tree, int));
264 static void instantiate_decls_1 PARAMS ((tree, int));
265 static void instantiate_decl PARAMS ((rtx, HOST_WIDE_INT, int));
266 static rtx instantiate_new_reg PARAMS ((rtx, HOST_WIDE_INT *));
267 static int instantiate_virtual_regs_1 PARAMS ((rtx *, rtx, int));
268 static void delete_handlers PARAMS ((void));
269 static void pad_to_arg_alignment PARAMS ((struct args_size *, int,
270 struct args_size *));
271 #ifndef ARGS_GROW_DOWNWARD
272 static void pad_below PARAMS ((struct args_size *, enum machine_mode,
275 static rtx round_trampoline_addr PARAMS ((rtx));
276 static rtx adjust_trampoline_addr PARAMS ((rtx));
277 static tree *identify_blocks_1 PARAMS ((rtx, tree *, tree *, tree *));
278 static void reorder_blocks_0 PARAMS ((tree));
279 static void reorder_blocks_1 PARAMS ((rtx, tree, varray_type *));
280 static void reorder_fix_fragments PARAMS ((tree));
281 static tree blocks_nreverse PARAMS ((tree));
282 static int all_blocks PARAMS ((tree, tree *));
283 static tree *get_block_vector PARAMS ((tree, int *));
284 extern tree debug_find_var_in_block_tree PARAMS ((tree, tree));
285 /* We always define `record_insns' even if its not used so that we
286 can always export `prologue_epilogue_contains'. */
287 static void record_insns PARAMS ((rtx, varray_type *)) ATTRIBUTE_UNUSED;
288 static int contains PARAMS ((rtx, varray_type));
290 static void emit_return_into_block PARAMS ((basic_block, rtx));
292 static void put_addressof_into_stack PARAMS ((rtx, struct hash_table *));
293 static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int,
294 struct hash_table *));
295 static void purge_single_hard_subreg_set PARAMS ((rtx));
296 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
297 static rtx keep_stack_depressed PARAMS ((rtx));
299 static int is_addressof PARAMS ((rtx *, void *));
300 static struct hash_entry *insns_for_mem_newfunc PARAMS ((struct hash_entry *,
303 static unsigned long insns_for_mem_hash PARAMS ((hash_table_key));
304 static bool insns_for_mem_comp PARAMS ((hash_table_key, hash_table_key));
305 static int insns_for_mem_walk PARAMS ((rtx *, void *));
306 static void compute_insns_for_mem PARAMS ((rtx, rtx, struct hash_table *));
307 static void mark_function_status PARAMS ((struct function *));
308 static void maybe_mark_struct_function PARAMS ((void *));
309 static void prepare_function_start PARAMS ((void));
310 static void do_clobber_return_reg PARAMS ((rtx, void *));
311 static void do_use_return_reg PARAMS ((rtx, void *));
313 /* Pointer to chain of `struct function' for containing functions. */
314 static struct function *outer_function_chain;
316 /* Given a function decl for a containing function,
317 return the `struct function' for it. */
320 find_function_data (decl)
325 for (p = outer_function_chain; p; p = p->outer)
332 /* Save the current context for compilation of a nested function.
333 This is called from language-specific code. The caller should use
334 the save_lang_status callback to save any language-specific state,
335 since this function knows only about language-independent
339 push_function_context_to (context)
346 if (context == current_function_decl)
347 cfun->contains_functions = 1;
350 struct function *containing = find_function_data (context);
351 containing->contains_functions = 1;
356 init_dummy_function_start ();
359 p->outer = outer_function_chain;
360 outer_function_chain = p;
361 p->fixup_var_refs_queue = 0;
363 if (save_lang_status)
364 (*save_lang_status) (p);
370 push_function_context ()
372 push_function_context_to (current_function_decl);
375 /* Restore the last saved context, at the end of a nested function.
376 This function is called from language-specific code. */
379 pop_function_context_from (context)
380 tree context ATTRIBUTE_UNUSED;
382 struct function *p = outer_function_chain;
383 struct var_refs_queue *queue;
386 outer_function_chain = p->outer;
388 current_function_decl = p->decl;
391 restore_emit_status (p);
393 if (restore_lang_status)
394 (*restore_lang_status) (p);
396 /* Finish doing put_var_into_stack for any of our variables which became
397 addressable during the nested function. If only one entry has to be
398 fixed up, just do that one. Otherwise, first make a list of MEMs that
399 are not to be unshared. */
400 if (p->fixup_var_refs_queue == 0)
402 else if (p->fixup_var_refs_queue->next == 0)
403 fixup_var_refs (p->fixup_var_refs_queue->modified,
404 p->fixup_var_refs_queue->promoted_mode,
405 p->fixup_var_refs_queue->unsignedp,
406 p->fixup_var_refs_queue->modified, 0);
411 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
412 list = gen_rtx_EXPR_LIST (VOIDmode, queue->modified, list);
414 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
415 fixup_var_refs (queue->modified, queue->promoted_mode,
416 queue->unsignedp, list, 0);
420 p->fixup_var_refs_queue = 0;
422 /* Reset variables that have known state during rtx generation. */
423 rtx_equal_function_value_matters = 1;
424 virtuals_instantiated = 0;
425 generating_concat_p = 1;
429 pop_function_context ()
431 pop_function_context_from (current_function_decl);
434 /* Clear out all parts of the state in F that can safely be discarded
435 after the function has been parsed, but not compiled, to let
436 garbage collection reclaim the memory. */
439 free_after_parsing (f)
442 /* f->expr->forced_labels is used by code generation. */
443 /* f->emit->regno_reg_rtx is used by code generation. */
444 /* f->varasm is used by code generation. */
445 /* f->eh->eh_return_stub_label is used by code generation. */
447 if (free_lang_status)
448 (*free_lang_status) (f);
449 free_stmt_status (f);
452 /* Clear out all parts of the state in F that can safely be discarded
453 after the function has been compiled, to let garbage collection
454 reclaim the memory. */
457 free_after_compilation (f)
461 free_expr_status (f);
462 free_emit_status (f);
463 free_varasm_status (f);
465 if (free_machine_status)
466 (*free_machine_status) (f);
468 if (f->x_parm_reg_stack_loc)
469 free (f->x_parm_reg_stack_loc);
471 f->x_temp_slots = NULL;
472 f->arg_offset_rtx = NULL;
473 f->return_rtx = NULL;
474 f->internal_arg_pointer = NULL;
475 f->x_nonlocal_labels = NULL;
476 f->x_nonlocal_goto_handler_slots = NULL;
477 f->x_nonlocal_goto_handler_labels = NULL;
478 f->x_nonlocal_goto_stack_level = NULL;
479 f->x_cleanup_label = NULL;
480 f->x_return_label = NULL;
481 f->x_save_expr_regs = NULL;
482 f->x_stack_slot_list = NULL;
483 f->x_rtl_expr_chain = NULL;
484 f->x_tail_recursion_label = NULL;
485 f->x_tail_recursion_reentry = NULL;
486 f->x_arg_pointer_save_area = NULL;
487 f->x_clobber_return_insn = NULL;
488 f->x_context_display = NULL;
489 f->x_trampoline_list = NULL;
490 f->x_parm_birth_insn = NULL;
491 f->x_last_parm_insn = NULL;
492 f->x_parm_reg_stack_loc = NULL;
493 f->fixup_var_refs_queue = NULL;
494 f->original_arg_vector = NULL;
495 f->original_decl_initial = NULL;
496 f->inl_last_parm_insn = NULL;
497 f->epilogue_delay_list = NULL;
500 /* Allocate fixed slots in the stack frame of the current function. */
502 /* Return size needed for stack frame based on slots so far allocated in
504 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
505 the caller may have to do that. */
508 get_func_frame_size (f)
511 #ifdef FRAME_GROWS_DOWNWARD
512 return -f->x_frame_offset;
514 return f->x_frame_offset;
518 /* Return size needed for stack frame based on slots so far allocated.
519 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
520 the caller may have to do that. */
524 return get_func_frame_size (cfun);
527 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
528 with machine mode MODE.
530 ALIGN controls the amount of alignment for the address of the slot:
531 0 means according to MODE,
532 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
533 positive specifies alignment boundary in bits.
535 We do not round to stack_boundary here.
537 FUNCTION specifies the function to allocate in. */
540 assign_stack_local_1 (mode, size, align, function)
541 enum machine_mode mode;
544 struct function *function;
547 int bigend_correction = 0;
549 int frame_off, frame_alignment, frame_phase;
556 alignment = BIGGEST_ALIGNMENT;
558 alignment = GET_MODE_ALIGNMENT (mode);
560 /* Allow the target to (possibly) increase the alignment of this
562 type = type_for_mode (mode, 0);
564 alignment = LOCAL_ALIGNMENT (type, alignment);
566 alignment /= BITS_PER_UNIT;
568 else if (align == -1)
570 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
571 size = CEIL_ROUND (size, alignment);
574 alignment = align / BITS_PER_UNIT;
576 #ifdef FRAME_GROWS_DOWNWARD
577 function->x_frame_offset -= size;
580 /* Ignore alignment we can't do with expected alignment of the boundary. */
581 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
582 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
584 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
585 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
587 /* Calculate how many bytes the start of local variables is off from
589 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
590 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
591 frame_phase = frame_off ? frame_alignment - frame_off : 0;
593 /* Round frame offset to that alignment.
594 We must be careful here, since FRAME_OFFSET might be negative and
595 division with a negative dividend isn't as well defined as we might
596 like. So we instead assume that ALIGNMENT is a power of two and
597 use logical operations which are unambiguous. */
598 #ifdef FRAME_GROWS_DOWNWARD
599 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
601 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase;
604 /* On a big-endian machine, if we are allocating more space than we will use,
605 use the least significant bytes of those that are allocated. */
606 if (BYTES_BIG_ENDIAN && mode != BLKmode)
607 bigend_correction = size - GET_MODE_SIZE (mode);
609 /* If we have already instantiated virtual registers, return the actual
610 address relative to the frame pointer. */
611 if (function == cfun && virtuals_instantiated)
612 addr = plus_constant (frame_pointer_rtx,
613 (frame_offset + bigend_correction
614 + STARTING_FRAME_OFFSET));
616 addr = plus_constant (virtual_stack_vars_rtx,
617 function->x_frame_offset + bigend_correction);
619 #ifndef FRAME_GROWS_DOWNWARD
620 function->x_frame_offset += size;
623 x = gen_rtx_MEM (mode, addr);
625 function->x_stack_slot_list
626 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
631 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
635 assign_stack_local (mode, size, align)
636 enum machine_mode mode;
640 return assign_stack_local_1 (mode, size, align, cfun);
643 /* Allocate a temporary stack slot and record it for possible later
646 MODE is the machine mode to be given to the returned rtx.
648 SIZE is the size in units of the space required. We do no rounding here
649 since assign_stack_local will do any required rounding.
651 KEEP is 1 if this slot is to be retained after a call to
652 free_temp_slots. Automatic variables for a block are allocated
653 with this flag. KEEP is 2 if we allocate a longer term temporary,
654 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
655 if we are to allocate something at an inner level to be treated as
656 a variable in the block (e.g., a SAVE_EXPR).
658 TYPE is the type that will be used for the stack slot. */
661 assign_stack_temp_for_type (mode, size, keep, type)
662 enum machine_mode mode;
668 struct temp_slot *p, *best_p = 0;
670 /* If SIZE is -1 it means that somebody tried to allocate a temporary
671 of a variable size. */
676 align = BIGGEST_ALIGNMENT;
678 align = GET_MODE_ALIGNMENT (mode);
681 type = type_for_mode (mode, 0);
684 align = LOCAL_ALIGNMENT (type, align);
686 /* Try to find an available, already-allocated temporary of the proper
687 mode which meets the size and alignment requirements. Choose the
688 smallest one with the closest alignment. */
689 for (p = temp_slots; p; p = p->next)
690 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
692 && objects_must_conflict_p (p->type, type)
693 && (best_p == 0 || best_p->size > p->size
694 || (best_p->size == p->size && best_p->align > p->align)))
696 if (p->align == align && p->size == size)
704 /* Make our best, if any, the one to use. */
707 /* If there are enough aligned bytes left over, make them into a new
708 temp_slot so that the extra bytes don't get wasted. Do this only
709 for BLKmode slots, so that we can be sure of the alignment. */
710 if (GET_MODE (best_p->slot) == BLKmode)
712 int alignment = best_p->align / BITS_PER_UNIT;
713 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
715 if (best_p->size - rounded_size >= alignment)
717 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
718 p->in_use = p->addr_taken = 0;
719 p->size = best_p->size - rounded_size;
720 p->base_offset = best_p->base_offset + rounded_size;
721 p->full_size = best_p->full_size - rounded_size;
722 p->slot = gen_rtx_MEM (BLKmode,
723 plus_constant (XEXP (best_p->slot, 0),
725 p->align = best_p->align;
728 p->type = best_p->type;
729 p->next = temp_slots;
732 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
735 best_p->size = rounded_size;
736 best_p->full_size = rounded_size;
743 /* If we still didn't find one, make a new temporary. */
746 HOST_WIDE_INT frame_offset_old = frame_offset;
748 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot));
750 /* We are passing an explicit alignment request to assign_stack_local.
751 One side effect of that is assign_stack_local will not round SIZE
752 to ensure the frame offset remains suitably aligned.
754 So for requests which depended on the rounding of SIZE, we go ahead
755 and round it now. We also make sure ALIGNMENT is at least
756 BIGGEST_ALIGNMENT. */
757 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
759 p->slot = assign_stack_local (mode,
761 ? CEIL_ROUND (size, align / BITS_PER_UNIT)
767 /* The following slot size computation is necessary because we don't
768 know the actual size of the temporary slot until assign_stack_local
769 has performed all the frame alignment and size rounding for the
770 requested temporary. Note that extra space added for alignment
771 can be either above or below this stack slot depending on which
772 way the frame grows. We include the extra space if and only if it
773 is above this slot. */
774 #ifdef FRAME_GROWS_DOWNWARD
775 p->size = frame_offset_old - frame_offset;
780 /* Now define the fields used by combine_temp_slots. */
781 #ifdef FRAME_GROWS_DOWNWARD
782 p->base_offset = frame_offset;
783 p->full_size = frame_offset_old - frame_offset;
785 p->base_offset = frame_offset_old;
786 p->full_size = frame_offset - frame_offset_old;
789 p->next = temp_slots;
795 p->rtl_expr = seq_rtl_expr;
800 p->level = target_temp_slot_level;
805 p->level = var_temp_slot_level;
810 p->level = temp_slot_level;
814 /* We may be reusing an old slot, so clear any MEM flags that may have been
816 RTX_UNCHANGING_P (p->slot) = 0;
817 MEM_IN_STRUCT_P (p->slot) = 0;
818 MEM_SCALAR_P (p->slot) = 0;
819 MEM_VOLATILE_P (p->slot) = 0;
820 set_mem_alias_set (p->slot, 0);
822 /* If we know the alias set for the memory that will be used, use
823 it. If there's no TYPE, then we don't know anything about the
824 alias set for the memory. */
825 set_mem_alias_set (p->slot, type ? get_alias_set (type) : 0);
826 set_mem_align (p->slot, align);
828 /* If a type is specified, set the relevant flags. */
831 RTX_UNCHANGING_P (p->slot) = TYPE_READONLY (type);
832 MEM_VOLATILE_P (p->slot) = TYPE_VOLATILE (type);
833 MEM_SET_IN_STRUCT_P (p->slot, AGGREGATE_TYPE_P (type));
839 /* Allocate a temporary stack slot and record it for possible later
840 reuse. First three arguments are same as in preceding function. */
843 assign_stack_temp (mode, size, keep)
844 enum machine_mode mode;
848 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
851 /* Assign a temporary.
852 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
853 and so that should be used in error messages. In either case, we
854 allocate of the given type.
855 KEEP is as for assign_stack_temp.
856 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
857 it is 0 if a register is OK.
858 DONT_PROMOTE is 1 if we should not promote values in register
862 assign_temp (type_or_decl, keep, memory_required, dont_promote)
866 int dont_promote ATTRIBUTE_UNUSED;
869 enum machine_mode mode;
870 #ifndef PROMOTE_FOR_CALL_ONLY
874 if (DECL_P (type_or_decl))
875 decl = type_or_decl, type = TREE_TYPE (decl);
877 decl = NULL, type = type_or_decl;
879 mode = TYPE_MODE (type);
880 #ifndef PROMOTE_FOR_CALL_ONLY
881 unsignedp = TREE_UNSIGNED (type);
884 if (mode == BLKmode || memory_required)
886 HOST_WIDE_INT size = int_size_in_bytes (type);
889 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
890 problems with allocating the stack space. */
894 /* Unfortunately, we don't yet know how to allocate variable-sized
895 temporaries. However, sometimes we have a fixed upper limit on
896 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
897 instead. This is the case for Chill variable-sized strings. */
898 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
899 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
900 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
901 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
903 /* The size of the temporary may be too large to fit into an integer. */
904 /* ??? Not sure this should happen except for user silliness, so limit
905 this to things that aren't compiler-generated temporaries. The
906 rest of the time we'll abort in assign_stack_temp_for_type. */
907 if (decl && size == -1
908 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
910 error_with_decl (decl, "size of variable `%s' is too large");
914 tmp = assign_stack_temp_for_type (mode, size, keep, type);
918 #ifndef PROMOTE_FOR_CALL_ONLY
920 mode = promote_mode (type, mode, &unsignedp, 0);
923 return gen_reg_rtx (mode);
926 /* Combine temporary stack slots which are adjacent on the stack.
928 This allows for better use of already allocated stack space. This is only
929 done for BLKmode slots because we can be sure that we won't have alignment
930 problems in this case. */
933 combine_temp_slots ()
935 struct temp_slot *p, *q;
936 struct temp_slot *prev_p, *prev_q;
939 /* We can't combine slots, because the information about which slot
940 is in which alias set will be lost. */
941 if (flag_strict_aliasing)
944 /* If there are a lot of temp slots, don't do anything unless
945 high levels of optimization. */
946 if (! flag_expensive_optimizations)
947 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
948 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
951 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
955 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
956 for (q = p->next, prev_q = p; q; q = prev_q->next)
959 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
961 if (p->base_offset + p->full_size == q->base_offset)
963 /* Q comes after P; combine Q into P. */
965 p->full_size += q->full_size;
968 else if (q->base_offset + q->full_size == p->base_offset)
970 /* P comes after Q; combine P into Q. */
972 q->full_size += p->full_size;
977 /* Either delete Q or advance past it. */
979 prev_q->next = q->next;
983 /* Either delete P or advance past it. */
987 prev_p->next = p->next;
989 temp_slots = p->next;
996 /* Find the temp slot corresponding to the object at address X. */
998 static struct temp_slot *
999 find_temp_slot_from_address (x)
1002 struct temp_slot *p;
1005 for (p = temp_slots; p; p = p->next)
1010 else if (XEXP (p->slot, 0) == x
1012 || (GET_CODE (x) == PLUS
1013 && XEXP (x, 0) == virtual_stack_vars_rtx
1014 && GET_CODE (XEXP (x, 1)) == CONST_INT
1015 && INTVAL (XEXP (x, 1)) >= p->base_offset
1016 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
1019 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
1020 for (next = p->address; next; next = XEXP (next, 1))
1021 if (XEXP (next, 0) == x)
1025 /* If we have a sum involving a register, see if it points to a temp
1027 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
1028 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
1030 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG
1031 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
1037 /* Indicate that NEW is an alternate way of referring to the temp slot
1038 that previously was known by OLD. */
1041 update_temp_slot_address (old, new)
1044 struct temp_slot *p;
1046 if (rtx_equal_p (old, new))
1049 p = find_temp_slot_from_address (old);
1051 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1052 is a register, see if one operand of the PLUS is a temporary
1053 location. If so, NEW points into it. Otherwise, if both OLD and
1054 NEW are a PLUS and if there is a register in common between them.
1055 If so, try a recursive call on those values. */
1058 if (GET_CODE (old) != PLUS)
1061 if (GET_CODE (new) == REG)
1063 update_temp_slot_address (XEXP (old, 0), new);
1064 update_temp_slot_address (XEXP (old, 1), new);
1067 else if (GET_CODE (new) != PLUS)
1070 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1071 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1072 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1073 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1074 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1075 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1076 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1077 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1082 /* Otherwise add an alias for the temp's address. */
1083 else if (p->address == 0)
1087 if (GET_CODE (p->address) != EXPR_LIST)
1088 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1090 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1094 /* If X could be a reference to a temporary slot, mark the fact that its
1095 address was taken. */
1098 mark_temp_addr_taken (x)
1101 struct temp_slot *p;
1106 /* If X is not in memory or is at a constant address, it cannot be in
1107 a temporary slot. */
1108 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1111 p = find_temp_slot_from_address (XEXP (x, 0));
1116 /* If X could be a reference to a temporary slot, mark that slot as
1117 belonging to the to one level higher than the current level. If X
1118 matched one of our slots, just mark that one. Otherwise, we can't
1119 easily predict which it is, so upgrade all of them. Kept slots
1120 need not be touched.
1122 This is called when an ({...}) construct occurs and a statement
1123 returns a value in memory. */
1126 preserve_temp_slots (x)
1129 struct temp_slot *p = 0;
1131 /* If there is no result, we still might have some objects whose address
1132 were taken, so we need to make sure they stay around. */
1135 for (p = temp_slots; p; p = p->next)
1136 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1142 /* If X is a register that is being used as a pointer, see if we have
1143 a temporary slot we know it points to. To be consistent with
1144 the code below, we really should preserve all non-kept slots
1145 if we can't find a match, but that seems to be much too costly. */
1146 if (GET_CODE (x) == REG && REG_POINTER (x))
1147 p = find_temp_slot_from_address (x);
1149 /* If X is not in memory or is at a constant address, it cannot be in
1150 a temporary slot, but it can contain something whose address was
1152 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1154 for (p = temp_slots; p; p = p->next)
1155 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1161 /* First see if we can find a match. */
1163 p = find_temp_slot_from_address (XEXP (x, 0));
1167 /* Move everything at our level whose address was taken to our new
1168 level in case we used its address. */
1169 struct temp_slot *q;
1171 if (p->level == temp_slot_level)
1173 for (q = temp_slots; q; q = q->next)
1174 if (q != p && q->addr_taken && q->level == p->level)
1183 /* Otherwise, preserve all non-kept slots at this level. */
1184 for (p = temp_slots; p; p = p->next)
1185 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1189 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1190 with that RTL_EXPR, promote it into a temporary slot at the present
1191 level so it will not be freed when we free slots made in the
1195 preserve_rtl_expr_result (x)
1198 struct temp_slot *p;
1200 /* If X is not in memory or is at a constant address, it cannot be in
1201 a temporary slot. */
1202 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1205 /* If we can find a match, move it to our level unless it is already at
1207 p = find_temp_slot_from_address (XEXP (x, 0));
1210 p->level = MIN (p->level, temp_slot_level);
1217 /* Free all temporaries used so far. This is normally called at the end
1218 of generating code for a statement. Don't free any temporaries
1219 currently in use for an RTL_EXPR that hasn't yet been emitted.
1220 We could eventually do better than this since it can be reused while
1221 generating the same RTL_EXPR, but this is complex and probably not
1227 struct temp_slot *p;
1229 for (p = temp_slots; p; p = p->next)
1230 if (p->in_use && p->level == temp_slot_level && ! p->keep
1231 && p->rtl_expr == 0)
1234 combine_temp_slots ();
1237 /* Free all temporary slots used in T, an RTL_EXPR node. */
1240 free_temps_for_rtl_expr (t)
1243 struct temp_slot *p;
1245 for (p = temp_slots; p; p = p->next)
1246 if (p->rtl_expr == t)
1248 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1249 needs to be preserved. This can happen if a temporary in
1250 the RTL_EXPR was addressed; preserve_temp_slots will move
1251 the temporary into a higher level. */
1252 if (temp_slot_level <= p->level)
1255 p->rtl_expr = NULL_TREE;
1258 combine_temp_slots ();
1261 /* Mark all temporaries ever allocated in this function as not suitable
1262 for reuse until the current level is exited. */
1265 mark_all_temps_used ()
1267 struct temp_slot *p;
1269 for (p = temp_slots; p; p = p->next)
1271 p->in_use = p->keep = 1;
1272 p->level = MIN (p->level, temp_slot_level);
1276 /* Push deeper into the nesting level for stack temporaries. */
1284 /* Likewise, but save the new level as the place to allocate variables
1289 push_temp_slots_for_block ()
1293 var_temp_slot_level = temp_slot_level;
1296 /* Likewise, but save the new level as the place to allocate temporaries
1297 for TARGET_EXPRs. */
1300 push_temp_slots_for_target ()
1304 target_temp_slot_level = temp_slot_level;
1307 /* Set and get the value of target_temp_slot_level. The only
1308 permitted use of these functions is to save and restore this value. */
1311 get_target_temp_slot_level ()
1313 return target_temp_slot_level;
1317 set_target_temp_slot_level (level)
1320 target_temp_slot_level = level;
1324 /* Pop a temporary nesting level. All slots in use in the current level
1330 struct temp_slot *p;
1332 for (p = temp_slots; p; p = p->next)
1333 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1336 combine_temp_slots ();
1341 /* Initialize temporary slots. */
1346 /* We have not allocated any temporaries yet. */
1348 temp_slot_level = 0;
1349 var_temp_slot_level = 0;
1350 target_temp_slot_level = 0;
1353 /* Retroactively move an auto variable from a register to a stack slot.
1354 This is done when an address-reference to the variable is seen. */
1357 put_var_into_stack (decl)
1361 enum machine_mode promoted_mode, decl_mode;
1362 struct function *function = 0;
1364 int can_use_addressof;
1365 int volatilep = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl);
1366 int usedp = (TREE_USED (decl)
1367 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0));
1369 context = decl_function_context (decl);
1371 /* Get the current rtl used for this object and its original mode. */
1372 reg = (TREE_CODE (decl) == SAVE_EXPR
1373 ? SAVE_EXPR_RTL (decl)
1374 : DECL_RTL_IF_SET (decl));
1376 /* No need to do anything if decl has no rtx yet
1377 since in that case caller is setting TREE_ADDRESSABLE
1378 and a stack slot will be assigned when the rtl is made. */
1382 /* Get the declared mode for this object. */
1383 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1384 : DECL_MODE (decl));
1385 /* Get the mode it's actually stored in. */
1386 promoted_mode = GET_MODE (reg);
1388 /* If this variable comes from an outer function, find that
1389 function's saved context. Don't use find_function_data here,
1390 because it might not be in any active function.
1391 FIXME: Is that really supposed to happen?
1392 It does in ObjC at least. */
1393 if (context != current_function_decl && context != inline_function_decl)
1394 for (function = outer_function_chain; function; function = function->outer)
1395 if (function->decl == context)
1398 /* If this is a variable-size object with a pseudo to address it,
1399 put that pseudo into the stack, if the var is nonlocal. */
1400 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl)
1401 && GET_CODE (reg) == MEM
1402 && GET_CODE (XEXP (reg, 0)) == REG
1403 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1405 reg = XEXP (reg, 0);
1406 decl_mode = promoted_mode = GET_MODE (reg);
1412 /* FIXME make it work for promoted modes too */
1413 && decl_mode == promoted_mode
1414 #ifdef NON_SAVING_SETJMP
1415 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1419 /* If we can't use ADDRESSOF, make sure we see through one we already
1421 if (! can_use_addressof && GET_CODE (reg) == MEM
1422 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1423 reg = XEXP (XEXP (reg, 0), 0);
1425 /* Now we should have a value that resides in one or more pseudo regs. */
1427 if (GET_CODE (reg) == REG)
1429 /* If this variable lives in the current function and we don't need
1430 to put things in the stack for the sake of setjmp, try to keep it
1431 in a register until we know we actually need the address. */
1432 if (can_use_addressof)
1433 gen_mem_addressof (reg, decl);
1435 put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode,
1436 decl_mode, volatilep, 0, usedp, 0);
1438 else if (GET_CODE (reg) == CONCAT)
1440 /* A CONCAT contains two pseudos; put them both in the stack.
1441 We do it so they end up consecutive.
1442 We fixup references to the parts only after we fixup references
1443 to the whole CONCAT, lest we do double fixups for the latter
1445 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1446 tree part_type = type_for_mode (part_mode, 0);
1447 rtx lopart = XEXP (reg, 0);
1448 rtx hipart = XEXP (reg, 1);
1449 #ifdef FRAME_GROWS_DOWNWARD
1450 /* Since part 0 should have a lower address, do it second. */
1451 put_reg_into_stack (function, hipart, part_type, part_mode,
1452 part_mode, volatilep, 0, 0, 0);
1453 put_reg_into_stack (function, lopart, part_type, part_mode,
1454 part_mode, volatilep, 0, 0, 0);
1456 put_reg_into_stack (function, lopart, part_type, part_mode,
1457 part_mode, volatilep, 0, 0, 0);
1458 put_reg_into_stack (function, hipart, part_type, part_mode,
1459 part_mode, volatilep, 0, 0, 0);
1462 /* Change the CONCAT into a combined MEM for both parts. */
1463 PUT_CODE (reg, MEM);
1464 MEM_ATTRS (reg) = 0;
1466 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1467 already computed alias sets. Here we want to re-generate. */
1469 SET_DECL_RTL (decl, NULL);
1470 set_mem_attributes (reg, decl, 1);
1472 SET_DECL_RTL (decl, reg);
1474 /* The two parts are in memory order already.
1475 Use the lower parts address as ours. */
1476 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1477 /* Prevent sharing of rtl that might lose. */
1478 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1479 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1482 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl),
1484 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0);
1485 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0);
1492 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1493 into the stack frame of FUNCTION (0 means the current function).
1494 DECL_MODE is the machine mode of the user-level data type.
1495 PROMOTED_MODE is the machine mode of the register.
1496 VOLATILE_P is nonzero if this is for a "volatile" decl.
1497 USED_P is nonzero if this reg might have already been used in an insn. */
1500 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p,
1501 original_regno, used_p, ht)
1502 struct function *function;
1505 enum machine_mode promoted_mode, decl_mode;
1507 unsigned int original_regno;
1509 struct hash_table *ht;
1511 struct function *func = function ? function : cfun;
1513 unsigned int regno = original_regno;
1516 regno = REGNO (reg);
1518 if (regno < func->x_max_parm_reg)
1519 new = func->x_parm_reg_stack_loc[regno];
1522 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func);
1524 PUT_CODE (reg, MEM);
1525 PUT_MODE (reg, decl_mode);
1526 XEXP (reg, 0) = XEXP (new, 0);
1527 MEM_ATTRS (reg) = 0;
1528 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1529 MEM_VOLATILE_P (reg) = volatile_p;
1531 /* If this is a memory ref that contains aggregate components,
1532 mark it as such for cse and loop optimize. If we are reusing a
1533 previously generated stack slot, then we need to copy the bit in
1534 case it was set for other reasons. For instance, it is set for
1535 __builtin_va_alist. */
1538 MEM_SET_IN_STRUCT_P (reg,
1539 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1540 set_mem_alias_set (reg, get_alias_set (type));
1544 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht);
1547 /* Make sure that all refs to the variable, previously made
1548 when it was a register, are fixed up to be valid again.
1549 See function above for meaning of arguments. */
1552 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht)
1553 struct function *function;
1556 enum machine_mode promoted_mode;
1557 struct hash_table *ht;
1559 int unsigned_p = type ? TREE_UNSIGNED (type) : 0;
1563 struct var_refs_queue *temp;
1566 = (struct var_refs_queue *) ggc_alloc (sizeof (struct var_refs_queue));
1567 temp->modified = reg;
1568 temp->promoted_mode = promoted_mode;
1569 temp->unsignedp = unsigned_p;
1570 temp->next = function->fixup_var_refs_queue;
1571 function->fixup_var_refs_queue = temp;
1574 /* Variable is local; fix it up now. */
1575 fixup_var_refs (reg, promoted_mode, unsigned_p, reg, ht);
1579 fixup_var_refs (var, promoted_mode, unsignedp, may_share, ht)
1581 enum machine_mode promoted_mode;
1583 struct hash_table *ht;
1587 rtx first_insn = get_insns ();
1588 struct sequence_stack *stack = seq_stack;
1589 tree rtl_exps = rtl_expr_chain;
1591 /* If there's a hash table, it must record all uses of VAR. */
1596 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp,
1601 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp,
1602 stack == 0, may_share);
1604 /* Scan all pending sequences too. */
1605 for (; stack; stack = stack->next)
1607 push_to_full_sequence (stack->first, stack->last);
1608 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp,
1609 stack->next != 0, may_share);
1610 /* Update remembered end of sequence
1611 in case we added an insn at the end. */
1612 stack->last = get_last_insn ();
1616 /* Scan all waiting RTL_EXPRs too. */
1617 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1619 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1620 if (seq != const0_rtx && seq != 0)
1622 push_to_sequence (seq);
1623 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1630 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1631 some part of an insn. Return a struct fixup_replacement whose OLD
1632 value is equal to X. Allocate a new structure if no such entry exists. */
1634 static struct fixup_replacement *
1635 find_fixup_replacement (replacements, x)
1636 struct fixup_replacement **replacements;
1639 struct fixup_replacement *p;
1641 /* See if we have already replaced this. */
1642 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1647 p = (struct fixup_replacement *) xmalloc (sizeof (struct fixup_replacement));
1650 p->next = *replacements;
1657 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1658 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1659 for the current function. MAY_SHARE is either a MEM that is not
1660 to be unshared or a list of them. */
1663 fixup_var_refs_insns (insn, var, promoted_mode, unsignedp, toplevel, may_share)
1666 enum machine_mode promoted_mode;
1673 /* fixup_var_refs_insn might modify insn, so save its next
1675 rtx next = NEXT_INSN (insn);
1677 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1678 the three sequences they (potentially) contain, and process
1679 them recursively. The CALL_INSN itself is not interesting. */
1681 if (GET_CODE (insn) == CALL_INSN
1682 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1686 /* Look at the Normal call, sibling call and tail recursion
1687 sequences attached to the CALL_PLACEHOLDER. */
1688 for (i = 0; i < 3; i++)
1690 rtx seq = XEXP (PATTERN (insn), i);
1693 push_to_sequence (seq);
1694 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1696 XEXP (PATTERN (insn), i) = get_insns ();
1702 else if (INSN_P (insn))
1703 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel,
1710 /* Look up the insns which reference VAR in HT and fix them up. Other
1711 arguments are the same as fixup_var_refs_insns.
1713 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1714 because the hash table will point straight to the interesting insn
1715 (inside the CALL_PLACEHOLDER). */
1718 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp, may_share)
1719 struct hash_table *ht;
1721 enum machine_mode promoted_mode;
1725 struct insns_for_mem_entry *ime
1726 = (struct insns_for_mem_entry *) hash_lookup (ht, var,
1727 /*create=*/0, /*copy=*/0);
1730 for (insn_list = ime->insns; insn_list != 0; insn_list = XEXP (insn_list, 1))
1731 if (INSN_P (XEXP (insn_list, 0)))
1732 fixup_var_refs_insn (XEXP (insn_list, 0), var, promoted_mode,
1733 unsignedp, 1, may_share);
1737 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1738 the insn under examination, VAR is the variable to fix up
1739 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1740 TOPLEVEL is nonzero if this is the main insn chain for this
1744 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel, no_share)
1747 enum machine_mode promoted_mode;
1753 rtx set, prev, prev_set;
1756 /* Remember the notes in case we delete the insn. */
1757 note = REG_NOTES (insn);
1759 /* If this is a CLOBBER of VAR, delete it.
1761 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1762 and REG_RETVAL notes too. */
1763 if (GET_CODE (PATTERN (insn)) == CLOBBER
1764 && (XEXP (PATTERN (insn), 0) == var
1765 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1766 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1767 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1769 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1770 /* The REG_LIBCALL note will go away since we are going to
1771 turn INSN into a NOTE, so just delete the
1772 corresponding REG_RETVAL note. */
1773 remove_note (XEXP (note, 0),
1774 find_reg_note (XEXP (note, 0), REG_RETVAL,
1780 /* The insn to load VAR from a home in the arglist
1781 is now a no-op. When we see it, just delete it.
1782 Similarly if this is storing VAR from a register from which
1783 it was loaded in the previous insn. This will occur
1784 when an ADDRESSOF was made for an arglist slot. */
1786 && (set = single_set (insn)) != 0
1787 && SET_DEST (set) == var
1788 /* If this represents the result of an insn group,
1789 don't delete the insn. */
1790 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1791 && (rtx_equal_p (SET_SRC (set), var)
1792 || (GET_CODE (SET_SRC (set)) == REG
1793 && (prev = prev_nonnote_insn (insn)) != 0
1794 && (prev_set = single_set (prev)) != 0
1795 && SET_DEST (prev_set) == SET_SRC (set)
1796 && rtx_equal_p (SET_SRC (prev_set), var))))
1802 struct fixup_replacement *replacements = 0;
1803 rtx next_insn = NEXT_INSN (insn);
1805 if (SMALL_REGISTER_CLASSES)
1807 /* If the insn that copies the results of a CALL_INSN
1808 into a pseudo now references VAR, we have to use an
1809 intermediate pseudo since we want the life of the
1810 return value register to be only a single insn.
1812 If we don't use an intermediate pseudo, such things as
1813 address computations to make the address of VAR valid
1814 if it is not can be placed between the CALL_INSN and INSN.
1816 To make sure this doesn't happen, we record the destination
1817 of the CALL_INSN and see if the next insn uses both that
1820 if (call_dest != 0 && GET_CODE (insn) == INSN
1821 && reg_mentioned_p (var, PATTERN (insn))
1822 && reg_mentioned_p (call_dest, PATTERN (insn)))
1824 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1826 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1828 PATTERN (insn) = replace_rtx (PATTERN (insn),
1832 if (GET_CODE (insn) == CALL_INSN
1833 && GET_CODE (PATTERN (insn)) == SET)
1834 call_dest = SET_DEST (PATTERN (insn));
1835 else if (GET_CODE (insn) == CALL_INSN
1836 && GET_CODE (PATTERN (insn)) == PARALLEL
1837 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1838 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1843 /* See if we have to do anything to INSN now that VAR is in
1844 memory. If it needs to be loaded into a pseudo, use a single
1845 pseudo for the entire insn in case there is a MATCH_DUP
1846 between two operands. We pass a pointer to the head of
1847 a list of struct fixup_replacements. If fixup_var_refs_1
1848 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1849 it will record them in this list.
1851 If it allocated a pseudo for any replacement, we copy into
1854 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1855 &replacements, no_share);
1857 /* If this is last_parm_insn, and any instructions were output
1858 after it to fix it up, then we must set last_parm_insn to
1859 the last such instruction emitted. */
1860 if (insn == last_parm_insn)
1861 last_parm_insn = PREV_INSN (next_insn);
1863 while (replacements)
1865 struct fixup_replacement *next;
1867 if (GET_CODE (replacements->new) == REG)
1872 /* OLD might be a (subreg (mem)). */
1873 if (GET_CODE (replacements->old) == SUBREG)
1875 = fixup_memory_subreg (replacements->old, insn,
1879 = fixup_stack_1 (replacements->old, insn);
1881 insert_before = insn;
1883 /* If we are changing the mode, do a conversion.
1884 This might be wasteful, but combine.c will
1885 eliminate much of the waste. */
1887 if (GET_MODE (replacements->new)
1888 != GET_MODE (replacements->old))
1891 convert_move (replacements->new,
1892 replacements->old, unsignedp);
1893 seq = gen_sequence ();
1897 seq = gen_move_insn (replacements->new,
1900 emit_insn_before (seq, insert_before);
1903 next = replacements->next;
1904 free (replacements);
1905 replacements = next;
1909 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1910 But don't touch other insns referred to by reg-notes;
1911 we will get them elsewhere. */
1914 if (GET_CODE (note) != INSN_LIST)
1916 = walk_fixup_memory_subreg (XEXP (note, 0), insn,
1918 note = XEXP (note, 1);
1922 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1923 See if the rtx expression at *LOC in INSN needs to be changed.
1925 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1926 contain a list of original rtx's and replacements. If we find that we need
1927 to modify this insn by replacing a memory reference with a pseudo or by
1928 making a new MEM to implement a SUBREG, we consult that list to see if
1929 we have already chosen a replacement. If none has already been allocated,
1930 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1931 or the SUBREG, as appropriate, to the pseudo. */
1934 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements, no_share)
1936 enum machine_mode promoted_mode;
1939 struct fixup_replacement **replacements;
1944 RTX_CODE code = GET_CODE (x);
1947 struct fixup_replacement *replacement;
1952 if (XEXP (x, 0) == var)
1954 /* Prevent sharing of rtl that might lose. */
1955 rtx sub = copy_rtx (XEXP (var, 0));
1957 if (! validate_change (insn, loc, sub, 0))
1959 rtx y = gen_reg_rtx (GET_MODE (sub));
1962 /* We should be able to replace with a register or all is lost.
1963 Note that we can't use validate_change to verify this, since
1964 we're not caring for replacing all dups simultaneously. */
1965 if (! validate_replace_rtx (*loc, y, insn))
1968 /* Careful! First try to recognize a direct move of the
1969 value, mimicking how things are done in gen_reload wrt
1970 PLUS. Consider what happens when insn is a conditional
1971 move instruction and addsi3 clobbers flags. */
1974 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1975 seq = gen_sequence ();
1978 if (recog_memoized (new_insn) < 0)
1980 /* That failed. Fall back on force_operand and hope. */
1983 sub = force_operand (sub, y);
1985 emit_insn (gen_move_insn (y, sub));
1986 seq = gen_sequence ();
1991 /* Don't separate setter from user. */
1992 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1993 insn = PREV_INSN (insn);
1996 emit_insn_before (seq, insn);
2004 /* If we already have a replacement, use it. Otherwise,
2005 try to fix up this address in case it is invalid. */
2007 replacement = find_fixup_replacement (replacements, var);
2008 if (replacement->new)
2010 *loc = replacement->new;
2014 *loc = replacement->new = x = fixup_stack_1 (x, insn);
2016 /* Unless we are forcing memory to register or we changed the mode,
2017 we can leave things the way they are if the insn is valid. */
2019 INSN_CODE (insn) = -1;
2020 if (! flag_force_mem && GET_MODE (x) == promoted_mode
2021 && recog_memoized (insn) >= 0)
2024 *loc = replacement->new = gen_reg_rtx (promoted_mode);
2028 /* If X contains VAR, we need to unshare it here so that we update
2029 each occurrence separately. But all identical MEMs in one insn
2030 must be replaced with the same rtx because of the possibility of
2033 if (reg_mentioned_p (var, x))
2035 replacement = find_fixup_replacement (replacements, x);
2036 if (replacement->new == 0)
2037 replacement->new = copy_most_rtx (x, no_share);
2039 *loc = x = replacement->new;
2040 code = GET_CODE (x);
2057 /* Note that in some cases those types of expressions are altered
2058 by optimize_bit_field, and do not survive to get here. */
2059 if (XEXP (x, 0) == var
2060 || (GET_CODE (XEXP (x, 0)) == SUBREG
2061 && SUBREG_REG (XEXP (x, 0)) == var))
2063 /* Get TEM as a valid MEM in the mode presently in the insn.
2065 We don't worry about the possibility of MATCH_DUP here; it
2066 is highly unlikely and would be tricky to handle. */
2069 if (GET_CODE (tem) == SUBREG)
2071 if (GET_MODE_BITSIZE (GET_MODE (tem))
2072 > GET_MODE_BITSIZE (GET_MODE (var)))
2074 replacement = find_fixup_replacement (replacements, var);
2075 if (replacement->new == 0)
2076 replacement->new = gen_reg_rtx (GET_MODE (var));
2077 SUBREG_REG (tem) = replacement->new;
2079 /* The following code works only if we have a MEM, so we
2080 need to handle the subreg here. We directly substitute
2081 it assuming that a subreg must be OK here. We already
2082 scheduled a replacement to copy the mem into the
2088 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2091 tem = fixup_stack_1 (tem, insn);
2093 /* Unless we want to load from memory, get TEM into the proper mode
2094 for an extract from memory. This can only be done if the
2095 extract is at a constant position and length. */
2097 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2098 && GET_CODE (XEXP (x, 2)) == CONST_INT
2099 && ! mode_dependent_address_p (XEXP (tem, 0))
2100 && ! MEM_VOLATILE_P (tem))
2102 enum machine_mode wanted_mode = VOIDmode;
2103 enum machine_mode is_mode = GET_MODE (tem);
2104 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2106 if (GET_CODE (x) == ZERO_EXTRACT)
2108 enum machine_mode new_mode
2109 = mode_for_extraction (EP_extzv, 1);
2110 if (new_mode != MAX_MACHINE_MODE)
2111 wanted_mode = new_mode;
2113 else if (GET_CODE (x) == SIGN_EXTRACT)
2115 enum machine_mode new_mode
2116 = mode_for_extraction (EP_extv, 1);
2117 if (new_mode != MAX_MACHINE_MODE)
2118 wanted_mode = new_mode;
2121 /* If we have a narrower mode, we can do something. */
2122 if (wanted_mode != VOIDmode
2123 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2125 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2126 rtx old_pos = XEXP (x, 2);
2129 /* If the bytes and bits are counted differently, we
2130 must adjust the offset. */
2131 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2132 offset = (GET_MODE_SIZE (is_mode)
2133 - GET_MODE_SIZE (wanted_mode) - offset);
2135 pos %= GET_MODE_BITSIZE (wanted_mode);
2137 newmem = adjust_address_nv (tem, wanted_mode, offset);
2139 /* Make the change and see if the insn remains valid. */
2140 INSN_CODE (insn) = -1;
2141 XEXP (x, 0) = newmem;
2142 XEXP (x, 2) = GEN_INT (pos);
2144 if (recog_memoized (insn) >= 0)
2147 /* Otherwise, restore old position. XEXP (x, 0) will be
2149 XEXP (x, 2) = old_pos;
2153 /* If we get here, the bitfield extract insn can't accept a memory
2154 reference. Copy the input into a register. */
2156 tem1 = gen_reg_rtx (GET_MODE (tem));
2157 emit_insn_before (gen_move_insn (tem1, tem), insn);
2164 if (SUBREG_REG (x) == var)
2166 /* If this is a special SUBREG made because VAR was promoted
2167 from a wider mode, replace it with VAR and call ourself
2168 recursively, this time saying that the object previously
2169 had its current mode (by virtue of the SUBREG). */
2171 if (SUBREG_PROMOTED_VAR_P (x))
2174 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements,
2179 /* If this SUBREG makes VAR wider, it has become a paradoxical
2180 SUBREG with VAR in memory, but these aren't allowed at this
2181 stage of the compilation. So load VAR into a pseudo and take
2182 a SUBREG of that pseudo. */
2183 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2185 replacement = find_fixup_replacement (replacements, var);
2186 if (replacement->new == 0)
2187 replacement->new = gen_reg_rtx (promoted_mode);
2188 SUBREG_REG (x) = replacement->new;
2192 /* See if we have already found a replacement for this SUBREG.
2193 If so, use it. Otherwise, make a MEM and see if the insn
2194 is recognized. If not, or if we should force MEM into a register,
2195 make a pseudo for this SUBREG. */
2196 replacement = find_fixup_replacement (replacements, x);
2197 if (replacement->new)
2199 *loc = replacement->new;
2203 replacement->new = *loc = fixup_memory_subreg (x, insn,
2206 INSN_CODE (insn) = -1;
2207 if (! flag_force_mem && recog_memoized (insn) >= 0)
2210 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2216 /* First do special simplification of bit-field references. */
2217 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2218 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2219 optimize_bit_field (x, insn, 0);
2220 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2221 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2222 optimize_bit_field (x, insn, 0);
2224 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2225 into a register and then store it back out. */
2226 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2227 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2228 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2229 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2230 > GET_MODE_SIZE (GET_MODE (var))))
2232 replacement = find_fixup_replacement (replacements, var);
2233 if (replacement->new == 0)
2234 replacement->new = gen_reg_rtx (GET_MODE (var));
2236 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2237 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2240 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2241 insn into a pseudo and store the low part of the pseudo into VAR. */
2242 if (GET_CODE (SET_DEST (x)) == SUBREG
2243 && SUBREG_REG (SET_DEST (x)) == var
2244 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2245 > GET_MODE_SIZE (GET_MODE (var))))
2247 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2248 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2255 rtx dest = SET_DEST (x);
2256 rtx src = SET_SRC (x);
2257 rtx outerdest = dest;
2259 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2260 || GET_CODE (dest) == SIGN_EXTRACT
2261 || GET_CODE (dest) == ZERO_EXTRACT)
2262 dest = XEXP (dest, 0);
2264 if (GET_CODE (src) == SUBREG)
2265 src = SUBREG_REG (src);
2267 /* If VAR does not appear at the top level of the SET
2268 just scan the lower levels of the tree. */
2270 if (src != var && dest != var)
2273 /* We will need to rerecognize this insn. */
2274 INSN_CODE (insn) = -1;
2276 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var
2277 && mode_for_extraction (EP_insv, -1) != MAX_MACHINE_MODE)
2279 /* Since this case will return, ensure we fixup all the
2281 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2282 insn, replacements, no_share);
2283 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2284 insn, replacements, no_share);
2285 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2286 insn, replacements, no_share);
2288 tem = XEXP (outerdest, 0);
2290 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2291 that may appear inside a ZERO_EXTRACT.
2292 This was legitimate when the MEM was a REG. */
2293 if (GET_CODE (tem) == SUBREG
2294 && SUBREG_REG (tem) == var)
2295 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2297 tem = fixup_stack_1 (tem, insn);
2299 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2300 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2301 && ! mode_dependent_address_p (XEXP (tem, 0))
2302 && ! MEM_VOLATILE_P (tem))
2304 enum machine_mode wanted_mode;
2305 enum machine_mode is_mode = GET_MODE (tem);
2306 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2308 wanted_mode = mode_for_extraction (EP_insv, 0);
2310 /* If we have a narrower mode, we can do something. */
2311 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2313 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2314 rtx old_pos = XEXP (outerdest, 2);
2317 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2318 offset = (GET_MODE_SIZE (is_mode)
2319 - GET_MODE_SIZE (wanted_mode) - offset);
2321 pos %= GET_MODE_BITSIZE (wanted_mode);
2323 newmem = adjust_address_nv (tem, wanted_mode, offset);
2325 /* Make the change and see if the insn remains valid. */
2326 INSN_CODE (insn) = -1;
2327 XEXP (outerdest, 0) = newmem;
2328 XEXP (outerdest, 2) = GEN_INT (pos);
2330 if (recog_memoized (insn) >= 0)
2333 /* Otherwise, restore old position. XEXP (x, 0) will be
2335 XEXP (outerdest, 2) = old_pos;
2339 /* If we get here, the bit-field store doesn't allow memory
2340 or isn't located at a constant position. Load the value into
2341 a register, do the store, and put it back into memory. */
2343 tem1 = gen_reg_rtx (GET_MODE (tem));
2344 emit_insn_before (gen_move_insn (tem1, tem), insn);
2345 emit_insn_after (gen_move_insn (tem, tem1), insn);
2346 XEXP (outerdest, 0) = tem1;
2350 /* STRICT_LOW_PART is a no-op on memory references
2351 and it can cause combinations to be unrecognizable,
2354 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2355 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2357 /* A valid insn to copy VAR into or out of a register
2358 must be left alone, to avoid an infinite loop here.
2359 If the reference to VAR is by a subreg, fix that up,
2360 since SUBREG is not valid for a memref.
2361 Also fix up the address of the stack slot.
2363 Note that we must not try to recognize the insn until
2364 after we know that we have valid addresses and no
2365 (subreg (mem ...) ...) constructs, since these interfere
2366 with determining the validity of the insn. */
2368 if ((SET_SRC (x) == var
2369 || (GET_CODE (SET_SRC (x)) == SUBREG
2370 && SUBREG_REG (SET_SRC (x)) == var))
2371 && (GET_CODE (SET_DEST (x)) == REG
2372 || (GET_CODE (SET_DEST (x)) == SUBREG
2373 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2374 && GET_MODE (var) == promoted_mode
2375 && x == single_set (insn))
2379 if (GET_CODE (SET_SRC (x)) == SUBREG
2380 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
2381 > GET_MODE_SIZE (GET_MODE (var))))
2383 /* This (subreg VAR) is now a paradoxical subreg. We need
2384 to replace VAR instead of the subreg. */
2385 replacement = find_fixup_replacement (replacements, var);
2386 if (replacement->new == NULL_RTX)
2387 replacement->new = gen_reg_rtx (GET_MODE (var));
2388 SUBREG_REG (SET_SRC (x)) = replacement->new;
2392 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2393 if (replacement->new)
2394 SET_SRC (x) = replacement->new;
2395 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2396 SET_SRC (x) = replacement->new
2397 = fixup_memory_subreg (SET_SRC (x), insn, promoted_mode,
2400 SET_SRC (x) = replacement->new
2401 = fixup_stack_1 (SET_SRC (x), insn);
2404 if (recog_memoized (insn) >= 0)
2407 /* INSN is not valid, but we know that we want to
2408 copy SET_SRC (x) to SET_DEST (x) in some way. So
2409 we generate the move and see whether it requires more
2410 than one insn. If it does, we emit those insns and
2411 delete INSN. Otherwise, we an just replace the pattern
2412 of INSN; we have already verified above that INSN has
2413 no other function that to do X. */
2415 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2416 if (GET_CODE (pat) == SEQUENCE)
2418 last = emit_insn_before (pat, insn);
2420 /* INSN might have REG_RETVAL or other important notes, so
2421 we need to store the pattern of the last insn in the
2422 sequence into INSN similarly to the normal case. LAST
2423 should not have REG_NOTES, but we allow them if INSN has
2425 if (REG_NOTES (last) && REG_NOTES (insn))
2427 if (REG_NOTES (last))
2428 REG_NOTES (insn) = REG_NOTES (last);
2429 PATTERN (insn) = PATTERN (last);
2434 PATTERN (insn) = pat;
2439 if ((SET_DEST (x) == var
2440 || (GET_CODE (SET_DEST (x)) == SUBREG
2441 && SUBREG_REG (SET_DEST (x)) == var))
2442 && (GET_CODE (SET_SRC (x)) == REG
2443 || (GET_CODE (SET_SRC (x)) == SUBREG
2444 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2445 && GET_MODE (var) == promoted_mode
2446 && x == single_set (insn))
2450 if (GET_CODE (SET_DEST (x)) == SUBREG)
2451 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn,
2454 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2456 if (recog_memoized (insn) >= 0)
2459 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2460 if (GET_CODE (pat) == SEQUENCE)
2462 last = emit_insn_before (pat, insn);
2464 /* INSN might have REG_RETVAL or other important notes, so
2465 we need to store the pattern of the last insn in the
2466 sequence into INSN similarly to the normal case. LAST
2467 should not have REG_NOTES, but we allow them if INSN has
2469 if (REG_NOTES (last) && REG_NOTES (insn))
2471 if (REG_NOTES (last))
2472 REG_NOTES (insn) = REG_NOTES (last);
2473 PATTERN (insn) = PATTERN (last);
2478 PATTERN (insn) = pat;
2483 /* Otherwise, storing into VAR must be handled specially
2484 by storing into a temporary and copying that into VAR
2485 with a new insn after this one. Note that this case
2486 will be used when storing into a promoted scalar since
2487 the insn will now have different modes on the input
2488 and output and hence will be invalid (except for the case
2489 of setting it to a constant, which does not need any
2490 change if it is valid). We generate extra code in that case,
2491 but combine.c will eliminate it. */
2496 rtx fixeddest = SET_DEST (x);
2497 enum machine_mode temp_mode;
2499 /* STRICT_LOW_PART can be discarded, around a MEM. */
2500 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2501 fixeddest = XEXP (fixeddest, 0);
2502 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2503 if (GET_CODE (fixeddest) == SUBREG)
2505 fixeddest = fixup_memory_subreg (fixeddest, insn,
2507 temp_mode = GET_MODE (fixeddest);
2511 fixeddest = fixup_stack_1 (fixeddest, insn);
2512 temp_mode = promoted_mode;
2515 temp = gen_reg_rtx (temp_mode);
2517 emit_insn_after (gen_move_insn (fixeddest,
2518 gen_lowpart (GET_MODE (fixeddest),
2522 SET_DEST (x) = temp;
2530 /* Nothing special about this RTX; fix its operands. */
2532 fmt = GET_RTX_FORMAT (code);
2533 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2536 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements,
2538 else if (fmt[i] == 'E')
2541 for (j = 0; j < XVECLEN (x, i); j++)
2542 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2543 insn, replacements, no_share);
2548 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2549 The REG was placed on the stack, so X now has the form (SUBREG:m1
2552 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2553 must be emitted to compute NEWADDR, put them before INSN.
2555 UNCRITICAL nonzero means accept paradoxical subregs.
2556 This is used for subregs found inside REG_NOTES. */
2559 fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2562 enum machine_mode promoted_mode;
2566 rtx mem = SUBREG_REG (x);
2567 rtx addr = XEXP (mem, 0);
2568 enum machine_mode mode = GET_MODE (x);
2571 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2572 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (mem)) && ! uncritical)
2575 offset = SUBREG_BYTE (x);
2576 if (BYTES_BIG_ENDIAN)
2577 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2578 the offset so that it points to the right location within the
2580 offset -= (GET_MODE_SIZE (promoted_mode) - GET_MODE_SIZE (GET_MODE (mem)));
2582 if (!flag_force_addr
2583 && memory_address_p (mode, plus_constant (addr, offset)))
2584 /* Shortcut if no insns need be emitted. */
2585 return adjust_address (mem, mode, offset);
2588 result = adjust_address (mem, mode, offset);
2589 emit_insn_before (gen_sequence (), insn);
2594 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2595 Replace subexpressions of X in place.
2596 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2597 Otherwise return X, with its contents possibly altered.
2599 INSN, PROMOTED_MODE and UNCRITICAL are as for
2600 fixup_memory_subreg. */
2603 walk_fixup_memory_subreg (x, insn, promoted_mode, uncritical)
2606 enum machine_mode promoted_mode;
2616 code = GET_CODE (x);
2618 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2619 return fixup_memory_subreg (x, insn, promoted_mode, uncritical);
2621 /* Nothing special about this RTX; fix its operands. */
2623 fmt = GET_RTX_FORMAT (code);
2624 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2627 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn,
2628 promoted_mode, uncritical);
2629 else if (fmt[i] == 'E')
2632 for (j = 0; j < XVECLEN (x, i); j++)
2634 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn,
2635 promoted_mode, uncritical);
2641 /* For each memory ref within X, if it refers to a stack slot
2642 with an out of range displacement, put the address in a temp register
2643 (emitting new insns before INSN to load these registers)
2644 and alter the memory ref to use that register.
2645 Replace each such MEM rtx with a copy, to avoid clobberage. */
2648 fixup_stack_1 (x, insn)
2653 RTX_CODE code = GET_CODE (x);
2658 rtx ad = XEXP (x, 0);
2659 /* If we have address of a stack slot but it's not valid
2660 (displacement is too large), compute the sum in a register. */
2661 if (GET_CODE (ad) == PLUS
2662 && GET_CODE (XEXP (ad, 0)) == REG
2663 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2664 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2665 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2666 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2667 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2669 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2670 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2671 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2672 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2675 if (memory_address_p (GET_MODE (x), ad))
2679 temp = copy_to_reg (ad);
2680 seq = gen_sequence ();
2682 emit_insn_before (seq, insn);
2683 return replace_equiv_address (x, temp);
2688 fmt = GET_RTX_FORMAT (code);
2689 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2692 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2693 else if (fmt[i] == 'E')
2696 for (j = 0; j < XVECLEN (x, i); j++)
2697 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2703 /* Optimization: a bit-field instruction whose field
2704 happens to be a byte or halfword in memory
2705 can be changed to a move instruction.
2707 We call here when INSN is an insn to examine or store into a bit-field.
2708 BODY is the SET-rtx to be altered.
2710 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2711 (Currently this is called only from function.c, and EQUIV_MEM
2715 optimize_bit_field (body, insn, equiv_mem)
2723 enum machine_mode mode;
2725 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2726 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2727 bitfield = SET_DEST (body), destflag = 1;
2729 bitfield = SET_SRC (body), destflag = 0;
2731 /* First check that the field being stored has constant size and position
2732 and is in fact a byte or halfword suitably aligned. */
2734 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2735 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2736 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2738 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2742 /* Now check that the containing word is memory, not a register,
2743 and that it is safe to change the machine mode. */
2745 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2746 memref = XEXP (bitfield, 0);
2747 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2749 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2750 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2751 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2752 memref = SUBREG_REG (XEXP (bitfield, 0));
2753 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2755 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2756 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2759 && ! mode_dependent_address_p (XEXP (memref, 0))
2760 && ! MEM_VOLATILE_P (memref))
2762 /* Now adjust the address, first for any subreg'ing
2763 that we are now getting rid of,
2764 and then for which byte of the word is wanted. */
2766 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2769 /* Adjust OFFSET to count bits from low-address byte. */
2770 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2771 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2772 - offset - INTVAL (XEXP (bitfield, 1)));
2774 /* Adjust OFFSET to count bytes from low-address byte. */
2775 offset /= BITS_PER_UNIT;
2776 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2778 offset += (SUBREG_BYTE (XEXP (bitfield, 0))
2779 / UNITS_PER_WORD) * UNITS_PER_WORD;
2780 if (BYTES_BIG_ENDIAN)
2781 offset -= (MIN (UNITS_PER_WORD,
2782 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2783 - MIN (UNITS_PER_WORD,
2784 GET_MODE_SIZE (GET_MODE (memref))));
2788 memref = adjust_address (memref, mode, offset);
2789 insns = get_insns ();
2791 emit_insns_before (insns, insn);
2793 /* Store this memory reference where
2794 we found the bit field reference. */
2798 validate_change (insn, &SET_DEST (body), memref, 1);
2799 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2801 rtx src = SET_SRC (body);
2802 while (GET_CODE (src) == SUBREG
2803 && SUBREG_BYTE (src) == 0)
2804 src = SUBREG_REG (src);
2805 if (GET_MODE (src) != GET_MODE (memref))
2806 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2807 validate_change (insn, &SET_SRC (body), src, 1);
2809 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2810 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2811 /* This shouldn't happen because anything that didn't have
2812 one of these modes should have got converted explicitly
2813 and then referenced through a subreg.
2814 This is so because the original bit-field was
2815 handled by agg_mode and so its tree structure had
2816 the same mode that memref now has. */
2821 rtx dest = SET_DEST (body);
2823 while (GET_CODE (dest) == SUBREG
2824 && SUBREG_BYTE (dest) == 0
2825 && (GET_MODE_CLASS (GET_MODE (dest))
2826 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2827 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2829 dest = SUBREG_REG (dest);
2831 validate_change (insn, &SET_DEST (body), dest, 1);
2833 if (GET_MODE (dest) == GET_MODE (memref))
2834 validate_change (insn, &SET_SRC (body), memref, 1);
2837 /* Convert the mem ref to the destination mode. */
2838 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2841 convert_move (newreg, memref,
2842 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2846 validate_change (insn, &SET_SRC (body), newreg, 1);
2850 /* See if we can convert this extraction or insertion into
2851 a simple move insn. We might not be able to do so if this
2852 was, for example, part of a PARALLEL.
2854 If we succeed, write out any needed conversions. If we fail,
2855 it is hard to guess why we failed, so don't do anything
2856 special; just let the optimization be suppressed. */
2858 if (apply_change_group () && seq)
2859 emit_insns_before (seq, insn);
2864 /* These routines are responsible for converting virtual register references
2865 to the actual hard register references once RTL generation is complete.
2867 The following four variables are used for communication between the
2868 routines. They contain the offsets of the virtual registers from their
2869 respective hard registers. */
2871 static int in_arg_offset;
2872 static int var_offset;
2873 static int dynamic_offset;
2874 static int out_arg_offset;
2875 static int cfa_offset;
2877 /* In most machines, the stack pointer register is equivalent to the bottom
2880 #ifndef STACK_POINTER_OFFSET
2881 #define STACK_POINTER_OFFSET 0
2884 /* If not defined, pick an appropriate default for the offset of dynamically
2885 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2886 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2888 #ifndef STACK_DYNAMIC_OFFSET
2890 /* The bottom of the stack points to the actual arguments. If
2891 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2892 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2893 stack space for register parameters is not pushed by the caller, but
2894 rather part of the fixed stack areas and hence not included in
2895 `current_function_outgoing_args_size'. Nevertheless, we must allow
2896 for it when allocating stack dynamic objects. */
2898 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2899 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2900 ((ACCUMULATE_OUTGOING_ARGS \
2901 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2902 + (STACK_POINTER_OFFSET)) \
2905 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2906 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2907 + (STACK_POINTER_OFFSET))
2911 /* On most machines, the CFA coincides with the first incoming parm. */
2913 #ifndef ARG_POINTER_CFA_OFFSET
2914 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2917 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2918 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2919 register, for later use if we do need to force REG into the stack. REG is
2920 overwritten by the MEM like in put_reg_into_stack. */
2923 gen_mem_addressof (reg, decl)
2927 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2930 /* Calculate this before we start messing with decl's RTL. */
2931 HOST_WIDE_INT set = decl ? get_alias_set (decl) : 0;
2933 /* If the original REG was a user-variable, then so is the REG whose
2934 address is being taken. Likewise for unchanging. */
2935 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2936 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg);
2938 PUT_CODE (reg, MEM);
2939 MEM_ATTRS (reg) = 0;
2944 tree type = TREE_TYPE (decl);
2945 enum machine_mode decl_mode
2946 = (DECL_P (decl) ? DECL_MODE (decl) : TYPE_MODE (TREE_TYPE (decl)));
2947 rtx decl_rtl = (TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl)
2948 : DECL_RTL_IF_SET (decl));
2950 PUT_MODE (reg, decl_mode);
2952 /* Clear DECL_RTL momentarily so functions below will work
2953 properly, then set it again. */
2954 if (DECL_P (decl) && decl_rtl == reg)
2955 SET_DECL_RTL (decl, 0);
2957 set_mem_attributes (reg, decl, 1);
2958 set_mem_alias_set (reg, set);
2960 if (DECL_P (decl) && decl_rtl == reg)
2961 SET_DECL_RTL (decl, reg);
2963 if (TREE_USED (decl) || (DECL_P (decl) && DECL_INITIAL (decl) != 0))
2964 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), reg, 0);
2967 fixup_var_refs (reg, GET_MODE (reg), 0, reg, 0);
2972 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2975 flush_addressof (decl)
2978 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2979 && DECL_RTL (decl) != 0
2980 && GET_CODE (DECL_RTL (decl)) == MEM
2981 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2982 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2983 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2986 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2989 put_addressof_into_stack (r, ht)
2991 struct hash_table *ht;
2994 int volatile_p, used_p;
2996 rtx reg = XEXP (r, 0);
2998 if (GET_CODE (reg) != REG)
3001 decl = ADDRESSOF_DECL (r);
3004 type = TREE_TYPE (decl);
3005 volatile_p = (TREE_CODE (decl) != SAVE_EXPR
3006 && TREE_THIS_VOLATILE (decl));
3007 used_p = (TREE_USED (decl)
3008 || (DECL_P (decl) && DECL_INITIAL (decl) != 0));
3017 put_reg_into_stack (0, reg, type, GET_MODE (reg), GET_MODE (reg),
3018 volatile_p, ADDRESSOF_REGNO (r), used_p, ht);
3021 /* List of replacements made below in purge_addressof_1 when creating
3022 bitfield insertions. */
3023 static rtx purge_bitfield_addressof_replacements;
3025 /* List of replacements made below in purge_addressof_1 for patterns
3026 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
3027 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
3028 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
3029 enough in complex cases, e.g. when some field values can be
3030 extracted by usage MEM with narrower mode. */
3031 static rtx purge_addressof_replacements;
3033 /* Helper function for purge_addressof. See if the rtx expression at *LOC
3034 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
3035 the stack. If the function returns FALSE then the replacement could not
3039 purge_addressof_1 (loc, insn, force, store, ht)
3043 struct hash_table *ht;
3051 /* Re-start here to avoid recursion in common cases. */
3058 code = GET_CODE (x);
3060 /* If we don't return in any of the cases below, we will recurse inside
3061 the RTX, which will normally result in any ADDRESSOF being forced into
3065 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht);
3066 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht);
3069 else if (code == ADDRESSOF)
3073 if (GET_CODE (XEXP (x, 0)) != MEM)
3075 put_addressof_into_stack (x, ht);
3079 /* We must create a copy of the rtx because it was created by
3080 overwriting a REG rtx which is always shared. */
3081 sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3082 if (validate_change (insn, loc, sub, 0)
3083 || validate_replace_rtx (x, sub, insn))
3087 sub = force_operand (sub, NULL_RTX);
3088 if (! validate_change (insn, loc, sub, 0)
3089 && ! validate_replace_rtx (x, sub, insn))
3092 insns = gen_sequence ();
3094 emit_insn_before (insns, insn);
3098 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3100 rtx sub = XEXP (XEXP (x, 0), 0);
3102 if (GET_CODE (sub) == MEM)
3103 sub = adjust_address_nv (sub, GET_MODE (x), 0);
3104 else if (GET_CODE (sub) == REG
3105 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3107 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3109 int size_x, size_sub;
3113 /* When processing REG_NOTES look at the list of
3114 replacements done on the insn to find the register that X
3118 for (tem = purge_bitfield_addressof_replacements;
3120 tem = XEXP (XEXP (tem, 1), 1))
3121 if (rtx_equal_p (x, XEXP (tem, 0)))
3123 *loc = XEXP (XEXP (tem, 1), 0);
3127 /* See comment for purge_addressof_replacements. */
3128 for (tem = purge_addressof_replacements;
3130 tem = XEXP (XEXP (tem, 1), 1))
3131 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3133 rtx z = XEXP (XEXP (tem, 1), 0);
3135 if (GET_MODE (x) == GET_MODE (z)
3136 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3137 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3140 /* It can happen that the note may speak of things
3141 in a wider (or just different) mode than the
3142 code did. This is especially true of
3145 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0)
3148 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3149 && (GET_MODE_SIZE (GET_MODE (x))
3150 > GET_MODE_SIZE (GET_MODE (z))))
3152 /* This can occur as a result in invalid
3153 pointer casts, e.g. float f; ...
3154 *(long long int *)&f.
3155 ??? We could emit a warning here, but
3156 without a line number that wouldn't be
3158 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3161 z = gen_lowpart (GET_MODE (x), z);
3167 /* Sometimes we may not be able to find the replacement. For
3168 example when the original insn was a MEM in a wider mode,
3169 and the note is part of a sign extension of a narrowed
3170 version of that MEM. Gcc testcase compile/990829-1.c can
3171 generate an example of this situation. Rather than complain
3172 we return false, which will prompt our caller to remove the
3177 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3178 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3180 /* Don't even consider working with paradoxical subregs,
3181 or the moral equivalent seen here. */
3182 if (size_x <= size_sub
3183 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3185 /* Do a bitfield insertion to mirror what would happen
3192 rtx p = PREV_INSN (insn);
3195 val = gen_reg_rtx (GET_MODE (x));
3196 if (! validate_change (insn, loc, val, 0))
3198 /* Discard the current sequence and put the
3199 ADDRESSOF on stack. */
3203 seq = gen_sequence ();
3205 emit_insn_before (seq, insn);
3206 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3210 store_bit_field (sub, size_x, 0, GET_MODE (x),
3211 val, GET_MODE_SIZE (GET_MODE (sub)));
3213 /* Make sure to unshare any shared rtl that store_bit_field
3214 might have created. */
3215 unshare_all_rtl_again (get_insns ());
3217 seq = gen_sequence ();
3219 p = emit_insn_after (seq, insn);
3220 if (NEXT_INSN (insn))
3221 compute_insns_for_mem (NEXT_INSN (insn),
3222 p ? NEXT_INSN (p) : NULL_RTX,
3227 rtx p = PREV_INSN (insn);
3230 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3231 GET_MODE (x), GET_MODE (x),
3232 GET_MODE_SIZE (GET_MODE (sub)));
3234 if (! validate_change (insn, loc, val, 0))
3236 /* Discard the current sequence and put the
3237 ADDRESSOF on stack. */
3242 seq = gen_sequence ();
3244 emit_insn_before (seq, insn);
3245 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3249 /* Remember the replacement so that the same one can be done
3250 on the REG_NOTES. */
3251 purge_bitfield_addressof_replacements
3252 = gen_rtx_EXPR_LIST (VOIDmode, x,
3255 purge_bitfield_addressof_replacements));
3257 /* We replaced with a reg -- all done. */
3262 else if (validate_change (insn, loc, sub, 0))
3264 /* Remember the replacement so that the same one can be done
3265 on the REG_NOTES. */
3266 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3270 for (tem = purge_addressof_replacements;
3272 tem = XEXP (XEXP (tem, 1), 1))
3273 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3275 XEXP (XEXP (tem, 1), 0) = sub;
3278 purge_addressof_replacements
3279 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3280 gen_rtx_EXPR_LIST (VOIDmode, sub,
3281 purge_addressof_replacements));
3289 /* Scan all subexpressions. */
3290 fmt = GET_RTX_FORMAT (code);
3291 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3294 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht);
3295 else if (*fmt == 'E')
3296 for (j = 0; j < XVECLEN (x, i); j++)
3297 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht);
3303 /* Return a new hash table entry in HT. */
3305 static struct hash_entry *
3306 insns_for_mem_newfunc (he, ht, k)
3307 struct hash_entry *he;
3308 struct hash_table *ht;
3309 hash_table_key k ATTRIBUTE_UNUSED;
3311 struct insns_for_mem_entry *ifmhe;
3315 ifmhe = ((struct insns_for_mem_entry *)
3316 hash_allocate (ht, sizeof (struct insns_for_mem_entry)));
3317 ifmhe->insns = NULL_RTX;
3322 /* Return a hash value for K, a REG. */
3324 static unsigned long
3325 insns_for_mem_hash (k)
3328 /* K is really a RTX. Just use the address as the hash value. */
3329 return (unsigned long) k;
3332 /* Return non-zero if K1 and K2 (two REGs) are the same. */
3335 insns_for_mem_comp (k1, k2)
3342 struct insns_for_mem_walk_info
3344 /* The hash table that we are using to record which INSNs use which
3346 struct hash_table *ht;
3348 /* The INSN we are currently processing. */
3351 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3352 to find the insns that use the REGs in the ADDRESSOFs. */
3356 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3357 that might be used in an ADDRESSOF expression, record this INSN in
3358 the hash table given by DATA (which is really a pointer to an
3359 insns_for_mem_walk_info structure). */
3362 insns_for_mem_walk (r, data)
3366 struct insns_for_mem_walk_info *ifmwi
3367 = (struct insns_for_mem_walk_info *) data;
3369 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3370 && GET_CODE (XEXP (*r, 0)) == REG)
3371 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0);
3372 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3374 /* Lookup this MEM in the hashtable, creating it if necessary. */
3375 struct insns_for_mem_entry *ifme
3376 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht,
3381 /* If we have not already recorded this INSN, do so now. Since
3382 we process the INSNs in order, we know that if we have
3383 recorded it it must be at the front of the list. */
3384 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3385 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3392 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3393 which REGs in HT. */
3396 compute_insns_for_mem (insns, last_insn, ht)
3399 struct hash_table *ht;
3402 struct insns_for_mem_walk_info ifmwi;
3405 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3406 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3410 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3414 /* Helper function for purge_addressof called through for_each_rtx.
3415 Returns true iff the rtl is an ADDRESSOF. */
3418 is_addressof (rtl, data)
3420 void *data ATTRIBUTE_UNUSED;
3422 return GET_CODE (*rtl) == ADDRESSOF;
3425 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3426 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3430 purge_addressof (insns)
3434 struct hash_table ht;
3436 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3437 requires a fixup pass over the instruction stream to correct
3438 INSNs that depended on the REG being a REG, and not a MEM. But,
3439 these fixup passes are slow. Furthermore, most MEMs are not
3440 mentioned in very many instructions. So, we speed up the process
3441 by pre-calculating which REGs occur in which INSNs; that allows
3442 us to perform the fixup passes much more quickly. */
3443 hash_table_init (&ht,
3444 insns_for_mem_newfunc,
3446 insns_for_mem_comp);
3447 compute_insns_for_mem (insns, NULL_RTX, &ht);
3449 for (insn = insns; insn; insn = NEXT_INSN (insn))
3450 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3451 || GET_CODE (insn) == CALL_INSN)
3453 if (! purge_addressof_1 (&PATTERN (insn), insn,
3454 asm_noperands (PATTERN (insn)) > 0, 0, &ht))
3455 /* If we could not replace the ADDRESSOFs in the insn,
3456 something is wrong. */
3459 if (! purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, &ht))
3461 /* If we could not replace the ADDRESSOFs in the insn's notes,
3462 we can just remove the offending notes instead. */
3465 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3467 /* If we find a REG_RETVAL note then the insn is a libcall.
3468 Such insns must have REG_EQUAL notes as well, in order
3469 for later passes of the compiler to work. So it is not
3470 safe to delete the notes here, and instead we abort. */
3471 if (REG_NOTE_KIND (note) == REG_RETVAL)
3473 if (for_each_rtx (¬e, is_addressof, NULL))
3474 remove_note (insn, note);
3480 hash_table_free (&ht);
3481 purge_bitfield_addressof_replacements = 0;
3482 purge_addressof_replacements = 0;
3484 /* REGs are shared. purge_addressof will destructively replace a REG
3485 with a MEM, which creates shared MEMs.
3487 Unfortunately, the children of put_reg_into_stack assume that MEMs
3488 referring to the same stack slot are shared (fixup_var_refs and
3489 the associated hash table code).
3491 So, we have to do another unsharing pass after we have flushed any
3492 REGs that had their address taken into the stack.
3494 It may be worth tracking whether or not we converted any REGs into
3495 MEMs to avoid this overhead when it is not needed. */
3496 unshare_all_rtl_again (get_insns ());
3499 /* Convert a SET of a hard subreg to a set of the appropriate hard
3500 register. A subroutine of purge_hard_subreg_sets. */
3503 purge_single_hard_subreg_set (pattern)
3506 rtx reg = SET_DEST (pattern);
3507 enum machine_mode mode = GET_MODE (SET_DEST (pattern));
3510 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG
3511 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER)
3513 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)),
3514 GET_MODE (SUBREG_REG (reg)),
3517 reg = SUBREG_REG (reg);
3521 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER)
3523 reg = gen_rtx_REG (mode, REGNO (reg) + offset);
3524 SET_DEST (pattern) = reg;
3528 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3529 only such SETs that we expect to see are those left in because
3530 integrate can't handle sets of parts of a return value register.
3532 We don't use alter_subreg because we only want to eliminate subregs
3533 of hard registers. */
3536 purge_hard_subreg_sets (insn)
3539 for (; insn; insn = NEXT_INSN (insn))
3543 rtx pattern = PATTERN (insn);
3544 switch (GET_CODE (pattern))
3547 if (GET_CODE (SET_DEST (pattern)) == SUBREG)
3548 purge_single_hard_subreg_set (pattern);
3553 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--)
3555 rtx inner_pattern = XVECEXP (pattern, 0, j);
3556 if (GET_CODE (inner_pattern) == SET
3557 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG)
3558 purge_single_hard_subreg_set (inner_pattern);
3569 /* Pass through the INSNS of function FNDECL and convert virtual register
3570 references to hard register references. */
3573 instantiate_virtual_regs (fndecl, insns)
3580 /* Compute the offsets to use for this function. */
3581 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3582 var_offset = STARTING_FRAME_OFFSET;
3583 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3584 out_arg_offset = STACK_POINTER_OFFSET;
3585 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl);
3587 /* Scan all variables and parameters of this function. For each that is
3588 in memory, instantiate all virtual registers if the result is a valid
3589 address. If not, we do it later. That will handle most uses of virtual
3590 regs on many machines. */
3591 instantiate_decls (fndecl, 1);
3593 /* Initialize recognition, indicating that volatile is OK. */
3596 /* Scan through all the insns, instantiating every virtual register still
3598 for (insn = insns; insn; insn = NEXT_INSN (insn))
3599 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3600 || GET_CODE (insn) == CALL_INSN)
3602 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3603 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
3604 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3605 if (GET_CODE (insn) == CALL_INSN)
3606 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn),
3610 /* Instantiate the stack slots for the parm registers, for later use in
3611 addressof elimination. */
3612 for (i = 0; i < max_parm_reg; ++i)
3613 if (parm_reg_stack_loc[i])
3614 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3616 /* Now instantiate the remaining register equivalences for debugging info.
3617 These will not be valid addresses. */
3618 instantiate_decls (fndecl, 0);
3620 /* Indicate that, from now on, assign_stack_local should use
3621 frame_pointer_rtx. */
3622 virtuals_instantiated = 1;
3625 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3626 all virtual registers in their DECL_RTL's.
3628 If VALID_ONLY, do this only if the resulting address is still valid.
3629 Otherwise, always do it. */
3632 instantiate_decls (fndecl, valid_only)
3638 /* Process all parameters of the function. */
3639 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3641 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3642 HOST_WIDE_INT size_rtl;
3644 instantiate_decl (DECL_RTL (decl), size, valid_only);
3646 /* If the parameter was promoted, then the incoming RTL mode may be
3647 larger than the declared type size. We must use the larger of
3649 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl)));
3650 size = MAX (size_rtl, size);
3651 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3654 /* Now process all variables defined in the function or its subblocks. */
3655 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3658 /* Subroutine of instantiate_decls: Process all decls in the given
3659 BLOCK node and all its subblocks. */
3662 instantiate_decls_1 (let, valid_only)
3668 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3669 if (DECL_RTL_SET_P (t))
3670 instantiate_decl (DECL_RTL (t),
3671 int_size_in_bytes (TREE_TYPE (t)),
3674 /* Process all subblocks. */
3675 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3676 instantiate_decls_1 (t, valid_only);
3679 /* Subroutine of the preceding procedures: Given RTL representing a
3680 decl and the size of the object, do any instantiation required.
3682 If VALID_ONLY is non-zero, it means that the RTL should only be
3683 changed if the new address is valid. */
3686 instantiate_decl (x, size, valid_only)
3691 enum machine_mode mode;
3694 /* If this is not a MEM, no need to do anything. Similarly if the
3695 address is a constant or a register that is not a virtual register. */
3697 if (x == 0 || GET_CODE (x) != MEM)
3701 if (CONSTANT_P (addr)
3702 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3703 || (GET_CODE (addr) == REG
3704 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3705 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3708 /* If we should only do this if the address is valid, copy the address.
3709 We need to do this so we can undo any changes that might make the
3710 address invalid. This copy is unfortunate, but probably can't be
3714 addr = copy_rtx (addr);
3716 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3718 if (valid_only && size >= 0)
3720 unsigned HOST_WIDE_INT decl_size = size;
3722 /* Now verify that the resulting address is valid for every integer or
3723 floating-point mode up to and including SIZE bytes long. We do this
3724 since the object might be accessed in any mode and frame addresses
3727 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3728 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3729 mode = GET_MODE_WIDER_MODE (mode))
3730 if (! memory_address_p (mode, addr))
3733 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3734 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3735 mode = GET_MODE_WIDER_MODE (mode))
3736 if (! memory_address_p (mode, addr))
3740 /* Put back the address now that we have updated it and we either know
3741 it is valid or we don't care whether it is valid. */
3746 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3747 is a virtual register, return the equivalent hard register and set the
3748 offset indirectly through the pointer. Otherwise, return 0. */
3751 instantiate_new_reg (x, poffset)
3753 HOST_WIDE_INT *poffset;
3756 HOST_WIDE_INT offset;
3758 if (x == virtual_incoming_args_rtx)
3759 new = arg_pointer_rtx, offset = in_arg_offset;
3760 else if (x == virtual_stack_vars_rtx)
3761 new = frame_pointer_rtx, offset = var_offset;
3762 else if (x == virtual_stack_dynamic_rtx)
3763 new = stack_pointer_rtx, offset = dynamic_offset;
3764 else if (x == virtual_outgoing_args_rtx)
3765 new = stack_pointer_rtx, offset = out_arg_offset;
3766 else if (x == virtual_cfa_rtx)
3767 new = arg_pointer_rtx, offset = cfa_offset;
3775 /* Given a pointer to a piece of rtx and an optional pointer to the
3776 containing object, instantiate any virtual registers present in it.
3778 If EXTRA_INSNS, we always do the replacement and generate
3779 any extra insns before OBJECT. If it zero, we do nothing if replacement
3782 Return 1 if we either had nothing to do or if we were able to do the
3783 needed replacement. Return 0 otherwise; we only return zero if
3784 EXTRA_INSNS is zero.
3786 We first try some simple transformations to avoid the creation of extra
3790 instantiate_virtual_regs_1 (loc, object, extra_insns)
3798 HOST_WIDE_INT offset = 0;
3804 /* Re-start here to avoid recursion in common cases. */
3811 code = GET_CODE (x);
3813 /* Check for some special cases. */
3831 /* We are allowed to set the virtual registers. This means that
3832 the actual register should receive the source minus the
3833 appropriate offset. This is used, for example, in the handling
3834 of non-local gotos. */
3835 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0)
3837 rtx src = SET_SRC (x);
3839 /* We are setting the register, not using it, so the relevant
3840 offset is the negative of the offset to use were we using
3843 instantiate_virtual_regs_1 (&src, NULL_RTX, 0);
3845 /* The only valid sources here are PLUS or REG. Just do
3846 the simplest possible thing to handle them. */
3847 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS)
3851 if (GET_CODE (src) != REG)
3852 temp = force_operand (src, NULL_RTX);
3855 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3859 emit_insns_before (seq, object);
3862 if (! validate_change (object, &SET_SRC (x), temp, 0)
3869 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3874 /* Handle special case of virtual register plus constant. */
3875 if (CONSTANT_P (XEXP (x, 1)))
3877 rtx old, new_offset;
3879 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3880 if (GET_CODE (XEXP (x, 0)) == PLUS)
3882 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset)))
3884 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3886 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3895 #ifdef POINTERS_EXTEND_UNSIGNED
3896 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3897 we can commute the PLUS and SUBREG because pointers into the
3898 frame are well-behaved. */
3899 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode
3900 && GET_CODE (XEXP (x, 1)) == CONST_INT
3902 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)),
3904 && validate_change (object, loc,
3905 plus_constant (gen_lowpart (ptr_mode,
3908 + INTVAL (XEXP (x, 1))),
3912 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0)
3914 /* We know the second operand is a constant. Unless the
3915 first operand is a REG (which has been already checked),
3916 it needs to be checked. */
3917 if (GET_CODE (XEXP (x, 0)) != REG)
3925 new_offset = plus_constant (XEXP (x, 1), offset);
3927 /* If the new constant is zero, try to replace the sum with just
3929 if (new_offset == const0_rtx
3930 && validate_change (object, loc, new, 0))
3933 /* Next try to replace the register and new offset.
3934 There are two changes to validate here and we can't assume that
3935 in the case of old offset equals new just changing the register
3936 will yield a valid insn. In the interests of a little efficiency,
3937 however, we only call validate change once (we don't queue up the
3938 changes and then call apply_change_group). */
3942 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3943 : (XEXP (x, 0) = new,
3944 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3952 /* Otherwise copy the new constant into a register and replace
3953 constant with that register. */
3954 temp = gen_reg_rtx (Pmode);
3956 if (validate_change (object, &XEXP (x, 1), temp, 0))
3957 emit_insn_before (gen_move_insn (temp, new_offset), object);
3960 /* If that didn't work, replace this expression with a
3961 register containing the sum. */
3964 new = gen_rtx_PLUS (Pmode, new, new_offset);
3967 temp = force_operand (new, NULL_RTX);
3971 emit_insns_before (seq, object);
3972 if (! validate_change (object, loc, temp, 0)
3973 && ! validate_replace_rtx (x, temp, object))
3981 /* Fall through to generic two-operand expression case. */
3987 case DIV: case UDIV:
3988 case MOD: case UMOD:
3989 case AND: case IOR: case XOR:
3990 case ROTATERT: case ROTATE:
3991 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3993 case GE: case GT: case GEU: case GTU:
3994 case LE: case LT: case LEU: case LTU:
3995 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3996 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
4001 /* Most cases of MEM that convert to valid addresses have already been
4002 handled by our scan of decls. The only special handling we
4003 need here is to make a copy of the rtx to ensure it isn't being
4004 shared if we have to change it to a pseudo.
4006 If the rtx is a simple reference to an address via a virtual register,
4007 it can potentially be shared. In such cases, first try to make it
4008 a valid address, which can also be shared. Otherwise, copy it and
4011 First check for common cases that need no processing. These are
4012 usually due to instantiation already being done on a previous instance
4016 if (CONSTANT_ADDRESS_P (temp)
4017 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4018 || temp == arg_pointer_rtx
4020 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4021 || temp == hard_frame_pointer_rtx
4023 || temp == frame_pointer_rtx)
4026 if (GET_CODE (temp) == PLUS
4027 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4028 && (XEXP (temp, 0) == frame_pointer_rtx
4029 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4030 || XEXP (temp, 0) == hard_frame_pointer_rtx
4032 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4033 || XEXP (temp, 0) == arg_pointer_rtx
4038 if (temp == virtual_stack_vars_rtx
4039 || temp == virtual_incoming_args_rtx
4040 || (GET_CODE (temp) == PLUS
4041 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4042 && (XEXP (temp, 0) == virtual_stack_vars_rtx
4043 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
4045 /* This MEM may be shared. If the substitution can be done without
4046 the need to generate new pseudos, we want to do it in place
4047 so all copies of the shared rtx benefit. The call below will
4048 only make substitutions if the resulting address is still
4051 Note that we cannot pass X as the object in the recursive call
4052 since the insn being processed may not allow all valid
4053 addresses. However, if we were not passed on object, we can
4054 only modify X without copying it if X will have a valid
4057 ??? Also note that this can still lose if OBJECT is an insn that
4058 has less restrictions on an address that some other insn.
4059 In that case, we will modify the shared address. This case
4060 doesn't seem very likely, though. One case where this could
4061 happen is in the case of a USE or CLOBBER reference, but we
4062 take care of that below. */
4064 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
4065 object ? object : x, 0))
4068 /* Otherwise make a copy and process that copy. We copy the entire
4069 RTL expression since it might be a PLUS which could also be
4071 *loc = x = copy_rtx (x);
4074 /* Fall through to generic unary operation case. */
4077 case STRICT_LOW_PART:
4079 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
4080 case SIGN_EXTEND: case ZERO_EXTEND:
4081 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
4082 case FLOAT: case FIX:
4083 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
4087 /* These case either have just one operand or we know that we need not
4088 check the rest of the operands. */
4094 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4095 go ahead and make the invalid one, but do it to a copy. For a REG,
4096 just make the recursive call, since there's no chance of a problem. */
4098 if ((GET_CODE (XEXP (x, 0)) == MEM
4099 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
4101 || (GET_CODE (XEXP (x, 0)) == REG
4102 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4105 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
4110 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4111 in front of this insn and substitute the temporary. */
4112 if ((new = instantiate_new_reg (x, &offset)) != 0)
4114 temp = plus_constant (new, offset);
4115 if (!validate_change (object, loc, temp, 0))
4121 temp = force_operand (temp, NULL_RTX);
4125 emit_insns_before (seq, object);
4126 if (! validate_change (object, loc, temp, 0)
4127 && ! validate_replace_rtx (x, temp, object))
4135 if (GET_CODE (XEXP (x, 0)) == REG)
4138 else if (GET_CODE (XEXP (x, 0)) == MEM)
4140 /* If we have a (addressof (mem ..)), do any instantiation inside
4141 since we know we'll be making the inside valid when we finally
4142 remove the ADDRESSOF. */
4143 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4152 /* Scan all subexpressions. */
4153 fmt = GET_RTX_FORMAT (code);
4154 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4157 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4160 else if (*fmt == 'E')
4161 for (j = 0; j < XVECLEN (x, i); j++)
4162 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4169 /* Optimization: assuming this function does not receive nonlocal gotos,
4170 delete the handlers for such, as well as the insns to establish
4171 and disestablish them. */
4177 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4179 /* Delete the handler by turning off the flag that would
4180 prevent jump_optimize from deleting it.
4181 Also permit deletion of the nonlocal labels themselves
4182 if nothing local refers to them. */
4183 if (GET_CODE (insn) == CODE_LABEL)
4187 LABEL_PRESERVE_P (insn) = 0;
4189 /* Remove it from the nonlocal_label list, to avoid confusing
4191 for (t = nonlocal_labels, last_t = 0; t;
4192 last_t = t, t = TREE_CHAIN (t))
4193 if (DECL_RTL (TREE_VALUE (t)) == insn)
4198 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4200 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4203 if (GET_CODE (insn) == INSN)
4207 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4208 if (reg_mentioned_p (t, PATTERN (insn)))
4214 || (nonlocal_goto_stack_level != 0
4215 && reg_mentioned_p (nonlocal_goto_stack_level,
4217 delete_related_insns (insn);
4225 return max_parm_reg;
4228 /* Return the first insn following those generated by `assign_parms'. */
4231 get_first_nonparm_insn ()
4234 return NEXT_INSN (last_parm_insn);
4235 return get_insns ();
4238 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4239 Crash if there is none. */
4242 get_first_block_beg ()
4245 rtx insn = get_first_nonparm_insn ();
4247 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher))
4248 if (GET_CODE (searcher) == NOTE
4249 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG)
4252 abort (); /* Invalid call to this function. (See comments above.) */
4256 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4257 This means a type for which function calls must pass an address to the
4258 function or get an address back from the function.
4259 EXP may be a type node or an expression (whose type is tested). */
4262 aggregate_value_p (exp)
4265 int i, regno, nregs;
4268 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
4270 if (TREE_CODE (type) == VOID_TYPE)
4272 if (RETURN_IN_MEMORY (type))
4274 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4275 and thus can't be returned in registers. */
4276 if (TREE_ADDRESSABLE (type))
4278 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4280 /* Make sure we have suitable call-clobbered regs to return
4281 the value in; if not, we must return it in memory. */
4282 reg = hard_function_value (type, 0, 0);
4284 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4286 if (GET_CODE (reg) != REG)
4289 regno = REGNO (reg);
4290 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4291 for (i = 0; i < nregs; i++)
4292 if (! call_used_regs[regno + i])
4297 /* Assign RTL expressions to the function's parameters.
4298 This may involve copying them into registers and using
4299 those registers as the RTL for them. */
4302 assign_parms (fndecl)
4308 CUMULATIVE_ARGS args_so_far;
4309 enum machine_mode promoted_mode, passed_mode;
4310 enum machine_mode nominal_mode, promoted_nominal_mode;
4312 /* Total space needed so far for args on the stack,
4313 given as a constant and a tree-expression. */
4314 struct args_size stack_args_size;
4315 tree fntype = TREE_TYPE (fndecl);
4316 tree fnargs = DECL_ARGUMENTS (fndecl);
4317 /* This is used for the arg pointer when referring to stack args. */
4318 rtx internal_arg_pointer;
4319 /* This is a dummy PARM_DECL that we used for the function result if
4320 the function returns a structure. */
4321 tree function_result_decl = 0;
4322 #ifdef SETUP_INCOMING_VARARGS
4323 int varargs_setup = 0;
4325 rtx conversion_insns = 0;
4326 struct args_size alignment_pad;
4328 /* Nonzero if the last arg is named `__builtin_va_alist',
4329 which is used on some machines for old-fashioned non-ANSI varargs.h;
4330 this should be stuck onto the stack as if it had arrived there. */
4332 = (current_function_varargs
4334 && (parm = tree_last (fnargs)) != 0
4336 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
4337 "__builtin_va_alist")));
4339 /* Nonzero if function takes extra anonymous args.
4340 This means the last named arg must be on the stack
4341 right before the anonymous ones. */
4343 = (TYPE_ARG_TYPES (fntype) != 0
4344 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4345 != void_type_node));
4347 current_function_stdarg = stdarg;
4349 /* If the reg that the virtual arg pointer will be translated into is
4350 not a fixed reg or is the stack pointer, make a copy of the virtual
4351 arg pointer, and address parms via the copy. The frame pointer is
4352 considered fixed even though it is not marked as such.
4354 The second time through, simply use ap to avoid generating rtx. */
4356 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4357 || ! (fixed_regs[ARG_POINTER_REGNUM]
4358 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
4359 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4361 internal_arg_pointer = virtual_incoming_args_rtx;
4362 current_function_internal_arg_pointer = internal_arg_pointer;
4364 stack_args_size.constant = 0;
4365 stack_args_size.var = 0;
4367 /* If struct value address is treated as the first argument, make it so. */
4368 if (aggregate_value_p (DECL_RESULT (fndecl))
4369 && ! current_function_returns_pcc_struct
4370 && struct_value_incoming_rtx == 0)
4372 tree type = build_pointer_type (TREE_TYPE (fntype));
4374 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4376 DECL_ARG_TYPE (function_result_decl) = type;
4377 TREE_CHAIN (function_result_decl) = fnargs;
4378 fnargs = function_result_decl;
4381 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4382 parm_reg_stack_loc = (rtx *) xcalloc (max_parm_reg, sizeof (rtx));
4384 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4385 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4387 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0);
4390 /* We haven't yet found an argument that we must push and pretend the
4392 current_function_pretend_args_size = 0;
4394 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4396 struct args_size stack_offset;
4397 struct args_size arg_size;
4398 int passed_pointer = 0;
4399 int did_conversion = 0;
4400 tree passed_type = DECL_ARG_TYPE (parm);
4401 tree nominal_type = TREE_TYPE (parm);
4403 int last_named = 0, named_arg;
4405 /* Set LAST_NAMED if this is last named arg before last
4407 if (stdarg || current_function_varargs)
4411 for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem))
4412 if (DECL_NAME (tem))
4418 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4419 most machines, if this is a varargs/stdarg function, then we treat
4420 the last named arg as if it were anonymous too. */
4421 named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
4423 if (TREE_TYPE (parm) == error_mark_node
4424 /* This can happen after weird syntax errors
4425 or if an enum type is defined among the parms. */
4426 || TREE_CODE (parm) != PARM_DECL
4427 || passed_type == NULL)
4429 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx));
4430 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4431 TREE_USED (parm) = 1;
4435 /* For varargs.h function, save info about regs and stack space
4436 used by the individual args, not including the va_alist arg. */
4437 if (hide_last_arg && last_named)
4438 current_function_args_info = args_so_far;
4440 /* Find mode of arg as it is passed, and mode of arg
4441 as it should be during execution of this function. */
4442 passed_mode = TYPE_MODE (passed_type);
4443 nominal_mode = TYPE_MODE (nominal_type);
4445 /* If the parm's mode is VOID, its value doesn't matter,
4446 and avoid the usual things like emit_move_insn that could crash. */
4447 if (nominal_mode == VOIDmode)
4449 SET_DECL_RTL (parm, const0_rtx);
4450 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4454 /* If the parm is to be passed as a transparent union, use the
4455 type of the first field for the tests below. We have already
4456 verified that the modes are the same. */
4457 if (DECL_TRANSPARENT_UNION (parm)
4458 || (TREE_CODE (passed_type) == UNION_TYPE
4459 && TYPE_TRANSPARENT_UNION (passed_type)))
4460 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4462 /* See if this arg was passed by invisible reference. It is if
4463 it is an object whose size depends on the contents of the
4464 object itself or if the machine requires these objects be passed
4467 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST
4468 && contains_placeholder_p (TYPE_SIZE (passed_type)))
4469 || TREE_ADDRESSABLE (passed_type)
4470 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4471 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4472 passed_type, named_arg)
4476 passed_type = nominal_type = build_pointer_type (passed_type);
4478 passed_mode = nominal_mode = Pmode;
4481 promoted_mode = passed_mode;
4483 #ifdef PROMOTE_FUNCTION_ARGS
4484 /* Compute the mode in which the arg is actually extended to. */
4485 unsignedp = TREE_UNSIGNED (passed_type);
4486 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4489 /* Let machine desc say which reg (if any) the parm arrives in.
4490 0 means it arrives on the stack. */
4491 #ifdef FUNCTION_INCOMING_ARG
4492 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4493 passed_type, named_arg);
4495 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4496 passed_type, named_arg);
4499 if (entry_parm == 0)
4500 promoted_mode = passed_mode;
4502 #ifdef SETUP_INCOMING_VARARGS
4503 /* If this is the last named parameter, do any required setup for
4504 varargs or stdargs. We need to know about the case of this being an
4505 addressable type, in which case we skip the registers it
4506 would have arrived in.
4508 For stdargs, LAST_NAMED will be set for two parameters, the one that
4509 is actually the last named, and the dummy parameter. We only
4510 want to do this action once.
4512 Also, indicate when RTL generation is to be suppressed. */
4513 if (last_named && !varargs_setup)
4515 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type,
4516 current_function_pretend_args_size, 0);
4521 /* Determine parm's home in the stack,
4522 in case it arrives in the stack or we should pretend it did.
4524 Compute the stack position and rtx where the argument arrives
4527 There is one complexity here: If this was a parameter that would
4528 have been passed in registers, but wasn't only because it is
4529 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4530 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4531 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4532 0 as it was the previous time. */
4534 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED;
4535 locate_and_pad_parm (promoted_mode, passed_type,
4536 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4539 #ifdef FUNCTION_INCOMING_ARG
4540 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4542 pretend_named) != 0,
4544 FUNCTION_ARG (args_so_far, promoted_mode,
4546 pretend_named) != 0,
4549 fndecl, &stack_args_size, &stack_offset, &arg_size,
4553 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
4555 if (offset_rtx == const0_rtx)
4556 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4558 stack_parm = gen_rtx_MEM (promoted_mode,
4559 gen_rtx_PLUS (Pmode,
4560 internal_arg_pointer,
4563 set_mem_attributes (stack_parm, parm, 1);
4566 /* If this parameter was passed both in registers and in the stack,
4567 use the copy on the stack. */
4568 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4571 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4572 /* If this parm was passed part in regs and part in memory,
4573 pretend it arrived entirely in memory
4574 by pushing the register-part onto the stack.
4576 In the special case of a DImode or DFmode that is split,
4577 we could put it together in a pseudoreg directly,
4578 but for now that's not worth bothering with. */
4582 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4583 passed_type, named_arg);
4587 current_function_pretend_args_size
4588 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
4589 / (PARM_BOUNDARY / BITS_PER_UNIT)
4590 * (PARM_BOUNDARY / BITS_PER_UNIT));
4592 /* Handle calls that pass values in multiple non-contiguous
4593 locations. The Irix 6 ABI has examples of this. */
4594 if (GET_CODE (entry_parm) == PARALLEL)
4595 emit_group_store (validize_mem (stack_parm), entry_parm,
4596 int_size_in_bytes (TREE_TYPE (parm)));
4599 move_block_from_reg (REGNO (entry_parm),
4600 validize_mem (stack_parm), nregs,
4601 int_size_in_bytes (TREE_TYPE (parm)));
4603 entry_parm = stack_parm;
4608 /* If we didn't decide this parm came in a register,
4609 by default it came on the stack. */
4610 if (entry_parm == 0)
4611 entry_parm = stack_parm;
4613 /* Record permanently how this parm was passed. */
4614 DECL_INCOMING_RTL (parm) = entry_parm;
4616 /* If there is actually space on the stack for this parm,
4617 count it in stack_args_size; otherwise set stack_parm to 0
4618 to indicate there is no preallocated stack slot for the parm. */
4620 if (entry_parm == stack_parm
4621 || (GET_CODE (entry_parm) == PARALLEL
4622 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4623 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4624 /* On some machines, even if a parm value arrives in a register
4625 there is still an (uninitialized) stack slot allocated for it.
4627 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4628 whether this parameter already has a stack slot allocated,
4629 because an arg block exists only if current_function_args_size
4630 is larger than some threshold, and we haven't calculated that
4631 yet. So, for now, we just assume that stack slots never exist
4633 || REG_PARM_STACK_SPACE (fndecl) > 0
4637 stack_args_size.constant += arg_size.constant;
4639 ADD_PARM_SIZE (stack_args_size, arg_size.var);
4642 /* No stack slot was pushed for this parm. */
4645 /* Update info on where next arg arrives in registers. */
4647 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4648 passed_type, named_arg);
4650 /* If we can't trust the parm stack slot to be aligned enough
4651 for its ultimate type, don't use that slot after entry.
4652 We'll make another stack slot, if we need one. */
4654 unsigned int thisparm_boundary
4655 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4657 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary)
4661 /* If parm was passed in memory, and we need to convert it on entry,
4662 don't store it back in that same slot. */
4664 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4667 /* When an argument is passed in multiple locations, we can't
4668 make use of this information, but we can save some copying if
4669 the whole argument is passed in a single register. */
4670 if (GET_CODE (entry_parm) == PARALLEL
4671 && nominal_mode != BLKmode && passed_mode != BLKmode)
4673 int i, len = XVECLEN (entry_parm, 0);
4675 for (i = 0; i < len; i++)
4676 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
4677 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG
4678 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
4680 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
4682 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
4683 DECL_INCOMING_RTL (parm) = entry_parm;
4688 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4689 in the mode in which it arrives.
4690 STACK_PARM is an RTX for a stack slot where the parameter can live
4691 during the function (in case we want to put it there).
4692 STACK_PARM is 0 if no stack slot was pushed for it.
4694 Now output code if necessary to convert ENTRY_PARM to
4695 the type in which this function declares it,
4696 and store that result in an appropriate place,
4697 which may be a pseudo reg, may be STACK_PARM,
4698 or may be a local stack slot if STACK_PARM is 0.
4700 Set DECL_RTL to that place. */
4702 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL)
4704 /* If a BLKmode arrives in registers, copy it to a stack slot.
4705 Handle calls that pass values in multiple non-contiguous
4706 locations. The Irix 6 ABI has examples of this. */
4707 if (GET_CODE (entry_parm) == REG
4708 || GET_CODE (entry_parm) == PARALLEL)
4711 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
4714 /* Note that we will be storing an integral number of words.
4715 So we have to be careful to ensure that we allocate an
4716 integral number of words. We do this below in the
4717 assign_stack_local if space was not allocated in the argument
4718 list. If it was, this will not work if PARM_BOUNDARY is not
4719 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4720 if it becomes a problem. */
4722 if (stack_parm == 0)
4725 = assign_stack_local (GET_MODE (entry_parm),
4727 set_mem_attributes (stack_parm, parm, 1);
4730 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4733 /* Handle calls that pass values in multiple non-contiguous
4734 locations. The Irix 6 ABI has examples of this. */
4735 if (GET_CODE (entry_parm) == PARALLEL)
4736 emit_group_store (validize_mem (stack_parm), entry_parm,
4737 int_size_in_bytes (TREE_TYPE (parm)));
4739 move_block_from_reg (REGNO (entry_parm),
4740 validize_mem (stack_parm),
4741 size_stored / UNITS_PER_WORD,
4742 int_size_in_bytes (TREE_TYPE (parm)));
4744 SET_DECL_RTL (parm, stack_parm);
4746 else if (! ((! optimize
4747 && ! DECL_REGISTER (parm))
4748 || TREE_SIDE_EFFECTS (parm)
4749 /* If -ffloat-store specified, don't put explicit
4750 float variables into registers. */
4751 || (flag_float_store
4752 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4753 /* Always assign pseudo to structure return or item passed
4754 by invisible reference. */
4755 || passed_pointer || parm == function_result_decl)
4757 /* Store the parm in a pseudoregister during the function, but we
4758 may need to do it in a wider mode. */
4761 unsigned int regno, regnoi = 0, regnor = 0;
4763 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4765 promoted_nominal_mode
4766 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4768 parmreg = gen_reg_rtx (promoted_nominal_mode);
4769 mark_user_reg (parmreg);
4771 /* If this was an item that we received a pointer to, set DECL_RTL
4775 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)),
4777 set_mem_attributes (x, parm, 1);
4778 SET_DECL_RTL (parm, x);
4782 SET_DECL_RTL (parm, parmreg);
4783 maybe_set_unchanging (DECL_RTL (parm), parm);
4786 /* Copy the value into the register. */
4787 if (nominal_mode != passed_mode
4788 || promoted_nominal_mode != promoted_mode)
4791 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4792 mode, by the caller. We now have to convert it to
4793 NOMINAL_MODE, if different. However, PARMREG may be in
4794 a different mode than NOMINAL_MODE if it is being stored
4797 If ENTRY_PARM is a hard register, it might be in a register
4798 not valid for operating in its mode (e.g., an odd-numbered
4799 register for a DFmode). In that case, moves are the only
4800 thing valid, so we can't do a convert from there. This
4801 occurs when the calling sequence allow such misaligned
4804 In addition, the conversion may involve a call, which could
4805 clobber parameters which haven't been copied to pseudo
4806 registers yet. Therefore, we must first copy the parm to
4807 a pseudo reg here, and save the conversion until after all
4808 parameters have been moved. */
4810 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4812 emit_move_insn (tempreg, validize_mem (entry_parm));
4814 push_to_sequence (conversion_insns);
4815 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4817 if (GET_CODE (tempreg) == SUBREG
4818 && GET_MODE (tempreg) == nominal_mode
4819 && GET_CODE (SUBREG_REG (tempreg)) == REG
4820 && nominal_mode == passed_mode
4821 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm)
4822 && GET_MODE_SIZE (GET_MODE (tempreg))
4823 < GET_MODE_SIZE (GET_MODE (entry_parm)))
4825 /* The argument is already sign/zero extended, so note it
4827 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
4828 SUBREG_PROMOTED_UNSIGNED_P (tempreg) = unsignedp;
4831 /* TREE_USED gets set erroneously during expand_assignment. */
4832 save_tree_used = TREE_USED (parm);
4833 expand_assignment (parm,
4834 make_tree (nominal_type, tempreg), 0, 0);
4835 TREE_USED (parm) = save_tree_used;
4836 conversion_insns = get_insns ();
4841 emit_move_insn (parmreg, validize_mem (entry_parm));
4843 /* If we were passed a pointer but the actual value
4844 can safely live in a register, put it in one. */
4845 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
4846 /* If by-reference argument was promoted, demote it. */
4847 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm))
4849 && ! DECL_REGISTER (parm))
4850 || TREE_SIDE_EFFECTS (parm)
4851 /* If -ffloat-store specified, don't put explicit
4852 float variables into registers. */
4853 || (flag_float_store
4854 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))))
4856 /* We can't use nominal_mode, because it will have been set to
4857 Pmode above. We must use the actual mode of the parm. */
4858 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
4859 mark_user_reg (parmreg);
4860 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
4862 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
4863 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm));
4864 push_to_sequence (conversion_insns);
4865 emit_move_insn (tempreg, DECL_RTL (parm));
4867 convert_to_mode (GET_MODE (parmreg),
4870 emit_move_insn (parmreg, DECL_RTL (parm));
4871 conversion_insns = get_insns();
4876 emit_move_insn (parmreg, DECL_RTL (parm));
4877 SET_DECL_RTL (parm, parmreg);
4878 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4882 #ifdef FUNCTION_ARG_CALLEE_COPIES
4883 /* If we are passed an arg by reference and it is our responsibility
4884 to make a copy, do it now.
4885 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4886 original argument, so we must recreate them in the call to
4887 FUNCTION_ARG_CALLEE_COPIES. */
4888 /* ??? Later add code to handle the case that if the argument isn't
4889 modified, don't do the copy. */
4891 else if (passed_pointer
4892 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
4893 TYPE_MODE (DECL_ARG_TYPE (parm)),
4894 DECL_ARG_TYPE (parm),
4896 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm)))
4899 tree type = DECL_ARG_TYPE (parm);
4901 /* This sequence may involve a library call perhaps clobbering
4902 registers that haven't been copied to pseudos yet. */
4904 push_to_sequence (conversion_insns);
4906 if (!COMPLETE_TYPE_P (type)
4907 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4908 /* This is a variable sized object. */
4909 copy = gen_rtx_MEM (BLKmode,
4910 allocate_dynamic_stack_space
4911 (expr_size (parm), NULL_RTX,
4912 TYPE_ALIGN (type)));
4914 copy = assign_stack_temp (TYPE_MODE (type),
4915 int_size_in_bytes (type), 1);
4916 set_mem_attributes (copy, parm, 1);
4918 store_expr (parm, copy, 0);
4919 emit_move_insn (parmreg, XEXP (copy, 0));
4920 conversion_insns = get_insns ();
4924 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4926 /* In any case, record the parm's desired stack location
4927 in case we later discover it must live in the stack.
4929 If it is a COMPLEX value, store the stack location for both
4932 if (GET_CODE (parmreg) == CONCAT)
4933 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
4935 regno = REGNO (parmreg);
4937 if (regno >= max_parm_reg)
4940 int old_max_parm_reg = max_parm_reg;
4942 /* It's slow to expand this one register at a time,
4943 but it's also rare and we need max_parm_reg to be
4944 precisely correct. */
4945 max_parm_reg = regno + 1;
4946 new = (rtx *) xrealloc (parm_reg_stack_loc,
4947 max_parm_reg * sizeof (rtx));
4948 memset ((char *) (new + old_max_parm_reg), 0,
4949 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4950 parm_reg_stack_loc = new;
4953 if (GET_CODE (parmreg) == CONCAT)
4955 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
4957 regnor = REGNO (gen_realpart (submode, parmreg));
4958 regnoi = REGNO (gen_imagpart (submode, parmreg));
4960 if (stack_parm != 0)
4962 parm_reg_stack_loc[regnor]
4963 = gen_realpart (submode, stack_parm);
4964 parm_reg_stack_loc[regnoi]
4965 = gen_imagpart (submode, stack_parm);
4969 parm_reg_stack_loc[regnor] = 0;
4970 parm_reg_stack_loc[regnoi] = 0;
4974 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
4976 /* Mark the register as eliminable if we did no conversion
4977 and it was copied from memory at a fixed offset,
4978 and the arg pointer was not copied to a pseudo-reg.
4979 If the arg pointer is a pseudo reg or the offset formed
4980 an invalid address, such memory-equivalences
4981 as we make here would screw up life analysis for it. */
4982 if (nominal_mode == passed_mode
4985 && GET_CODE (stack_parm) == MEM
4986 && stack_offset.var == 0
4987 && reg_mentioned_p (virtual_incoming_args_rtx,
4988 XEXP (stack_parm, 0)))
4990 rtx linsn = get_last_insn ();
4993 /* Mark complex types separately. */
4994 if (GET_CODE (parmreg) == CONCAT)
4995 /* Scan backwards for the set of the real and
4997 for (sinsn = linsn; sinsn != 0;
4998 sinsn = prev_nonnote_insn (sinsn))
5000 set = single_set (sinsn);
5002 && SET_DEST (set) == regno_reg_rtx [regnoi])
5004 = gen_rtx_EXPR_LIST (REG_EQUIV,
5005 parm_reg_stack_loc[regnoi],
5008 && SET_DEST (set) == regno_reg_rtx [regnor])
5010 = gen_rtx_EXPR_LIST (REG_EQUIV,
5011 parm_reg_stack_loc[regnor],
5014 else if ((set = single_set (linsn)) != 0
5015 && SET_DEST (set) == parmreg)
5017 = gen_rtx_EXPR_LIST (REG_EQUIV,
5018 stack_parm, REG_NOTES (linsn));
5021 /* For pointer data type, suggest pointer register. */
5022 if (POINTER_TYPE_P (TREE_TYPE (parm)))
5023 mark_reg_pointer (parmreg,
5024 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
5026 /* If something wants our address, try to use ADDRESSOF. */
5027 if (TREE_ADDRESSABLE (parm))
5029 /* If we end up putting something into the stack,
5030 fixup_var_refs_insns will need to make a pass over
5031 all the instructions. It looks through the pending
5032 sequences -- but it can't see the ones in the
5033 CONVERSION_INSNS, if they're not on the sequence
5034 stack. So, we go back to that sequence, just so that
5035 the fixups will happen. */
5036 push_to_sequence (conversion_insns);
5037 put_var_into_stack (parm);
5038 conversion_insns = get_insns ();
5044 /* Value must be stored in the stack slot STACK_PARM
5045 during function execution. */
5047 if (promoted_mode != nominal_mode)
5049 /* Conversion is required. */
5050 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
5052 emit_move_insn (tempreg, validize_mem (entry_parm));
5054 push_to_sequence (conversion_insns);
5055 entry_parm = convert_to_mode (nominal_mode, tempreg,
5056 TREE_UNSIGNED (TREE_TYPE (parm)));
5058 /* ??? This may need a big-endian conversion on sparc64. */
5059 stack_parm = adjust_address (stack_parm, nominal_mode, 0);
5061 conversion_insns = get_insns ();
5066 if (entry_parm != stack_parm)
5068 if (stack_parm == 0)
5071 = assign_stack_local (GET_MODE (entry_parm),
5072 GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
5073 set_mem_attributes (stack_parm, parm, 1);
5076 if (promoted_mode != nominal_mode)
5078 push_to_sequence (conversion_insns);
5079 emit_move_insn (validize_mem (stack_parm),
5080 validize_mem (entry_parm));
5081 conversion_insns = get_insns ();
5085 emit_move_insn (validize_mem (stack_parm),
5086 validize_mem (entry_parm));
5089 SET_DECL_RTL (parm, stack_parm);
5092 /* If this "parameter" was the place where we are receiving the
5093 function's incoming structure pointer, set up the result. */
5094 if (parm == function_result_decl)
5096 tree result = DECL_RESULT (fndecl);
5097 rtx addr = DECL_RTL (parm);
5100 #ifdef POINTERS_EXTEND_UNSIGNED
5101 if (GET_MODE (addr) != Pmode)
5102 addr = convert_memory_address (Pmode, addr);
5105 x = gen_rtx_MEM (DECL_MODE (result), addr);
5106 set_mem_attributes (x, result, 1);
5107 SET_DECL_RTL (result, x);
5110 if (GET_CODE (DECL_RTL (parm)) == REG)
5111 REGNO_DECL (REGNO (DECL_RTL (parm))) = parm;
5112 else if (GET_CODE (DECL_RTL (parm)) == CONCAT)
5114 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 0))) = parm;
5115 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 1))) = parm;
5120 /* Output all parameter conversion instructions (possibly including calls)
5121 now that all parameters have been copied out of hard registers. */
5122 emit_insns (conversion_insns);
5124 last_parm_insn = get_last_insn ();
5126 current_function_args_size = stack_args_size.constant;
5128 /* Adjust function incoming argument size for alignment and
5131 #ifdef REG_PARM_STACK_SPACE
5132 #ifndef MAYBE_REG_PARM_STACK_SPACE
5133 current_function_args_size = MAX (current_function_args_size,
5134 REG_PARM_STACK_SPACE (fndecl));
5138 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5140 current_function_args_size
5141 = ((current_function_args_size + STACK_BYTES - 1)
5142 / STACK_BYTES) * STACK_BYTES;
5144 #ifdef ARGS_GROW_DOWNWARD
5145 current_function_arg_offset_rtx
5146 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5147 : expand_expr (size_diffop (stack_args_size.var,
5148 size_int (-stack_args_size.constant)),
5149 NULL_RTX, VOIDmode, 0));
5151 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5154 /* See how many bytes, if any, of its args a function should try to pop
5157 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5158 current_function_args_size);
5160 /* For stdarg.h function, save info about
5161 regs and stack space used by the named args. */
5164 current_function_args_info = args_so_far;
5166 /* Set the rtx used for the function return value. Put this in its
5167 own variable so any optimizers that need this information don't have
5168 to include tree.h. Do this here so it gets done when an inlined
5169 function gets output. */
5171 current_function_return_rtx
5172 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
5173 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
5175 /* If scalar return value was computed in a pseudo-reg, or was a named
5176 return value that got dumped to the stack, copy that to the hard
5178 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
5180 tree decl_result = DECL_RESULT (fndecl);
5181 rtx decl_rtl = DECL_RTL (decl_result);
5183 if (REG_P (decl_rtl)
5184 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5185 : DECL_REGISTER (decl_result))
5189 #ifdef FUNCTION_OUTGOING_VALUE
5190 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
5193 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
5196 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
5197 /* The delay slot scheduler assumes that current_function_return_rtx
5198 holds the hard register containing the return value, not a
5199 temporary pseudo. */
5200 current_function_return_rtx = real_decl_rtl;
5205 /* Indicate whether REGNO is an incoming argument to the current function
5206 that was promoted to a wider mode. If so, return the RTX for the
5207 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5208 that REGNO is promoted from and whether the promotion was signed or
5211 #ifdef PROMOTE_FUNCTION_ARGS
5214 promoted_input_arg (regno, pmode, punsignedp)
5216 enum machine_mode *pmode;
5221 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5222 arg = TREE_CHAIN (arg))
5223 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5224 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5225 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5227 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5228 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5230 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5231 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5232 && mode != DECL_MODE (arg))
5234 *pmode = DECL_MODE (arg);
5235 *punsignedp = unsignedp;
5236 return DECL_INCOMING_RTL (arg);
5245 /* Compute the size and offset from the start of the stacked arguments for a
5246 parm passed in mode PASSED_MODE and with type TYPE.
5248 INITIAL_OFFSET_PTR points to the current offset into the stacked
5251 The starting offset and size for this parm are returned in *OFFSET_PTR
5252 and *ARG_SIZE_PTR, respectively.
5254 IN_REGS is non-zero if the argument will be passed in registers. It will
5255 never be set if REG_PARM_STACK_SPACE is not defined.
5257 FNDECL is the function in which the argument was defined.
5259 There are two types of rounding that are done. The first, controlled by
5260 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5261 list to be aligned to the specific boundary (in bits). This rounding
5262 affects the initial and starting offsets, but not the argument size.
5264 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5265 optionally rounds the size of the parm to PARM_BOUNDARY. The
5266 initial offset is not affected by this rounding, while the size always
5267 is and the starting offset may be. */
5269 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5270 initial_offset_ptr is positive because locate_and_pad_parm's
5271 callers pass in the total size of args so far as
5272 initial_offset_ptr. arg_size_ptr is always positive. */
5275 locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
5276 initial_offset_ptr, offset_ptr, arg_size_ptr,
5278 enum machine_mode passed_mode;
5280 int in_regs ATTRIBUTE_UNUSED;
5281 tree fndecl ATTRIBUTE_UNUSED;
5282 struct args_size *initial_offset_ptr;
5283 struct args_size *offset_ptr;
5284 struct args_size *arg_size_ptr;
5285 struct args_size *alignment_pad;
5289 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5290 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5291 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5293 #ifdef REG_PARM_STACK_SPACE
5294 /* If we have found a stack parm before we reach the end of the
5295 area reserved for registers, skip that area. */
5298 int reg_parm_stack_space = 0;
5300 #ifdef MAYBE_REG_PARM_STACK_SPACE
5301 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5303 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5305 if (reg_parm_stack_space > 0)
5307 if (initial_offset_ptr->var)
5309 initial_offset_ptr->var
5310 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5311 ssize_int (reg_parm_stack_space));
5312 initial_offset_ptr->constant = 0;
5314 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5315 initial_offset_ptr->constant = reg_parm_stack_space;
5318 #endif /* REG_PARM_STACK_SPACE */
5320 arg_size_ptr->var = 0;
5321 arg_size_ptr->constant = 0;
5322 alignment_pad->var = 0;
5323 alignment_pad->constant = 0;
5325 #ifdef ARGS_GROW_DOWNWARD
5326 if (initial_offset_ptr->var)
5328 offset_ptr->constant = 0;
5329 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0),
5330 initial_offset_ptr->var);
5334 offset_ptr->constant = -initial_offset_ptr->constant;
5335 offset_ptr->var = 0;
5337 if (where_pad != none
5338 && (!host_integerp (sizetree, 1)
5339 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5340 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5341 SUB_PARM_SIZE (*offset_ptr, sizetree);
5342 if (where_pad != downward)
5343 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad);
5344 if (initial_offset_ptr->var)
5345 arg_size_ptr->var = size_binop (MINUS_EXPR,
5346 size_binop (MINUS_EXPR,
5348 initial_offset_ptr->var),
5352 arg_size_ptr->constant = (-initial_offset_ptr->constant
5353 - offset_ptr->constant);
5355 #else /* !ARGS_GROW_DOWNWARD */
5357 #ifdef REG_PARM_STACK_SPACE
5358 || REG_PARM_STACK_SPACE (fndecl) > 0
5361 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad);
5362 *offset_ptr = *initial_offset_ptr;
5364 #ifdef PUSH_ROUNDING
5365 if (passed_mode != BLKmode)
5366 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5369 /* Pad_below needs the pre-rounded size to know how much to pad below
5370 so this must be done before rounding up. */
5371 if (where_pad == downward
5372 /* However, BLKmode args passed in regs have their padding done elsewhere.
5373 The stack slot must be able to hold the entire register. */
5374 && !(in_regs && passed_mode == BLKmode))
5375 pad_below (offset_ptr, passed_mode, sizetree);
5377 if (where_pad != none
5378 && (!host_integerp (sizetree, 1)
5379 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5380 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5382 ADD_PARM_SIZE (*arg_size_ptr, sizetree);
5383 #endif /* ARGS_GROW_DOWNWARD */
5386 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5387 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5390 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad)
5391 struct args_size *offset_ptr;
5393 struct args_size *alignment_pad;
5395 tree save_var = NULL_TREE;
5396 HOST_WIDE_INT save_constant = 0;
5398 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5400 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5402 save_var = offset_ptr->var;
5403 save_constant = offset_ptr->constant;
5406 alignment_pad->var = NULL_TREE;
5407 alignment_pad->constant = 0;
5409 if (boundary > BITS_PER_UNIT)
5411 if (offset_ptr->var)
5414 #ifdef ARGS_GROW_DOWNWARD
5419 (ARGS_SIZE_TREE (*offset_ptr),
5420 boundary / BITS_PER_UNIT);
5421 offset_ptr->constant = 0; /*?*/
5422 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5423 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
5428 offset_ptr->constant =
5429 #ifdef ARGS_GROW_DOWNWARD
5430 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes);
5432 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes);
5434 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5435 alignment_pad->constant = offset_ptr->constant - save_constant;
5440 #ifndef ARGS_GROW_DOWNWARD
5442 pad_below (offset_ptr, passed_mode, sizetree)
5443 struct args_size *offset_ptr;
5444 enum machine_mode passed_mode;
5447 if (passed_mode != BLKmode)
5449 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5450 offset_ptr->constant
5451 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5452 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5453 - GET_MODE_SIZE (passed_mode));
5457 if (TREE_CODE (sizetree) != INTEGER_CST
5458 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5460 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5461 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5463 ADD_PARM_SIZE (*offset_ptr, s2);
5464 SUB_PARM_SIZE (*offset_ptr, sizetree);
5470 /* Walk the tree of blocks describing the binding levels within a function
5471 and warn about uninitialized variables.
5472 This is done after calling flow_analysis and before global_alloc
5473 clobbers the pseudo-regs to hard regs. */
5476 uninitialized_vars_warning (block)
5480 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5482 if (warn_uninitialized
5483 && TREE_CODE (decl) == VAR_DECL
5484 /* These warnings are unreliable for and aggregates
5485 because assigning the fields one by one can fail to convince
5486 flow.c that the entire aggregate was initialized.
5487 Unions are troublesome because members may be shorter. */
5488 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5489 && DECL_RTL (decl) != 0
5490 && GET_CODE (DECL_RTL (decl)) == REG
5491 /* Global optimizations can make it difficult to determine if a
5492 particular variable has been initialized. However, a VAR_DECL
5493 with a nonzero DECL_INITIAL had an initializer, so do not
5494 claim it is potentially uninitialized.
5496 We do not care about the actual value in DECL_INITIAL, so we do
5497 not worry that it may be a dangling pointer. */
5498 && DECL_INITIAL (decl) == NULL_TREE
5499 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5500 warning_with_decl (decl,
5501 "`%s' might be used uninitialized in this function");
5503 && TREE_CODE (decl) == VAR_DECL
5504 && DECL_RTL (decl) != 0
5505 && GET_CODE (DECL_RTL (decl)) == REG
5506 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5507 warning_with_decl (decl,
5508 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5510 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5511 uninitialized_vars_warning (sub);
5514 /* Do the appropriate part of uninitialized_vars_warning
5515 but for arguments instead of local variables. */
5518 setjmp_args_warning ()
5521 for (decl = DECL_ARGUMENTS (current_function_decl);
5522 decl; decl = TREE_CHAIN (decl))
5523 if (DECL_RTL (decl) != 0
5524 && GET_CODE (DECL_RTL (decl)) == REG
5525 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5526 warning_with_decl (decl,
5527 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5530 /* If this function call setjmp, put all vars into the stack
5531 unless they were declared `register'. */
5534 setjmp_protect (block)
5538 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5539 if ((TREE_CODE (decl) == VAR_DECL
5540 || TREE_CODE (decl) == PARM_DECL)
5541 && DECL_RTL (decl) != 0
5542 && (GET_CODE (DECL_RTL (decl)) == REG
5543 || (GET_CODE (DECL_RTL (decl)) == MEM
5544 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5545 /* If this variable came from an inline function, it must be
5546 that its life doesn't overlap the setjmp. If there was a
5547 setjmp in the function, it would already be in memory. We
5548 must exclude such variable because their DECL_RTL might be
5549 set to strange things such as virtual_stack_vars_rtx. */
5550 && ! DECL_FROM_INLINE (decl)
5552 #ifdef NON_SAVING_SETJMP
5553 /* If longjmp doesn't restore the registers,
5554 don't put anything in them. */
5558 ! DECL_REGISTER (decl)))
5559 put_var_into_stack (decl);
5560 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5561 setjmp_protect (sub);
5564 /* Like the previous function, but for args instead of local variables. */
5567 setjmp_protect_args ()
5570 for (decl = DECL_ARGUMENTS (current_function_decl);
5571 decl; decl = TREE_CHAIN (decl))
5572 if ((TREE_CODE (decl) == VAR_DECL
5573 || TREE_CODE (decl) == PARM_DECL)
5574 && DECL_RTL (decl) != 0
5575 && (GET_CODE (DECL_RTL (decl)) == REG
5576 || (GET_CODE (DECL_RTL (decl)) == MEM
5577 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5579 /* If longjmp doesn't restore the registers,
5580 don't put anything in them. */
5581 #ifdef NON_SAVING_SETJMP
5585 ! DECL_REGISTER (decl)))
5586 put_var_into_stack (decl);
5589 /* Return the context-pointer register corresponding to DECL,
5590 or 0 if it does not need one. */
5593 lookup_static_chain (decl)
5596 tree context = decl_function_context (decl);
5600 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5603 /* We treat inline_function_decl as an alias for the current function
5604 because that is the inline function whose vars, types, etc.
5605 are being merged into the current function.
5606 See expand_inline_function. */
5607 if (context == current_function_decl || context == inline_function_decl)
5608 return virtual_stack_vars_rtx;
5610 for (link = context_display; link; link = TREE_CHAIN (link))
5611 if (TREE_PURPOSE (link) == context)
5612 return RTL_EXPR_RTL (TREE_VALUE (link));
5617 /* Convert a stack slot address ADDR for variable VAR
5618 (from a containing function)
5619 into an address valid in this function (using a static chain). */
5622 fix_lexical_addr (addr, var)
5627 HOST_WIDE_INT displacement;
5628 tree context = decl_function_context (var);
5629 struct function *fp;
5632 /* If this is the present function, we need not do anything. */
5633 if (context == current_function_decl || context == inline_function_decl)
5636 fp = find_function_data (context);
5638 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5639 addr = XEXP (XEXP (addr, 0), 0);
5641 /* Decode given address as base reg plus displacement. */
5642 if (GET_CODE (addr) == REG)
5643 basereg = addr, displacement = 0;
5644 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5645 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5649 /* We accept vars reached via the containing function's
5650 incoming arg pointer and via its stack variables pointer. */
5651 if (basereg == fp->internal_arg_pointer)
5653 /* If reached via arg pointer, get the arg pointer value
5654 out of that function's stack frame.
5656 There are two cases: If a separate ap is needed, allocate a
5657 slot in the outer function for it and dereference it that way.
5658 This is correct even if the real ap is actually a pseudo.
5659 Otherwise, just adjust the offset from the frame pointer to
5662 #ifdef NEED_SEPARATE_AP
5665 addr = get_arg_pointer_save_area (fp);
5666 addr = fix_lexical_addr (XEXP (addr, 0), var);
5667 addr = memory_address (Pmode, addr);
5669 base = gen_rtx_MEM (Pmode, addr);
5670 set_mem_alias_set (base, get_frame_alias_set ());
5671 base = copy_to_reg (base);
5673 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5674 base = lookup_static_chain (var);
5678 else if (basereg == virtual_stack_vars_rtx)
5680 /* This is the same code as lookup_static_chain, duplicated here to
5681 avoid an extra call to decl_function_context. */
5684 for (link = context_display; link; link = TREE_CHAIN (link))
5685 if (TREE_PURPOSE (link) == context)
5687 base = RTL_EXPR_RTL (TREE_VALUE (link));
5695 /* Use same offset, relative to appropriate static chain or argument
5697 return plus_constant (base, displacement);
5700 /* Return the address of the trampoline for entering nested fn FUNCTION.
5701 If necessary, allocate a trampoline (in the stack frame)
5702 and emit rtl to initialize its contents (at entry to this function). */
5705 trampoline_address (function)
5711 struct function *fp;
5714 /* Find an existing trampoline and return it. */
5715 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5716 if (TREE_PURPOSE (link) == function)
5718 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5720 for (fp = outer_function_chain; fp; fp = fp->outer)
5721 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5722 if (TREE_PURPOSE (link) == function)
5724 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5726 return adjust_trampoline_addr (tramp);
5729 /* None exists; we must make one. */
5731 /* Find the `struct function' for the function containing FUNCTION. */
5733 fn_context = decl_function_context (function);
5734 if (fn_context != current_function_decl
5735 && fn_context != inline_function_decl)
5736 fp = find_function_data (fn_context);
5738 /* Allocate run-time space for this trampoline
5739 (usually in the defining function's stack frame). */
5740 #ifdef ALLOCATE_TRAMPOLINE
5741 tramp = ALLOCATE_TRAMPOLINE (fp);
5743 /* If rounding needed, allocate extra space
5744 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5745 #ifdef TRAMPOLINE_ALIGNMENT
5746 #define TRAMPOLINE_REAL_SIZE \
5747 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5749 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
5751 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5755 /* Record the trampoline for reuse and note it for later initialization
5756 by expand_function_end. */
5759 rtlexp = make_node (RTL_EXPR);
5760 RTL_EXPR_RTL (rtlexp) = tramp;
5761 fp->x_trampoline_list = tree_cons (function, rtlexp,
5762 fp->x_trampoline_list);
5766 /* Make the RTL_EXPR node temporary, not momentary, so that the
5767 trampoline_list doesn't become garbage. */
5768 rtlexp = make_node (RTL_EXPR);
5770 RTL_EXPR_RTL (rtlexp) = tramp;
5771 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
5774 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
5775 return adjust_trampoline_addr (tramp);
5778 /* Given a trampoline address,
5779 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5782 round_trampoline_addr (tramp)
5785 #ifdef TRAMPOLINE_ALIGNMENT
5786 /* Round address up to desired boundary. */
5787 rtx temp = gen_reg_rtx (Pmode);
5788 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1);
5789 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
5791 temp = expand_simple_binop (Pmode, PLUS, tramp, addend,
5792 temp, 0, OPTAB_LIB_WIDEN);
5793 tramp = expand_simple_binop (Pmode, AND, temp, mask,
5794 temp, 0, OPTAB_LIB_WIDEN);
5799 /* Given a trampoline address, round it then apply any
5800 platform-specific adjustments so that the result can be used for a
5804 adjust_trampoline_addr (tramp)
5807 tramp = round_trampoline_addr (tramp);
5808 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5809 TRAMPOLINE_ADJUST_ADDRESS (tramp);
5814 /* Put all this function's BLOCK nodes including those that are chained
5815 onto the first block into a vector, and return it.
5816 Also store in each NOTE for the beginning or end of a block
5817 the index of that block in the vector.
5818 The arguments are BLOCK, the chain of top-level blocks of the function,
5819 and INSNS, the insn chain of the function. */
5825 tree *block_vector, *last_block_vector;
5827 tree block = DECL_INITIAL (current_function_decl);
5832 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5833 depth-first order. */
5834 block_vector = get_block_vector (block, &n_blocks);
5835 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree));
5837 last_block_vector = identify_blocks_1 (get_insns (),
5839 block_vector + n_blocks,
5842 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5843 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5844 if (0 && last_block_vector != block_vector + n_blocks)
5847 free (block_vector);
5851 /* Subroutine of identify_blocks. Do the block substitution on the
5852 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5854 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5855 BLOCK_VECTOR is incremented for each block seen. */
5858 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack)
5861 tree *end_block_vector;
5862 tree *orig_block_stack;
5865 tree *block_stack = orig_block_stack;
5867 for (insn = insns; insn; insn = NEXT_INSN (insn))
5869 if (GET_CODE (insn) == NOTE)
5871 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5875 /* If there are more block notes than BLOCKs, something
5877 if (block_vector == end_block_vector)
5880 b = *block_vector++;
5881 NOTE_BLOCK (insn) = b;
5884 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
5886 /* If there are more NOTE_INSN_BLOCK_ENDs than
5887 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5888 if (block_stack == orig_block_stack)
5891 NOTE_BLOCK (insn) = *--block_stack;
5894 else if (GET_CODE (insn) == CALL_INSN
5895 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
5897 rtx cp = PATTERN (insn);
5899 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector,
5900 end_block_vector, block_stack);
5902 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector,
5903 end_block_vector, block_stack);
5905 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector,
5906 end_block_vector, block_stack);
5910 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5911 something is badly wrong. */
5912 if (block_stack != orig_block_stack)
5915 return block_vector;
5918 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5919 and create duplicate blocks. */
5920 /* ??? Need an option to either create block fragments or to create
5921 abstract origin duplicates of a source block. It really depends
5922 on what optimization has been performed. */
5927 tree block = DECL_INITIAL (current_function_decl);
5928 varray_type block_stack;
5930 if (block == NULL_TREE)
5933 VARRAY_TREE_INIT (block_stack, 10, "block_stack");
5935 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5936 reorder_blocks_0 (block);
5938 /* Prune the old trees away, so that they don't get in the way. */
5939 BLOCK_SUBBLOCKS (block) = NULL_TREE;
5940 BLOCK_CHAIN (block) = NULL_TREE;
5942 /* Recreate the block tree from the note nesting. */
5943 reorder_blocks_1 (get_insns (), block, &block_stack);
5944 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
5946 /* Remove deleted blocks from the block fragment chains. */
5947 reorder_fix_fragments (block);
5949 VARRAY_FREE (block_stack);
5952 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5955 reorder_blocks_0 (block)
5960 TREE_ASM_WRITTEN (block) = 0;
5961 reorder_blocks_0 (BLOCK_SUBBLOCKS (block));
5962 block = BLOCK_CHAIN (block);
5967 reorder_blocks_1 (insns, current_block, p_block_stack)
5970 varray_type *p_block_stack;
5974 for (insn = insns; insn; insn = NEXT_INSN (insn))
5976 if (GET_CODE (insn) == NOTE)
5978 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
5980 tree block = NOTE_BLOCK (insn);
5982 /* If we have seen this block before, that means it now
5983 spans multiple address regions. Create a new fragment. */
5984 if (TREE_ASM_WRITTEN (block))
5986 tree new_block = copy_node (block);
5989 origin = (BLOCK_FRAGMENT_ORIGIN (block)
5990 ? BLOCK_FRAGMENT_ORIGIN (block)
5992 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
5993 BLOCK_FRAGMENT_CHAIN (new_block)
5994 = BLOCK_FRAGMENT_CHAIN (origin);
5995 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
5997 NOTE_BLOCK (insn) = new_block;
6001 BLOCK_SUBBLOCKS (block) = 0;
6002 TREE_ASM_WRITTEN (block) = 1;
6003 BLOCK_SUPERCONTEXT (block) = current_block;
6004 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
6005 BLOCK_SUBBLOCKS (current_block) = block;
6006 current_block = block;
6007 VARRAY_PUSH_TREE (*p_block_stack, block);
6009 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
6011 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack);
6012 VARRAY_POP (*p_block_stack);
6013 BLOCK_SUBBLOCKS (current_block)
6014 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
6015 current_block = BLOCK_SUPERCONTEXT (current_block);
6018 else if (GET_CODE (insn) == CALL_INSN
6019 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
6021 rtx cp = PATTERN (insn);
6022 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack);
6024 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack);
6026 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
6031 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
6032 appears in the block tree, select one of the fragments to become
6033 the new origin block. */
6036 reorder_fix_fragments (block)
6041 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
6042 tree new_origin = NULL_TREE;
6046 if (! TREE_ASM_WRITTEN (dup_origin))
6048 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
6050 /* Find the first of the remaining fragments. There must
6051 be at least one -- the current block. */
6052 while (! TREE_ASM_WRITTEN (new_origin))
6053 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
6054 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
6057 else if (! dup_origin)
6060 /* Re-root the rest of the fragments to the new origin. In the
6061 case that DUP_ORIGIN was null, that means BLOCK was the origin
6062 of a chain of fragments and we want to remove those fragments
6063 that didn't make it to the output. */
6066 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
6071 if (TREE_ASM_WRITTEN (chain))
6073 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
6075 pp = &BLOCK_FRAGMENT_CHAIN (chain);
6077 chain = BLOCK_FRAGMENT_CHAIN (chain);
6082 reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
6083 block = BLOCK_CHAIN (block);
6087 /* Reverse the order of elements in the chain T of blocks,
6088 and return the new head of the chain (old last element). */
6094 tree prev = 0, decl, next;
6095 for (decl = t; decl; decl = next)
6097 next = BLOCK_CHAIN (decl);
6098 BLOCK_CHAIN (decl) = prev;
6104 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6105 non-NULL, list them all into VECTOR, in a depth-first preorder
6106 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6110 all_blocks (block, vector)
6118 TREE_ASM_WRITTEN (block) = 0;
6120 /* Record this block. */
6122 vector[n_blocks] = block;
6126 /* Record the subblocks, and their subblocks... */
6127 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
6128 vector ? vector + n_blocks : 0);
6129 block = BLOCK_CHAIN (block);
6135 /* Return a vector containing all the blocks rooted at BLOCK. The
6136 number of elements in the vector is stored in N_BLOCKS_P. The
6137 vector is dynamically allocated; it is the caller's responsibility
6138 to call `free' on the pointer returned. */
6141 get_block_vector (block, n_blocks_p)
6147 *n_blocks_p = all_blocks (block, NULL);
6148 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree));
6149 all_blocks (block, block_vector);
6151 return block_vector;
6154 static int next_block_index = 2;
6156 /* Set BLOCK_NUMBER for all the blocks in FN. */
6166 /* For SDB and XCOFF debugging output, we start numbering the blocks
6167 from 1 within each function, rather than keeping a running
6169 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6170 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
6171 next_block_index = 1;
6174 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
6176 /* The top-level BLOCK isn't numbered at all. */
6177 for (i = 1; i < n_blocks; ++i)
6178 /* We number the blocks from two. */
6179 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
6181 free (block_vector);
6186 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6189 debug_find_var_in_block_tree (var, block)
6195 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
6199 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
6201 tree ret = debug_find_var_in_block_tree (var, t);
6209 /* Allocate a function structure and reset its contents to the defaults. */
6212 prepare_function_start ()
6214 cfun = (struct function *) ggc_alloc_cleared (sizeof (struct function));
6216 init_stmt_for_function ();
6217 init_eh_for_function ();
6219 cse_not_expected = ! optimize;
6221 /* Caller save not needed yet. */
6222 caller_save_needed = 0;
6224 /* No stack slots have been made yet. */
6225 stack_slot_list = 0;
6227 current_function_has_nonlocal_label = 0;
6228 current_function_has_nonlocal_goto = 0;
6230 /* There is no stack slot for handling nonlocal gotos. */
6231 nonlocal_goto_handler_slots = 0;
6232 nonlocal_goto_stack_level = 0;
6234 /* No labels have been declared for nonlocal use. */
6235 nonlocal_labels = 0;
6236 nonlocal_goto_handler_labels = 0;
6238 /* No function calls so far in this function. */
6239 function_call_count = 0;
6241 /* No parm regs have been allocated.
6242 (This is important for output_inline_function.) */
6243 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
6245 /* Initialize the RTL mechanism. */
6248 /* Initialize the queue of pending postincrement and postdecrements,
6249 and some other info in expr.c. */
6252 /* We haven't done register allocation yet. */
6255 init_varasm_status (cfun);
6257 /* Clear out data used for inlining. */
6258 cfun->inlinable = 0;
6259 cfun->original_decl_initial = 0;
6260 cfun->original_arg_vector = 0;
6262 cfun->stack_alignment_needed = STACK_BOUNDARY;
6263 cfun->preferred_stack_boundary = STACK_BOUNDARY;
6265 /* Set if a call to setjmp is seen. */
6266 current_function_calls_setjmp = 0;
6268 /* Set if a call to longjmp is seen. */
6269 current_function_calls_longjmp = 0;
6271 current_function_calls_alloca = 0;
6272 current_function_contains_functions = 0;
6273 current_function_is_leaf = 0;
6274 current_function_nothrow = 0;
6275 current_function_sp_is_unchanging = 0;
6276 current_function_uses_only_leaf_regs = 0;
6277 current_function_has_computed_jump = 0;
6278 current_function_is_thunk = 0;
6280 current_function_returns_pcc_struct = 0;
6281 current_function_returns_struct = 0;
6282 current_function_epilogue_delay_list = 0;
6283 current_function_uses_const_pool = 0;
6284 current_function_uses_pic_offset_table = 0;
6285 current_function_cannot_inline = 0;
6287 /* We have not yet needed to make a label to jump to for tail-recursion. */
6288 tail_recursion_label = 0;
6290 /* We haven't had a need to make a save area for ap yet. */
6291 arg_pointer_save_area = 0;
6293 /* No stack slots allocated yet. */
6296 /* No SAVE_EXPRs in this function yet. */
6299 /* No RTL_EXPRs in this function yet. */
6302 /* Set up to allocate temporaries. */
6305 /* Indicate that we need to distinguish between the return value of the
6306 present function and the return value of a function being called. */
6307 rtx_equal_function_value_matters = 1;
6309 /* Indicate that we have not instantiated virtual registers yet. */
6310 virtuals_instantiated = 0;
6312 /* Indicate that we want CONCATs now. */
6313 generating_concat_p = 1;
6315 /* Indicate we have no need of a frame pointer yet. */
6316 frame_pointer_needed = 0;
6318 /* By default assume not varargs or stdarg. */
6319 current_function_varargs = 0;
6320 current_function_stdarg = 0;
6322 /* We haven't made any trampolines for this function yet. */
6323 trampoline_list = 0;
6325 init_pending_stack_adjust ();
6326 inhibit_defer_pop = 0;
6328 current_function_outgoing_args_size = 0;
6330 if (init_lang_status)
6331 (*init_lang_status) (cfun);
6332 if (init_machine_status)
6333 (*init_machine_status) (cfun);
6336 /* Initialize the rtl expansion mechanism so that we can do simple things
6337 like generate sequences. This is used to provide a context during global
6338 initialization of some passes. */
6340 init_dummy_function_start ()
6342 prepare_function_start ();
6345 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6346 and initialize static variables for generating RTL for the statements
6350 init_function_start (subr, filename, line)
6352 const char *filename;
6355 prepare_function_start ();
6357 current_function_name = (*decl_printable_name) (subr, 2);
6360 /* Nonzero if this is a nested function that uses a static chain. */
6362 current_function_needs_context
6363 = (decl_function_context (current_function_decl) != 0
6364 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6366 /* Within function body, compute a type's size as soon it is laid out. */
6367 immediate_size_expand++;
6369 /* Prevent ever trying to delete the first instruction of a function.
6370 Also tell final how to output a linenum before the function prologue.
6371 Note linenums could be missing, e.g. when compiling a Java .class file. */
6373 emit_line_note (filename, line);
6375 /* Make sure first insn is a note even if we don't want linenums.
6376 This makes sure the first insn will never be deleted.
6377 Also, final expects a note to appear there. */
6378 emit_note (NULL, NOTE_INSN_DELETED);
6380 /* Set flags used by final.c. */
6381 if (aggregate_value_p (DECL_RESULT (subr)))
6383 #ifdef PCC_STATIC_STRUCT_RETURN
6384 current_function_returns_pcc_struct = 1;
6386 current_function_returns_struct = 1;
6389 /* Warn if this value is an aggregate type,
6390 regardless of which calling convention we are using for it. */
6391 if (warn_aggregate_return
6392 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6393 warning ("function returns an aggregate");
6395 current_function_returns_pointer
6396 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
6399 /* Make sure all values used by the optimization passes have sane
6402 init_function_for_compilation ()
6406 /* No prologue/epilogue insns yet. */
6407 VARRAY_GROW (prologue, 0);
6408 VARRAY_GROW (epilogue, 0);
6409 VARRAY_GROW (sibcall_epilogue, 0);
6412 /* Indicate that the current function uses extra args
6413 not explicitly mentioned in the argument list in any fashion. */
6418 current_function_varargs = 1;
6421 /* Expand a call to __main at the beginning of a possible main function. */
6423 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6424 #undef HAS_INIT_SECTION
6425 #define HAS_INIT_SECTION
6429 expand_main_function ()
6431 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6432 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
6434 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
6438 /* Forcibly align the stack. */
6439 #ifdef STACK_GROWS_DOWNWARD
6440 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
6441 stack_pointer_rtx, 1, OPTAB_WIDEN);
6443 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
6444 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN);
6445 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align),
6446 stack_pointer_rtx, 1, OPTAB_WIDEN);
6448 if (tmp != stack_pointer_rtx)
6449 emit_move_insn (stack_pointer_rtx, tmp);
6451 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6452 tmp = force_reg (Pmode, const0_rtx);
6453 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
6454 seq = gen_sequence ();
6457 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp))
6458 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG)
6461 emit_insn_before (seq, tmp);
6467 #ifndef HAS_INIT_SECTION
6468 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), LCT_NORMAL,
6473 extern struct obstack permanent_obstack;
6475 /* The PENDING_SIZES represent the sizes of variable-sized types.
6476 Create RTL for the various sizes now (using temporary variables),
6477 so that we can refer to the sizes from the RTL we are generating
6478 for the current function. The PENDING_SIZES are a TREE_LIST. The
6479 TREE_VALUE of each node is a SAVE_EXPR. */
6482 expand_pending_sizes (pending_sizes)
6487 /* Evaluate now the sizes of any types declared among the arguments. */
6488 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem))
6490 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
6491 /* Flush the queue in case this parameter declaration has
6497 /* Start the RTL for a new function, and set variables used for
6499 SUBR is the FUNCTION_DECL node.
6500 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6501 the function's parameters, which must be run at any return statement. */
6504 expand_function_start (subr, parms_have_cleanups)
6506 int parms_have_cleanups;
6509 rtx last_ptr = NULL_RTX;
6511 /* Make sure volatile mem refs aren't considered
6512 valid operands of arithmetic insns. */
6513 init_recog_no_volatile ();
6515 current_function_instrument_entry_exit
6516 = (flag_instrument_function_entry_exit
6517 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6519 current_function_profile
6521 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6523 current_function_limit_stack
6524 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
6526 /* If function gets a static chain arg, store it in the stack frame.
6527 Do this first, so it gets the first stack slot offset. */
6528 if (current_function_needs_context)
6530 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6532 /* Delay copying static chain if it is not a register to avoid
6533 conflicts with regs used for parameters. */
6534 if (! SMALL_REGISTER_CLASSES
6535 || GET_CODE (static_chain_incoming_rtx) == REG)
6536 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6539 /* If the parameters of this function need cleaning up, get a label
6540 for the beginning of the code which executes those cleanups. This must
6541 be done before doing anything with return_label. */
6542 if (parms_have_cleanups)
6543 cleanup_label = gen_label_rtx ();
6547 /* Make the label for return statements to jump to. Do not special
6548 case machines with special return instructions -- they will be
6549 handled later during jump, ifcvt, or epilogue creation. */
6550 return_label = gen_label_rtx ();
6552 /* Initialize rtx used to return the value. */
6553 /* Do this before assign_parms so that we copy the struct value address
6554 before any library calls that assign parms might generate. */
6556 /* Decide whether to return the value in memory or in a register. */
6557 if (aggregate_value_p (DECL_RESULT (subr)))
6559 /* Returning something that won't go in a register. */
6560 rtx value_address = 0;
6562 #ifdef PCC_STATIC_STRUCT_RETURN
6563 if (current_function_returns_pcc_struct)
6565 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6566 value_address = assemble_static_space (size);
6571 /* Expect to be passed the address of a place to store the value.
6572 If it is passed as an argument, assign_parms will take care of
6574 if (struct_value_incoming_rtx)
6576 value_address = gen_reg_rtx (Pmode);
6577 emit_move_insn (value_address, struct_value_incoming_rtx);
6582 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6583 set_mem_attributes (x, DECL_RESULT (subr), 1);
6584 SET_DECL_RTL (DECL_RESULT (subr), x);
6587 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6588 /* If return mode is void, this decl rtl should not be used. */
6589 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
6592 /* Compute the return values into a pseudo reg, which we will copy
6593 into the true return register after the cleanups are done. */
6595 /* In order to figure out what mode to use for the pseudo, we
6596 figure out what the mode of the eventual return register will
6597 actually be, and use that. */
6599 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)),
6602 /* Structures that are returned in registers are not aggregate_value_p,
6603 so we may see a PARALLEL. Don't play pseudo games with this. */
6604 if (! REG_P (hard_reg))
6605 SET_DECL_RTL (DECL_RESULT (subr), hard_reg);
6608 /* Create the pseudo. */
6609 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg)));
6611 /* Needed because we may need to move this to memory
6612 in case it's a named return value whose address is taken. */
6613 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6617 /* Initialize rtx for parameters and local variables.
6618 In some cases this requires emitting insns. */
6620 assign_parms (subr);
6622 /* Copy the static chain now if it wasn't a register. The delay is to
6623 avoid conflicts with the parameter passing registers. */
6625 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6626 if (GET_CODE (static_chain_incoming_rtx) != REG)
6627 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6629 /* The following was moved from init_function_start.
6630 The move is supposed to make sdb output more accurate. */
6631 /* Indicate the beginning of the function body,
6632 as opposed to parm setup. */
6633 emit_note (NULL, NOTE_INSN_FUNCTION_BEG);
6635 if (GET_CODE (get_last_insn ()) != NOTE)
6636 emit_note (NULL, NOTE_INSN_DELETED);
6637 parm_birth_insn = get_last_insn ();
6639 context_display = 0;
6640 if (current_function_needs_context)
6642 /* Fetch static chain values for containing functions. */
6643 tem = decl_function_context (current_function_decl);
6644 /* Copy the static chain pointer into a pseudo. If we have
6645 small register classes, copy the value from memory if
6646 static_chain_incoming_rtx is a REG. */
6649 /* If the static chain originally came in a register, put it back
6650 there, then move it out in the next insn. The reason for
6651 this peculiar code is to satisfy function integration. */
6652 if (SMALL_REGISTER_CLASSES
6653 && GET_CODE (static_chain_incoming_rtx) == REG)
6654 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6655 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6660 tree rtlexp = make_node (RTL_EXPR);
6662 RTL_EXPR_RTL (rtlexp) = last_ptr;
6663 context_display = tree_cons (tem, rtlexp, context_display);
6664 tem = decl_function_context (tem);
6667 /* Chain thru stack frames, assuming pointer to next lexical frame
6668 is found at the place we always store it. */
6669 #ifdef FRAME_GROWS_DOWNWARD
6670 last_ptr = plus_constant (last_ptr,
6671 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode));
6673 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr));
6674 set_mem_alias_set (last_ptr, get_frame_alias_set ());
6675 last_ptr = copy_to_reg (last_ptr);
6677 /* If we are not optimizing, ensure that we know that this
6678 piece of context is live over the entire function. */
6680 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6685 if (current_function_instrument_entry_exit)
6687 rtx fun = DECL_RTL (current_function_decl);
6688 if (GET_CODE (fun) == MEM)
6689 fun = XEXP (fun, 0);
6692 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode,
6694 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6696 hard_frame_pointer_rtx),
6700 if (current_function_profile)
6702 current_function_profile_label_no = profile_label_no++;
6704 PROFILE_HOOK (current_function_profile_label_no);
6708 /* After the display initializations is where the tail-recursion label
6709 should go, if we end up needing one. Ensure we have a NOTE here
6710 since some things (like trampolines) get placed before this. */
6711 tail_recursion_reentry = emit_note (NULL, NOTE_INSN_DELETED);
6713 /* Evaluate now the sizes of any types declared among the arguments. */
6714 expand_pending_sizes (nreverse (get_pending_sizes ()));
6716 /* Make sure there is a line number after the function entry setup code. */
6717 force_next_line_note ();
6720 /* Undo the effects of init_dummy_function_start. */
6722 expand_dummy_function_end ()
6724 /* End any sequences that failed to be closed due to syntax errors. */
6725 while (in_sequence_p ())
6728 /* Outside function body, can't compute type's actual size
6729 until next function's body starts. */
6731 free_after_parsing (cfun);
6732 free_after_compilation (cfun);
6736 /* Call DOIT for each hard register used as a return value from
6737 the current function. */
6740 diddle_return_value (doit, arg)
6741 void (*doit) PARAMS ((rtx, void *));
6744 rtx outgoing = current_function_return_rtx;
6749 if (GET_CODE (outgoing) == REG)
6750 (*doit) (outgoing, arg);
6751 else if (GET_CODE (outgoing) == PARALLEL)
6755 for (i = 0; i < XVECLEN (outgoing, 0); i++)
6757 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
6759 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6766 do_clobber_return_reg (reg, arg)
6768 void *arg ATTRIBUTE_UNUSED;
6770 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
6774 clobber_return_register ()
6776 diddle_return_value (do_clobber_return_reg, NULL);
6778 /* In case we do use pseudo to return value, clobber it too. */
6779 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6781 tree decl_result = DECL_RESULT (current_function_decl);
6782 rtx decl_rtl = DECL_RTL (decl_result);
6783 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
6785 do_clobber_return_reg (decl_rtl, NULL);
6791 do_use_return_reg (reg, arg)
6793 void *arg ATTRIBUTE_UNUSED;
6795 emit_insn (gen_rtx_USE (VOIDmode, reg));
6799 use_return_register ()
6801 diddle_return_value (do_use_return_reg, NULL);
6804 /* Generate RTL for the end of the current function.
6805 FILENAME and LINE are the current position in the source file.
6807 It is up to language-specific callers to do cleanups for parameters--
6808 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6811 expand_function_end (filename, line, end_bindings)
6812 const char *filename;
6819 #ifdef TRAMPOLINE_TEMPLATE
6820 static rtx initial_trampoline;
6823 finish_expr_for_function ();
6825 /* If arg_pointer_save_area was referenced only from a nested
6826 function, we will not have initialized it yet. Do that now. */
6827 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init)
6828 get_arg_pointer_save_area (cfun);
6830 #ifdef NON_SAVING_SETJMP
6831 /* Don't put any variables in registers if we call setjmp
6832 on a machine that fails to restore the registers. */
6833 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6835 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6836 setjmp_protect (DECL_INITIAL (current_function_decl));
6838 setjmp_protect_args ();
6842 /* Initialize any trampolines required by this function. */
6843 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6845 tree function = TREE_PURPOSE (link);
6846 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function);
6847 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6848 #ifdef TRAMPOLINE_TEMPLATE
6853 #ifdef TRAMPOLINE_TEMPLATE
6854 /* First make sure this compilation has a template for
6855 initializing trampolines. */
6856 if (initial_trampoline == 0)
6859 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
6860 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
6862 ggc_add_rtx_root (&initial_trampoline, 1);
6866 /* Generate insns to initialize the trampoline. */
6868 tramp = round_trampoline_addr (XEXP (tramp, 0));
6869 #ifdef TRAMPOLINE_TEMPLATE
6870 blktramp = replace_equiv_address (initial_trampoline, tramp);
6871 emit_block_move (blktramp, initial_trampoline,
6872 GEN_INT (TRAMPOLINE_SIZE));
6874 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
6878 /* Put those insns at entry to the containing function (this one). */
6879 emit_insns_before (seq, tail_recursion_reentry);
6882 /* If we are doing stack checking and this function makes calls,
6883 do a stack probe at the start of the function to ensure we have enough
6884 space for another stack frame. */
6885 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
6889 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
6890 if (GET_CODE (insn) == CALL_INSN)
6893 probe_stack_range (STACK_CHECK_PROTECT,
6894 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
6897 emit_insns_before (seq, tail_recursion_reentry);
6902 /* Warn about unused parms if extra warnings were specified. */
6903 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
6904 warning. WARN_UNUSED_PARAMETER is negative when set by
6906 if (warn_unused_parameter > 0
6907 || (warn_unused_parameter < 0 && extra_warnings))
6911 for (decl = DECL_ARGUMENTS (current_function_decl);
6912 decl; decl = TREE_CHAIN (decl))
6913 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6914 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl))
6915 warning_with_decl (decl, "unused parameter `%s'");
6918 /* Delete handlers for nonlocal gotos if nothing uses them. */
6919 if (nonlocal_goto_handler_slots != 0
6920 && ! current_function_has_nonlocal_label)
6923 /* End any sequences that failed to be closed due to syntax errors. */
6924 while (in_sequence_p ())
6927 /* Outside function body, can't compute type's actual size
6928 until next function's body starts. */
6929 immediate_size_expand--;
6931 clear_pending_stack_adjust ();
6932 do_pending_stack_adjust ();
6934 /* Mark the end of the function body.
6935 If control reaches this insn, the function can drop through
6936 without returning a value. */
6937 emit_note (NULL, NOTE_INSN_FUNCTION_END);
6939 /* Must mark the last line number note in the function, so that the test
6940 coverage code can avoid counting the last line twice. This just tells
6941 the code to ignore the immediately following line note, since there
6942 already exists a copy of this note somewhere above. This line number
6943 note is still needed for debugging though, so we can't delete it. */
6944 if (flag_test_coverage)
6945 emit_note (NULL, NOTE_INSN_REPEATED_LINE_NUMBER);
6947 /* Output a linenumber for the end of the function.
6948 SDB depends on this. */
6949 emit_line_note_force (filename, line);
6951 /* Before the return label (if any), clobber the return
6952 registers so that they are not propagated live to the rest of
6953 the function. This can only happen with functions that drop
6954 through; if there had been a return statement, there would
6955 have either been a return rtx, or a jump to the return label.
6957 We delay actual code generation after the current_function_value_rtx
6959 clobber_after = get_last_insn ();
6961 /* Output the label for the actual return from the function,
6962 if one is expected. This happens either because a function epilogue
6963 is used instead of a return instruction, or because a return was done
6964 with a goto in order to run local cleanups, or because of pcc-style
6965 structure returning. */
6967 emit_label (return_label);
6969 /* C++ uses this. */
6971 expand_end_bindings (0, 0, 0);
6973 if (current_function_instrument_entry_exit)
6975 rtx fun = DECL_RTL (current_function_decl);
6976 if (GET_CODE (fun) == MEM)
6977 fun = XEXP (fun, 0);
6980 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode,
6982 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6984 hard_frame_pointer_rtx),
6988 /* Let except.c know where it should emit the call to unregister
6989 the function context for sjlj exceptions. */
6990 if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
6991 sjlj_emit_function_exit_after (get_last_insn ());
6993 /* If we had calls to alloca, and this machine needs
6994 an accurate stack pointer to exit the function,
6995 insert some code to save and restore the stack pointer. */
6996 #ifdef EXIT_IGNORE_STACK
6997 if (! EXIT_IGNORE_STACK)
6999 if (current_function_calls_alloca)
7003 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
7004 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
7007 /* If scalar return value was computed in a pseudo-reg, or was a named
7008 return value that got dumped to the stack, copy that to the hard
7010 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
7012 tree decl_result = DECL_RESULT (current_function_decl);
7013 rtx decl_rtl = DECL_RTL (decl_result);
7015 if (REG_P (decl_rtl)
7016 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
7017 : DECL_REGISTER (decl_result))
7019 rtx real_decl_rtl = current_function_return_rtx;
7021 /* This should be set in assign_parms. */
7022 if (! REG_FUNCTION_VALUE_P (real_decl_rtl))
7025 /* If this is a BLKmode structure being returned in registers,
7026 then use the mode computed in expand_return. Note that if
7027 decl_rtl is memory, then its mode may have been changed,
7028 but that current_function_return_rtx has not. */
7029 if (GET_MODE (real_decl_rtl) == BLKmode)
7030 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
7032 /* If a named return value dumped decl_return to memory, then
7033 we may need to re-do the PROMOTE_MODE signed/unsigned
7035 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
7037 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result));
7039 #ifdef PROMOTE_FUNCTION_RETURN
7040 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
7044 convert_move (real_decl_rtl, decl_rtl, unsignedp);
7046 else if (GET_CODE (real_decl_rtl) == PARALLEL)
7047 emit_group_load (real_decl_rtl, decl_rtl,
7048 int_size_in_bytes (TREE_TYPE (decl_result)));
7050 emit_move_insn (real_decl_rtl, decl_rtl);
7054 /* If returning a structure, arrange to return the address of the value
7055 in a place where debuggers expect to find it.
7057 If returning a structure PCC style,
7058 the caller also depends on this value.
7059 And current_function_returns_pcc_struct is not necessarily set. */
7060 if (current_function_returns_struct
7061 || current_function_returns_pcc_struct)
7064 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
7065 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
7066 #ifdef FUNCTION_OUTGOING_VALUE
7068 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
7069 current_function_decl);
7072 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl);
7075 /* Mark this as a function return value so integrate will delete the
7076 assignment and USE below when inlining this function. */
7077 REG_FUNCTION_VALUE_P (outgoing) = 1;
7079 #ifdef POINTERS_EXTEND_UNSIGNED
7080 /* The address may be ptr_mode and OUTGOING may be Pmode. */
7081 if (GET_MODE (outgoing) != GET_MODE (value_address))
7082 value_address = convert_memory_address (GET_MODE (outgoing),
7086 emit_move_insn (outgoing, value_address);
7088 /* Show return register used to hold result (in this case the address
7090 current_function_return_rtx = outgoing;
7093 /* If this is an implementation of throw, do what's necessary to
7094 communicate between __builtin_eh_return and the epilogue. */
7095 expand_eh_return ();
7097 /* Emit the actual code to clobber return register. */
7102 clobber_return_register ();
7103 seq = gen_sequence ();
7106 after = emit_insn_after (seq, clobber_after);
7108 if (clobber_after != after)
7109 cfun->x_clobber_return_insn = after;
7112 /* ??? This should no longer be necessary since stupid is no longer with
7113 us, but there are some parts of the compiler (eg reload_combine, and
7114 sh mach_dep_reorg) that still try and compute their own lifetime info
7115 instead of using the general framework. */
7116 use_return_register ();
7118 /* Fix up any gotos that jumped out to the outermost
7119 binding level of the function.
7120 Must follow emitting RETURN_LABEL. */
7122 /* If you have any cleanups to do at this point,
7123 and they need to create temporary variables,
7124 then you will lose. */
7125 expand_fixups (get_insns ());
7129 get_arg_pointer_save_area (f)
7132 rtx ret = f->x_arg_pointer_save_area;
7136 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f);
7137 f->x_arg_pointer_save_area = ret;
7140 if (f == cfun && ! f->arg_pointer_save_area_init)
7144 /* Save the arg pointer at the beginning of the function. The
7145 generated stack slot may not be a valid memory address, so we
7146 have to check it and fix it if necessary. */
7148 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx);
7149 seq = gen_sequence ();
7152 push_topmost_sequence ();
7153 emit_insn_after (seq, get_insns ());
7154 pop_topmost_sequence ();
7160 /* Extend a vector that records the INSN_UIDs of INSNS (either a
7161 sequence or a single insn). */
7164 record_insns (insns, vecp)
7168 if (GET_CODE (insns) == SEQUENCE)
7170 int len = XVECLEN (insns, 0);
7171 int i = VARRAY_SIZE (*vecp);
7173 VARRAY_GROW (*vecp, i + len);
7176 VARRAY_INT (*vecp, i) = INSN_UID (XVECEXP (insns, 0, len));
7182 int i = VARRAY_SIZE (*vecp);
7183 VARRAY_GROW (*vecp, i + 1);
7184 VARRAY_INT (*vecp, i) = INSN_UID (insns);
7188 /* Determine how many INSN_UIDs in VEC are part of INSN. */
7191 contains (insn, vec)
7197 if (GET_CODE (insn) == INSN
7198 && GET_CODE (PATTERN (insn)) == SEQUENCE)
7201 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
7202 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7203 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
7209 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7210 if (INSN_UID (insn) == VARRAY_INT (vec, j))
7217 prologue_epilogue_contains (insn)
7220 if (contains (insn, prologue))
7222 if (contains (insn, epilogue))
7228 sibcall_epilogue_contains (insn)
7231 if (sibcall_epilogue)
7232 return contains (insn, sibcall_epilogue);
7237 /* Insert gen_return at the end of block BB. This also means updating
7238 block_for_insn appropriately. */
7241 emit_return_into_block (bb, line_note)
7247 p = NEXT_INSN (bb->end);
7248 end = emit_jump_insn_after (gen_return (), bb->end);
7250 emit_line_note_after (NOTE_SOURCE_FILE (line_note),
7251 NOTE_LINE_NUMBER (line_note), PREV_INSN (bb->end));
7253 #endif /* HAVE_return */
7255 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7257 /* These functions convert the epilogue into a variant that does not modify the
7258 stack pointer. This is used in cases where a function returns an object
7259 whose size is not known until it is computed. The called function leaves the
7260 object on the stack, leaves the stack depressed, and returns a pointer to
7263 What we need to do is track all modifications and references to the stack
7264 pointer, deleting the modifications and changing the references to point to
7265 the location the stack pointer would have pointed to had the modifications
7268 These functions need to be portable so we need to make as few assumptions
7269 about the epilogue as we can. However, the epilogue basically contains
7270 three things: instructions to reset the stack pointer, instructions to
7271 reload registers, possibly including the frame pointer, and an
7272 instruction to return to the caller.
7274 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7275 We also make no attempt to validate the insns we make since if they are
7276 invalid, we probably can't do anything valid. The intent is that these
7277 routines get "smarter" as more and more machines start to use them and
7278 they try operating on different epilogues.
7280 We use the following structure to track what the part of the epilogue that
7281 we've already processed has done. We keep two copies of the SP equivalence,
7282 one for use during the insn we are processing and one for use in the next
7283 insn. The difference is because one part of a PARALLEL may adjust SP
7284 and the other may use it. */
7288 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */
7289 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */
7290 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */
7291 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */
7292 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG
7293 should be set to once we no longer need
7297 static void handle_epilogue_set PARAMS ((rtx, struct epi_info *));
7298 static void emit_equiv_load PARAMS ((struct epi_info *));
7300 /* Modify SEQ, a SEQUENCE that is part of the epilogue, to no modifications
7301 to the stack pointer. Return the new sequence. */
7304 keep_stack_depressed (seq)
7308 struct epi_info info;
7310 /* If the epilogue is just a single instruction, it ust be OK as is. */
7312 if (GET_CODE (seq) != SEQUENCE)
7315 /* Otherwise, start a sequence, initialize the information we have, and
7316 process all the insns we were given. */
7319 info.sp_equiv_reg = stack_pointer_rtx;
7321 info.equiv_reg_src = 0;
7323 for (i = 0; i < XVECLEN (seq, 0); i++)
7325 rtx insn = XVECEXP (seq, 0, i);
7333 /* If this insn references the register that SP is equivalent to and
7334 we have a pending load to that register, we must force out the load
7335 first and then indicate we no longer know what SP's equivalent is. */
7336 if (info.equiv_reg_src != 0
7337 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn)))
7339 emit_equiv_load (&info);
7340 info.sp_equiv_reg = 0;
7343 info.new_sp_equiv_reg = info.sp_equiv_reg;
7344 info.new_sp_offset = info.sp_offset;
7346 /* If this is a (RETURN) and the return address is on the stack,
7347 update the address and change to an indirect jump. */
7348 if (GET_CODE (PATTERN (insn)) == RETURN
7349 || (GET_CODE (PATTERN (insn)) == PARALLEL
7350 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
7352 rtx retaddr = INCOMING_RETURN_ADDR_RTX;
7354 HOST_WIDE_INT offset = 0;
7355 rtx jump_insn, jump_set;
7357 /* If the return address is in a register, we can emit the insn
7358 unchanged. Otherwise, it must be a MEM and we see what the
7359 base register and offset are. In any case, we have to emit any
7360 pending load to the equivalent reg of SP, if any. */
7361 if (GET_CODE (retaddr) == REG)
7363 emit_equiv_load (&info);
7367 else if (GET_CODE (retaddr) == MEM
7368 && GET_CODE (XEXP (retaddr, 0)) == REG)
7369 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0;
7370 else if (GET_CODE (retaddr) == MEM
7371 && GET_CODE (XEXP (retaddr, 0)) == PLUS
7372 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG
7373 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT)
7375 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0)));
7376 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1));
7381 /* If the base of the location containing the return pointer
7382 is SP, we must update it with the replacement address. Otherwise,
7383 just build the necessary MEM. */
7384 retaddr = plus_constant (base, offset);
7385 if (base == stack_pointer_rtx)
7386 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx,
7387 plus_constant (info.sp_equiv_reg,
7390 retaddr = gen_rtx_MEM (Pmode, retaddr);
7392 /* If there is a pending load to the equivalent register for SP
7393 and we reference that register, we must load our address into
7394 a scratch register and then do that load. */
7395 if (info.equiv_reg_src
7396 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr))
7401 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7402 if (HARD_REGNO_MODE_OK (regno, Pmode)
7403 && !fixed_regs[regno]
7404 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
7405 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start,
7407 && !refers_to_regno_p (regno,
7408 regno + HARD_REGNO_NREGS (regno,
7410 info.equiv_reg_src, NULL))
7413 if (regno == FIRST_PSEUDO_REGISTER)
7416 reg = gen_rtx_REG (Pmode, regno);
7417 emit_move_insn (reg, retaddr);
7421 emit_equiv_load (&info);
7422 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr));
7424 /* Show the SET in the above insn is a RETURN. */
7425 jump_set = single_set (jump_insn);
7429 SET_IS_RETURN_P (jump_set) = 1;
7432 /* If SP is not mentioned in the pattern and its equivalent register, if
7433 any, is not modified, just emit it. Otherwise, if neither is set,
7434 replace the reference to SP and emit the insn. If none of those are
7435 true, handle each SET individually. */
7436 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))
7437 && (info.sp_equiv_reg == stack_pointer_rtx
7438 || !reg_set_p (info.sp_equiv_reg, insn)))
7440 else if (! reg_set_p (stack_pointer_rtx, insn)
7441 && (info.sp_equiv_reg == stack_pointer_rtx
7442 || !reg_set_p (info.sp_equiv_reg, insn)))
7444 if (! validate_replace_rtx (stack_pointer_rtx,
7445 plus_constant (info.sp_equiv_reg,
7452 else if (GET_CODE (PATTERN (insn)) == SET)
7453 handle_epilogue_set (PATTERN (insn), &info);
7454 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
7456 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++)
7457 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
7458 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info);
7463 info.sp_equiv_reg = info.new_sp_equiv_reg;
7464 info.sp_offset = info.new_sp_offset;
7467 seq = gen_sequence ();
7472 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7473 structure that contains information about what we've seen so far. We
7474 process this SET by either updating that data or by emitting one or
7478 handle_epilogue_set (set, p)
7482 /* First handle the case where we are setting SP. Record what it is being
7483 set from. If unknown, abort. */
7484 if (reg_set_p (stack_pointer_rtx, set))
7486 if (SET_DEST (set) != stack_pointer_rtx)
7489 if (GET_CODE (SET_SRC (set)) == PLUS
7490 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
7492 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0);
7493 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1));
7496 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0;
7498 /* If we are adjusting SP, we adjust from the old data. */
7499 if (p->new_sp_equiv_reg == stack_pointer_rtx)
7501 p->new_sp_equiv_reg = p->sp_equiv_reg;
7502 p->new_sp_offset += p->sp_offset;
7505 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG)
7511 /* Next handle the case where we are setting SP's equivalent register.
7512 If we already have a value to set it to, abort. We could update, but
7513 there seems little point in handling that case. Note that we have
7514 to allow for the case where we are setting the register set in
7515 the previous part of a PARALLEL inside a single insn. But use the
7516 old offset for any updates within this insn. */
7517 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set))
7519 if (!rtx_equal_p (p->new_sp_equiv_reg, SET_DEST (set))
7520 || p->equiv_reg_src != 0)
7524 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7525 plus_constant (p->sp_equiv_reg,
7529 /* Otherwise, replace any references to SP in the insn to its new value
7530 and emit the insn. */
7533 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7534 plus_constant (p->sp_equiv_reg,
7536 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx,
7537 plus_constant (p->sp_equiv_reg,
7543 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7549 if (p->equiv_reg_src != 0)
7550 emit_move_insn (p->sp_equiv_reg, p->equiv_reg_src);
7552 p->equiv_reg_src = 0;
7556 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7557 this into place with notes indicating where the prologue ends and where
7558 the epilogue begins. Update the basic block information when possible. */
7561 thread_prologue_and_epilogue_insns (f)
7562 rtx f ATTRIBUTE_UNUSED;
7566 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7569 #ifdef HAVE_prologue
7570 rtx prologue_end = NULL_RTX;
7572 #if defined (HAVE_epilogue) || defined(HAVE_return)
7573 rtx epilogue_end = NULL_RTX;
7576 #ifdef HAVE_prologue
7580 seq = gen_prologue ();
7583 /* Retain a map of the prologue insns. */
7584 if (GET_CODE (seq) != SEQUENCE)
7586 record_insns (seq, &prologue);
7587 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END);
7589 seq = gen_sequence ();
7592 /* Can't deal with multiple successors of the entry block
7593 at the moment. Function should always have at least one
7595 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next)
7598 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
7603 /* If the exit block has no non-fake predecessors, we don't need
7605 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7606 if ((e->flags & EDGE_FAKE) == 0)
7612 if (optimize && HAVE_return)
7614 /* If we're allowed to generate a simple return instruction,
7615 then by definition we don't need a full epilogue. Examine
7616 the block that falls through to EXIT. If it does not
7617 contain any code, examine its predecessors and try to
7618 emit (conditional) return instructions. */
7624 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7625 if (e->flags & EDGE_FALLTHRU)
7631 /* Verify that there are no active instructions in the last block. */
7633 while (label && GET_CODE (label) != CODE_LABEL)
7635 if (active_insn_p (label))
7637 label = PREV_INSN (label);
7640 if (last->head == label && GET_CODE (label) == CODE_LABEL)
7642 rtx epilogue_line_note = NULL_RTX;
7644 /* Locate the line number associated with the closing brace,
7645 if we can find one. */
7646 for (seq = get_last_insn ();
7647 seq && ! active_insn_p (seq);
7648 seq = PREV_INSN (seq))
7649 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0)
7651 epilogue_line_note = seq;
7655 for (e = last->pred; e; e = e_next)
7657 basic_block bb = e->src;
7660 e_next = e->pred_next;
7661 if (bb == ENTRY_BLOCK_PTR)
7665 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label)
7668 /* If we have an unconditional jump, we can replace that
7669 with a simple return instruction. */
7670 if (simplejump_p (jump))
7672 emit_return_into_block (bb, epilogue_line_note);
7676 /* If we have a conditional jump, we can try to replace
7677 that with a conditional return instruction. */
7678 else if (condjump_p (jump))
7682 ret = SET_SRC (PATTERN (jump));
7683 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF)
7684 loc = &XEXP (ret, 1);
7686 loc = &XEXP (ret, 2);
7687 ret = gen_rtx_RETURN (VOIDmode);
7689 if (! validate_change (jump, loc, ret, 0))
7691 if (JUMP_LABEL (jump))
7692 LABEL_NUSES (JUMP_LABEL (jump))--;
7694 /* If this block has only one successor, it both jumps
7695 and falls through to the fallthru block, so we can't
7697 if (bb->succ->succ_next == NULL)
7703 /* Fix up the CFG for the successful change we just made. */
7704 redirect_edge_succ (e, EXIT_BLOCK_PTR);
7707 /* Emit a return insn for the exit fallthru block. Whether
7708 this is still reachable will be determined later. */
7710 emit_barrier_after (last->end);
7711 emit_return_into_block (last, epilogue_line_note);
7712 epilogue_end = last->end;
7713 last->succ->flags &= ~EDGE_FALLTHRU;
7718 #ifdef HAVE_epilogue
7721 /* Find the edge that falls through to EXIT. Other edges may exist
7722 due to RETURN instructions, but those don't need epilogues.
7723 There really shouldn't be a mixture -- either all should have
7724 been converted or none, however... */
7726 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7727 if (e->flags & EDGE_FALLTHRU)
7733 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG);
7735 seq = gen_epilogue ();
7737 #ifdef INCOMING_RETURN_ADDR_RTX
7738 /* If this function returns with the stack depressed and we can support
7739 it, massage the epilogue to actually do that. */
7740 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
7741 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
7742 seq = keep_stack_depressed (seq);
7745 emit_jump_insn (seq);
7747 /* Retain a map of the epilogue insns. */
7748 if (GET_CODE (seq) != SEQUENCE)
7750 record_insns (seq, &epilogue);
7752 seq = gen_sequence ();
7755 insert_insn_on_edge (seq, e);
7762 commit_edge_insertions ();
7764 #ifdef HAVE_sibcall_epilogue
7765 /* Emit sibling epilogues before any sibling call sites. */
7766 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7768 basic_block bb = e->src;
7773 if (GET_CODE (insn) != CALL_INSN
7774 || ! SIBLING_CALL_P (insn))
7778 seq = gen_sibcall_epilogue ();
7781 i = PREV_INSN (insn);
7782 newinsn = emit_insn_before (seq, insn);
7784 /* Retain a map of the epilogue insns. Used in life analysis to
7785 avoid getting rid of sibcall epilogue insns. */
7786 record_insns (GET_CODE (seq) == SEQUENCE
7787 ? seq : newinsn, &sibcall_epilogue);
7791 #ifdef HAVE_prologue
7796 /* GDB handles `break f' by setting a breakpoint on the first
7797 line note after the prologue. Which means (1) that if
7798 there are line number notes before where we inserted the
7799 prologue we should move them, and (2) we should generate a
7800 note before the end of the first basic block, if there isn't
7803 ??? This behaviour is completely broken when dealing with
7804 multiple entry functions. We simply place the note always
7805 into first basic block and let alternate entry points
7809 for (insn = prologue_end; insn; insn = prev)
7811 prev = PREV_INSN (insn);
7812 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7814 /* Note that we cannot reorder the first insn in the
7815 chain, since rest_of_compilation relies on that
7816 remaining constant. */
7819 reorder_insns (insn, insn, prologue_end);
7823 /* Find the last line number note in the first block. */
7824 for (insn = BASIC_BLOCK (0)->end;
7825 insn != prologue_end && insn;
7826 insn = PREV_INSN (insn))
7827 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7830 /* If we didn't find one, make a copy of the first line number
7834 for (insn = next_active_insn (prologue_end);
7836 insn = PREV_INSN (insn))
7837 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7839 emit_line_note_after (NOTE_SOURCE_FILE (insn),
7840 NOTE_LINE_NUMBER (insn),
7847 #ifdef HAVE_epilogue
7852 /* Similarly, move any line notes that appear after the epilogue.
7853 There is no need, however, to be quite so anal about the existence
7855 for (insn = epilogue_end; insn; insn = next)
7857 next = NEXT_INSN (insn);
7858 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
7859 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
7865 /* Reposition the prologue-end and epilogue-begin notes after instruction
7866 scheduling and delayed branch scheduling. */
7869 reposition_prologue_and_epilogue_notes (f)
7870 rtx f ATTRIBUTE_UNUSED;
7872 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7873 rtx insn, last, note;
7876 if ((len = VARRAY_SIZE (prologue)) > 0)
7880 /* Scan from the beginning until we reach the last prologue insn.
7881 We apparently can't depend on basic_block_{head,end} after
7883 for (insn = f; insn; insn = NEXT_INSN (insn))
7885 if (GET_CODE (insn) == NOTE)
7887 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
7890 else if (contains (insn, prologue))
7902 /* Find the prologue-end note if we haven't already, and
7903 move it to just after the last prologue insn. */
7906 for (note = last; (note = NEXT_INSN (note));)
7907 if (GET_CODE (note) == NOTE
7908 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
7912 next = NEXT_INSN (note);
7914 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7915 if (GET_CODE (last) == CODE_LABEL)
7916 last = NEXT_INSN (last);
7917 reorder_insns (note, note, last);
7921 if ((len = VARRAY_SIZE (epilogue)) > 0)
7925 /* Scan from the end until we reach the first epilogue insn.
7926 We apparently can't depend on basic_block_{head,end} after
7928 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
7930 if (GET_CODE (insn) == NOTE)
7932 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
7935 else if (contains (insn, epilogue))
7945 /* Find the epilogue-begin note if we haven't already, and
7946 move it to just before the first epilogue insn. */
7949 for (note = insn; (note = PREV_INSN (note));)
7950 if (GET_CODE (note) == NOTE
7951 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
7955 if (PREV_INSN (last) != note)
7956 reorder_insns (note, note, PREV_INSN (last));
7959 #endif /* HAVE_prologue or HAVE_epilogue */
7962 /* Mark P for GC. */
7965 mark_function_status (p)
7968 struct var_refs_queue *q;
7969 struct temp_slot *t;
7976 ggc_mark_rtx (p->arg_offset_rtx);
7978 if (p->x_parm_reg_stack_loc)
7979 for (i = p->x_max_parm_reg, r = p->x_parm_reg_stack_loc;
7983 ggc_mark_rtx (p->return_rtx);
7984 ggc_mark_rtx (p->x_cleanup_label);
7985 ggc_mark_rtx (p->x_return_label);
7986 ggc_mark_rtx (p->x_save_expr_regs);
7987 ggc_mark_rtx (p->x_stack_slot_list);
7988 ggc_mark_rtx (p->x_parm_birth_insn);
7989 ggc_mark_rtx (p->x_tail_recursion_label);
7990 ggc_mark_rtx (p->x_tail_recursion_reentry);
7991 ggc_mark_rtx (p->internal_arg_pointer);
7992 ggc_mark_rtx (p->x_arg_pointer_save_area);
7993 ggc_mark_tree (p->x_rtl_expr_chain);
7994 ggc_mark_rtx (p->x_last_parm_insn);
7995 ggc_mark_tree (p->x_context_display);
7996 ggc_mark_tree (p->x_trampoline_list);
7997 ggc_mark_rtx (p->epilogue_delay_list);
7998 ggc_mark_rtx (p->x_clobber_return_insn);
8000 for (t = p->x_temp_slots; t != 0; t = t->next)
8003 ggc_mark_rtx (t->slot);
8004 ggc_mark_rtx (t->address);
8005 ggc_mark_tree (t->rtl_expr);
8006 ggc_mark_tree (t->type);
8009 for (q = p->fixup_var_refs_queue; q != 0; q = q->next)
8012 ggc_mark_rtx (q->modified);
8015 ggc_mark_rtx (p->x_nonlocal_goto_handler_slots);
8016 ggc_mark_rtx (p->x_nonlocal_goto_handler_labels);
8017 ggc_mark_rtx (p->x_nonlocal_goto_stack_level);
8018 ggc_mark_tree (p->x_nonlocal_labels);
8020 mark_hard_reg_initial_vals (p);
8023 /* Mark the struct function pointed to by *ARG for GC, if it is not
8024 NULL. This is used to mark the current function and the outer
8028 maybe_mark_struct_function (arg)
8031 struct function *f = *(struct function **) arg;
8036 ggc_mark_struct_function (f);
8039 /* Mark a struct function * for GC. This is called from ggc-common.c. */
8042 ggc_mark_struct_function (f)
8046 ggc_mark_tree (f->decl);
8048 mark_function_status (f);
8049 mark_eh_status (f->eh);
8050 mark_stmt_status (f->stmt);
8051 mark_expr_status (f->expr);
8052 mark_emit_status (f->emit);
8053 mark_varasm_status (f->varasm);
8055 if (mark_machine_status)
8056 (*mark_machine_status) (f);
8057 if (mark_lang_status)
8058 (*mark_lang_status) (f);
8060 if (f->original_arg_vector)
8061 ggc_mark_rtvec ((rtvec) f->original_arg_vector);
8062 if (f->original_decl_initial)
8063 ggc_mark_tree (f->original_decl_initial);
8065 ggc_mark_struct_function (f->outer);
8068 /* Called once, at initialization, to initialize function.c. */
8071 init_function_once ()
8073 ggc_add_root (&cfun, 1, sizeof cfun, maybe_mark_struct_function);
8074 ggc_add_root (&outer_function_chain, 1, sizeof outer_function_chain,
8075 maybe_mark_struct_function);
8077 VARRAY_INT_INIT (prologue, 0, "prologue");
8078 VARRAY_INT_INIT (epilogue, 0, "epilogue");
8079 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");