1 /* Expands front end tree to back end RTL for GCC.
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 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
24 /* This file handles the generation of rtl code from tree structure
25 at the level of the function as a whole.
26 It creates the rtl expressions for parameters and auto variables
27 and has full responsibility for allocating stack slots.
29 `expand_function_start' is called at the beginning of a function,
30 before the function body is parsed, and `expand_function_end' is
31 called after parsing the body.
33 Call `assign_stack_local' to allocate a stack slot for a local variable.
34 This is usually done during the RTL generation for the function body,
35 but it can also be done in the reload pass when a pseudo-register does
36 not get a hard register.
38 Call `put_var_into_stack' when you learn, belatedly, that a variable
39 previously given a pseudo-register must in fact go in the stack.
40 This function changes the DECL_RTL to be a stack slot instead of a reg
41 then scans all the RTL instructions so far generated to correct them. */
45 #include "coretypes.h"
56 #include "hard-reg-set.h"
57 #include "insn-config.h"
60 #include "basic-block.h"
65 #include "integrate.h"
66 #include "langhooks.h"
69 #ifndef TRAMPOLINE_ALIGNMENT
70 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
73 #ifndef LOCAL_ALIGNMENT
74 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
77 #ifndef STACK_ALIGNMENT_NEEDED
78 #define STACK_ALIGNMENT_NEEDED 1
81 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
83 /* Some systems use __main in a way incompatible with its use in gcc, in these
84 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
85 give the same symbol without quotes for an alternative entry point. You
86 must define both, or neither. */
88 #define NAME__MAIN "__main"
91 /* Round a value to the lowest integer less than it that is a multiple of
92 the required alignment. Avoid using division in case the value is
93 negative. Assume the alignment is a power of two. */
94 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
96 /* Similar, but round to the next highest integer that meets the
98 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
100 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
101 during rtl generation. If they are different register numbers, this is
102 always true. It may also be true if
103 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
104 generation. See fix_lexical_addr for details. */
106 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
107 #define NEED_SEPARATE_AP
110 /* Nonzero if function being compiled doesn't contain any calls
111 (ignoring the prologue and epilogue). This is set prior to
112 local register allocation and is valid for the remaining
114 int current_function_is_leaf;
116 /* Nonzero if function being compiled doesn't contain any instructions
117 that can throw an exception. This is set prior to final. */
119 int current_function_nothrow;
121 /* Nonzero if function being compiled doesn't modify the stack pointer
122 (ignoring the prologue and epilogue). This is only valid after
123 life_analysis has run. */
124 int current_function_sp_is_unchanging;
126 /* Nonzero if the function being compiled is a leaf function which only
127 uses leaf registers. This is valid after reload (specifically after
128 sched2) and is useful only if the port defines LEAF_REGISTERS. */
129 int current_function_uses_only_leaf_regs;
131 /* Nonzero once virtual register instantiation has been done.
132 assign_stack_local uses frame_pointer_rtx when this is nonzero.
133 calls.c:emit_library_call_value_1 uses it to set up
134 post-instantiation libcalls. */
135 int virtuals_instantiated;
137 /* Nonzero if at least one trampoline has been created. */
138 int trampolines_created;
140 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
141 static GTY(()) int funcdef_no;
143 /* These variables hold pointers to functions to create and destroy
144 target specific, per-function data structures. */
145 struct machine_function * (*init_machine_status) (void);
147 /* The FUNCTION_DECL for an inline function currently being expanded. */
148 tree inline_function_decl;
150 /* The currently compiled function. */
151 struct function *cfun = 0;
153 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
154 static GTY(()) varray_type prologue;
155 static GTY(()) varray_type epilogue;
157 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
159 static GTY(()) varray_type sibcall_epilogue;
161 /* In order to evaluate some expressions, such as function calls returning
162 structures in memory, we need to temporarily allocate stack locations.
163 We record each allocated temporary in the following structure.
165 Associated with each temporary slot is a nesting level. When we pop up
166 one level, all temporaries associated with the previous level are freed.
167 Normally, all temporaries are freed after the execution of the statement
168 in which they were created. However, if we are inside a ({...}) grouping,
169 the result may be in a temporary and hence must be preserved. If the
170 result could be in a temporary, we preserve it if we can determine which
171 one it is in. If we cannot determine which temporary may contain the
172 result, all temporaries are preserved. A temporary is preserved by
173 pretending it was allocated at the previous nesting level.
175 Automatic variables are also assigned temporary slots, at the nesting
176 level where they are defined. They are marked a "kept" so that
177 free_temp_slots will not free them. */
179 struct temp_slot GTY(())
181 /* Points to next temporary slot. */
182 struct temp_slot *next;
183 /* The rtx to used to reference the slot. */
185 /* The rtx used to represent the address if not the address of the
186 slot above. May be an EXPR_LIST if multiple addresses exist. */
188 /* The alignment (in bits) of the slot. */
190 /* The size, in units, of the slot. */
192 /* The type of the object in the slot, or zero if it doesn't correspond
193 to a type. We use this to determine whether a slot can be reused.
194 It can be reused if objects of the type of the new slot will always
195 conflict with objects of the type of the old slot. */
197 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
199 /* Nonzero if this temporary is currently in use. */
201 /* Nonzero if this temporary has its address taken. */
203 /* Nesting level at which this slot is being used. */
205 /* Nonzero if this should survive a call to free_temp_slots. */
207 /* The offset of the slot from the frame_pointer, including extra space
208 for alignment. This info is for combine_temp_slots. */
209 HOST_WIDE_INT base_offset;
210 /* The size of the slot, including extra space for alignment. This
211 info is for combine_temp_slots. */
212 HOST_WIDE_INT full_size;
215 /* This structure is used to record MEMs or pseudos used to replace VAR, any
216 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
217 maintain this list in case two operands of an insn were required to match;
218 in that case we must ensure we use the same replacement. */
220 struct fixup_replacement GTY(())
224 struct fixup_replacement *next;
227 struct insns_for_mem_entry
231 /* These are the INSNs which reference the MEM. */
235 /* Forward declarations. */
237 static rtx assign_stack_local_1 (enum machine_mode, HOST_WIDE_INT, int,
239 static struct temp_slot *find_temp_slot_from_address (rtx);
240 static void put_reg_into_stack (struct function *, rtx, tree, enum machine_mode,
241 unsigned int, bool, bool, bool, htab_t);
242 static void schedule_fixup_var_refs (struct function *, rtx, tree, enum machine_mode,
244 static void fixup_var_refs (rtx, enum machine_mode, int, rtx, htab_t);
245 static struct fixup_replacement
246 *find_fixup_replacement (struct fixup_replacement **, rtx);
247 static void fixup_var_refs_insns (rtx, rtx, enum machine_mode, int, int, rtx);
248 static void fixup_var_refs_insns_with_hash (htab_t, rtx, enum machine_mode, int, rtx);
249 static void fixup_var_refs_insn (rtx, rtx, enum machine_mode, int, int, rtx);
250 static void fixup_var_refs_1 (rtx, enum machine_mode, rtx *, rtx,
251 struct fixup_replacement **, rtx);
252 static rtx fixup_memory_subreg (rtx, rtx, enum machine_mode, int);
253 static rtx walk_fixup_memory_subreg (rtx, rtx, enum machine_mode, int);
254 static rtx fixup_stack_1 (rtx, rtx);
255 static void optimize_bit_field (rtx, rtx, rtx *);
256 static void instantiate_decls (tree, int);
257 static void instantiate_decls_1 (tree, int);
258 static void instantiate_decl (rtx, HOST_WIDE_INT, int);
259 static rtx instantiate_new_reg (rtx, HOST_WIDE_INT *);
260 static int instantiate_virtual_regs_1 (rtx *, rtx, int);
261 static void delete_handlers (void);
262 static void pad_to_arg_alignment (struct args_size *, int, struct args_size *);
263 static void pad_below (struct args_size *, enum machine_mode, tree);
264 static rtx round_trampoline_addr (rtx);
265 static rtx adjust_trampoline_addr (rtx);
266 static tree *identify_blocks_1 (rtx, tree *, tree *, tree *);
267 static void reorder_blocks_0 (tree);
268 static void reorder_blocks_1 (rtx, tree, varray_type *);
269 static void reorder_fix_fragments (tree);
270 static tree blocks_nreverse (tree);
271 static int all_blocks (tree, tree *);
272 static tree *get_block_vector (tree, int *);
273 extern tree debug_find_var_in_block_tree (tree, tree);
274 /* We always define `record_insns' even if its not used so that we
275 can always export `prologue_epilogue_contains'. */
276 static void record_insns (rtx, varray_type *) ATTRIBUTE_UNUSED;
277 static int contains (rtx, varray_type);
279 static void emit_return_into_block (basic_block, rtx);
281 static void put_addressof_into_stack (rtx, htab_t);
282 static bool purge_addressof_1 (rtx *, rtx, int, int, int, htab_t);
283 static void purge_single_hard_subreg_set (rtx);
284 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
285 static rtx keep_stack_depressed (rtx);
287 static int is_addressof (rtx *, void *);
288 static hashval_t insns_for_mem_hash (const void *);
289 static int insns_for_mem_comp (const void *, const void *);
290 static int insns_for_mem_walk (rtx *, void *);
291 static void compute_insns_for_mem (rtx, rtx, htab_t);
292 static void prepare_function_start (tree);
293 static void do_clobber_return_reg (rtx, void *);
294 static void do_use_return_reg (rtx, void *);
295 static void instantiate_virtual_regs_lossage (rtx);
296 static tree split_complex_args (tree);
297 static void set_insn_locators (rtx, int) ATTRIBUTE_UNUSED;
299 /* Pointer to chain of `struct function' for containing functions. */
300 struct function *outer_function_chain;
302 /* List of insns that were postponed by purge_addressof_1. */
303 static rtx postponed_insns;
305 /* Given a function decl for a containing function,
306 return the `struct function' for it. */
309 find_function_data (tree decl)
313 for (p = outer_function_chain; p; p = p->outer)
320 /* Save the current context for compilation of a nested function.
321 This is called from language-specific code. The caller should use
322 the enter_nested langhook to save any language-specific state,
323 since this function knows only about language-independent
327 push_function_context_to (tree context)
333 if (context == current_function_decl)
334 cfun->contains_functions = 1;
337 struct function *containing = find_function_data (context);
338 containing->contains_functions = 1;
343 init_dummy_function_start ();
346 p->outer = outer_function_chain;
347 outer_function_chain = p;
348 p->fixup_var_refs_queue = 0;
350 (*lang_hooks.function.enter_nested) (p);
356 push_function_context (void)
358 push_function_context_to (current_function_decl);
361 /* Restore the last saved context, at the end of a nested function.
362 This function is called from language-specific code. */
365 pop_function_context_from (tree context ATTRIBUTE_UNUSED)
367 struct function *p = outer_function_chain;
368 struct var_refs_queue *queue;
371 outer_function_chain = p->outer;
373 current_function_decl = p->decl;
376 restore_emit_status (p);
378 (*lang_hooks.function.leave_nested) (p);
380 /* Finish doing put_var_into_stack for any of our variables which became
381 addressable during the nested function. If only one entry has to be
382 fixed up, just do that one. Otherwise, first make a list of MEMs that
383 are not to be unshared. */
384 if (p->fixup_var_refs_queue == 0)
386 else if (p->fixup_var_refs_queue->next == 0)
387 fixup_var_refs (p->fixup_var_refs_queue->modified,
388 p->fixup_var_refs_queue->promoted_mode,
389 p->fixup_var_refs_queue->unsignedp,
390 p->fixup_var_refs_queue->modified, 0);
395 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
396 list = gen_rtx_EXPR_LIST (VOIDmode, queue->modified, list);
398 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next)
399 fixup_var_refs (queue->modified, queue->promoted_mode,
400 queue->unsignedp, list, 0);
404 p->fixup_var_refs_queue = 0;
406 /* Reset variables that have known state during rtx generation. */
407 rtx_equal_function_value_matters = 1;
408 virtuals_instantiated = 0;
409 generating_concat_p = 1;
413 pop_function_context (void)
415 pop_function_context_from (current_function_decl);
418 /* Clear out all parts of the state in F that can safely be discarded
419 after the function has been parsed, but not compiled, to let
420 garbage collection reclaim the memory. */
423 free_after_parsing (struct function *f)
425 /* f->expr->forced_labels is used by code generation. */
426 /* f->emit->regno_reg_rtx is used by code generation. */
427 /* f->varasm is used by code generation. */
428 /* f->eh->eh_return_stub_label is used by code generation. */
430 (*lang_hooks.function.final) (f);
434 /* Clear out all parts of the state in F that can safely be discarded
435 after the function has been compiled, to let garbage collection
436 reclaim the memory. */
439 free_after_compilation (struct function *f)
447 f->x_temp_slots = NULL;
448 f->arg_offset_rtx = NULL;
449 f->return_rtx = NULL;
450 f->internal_arg_pointer = NULL;
451 f->x_nonlocal_labels = NULL;
452 f->x_nonlocal_goto_handler_slots = NULL;
453 f->x_nonlocal_goto_handler_labels = NULL;
454 f->x_nonlocal_goto_stack_level = NULL;
455 f->x_cleanup_label = NULL;
456 f->x_return_label = NULL;
457 f->x_naked_return_label = NULL;
458 f->computed_goto_common_label = NULL;
459 f->computed_goto_common_reg = NULL;
460 f->x_save_expr_regs = NULL;
461 f->x_stack_slot_list = NULL;
462 f->x_rtl_expr_chain = NULL;
463 f->x_tail_recursion_label = NULL;
464 f->x_tail_recursion_reentry = NULL;
465 f->x_arg_pointer_save_area = NULL;
466 f->x_clobber_return_insn = NULL;
467 f->x_context_display = NULL;
468 f->x_trampoline_list = NULL;
469 f->x_parm_birth_insn = NULL;
470 f->x_last_parm_insn = NULL;
471 f->x_parm_reg_stack_loc = NULL;
472 f->fixup_var_refs_queue = NULL;
473 f->original_arg_vector = NULL;
474 f->original_decl_initial = NULL;
475 f->inl_last_parm_insn = NULL;
476 f->epilogue_delay_list = NULL;
479 /* Allocate fixed slots in the stack frame of the current function. */
481 /* Return size needed for stack frame based on slots so far allocated in
483 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
484 the caller may have to do that. */
487 get_func_frame_size (struct function *f)
489 #ifdef FRAME_GROWS_DOWNWARD
490 return -f->x_frame_offset;
492 return f->x_frame_offset;
496 /* Return size needed for stack frame based on slots so far allocated.
497 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
498 the caller may have to do that. */
500 get_frame_size (void)
502 return get_func_frame_size (cfun);
505 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
506 with machine mode MODE.
508 ALIGN controls the amount of alignment for the address of the slot:
509 0 means according to MODE,
510 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
511 -2 means use BITS_PER_UNIT,
512 positive specifies alignment boundary in bits.
514 We do not round to stack_boundary here.
516 FUNCTION specifies the function to allocate in. */
519 assign_stack_local_1 (enum machine_mode mode, HOST_WIDE_INT size, int align,
520 struct function *function)
523 int bigend_correction = 0;
525 int frame_off, frame_alignment, frame_phase;
532 alignment = BIGGEST_ALIGNMENT;
534 alignment = GET_MODE_ALIGNMENT (mode);
536 /* Allow the target to (possibly) increase the alignment of this
538 type = (*lang_hooks.types.type_for_mode) (mode, 0);
540 alignment = LOCAL_ALIGNMENT (type, alignment);
542 alignment /= BITS_PER_UNIT;
544 else if (align == -1)
546 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
547 size = CEIL_ROUND (size, alignment);
549 else if (align == -2)
550 alignment = 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
552 alignment = align / BITS_PER_UNIT;
554 #ifdef FRAME_GROWS_DOWNWARD
555 function->x_frame_offset -= size;
558 /* Ignore alignment we can't do with expected alignment of the boundary. */
559 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY)
560 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
562 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT)
563 function->stack_alignment_needed = alignment * BITS_PER_UNIT;
565 /* Calculate how many bytes the start of local variables is off from
567 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
568 frame_off = STARTING_FRAME_OFFSET % frame_alignment;
569 frame_phase = frame_off ? frame_alignment - frame_off : 0;
571 /* Round the frame offset to the specified alignment. The default is
572 to always honor requests to align the stack but a port may choose to
573 do its own stack alignment by defining STACK_ALIGNMENT_NEEDED. */
574 if (STACK_ALIGNMENT_NEEDED
578 /* We must be careful here, since FRAME_OFFSET might be negative and
579 division with a negative dividend isn't as well defined as we might
580 like. So we instead assume that ALIGNMENT is a power of two and
581 use logical operations which are unambiguous. */
582 #ifdef FRAME_GROWS_DOWNWARD
583 function->x_frame_offset
584 = (FLOOR_ROUND (function->x_frame_offset - frame_phase, alignment)
587 function->x_frame_offset
588 = (CEIL_ROUND (function->x_frame_offset - frame_phase, alignment)
593 /* On a big-endian machine, if we are allocating more space than we will use,
594 use the least significant bytes of those that are allocated. */
595 if (BYTES_BIG_ENDIAN && mode != BLKmode)
596 bigend_correction = size - GET_MODE_SIZE (mode);
598 /* If we have already instantiated virtual registers, return the actual
599 address relative to the frame pointer. */
600 if (function == cfun && virtuals_instantiated)
601 addr = plus_constant (frame_pointer_rtx,
603 (frame_offset + bigend_correction
604 + STARTING_FRAME_OFFSET, Pmode));
606 addr = plus_constant (virtual_stack_vars_rtx,
608 (function->x_frame_offset + bigend_correction,
611 #ifndef FRAME_GROWS_DOWNWARD
612 function->x_frame_offset += size;
615 x = gen_rtx_MEM (mode, addr);
617 function->x_stack_slot_list
618 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list);
623 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
627 assign_stack_local (enum machine_mode mode, HOST_WIDE_INT size, int align)
629 return assign_stack_local_1 (mode, size, align, cfun);
632 /* Allocate a temporary stack slot and record it for possible later
635 MODE is the machine mode to be given to the returned rtx.
637 SIZE is the size in units of the space required. We do no rounding here
638 since assign_stack_local will do any required rounding.
640 KEEP is 1 if this slot is to be retained after a call to
641 free_temp_slots. Automatic variables for a block are allocated
642 with this flag. KEEP is 2 if we allocate a longer term temporary,
643 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
644 if we are to allocate something at an inner level to be treated as
645 a variable in the block (e.g., a SAVE_EXPR).
647 TYPE is the type that will be used for the stack slot. */
650 assign_stack_temp_for_type (enum machine_mode mode, HOST_WIDE_INT size, int keep,
654 struct temp_slot *p, *best_p = 0;
657 /* If SIZE is -1 it means that somebody tried to allocate a temporary
658 of a variable size. */
663 align = BIGGEST_ALIGNMENT;
665 align = GET_MODE_ALIGNMENT (mode);
668 type = (*lang_hooks.types.type_for_mode) (mode, 0);
671 align = LOCAL_ALIGNMENT (type, align);
673 /* Try to find an available, already-allocated temporary of the proper
674 mode which meets the size and alignment requirements. Choose the
675 smallest one with the closest alignment. */
676 for (p = temp_slots; p; p = p->next)
677 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode
679 && objects_must_conflict_p (p->type, type)
680 && (best_p == 0 || best_p->size > p->size
681 || (best_p->size == p->size && best_p->align > p->align)))
683 if (p->align == align && p->size == size)
691 /* Make our best, if any, the one to use. */
694 /* If there are enough aligned bytes left over, make them into a new
695 temp_slot so that the extra bytes don't get wasted. Do this only
696 for BLKmode slots, so that we can be sure of the alignment. */
697 if (GET_MODE (best_p->slot) == BLKmode)
699 int alignment = best_p->align / BITS_PER_UNIT;
700 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment);
702 if (best_p->size - rounded_size >= alignment)
704 p = ggc_alloc (sizeof (struct temp_slot));
705 p->in_use = p->addr_taken = 0;
706 p->size = best_p->size - rounded_size;
707 p->base_offset = best_p->base_offset + rounded_size;
708 p->full_size = best_p->full_size - rounded_size;
709 p->slot = gen_rtx_MEM (BLKmode,
710 plus_constant (XEXP (best_p->slot, 0),
712 p->align = best_p->align;
715 p->type = best_p->type;
716 p->next = temp_slots;
719 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot,
722 best_p->size = rounded_size;
723 best_p->full_size = rounded_size;
730 /* If we still didn't find one, make a new temporary. */
733 HOST_WIDE_INT frame_offset_old = frame_offset;
735 p = ggc_alloc (sizeof (struct temp_slot));
737 /* We are passing an explicit alignment request to assign_stack_local.
738 One side effect of that is assign_stack_local will not round SIZE
739 to ensure the frame offset remains suitably aligned.
741 So for requests which depended on the rounding of SIZE, we go ahead
742 and round it now. We also make sure ALIGNMENT is at least
743 BIGGEST_ALIGNMENT. */
744 if (mode == BLKmode && align < BIGGEST_ALIGNMENT)
746 p->slot = assign_stack_local (mode,
748 ? CEIL_ROUND (size, (int) align / BITS_PER_UNIT)
754 /* The following slot size computation is necessary because we don't
755 know the actual size of the temporary slot until assign_stack_local
756 has performed all the frame alignment and size rounding for the
757 requested temporary. Note that extra space added for alignment
758 can be either above or below this stack slot depending on which
759 way the frame grows. We include the extra space if and only if it
760 is above this slot. */
761 #ifdef FRAME_GROWS_DOWNWARD
762 p->size = frame_offset_old - frame_offset;
767 /* Now define the fields used by combine_temp_slots. */
768 #ifdef FRAME_GROWS_DOWNWARD
769 p->base_offset = frame_offset;
770 p->full_size = frame_offset_old - frame_offset;
772 p->base_offset = frame_offset_old;
773 p->full_size = frame_offset - frame_offset_old;
776 p->next = temp_slots;
782 p->rtl_expr = seq_rtl_expr;
787 p->level = target_temp_slot_level;
792 p->level = var_temp_slot_level;
797 p->level = temp_slot_level;
802 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
803 slot = gen_rtx_MEM (mode, XEXP (p->slot, 0));
804 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list);
806 /* If we know the alias set for the memory that will be used, use
807 it. If there's no TYPE, then we don't know anything about the
808 alias set for the memory. */
809 set_mem_alias_set (slot, type ? get_alias_set (type) : 0);
810 set_mem_align (slot, align);
812 /* If a type is specified, set the relevant flags. */
815 RTX_UNCHANGING_P (slot) = (lang_hooks.honor_readonly
816 && TYPE_READONLY (type));
817 MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type);
818 MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type));
824 /* Allocate a temporary stack slot and record it for possible later
825 reuse. First three arguments are same as in preceding function. */
828 assign_stack_temp (enum machine_mode mode, HOST_WIDE_INT size, int keep)
830 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE);
833 /* Assign a temporary.
834 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
835 and so that should be used in error messages. In either case, we
836 allocate of the given type.
837 KEEP is as for assign_stack_temp.
838 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
839 it is 0 if a register is OK.
840 DONT_PROMOTE is 1 if we should not promote values in register
844 assign_temp (tree type_or_decl, int keep, int memory_required,
845 int dont_promote ATTRIBUTE_UNUSED)
848 enum machine_mode mode;
849 #ifndef PROMOTE_FOR_CALL_ONLY
853 if (DECL_P (type_or_decl))
854 decl = type_or_decl, type = TREE_TYPE (decl);
856 decl = NULL, type = type_or_decl;
858 mode = TYPE_MODE (type);
859 #ifndef PROMOTE_FOR_CALL_ONLY
860 unsignedp = TREE_UNSIGNED (type);
863 if (mode == BLKmode || memory_required)
865 HOST_WIDE_INT size = int_size_in_bytes (type);
868 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
869 problems with allocating the stack space. */
873 /* Unfortunately, we don't yet know how to allocate variable-sized
874 temporaries. However, sometimes we have a fixed upper limit on
875 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
876 instead. This is the case for Chill variable-sized strings. */
877 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE
878 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE
879 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1))
880 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1);
882 /* The size of the temporary may be too large to fit into an integer. */
883 /* ??? Not sure this should happen except for user silliness, so limit
884 this to things that aren't compiler-generated temporaries. The
885 rest of the time we'll abort in assign_stack_temp_for_type. */
886 if (decl && size == -1
887 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST)
889 error ("%Jsize of variable '%D' is too large", decl, decl);
893 tmp = assign_stack_temp_for_type (mode, size, keep, type);
897 #ifndef PROMOTE_FOR_CALL_ONLY
899 mode = promote_mode (type, mode, &unsignedp, 0);
902 return gen_reg_rtx (mode);
905 /* Combine temporary stack slots which are adjacent on the stack.
907 This allows for better use of already allocated stack space. This is only
908 done for BLKmode slots because we can be sure that we won't have alignment
909 problems in this case. */
912 combine_temp_slots (void)
914 struct temp_slot *p, *q;
915 struct temp_slot *prev_p, *prev_q;
918 /* We can't combine slots, because the information about which slot
919 is in which alias set will be lost. */
920 if (flag_strict_aliasing)
923 /* If there are a lot of temp slots, don't do anything unless
924 high levels of optimization. */
925 if (! flag_expensive_optimizations)
926 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++)
927 if (num_slots > 100 || (num_slots > 10 && optimize == 0))
930 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots)
934 if (! p->in_use && GET_MODE (p->slot) == BLKmode)
935 for (q = p->next, prev_q = p; q; q = prev_q->next)
938 if (! q->in_use && GET_MODE (q->slot) == BLKmode)
940 if (p->base_offset + p->full_size == q->base_offset)
942 /* Q comes after P; combine Q into P. */
944 p->full_size += q->full_size;
947 else if (q->base_offset + q->full_size == p->base_offset)
949 /* P comes after Q; combine P into Q. */
951 q->full_size += p->full_size;
956 /* Either delete Q or advance past it. */
958 prev_q->next = q->next;
962 /* Either delete P or advance past it. */
966 prev_p->next = p->next;
968 temp_slots = p->next;
975 /* Find the temp slot corresponding to the object at address X. */
977 static struct temp_slot *
978 find_temp_slot_from_address (rtx x)
983 for (p = temp_slots; p; p = p->next)
988 else if (XEXP (p->slot, 0) == x
990 || (GET_CODE (x) == PLUS
991 && XEXP (x, 0) == virtual_stack_vars_rtx
992 && GET_CODE (XEXP (x, 1)) == CONST_INT
993 && INTVAL (XEXP (x, 1)) >= p->base_offset
994 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size))
997 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST)
998 for (next = p->address; next; next = XEXP (next, 1))
999 if (XEXP (next, 0) == x)
1003 /* If we have a sum involving a register, see if it points to a temp
1005 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
1006 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0)
1008 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG
1009 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0)
1015 /* Indicate that NEW is an alternate way of referring to the temp slot
1016 that previously was known by OLD. */
1019 update_temp_slot_address (rtx old, rtx new)
1021 struct temp_slot *p;
1023 if (rtx_equal_p (old, new))
1026 p = find_temp_slot_from_address (old);
1028 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1029 is a register, see if one operand of the PLUS is a temporary
1030 location. If so, NEW points into it. Otherwise, if both OLD and
1031 NEW are a PLUS and if there is a register in common between them.
1032 If so, try a recursive call on those values. */
1035 if (GET_CODE (old) != PLUS)
1038 if (GET_CODE (new) == REG)
1040 update_temp_slot_address (XEXP (old, 0), new);
1041 update_temp_slot_address (XEXP (old, 1), new);
1044 else if (GET_CODE (new) != PLUS)
1047 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0)))
1048 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1));
1049 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0)))
1050 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1));
1051 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1)))
1052 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0));
1053 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1)))
1054 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0));
1059 /* Otherwise add an alias for the temp's address. */
1060 else if (p->address == 0)
1064 if (GET_CODE (p->address) != EXPR_LIST)
1065 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX);
1067 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address);
1071 /* If X could be a reference to a temporary slot, mark the fact that its
1072 address was taken. */
1075 mark_temp_addr_taken (rtx x)
1077 struct temp_slot *p;
1082 /* If X is not in memory or is at a constant address, it cannot be in
1083 a temporary slot. */
1084 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1087 p = find_temp_slot_from_address (XEXP (x, 0));
1092 /* If X could be a reference to a temporary slot, mark that slot as
1093 belonging to the to one level higher than the current level. If X
1094 matched one of our slots, just mark that one. Otherwise, we can't
1095 easily predict which it is, so upgrade all of them. Kept slots
1096 need not be touched.
1098 This is called when an ({...}) construct occurs and a statement
1099 returns a value in memory. */
1102 preserve_temp_slots (rtx x)
1104 struct temp_slot *p = 0;
1106 /* If there is no result, we still might have some objects whose address
1107 were taken, so we need to make sure they stay around. */
1110 for (p = temp_slots; p; p = p->next)
1111 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1117 /* If X is a register that is being used as a pointer, see if we have
1118 a temporary slot we know it points to. To be consistent with
1119 the code below, we really should preserve all non-kept slots
1120 if we can't find a match, but that seems to be much too costly. */
1121 if (GET_CODE (x) == REG && REG_POINTER (x))
1122 p = find_temp_slot_from_address (x);
1124 /* If X is not in memory or is at a constant address, it cannot be in
1125 a temporary slot, but it can contain something whose address was
1127 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))))
1129 for (p = temp_slots; p; p = p->next)
1130 if (p->in_use && p->level == temp_slot_level && p->addr_taken)
1136 /* First see if we can find a match. */
1138 p = find_temp_slot_from_address (XEXP (x, 0));
1142 /* Move everything at our level whose address was taken to our new
1143 level in case we used its address. */
1144 struct temp_slot *q;
1146 if (p->level == temp_slot_level)
1148 for (q = temp_slots; q; q = q->next)
1149 if (q != p && q->addr_taken && q->level == p->level)
1158 /* Otherwise, preserve all non-kept slots at this level. */
1159 for (p = temp_slots; p; p = p->next)
1160 if (p->in_use && p->level == temp_slot_level && ! p->keep)
1164 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1165 with that RTL_EXPR, promote it into a temporary slot at the present
1166 level so it will not be freed when we free slots made in the
1170 preserve_rtl_expr_result (rtx x)
1172 struct temp_slot *p;
1174 /* If X is not in memory or is at a constant address, it cannot be in
1175 a temporary slot. */
1176 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
1179 /* If we can find a match, move it to our level unless it is already at
1181 p = find_temp_slot_from_address (XEXP (x, 0));
1184 p->level = MIN (p->level, temp_slot_level);
1191 /* Free all temporaries used so far. This is normally called at the end
1192 of generating code for a statement. Don't free any temporaries
1193 currently in use for an RTL_EXPR that hasn't yet been emitted.
1194 We could eventually do better than this since it can be reused while
1195 generating the same RTL_EXPR, but this is complex and probably not
1199 free_temp_slots (void)
1201 struct temp_slot *p;
1203 for (p = temp_slots; p; p = p->next)
1204 if (p->in_use && p->level == temp_slot_level && ! p->keep
1205 && p->rtl_expr == 0)
1208 combine_temp_slots ();
1211 /* Free all temporary slots used in T, an RTL_EXPR node. */
1214 free_temps_for_rtl_expr (tree t)
1216 struct temp_slot *p;
1218 for (p = temp_slots; p; p = p->next)
1219 if (p->rtl_expr == t)
1221 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1222 needs to be preserved. This can happen if a temporary in
1223 the RTL_EXPR was addressed; preserve_temp_slots will move
1224 the temporary into a higher level. */
1225 if (temp_slot_level <= p->level)
1228 p->rtl_expr = NULL_TREE;
1231 combine_temp_slots ();
1234 /* Mark all temporaries ever allocated in this function as not suitable
1235 for reuse until the current level is exited. */
1238 mark_all_temps_used (void)
1240 struct temp_slot *p;
1242 for (p = temp_slots; p; p = p->next)
1244 p->in_use = p->keep = 1;
1245 p->level = MIN (p->level, temp_slot_level);
1249 /* Push deeper into the nesting level for stack temporaries. */
1252 push_temp_slots (void)
1257 /* Pop a temporary nesting level. All slots in use in the current level
1261 pop_temp_slots (void)
1263 struct temp_slot *p;
1265 for (p = temp_slots; p; p = p->next)
1266 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0)
1269 combine_temp_slots ();
1274 /* Initialize temporary slots. */
1277 init_temp_slots (void)
1279 /* We have not allocated any temporaries yet. */
1281 temp_slot_level = 0;
1282 var_temp_slot_level = 0;
1283 target_temp_slot_level = 0;
1286 /* Retroactively move an auto variable from a register to a stack
1287 slot. This is done when an address-reference to the variable is
1288 seen. If RESCAN is true, all previously emitted instructions are
1289 examined and modified to handle the fact that DECL is now
1293 put_var_into_stack (tree decl, int rescan)
1296 enum machine_mode promoted_mode, decl_mode;
1297 struct function *function = 0;
1299 bool can_use_addressof_p;
1300 bool volatile_p = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl);
1301 bool used_p = (TREE_USED (decl)
1302 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0));
1304 context = decl_function_context (decl);
1306 /* Get the current rtl used for this object and its original mode. */
1307 reg = (TREE_CODE (decl) == SAVE_EXPR
1308 ? SAVE_EXPR_RTL (decl)
1309 : DECL_RTL_IF_SET (decl));
1311 /* No need to do anything if decl has no rtx yet
1312 since in that case caller is setting TREE_ADDRESSABLE
1313 and a stack slot will be assigned when the rtl is made. */
1317 /* Get the declared mode for this object. */
1318 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl))
1319 : DECL_MODE (decl));
1320 /* Get the mode it's actually stored in. */
1321 promoted_mode = GET_MODE (reg);
1323 /* If this variable comes from an outer function, find that
1324 function's saved context. Don't use find_function_data here,
1325 because it might not be in any active function.
1326 FIXME: Is that really supposed to happen?
1327 It does in ObjC at least. */
1328 if (context != current_function_decl && context != inline_function_decl)
1329 for (function = outer_function_chain; function; function = function->outer)
1330 if (function->decl == context)
1333 /* If this is a variable-sized object or a structure passed by invisible
1334 reference, with a pseudo to address it, put that pseudo into the stack
1335 if the var is non-local. */
1336 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl)
1337 && GET_CODE (reg) == MEM
1338 && GET_CODE (XEXP (reg, 0)) == REG
1339 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
1341 reg = XEXP (reg, 0);
1342 decl_mode = promoted_mode = GET_MODE (reg);
1345 /* If this variable lives in the current function and we don't need to put it
1346 in the stack for the sake of setjmp or the non-locality, try to keep it in
1347 a register until we know we actually need the address. */
1350 && ! (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl))
1352 /* FIXME make it work for promoted modes too */
1353 && decl_mode == promoted_mode
1354 #ifdef NON_SAVING_SETJMP
1355 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp)
1359 /* If we can't use ADDRESSOF, make sure we see through one we already
1361 if (! can_use_addressof_p
1362 && GET_CODE (reg) == MEM
1363 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF)
1364 reg = XEXP (XEXP (reg, 0), 0);
1366 /* Now we should have a value that resides in one or more pseudo regs. */
1368 if (GET_CODE (reg) == REG)
1370 if (can_use_addressof_p)
1371 gen_mem_addressof (reg, decl, rescan);
1373 put_reg_into_stack (function, reg, TREE_TYPE (decl), decl_mode,
1374 0, volatile_p, used_p, false, 0);
1376 else if (GET_CODE (reg) == CONCAT)
1378 /* A CONCAT contains two pseudos; put them both in the stack.
1379 We do it so they end up consecutive.
1380 We fixup references to the parts only after we fixup references
1381 to the whole CONCAT, lest we do double fixups for the latter
1383 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0));
1384 tree part_type = (*lang_hooks.types.type_for_mode) (part_mode, 0);
1385 rtx lopart = XEXP (reg, 0);
1386 rtx hipart = XEXP (reg, 1);
1387 #ifdef FRAME_GROWS_DOWNWARD
1388 /* Since part 0 should have a lower address, do it second. */
1389 put_reg_into_stack (function, hipart, part_type, part_mode,
1390 0, volatile_p, false, false, 0);
1391 put_reg_into_stack (function, lopart, part_type, part_mode,
1392 0, volatile_p, false, true, 0);
1394 put_reg_into_stack (function, lopart, part_type, part_mode,
1395 0, volatile_p, false, false, 0);
1396 put_reg_into_stack (function, hipart, part_type, part_mode,
1397 0, volatile_p, false, true, 0);
1400 /* Change the CONCAT into a combined MEM for both parts. */
1401 PUT_CODE (reg, MEM);
1402 MEM_ATTRS (reg) = 0;
1404 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1405 already computed alias sets. Here we want to re-generate. */
1407 SET_DECL_RTL (decl, NULL);
1408 set_mem_attributes (reg, decl, 1);
1410 SET_DECL_RTL (decl, reg);
1412 /* The two parts are in memory order already.
1413 Use the lower parts address as ours. */
1414 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0);
1415 /* Prevent sharing of rtl that might lose. */
1416 if (GET_CODE (XEXP (reg, 0)) == PLUS)
1417 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0));
1418 if (used_p && rescan)
1420 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl),
1422 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0);
1423 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0);
1430 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1431 into the stack frame of FUNCTION (0 means the current function).
1432 TYPE is the user-level data type of the value hold in the register.
1433 DECL_MODE is the machine mode of the user-level data type.
1434 ORIGINAL_REGNO must be set if the real regno is not visible in REG.
1435 VOLATILE_P is true if this is for a "volatile" decl.
1436 USED_P is true if this reg might have already been used in an insn.
1437 CONSECUTIVE_P is true if the stack slot assigned to reg must be
1438 consecutive with the previous stack slot. */
1441 put_reg_into_stack (struct function *function, rtx reg, tree type,
1442 enum machine_mode decl_mode, unsigned int original_regno,
1443 bool volatile_p, bool used_p, bool consecutive_p,
1446 struct function *func = function ? function : cfun;
1447 enum machine_mode mode = GET_MODE (reg);
1448 unsigned int regno = original_regno;
1452 regno = REGNO (reg);
1454 if (regno < func->x_max_parm_reg)
1456 if (!func->x_parm_reg_stack_loc)
1458 new = func->x_parm_reg_stack_loc[regno];
1462 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode),
1463 consecutive_p ? -2 : 0, func);
1465 PUT_CODE (reg, MEM);
1466 PUT_MODE (reg, decl_mode);
1467 XEXP (reg, 0) = XEXP (new, 0);
1468 MEM_ATTRS (reg) = 0;
1469 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1470 MEM_VOLATILE_P (reg) = volatile_p;
1472 /* If this is a memory ref that contains aggregate components,
1473 mark it as such for cse and loop optimize. If we are reusing a
1474 previously generated stack slot, then we need to copy the bit in
1475 case it was set for other reasons. For instance, it is set for
1476 __builtin_va_alist. */
1479 MEM_SET_IN_STRUCT_P (reg,
1480 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new));
1481 set_mem_alias_set (reg, get_alias_set (type));
1485 schedule_fixup_var_refs (function, reg, type, mode, ht);
1488 /* Make sure that all refs to the variable, previously made
1489 when it was a register, are fixed up to be valid again.
1490 See function above for meaning of arguments. */
1493 schedule_fixup_var_refs (struct function *function, rtx reg, tree type,
1494 enum machine_mode promoted_mode, htab_t ht)
1496 int unsigned_p = type ? TREE_UNSIGNED (type) : 0;
1500 struct var_refs_queue *temp;
1502 temp = ggc_alloc (sizeof (struct var_refs_queue));
1503 temp->modified = reg;
1504 temp->promoted_mode = promoted_mode;
1505 temp->unsignedp = unsigned_p;
1506 temp->next = function->fixup_var_refs_queue;
1507 function->fixup_var_refs_queue = temp;
1510 /* Variable is local; fix it up now. */
1511 fixup_var_refs (reg, promoted_mode, unsigned_p, reg, ht);
1515 fixup_var_refs (rtx var, enum machine_mode promoted_mode, int unsignedp,
1516 rtx may_share, htab_t ht)
1519 rtx first_insn = get_insns ();
1520 struct sequence_stack *stack = seq_stack;
1521 tree rtl_exps = rtl_expr_chain;
1523 /* If there's a hash table, it must record all uses of VAR. */
1528 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp,
1533 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp,
1534 stack == 0, may_share);
1536 /* Scan all pending sequences too. */
1537 for (; stack; stack = stack->next)
1539 push_to_full_sequence (stack->first, stack->last);
1540 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp,
1541 stack->next != 0, may_share);
1542 /* Update remembered end of sequence
1543 in case we added an insn at the end. */
1544 stack->last = get_last_insn ();
1548 /* Scan all waiting RTL_EXPRs too. */
1549 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
1551 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
1552 if (seq != const0_rtx && seq != 0)
1554 push_to_sequence (seq);
1555 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1562 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1563 some part of an insn. Return a struct fixup_replacement whose OLD
1564 value is equal to X. Allocate a new structure if no such entry exists. */
1566 static struct fixup_replacement *
1567 find_fixup_replacement (struct fixup_replacement **replacements, rtx x)
1569 struct fixup_replacement *p;
1571 /* See if we have already replaced this. */
1572 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next)
1577 p = xmalloc (sizeof (struct fixup_replacement));
1580 p->next = *replacements;
1587 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1588 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1589 for the current function. MAY_SHARE is either a MEM that is not
1590 to be unshared or a list of them. */
1593 fixup_var_refs_insns (rtx insn, rtx var, enum machine_mode promoted_mode,
1594 int unsignedp, int toplevel, rtx may_share)
1598 /* fixup_var_refs_insn might modify insn, so save its next
1600 rtx next = NEXT_INSN (insn);
1602 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1603 the three sequences they (potentially) contain, and process
1604 them recursively. The CALL_INSN itself is not interesting. */
1606 if (GET_CODE (insn) == CALL_INSN
1607 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
1611 /* Look at the Normal call, sibling call and tail recursion
1612 sequences attached to the CALL_PLACEHOLDER. */
1613 for (i = 0; i < 3; i++)
1615 rtx seq = XEXP (PATTERN (insn), i);
1618 push_to_sequence (seq);
1619 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0,
1621 XEXP (PATTERN (insn), i) = get_insns ();
1627 else if (INSN_P (insn))
1628 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel,
1635 /* Look up the insns which reference VAR in HT and fix them up. Other
1636 arguments are the same as fixup_var_refs_insns.
1638 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1639 because the hash table will point straight to the interesting insn
1640 (inside the CALL_PLACEHOLDER). */
1643 fixup_var_refs_insns_with_hash (htab_t ht, rtx var, enum machine_mode promoted_mode,
1644 int unsignedp, rtx may_share)
1646 struct insns_for_mem_entry tmp;
1647 struct insns_for_mem_entry *ime;
1651 ime = htab_find (ht, &tmp);
1652 for (insn_list = ime->insns; insn_list != 0; insn_list = XEXP (insn_list, 1))
1653 if (INSN_P (XEXP (insn_list, 0)) && !INSN_DELETED_P (XEXP (insn_list, 0)))
1654 fixup_var_refs_insn (XEXP (insn_list, 0), var, promoted_mode,
1655 unsignedp, 1, may_share);
1659 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1660 the insn under examination, VAR is the variable to fix up
1661 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1662 TOPLEVEL is nonzero if this is the main insn chain for this
1666 fixup_var_refs_insn (rtx insn, rtx var, enum machine_mode promoted_mode,
1667 int unsignedp, int toplevel, rtx no_share)
1670 rtx set, prev, prev_set;
1673 /* Remember the notes in case we delete the insn. */
1674 note = REG_NOTES (insn);
1676 /* If this is a CLOBBER of VAR, delete it.
1678 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1679 and REG_RETVAL notes too. */
1680 if (GET_CODE (PATTERN (insn)) == CLOBBER
1681 && (XEXP (PATTERN (insn), 0) == var
1682 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT
1683 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var
1684 || XEXP (XEXP (PATTERN (insn), 0), 1) == var))))
1686 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0)
1687 /* The REG_LIBCALL note will go away since we are going to
1688 turn INSN into a NOTE, so just delete the
1689 corresponding REG_RETVAL note. */
1690 remove_note (XEXP (note, 0),
1691 find_reg_note (XEXP (note, 0), REG_RETVAL,
1697 /* The insn to load VAR from a home in the arglist
1698 is now a no-op. When we see it, just delete it.
1699 Similarly if this is storing VAR from a register from which
1700 it was loaded in the previous insn. This will occur
1701 when an ADDRESSOF was made for an arglist slot. */
1703 && (set = single_set (insn)) != 0
1704 && SET_DEST (set) == var
1705 /* If this represents the result of an insn group,
1706 don't delete the insn. */
1707 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0
1708 && (rtx_equal_p (SET_SRC (set), var)
1709 || (GET_CODE (SET_SRC (set)) == REG
1710 && (prev = prev_nonnote_insn (insn)) != 0
1711 && (prev_set = single_set (prev)) != 0
1712 && SET_DEST (prev_set) == SET_SRC (set)
1713 && rtx_equal_p (SET_SRC (prev_set), var))))
1719 struct fixup_replacement *replacements = 0;
1720 rtx next_insn = NEXT_INSN (insn);
1722 if (SMALL_REGISTER_CLASSES)
1724 /* If the insn that copies the results of a CALL_INSN
1725 into a pseudo now references VAR, we have to use an
1726 intermediate pseudo since we want the life of the
1727 return value register to be only a single insn.
1729 If we don't use an intermediate pseudo, such things as
1730 address computations to make the address of VAR valid
1731 if it is not can be placed between the CALL_INSN and INSN.
1733 To make sure this doesn't happen, we record the destination
1734 of the CALL_INSN and see if the next insn uses both that
1737 if (call_dest != 0 && GET_CODE (insn) == INSN
1738 && reg_mentioned_p (var, PATTERN (insn))
1739 && reg_mentioned_p (call_dest, PATTERN (insn)))
1741 rtx temp = gen_reg_rtx (GET_MODE (call_dest));
1743 emit_insn_before (gen_move_insn (temp, call_dest), insn);
1745 PATTERN (insn) = replace_rtx (PATTERN (insn),
1749 if (GET_CODE (insn) == CALL_INSN
1750 && GET_CODE (PATTERN (insn)) == SET)
1751 call_dest = SET_DEST (PATTERN (insn));
1752 else if (GET_CODE (insn) == CALL_INSN
1753 && GET_CODE (PATTERN (insn)) == PARALLEL
1754 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
1755 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
1760 /* See if we have to do anything to INSN now that VAR is in
1761 memory. If it needs to be loaded into a pseudo, use a single
1762 pseudo for the entire insn in case there is a MATCH_DUP
1763 between two operands. We pass a pointer to the head of
1764 a list of struct fixup_replacements. If fixup_var_refs_1
1765 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1766 it will record them in this list.
1768 If it allocated a pseudo for any replacement, we copy into
1771 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn,
1772 &replacements, no_share);
1774 /* If this is last_parm_insn, and any instructions were output
1775 after it to fix it up, then we must set last_parm_insn to
1776 the last such instruction emitted. */
1777 if (insn == last_parm_insn)
1778 last_parm_insn = PREV_INSN (next_insn);
1780 while (replacements)
1782 struct fixup_replacement *next;
1784 if (GET_CODE (replacements->new) == REG)
1789 /* OLD might be a (subreg (mem)). */
1790 if (GET_CODE (replacements->old) == SUBREG)
1792 = fixup_memory_subreg (replacements->old, insn,
1796 = fixup_stack_1 (replacements->old, insn);
1798 insert_before = insn;
1800 /* If we are changing the mode, do a conversion.
1801 This might be wasteful, but combine.c will
1802 eliminate much of the waste. */
1804 if (GET_MODE (replacements->new)
1805 != GET_MODE (replacements->old))
1808 convert_move (replacements->new,
1809 replacements->old, unsignedp);
1814 seq = gen_move_insn (replacements->new,
1817 emit_insn_before (seq, insert_before);
1820 next = replacements->next;
1821 free (replacements);
1822 replacements = next;
1826 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1827 But don't touch other insns referred to by reg-notes;
1828 we will get them elsewhere. */
1831 if (GET_CODE (note) != INSN_LIST)
1833 = walk_fixup_memory_subreg (XEXP (note, 0), insn,
1835 note = XEXP (note, 1);
1839 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1840 See if the rtx expression at *LOC in INSN needs to be changed.
1842 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1843 contain a list of original rtx's and replacements. If we find that we need
1844 to modify this insn by replacing a memory reference with a pseudo or by
1845 making a new MEM to implement a SUBREG, we consult that list to see if
1846 we have already chosen a replacement. If none has already been allocated,
1847 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1848 or the SUBREG, as appropriate, to the pseudo. */
1851 fixup_var_refs_1 (rtx var, enum machine_mode promoted_mode, rtx *loc, rtx insn,
1852 struct fixup_replacement **replacements, rtx no_share)
1856 RTX_CODE code = GET_CODE (x);
1859 struct fixup_replacement *replacement;
1864 if (XEXP (x, 0) == var)
1866 /* Prevent sharing of rtl that might lose. */
1867 rtx sub = copy_rtx (XEXP (var, 0));
1869 if (! validate_change (insn, loc, sub, 0))
1871 rtx y = gen_reg_rtx (GET_MODE (sub));
1874 /* We should be able to replace with a register or all is lost.
1875 Note that we can't use validate_change to verify this, since
1876 we're not caring for replacing all dups simultaneously. */
1877 if (! validate_replace_rtx (*loc, y, insn))
1880 /* Careful! First try to recognize a direct move of the
1881 value, mimicking how things are done in gen_reload wrt
1882 PLUS. Consider what happens when insn is a conditional
1883 move instruction and addsi3 clobbers flags. */
1886 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub));
1890 if (recog_memoized (new_insn) < 0)
1892 /* That failed. Fall back on force_operand and hope. */
1895 sub = force_operand (sub, y);
1897 emit_insn (gen_move_insn (y, sub));
1903 /* Don't separate setter from user. */
1904 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn)))
1905 insn = PREV_INSN (insn);
1908 emit_insn_before (seq, insn);
1916 /* If we already have a replacement, use it. Otherwise,
1917 try to fix up this address in case it is invalid. */
1919 replacement = find_fixup_replacement (replacements, var);
1920 if (replacement->new)
1922 *loc = replacement->new;
1926 *loc = replacement->new = x = fixup_stack_1 (x, insn);
1928 /* Unless we are forcing memory to register or we changed the mode,
1929 we can leave things the way they are if the insn is valid. */
1931 INSN_CODE (insn) = -1;
1932 if (! flag_force_mem && GET_MODE (x) == promoted_mode
1933 && recog_memoized (insn) >= 0)
1936 *loc = replacement->new = gen_reg_rtx (promoted_mode);
1940 /* If X contains VAR, we need to unshare it here so that we update
1941 each occurrence separately. But all identical MEMs in one insn
1942 must be replaced with the same rtx because of the possibility of
1945 if (reg_mentioned_p (var, x))
1947 replacement = find_fixup_replacement (replacements, x);
1948 if (replacement->new == 0)
1949 replacement->new = copy_most_rtx (x, no_share);
1951 *loc = x = replacement->new;
1952 code = GET_CODE (x);
1969 /* Note that in some cases those types of expressions are altered
1970 by optimize_bit_field, and do not survive to get here. */
1971 if (XEXP (x, 0) == var
1972 || (GET_CODE (XEXP (x, 0)) == SUBREG
1973 && SUBREG_REG (XEXP (x, 0)) == var))
1975 /* Get TEM as a valid MEM in the mode presently in the insn.
1977 We don't worry about the possibility of MATCH_DUP here; it
1978 is highly unlikely and would be tricky to handle. */
1981 if (GET_CODE (tem) == SUBREG)
1983 if (GET_MODE_BITSIZE (GET_MODE (tem))
1984 > GET_MODE_BITSIZE (GET_MODE (var)))
1986 replacement = find_fixup_replacement (replacements, var);
1987 if (replacement->new == 0)
1988 replacement->new = gen_reg_rtx (GET_MODE (var));
1989 SUBREG_REG (tem) = replacement->new;
1991 /* The following code works only if we have a MEM, so we
1992 need to handle the subreg here. We directly substitute
1993 it assuming that a subreg must be OK here. We already
1994 scheduled a replacement to copy the mem into the
2000 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2003 tem = fixup_stack_1 (tem, insn);
2005 /* Unless we want to load from memory, get TEM into the proper mode
2006 for an extract from memory. This can only be done if the
2007 extract is at a constant position and length. */
2009 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
2010 && GET_CODE (XEXP (x, 2)) == CONST_INT
2011 && ! mode_dependent_address_p (XEXP (tem, 0))
2012 && ! MEM_VOLATILE_P (tem))
2014 enum machine_mode wanted_mode = VOIDmode;
2015 enum machine_mode is_mode = GET_MODE (tem);
2016 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2));
2018 if (GET_CODE (x) == ZERO_EXTRACT)
2020 enum machine_mode new_mode
2021 = mode_for_extraction (EP_extzv, 1);
2022 if (new_mode != MAX_MACHINE_MODE)
2023 wanted_mode = new_mode;
2025 else if (GET_CODE (x) == SIGN_EXTRACT)
2027 enum machine_mode new_mode
2028 = mode_for_extraction (EP_extv, 1);
2029 if (new_mode != MAX_MACHINE_MODE)
2030 wanted_mode = new_mode;
2033 /* If we have a narrower mode, we can do something. */
2034 if (wanted_mode != VOIDmode
2035 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2037 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2038 rtx old_pos = XEXP (x, 2);
2041 /* If the bytes and bits are counted differently, we
2042 must adjust the offset. */
2043 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2044 offset = (GET_MODE_SIZE (is_mode)
2045 - GET_MODE_SIZE (wanted_mode) - offset);
2047 pos %= GET_MODE_BITSIZE (wanted_mode);
2049 newmem = adjust_address_nv (tem, wanted_mode, offset);
2051 /* Make the change and see if the insn remains valid. */
2052 INSN_CODE (insn) = -1;
2053 XEXP (x, 0) = newmem;
2054 XEXP (x, 2) = GEN_INT (pos);
2056 if (recog_memoized (insn) >= 0)
2059 /* Otherwise, restore old position. XEXP (x, 0) will be
2061 XEXP (x, 2) = old_pos;
2065 /* If we get here, the bitfield extract insn can't accept a memory
2066 reference. Copy the input into a register. */
2068 tem1 = gen_reg_rtx (GET_MODE (tem));
2069 emit_insn_before (gen_move_insn (tem1, tem), insn);
2076 if (SUBREG_REG (x) == var)
2078 /* If this is a special SUBREG made because VAR was promoted
2079 from a wider mode, replace it with VAR and call ourself
2080 recursively, this time saying that the object previously
2081 had its current mode (by virtue of the SUBREG). */
2083 if (SUBREG_PROMOTED_VAR_P (x))
2086 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements,
2091 /* If this SUBREG makes VAR wider, it has become a paradoxical
2092 SUBREG with VAR in memory, but these aren't allowed at this
2093 stage of the compilation. So load VAR into a pseudo and take
2094 a SUBREG of that pseudo. */
2095 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
2097 replacement = find_fixup_replacement (replacements, var);
2098 if (replacement->new == 0)
2099 replacement->new = gen_reg_rtx (promoted_mode);
2100 SUBREG_REG (x) = replacement->new;
2104 /* See if we have already found a replacement for this SUBREG.
2105 If so, use it. Otherwise, make a MEM and see if the insn
2106 is recognized. If not, or if we should force MEM into a register,
2107 make a pseudo for this SUBREG. */
2108 replacement = find_fixup_replacement (replacements, x);
2109 if (replacement->new)
2111 enum machine_mode mode = GET_MODE (x);
2112 *loc = replacement->new;
2114 /* Careful! We may have just replaced a SUBREG by a MEM, which
2115 means that the insn may have become invalid again. We can't
2116 in this case make a new replacement since we already have one
2117 and we must deal with MATCH_DUPs. */
2118 if (GET_CODE (replacement->new) == MEM)
2120 INSN_CODE (insn) = -1;
2121 if (recog_memoized (insn) >= 0)
2124 fixup_var_refs_1 (replacement->new, mode, &PATTERN (insn),
2125 insn, replacements, no_share);
2131 replacement->new = *loc = fixup_memory_subreg (x, insn,
2134 INSN_CODE (insn) = -1;
2135 if (! flag_force_mem && recog_memoized (insn) >= 0)
2138 *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
2144 /* First do special simplification of bit-field references. */
2145 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
2146 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
2147 optimize_bit_field (x, insn, 0);
2148 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
2149 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
2150 optimize_bit_field (x, insn, 0);
2152 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2153 into a register and then store it back out. */
2154 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT
2155 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG
2156 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var
2157 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0)))
2158 > GET_MODE_SIZE (GET_MODE (var))))
2160 replacement = find_fixup_replacement (replacements, var);
2161 if (replacement->new == 0)
2162 replacement->new = gen_reg_rtx (GET_MODE (var));
2164 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new;
2165 emit_insn_after (gen_move_insn (var, replacement->new), insn);
2168 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2169 insn into a pseudo and store the low part of the pseudo into VAR. */
2170 if (GET_CODE (SET_DEST (x)) == SUBREG
2171 && SUBREG_REG (SET_DEST (x)) == var
2172 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
2173 > GET_MODE_SIZE (GET_MODE (var))))
2175 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
2176 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
2183 rtx dest = SET_DEST (x);
2184 rtx src = SET_SRC (x);
2185 rtx outerdest = dest;
2187 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2188 || GET_CODE (dest) == SIGN_EXTRACT
2189 || GET_CODE (dest) == ZERO_EXTRACT)
2190 dest = XEXP (dest, 0);
2192 if (GET_CODE (src) == SUBREG)
2193 src = SUBREG_REG (src);
2195 /* If VAR does not appear at the top level of the SET
2196 just scan the lower levels of the tree. */
2198 if (src != var && dest != var)
2201 /* We will need to rerecognize this insn. */
2202 INSN_CODE (insn) = -1;
2204 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var
2205 && mode_for_extraction (EP_insv, -1) != MAX_MACHINE_MODE)
2207 /* Since this case will return, ensure we fixup all the
2209 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1),
2210 insn, replacements, no_share);
2211 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2),
2212 insn, replacements, no_share);
2213 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x),
2214 insn, replacements, no_share);
2216 tem = XEXP (outerdest, 0);
2218 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2219 that may appear inside a ZERO_EXTRACT.
2220 This was legitimate when the MEM was a REG. */
2221 if (GET_CODE (tem) == SUBREG
2222 && SUBREG_REG (tem) == var)
2223 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0);
2225 tem = fixup_stack_1 (tem, insn);
2227 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
2228 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
2229 && ! mode_dependent_address_p (XEXP (tem, 0))
2230 && ! MEM_VOLATILE_P (tem))
2232 enum machine_mode wanted_mode;
2233 enum machine_mode is_mode = GET_MODE (tem);
2234 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2));
2236 wanted_mode = mode_for_extraction (EP_insv, 0);
2238 /* If we have a narrower mode, we can do something. */
2239 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
2241 HOST_WIDE_INT offset = pos / BITS_PER_UNIT;
2242 rtx old_pos = XEXP (outerdest, 2);
2245 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN)
2246 offset = (GET_MODE_SIZE (is_mode)
2247 - GET_MODE_SIZE (wanted_mode) - offset);
2249 pos %= GET_MODE_BITSIZE (wanted_mode);
2251 newmem = adjust_address_nv (tem, wanted_mode, offset);
2253 /* Make the change and see if the insn remains valid. */
2254 INSN_CODE (insn) = -1;
2255 XEXP (outerdest, 0) = newmem;
2256 XEXP (outerdest, 2) = GEN_INT (pos);
2258 if (recog_memoized (insn) >= 0)
2261 /* Otherwise, restore old position. XEXP (x, 0) will be
2263 XEXP (outerdest, 2) = old_pos;
2267 /* If we get here, the bit-field store doesn't allow memory
2268 or isn't located at a constant position. Load the value into
2269 a register, do the store, and put it back into memory. */
2271 tem1 = gen_reg_rtx (GET_MODE (tem));
2272 emit_insn_before (gen_move_insn (tem1, tem), insn);
2273 emit_insn_after (gen_move_insn (tem, tem1), insn);
2274 XEXP (outerdest, 0) = tem1;
2278 /* STRICT_LOW_PART is a no-op on memory references
2279 and it can cause combinations to be unrecognizable,
2282 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
2283 SET_DEST (x) = XEXP (SET_DEST (x), 0);
2285 /* A valid insn to copy VAR into or out of a register
2286 must be left alone, to avoid an infinite loop here.
2287 If the reference to VAR is by a subreg, fix that up,
2288 since SUBREG is not valid for a memref.
2289 Also fix up the address of the stack slot.
2291 Note that we must not try to recognize the insn until
2292 after we know that we have valid addresses and no
2293 (subreg (mem ...) ...) constructs, since these interfere
2294 with determining the validity of the insn. */
2296 if ((SET_SRC (x) == var
2297 || (GET_CODE (SET_SRC (x)) == SUBREG
2298 && SUBREG_REG (SET_SRC (x)) == var))
2299 && (GET_CODE (SET_DEST (x)) == REG
2300 || (GET_CODE (SET_DEST (x)) == SUBREG
2301 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
2302 && GET_MODE (var) == promoted_mode
2303 && x == single_set (insn))
2307 if (GET_CODE (SET_SRC (x)) == SUBREG
2308 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x)))
2309 > GET_MODE_SIZE (GET_MODE (var))))
2311 /* This (subreg VAR) is now a paradoxical subreg. We need
2312 to replace VAR instead of the subreg. */
2313 replacement = find_fixup_replacement (replacements, var);
2314 if (replacement->new == NULL_RTX)
2315 replacement->new = gen_reg_rtx (GET_MODE (var));
2316 SUBREG_REG (SET_SRC (x)) = replacement->new;
2320 replacement = find_fixup_replacement (replacements, SET_SRC (x));
2321 if (replacement->new)
2322 SET_SRC (x) = replacement->new;
2323 else if (GET_CODE (SET_SRC (x)) == SUBREG)
2324 SET_SRC (x) = replacement->new
2325 = fixup_memory_subreg (SET_SRC (x), insn, promoted_mode,
2328 SET_SRC (x) = replacement->new
2329 = fixup_stack_1 (SET_SRC (x), insn);
2332 if (recog_memoized (insn) >= 0)
2335 /* INSN is not valid, but we know that we want to
2336 copy SET_SRC (x) to SET_DEST (x) in some way. So
2337 we generate the move and see whether it requires more
2338 than one insn. If it does, we emit those insns and
2339 delete INSN. Otherwise, we can just replace the pattern
2340 of INSN; we have already verified above that INSN has
2341 no other function that to do X. */
2343 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2344 if (NEXT_INSN (pat) != NULL_RTX)
2346 last = emit_insn_before (pat, insn);
2348 /* INSN might have REG_RETVAL or other important notes, so
2349 we need to store the pattern of the last insn in the
2350 sequence into INSN similarly to the normal case. LAST
2351 should not have REG_NOTES, but we allow them if INSN has
2353 if (REG_NOTES (last) && REG_NOTES (insn))
2355 if (REG_NOTES (last))
2356 REG_NOTES (insn) = REG_NOTES (last);
2357 PATTERN (insn) = PATTERN (last);
2362 PATTERN (insn) = PATTERN (pat);
2367 if ((SET_DEST (x) == var
2368 || (GET_CODE (SET_DEST (x)) == SUBREG
2369 && SUBREG_REG (SET_DEST (x)) == var))
2370 && (GET_CODE (SET_SRC (x)) == REG
2371 || (GET_CODE (SET_SRC (x)) == SUBREG
2372 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
2373 && GET_MODE (var) == promoted_mode
2374 && x == single_set (insn))
2378 if (GET_CODE (SET_DEST (x)) == SUBREG)
2379 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn,
2382 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
2384 if (recog_memoized (insn) >= 0)
2387 pat = gen_move_insn (SET_DEST (x), SET_SRC (x));
2388 if (NEXT_INSN (pat) != NULL_RTX)
2390 last = emit_insn_before (pat, insn);
2392 /* INSN might have REG_RETVAL or other important notes, so
2393 we need to store the pattern of the last insn in the
2394 sequence into INSN similarly to the normal case. LAST
2395 should not have REG_NOTES, but we allow them if INSN has
2397 if (REG_NOTES (last) && REG_NOTES (insn))
2399 if (REG_NOTES (last))
2400 REG_NOTES (insn) = REG_NOTES (last);
2401 PATTERN (insn) = PATTERN (last);
2406 PATTERN (insn) = PATTERN (pat);
2411 /* Otherwise, storing into VAR must be handled specially
2412 by storing into a temporary and copying that into VAR
2413 with a new insn after this one. Note that this case
2414 will be used when storing into a promoted scalar since
2415 the insn will now have different modes on the input
2416 and output and hence will be invalid (except for the case
2417 of setting it to a constant, which does not need any
2418 change if it is valid). We generate extra code in that case,
2419 but combine.c will eliminate it. */
2424 rtx fixeddest = SET_DEST (x);
2425 enum machine_mode temp_mode;
2427 /* STRICT_LOW_PART can be discarded, around a MEM. */
2428 if (GET_CODE (fixeddest) == STRICT_LOW_PART)
2429 fixeddest = XEXP (fixeddest, 0);
2430 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2431 if (GET_CODE (fixeddest) == SUBREG)
2433 fixeddest = fixup_memory_subreg (fixeddest, insn,
2435 temp_mode = GET_MODE (fixeddest);
2439 fixeddest = fixup_stack_1 (fixeddest, insn);
2440 temp_mode = promoted_mode;
2443 temp = gen_reg_rtx (temp_mode);
2445 emit_insn_after (gen_move_insn (fixeddest,
2446 gen_lowpart (GET_MODE (fixeddest),
2450 SET_DEST (x) = temp;
2458 /* Nothing special about this RTX; fix its operands. */
2460 fmt = GET_RTX_FORMAT (code);
2461 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2464 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements,
2466 else if (fmt[i] == 'E')
2469 for (j = 0; j < XVECLEN (x, i); j++)
2470 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j),
2471 insn, replacements, no_share);
2476 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2477 The REG was placed on the stack, so X now has the form (SUBREG:m1
2480 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2481 must be emitted to compute NEWADDR, put them before INSN.
2483 UNCRITICAL nonzero means accept paradoxical subregs.
2484 This is used for subregs found inside REG_NOTES. */
2487 fixup_memory_subreg (rtx x, rtx insn, enum machine_mode promoted_mode, int uncritical)
2490 rtx mem = SUBREG_REG (x);
2491 rtx addr = XEXP (mem, 0);
2492 enum machine_mode mode = GET_MODE (x);
2495 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2496 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (mem)) && ! uncritical)
2499 offset = SUBREG_BYTE (x);
2500 if (BYTES_BIG_ENDIAN)
2501 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2502 the offset so that it points to the right location within the
2504 offset -= (GET_MODE_SIZE (promoted_mode) - GET_MODE_SIZE (GET_MODE (mem)));
2506 if (!flag_force_addr
2507 && memory_address_p (mode, plus_constant (addr, offset)))
2508 /* Shortcut if no insns need be emitted. */
2509 return adjust_address (mem, mode, offset);
2512 result = adjust_address (mem, mode, offset);
2516 emit_insn_before (seq, insn);
2520 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2521 Replace subexpressions of X in place.
2522 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2523 Otherwise return X, with its contents possibly altered.
2525 INSN, PROMOTED_MODE and UNCRITICAL are as for
2526 fixup_memory_subreg. */
2529 walk_fixup_memory_subreg (rtx x, rtx insn, enum machine_mode promoted_mode,
2539 code = GET_CODE (x);
2541 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
2542 return fixup_memory_subreg (x, insn, promoted_mode, uncritical);
2544 /* Nothing special about this RTX; fix its operands. */
2546 fmt = GET_RTX_FORMAT (code);
2547 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2550 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn,
2551 promoted_mode, uncritical);
2552 else if (fmt[i] == 'E')
2555 for (j = 0; j < XVECLEN (x, i); j++)
2557 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn,
2558 promoted_mode, uncritical);
2564 /* For each memory ref within X, if it refers to a stack slot
2565 with an out of range displacement, put the address in a temp register
2566 (emitting new insns before INSN to load these registers)
2567 and alter the memory ref to use that register.
2568 Replace each such MEM rtx with a copy, to avoid clobberage. */
2571 fixup_stack_1 (rtx x, rtx insn)
2574 RTX_CODE code = GET_CODE (x);
2579 rtx ad = XEXP (x, 0);
2580 /* If we have address of a stack slot but it's not valid
2581 (displacement is too large), compute the sum in a register. */
2582 if (GET_CODE (ad) == PLUS
2583 && GET_CODE (XEXP (ad, 0)) == REG
2584 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
2585 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER)
2586 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM
2587 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2588 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM
2590 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM
2591 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM
2592 || XEXP (ad, 0) == current_function_internal_arg_pointer)
2593 && GET_CODE (XEXP (ad, 1)) == CONST_INT)
2596 if (memory_address_p (GET_MODE (x), ad))
2600 temp = copy_to_reg (ad);
2603 emit_insn_before (seq, insn);
2604 return replace_equiv_address (x, temp);
2609 fmt = GET_RTX_FORMAT (code);
2610 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2613 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
2614 else if (fmt[i] == 'E')
2617 for (j = 0; j < XVECLEN (x, i); j++)
2618 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
2624 /* Optimization: a bit-field instruction whose field
2625 happens to be a byte or halfword in memory
2626 can be changed to a move instruction.
2628 We call here when INSN is an insn to examine or store into a bit-field.
2629 BODY is the SET-rtx to be altered.
2631 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2632 (Currently this is called only from function.c, and EQUIV_MEM
2636 optimize_bit_field (rtx body, rtx insn, rtx *equiv_mem)
2641 enum machine_mode mode;
2643 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
2644 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
2645 bitfield = SET_DEST (body), destflag = 1;
2647 bitfield = SET_SRC (body), destflag = 0;
2649 /* First check that the field being stored has constant size and position
2650 and is in fact a byte or halfword suitably aligned. */
2652 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
2653 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
2654 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
2656 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
2660 /* Now check that the containing word is memory, not a register,
2661 and that it is safe to change the machine mode. */
2663 if (GET_CODE (XEXP (bitfield, 0)) == MEM)
2664 memref = XEXP (bitfield, 0);
2665 else if (GET_CODE (XEXP (bitfield, 0)) == REG
2667 memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
2668 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2669 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
2670 memref = SUBREG_REG (XEXP (bitfield, 0));
2671 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
2673 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
2674 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
2677 && ! mode_dependent_address_p (XEXP (memref, 0))
2678 && ! MEM_VOLATILE_P (memref))
2680 /* Now adjust the address, first for any subreg'ing
2681 that we are now getting rid of,
2682 and then for which byte of the word is wanted. */
2684 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2));
2687 /* Adjust OFFSET to count bits from low-address byte. */
2688 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN)
2689 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
2690 - offset - INTVAL (XEXP (bitfield, 1)));
2692 /* Adjust OFFSET to count bytes from low-address byte. */
2693 offset /= BITS_PER_UNIT;
2694 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
2696 offset += (SUBREG_BYTE (XEXP (bitfield, 0))
2697 / UNITS_PER_WORD) * UNITS_PER_WORD;
2698 if (BYTES_BIG_ENDIAN)
2699 offset -= (MIN (UNITS_PER_WORD,
2700 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
2701 - MIN (UNITS_PER_WORD,
2702 GET_MODE_SIZE (GET_MODE (memref))));
2706 memref = adjust_address (memref, mode, offset);
2707 insns = get_insns ();
2709 emit_insn_before (insns, insn);
2711 /* Store this memory reference where
2712 we found the bit field reference. */
2716 validate_change (insn, &SET_DEST (body), memref, 1);
2717 if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
2719 rtx src = SET_SRC (body);
2720 while (GET_CODE (src) == SUBREG
2721 && SUBREG_BYTE (src) == 0)
2722 src = SUBREG_REG (src);
2723 if (GET_MODE (src) != GET_MODE (memref))
2724 src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
2725 validate_change (insn, &SET_SRC (body), src, 1);
2727 else if (GET_MODE (SET_SRC (body)) != VOIDmode
2728 && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
2729 /* This shouldn't happen because anything that didn't have
2730 one of these modes should have got converted explicitly
2731 and then referenced through a subreg.
2732 This is so because the original bit-field was
2733 handled by agg_mode and so its tree structure had
2734 the same mode that memref now has. */
2739 rtx dest = SET_DEST (body);
2741 while (GET_CODE (dest) == SUBREG
2742 && SUBREG_BYTE (dest) == 0
2743 && (GET_MODE_CLASS (GET_MODE (dest))
2744 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest))))
2745 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
2747 dest = SUBREG_REG (dest);
2749 validate_change (insn, &SET_DEST (body), dest, 1);
2751 if (GET_MODE (dest) == GET_MODE (memref))
2752 validate_change (insn, &SET_SRC (body), memref, 1);
2755 /* Convert the mem ref to the destination mode. */
2756 rtx newreg = gen_reg_rtx (GET_MODE (dest));
2759 convert_move (newreg, memref,
2760 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
2764 validate_change (insn, &SET_SRC (body), newreg, 1);
2768 /* See if we can convert this extraction or insertion into
2769 a simple move insn. We might not be able to do so if this
2770 was, for example, part of a PARALLEL.
2772 If we succeed, write out any needed conversions. If we fail,
2773 it is hard to guess why we failed, so don't do anything
2774 special; just let the optimization be suppressed. */
2776 if (apply_change_group () && seq)
2777 emit_insn_before (seq, insn);
2782 /* These routines are responsible for converting virtual register references
2783 to the actual hard register references once RTL generation is complete.
2785 The following four variables are used for communication between the
2786 routines. They contain the offsets of the virtual registers from their
2787 respective hard registers. */
2789 static int in_arg_offset;
2790 static int var_offset;
2791 static int dynamic_offset;
2792 static int out_arg_offset;
2793 static int cfa_offset;
2795 /* In most machines, the stack pointer register is equivalent to the bottom
2798 #ifndef STACK_POINTER_OFFSET
2799 #define STACK_POINTER_OFFSET 0
2802 /* If not defined, pick an appropriate default for the offset of dynamically
2803 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2804 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2806 #ifndef STACK_DYNAMIC_OFFSET
2808 /* The bottom of the stack points to the actual arguments. If
2809 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2810 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2811 stack space for register parameters is not pushed by the caller, but
2812 rather part of the fixed stack areas and hence not included in
2813 `current_function_outgoing_args_size'. Nevertheless, we must allow
2814 for it when allocating stack dynamic objects. */
2816 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2817 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2818 ((ACCUMULATE_OUTGOING_ARGS \
2819 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2820 + (STACK_POINTER_OFFSET)) \
2823 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2824 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2825 + (STACK_POINTER_OFFSET))
2829 /* On most machines, the CFA coincides with the first incoming parm. */
2831 #ifndef ARG_POINTER_CFA_OFFSET
2832 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2835 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just
2836 had its address taken. DECL is the decl or SAVE_EXPR for the
2837 object stored in the register, for later use if we do need to force
2838 REG into the stack. REG is overwritten by the MEM like in
2839 put_reg_into_stack. RESCAN is true if previously emitted
2840 instructions must be rescanned and modified now that the REG has
2841 been transformed. */
2844 gen_mem_addressof (rtx reg, tree decl, int rescan)
2846 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)),
2849 /* Calculate this before we start messing with decl's RTL. */
2850 HOST_WIDE_INT set = decl ? get_alias_set (decl) : 0;
2852 /* If the original REG was a user-variable, then so is the REG whose
2853 address is being taken. Likewise for unchanging. */
2854 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg);
2855 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg);
2857 PUT_CODE (reg, MEM);
2858 MEM_ATTRS (reg) = 0;
2863 tree type = TREE_TYPE (decl);
2864 enum machine_mode decl_mode
2865 = (DECL_P (decl) ? DECL_MODE (decl) : TYPE_MODE (TREE_TYPE (decl)));
2866 rtx decl_rtl = (TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl)
2867 : DECL_RTL_IF_SET (decl));
2869 PUT_MODE (reg, decl_mode);
2871 /* Clear DECL_RTL momentarily so functions below will work
2872 properly, then set it again. */
2873 if (DECL_P (decl) && decl_rtl == reg)
2874 SET_DECL_RTL (decl, 0);
2876 set_mem_attributes (reg, decl, 1);
2877 set_mem_alias_set (reg, set);
2879 if (DECL_P (decl) && decl_rtl == reg)
2880 SET_DECL_RTL (decl, reg);
2883 && (TREE_USED (decl) || (DECL_P (decl) && DECL_INITIAL (decl) != 0)))
2884 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), reg, 0);
2888 /* This can only happen during reload. Clear the same flag bits as
2890 MEM_VOLATILE_P (reg) = 0;
2891 RTX_UNCHANGING_P (reg) = 0;
2892 MEM_IN_STRUCT_P (reg) = 0;
2893 MEM_SCALAR_P (reg) = 0;
2894 MEM_ATTRS (reg) = 0;
2896 fixup_var_refs (reg, GET_MODE (reg), 0, reg, 0);
2902 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2905 flush_addressof (tree decl)
2907 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL)
2908 && DECL_RTL (decl) != 0
2909 && GET_CODE (DECL_RTL (decl)) == MEM
2910 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF
2911 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG)
2912 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0);
2915 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2918 put_addressof_into_stack (rtx r, htab_t ht)
2921 bool volatile_p, used_p;
2923 rtx reg = XEXP (r, 0);
2925 if (GET_CODE (reg) != REG)
2928 decl = ADDRESSOF_DECL (r);
2931 type = TREE_TYPE (decl);
2932 volatile_p = (TREE_CODE (decl) != SAVE_EXPR
2933 && TREE_THIS_VOLATILE (decl));
2934 used_p = (TREE_USED (decl)
2935 || (DECL_P (decl) && DECL_INITIAL (decl) != 0));
2944 put_reg_into_stack (0, reg, type, GET_MODE (reg), ADDRESSOF_REGNO (r),
2945 volatile_p, used_p, false, ht);
2948 /* List of replacements made below in purge_addressof_1 when creating
2949 bitfield insertions. */
2950 static rtx purge_bitfield_addressof_replacements;
2952 /* List of replacements made below in purge_addressof_1 for patterns
2953 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
2954 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
2955 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
2956 enough in complex cases, e.g. when some field values can be
2957 extracted by usage MEM with narrower mode. */
2958 static rtx purge_addressof_replacements;
2960 /* Helper function for purge_addressof. See if the rtx expression at *LOC
2961 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2962 the stack. If the function returns FALSE then the replacement could not
2963 be made. If MAY_POSTPONE is true and we would not put the addressof
2964 to stack, postpone processing of the insn. */
2967 purge_addressof_1 (rtx *loc, rtx insn, int force, int store, int may_postpone,
2975 bool libcall = false;
2977 /* Re-start here to avoid recursion in common cases. */
2984 /* Is this a libcall? */
2986 libcall = REG_NOTE_KIND (*loc) == REG_RETVAL;
2988 code = GET_CODE (x);
2990 /* If we don't return in any of the cases below, we will recurse inside
2991 the RTX, which will normally result in any ADDRESSOF being forced into
2995 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1,
2997 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0,
3001 else if (code == ADDRESSOF)
3005 if (GET_CODE (XEXP (x, 0)) != MEM)
3006 put_addressof_into_stack (x, ht);
3008 /* We must create a copy of the rtx because it was created by
3009 overwriting a REG rtx which is always shared. */
3010 sub = copy_rtx (XEXP (XEXP (x, 0), 0));
3011 if (validate_change (insn, loc, sub, 0)
3012 || validate_replace_rtx (x, sub, insn))
3017 /* If SUB is a hard or virtual register, try it as a pseudo-register.
3018 Otherwise, perhaps SUB is an expression, so generate code to compute
3020 if (GET_CODE (sub) == REG && REGNO (sub) <= LAST_VIRTUAL_REGISTER)
3021 sub = copy_to_reg (sub);
3023 sub = force_operand (sub, NULL_RTX);
3025 if (! validate_change (insn, loc, sub, 0)
3026 && ! validate_replace_rtx (x, sub, insn))
3029 insns = get_insns ();
3031 emit_insn_before (insns, insn);
3035 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force)
3037 rtx sub = XEXP (XEXP (x, 0), 0);
3039 if (GET_CODE (sub) == MEM)
3040 sub = adjust_address_nv (sub, GET_MODE (x), 0);
3041 else if (GET_CODE (sub) == REG
3042 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode))
3044 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub))
3046 int size_x, size_sub;
3050 /* Postpone for now, so that we do not emit bitfield arithmetics
3051 unless there is some benefit from it. */
3052 if (!postponed_insns || XEXP (postponed_insns, 0) != insn)
3053 postponed_insns = alloc_INSN_LIST (insn, postponed_insns);
3059 /* When processing REG_NOTES look at the list of
3060 replacements done on the insn to find the register that X
3064 for (tem = purge_bitfield_addressof_replacements;
3066 tem = XEXP (XEXP (tem, 1), 1))
3067 if (rtx_equal_p (x, XEXP (tem, 0)))
3069 *loc = XEXP (XEXP (tem, 1), 0);
3073 /* See comment for purge_addressof_replacements. */
3074 for (tem = purge_addressof_replacements;
3076 tem = XEXP (XEXP (tem, 1), 1))
3077 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3079 rtx z = XEXP (XEXP (tem, 1), 0);
3081 if (GET_MODE (x) == GET_MODE (z)
3082 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG
3083 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG))
3086 /* It can happen that the note may speak of things
3087 in a wider (or just different) mode than the
3088 code did. This is especially true of
3091 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0)
3094 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3095 && (GET_MODE_SIZE (GET_MODE (x))
3096 > GET_MODE_SIZE (GET_MODE (z))))
3098 /* This can occur as a result in invalid
3099 pointer casts, e.g. float f; ...
3100 *(long long int *)&f.
3101 ??? We could emit a warning here, but
3102 without a line number that wouldn't be
3104 z = gen_rtx_SUBREG (GET_MODE (x), z, 0);
3107 z = gen_lowpart (GET_MODE (x), z);
3113 /* When we are processing the REG_NOTES of the last instruction
3114 of a libcall, there will be typically no replacements
3115 for that insn; the replacements happened before, piecemeal
3116 fashion. OTOH we are not interested in the details of
3117 this for the REG_EQUAL note, we want to know the big picture,
3118 which can be succinctly described with a simple SUBREG.
3119 Note that removing the REG_EQUAL note is not an option
3120 on the last insn of a libcall, so we must do a replacement. */
3122 /* In compile/990107-1.c:7 compiled at -O1 -m1 for sh-elf,
3124 (mem:DI (addressof:SI (reg/v:DF 160) 159 0x401c8510)
3125 [0 S8 A32]), which can be expressed with a simple
3127 if ((GET_MODE_SIZE (GET_MODE (x))
3128 <= GET_MODE_SIZE (GET_MODE (sub)))
3129 /* Again, invalid pointer casts (as in
3130 compile/990203-1.c) can require paradoxical
3132 || (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD
3133 && (GET_MODE_SIZE (GET_MODE (x))
3134 > GET_MODE_SIZE (GET_MODE (sub)))
3137 *loc = gen_rtx_SUBREG (GET_MODE (x), sub, 0);
3140 /* ??? Are there other cases we should handle? */
3142 /* Sometimes we may not be able to find the replacement. For
3143 example when the original insn was a MEM in a wider mode,
3144 and the note is part of a sign extension of a narrowed
3145 version of that MEM. Gcc testcase compile/990829-1.c can
3146 generate an example of this situation. Rather than complain
3147 we return false, which will prompt our caller to remove the
3152 size_x = GET_MODE_BITSIZE (GET_MODE (x));
3153 size_sub = GET_MODE_BITSIZE (GET_MODE (sub));
3155 /* Do not frob unchanging MEMs. If a later reference forces the
3156 pseudo to the stack, we can wind up with multiple writes to
3157 an unchanging memory, which is invalid. */
3158 if (RTX_UNCHANGING_P (x) && size_x != size_sub)
3161 /* Don't even consider working with paradoxical subregs,
3162 or the moral equivalent seen here. */
3163 else if (size_x <= size_sub
3164 && int_mode_for_mode (GET_MODE (sub)) != BLKmode)
3166 /* Do a bitfield insertion to mirror what would happen
3173 rtx p = PREV_INSN (insn);
3176 val = gen_reg_rtx (GET_MODE (x));
3177 if (! validate_change (insn, loc, val, 0))
3179 /* Discard the current sequence and put the
3180 ADDRESSOF on stack. */
3186 emit_insn_before (seq, insn);
3187 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3191 store_bit_field (sub, size_x, 0, GET_MODE (x),
3192 val, GET_MODE_SIZE (GET_MODE (sub)));
3194 /* Make sure to unshare any shared rtl that store_bit_field
3195 might have created. */
3196 unshare_all_rtl_again (get_insns ());
3200 p = emit_insn_after (seq, insn);
3201 if (NEXT_INSN (insn))
3202 compute_insns_for_mem (NEXT_INSN (insn),
3203 p ? NEXT_INSN (p) : NULL_RTX,
3208 rtx p = PREV_INSN (insn);
3211 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX,
3212 GET_MODE (x), GET_MODE (x),
3213 GET_MODE_SIZE (GET_MODE (sub)));
3215 if (! validate_change (insn, loc, val, 0))
3217 /* Discard the current sequence and put the
3218 ADDRESSOF on stack. */
3225 emit_insn_before (seq, insn);
3226 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (),
3230 /* Remember the replacement so that the same one can be done
3231 on the REG_NOTES. */
3232 purge_bitfield_addressof_replacements
3233 = gen_rtx_EXPR_LIST (VOIDmode, x,
3236 purge_bitfield_addressof_replacements));
3238 /* We replaced with a reg -- all done. */
3243 else if (validate_change (insn, loc, sub, 0))
3245 /* Remember the replacement so that the same one can be done
3246 on the REG_NOTES. */
3247 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG)
3251 for (tem = purge_addressof_replacements;
3253 tem = XEXP (XEXP (tem, 1), 1))
3254 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0)))
3256 XEXP (XEXP (tem, 1), 0) = sub;
3259 purge_addressof_replacements
3260 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0),
3261 gen_rtx_EXPR_LIST (VOIDmode, sub,
3262 purge_addressof_replacements));
3270 /* Scan all subexpressions. */
3271 fmt = GET_RTX_FORMAT (code);
3272 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
3275 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0,
3277 else if (*fmt == 'E')
3278 for (j = 0; j < XVECLEN (x, i); j++)
3279 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0,
3286 /* Return a hash value for K, a REG. */
3289 insns_for_mem_hash (const void *k)
3291 /* Use the address of the key for the hash value. */
3292 struct insns_for_mem_entry *m = (struct insns_for_mem_entry *) k;
3293 return htab_hash_pointer (m->key);
3296 /* Return nonzero if K1 and K2 (two REGs) are the same. */
3299 insns_for_mem_comp (const void *k1, const void *k2)
3301 struct insns_for_mem_entry *m1 = (struct insns_for_mem_entry *) k1;
3302 struct insns_for_mem_entry *m2 = (struct insns_for_mem_entry *) k2;
3303 return m1->key == m2->key;
3306 struct insns_for_mem_walk_info
3308 /* The hash table that we are using to record which INSNs use which
3312 /* The INSN we are currently processing. */
3315 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3316 to find the insns that use the REGs in the ADDRESSOFs. */
3320 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3321 that might be used in an ADDRESSOF expression, record this INSN in
3322 the hash table given by DATA (which is really a pointer to an
3323 insns_for_mem_walk_info structure). */
3326 insns_for_mem_walk (rtx *r, void *data)
3328 struct insns_for_mem_walk_info *ifmwi
3329 = (struct insns_for_mem_walk_info *) data;
3330 struct insns_for_mem_entry tmp;
3331 tmp.insns = NULL_RTX;
3333 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF
3334 && GET_CODE (XEXP (*r, 0)) == REG)
3337 tmp.key = XEXP (*r, 0);
3338 e = htab_find_slot (ifmwi->ht, &tmp, INSERT);
3341 *e = ggc_alloc (sizeof (tmp));
3342 memcpy (*e, &tmp, sizeof (tmp));
3345 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG)
3347 struct insns_for_mem_entry *ifme;
3349 ifme = htab_find (ifmwi->ht, &tmp);
3351 /* If we have not already recorded this INSN, do so now. Since
3352 we process the INSNs in order, we know that if we have
3353 recorded it it must be at the front of the list. */
3354 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn))
3355 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn,
3362 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3363 which REGs in HT. */
3366 compute_insns_for_mem (rtx insns, rtx last_insn, htab_t ht)
3369 struct insns_for_mem_walk_info ifmwi;
3372 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass)
3373 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn))
3377 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi);
3381 /* Helper function for purge_addressof called through for_each_rtx.
3382 Returns true iff the rtl is an ADDRESSOF. */
3385 is_addressof (rtx *rtl, void *data ATTRIBUTE_UNUSED)
3387 return GET_CODE (*rtl) == ADDRESSOF;
3390 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3391 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3395 purge_addressof (rtx insns)
3400 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3401 requires a fixup pass over the instruction stream to correct
3402 INSNs that depended on the REG being a REG, and not a MEM. But,
3403 these fixup passes are slow. Furthermore, most MEMs are not
3404 mentioned in very many instructions. So, we speed up the process
3405 by pre-calculating which REGs occur in which INSNs; that allows
3406 us to perform the fixup passes much more quickly. */
3407 ht = htab_create_ggc (1000, insns_for_mem_hash, insns_for_mem_comp, NULL);
3408 compute_insns_for_mem (insns, NULL_RTX, ht);
3410 postponed_insns = NULL;
3412 for (insn = insns; insn; insn = NEXT_INSN (insn))
3415 if (! purge_addressof_1 (&PATTERN (insn), insn,
3416 asm_noperands (PATTERN (insn)) > 0, 0, 1, ht))
3417 /* If we could not replace the ADDRESSOFs in the insn,
3418 something is wrong. */
3421 if (! purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, 0, ht))
3423 /* If we could not replace the ADDRESSOFs in the insn's notes,
3424 we can just remove the offending notes instead. */
3427 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
3429 /* If we find a REG_RETVAL note then the insn is a libcall.
3430 Such insns must have REG_EQUAL notes as well, in order
3431 for later passes of the compiler to work. So it is not
3432 safe to delete the notes here, and instead we abort. */
3433 if (REG_NOTE_KIND (note) == REG_RETVAL)
3435 if (for_each_rtx (¬e, is_addressof, NULL))
3436 remove_note (insn, note);
3441 /* Process the postponed insns. */
3442 while (postponed_insns)
3444 insn = XEXP (postponed_insns, 0);
3445 tmp = postponed_insns;
3446 postponed_insns = XEXP (postponed_insns, 1);
3447 free_INSN_LIST_node (tmp);
3449 if (! purge_addressof_1 (&PATTERN (insn), insn,
3450 asm_noperands (PATTERN (insn)) > 0, 0, 0, ht))
3455 purge_bitfield_addressof_replacements = 0;
3456 purge_addressof_replacements = 0;
3458 /* REGs are shared. purge_addressof will destructively replace a REG
3459 with a MEM, which creates shared MEMs.
3461 Unfortunately, the children of put_reg_into_stack assume that MEMs
3462 referring to the same stack slot are shared (fixup_var_refs and
3463 the associated hash table code).
3465 So, we have to do another unsharing pass after we have flushed any
3466 REGs that had their address taken into the stack.
3468 It may be worth tracking whether or not we converted any REGs into
3469 MEMs to avoid this overhead when it is not needed. */
3470 unshare_all_rtl_again (get_insns ());
3473 /* Convert a SET of a hard subreg to a set of the appropriate hard
3474 register. A subroutine of purge_hard_subreg_sets. */
3477 purge_single_hard_subreg_set (rtx pattern)
3479 rtx reg = SET_DEST (pattern);
3480 enum machine_mode mode = GET_MODE (SET_DEST (pattern));
3483 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG
3484 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER)
3486 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)),
3487 GET_MODE (SUBREG_REG (reg)),
3490 reg = SUBREG_REG (reg);
3494 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER)
3496 reg = gen_rtx_REG (mode, REGNO (reg) + offset);
3497 SET_DEST (pattern) = reg;
3501 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3502 only such SETs that we expect to see are those left in because
3503 integrate can't handle sets of parts of a return value register.
3505 We don't use alter_subreg because we only want to eliminate subregs
3506 of hard registers. */
3509 purge_hard_subreg_sets (rtx insn)
3511 for (; insn; insn = NEXT_INSN (insn))
3515 rtx pattern = PATTERN (insn);
3516 switch (GET_CODE (pattern))
3519 if (GET_CODE (SET_DEST (pattern)) == SUBREG)
3520 purge_single_hard_subreg_set (pattern);
3525 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--)
3527 rtx inner_pattern = XVECEXP (pattern, 0, j);
3528 if (GET_CODE (inner_pattern) == SET
3529 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG)
3530 purge_single_hard_subreg_set (inner_pattern);
3541 /* Pass through the INSNS of function FNDECL and convert virtual register
3542 references to hard register references. */
3545 instantiate_virtual_regs (tree fndecl, rtx insns)
3550 /* Compute the offsets to use for this function. */
3551 in_arg_offset = FIRST_PARM_OFFSET (fndecl);
3552 var_offset = STARTING_FRAME_OFFSET;
3553 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
3554 out_arg_offset = STACK_POINTER_OFFSET;
3555 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl);
3557 /* Scan all variables and parameters of this function. For each that is
3558 in memory, instantiate all virtual registers if the result is a valid
3559 address. If not, we do it later. That will handle most uses of virtual
3560 regs on many machines. */
3561 instantiate_decls (fndecl, 1);
3563 /* Initialize recognition, indicating that volatile is OK. */
3566 /* Scan through all the insns, instantiating every virtual register still
3568 for (insn = insns; insn; insn = NEXT_INSN (insn))
3569 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
3570 || GET_CODE (insn) == CALL_INSN)
3572 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1);
3573 if (INSN_DELETED_P (insn))
3575 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0);
3576 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3577 if (GET_CODE (insn) == CALL_INSN)
3578 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn),
3581 /* Past this point all ASM statements should match. Verify that
3582 to avoid failures later in the compilation process. */
3583 if (asm_noperands (PATTERN (insn)) >= 0
3584 && ! check_asm_operands (PATTERN (insn)))
3585 instantiate_virtual_regs_lossage (insn);
3588 /* Instantiate the stack slots for the parm registers, for later use in
3589 addressof elimination. */
3590 for (i = 0; i < max_parm_reg; ++i)
3591 if (parm_reg_stack_loc[i])
3592 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0);
3594 /* Now instantiate the remaining register equivalences for debugging info.
3595 These will not be valid addresses. */
3596 instantiate_decls (fndecl, 0);
3598 /* Indicate that, from now on, assign_stack_local should use
3599 frame_pointer_rtx. */
3600 virtuals_instantiated = 1;
3603 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3604 all virtual registers in their DECL_RTL's.
3606 If VALID_ONLY, do this only if the resulting address is still valid.
3607 Otherwise, always do it. */
3610 instantiate_decls (tree fndecl, int valid_only)
3614 /* Process all parameters of the function. */
3615 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
3617 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
3618 HOST_WIDE_INT size_rtl;
3620 instantiate_decl (DECL_RTL (decl), size, valid_only);
3622 /* If the parameter was promoted, then the incoming RTL mode may be
3623 larger than the declared type size. We must use the larger of
3625 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl)));
3626 size = MAX (size_rtl, size);
3627 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only);
3630 /* Now process all variables defined in the function or its subblocks. */
3631 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
3634 /* Subroutine of instantiate_decls: Process all decls in the given
3635 BLOCK node and all its subblocks. */
3638 instantiate_decls_1 (tree let, int valid_only)
3642 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
3643 if (DECL_RTL_SET_P (t))
3644 instantiate_decl (DECL_RTL (t),
3645 int_size_in_bytes (TREE_TYPE (t)),
3648 /* Process all subblocks. */
3649 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
3650 instantiate_decls_1 (t, valid_only);
3653 /* Subroutine of the preceding procedures: Given RTL representing a
3654 decl and the size of the object, do any instantiation required.
3656 If VALID_ONLY is nonzero, it means that the RTL should only be
3657 changed if the new address is valid. */
3660 instantiate_decl (rtx x, HOST_WIDE_INT size, int valid_only)
3662 enum machine_mode mode;
3668 /* If this is a CONCAT, recurse for the pieces. */
3669 if (GET_CODE (x) == CONCAT)
3671 instantiate_decl (XEXP (x, 0), size / 2, valid_only);
3672 instantiate_decl (XEXP (x, 1), size / 2, valid_only);
3676 /* If this is not a MEM, no need to do anything. Similarly if the
3677 address is a constant or a register that is not a virtual register. */
3678 if (GET_CODE (x) != MEM)
3682 if (CONSTANT_P (addr)
3683 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG)
3684 || (GET_CODE (addr) == REG
3685 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER
3686 || REGNO (addr) > LAST_VIRTUAL_REGISTER)))
3689 /* If we should only do this if the address is valid, copy the address.
3690 We need to do this so we can undo any changes that might make the
3691 address invalid. This copy is unfortunate, but probably can't be
3695 addr = copy_rtx (addr);
3697 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0);
3699 if (valid_only && size >= 0)
3701 unsigned HOST_WIDE_INT decl_size = size;
3703 /* Now verify that the resulting address is valid for every integer or
3704 floating-point mode up to and including SIZE bytes long. We do this
3705 since the object might be accessed in any mode and frame addresses
3708 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
3709 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3710 mode = GET_MODE_WIDER_MODE (mode))
3711 if (! memory_address_p (mode, addr))
3714 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
3715 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size;
3716 mode = GET_MODE_WIDER_MODE (mode))
3717 if (! memory_address_p (mode, addr))
3721 /* Put back the address now that we have updated it and we either know
3722 it is valid or we don't care whether it is valid. */
3727 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3728 is a virtual register, return the equivalent hard register and set the
3729 offset indirectly through the pointer. Otherwise, return 0. */
3732 instantiate_new_reg (rtx x, HOST_WIDE_INT *poffset)
3735 HOST_WIDE_INT offset;
3737 if (x == virtual_incoming_args_rtx)
3738 new = arg_pointer_rtx, offset = in_arg_offset;
3739 else if (x == virtual_stack_vars_rtx)
3740 new = frame_pointer_rtx, offset = var_offset;
3741 else if (x == virtual_stack_dynamic_rtx)
3742 new = stack_pointer_rtx, offset = dynamic_offset;
3743 else if (x == virtual_outgoing_args_rtx)
3744 new = stack_pointer_rtx, offset = out_arg_offset;
3745 else if (x == virtual_cfa_rtx)
3746 new = arg_pointer_rtx, offset = cfa_offset;
3755 /* Called when instantiate_virtual_regs has failed to update the instruction.
3756 Usually this means that non-matching instruction has been emit, however for
3757 asm statements it may be the problem in the constraints. */
3759 instantiate_virtual_regs_lossage (rtx insn)
3761 if (asm_noperands (PATTERN (insn)) >= 0)
3763 error_for_asm (insn, "impossible constraint in `asm'");
3769 /* Given a pointer to a piece of rtx and an optional pointer to the
3770 containing object, instantiate any virtual registers present in it.
3772 If EXTRA_INSNS, we always do the replacement and generate
3773 any extra insns before OBJECT. If it zero, we do nothing if replacement
3776 Return 1 if we either had nothing to do or if we were able to do the
3777 needed replacement. Return 0 otherwise; we only return zero if
3778 EXTRA_INSNS is zero.
3780 We first try some simple transformations to avoid the creation of extra
3784 instantiate_virtual_regs_1 (rtx *loc, rtx object, int extra_insns)
3789 HOST_WIDE_INT offset = 0;
3795 /* Re-start here to avoid recursion in common cases. */
3802 /* We may have detected and deleted invalid asm statements. */
3803 if (object && INSN_P (object) && INSN_DELETED_P (object))
3806 code = GET_CODE (x);
3808 /* Check for some special cases. */
3826 /* We are allowed to set the virtual registers. This means that
3827 the actual register should receive the source minus the
3828 appropriate offset. This is used, for example, in the handling
3829 of non-local gotos. */
3830 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0)
3832 rtx src = SET_SRC (x);
3834 /* We are setting the register, not using it, so the relevant
3835 offset is the negative of the offset to use were we using
3838 instantiate_virtual_regs_1 (&src, NULL_RTX, 0);
3840 /* The only valid sources here are PLUS or REG. Just do
3841 the simplest possible thing to handle them. */
3842 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS)
3844 instantiate_virtual_regs_lossage (object);
3849 if (GET_CODE (src) != REG)
3850 temp = force_operand (src, NULL_RTX);
3853 temp = force_operand (plus_constant (temp, offset), NULL_RTX);
3857 emit_insn_before (seq, object);
3860 if (! validate_change (object, &SET_SRC (x), temp, 0)
3862 instantiate_virtual_regs_lossage (object);
3867 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns);
3872 /* Handle special case of virtual register plus constant. */
3873 if (CONSTANT_P (XEXP (x, 1)))
3875 rtx old, new_offset;
3877 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3878 if (GET_CODE (XEXP (x, 0)) == PLUS)
3880 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset)))
3882 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object,
3884 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1));
3893 #ifdef POINTERS_EXTEND_UNSIGNED
3894 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3895 we can commute the PLUS and SUBREG because pointers into the
3896 frame are well-behaved. */
3897 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode
3898 && GET_CODE (XEXP (x, 1)) == CONST_INT
3900 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)),
3902 && validate_change (object, loc,
3903 plus_constant (gen_lowpart (ptr_mode,
3906 + INTVAL (XEXP (x, 1))),
3910 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0)
3912 /* We know the second operand is a constant. Unless the
3913 first operand is a REG (which has been already checked),
3914 it needs to be checked. */
3915 if (GET_CODE (XEXP (x, 0)) != REG)
3923 new_offset = plus_constant (XEXP (x, 1), offset);
3925 /* If the new constant is zero, try to replace the sum with just
3927 if (new_offset == const0_rtx
3928 && validate_change (object, loc, new, 0))
3931 /* Next try to replace the register and new offset.
3932 There are two changes to validate here and we can't assume that
3933 in the case of old offset equals new just changing the register
3934 will yield a valid insn. In the interests of a little efficiency,
3935 however, we only call validate change once (we don't queue up the
3936 changes and then call apply_change_group). */
3940 ? ! validate_change (object, &XEXP (x, 0), new, 0)
3941 : (XEXP (x, 0) = new,
3942 ! validate_change (object, &XEXP (x, 1), new_offset, 0)))
3950 /* Otherwise copy the new constant into a register and replace
3951 constant with that register. */
3952 temp = gen_reg_rtx (Pmode);
3954 if (validate_change (object, &XEXP (x, 1), temp, 0))
3955 emit_insn_before (gen_move_insn (temp, new_offset), object);
3958 /* If that didn't work, replace this expression with a
3959 register containing the sum. */
3962 new = gen_rtx_PLUS (Pmode, new, new_offset);
3965 temp = force_operand (new, NULL_RTX);
3969 emit_insn_before (seq, object);
3970 if (! validate_change (object, loc, temp, 0)
3971 && ! validate_replace_rtx (x, temp, object))
3973 instantiate_virtual_regs_lossage (object);
3982 /* Fall through to generic two-operand expression case. */
3988 case DIV: case UDIV:
3989 case MOD: case UMOD:
3990 case AND: case IOR: case XOR:
3991 case ROTATERT: case ROTATE:
3992 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
3994 case GE: case GT: case GEU: case GTU:
3995 case LE: case LT: case LEU: case LTU:
3996 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
3997 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns);
4002 /* Most cases of MEM that convert to valid addresses have already been
4003 handled by our scan of decls. The only special handling we
4004 need here is to make a copy of the rtx to ensure it isn't being
4005 shared if we have to change it to a pseudo.
4007 If the rtx is a simple reference to an address via a virtual register,
4008 it can potentially be shared. In such cases, first try to make it
4009 a valid address, which can also be shared. Otherwise, copy it and
4012 First check for common cases that need no processing. These are
4013 usually due to instantiation already being done on a previous instance
4017 if (CONSTANT_ADDRESS_P (temp)
4018 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4019 || temp == arg_pointer_rtx
4021 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4022 || temp == hard_frame_pointer_rtx
4024 || temp == frame_pointer_rtx)
4027 if (GET_CODE (temp) == PLUS
4028 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4029 && (XEXP (temp, 0) == frame_pointer_rtx
4030 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
4031 || XEXP (temp, 0) == hard_frame_pointer_rtx
4033 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
4034 || XEXP (temp, 0) == arg_pointer_rtx
4039 if (temp == virtual_stack_vars_rtx
4040 || temp == virtual_incoming_args_rtx
4041 || (GET_CODE (temp) == PLUS
4042 && CONSTANT_ADDRESS_P (XEXP (temp, 1))
4043 && (XEXP (temp, 0) == virtual_stack_vars_rtx
4044 || XEXP (temp, 0) == virtual_incoming_args_rtx)))
4046 /* This MEM may be shared. If the substitution can be done without
4047 the need to generate new pseudos, we want to do it in place
4048 so all copies of the shared rtx benefit. The call below will
4049 only make substitutions if the resulting address is still
4052 Note that we cannot pass X as the object in the recursive call
4053 since the insn being processed may not allow all valid
4054 addresses. However, if we were not passed on object, we can
4055 only modify X without copying it if X will have a valid
4058 ??? Also note that this can still lose if OBJECT is an insn that
4059 has less restrictions on an address that some other insn.
4060 In that case, we will modify the shared address. This case
4061 doesn't seem very likely, though. One case where this could
4062 happen is in the case of a USE or CLOBBER reference, but we
4063 take care of that below. */
4065 if (instantiate_virtual_regs_1 (&XEXP (x, 0),
4066 object ? object : x, 0))
4069 /* Otherwise make a copy and process that copy. We copy the entire
4070 RTL expression since it might be a PLUS which could also be
4072 *loc = x = copy_rtx (x);
4075 /* Fall through to generic unary operation case. */
4078 case STRICT_LOW_PART:
4080 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC:
4081 case SIGN_EXTEND: case ZERO_EXTEND:
4082 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
4083 case FLOAT: case FIX:
4084 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
4089 case POPCOUNT: case PARITY:
4090 /* These case either have just one operand or we know that we need not
4091 check the rest of the operands. */
4097 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4098 go ahead and make the invalid one, but do it to a copy. For a REG,
4099 just make the recursive call, since there's no chance of a problem. */
4101 if ((GET_CODE (XEXP (x, 0)) == MEM
4102 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0),
4104 || (GET_CODE (XEXP (x, 0)) == REG
4105 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0)))
4108 XEXP (x, 0) = copy_rtx (XEXP (x, 0));
4113 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4114 in front of this insn and substitute the temporary. */
4115 if ((new = instantiate_new_reg (x, &offset)) != 0)
4117 temp = plus_constant (new, offset);
4118 if (!validate_change (object, loc, temp, 0))
4124 temp = force_operand (temp, NULL_RTX);
4128 emit_insn_before (seq, object);
4129 if (! validate_change (object, loc, temp, 0)
4130 && ! validate_replace_rtx (x, temp, object))
4131 instantiate_virtual_regs_lossage (object);
4138 if (GET_CODE (XEXP (x, 0)) == REG)
4141 else if (GET_CODE (XEXP (x, 0)) == MEM)
4143 /* If we have a (addressof (mem ..)), do any instantiation inside
4144 since we know we'll be making the inside valid when we finally
4145 remove the ADDRESSOF. */
4146 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0);
4155 /* Scan all subexpressions. */
4156 fmt = GET_RTX_FORMAT (code);
4157 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
4160 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns))
4163 else if (*fmt == 'E')
4164 for (j = 0; j < XVECLEN (x, i); j++)
4165 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object,
4172 /* Optimization: assuming this function does not receive nonlocal gotos,
4173 delete the handlers for such, as well as the insns to establish
4174 and disestablish them. */
4177 delete_handlers (void)
4180 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4182 /* Delete the handler by turning off the flag that would
4183 prevent jump_optimize from deleting it.
4184 Also permit deletion of the nonlocal labels themselves
4185 if nothing local refers to them. */
4186 if (GET_CODE (insn) == CODE_LABEL)
4190 LABEL_PRESERVE_P (insn) = 0;
4192 /* Remove it from the nonlocal_label list, to avoid confusing
4194 for (t = nonlocal_labels, last_t = 0; t;
4195 last_t = t, t = TREE_CHAIN (t))
4196 if (DECL_RTL (TREE_VALUE (t)) == insn)
4201 nonlocal_labels = TREE_CHAIN (nonlocal_labels);
4203 TREE_CHAIN (last_t) = TREE_CHAIN (t);
4206 if (GET_CODE (insn) == INSN)
4210 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1))
4211 if (reg_mentioned_p (t, PATTERN (insn)))
4217 || (nonlocal_goto_stack_level != 0
4218 && reg_mentioned_p (nonlocal_goto_stack_level,
4220 delete_related_insns (insn);
4225 /* Return the first insn following those generated by `assign_parms'. */
4228 get_first_nonparm_insn (void)
4231 return NEXT_INSN (last_parm_insn);
4232 return get_insns ();
4235 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4236 This means a type for which function calls must pass an address to the
4237 function or get an address back from the function.
4238 EXP may be a type node or an expression (whose type is tested). */
4241 aggregate_value_p (tree exp, tree fntype)
4243 int i, regno, nregs;
4246 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp);
4249 switch (TREE_CODE (fntype))
4252 fntype = get_callee_fndecl (fntype);
4253 fntype = fntype ? TREE_TYPE (fntype) : 0;
4256 fntype = TREE_TYPE (fntype);
4261 case IDENTIFIER_NODE:
4265 /* We don't expect other rtl types here. */
4269 if (TREE_CODE (type) == VOID_TYPE)
4271 if (targetm.calls.return_in_memory (type, fntype))
4273 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4274 and thus can't be returned in registers. */
4275 if (TREE_ADDRESSABLE (type))
4277 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type))
4279 /* Make sure we have suitable call-clobbered regs to return
4280 the value in; if not, we must return it in memory. */
4281 reg = hard_function_value (type, 0, 0);
4283 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4285 if (GET_CODE (reg) != REG)
4288 regno = REGNO (reg);
4289 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type));
4290 for (i = 0; i < nregs; i++)
4291 if (! call_used_regs[regno + i])
4296 /* Assign RTL expressions to the function's parameters.
4297 This may involve copying them into registers and using
4298 those registers as the RTL for them. */
4301 assign_parms (tree fndecl)
4304 CUMULATIVE_ARGS args_so_far;
4305 /* Total space needed so far for args on the stack,
4306 given as a constant and a tree-expression. */
4307 struct args_size stack_args_size;
4308 tree fntype = TREE_TYPE (fndecl);
4309 tree fnargs = DECL_ARGUMENTS (fndecl), orig_fnargs;
4310 /* This is used for the arg pointer when referring to stack args. */
4311 rtx internal_arg_pointer;
4312 /* This is a dummy PARM_DECL that we used for the function result if
4313 the function returns a structure. */
4314 tree function_result_decl = 0;
4315 int varargs_setup = 0;
4316 int reg_parm_stack_space ATTRIBUTE_UNUSED = 0;
4317 rtx conversion_insns = 0;
4319 /* Nonzero if function takes extra anonymous args.
4320 This means the last named arg must be on the stack
4321 right before the anonymous ones. */
4323 = (TYPE_ARG_TYPES (fntype) != 0
4324 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4325 != void_type_node));
4327 current_function_stdarg = stdarg;
4329 /* If the reg that the virtual arg pointer will be translated into is
4330 not a fixed reg or is the stack pointer, make a copy of the virtual
4331 arg pointer, and address parms via the copy. The frame pointer is
4332 considered fixed even though it is not marked as such.
4334 The second time through, simply use ap to avoid generating rtx. */
4336 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
4337 || ! (fixed_regs[ARG_POINTER_REGNUM]
4338 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)))
4339 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
4341 internal_arg_pointer = virtual_incoming_args_rtx;
4342 current_function_internal_arg_pointer = internal_arg_pointer;
4344 stack_args_size.constant = 0;
4345 stack_args_size.var = 0;
4347 /* If struct value address is treated as the first argument, make it so. */
4348 if (aggregate_value_p (DECL_RESULT (fndecl), fndecl)
4349 && ! current_function_returns_pcc_struct
4350 && targetm.calls.struct_value_rtx (TREE_TYPE (fndecl), 1) == 0)
4352 tree type = build_pointer_type (TREE_TYPE (fntype));
4354 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type);
4356 DECL_ARG_TYPE (function_result_decl) = type;
4357 TREE_CHAIN (function_result_decl) = fnargs;
4358 fnargs = function_result_decl;
4361 orig_fnargs = fnargs;
4363 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
4364 parm_reg_stack_loc = ggc_alloc_cleared (max_parm_reg * sizeof (rtx));
4366 /* If the target wants to split complex arguments into scalars, do so. */
4367 if (targetm.calls.split_complex_arg)
4368 fnargs = split_complex_args (fnargs);
4370 #ifdef REG_PARM_STACK_SPACE
4371 #ifdef MAYBE_REG_PARM_STACK_SPACE
4372 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
4374 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
4378 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4379 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX);
4381 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, fndecl, -1);
4384 /* We haven't yet found an argument that we must push and pretend the
4386 current_function_pretend_args_size = 0;
4388 for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
4392 enum machine_mode promoted_mode, passed_mode;
4393 enum machine_mode nominal_mode, promoted_nominal_mode;
4395 struct locate_and_pad_arg_data locate;
4396 int passed_pointer = 0;
4397 int did_conversion = 0;
4398 tree passed_type = DECL_ARG_TYPE (parm);
4399 tree nominal_type = TREE_TYPE (parm);
4400 int last_named = 0, named_arg;
4403 int pretend_bytes = 0;
4405 /* Set LAST_NAMED if this is last named arg before last
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 = targetm.calls.strict_argument_naming (&args_so_far) ? 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 /* Find mode of arg as it is passed, and mode of arg
4436 as it should be during execution of this function. */
4437 passed_mode = TYPE_MODE (passed_type);
4438 nominal_mode = TYPE_MODE (nominal_type);
4440 /* If the parm's mode is VOID, its value doesn't matter,
4441 and avoid the usual things like emit_move_insn that could crash. */
4442 if (nominal_mode == VOIDmode)
4444 SET_DECL_RTL (parm, const0_rtx);
4445 DECL_INCOMING_RTL (parm) = DECL_RTL (parm);
4449 /* If the parm is to be passed as a transparent union, use the
4450 type of the first field for the tests below. We have already
4451 verified that the modes are the same. */
4452 if (DECL_TRANSPARENT_UNION (parm)
4453 || (TREE_CODE (passed_type) == UNION_TYPE
4454 && TYPE_TRANSPARENT_UNION (passed_type)))
4455 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type));
4457 /* See if this arg was passed by invisible reference. It is if
4458 it is an object whose size depends on the contents of the
4459 object itself or if the machine requires these objects be passed
4462 if (CONTAINS_PLACEHOLDER_P (TYPE_SIZE (passed_type))
4463 || TREE_ADDRESSABLE (passed_type)
4464 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4465 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
4466 passed_type, named_arg)
4470 passed_type = nominal_type = build_pointer_type (passed_type);
4472 passed_mode = nominal_mode = Pmode;
4474 /* See if the frontend wants to pass this by invisible reference. */
4475 else if (passed_type != nominal_type
4476 && POINTER_TYPE_P (passed_type)
4477 && TREE_TYPE (passed_type) == nominal_type)
4479 nominal_type = passed_type;
4481 passed_mode = nominal_mode = Pmode;
4484 promoted_mode = passed_mode;
4486 if (targetm.calls.promote_function_args (TREE_TYPE (fndecl)))
4488 /* Compute the mode in which the arg is actually extended to. */
4489 unsignedp = TREE_UNSIGNED (passed_type);
4490 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1);
4493 /* Let machine desc say which reg (if any) the parm arrives in.
4494 0 means it arrives on the stack. */
4495 #ifdef FUNCTION_INCOMING_ARG
4496 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4497 passed_type, named_arg);
4499 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode,
4500 passed_type, named_arg);
4503 if (entry_parm == 0)
4504 promoted_mode = passed_mode;
4506 /* If this is the last named parameter, do any required setup for
4507 varargs or stdargs. We need to know about the case of this being an
4508 addressable type, in which case we skip the registers it
4509 would have arrived in.
4511 For stdargs, LAST_NAMED will be set for two parameters, the one that
4512 is actually the last named, and the dummy parameter. We only
4513 want to do this action once.
4515 Also, indicate when RTL generation is to be suppressed. */
4516 if (last_named && !varargs_setup)
4518 int varargs_pretend_bytes = 0;
4519 targetm.calls.setup_incoming_varargs (&args_so_far, promoted_mode,
4521 &varargs_pretend_bytes, 0);
4524 /* If the back-end has requested extra stack space, record how
4525 much is needed. Do not change pretend_args_size otherwise
4526 since it may be nonzero from an earlier partial argument. */
4527 if (varargs_pretend_bytes > 0)
4528 current_function_pretend_args_size = varargs_pretend_bytes;
4531 /* Determine parm's home in the stack,
4532 in case it arrives in the stack or we should pretend it did.
4534 Compute the stack position and rtx where the argument arrives
4537 There is one complexity here: If this was a parameter that would
4538 have been passed in registers, but wasn't only because it is
4539 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4540 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4541 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4542 0 as it was the previous time. */
4543 in_regs = entry_parm != 0;
4544 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4547 if (!in_regs && !named_arg)
4550 targetm.calls.pretend_outgoing_varargs_named (&args_so_far);
4553 #ifdef FUNCTION_INCOMING_ARG
4554 in_regs = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode,
4556 pretend_named) != 0;
4558 in_regs = FUNCTION_ARG (args_so_far, promoted_mode,
4560 pretend_named) != 0;
4565 /* If this parameter was passed both in registers and in the stack,
4566 use the copy on the stack. */
4567 if (MUST_PASS_IN_STACK (promoted_mode, passed_type))
4570 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4573 partial = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode,
4574 passed_type, named_arg);
4576 #ifndef MAYBE_REG_PARM_STACK_SPACE
4577 /* The caller might already have allocated stack space
4578 for the register parameters. */
4579 && reg_parm_stack_space == 0
4583 /* Part of this argument is passed in registers and part
4584 is passed on the stack. Ask the prologue code to extend
4585 the stack part so that we can recreate the full value.
4587 PRETEND_BYTES is the size of the registers we need to store.
4588 CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
4589 stack space that the prologue should allocate.
4591 Internally, gcc assumes that the argument pointer is
4592 aligned to STACK_BOUNDARY bits. This is used both for
4593 alignment optimizations (see init_emit) and to locate
4594 arguments that are aligned to more than PARM_BOUNDARY
4595 bits. We must preserve this invariant by rounding
4596 CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to a stack
4598 pretend_bytes = partial * UNITS_PER_WORD;
4599 current_function_pretend_args_size
4600 = CEIL_ROUND (pretend_bytes, STACK_BYTES);
4602 /* If PRETEND_BYTES != CURRENT_FUNCTION_PRETEND_ARGS_SIZE,
4603 insert the padding before the start of the first pretend
4605 stack_args_size.constant
4606 = (current_function_pretend_args_size - pretend_bytes);
4611 memset (&locate, 0, sizeof (locate));
4612 locate_and_pad_parm (promoted_mode, passed_type, in_regs,
4613 entry_parm ? partial : 0, fndecl,
4614 &stack_args_size, &locate);
4618 unsigned int align, boundary;
4620 /* If we're passing this arg using a reg, make its stack home
4621 the aligned stack slot. */
4623 offset_rtx = ARGS_SIZE_RTX (locate.slot_offset);
4625 offset_rtx = ARGS_SIZE_RTX (locate.offset);
4627 if (offset_rtx == const0_rtx)
4628 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer);
4630 stack_parm = gen_rtx_MEM (promoted_mode,
4631 gen_rtx_PLUS (Pmode,
4632 internal_arg_pointer,
4635 set_mem_attributes (stack_parm, parm, 1);
4637 boundary = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type);
4640 /* If we're padding upward, we know that the alignment of the slot
4641 is FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
4642 intentionally forcing upward padding. Otherwise we have to come
4643 up with a guess at the alignment based on OFFSET_RTX. */
4644 if (locate.where_pad == upward || entry_parm)
4646 else if (GET_CODE (offset_rtx) == CONST_INT)
4648 align = INTVAL (offset_rtx) * BITS_PER_UNIT | boundary;
4649 align = align & -align;
4652 set_mem_align (stack_parm, align);
4655 set_reg_attrs_for_parm (entry_parm, stack_parm);
4658 /* If this parm was passed part in regs and part in memory,
4659 pretend it arrived entirely in memory
4660 by pushing the register-part onto the stack.
4662 In the special case of a DImode or DFmode that is split,
4663 we could put it together in a pseudoreg directly,
4664 but for now that's not worth bothering with. */
4668 /* Handle calls that pass values in multiple non-contiguous
4669 locations. The Irix 6 ABI has examples of this. */
4670 if (GET_CODE (entry_parm) == PARALLEL)
4671 emit_group_store (validize_mem (stack_parm), entry_parm,
4673 int_size_in_bytes (TREE_TYPE (parm)));
4676 move_block_from_reg (REGNO (entry_parm), validize_mem (stack_parm),
4679 entry_parm = stack_parm;
4682 /* If we didn't decide this parm came in a register,
4683 by default it came on the stack. */
4684 if (entry_parm == 0)
4685 entry_parm = stack_parm;
4687 /* Record permanently how this parm was passed. */
4688 DECL_INCOMING_RTL (parm) = entry_parm;
4690 /* If there is actually space on the stack for this parm,
4691 count it in stack_args_size; otherwise set stack_parm to 0
4692 to indicate there is no preallocated stack slot for the parm. */
4694 if (entry_parm == stack_parm
4695 || (GET_CODE (entry_parm) == PARALLEL
4696 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
4697 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4698 /* On some machines, even if a parm value arrives in a register
4699 there is still an (uninitialized) stack slot allocated for it.
4701 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4702 whether this parameter already has a stack slot allocated,
4703 because an arg block exists only if current_function_args_size
4704 is larger than some threshold, and we haven't calculated that
4705 yet. So, for now, we just assume that stack slots never exist
4707 || REG_PARM_STACK_SPACE (fndecl) > 0
4711 stack_args_size.constant += pretend_bytes + locate.size.constant;
4712 if (locate.size.var)
4713 ADD_PARM_SIZE (stack_args_size, locate.size.var);
4716 /* No stack slot was pushed for this parm. */
4719 /* Update info on where next arg arrives in registers. */
4721 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode,
4722 passed_type, named_arg);
4724 /* If we can't trust the parm stack slot to be aligned enough
4725 for its ultimate type, don't use that slot after entry.
4726 We'll make another stack slot, if we need one. */
4727 if (STRICT_ALIGNMENT && stack_parm
4728 && GET_MODE_ALIGNMENT (nominal_mode) > MEM_ALIGN (stack_parm))
4731 /* If parm was passed in memory, and we need to convert it on entry,
4732 don't store it back in that same slot. */
4733 if (entry_parm == stack_parm
4734 && nominal_mode != BLKmode && nominal_mode != passed_mode)
4737 /* When an argument is passed in multiple locations, we can't
4738 make use of this information, but we can save some copying if
4739 the whole argument is passed in a single register. */
4740 if (GET_CODE (entry_parm) == PARALLEL
4741 && nominal_mode != BLKmode && passed_mode != BLKmode)
4743 int i, len = XVECLEN (entry_parm, 0);
4745 for (i = 0; i < len; i++)
4746 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX
4747 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG
4748 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0))
4750 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0)
4752 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0);
4753 DECL_INCOMING_RTL (parm) = entry_parm;
4758 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4759 in the mode in which it arrives.
4760 STACK_PARM is an RTX for a stack slot where the parameter can live
4761 during the function (in case we want to put it there).
4762 STACK_PARM is 0 if no stack slot was pushed for it.
4764 Now output code if necessary to convert ENTRY_PARM to
4765 the type in which this function declares it,
4766 and store that result in an appropriate place,
4767 which may be a pseudo reg, may be STACK_PARM,
4768 or may be a local stack slot if STACK_PARM is 0.
4770 Set DECL_RTL to that place. */
4772 if (GET_CODE (entry_parm) == PARALLEL && nominal_mode != BLKmode
4773 && XVECLEN (entry_parm, 0) > 1)
4775 /* Reconstitute objects the size of a register or larger using
4776 register operations instead of the stack. */
4777 rtx parmreg = gen_reg_rtx (nominal_mode);
4779 if (REG_P (parmreg))
4781 unsigned int regno = REGNO (parmreg);
4783 emit_group_store (parmreg, entry_parm, TREE_TYPE (parm),
4784 int_size_in_bytes (TREE_TYPE (parm)));
4785 SET_DECL_RTL (parm, parmreg);
4787 if (regno >= max_parm_reg)
4790 int old_max_parm_reg = max_parm_reg;
4792 /* It's slow to expand this one register at a time,
4793 but it's also rare and we need max_parm_reg to be
4794 precisely correct. */
4795 max_parm_reg = regno + 1;
4796 new = ggc_realloc (parm_reg_stack_loc,
4797 max_parm_reg * sizeof (rtx));
4798 memset (new + old_max_parm_reg, 0,
4799 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
4800 parm_reg_stack_loc = new;
4801 parm_reg_stack_loc[regno] = stack_parm;
4806 if (nominal_mode == BLKmode
4807 #ifdef BLOCK_REG_PADDING
4808 || (locate.where_pad == (BYTES_BIG_ENDIAN ? upward : downward)
4809 && GET_MODE_SIZE (promoted_mode) < UNITS_PER_WORD)
4811 || GET_CODE (entry_parm) == PARALLEL)
4813 /* If a BLKmode arrives in registers, copy it to a stack slot.
4814 Handle calls that pass values in multiple non-contiguous
4815 locations. The Irix 6 ABI has examples of this. */
4816 if (GET_CODE (entry_parm) == REG
4817 || GET_CODE (entry_parm) == PARALLEL)
4819 int size = int_size_in_bytes (TREE_TYPE (parm));
4820 int size_stored = CEIL_ROUND (size, UNITS_PER_WORD);
4823 /* Note that we will be storing an integral number of words.
4824 So we have to be careful to ensure that we allocate an
4825 integral number of words. We do this below in the
4826 assign_stack_local if space was not allocated in the argument
4827 list. If it was, this will not work if PARM_BOUNDARY is not
4828 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4829 if it becomes a problem. Exception is when BLKmode arrives
4830 with arguments not conforming to word_mode. */
4832 if (stack_parm == 0)
4834 stack_parm = assign_stack_local (BLKmode, size_stored, 0);
4835 PUT_MODE (stack_parm, GET_MODE (entry_parm));
4836 set_mem_attributes (stack_parm, parm, 1);
4838 else if (GET_CODE (entry_parm) == PARALLEL)
4840 else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
4843 mem = validize_mem (stack_parm);
4845 /* Handle calls that pass values in multiple non-contiguous
4846 locations. The Irix 6 ABI has examples of this. */
4847 if (GET_CODE (entry_parm) == PARALLEL)
4848 emit_group_store (mem, entry_parm, TREE_TYPE (parm), size);
4853 /* If SIZE is that of a mode no bigger than a word, just use
4854 that mode's store operation. */
4855 else if (size <= UNITS_PER_WORD)
4857 enum machine_mode mode
4858 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
4861 #ifdef BLOCK_REG_PADDING
4862 && (size == UNITS_PER_WORD
4863 || (BLOCK_REG_PADDING (mode, TREE_TYPE (parm), 1)
4864 != (BYTES_BIG_ENDIAN ? upward : downward)))
4868 rtx reg = gen_rtx_REG (mode, REGNO (entry_parm));
4869 emit_move_insn (change_address (mem, mode, 0), reg);
4872 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
4873 machine must be aligned to the left before storing
4874 to memory. Note that the previous test doesn't
4875 handle all cases (e.g. SIZE == 3). */
4876 else if (size != UNITS_PER_WORD
4877 #ifdef BLOCK_REG_PADDING
4878 && (BLOCK_REG_PADDING (mode, TREE_TYPE (parm), 1)
4886 int by = (UNITS_PER_WORD - size) * BITS_PER_UNIT;
4887 rtx reg = gen_rtx_REG (word_mode, REGNO (entry_parm));
4889 x = expand_binop (word_mode, ashl_optab, reg,
4890 GEN_INT (by), 0, 1, OPTAB_WIDEN);
4891 tem = change_address (mem, word_mode, 0);
4892 emit_move_insn (tem, x);
4895 move_block_from_reg (REGNO (entry_parm), mem,
4896 size_stored / UNITS_PER_WORD);
4899 move_block_from_reg (REGNO (entry_parm), mem,
4900 size_stored / UNITS_PER_WORD);
4902 /* If parm is already bound to register pair, don't change
4904 if (! DECL_RTL_SET_P (parm))
4905 SET_DECL_RTL (parm, stack_parm);
4907 else if (! ((! optimize
4908 && ! DECL_REGISTER (parm))
4909 || TREE_SIDE_EFFECTS (parm)
4910 /* If -ffloat-store specified, don't put explicit
4911 float variables into registers. */
4912 || (flag_float_store
4913 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
4914 /* Always assign pseudo to structure return or item passed
4915 by invisible reference. */
4916 || passed_pointer || parm == function_result_decl)
4918 /* Store the parm in a pseudoregister during the function, but we
4919 may need to do it in a wider mode. */
4922 unsigned int regno, regnoi = 0, regnor = 0;
4924 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm));
4926 promoted_nominal_mode
4927 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0);
4929 parmreg = gen_reg_rtx (promoted_nominal_mode);
4930 mark_user_reg (parmreg);
4932 /* If this was an item that we received a pointer to, set DECL_RTL
4936 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)),
4938 set_mem_attributes (x, parm, 1);
4939 SET_DECL_RTL (parm, x);
4943 SET_DECL_RTL (parm, parmreg);
4944 maybe_set_unchanging (DECL_RTL (parm), parm);
4947 /* Copy the value into the register. */
4948 if (nominal_mode != passed_mode
4949 || promoted_nominal_mode != promoted_mode)
4952 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4953 mode, by the caller. We now have to convert it to
4954 NOMINAL_MODE, if different. However, PARMREG may be in
4955 a different mode than NOMINAL_MODE if it is being stored
4958 If ENTRY_PARM is a hard register, it might be in a register
4959 not valid for operating in its mode (e.g., an odd-numbered
4960 register for a DFmode). In that case, moves are the only
4961 thing valid, so we can't do a convert from there. This
4962 occurs when the calling sequence allow such misaligned
4965 In addition, the conversion may involve a call, which could
4966 clobber parameters which haven't been copied to pseudo
4967 registers yet. Therefore, we must first copy the parm to
4968 a pseudo reg here, and save the conversion until after all
4969 parameters have been moved. */
4971 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
4973 emit_move_insn (tempreg, validize_mem (entry_parm));
4975 push_to_sequence (conversion_insns);
4976 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp);
4978 if (GET_CODE (tempreg) == SUBREG
4979 && GET_MODE (tempreg) == nominal_mode
4980 && GET_CODE (SUBREG_REG (tempreg)) == REG
4981 && nominal_mode == passed_mode
4982 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm)
4983 && GET_MODE_SIZE (GET_MODE (tempreg))
4984 < GET_MODE_SIZE (GET_MODE (entry_parm)))
4986 /* The argument is already sign/zero extended, so note it
4988 SUBREG_PROMOTED_VAR_P (tempreg) = 1;
4989 SUBREG_PROMOTED_UNSIGNED_SET (tempreg, unsignedp);
4992 /* TREE_USED gets set erroneously during expand_assignment. */
4993 save_tree_used = TREE_USED (parm);
4994 expand_assignment (parm,
4995 make_tree (nominal_type, tempreg), 0);
4996 TREE_USED (parm) = save_tree_used;
4997 conversion_insns = get_insns ();
5002 emit_move_insn (parmreg, validize_mem (entry_parm));
5004 /* If we were passed a pointer but the actual value
5005 can safely live in a register, put it in one. */
5006 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode
5007 /* If by-reference argument was promoted, demote it. */
5008 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm))
5010 && ! DECL_REGISTER (parm))
5011 || TREE_SIDE_EFFECTS (parm)
5012 /* If -ffloat-store specified, don't put explicit
5013 float variables into registers. */
5014 || (flag_float_store
5015 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))))
5017 /* We can't use nominal_mode, because it will have been set to
5018 Pmode above. We must use the actual mode of the parm. */
5019 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm)));
5020 mark_user_reg (parmreg);
5021 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm)))
5023 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm)));
5024 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm));
5025 push_to_sequence (conversion_insns);
5026 emit_move_insn (tempreg, DECL_RTL (parm));
5028 convert_to_mode (GET_MODE (parmreg),
5031 emit_move_insn (parmreg, DECL_RTL (parm));
5032 conversion_insns = get_insns();
5037 emit_move_insn (parmreg, DECL_RTL (parm));
5038 SET_DECL_RTL (parm, parmreg);
5039 /* STACK_PARM is the pointer, not the parm, and PARMREG is
5043 #ifdef FUNCTION_ARG_CALLEE_COPIES
5044 /* If we are passed an arg by reference and it is our responsibility
5045 to make a copy, do it now.
5046 PASSED_TYPE and PASSED mode now refer to the pointer, not the
5047 original argument, so we must recreate them in the call to
5048 FUNCTION_ARG_CALLEE_COPIES. */
5049 /* ??? Later add code to handle the case that if the argument isn't
5050 modified, don't do the copy. */
5052 else if (passed_pointer
5053 && FUNCTION_ARG_CALLEE_COPIES (args_so_far,
5054 TYPE_MODE (TREE_TYPE (passed_type)),
5055 TREE_TYPE (passed_type),
5057 && ! TREE_ADDRESSABLE (TREE_TYPE (passed_type)))
5060 tree type = TREE_TYPE (passed_type);
5062 /* This sequence may involve a library call perhaps clobbering
5063 registers that haven't been copied to pseudos yet. */
5065 push_to_sequence (conversion_insns);
5067 if (!COMPLETE_TYPE_P (type)
5068 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
5069 /* This is a variable sized object. */
5070 copy = gen_rtx_MEM (BLKmode,
5071 allocate_dynamic_stack_space
5072 (expr_size (parm), NULL_RTX,
5073 TYPE_ALIGN (type)));
5075 copy = assign_stack_temp (TYPE_MODE (type),
5076 int_size_in_bytes (type), 1);
5077 set_mem_attributes (copy, parm, 1);
5079 store_expr (parm, copy, 0);
5080 emit_move_insn (parmreg, XEXP (copy, 0));
5081 conversion_insns = get_insns ();
5085 #endif /* FUNCTION_ARG_CALLEE_COPIES */
5087 /* In any case, record the parm's desired stack location
5088 in case we later discover it must live in the stack.
5090 If it is a COMPLEX value, store the stack location for both
5093 if (GET_CODE (parmreg) == CONCAT)
5094 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1)));
5096 regno = REGNO (parmreg);
5098 if (regno >= max_parm_reg)
5101 int old_max_parm_reg = max_parm_reg;
5103 /* It's slow to expand this one register at a time,
5104 but it's also rare and we need max_parm_reg to be
5105 precisely correct. */
5106 max_parm_reg = regno + 1;
5107 new = ggc_realloc (parm_reg_stack_loc,
5108 max_parm_reg * sizeof (rtx));
5109 memset (new + old_max_parm_reg, 0,
5110 (max_parm_reg - old_max_parm_reg) * sizeof (rtx));
5111 parm_reg_stack_loc = new;
5114 if (GET_CODE (parmreg) == CONCAT)
5116 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0));
5118 regnor = REGNO (gen_realpart (submode, parmreg));
5119 regnoi = REGNO (gen_imagpart (submode, parmreg));
5121 if (stack_parm != 0)
5123 parm_reg_stack_loc[regnor]
5124 = gen_realpart (submode, stack_parm);
5125 parm_reg_stack_loc[regnoi]
5126 = gen_imagpart (submode, stack_parm);
5130 parm_reg_stack_loc[regnor] = 0;
5131 parm_reg_stack_loc[regnoi] = 0;
5135 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
5137 /* Mark the register as eliminable if we did no conversion
5138 and it was copied from memory at a fixed offset,
5139 and the arg pointer was not copied to a pseudo-reg.
5140 If the arg pointer is a pseudo reg or the offset formed
5141 an invalid address, such memory-equivalences
5142 as we make here would screw up life analysis for it. */
5143 if (nominal_mode == passed_mode
5146 && GET_CODE (stack_parm) == MEM
5147 && locate.offset.var == 0
5148 && reg_mentioned_p (virtual_incoming_args_rtx,
5149 XEXP (stack_parm, 0)))
5151 rtx linsn = get_last_insn ();
5154 /* Mark complex types separately. */
5155 if (GET_CODE (parmreg) == CONCAT)
5156 /* Scan backwards for the set of the real and
5158 for (sinsn = linsn; sinsn != 0;
5159 sinsn = prev_nonnote_insn (sinsn))
5161 set = single_set (sinsn);
5163 && SET_DEST (set) == regno_reg_rtx [regnoi])
5165 = gen_rtx_EXPR_LIST (REG_EQUIV,
5166 parm_reg_stack_loc[regnoi],
5169 && SET_DEST (set) == regno_reg_rtx [regnor])
5171 = gen_rtx_EXPR_LIST (REG_EQUIV,
5172 parm_reg_stack_loc[regnor],
5175 else if ((set = single_set (linsn)) != 0
5176 && SET_DEST (set) == parmreg)
5178 = gen_rtx_EXPR_LIST (REG_EQUIV,
5179 stack_parm, REG_NOTES (linsn));
5182 /* For pointer data type, suggest pointer register. */
5183 if (POINTER_TYPE_P (TREE_TYPE (parm)))
5184 mark_reg_pointer (parmreg,
5185 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))));
5187 /* If something wants our address, try to use ADDRESSOF. */
5188 if (TREE_ADDRESSABLE (parm))
5190 /* If we end up putting something into the stack,
5191 fixup_var_refs_insns will need to make a pass over
5192 all the instructions. It looks through the pending
5193 sequences -- but it can't see the ones in the
5194 CONVERSION_INSNS, if they're not on the sequence
5195 stack. So, we go back to that sequence, just so that
5196 the fixups will happen. */
5197 push_to_sequence (conversion_insns);
5198 put_var_into_stack (parm, /*rescan=*/true);
5199 conversion_insns = get_insns ();
5205 /* Value must be stored in the stack slot STACK_PARM
5206 during function execution. */
5208 if (promoted_mode != nominal_mode)
5210 /* Conversion is required. */
5211 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm));
5213 emit_move_insn (tempreg, validize_mem (entry_parm));
5215 push_to_sequence (conversion_insns);
5216 entry_parm = convert_to_mode (nominal_mode, tempreg,
5217 TREE_UNSIGNED (TREE_TYPE (parm)));
5219 /* ??? This may need a big-endian conversion on sparc64. */
5220 stack_parm = adjust_address (stack_parm, nominal_mode, 0);
5222 conversion_insns = get_insns ();
5227 if (entry_parm != stack_parm)
5229 if (stack_parm == 0)
5232 = assign_stack_local (GET_MODE (entry_parm),
5233 GET_MODE_SIZE (GET_MODE (entry_parm)),
5235 set_mem_attributes (stack_parm, parm, 1);
5238 if (promoted_mode != nominal_mode)
5240 push_to_sequence (conversion_insns);
5241 emit_move_insn (validize_mem (stack_parm),
5242 validize_mem (entry_parm));
5243 conversion_insns = get_insns ();
5247 emit_move_insn (validize_mem (stack_parm),
5248 validize_mem (entry_parm));
5251 SET_DECL_RTL (parm, stack_parm);
5255 if (targetm.calls.split_complex_arg && fnargs != orig_fnargs)
5257 for (parm = orig_fnargs; parm; parm = TREE_CHAIN (parm))
5259 if (TREE_CODE (TREE_TYPE (parm)) == COMPLEX_TYPE
5260 && targetm.calls.split_complex_arg (TREE_TYPE (parm)))
5262 rtx tmp, real, imag;
5263 enum machine_mode inner = GET_MODE_INNER (DECL_MODE (parm));
5265 real = DECL_RTL (fnargs);
5266 imag = DECL_RTL (TREE_CHAIN (fnargs));
5267 if (inner != GET_MODE (real))
5269 real = gen_lowpart_SUBREG (inner, real);
5270 imag = gen_lowpart_SUBREG (inner, imag);
5272 tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
5273 SET_DECL_RTL (parm, tmp);
5275 real = DECL_INCOMING_RTL (fnargs);
5276 imag = DECL_INCOMING_RTL (TREE_CHAIN (fnargs));
5277 if (inner != GET_MODE (real))
5279 real = gen_lowpart_SUBREG (inner, real);
5280 imag = gen_lowpart_SUBREG (inner, imag);
5282 tmp = gen_rtx_CONCAT (DECL_MODE (parm), real, imag);
5283 DECL_INCOMING_RTL (parm) = tmp;
5284 fnargs = TREE_CHAIN (fnargs);
5288 SET_DECL_RTL (parm, DECL_RTL (fnargs));
5289 DECL_INCOMING_RTL (parm) = DECL_INCOMING_RTL (fnargs);
5291 fnargs = TREE_CHAIN (fnargs);
5295 /* Output all parameter conversion instructions (possibly including calls)
5296 now that all parameters have been copied out of hard registers. */
5297 emit_insn (conversion_insns);
5299 /* If we are receiving a struct value address as the first argument, set up
5300 the RTL for the function result. As this might require code to convert
5301 the transmitted address to Pmode, we do this here to ensure that possible
5302 preliminary conversions of the address have been emitted already. */
5303 if (function_result_decl)
5305 tree result = DECL_RESULT (fndecl);
5306 rtx addr = DECL_RTL (function_result_decl);
5309 addr = convert_memory_address (Pmode, addr);
5310 x = gen_rtx_MEM (DECL_MODE (result), addr);
5311 set_mem_attributes (x, result, 1);
5312 SET_DECL_RTL (result, x);
5315 last_parm_insn = get_last_insn ();
5317 current_function_args_size = stack_args_size.constant;
5319 /* Adjust function incoming argument size for alignment and
5322 #ifdef REG_PARM_STACK_SPACE
5323 #ifndef MAYBE_REG_PARM_STACK_SPACE
5324 current_function_args_size = MAX (current_function_args_size,
5325 REG_PARM_STACK_SPACE (fndecl));
5329 current_function_args_size
5330 = ((current_function_args_size + STACK_BYTES - 1)
5331 / STACK_BYTES) * STACK_BYTES;
5333 #ifdef ARGS_GROW_DOWNWARD
5334 current_function_arg_offset_rtx
5335 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant)
5336 : expand_expr (size_diffop (stack_args_size.var,
5337 size_int (-stack_args_size.constant)),
5338 NULL_RTX, VOIDmode, 0));
5340 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
5343 /* See how many bytes, if any, of its args a function should try to pop
5346 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl),
5347 current_function_args_size);
5349 /* For stdarg.h function, save info about
5350 regs and stack space used by the named args. */
5352 current_function_args_info = args_so_far;
5354 /* Set the rtx used for the function return value. Put this in its
5355 own variable so any optimizers that need this information don't have
5356 to include tree.h. Do this here so it gets done when an inlined
5357 function gets output. */
5359 current_function_return_rtx
5360 = (DECL_RTL_SET_P (DECL_RESULT (fndecl))
5361 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX);
5363 /* If scalar return value was computed in a pseudo-reg, or was a named
5364 return value that got dumped to the stack, copy that to the hard
5366 if (DECL_RTL_SET_P (DECL_RESULT (fndecl)))
5368 tree decl_result = DECL_RESULT (fndecl);
5369 rtx decl_rtl = DECL_RTL (decl_result);
5371 if (REG_P (decl_rtl)
5372 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
5373 : DECL_REGISTER (decl_result))
5377 #ifdef FUNCTION_OUTGOING_VALUE
5378 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result),
5381 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result),
5384 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1;
5385 /* The delay slot scheduler assumes that current_function_return_rtx
5386 holds the hard register containing the return value, not a
5387 temporary pseudo. */
5388 current_function_return_rtx = real_decl_rtl;
5393 /* If ARGS contains entries with complex types, split the entry into two
5394 entries of the component type. Return a new list of substitutions are
5395 needed, else the old list. */
5398 split_complex_args (tree args)
5402 /* Before allocating memory, check for the common case of no complex. */
5403 for (p = args; p; p = TREE_CHAIN (p))
5405 tree type = TREE_TYPE (p);
5406 if (TREE_CODE (type) == COMPLEX_TYPE
5407 && targetm.calls.split_complex_arg (type))
5413 args = copy_list (args);
5415 for (p = args; p; p = TREE_CHAIN (p))
5417 tree type = TREE_TYPE (p);
5418 if (TREE_CODE (type) == COMPLEX_TYPE
5419 && targetm.calls.split_complex_arg (type))
5422 tree subtype = TREE_TYPE (type);
5424 /* Rewrite the PARM_DECL's type with its component. */
5425 TREE_TYPE (p) = subtype;
5426 DECL_ARG_TYPE (p) = TREE_TYPE (DECL_ARG_TYPE (p));
5427 DECL_MODE (p) = VOIDmode;
5428 DECL_SIZE (p) = NULL;
5429 DECL_SIZE_UNIT (p) = NULL;
5432 /* Build a second synthetic decl. */
5433 decl = build_decl (PARM_DECL, NULL_TREE, subtype);
5434 DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (p);
5435 layout_decl (decl, 0);
5437 /* Splice it in; skip the new decl. */
5438 TREE_CHAIN (decl) = TREE_CHAIN (p);
5439 TREE_CHAIN (p) = decl;
5447 /* Indicate whether REGNO is an incoming argument to the current function
5448 that was promoted to a wider mode. If so, return the RTX for the
5449 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5450 that REGNO is promoted from and whether the promotion was signed or
5454 promoted_input_arg (unsigned int regno, enum machine_mode *pmode, int *punsignedp)
5458 for (arg = DECL_ARGUMENTS (current_function_decl); arg;
5459 arg = TREE_CHAIN (arg))
5460 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG
5461 && REGNO (DECL_INCOMING_RTL (arg)) == regno
5462 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg)))
5464 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg));
5465 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg));
5467 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1);
5468 if (mode == GET_MODE (DECL_INCOMING_RTL (arg))
5469 && mode != DECL_MODE (arg))
5471 *pmode = DECL_MODE (arg);
5472 *punsignedp = unsignedp;
5473 return DECL_INCOMING_RTL (arg);
5481 /* Compute the size and offset from the start of the stacked arguments for a
5482 parm passed in mode PASSED_MODE and with type TYPE.
5484 INITIAL_OFFSET_PTR points to the current offset into the stacked
5487 The starting offset and size for this parm are returned in
5488 LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
5489 nonzero, the offset is that of stack slot, which is returned in
5490 LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
5491 padding required from the initial offset ptr to the stack slot.
5493 IN_REGS is nonzero if the argument will be passed in registers. It will
5494 never be set if REG_PARM_STACK_SPACE is not defined.
5496 FNDECL is the function in which the argument was defined.
5498 There are two types of rounding that are done. The first, controlled by
5499 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5500 list to be aligned to the specific boundary (in bits). This rounding
5501 affects the initial and starting offsets, but not the argument size.
5503 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5504 optionally rounds the size of the parm to PARM_BOUNDARY. The
5505 initial offset is not affected by this rounding, while the size always
5506 is and the starting offset may be. */
5508 /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
5509 INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
5510 callers pass in the total size of args so far as
5511 INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
5514 locate_and_pad_parm (enum machine_mode passed_mode, tree type, int in_regs,
5515 int partial, tree fndecl ATTRIBUTE_UNUSED,
5516 struct args_size *initial_offset_ptr,
5517 struct locate_and_pad_arg_data *locate)
5520 enum direction where_pad;
5522 int reg_parm_stack_space = 0;
5523 int part_size_in_regs;
5525 #ifdef REG_PARM_STACK_SPACE
5526 #ifdef MAYBE_REG_PARM_STACK_SPACE
5527 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE;
5529 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
5532 /* If we have found a stack parm before we reach the end of the
5533 area reserved for registers, skip that area. */
5536 if (reg_parm_stack_space > 0)
5538 if (initial_offset_ptr->var)
5540 initial_offset_ptr->var
5541 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
5542 ssize_int (reg_parm_stack_space));
5543 initial_offset_ptr->constant = 0;
5545 else if (initial_offset_ptr->constant < reg_parm_stack_space)
5546 initial_offset_ptr->constant = reg_parm_stack_space;
5549 #endif /* REG_PARM_STACK_SPACE */
5551 part_size_in_regs = 0;
5552 if (reg_parm_stack_space == 0)
5553 part_size_in_regs = ((partial * UNITS_PER_WORD)
5554 / (PARM_BOUNDARY / BITS_PER_UNIT)
5555 * (PARM_BOUNDARY / BITS_PER_UNIT));
5558 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
5559 where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
5560 boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
5561 locate->where_pad = where_pad;
5563 #ifdef ARGS_GROW_DOWNWARD
5564 locate->slot_offset.constant = -initial_offset_ptr->constant;
5565 if (initial_offset_ptr->var)
5566 locate->slot_offset.var = size_binop (MINUS_EXPR, ssize_int (0),
5567 initial_offset_ptr->var);
5571 if (where_pad != none
5572 && (!host_integerp (sizetree, 1)
5573 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5574 s2 = round_up (s2, PARM_BOUNDARY / BITS_PER_UNIT);
5575 SUB_PARM_SIZE (locate->slot_offset, s2);
5578 locate->slot_offset.constant += part_size_in_regs;
5581 #ifdef REG_PARM_STACK_SPACE
5582 || REG_PARM_STACK_SPACE (fndecl) > 0
5585 pad_to_arg_alignment (&locate->slot_offset, boundary,
5586 &locate->alignment_pad);
5588 locate->size.constant = (-initial_offset_ptr->constant
5589 - locate->slot_offset.constant);
5590 if (initial_offset_ptr->var)
5591 locate->size.var = size_binop (MINUS_EXPR,
5592 size_binop (MINUS_EXPR,
5594 initial_offset_ptr->var),
5595 locate->slot_offset.var);
5597 /* Pad_below needs the pre-rounded size to know how much to pad
5599 locate->offset = locate->slot_offset;
5600 if (where_pad == downward)
5601 pad_below (&locate->offset, passed_mode, sizetree);
5603 #else /* !ARGS_GROW_DOWNWARD */
5605 #ifdef REG_PARM_STACK_SPACE
5606 || REG_PARM_STACK_SPACE (fndecl) > 0
5609 pad_to_arg_alignment (initial_offset_ptr, boundary,
5610 &locate->alignment_pad);
5611 locate->slot_offset = *initial_offset_ptr;
5613 #ifdef PUSH_ROUNDING
5614 if (passed_mode != BLKmode)
5615 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
5618 /* Pad_below needs the pre-rounded size to know how much to pad below
5619 so this must be done before rounding up. */
5620 locate->offset = locate->slot_offset;
5621 if (where_pad == downward)
5622 pad_below (&locate->offset, passed_mode, sizetree);
5624 if (where_pad != none
5625 && (!host_integerp (sizetree, 1)
5626 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY))
5627 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5629 ADD_PARM_SIZE (locate->size, sizetree);
5631 locate->size.constant -= part_size_in_regs;
5632 #endif /* ARGS_GROW_DOWNWARD */
5635 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5636 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5639 pad_to_arg_alignment (struct args_size *offset_ptr, int boundary,
5640 struct args_size *alignment_pad)
5642 tree save_var = NULL_TREE;
5643 HOST_WIDE_INT save_constant = 0;
5644 int boundary_in_bytes = boundary / BITS_PER_UNIT;
5645 HOST_WIDE_INT sp_offset = STACK_POINTER_OFFSET;
5647 #ifdef SPARC_STACK_BOUNDARY_HACK
5648 /* The sparc port has a bug. It sometimes claims a STACK_BOUNDARY
5649 higher than the real alignment of %sp. However, when it does this,
5650 the alignment of %sp+STACK_POINTER_OFFSET will be STACK_BOUNDARY.
5651 This is a temporary hack while the sparc port is fixed. */
5652 if (SPARC_STACK_BOUNDARY_HACK)
5656 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5658 save_var = offset_ptr->var;
5659 save_constant = offset_ptr->constant;
5662 alignment_pad->var = NULL_TREE;
5663 alignment_pad->constant = 0;
5665 if (boundary > BITS_PER_UNIT)
5667 if (offset_ptr->var)
5669 tree sp_offset_tree = ssize_int (sp_offset);
5670 tree offset = size_binop (PLUS_EXPR,
5671 ARGS_SIZE_TREE (*offset_ptr),
5673 #ifdef ARGS_GROW_DOWNWARD
5674 tree rounded = round_down (offset, boundary / BITS_PER_UNIT);
5676 tree rounded = round_up (offset, boundary / BITS_PER_UNIT);
5679 offset_ptr->var = size_binop (MINUS_EXPR, rounded, sp_offset_tree);
5680 /* ARGS_SIZE_TREE includes constant term. */
5681 offset_ptr->constant = 0;
5682 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5683 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var,
5688 offset_ptr->constant = -sp_offset +
5689 #ifdef ARGS_GROW_DOWNWARD
5690 FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
5692 CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes);
5694 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY)
5695 alignment_pad->constant = offset_ptr->constant - save_constant;
5701 pad_below (struct args_size *offset_ptr, enum machine_mode passed_mode, tree sizetree)
5703 if (passed_mode != BLKmode)
5705 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
5706 offset_ptr->constant
5707 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
5708 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
5709 - GET_MODE_SIZE (passed_mode));
5713 if (TREE_CODE (sizetree) != INTEGER_CST
5714 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
5716 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5717 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
5719 ADD_PARM_SIZE (*offset_ptr, s2);
5720 SUB_PARM_SIZE (*offset_ptr, sizetree);
5725 /* Walk the tree of blocks describing the binding levels within a function
5726 and warn about uninitialized variables.
5727 This is done after calling flow_analysis and before global_alloc
5728 clobbers the pseudo-regs to hard regs. */
5731 uninitialized_vars_warning (tree block)
5734 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5736 if (warn_uninitialized
5737 && TREE_CODE (decl) == VAR_DECL
5738 /* These warnings are unreliable for and aggregates
5739 because assigning the fields one by one can fail to convince
5740 flow.c that the entire aggregate was initialized.
5741 Unions are troublesome because members may be shorter. */
5742 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl))
5743 && DECL_RTL_SET_P (decl)
5744 && GET_CODE (DECL_RTL (decl)) == REG
5745 /* Global optimizations can make it difficult to determine if a
5746 particular variable has been initialized. However, a VAR_DECL
5747 with a nonzero DECL_INITIAL had an initializer, so do not
5748 claim it is potentially uninitialized.
5750 When the DECL_INITIAL is NULL call the language hook to tell us
5751 if we want to warn. */
5752 && (DECL_INITIAL (decl) == NULL_TREE || lang_hooks.decl_uninit (decl))
5753 && regno_uninitialized (REGNO (DECL_RTL (decl))))
5754 warning ("%J'%D' might be used uninitialized in this function",
5757 && TREE_CODE (decl) == VAR_DECL
5758 && DECL_RTL_SET_P (decl)
5759 && GET_CODE (DECL_RTL (decl)) == REG
5760 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5761 warning ("%Jvariable '%D' might be clobbered by `longjmp' or `vfork'",
5764 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5765 uninitialized_vars_warning (sub);
5768 /* Do the appropriate part of uninitialized_vars_warning
5769 but for arguments instead of local variables. */
5772 setjmp_args_warning (void)
5775 for (decl = DECL_ARGUMENTS (current_function_decl);
5776 decl; decl = TREE_CHAIN (decl))
5777 if (DECL_RTL (decl) != 0
5778 && GET_CODE (DECL_RTL (decl)) == REG
5779 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
5780 warning ("%Jargument '%D' might be clobbered by `longjmp' or `vfork'",
5784 /* If this function call setjmp, put all vars into the stack
5785 unless they were declared `register'. */
5788 setjmp_protect (tree block)
5791 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
5792 if ((TREE_CODE (decl) == VAR_DECL
5793 || TREE_CODE (decl) == PARM_DECL)
5794 && DECL_RTL (decl) != 0
5795 && (GET_CODE (DECL_RTL (decl)) == REG
5796 || (GET_CODE (DECL_RTL (decl)) == MEM
5797 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5798 /* If this variable came from an inline function, it must be
5799 that its life doesn't overlap the setjmp. If there was a
5800 setjmp in the function, it would already be in memory. We
5801 must exclude such variable because their DECL_RTL might be
5802 set to strange things such as virtual_stack_vars_rtx. */
5803 && ! DECL_FROM_INLINE (decl)
5805 #ifdef NON_SAVING_SETJMP
5806 /* If longjmp doesn't restore the registers,
5807 don't put anything in them. */
5811 ! DECL_REGISTER (decl)))
5812 put_var_into_stack (decl, /*rescan=*/true);
5813 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
5814 setjmp_protect (sub);
5817 /* Like the previous function, but for args instead of local variables. */
5820 setjmp_protect_args (void)
5823 for (decl = DECL_ARGUMENTS (current_function_decl);
5824 decl; decl = TREE_CHAIN (decl))
5825 if ((TREE_CODE (decl) == VAR_DECL
5826 || TREE_CODE (decl) == PARM_DECL)
5827 && DECL_RTL (decl) != 0
5828 && (GET_CODE (DECL_RTL (decl)) == REG
5829 || (GET_CODE (DECL_RTL (decl)) == MEM
5830 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF))
5832 /* If longjmp doesn't restore the registers,
5833 don't put anything in them. */
5834 #ifdef NON_SAVING_SETJMP
5838 ! DECL_REGISTER (decl)))
5839 put_var_into_stack (decl, /*rescan=*/true);
5842 /* Return the context-pointer register corresponding to DECL,
5843 or 0 if it does not need one. */
5846 lookup_static_chain (tree decl)
5848 tree context = decl_function_context (decl);
5852 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl)))
5855 /* We treat inline_function_decl as an alias for the current function
5856 because that is the inline function whose vars, types, etc.
5857 are being merged into the current function.
5858 See expand_inline_function. */
5859 if (context == current_function_decl || context == inline_function_decl)
5860 return virtual_stack_vars_rtx;
5862 for (link = context_display; link; link = TREE_CHAIN (link))
5863 if (TREE_PURPOSE (link) == context)
5864 return RTL_EXPR_RTL (TREE_VALUE (link));
5869 /* Convert a stack slot address ADDR for variable VAR
5870 (from a containing function)
5871 into an address valid in this function (using a static chain). */
5874 fix_lexical_addr (rtx addr, tree var)
5877 HOST_WIDE_INT displacement;
5878 tree context = decl_function_context (var);
5879 struct function *fp;
5882 /* If this is the present function, we need not do anything. */
5883 if (context == current_function_decl || context == inline_function_decl)
5886 fp = find_function_data (context);
5888 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM)
5889 addr = XEXP (XEXP (addr, 0), 0);
5891 /* Decode given address as base reg plus displacement. */
5892 if (GET_CODE (addr) == REG)
5893 basereg = addr, displacement = 0;
5894 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5895 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
5899 /* We accept vars reached via the containing function's
5900 incoming arg pointer and via its stack variables pointer. */
5901 if (basereg == fp->internal_arg_pointer)
5903 /* If reached via arg pointer, get the arg pointer value
5904 out of that function's stack frame.
5906 There are two cases: If a separate ap is needed, allocate a
5907 slot in the outer function for it and dereference it that way.
5908 This is correct even if the real ap is actually a pseudo.
5909 Otherwise, just adjust the offset from the frame pointer to
5912 #ifdef NEED_SEPARATE_AP
5915 addr = get_arg_pointer_save_area (fp);
5916 addr = fix_lexical_addr (XEXP (addr, 0), var);
5917 addr = memory_address (Pmode, addr);
5919 base = gen_rtx_MEM (Pmode, addr);
5920 set_mem_alias_set (base, get_frame_alias_set ());
5921 base = copy_to_reg (base);
5923 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET);
5924 base = lookup_static_chain (var);
5928 else if (basereg == virtual_stack_vars_rtx)
5930 /* This is the same code as lookup_static_chain, duplicated here to
5931 avoid an extra call to decl_function_context. */
5934 for (link = context_display; link; link = TREE_CHAIN (link))
5935 if (TREE_PURPOSE (link) == context)
5937 base = RTL_EXPR_RTL (TREE_VALUE (link));
5945 /* Use same offset, relative to appropriate static chain or argument
5947 return plus_constant (base, displacement);
5950 /* Return the address of the trampoline for entering nested fn FUNCTION.
5951 If necessary, allocate a trampoline (in the stack frame)
5952 and emit rtl to initialize its contents (at entry to this function). */
5955 trampoline_address (tree function)
5960 struct function *fp;
5963 /* Find an existing trampoline and return it. */
5964 for (link = trampoline_list; link; link = TREE_CHAIN (link))
5965 if (TREE_PURPOSE (link) == function)
5967 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0));
5969 for (fp = outer_function_chain; fp; fp = fp->outer)
5970 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link))
5971 if (TREE_PURPOSE (link) == function)
5973 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
5975 return adjust_trampoline_addr (tramp);
5978 /* None exists; we must make one. */
5980 /* Find the `struct function' for the function containing FUNCTION. */
5982 fn_context = decl_function_context (function);
5983 if (fn_context != current_function_decl
5984 && fn_context != inline_function_decl)
5985 fp = find_function_data (fn_context);
5987 /* Allocate run-time space for this trampoline. */
5988 /* If rounding needed, allocate extra space
5989 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5990 #define TRAMPOLINE_REAL_SIZE \
5991 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5992 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0,
5994 /* Record the trampoline for reuse and note it for later initialization
5995 by expand_function_end. */
5998 rtlexp = make_node (RTL_EXPR);
5999 RTL_EXPR_RTL (rtlexp) = tramp;
6000 fp->x_trampoline_list = tree_cons (function, rtlexp,
6001 fp->x_trampoline_list);
6005 /* Make the RTL_EXPR node temporary, not momentary, so that the
6006 trampoline_list doesn't become garbage. */
6007 rtlexp = make_node (RTL_EXPR);
6009 RTL_EXPR_RTL (rtlexp) = tramp;
6010 trampoline_list = tree_cons (function, rtlexp, trampoline_list);
6013 tramp = fix_lexical_addr (XEXP (tramp, 0), function);
6014 return adjust_trampoline_addr (tramp);
6017 /* Given a trampoline address,
6018 round it to multiple of TRAMPOLINE_ALIGNMENT. */
6021 round_trampoline_addr (rtx tramp)
6023 /* Round address up to desired boundary. */
6024 rtx temp = gen_reg_rtx (Pmode);
6025 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1);
6026 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
6028 temp = expand_simple_binop (Pmode, PLUS, tramp, addend,
6029 temp, 0, OPTAB_LIB_WIDEN);
6030 tramp = expand_simple_binop (Pmode, AND, temp, mask,
6031 temp, 0, OPTAB_LIB_WIDEN);
6036 /* Given a trampoline address, round it then apply any
6037 platform-specific adjustments so that the result can be used for a
6041 adjust_trampoline_addr (rtx tramp)
6043 tramp = round_trampoline_addr (tramp);
6044 #ifdef TRAMPOLINE_ADJUST_ADDRESS
6045 TRAMPOLINE_ADJUST_ADDRESS (tramp);
6050 /* Put all this function's BLOCK nodes including those that are chained
6051 onto the first block into a vector, and return it.
6052 Also store in each NOTE for the beginning or end of a block
6053 the index of that block in the vector.
6054 The arguments are BLOCK, the chain of top-level blocks of the function,
6055 and INSNS, the insn chain of the function. */
6058 identify_blocks (void)
6061 tree *block_vector, *last_block_vector;
6063 tree block = DECL_INITIAL (current_function_decl);
6068 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
6069 depth-first order. */
6070 block_vector = get_block_vector (block, &n_blocks);
6071 block_stack = xmalloc (n_blocks * sizeof (tree));
6073 last_block_vector = identify_blocks_1 (get_insns (),
6075 block_vector + n_blocks,
6078 /* If we didn't use all of the subblocks, we've misplaced block notes. */
6079 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
6080 if (0 && last_block_vector != block_vector + n_blocks)
6083 free (block_vector);
6087 /* Subroutine of identify_blocks. Do the block substitution on the
6088 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
6090 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
6091 BLOCK_VECTOR is incremented for each block seen. */
6094 identify_blocks_1 (rtx insns, tree *block_vector, tree *end_block_vector,
6095 tree *orig_block_stack)
6098 tree *block_stack = orig_block_stack;
6100 for (insn = insns; insn; insn = NEXT_INSN (insn))
6102 if (GET_CODE (insn) == NOTE)
6104 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
6108 /* If there are more block notes than BLOCKs, something
6110 if (block_vector == end_block_vector)
6113 b = *block_vector++;
6114 NOTE_BLOCK (insn) = b;
6117 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
6119 /* If there are more NOTE_INSN_BLOCK_ENDs than
6120 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
6121 if (block_stack == orig_block_stack)
6124 NOTE_BLOCK (insn) = *--block_stack;
6127 else if (GET_CODE (insn) == CALL_INSN
6128 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
6130 rtx cp = PATTERN (insn);
6132 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector,
6133 end_block_vector, block_stack);
6135 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector,
6136 end_block_vector, block_stack);
6138 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector,
6139 end_block_vector, block_stack);
6143 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
6144 something is badly wrong. */
6145 if (block_stack != orig_block_stack)
6148 return block_vector;
6151 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
6152 and create duplicate blocks. */
6153 /* ??? Need an option to either create block fragments or to create
6154 abstract origin duplicates of a source block. It really depends
6155 on what optimization has been performed. */
6158 reorder_blocks (void)
6160 tree block = DECL_INITIAL (current_function_decl);
6161 varray_type block_stack;
6163 if (block == NULL_TREE)
6166 VARRAY_TREE_INIT (block_stack, 10, "block_stack");
6168 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
6169 reorder_blocks_0 (block);
6171 /* Prune the old trees away, so that they don't get in the way. */
6172 BLOCK_SUBBLOCKS (block) = NULL_TREE;
6173 BLOCK_CHAIN (block) = NULL_TREE;
6175 /* Recreate the block tree from the note nesting. */
6176 reorder_blocks_1 (get_insns (), block, &block_stack);
6177 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block));
6179 /* Remove deleted blocks from the block fragment chains. */
6180 reorder_fix_fragments (block);
6183 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
6186 reorder_blocks_0 (tree block)
6190 TREE_ASM_WRITTEN (block) = 0;
6191 reorder_blocks_0 (BLOCK_SUBBLOCKS (block));
6192 block = BLOCK_CHAIN (block);
6197 reorder_blocks_1 (rtx insns, tree current_block, varray_type *p_block_stack)
6201 for (insn = insns; insn; insn = NEXT_INSN (insn))
6203 if (GET_CODE (insn) == NOTE)
6205 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
6207 tree block = NOTE_BLOCK (insn);
6209 /* If we have seen this block before, that means it now
6210 spans multiple address regions. Create a new fragment. */
6211 if (TREE_ASM_WRITTEN (block))
6213 tree new_block = copy_node (block);
6216 origin = (BLOCK_FRAGMENT_ORIGIN (block)
6217 ? BLOCK_FRAGMENT_ORIGIN (block)
6219 BLOCK_FRAGMENT_ORIGIN (new_block) = origin;
6220 BLOCK_FRAGMENT_CHAIN (new_block)
6221 = BLOCK_FRAGMENT_CHAIN (origin);
6222 BLOCK_FRAGMENT_CHAIN (origin) = new_block;
6224 NOTE_BLOCK (insn) = new_block;
6228 BLOCK_SUBBLOCKS (block) = 0;
6229 TREE_ASM_WRITTEN (block) = 1;
6230 /* When there's only one block for the entire function,
6231 current_block == block and we mustn't do this, it
6232 will cause infinite recursion. */
6233 if (block != current_block)
6235 BLOCK_SUPERCONTEXT (block) = current_block;
6236 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block);
6237 BLOCK_SUBBLOCKS (current_block) = block;
6238 current_block = block;
6240 VARRAY_PUSH_TREE (*p_block_stack, block);
6242 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
6244 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack);
6245 VARRAY_POP (*p_block_stack);
6246 BLOCK_SUBBLOCKS (current_block)
6247 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block));
6248 current_block = BLOCK_SUPERCONTEXT (current_block);
6251 else if (GET_CODE (insn) == CALL_INSN
6252 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
6254 rtx cp = PATTERN (insn);
6255 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack);
6257 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack);
6259 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack);
6264 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
6265 appears in the block tree, select one of the fragments to become
6266 the new origin block. */
6269 reorder_fix_fragments (tree block)
6273 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block);
6274 tree new_origin = NULL_TREE;
6278 if (! TREE_ASM_WRITTEN (dup_origin))
6280 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin);
6282 /* Find the first of the remaining fragments. There must
6283 be at least one -- the current block. */
6284 while (! TREE_ASM_WRITTEN (new_origin))
6285 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin);
6286 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE;
6289 else if (! dup_origin)
6292 /* Re-root the rest of the fragments to the new origin. In the
6293 case that DUP_ORIGIN was null, that means BLOCK was the origin
6294 of a chain of fragments and we want to remove those fragments
6295 that didn't make it to the output. */
6298 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin);
6303 if (TREE_ASM_WRITTEN (chain))
6305 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin;
6307 pp = &BLOCK_FRAGMENT_CHAIN (chain);
6309 chain = BLOCK_FRAGMENT_CHAIN (chain);
6314 reorder_fix_fragments (BLOCK_SUBBLOCKS (block));
6315 block = BLOCK_CHAIN (block);
6319 /* Reverse the order of elements in the chain T of blocks,
6320 and return the new head of the chain (old last element). */
6323 blocks_nreverse (tree t)
6325 tree prev = 0, decl, next;
6326 for (decl = t; decl; decl = next)
6328 next = BLOCK_CHAIN (decl);
6329 BLOCK_CHAIN (decl) = prev;
6335 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6336 non-NULL, list them all into VECTOR, in a depth-first preorder
6337 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6341 all_blocks (tree block, tree *vector)
6347 TREE_ASM_WRITTEN (block) = 0;
6349 /* Record this block. */
6351 vector[n_blocks] = block;
6355 /* Record the subblocks, and their subblocks... */
6356 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block),
6357 vector ? vector + n_blocks : 0);
6358 block = BLOCK_CHAIN (block);
6364 /* Return a vector containing all the blocks rooted at BLOCK. The
6365 number of elements in the vector is stored in N_BLOCKS_P. The
6366 vector is dynamically allocated; it is the caller's responsibility
6367 to call `free' on the pointer returned. */
6370 get_block_vector (tree block, int *n_blocks_p)
6374 *n_blocks_p = all_blocks (block, NULL);
6375 block_vector = xmalloc (*n_blocks_p * sizeof (tree));
6376 all_blocks (block, block_vector);
6378 return block_vector;
6381 static GTY(()) int next_block_index = 2;
6383 /* Set BLOCK_NUMBER for all the blocks in FN. */
6386 number_blocks (tree fn)
6392 /* For SDB and XCOFF debugging output, we start numbering the blocks
6393 from 1 within each function, rather than keeping a running
6395 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6396 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG)
6397 next_block_index = 1;
6400 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks);
6402 /* The top-level BLOCK isn't numbered at all. */
6403 for (i = 1; i < n_blocks; ++i)
6404 /* We number the blocks from two. */
6405 BLOCK_NUMBER (block_vector[i]) = next_block_index++;
6407 free (block_vector);
6412 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6415 debug_find_var_in_block_tree (tree var, tree block)
6419 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
6423 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
6425 tree ret = debug_find_var_in_block_tree (var, t);
6433 /* Allocate a function structure for FNDECL and set its contents
6437 allocate_struct_function (tree fndecl)
6441 cfun = ggc_alloc_cleared (sizeof (struct function));
6443 max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
6445 cfun->stack_alignment_needed = STACK_BOUNDARY;
6446 cfun->preferred_stack_boundary = STACK_BOUNDARY;
6448 current_function_funcdef_no = funcdef_no++;
6450 cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
6452 init_stmt_for_function ();
6453 init_eh_for_function ();
6455 (*lang_hooks.function.init) (cfun);
6456 if (init_machine_status)
6457 cfun->machine = (*init_machine_status) ();
6462 DECL_SAVED_INSNS (fndecl) = cfun;
6463 cfun->decl = fndecl;
6465 result = DECL_RESULT (fndecl);
6466 if (aggregate_value_p (result, fndecl))
6468 #ifdef PCC_STATIC_STRUCT_RETURN
6469 current_function_returns_pcc_struct = 1;
6471 current_function_returns_struct = 1;
6474 current_function_returns_pointer = POINTER_TYPE_P (TREE_TYPE (result));
6476 current_function_needs_context
6477 = (decl_function_context (current_function_decl) != 0
6478 && ! DECL_NO_STATIC_CHAIN (current_function_decl));
6481 /* Reset cfun, and other non-struct-function variables to defaults as
6482 appropriate for emitting rtl at the start of a function. */
6485 prepare_function_start (tree fndecl)
6487 if (fndecl && DECL_SAVED_INSNS (fndecl))
6488 cfun = DECL_SAVED_INSNS (fndecl);
6490 allocate_struct_function (fndecl);
6492 init_varasm_status (cfun);
6495 cse_not_expected = ! optimize;
6497 /* Caller save not needed yet. */
6498 caller_save_needed = 0;
6500 /* We haven't done register allocation yet. */
6503 /* Indicate that we need to distinguish between the return value of the
6504 present function and the return value of a function being called. */
6505 rtx_equal_function_value_matters = 1;
6507 /* Indicate that we have not instantiated virtual registers yet. */
6508 virtuals_instantiated = 0;
6510 /* Indicate that we want CONCATs now. */
6511 generating_concat_p = 1;
6513 /* Indicate we have no need of a frame pointer yet. */
6514 frame_pointer_needed = 0;
6517 /* Initialize the rtl expansion mechanism so that we can do simple things
6518 like generate sequences. This is used to provide a context during global
6519 initialization of some passes. */
6521 init_dummy_function_start (void)
6523 prepare_function_start (NULL);
6526 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6527 and initialize static variables for generating RTL for the statements
6531 init_function_start (tree subr)
6533 prepare_function_start (subr);
6535 /* Within function body, compute a type's size as soon it is laid out. */
6536 immediate_size_expand++;
6538 /* Prevent ever trying to delete the first instruction of a
6539 function. Also tell final how to output a linenum before the
6540 function prologue. Note linenums could be missing, e.g. when
6541 compiling a Java .class file. */
6542 if (DECL_SOURCE_LINE (subr))
6543 emit_line_note (DECL_SOURCE_LOCATION (subr));
6545 /* Make sure first insn is a note even if we don't want linenums.
6546 This makes sure the first insn will never be deleted.
6547 Also, final expects a note to appear there. */
6548 emit_note (NOTE_INSN_DELETED);
6550 /* Warn if this value is an aggregate type,
6551 regardless of which calling convention we are using for it. */
6552 if (warn_aggregate_return
6553 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
6554 warning ("function returns an aggregate");
6557 /* Make sure all values used by the optimization passes have sane
6560 init_function_for_compilation (void)
6564 /* No prologue/epilogue insns yet. */
6565 VARRAY_GROW (prologue, 0);
6566 VARRAY_GROW (epilogue, 0);
6567 VARRAY_GROW (sibcall_epilogue, 0);
6570 /* Expand a call to __main at the beginning of a possible main function. */
6572 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6573 #undef HAS_INIT_SECTION
6574 #define HAS_INIT_SECTION
6578 expand_main_function (void)
6580 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6581 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN)
6583 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT;
6587 /* Forcibly align the stack. */
6588 #ifdef STACK_GROWS_DOWNWARD
6589 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align),
6590 stack_pointer_rtx, 1, OPTAB_WIDEN);
6592 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx,
6593 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN);
6594 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align),
6595 stack_pointer_rtx, 1, OPTAB_WIDEN);
6597 if (tmp != stack_pointer_rtx)
6598 emit_move_insn (stack_pointer_rtx, tmp);
6600 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6601 tmp = force_reg (Pmode, const0_rtx);
6602 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT);
6606 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp))
6607 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG)
6610 emit_insn_before (seq, tmp);
6616 #ifndef HAS_INIT_SECTION
6617 emit_library_call (init_one_libfunc (NAME__MAIN), LCT_NORMAL, VOIDmode, 0);
6621 /* The PENDING_SIZES represent the sizes of variable-sized types.
6622 Create RTL for the various sizes now (using temporary variables),
6623 so that we can refer to the sizes from the RTL we are generating
6624 for the current function. The PENDING_SIZES are a TREE_LIST. The
6625 TREE_VALUE of each node is a SAVE_EXPR. */
6628 expand_pending_sizes (tree pending_sizes)
6632 /* Evaluate now the sizes of any types declared among the arguments. */
6633 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem))
6635 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0);
6636 /* Flush the queue in case this parameter declaration has
6642 /* Start the RTL for a new function, and set variables used for
6644 SUBR is the FUNCTION_DECL node.
6645 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6646 the function's parameters, which must be run at any return statement. */
6649 expand_function_start (tree subr, int parms_have_cleanups)
6652 rtx last_ptr = NULL_RTX;
6654 /* Make sure volatile mem refs aren't considered
6655 valid operands of arithmetic insns. */
6656 init_recog_no_volatile ();
6658 current_function_instrument_entry_exit
6659 = (flag_instrument_function_entry_exit
6660 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6662 current_function_profile
6664 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr));
6666 current_function_limit_stack
6667 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr));
6669 /* If function gets a static chain arg, store it in the stack frame.
6670 Do this first, so it gets the first stack slot offset. */
6671 if (current_function_needs_context)
6673 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
6675 /* Delay copying static chain if it is not a register to avoid
6676 conflicts with regs used for parameters. */
6677 if (! SMALL_REGISTER_CLASSES
6678 || GET_CODE (static_chain_incoming_rtx) == REG)
6679 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6682 /* If the parameters of this function need cleaning up, get a label
6683 for the beginning of the code which executes those cleanups. This must
6684 be done before doing anything with return_label. */
6685 if (parms_have_cleanups)
6686 cleanup_label = gen_label_rtx ();
6690 /* Make the label for return statements to jump to. Do not special
6691 case machines with special return instructions -- they will be
6692 handled later during jump, ifcvt, or epilogue creation. */
6693 return_label = gen_label_rtx ();
6695 /* Initialize rtx used to return the value. */
6696 /* Do this before assign_parms so that we copy the struct value address
6697 before any library calls that assign parms might generate. */
6699 /* Decide whether to return the value in memory or in a register. */
6700 if (aggregate_value_p (DECL_RESULT (subr), subr))
6702 /* Returning something that won't go in a register. */
6703 rtx value_address = 0;
6705 #ifdef PCC_STATIC_STRUCT_RETURN
6706 if (current_function_returns_pcc_struct)
6708 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
6709 value_address = assemble_static_space (size);
6714 rtx sv = targetm.calls.struct_value_rtx (TREE_TYPE (subr), 1);
6715 /* Expect to be passed the address of a place to store the value.
6716 If it is passed as an argument, assign_parms will take care of
6720 value_address = gen_reg_rtx (Pmode);
6721 emit_move_insn (value_address, sv);
6726 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address);
6727 set_mem_attributes (x, DECL_RESULT (subr), 1);
6728 SET_DECL_RTL (DECL_RESULT (subr), x);
6731 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
6732 /* If return mode is void, this decl rtl should not be used. */
6733 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX);
6736 /* Compute the return values into a pseudo reg, which we will copy
6737 into the true return register after the cleanups are done. */
6739 /* In order to figure out what mode to use for the pseudo, we
6740 figure out what the mode of the eventual return register will
6741 actually be, and use that. */
6743 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)),
6746 /* Structures that are returned in registers are not aggregate_value_p,
6747 so we may see a PARALLEL or a REG. */
6748 if (REG_P (hard_reg))
6749 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg)));
6750 else if (GET_CODE (hard_reg) == PARALLEL)
6751 SET_DECL_RTL (DECL_RESULT (subr), gen_group_rtx (hard_reg));
6755 /* Set DECL_REGISTER flag so that expand_function_end will copy the
6756 result to the real return register(s). */
6757 DECL_REGISTER (DECL_RESULT (subr)) = 1;
6760 /* Initialize rtx for parameters and local variables.
6761 In some cases this requires emitting insns. */
6763 assign_parms (subr);
6765 /* Copy the static chain now if it wasn't a register. The delay is to
6766 avoid conflicts with the parameter passing registers. */
6768 if (SMALL_REGISTER_CLASSES && current_function_needs_context)
6769 if (GET_CODE (static_chain_incoming_rtx) != REG)
6770 emit_move_insn (last_ptr, static_chain_incoming_rtx);
6772 /* The following was moved from init_function_start.
6773 The move is supposed to make sdb output more accurate. */
6774 /* Indicate the beginning of the function body,
6775 as opposed to parm setup. */
6776 emit_note (NOTE_INSN_FUNCTION_BEG);
6778 if (GET_CODE (get_last_insn ()) != NOTE)
6779 emit_note (NOTE_INSN_DELETED);
6780 parm_birth_insn = get_last_insn ();
6782 context_display = 0;
6783 if (current_function_needs_context)
6785 /* Fetch static chain values for containing functions. */
6786 tem = decl_function_context (current_function_decl);
6787 /* Copy the static chain pointer into a pseudo. If we have
6788 small register classes, copy the value from memory if
6789 static_chain_incoming_rtx is a REG. */
6792 /* If the static chain originally came in a register, put it back
6793 there, then move it out in the next insn. The reason for
6794 this peculiar code is to satisfy function integration. */
6795 if (SMALL_REGISTER_CLASSES
6796 && GET_CODE (static_chain_incoming_rtx) == REG)
6797 emit_move_insn (static_chain_incoming_rtx, last_ptr);
6798 last_ptr = copy_to_reg (static_chain_incoming_rtx);
6803 tree rtlexp = make_node (RTL_EXPR);
6805 RTL_EXPR_RTL (rtlexp) = last_ptr;
6806 context_display = tree_cons (tem, rtlexp, context_display);
6807 tem = decl_function_context (tem);
6810 /* Chain through stack frames, assuming pointer to next lexical frame
6811 is found at the place we always store it. */
6812 #ifdef FRAME_GROWS_DOWNWARD
6813 last_ptr = plus_constant (last_ptr,
6814 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode));
6816 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr));
6817 set_mem_alias_set (last_ptr, get_frame_alias_set ());
6818 last_ptr = copy_to_reg (last_ptr);
6820 /* If we are not optimizing, ensure that we know that this
6821 piece of context is live over the entire function. */
6823 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr,
6828 if (current_function_instrument_entry_exit)
6830 rtx fun = DECL_RTL (current_function_decl);
6831 if (GET_CODE (fun) == MEM)
6832 fun = XEXP (fun, 0);
6835 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode,
6837 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
6839 hard_frame_pointer_rtx),
6843 if (current_function_profile)
6846 PROFILE_HOOK (current_function_funcdef_no);
6850 /* After the display initializations is where the tail-recursion label
6851 should go, if we end up needing one. Ensure we have a NOTE here
6852 since some things (like trampolines) get placed before this. */
6853 tail_recursion_reentry = emit_note (NOTE_INSN_DELETED);
6855 /* Evaluate now the sizes of any types declared among the arguments. */
6856 expand_pending_sizes (nreverse (get_pending_sizes ()));
6858 /* Make sure there is a line number after the function entry setup code. */
6859 force_next_line_note ();
6862 /* Undo the effects of init_dummy_function_start. */
6864 expand_dummy_function_end (void)
6866 /* End any sequences that failed to be closed due to syntax errors. */
6867 while (in_sequence_p ())
6870 /* Outside function body, can't compute type's actual size
6871 until next function's body starts. */
6873 free_after_parsing (cfun);
6874 free_after_compilation (cfun);
6878 /* Call DOIT for each hard register used as a return value from
6879 the current function. */
6882 diddle_return_value (void (*doit) (rtx, void *), void *arg)
6884 rtx outgoing = current_function_return_rtx;
6889 if (GET_CODE (outgoing) == REG)
6890 (*doit) (outgoing, arg);
6891 else if (GET_CODE (outgoing) == PARALLEL)
6895 for (i = 0; i < XVECLEN (outgoing, 0); i++)
6897 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
6899 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER)
6906 do_clobber_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
6908 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg));
6912 clobber_return_register (void)
6914 diddle_return_value (do_clobber_return_reg, NULL);
6916 /* In case we do use pseudo to return value, clobber it too. */
6917 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
6919 tree decl_result = DECL_RESULT (current_function_decl);
6920 rtx decl_rtl = DECL_RTL (decl_result);
6921 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER)
6923 do_clobber_return_reg (decl_rtl, NULL);
6929 do_use_return_reg (rtx reg, void *arg ATTRIBUTE_UNUSED)
6931 emit_insn (gen_rtx_USE (VOIDmode, reg));
6935 use_return_register (void)
6937 diddle_return_value (do_use_return_reg, NULL);
6940 /* Possibly warn about unused parameters. */
6942 do_warn_unused_parameter (tree fn)
6946 for (decl = DECL_ARGUMENTS (fn);
6947 decl; decl = TREE_CHAIN (decl))
6948 if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL
6949 && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl))
6950 warning ("%Junused parameter '%D'", decl, decl);
6953 static GTY(()) rtx initial_trampoline;
6955 /* Generate RTL for the end of the current function. */
6958 expand_function_end (void)
6963 finish_expr_for_function ();
6965 /* If arg_pointer_save_area was referenced only from a nested
6966 function, we will not have initialized it yet. Do that now. */
6967 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init)
6968 get_arg_pointer_save_area (cfun);
6970 #ifdef NON_SAVING_SETJMP
6971 /* Don't put any variables in registers if we call setjmp
6972 on a machine that fails to restore the registers. */
6973 if (NON_SAVING_SETJMP && current_function_calls_setjmp)
6975 if (DECL_INITIAL (current_function_decl) != error_mark_node)
6976 setjmp_protect (DECL_INITIAL (current_function_decl));
6978 setjmp_protect_args ();
6982 /* Initialize any trampolines required by this function. */
6983 for (link = trampoline_list; link; link = TREE_CHAIN (link))
6985 tree function = TREE_PURPOSE (link);
6986 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function);
6987 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
6988 #ifdef TRAMPOLINE_TEMPLATE
6993 #ifdef TRAMPOLINE_TEMPLATE
6994 /* First make sure this compilation has a template for
6995 initializing trampolines. */
6996 if (initial_trampoline == 0)
6999 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ());
7000 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
7004 /* Generate insns to initialize the trampoline. */
7006 tramp = round_trampoline_addr (XEXP (tramp, 0));
7007 #ifdef TRAMPOLINE_TEMPLATE
7008 blktramp = replace_equiv_address (initial_trampoline, tramp);
7009 emit_block_move (blktramp, initial_trampoline,
7010 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
7012 trampolines_created = 1;
7013 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context);
7017 /* Put those insns at entry to the containing function (this one). */
7018 emit_insn_before (seq, tail_recursion_reentry);
7021 /* If we are doing stack checking and this function makes calls,
7022 do a stack probe at the start of the function to ensure we have enough
7023 space for another stack frame. */
7024 if (flag_stack_check && ! STACK_CHECK_BUILTIN)
7028 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
7029 if (GET_CODE (insn) == CALL_INSN)
7032 probe_stack_range (STACK_CHECK_PROTECT,
7033 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE));
7036 emit_insn_before (seq, tail_recursion_reentry);
7041 /* Possibly warn about unused parameters.
7042 When frontend does unit-at-a-time, the warning is already
7043 issued at finalization time. */
7044 if (warn_unused_parameter
7045 && !lang_hooks.callgraph.expand_function)
7046 do_warn_unused_parameter (current_function_decl);
7048 /* Delete handlers for nonlocal gotos if nothing uses them. */
7049 if (nonlocal_goto_handler_slots != 0
7050 && ! current_function_has_nonlocal_label)
7053 /* End any sequences that failed to be closed due to syntax errors. */
7054 while (in_sequence_p ())
7057 /* Outside function body, can't compute type's actual size
7058 until next function's body starts. */
7059 immediate_size_expand--;
7061 clear_pending_stack_adjust ();
7062 do_pending_stack_adjust ();
7064 /* ??? This is a kludge. We want to ensure that instructions that
7065 may trap are not moved into the epilogue by scheduling, because
7066 we don't always emit unwind information for the epilogue.
7067 However, not all machine descriptions define a blockage insn, so
7068 emit an ASM_INPUT to act as one. */
7069 if (flag_non_call_exceptions)
7070 emit_insn (gen_rtx_ASM_INPUT (VOIDmode, ""));
7072 /* Mark the end of the function body.
7073 If control reaches this insn, the function can drop through
7074 without returning a value. */
7075 emit_note (NOTE_INSN_FUNCTION_END);
7077 /* Must mark the last line number note in the function, so that the test
7078 coverage code can avoid counting the last line twice. This just tells
7079 the code to ignore the immediately following line note, since there
7080 already exists a copy of this note somewhere above. This line number
7081 note is still needed for debugging though, so we can't delete it. */
7082 if (flag_test_coverage)
7083 emit_note (NOTE_INSN_REPEATED_LINE_NUMBER);
7085 /* Output a linenumber for the end of the function.
7086 SDB depends on this. */
7087 force_next_line_note ();
7088 emit_line_note (input_location);
7090 /* Before the return label (if any), clobber the return
7091 registers so that they are not propagated live to the rest of
7092 the function. This can only happen with functions that drop
7093 through; if there had been a return statement, there would
7094 have either been a return rtx, or a jump to the return label.
7096 We delay actual code generation after the current_function_value_rtx
7098 clobber_after = get_last_insn ();
7100 /* Output the label for the actual return from the function,
7101 if one is expected. This happens either because a function epilogue
7102 is used instead of a return instruction, or because a return was done
7103 with a goto in order to run local cleanups, or because of pcc-style
7104 structure returning. */
7106 emit_label (return_label);
7108 if (current_function_instrument_entry_exit)
7110 rtx fun = DECL_RTL (current_function_decl);
7111 if (GET_CODE (fun) == MEM)
7112 fun = XEXP (fun, 0);
7115 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode,
7117 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS,
7119 hard_frame_pointer_rtx),
7123 #ifdef TARGET_PROFILER_EPILOGUE
7124 if (current_function_profile && TARGET_PROFILER_EPILOGUE)
7126 static rtx mexitcount_libfunc;
7127 static int initialized;
7131 mexitcount_libfunc = init_one_libfunc (".mexitcount");
7134 emit_library_call (mexitcount_libfunc, LCT_NORMAL, VOIDmode, 0);
7138 /* Let except.c know where it should emit the call to unregister
7139 the function context for sjlj exceptions. */
7140 if (flag_exceptions && USING_SJLJ_EXCEPTIONS)
7141 sjlj_emit_function_exit_after (get_last_insn ());
7143 /* If we had calls to alloca, and this machine needs
7144 an accurate stack pointer to exit the function,
7145 insert some code to save and restore the stack pointer. */
7146 if (! EXIT_IGNORE_STACK
7147 && current_function_calls_alloca)
7151 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn);
7152 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX);
7155 /* If scalar return value was computed in a pseudo-reg, or was a named
7156 return value that got dumped to the stack, copy that to the hard
7158 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl)))
7160 tree decl_result = DECL_RESULT (current_function_decl);
7161 rtx decl_rtl = DECL_RTL (decl_result);
7163 if (REG_P (decl_rtl)
7164 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER
7165 : DECL_REGISTER (decl_result))
7167 rtx real_decl_rtl = current_function_return_rtx;
7169 /* This should be set in assign_parms. */
7170 if (! REG_FUNCTION_VALUE_P (real_decl_rtl))
7173 /* If this is a BLKmode structure being returned in registers,
7174 then use the mode computed in expand_return. Note that if
7175 decl_rtl is memory, then its mode may have been changed,
7176 but that current_function_return_rtx has not. */
7177 if (GET_MODE (real_decl_rtl) == BLKmode)
7178 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl));
7180 /* If a named return value dumped decl_return to memory, then
7181 we may need to re-do the PROMOTE_MODE signed/unsigned
7183 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl))
7185 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result));
7187 if (targetm.calls.promote_function_return (TREE_TYPE (current_function_decl)))
7188 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl),
7191 convert_move (real_decl_rtl, decl_rtl, unsignedp);
7193 else if (GET_CODE (real_decl_rtl) == PARALLEL)
7195 /* If expand_function_start has created a PARALLEL for decl_rtl,
7196 move the result to the real return registers. Otherwise, do
7197 a group load from decl_rtl for a named return. */
7198 if (GET_CODE (decl_rtl) == PARALLEL)
7199 emit_group_move (real_decl_rtl, decl_rtl);
7201 emit_group_load (real_decl_rtl, decl_rtl,
7202 TREE_TYPE (decl_result),
7203 int_size_in_bytes (TREE_TYPE (decl_result)));
7206 emit_move_insn (real_decl_rtl, decl_rtl);
7210 /* If returning a structure, arrange to return the address of the value
7211 in a place where debuggers expect to find it.
7213 If returning a structure PCC style,
7214 the caller also depends on this value.
7215 And current_function_returns_pcc_struct is not necessarily set. */
7216 if (current_function_returns_struct
7217 || current_function_returns_pcc_struct)
7220 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
7221 tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
7222 #ifdef FUNCTION_OUTGOING_VALUE
7224 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
7225 current_function_decl);
7228 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl);
7231 /* Mark this as a function return value so integrate will delete the
7232 assignment and USE below when inlining this function. */
7233 REG_FUNCTION_VALUE_P (outgoing) = 1;
7235 /* The address may be ptr_mode and OUTGOING may be Pmode. */
7236 value_address = convert_memory_address (GET_MODE (outgoing),
7239 emit_move_insn (outgoing, value_address);
7241 /* Show return register used to hold result (in this case the address
7243 current_function_return_rtx = outgoing;
7246 /* If this is an implementation of throw, do what's necessary to
7247 communicate between __builtin_eh_return and the epilogue. */
7248 expand_eh_return ();
7250 /* Emit the actual code to clobber return register. */
7255 clobber_return_register ();
7259 after = emit_insn_after (seq, clobber_after);
7261 if (clobber_after != after)
7262 cfun->x_clobber_return_insn = after;
7265 /* Output the label for the naked return from the function, if one is
7266 expected. This is currently used only by __builtin_return. */
7267 if (naked_return_label)
7268 emit_label (naked_return_label);
7270 /* ??? This should no longer be necessary since stupid is no longer with
7271 us, but there are some parts of the compiler (eg reload_combine, and
7272 sh mach_dep_reorg) that still try and compute their own lifetime info
7273 instead of using the general framework. */
7274 use_return_register ();
7276 /* Fix up any gotos that jumped out to the outermost
7277 binding level of the function.
7278 Must follow emitting RETURN_LABEL. */
7280 /* If you have any cleanups to do at this point,
7281 and they need to create temporary variables,
7282 then you will lose. */
7283 expand_fixups (get_insns ());
7287 get_arg_pointer_save_area (struct function *f)
7289 rtx ret = f->x_arg_pointer_save_area;
7293 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f);
7294 f->x_arg_pointer_save_area = ret;
7297 if (f == cfun && ! f->arg_pointer_save_area_init)
7301 /* Save the arg pointer at the beginning of the function. The
7302 generated stack slot may not be a valid memory address, so we
7303 have to check it and fix it if necessary. */
7305 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx);
7309 push_topmost_sequence ();
7310 emit_insn_after (seq, get_insns ());
7311 pop_topmost_sequence ();
7317 /* Extend a vector that records the INSN_UIDs of INSNS
7318 (a list of one or more insns). */
7321 record_insns (rtx insns, varray_type *vecp)
7328 while (tmp != NULL_RTX)
7331 tmp = NEXT_INSN (tmp);
7334 i = VARRAY_SIZE (*vecp);
7335 VARRAY_GROW (*vecp, i + len);
7337 while (tmp != NULL_RTX)
7339 VARRAY_INT (*vecp, i) = INSN_UID (tmp);
7341 tmp = NEXT_INSN (tmp);
7345 /* Set the locator of the insn chain starting at INSN to LOC. */
7347 set_insn_locators (rtx insn, int loc)
7349 while (insn != NULL_RTX)
7352 INSN_LOCATOR (insn) = loc;
7353 insn = NEXT_INSN (insn);
7357 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
7358 be running after reorg, SEQUENCE rtl is possible. */
7361 contains (rtx insn, varray_type vec)
7365 if (GET_CODE (insn) == INSN
7366 && GET_CODE (PATTERN (insn)) == SEQUENCE)
7369 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
7370 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7371 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j))
7377 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j)
7378 if (INSN_UID (insn) == VARRAY_INT (vec, j))
7385 prologue_epilogue_contains (rtx insn)
7387 if (contains (insn, prologue))
7389 if (contains (insn, epilogue))
7395 sibcall_epilogue_contains (rtx insn)
7397 if (sibcall_epilogue)
7398 return contains (insn, sibcall_epilogue);
7403 /* Insert gen_return at the end of block BB. This also means updating
7404 block_for_insn appropriately. */
7407 emit_return_into_block (basic_block bb, rtx line_note)
7409 emit_jump_insn_after (gen_return (), BB_END (bb));
7411 emit_note_copy_after (line_note, PREV_INSN (BB_END (bb)));
7413 #endif /* HAVE_return */
7415 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7417 /* These functions convert the epilogue into a variant that does not modify the
7418 stack pointer. This is used in cases where a function returns an object
7419 whose size is not known until it is computed. The called function leaves the
7420 object on the stack, leaves the stack depressed, and returns a pointer to
7423 What we need to do is track all modifications and references to the stack
7424 pointer, deleting the modifications and changing the references to point to
7425 the location the stack pointer would have pointed to had the modifications
7428 These functions need to be portable so we need to make as few assumptions
7429 about the epilogue as we can. However, the epilogue basically contains
7430 three things: instructions to reset the stack pointer, instructions to
7431 reload registers, possibly including the frame pointer, and an
7432 instruction to return to the caller.
7434 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7435 We also make no attempt to validate the insns we make since if they are
7436 invalid, we probably can't do anything valid. The intent is that these
7437 routines get "smarter" as more and more machines start to use them and
7438 they try operating on different epilogues.
7440 We use the following structure to track what the part of the epilogue that
7441 we've already processed has done. We keep two copies of the SP equivalence,
7442 one for use during the insn we are processing and one for use in the next
7443 insn. The difference is because one part of a PARALLEL may adjust SP
7444 and the other may use it. */
7448 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */
7449 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */
7450 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */
7451 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */
7452 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG
7453 should be set to once we no longer need
7455 rtx const_equiv[FIRST_PSEUDO_REGISTER]; /* Any known constant equivalences
7459 static void handle_epilogue_set (rtx, struct epi_info *);
7460 static void update_epilogue_consts (rtx, rtx, void *);
7461 static void emit_equiv_load (struct epi_info *);
7463 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
7464 no modifications to the stack pointer. Return the new list of insns. */
7467 keep_stack_depressed (rtx insns)
7470 struct epi_info info;
7473 /* If the epilogue is just a single instruction, it must be OK as is. */
7474 if (NEXT_INSN (insns) == NULL_RTX)
7477 /* Otherwise, start a sequence, initialize the information we have, and
7478 process all the insns we were given. */
7481 info.sp_equiv_reg = stack_pointer_rtx;
7483 info.equiv_reg_src = 0;
7485 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
7486 info.const_equiv[j] = 0;
7490 while (insn != NULL_RTX)
7492 next = NEXT_INSN (insn);
7501 /* If this insn references the register that SP is equivalent to and
7502 we have a pending load to that register, we must force out the load
7503 first and then indicate we no longer know what SP's equivalent is. */
7504 if (info.equiv_reg_src != 0
7505 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn)))
7507 emit_equiv_load (&info);
7508 info.sp_equiv_reg = 0;
7511 info.new_sp_equiv_reg = info.sp_equiv_reg;
7512 info.new_sp_offset = info.sp_offset;
7514 /* If this is a (RETURN) and the return address is on the stack,
7515 update the address and change to an indirect jump. */
7516 if (GET_CODE (PATTERN (insn)) == RETURN
7517 || (GET_CODE (PATTERN (insn)) == PARALLEL
7518 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN))
7520 rtx retaddr = INCOMING_RETURN_ADDR_RTX;
7522 HOST_WIDE_INT offset = 0;
7523 rtx jump_insn, jump_set;
7525 /* If the return address is in a register, we can emit the insn
7526 unchanged. Otherwise, it must be a MEM and we see what the
7527 base register and offset are. In any case, we have to emit any
7528 pending load to the equivalent reg of SP, if any. */
7529 if (GET_CODE (retaddr) == REG)
7531 emit_equiv_load (&info);
7536 else if (GET_CODE (retaddr) == MEM
7537 && GET_CODE (XEXP (retaddr, 0)) == REG)
7538 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0;
7539 else if (GET_CODE (retaddr) == MEM
7540 && GET_CODE (XEXP (retaddr, 0)) == PLUS
7541 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG
7542 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT)
7544 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0)));
7545 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1));
7550 /* If the base of the location containing the return pointer
7551 is SP, we must update it with the replacement address. Otherwise,
7552 just build the necessary MEM. */
7553 retaddr = plus_constant (base, offset);
7554 if (base == stack_pointer_rtx)
7555 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx,
7556 plus_constant (info.sp_equiv_reg,
7559 retaddr = gen_rtx_MEM (Pmode, retaddr);
7561 /* If there is a pending load to the equivalent register for SP
7562 and we reference that register, we must load our address into
7563 a scratch register and then do that load. */
7564 if (info.equiv_reg_src
7565 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr))
7570 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
7571 if (HARD_REGNO_MODE_OK (regno, Pmode)
7572 && !fixed_regs[regno]
7573 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno)
7574 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start,
7576 && !refers_to_regno_p (regno,
7577 regno + HARD_REGNO_NREGS (regno,
7579 info.equiv_reg_src, NULL)
7580 && info.const_equiv[regno] == 0)
7583 if (regno == FIRST_PSEUDO_REGISTER)
7586 reg = gen_rtx_REG (Pmode, regno);
7587 emit_move_insn (reg, retaddr);
7591 emit_equiv_load (&info);
7592 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr));
7594 /* Show the SET in the above insn is a RETURN. */
7595 jump_set = single_set (jump_insn);
7599 SET_IS_RETURN_P (jump_set) = 1;
7602 /* If SP is not mentioned in the pattern and its equivalent register, if
7603 any, is not modified, just emit it. Otherwise, if neither is set,
7604 replace the reference to SP and emit the insn. If none of those are
7605 true, handle each SET individually. */
7606 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))
7607 && (info.sp_equiv_reg == stack_pointer_rtx
7608 || !reg_set_p (info.sp_equiv_reg, insn)))
7610 else if (! reg_set_p (stack_pointer_rtx, insn)
7611 && (info.sp_equiv_reg == stack_pointer_rtx
7612 || !reg_set_p (info.sp_equiv_reg, insn)))
7614 if (! validate_replace_rtx (stack_pointer_rtx,
7615 plus_constant (info.sp_equiv_reg,
7622 else if (GET_CODE (PATTERN (insn)) == SET)
7623 handle_epilogue_set (PATTERN (insn), &info);
7624 else if (GET_CODE (PATTERN (insn)) == PARALLEL)
7626 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++)
7627 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
7628 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info);
7633 info.sp_equiv_reg = info.new_sp_equiv_reg;
7634 info.sp_offset = info.new_sp_offset;
7636 /* Now update any constants this insn sets. */
7637 note_stores (PATTERN (insn), update_epilogue_consts, &info);
7641 insns = get_insns ();
7646 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7647 structure that contains information about what we've seen so far. We
7648 process this SET by either updating that data or by emitting one or
7652 handle_epilogue_set (rtx set, struct epi_info *p)
7654 /* First handle the case where we are setting SP. Record what it is being
7655 set from. If unknown, abort. */
7656 if (reg_set_p (stack_pointer_rtx, set))
7658 if (SET_DEST (set) != stack_pointer_rtx)
7661 if (GET_CODE (SET_SRC (set)) == PLUS)
7663 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0);
7664 if (GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT)
7665 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1));
7666 else if (GET_CODE (XEXP (SET_SRC (set), 1)) == REG
7667 && REGNO (XEXP (SET_SRC (set), 1)) < FIRST_PSEUDO_REGISTER
7668 && p->const_equiv[REGNO (XEXP (SET_SRC (set), 1))] != 0)
7670 = INTVAL (p->const_equiv[REGNO (XEXP (SET_SRC (set), 1))]);
7675 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0;
7677 /* If we are adjusting SP, we adjust from the old data. */
7678 if (p->new_sp_equiv_reg == stack_pointer_rtx)
7680 p->new_sp_equiv_reg = p->sp_equiv_reg;
7681 p->new_sp_offset += p->sp_offset;
7684 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG)
7690 /* Next handle the case where we are setting SP's equivalent register.
7691 If we already have a value to set it to, abort. We could update, but
7692 there seems little point in handling that case. Note that we have
7693 to allow for the case where we are setting the register set in
7694 the previous part of a PARALLEL inside a single insn. But use the
7695 old offset for any updates within this insn. We must allow for the case
7696 where the register is being set in a different (usually wider) mode than
7698 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set))
7700 if (p->equiv_reg_src != 0
7701 || GET_CODE (p->new_sp_equiv_reg) != REG
7702 || GET_CODE (SET_DEST (set)) != REG
7703 || GET_MODE_BITSIZE (GET_MODE (SET_DEST (set))) > BITS_PER_WORD
7704 || REGNO (p->new_sp_equiv_reg) != REGNO (SET_DEST (set)))
7708 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7709 plus_constant (p->sp_equiv_reg,
7713 /* Otherwise, replace any references to SP in the insn to its new value
7714 and emit the insn. */
7717 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx,
7718 plus_constant (p->sp_equiv_reg,
7720 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx,
7721 plus_constant (p->sp_equiv_reg,
7727 /* Update the tracking information for registers set to constants. */
7730 update_epilogue_consts (rtx dest, rtx x, void *data)
7732 struct epi_info *p = (struct epi_info *) data;
7734 if (GET_CODE (dest) != REG || REGNO (dest) >= FIRST_PSEUDO_REGISTER)
7736 else if (GET_CODE (x) == CLOBBER || ! rtx_equal_p (dest, SET_DEST (x))
7737 || GET_CODE (SET_SRC (x)) != CONST_INT)
7738 p->const_equiv[REGNO (dest)] = 0;
7740 p->const_equiv[REGNO (dest)] = SET_SRC (x);
7743 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7746 emit_equiv_load (struct epi_info *p)
7748 if (p->equiv_reg_src != 0)
7750 rtx dest = p->sp_equiv_reg;
7752 if (GET_MODE (p->equiv_reg_src) != GET_MODE (dest))
7753 dest = gen_rtx_REG (GET_MODE (p->equiv_reg_src),
7754 REGNO (p->sp_equiv_reg));
7756 emit_move_insn (dest, p->equiv_reg_src);
7757 p->equiv_reg_src = 0;
7762 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7763 this into place with notes indicating where the prologue ends and where
7764 the epilogue begins. Update the basic block information when possible. */
7767 thread_prologue_and_epilogue_insns (rtx f ATTRIBUTE_UNUSED)
7771 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7774 #ifdef HAVE_prologue
7775 rtx prologue_end = NULL_RTX;
7777 #if defined (HAVE_epilogue) || defined(HAVE_return)
7778 rtx epilogue_end = NULL_RTX;
7781 #ifdef HAVE_prologue
7785 seq = gen_prologue ();
7788 /* Retain a map of the prologue insns. */
7789 record_insns (seq, &prologue);
7790 prologue_end = emit_note (NOTE_INSN_PROLOGUE_END);
7794 set_insn_locators (seq, prologue_locator);
7796 /* Can't deal with multiple successors of the entry block
7797 at the moment. Function should always have at least one
7799 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next)
7802 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
7807 /* If the exit block has no non-fake predecessors, we don't need
7809 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7810 if ((e->flags & EDGE_FAKE) == 0)
7816 if (optimize && HAVE_return)
7818 /* If we're allowed to generate a simple return instruction,
7819 then by definition we don't need a full epilogue. Examine
7820 the block that falls through to EXIT. If it does not
7821 contain any code, examine its predecessors and try to
7822 emit (conditional) return instructions. */
7828 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7829 if (e->flags & EDGE_FALLTHRU)
7835 /* Verify that there are no active instructions in the last block. */
7836 label = BB_END (last);
7837 while (label && GET_CODE (label) != CODE_LABEL)
7839 if (active_insn_p (label))
7841 label = PREV_INSN (label);
7844 if (BB_HEAD (last) == label && GET_CODE (label) == CODE_LABEL)
7846 rtx epilogue_line_note = NULL_RTX;
7848 /* Locate the line number associated with the closing brace,
7849 if we can find one. */
7850 for (seq = get_last_insn ();
7851 seq && ! active_insn_p (seq);
7852 seq = PREV_INSN (seq))
7853 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0)
7855 epilogue_line_note = seq;
7859 for (e = last->pred; e; e = e_next)
7861 basic_block bb = e->src;
7864 e_next = e->pred_next;
7865 if (bb == ENTRY_BLOCK_PTR)
7869 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label)
7872 /* If we have an unconditional jump, we can replace that
7873 with a simple return instruction. */
7874 if (simplejump_p (jump))
7876 emit_return_into_block (bb, epilogue_line_note);
7880 /* If we have a conditional jump, we can try to replace
7881 that with a conditional return instruction. */
7882 else if (condjump_p (jump))
7884 if (! redirect_jump (jump, 0, 0))
7887 /* If this block has only one successor, it both jumps
7888 and falls through to the fallthru block, so we can't
7890 if (bb->succ->succ_next == NULL)
7896 /* Fix up the CFG for the successful change we just made. */
7897 redirect_edge_succ (e, EXIT_BLOCK_PTR);
7900 /* Emit a return insn for the exit fallthru block. Whether
7901 this is still reachable will be determined later. */
7903 emit_barrier_after (BB_END (last));
7904 emit_return_into_block (last, epilogue_line_note);
7905 epilogue_end = BB_END (last);
7906 last->succ->flags &= ~EDGE_FALLTHRU;
7911 #ifdef HAVE_epilogue
7914 /* Find the edge that falls through to EXIT. Other edges may exist
7915 due to RETURN instructions, but those don't need epilogues.
7916 There really shouldn't be a mixture -- either all should have
7917 been converted or none, however... */
7919 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7920 if (e->flags & EDGE_FALLTHRU)
7926 epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG);
7928 seq = gen_epilogue ();
7930 #ifdef INCOMING_RETURN_ADDR_RTX
7931 /* If this function returns with the stack depressed and we can support
7932 it, massage the epilogue to actually do that. */
7933 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE
7934 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl)))
7935 seq = keep_stack_depressed (seq);
7938 emit_jump_insn (seq);
7940 /* Retain a map of the epilogue insns. */
7941 record_insns (seq, &epilogue);
7942 set_insn_locators (seq, epilogue_locator);
7947 insert_insn_on_edge (seq, e);
7954 commit_edge_insertions ();
7956 #ifdef HAVE_sibcall_epilogue
7957 /* Emit sibling epilogues before any sibling call sites. */
7958 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
7960 basic_block bb = e->src;
7961 rtx insn = BB_END (bb);
7965 if (GET_CODE (insn) != CALL_INSN
7966 || ! SIBLING_CALL_P (insn))
7970 emit_insn (gen_sibcall_epilogue ());
7974 /* Retain a map of the epilogue insns. Used in life analysis to
7975 avoid getting rid of sibcall epilogue insns. Do this before we
7976 actually emit the sequence. */
7977 record_insns (seq, &sibcall_epilogue);
7978 set_insn_locators (seq, epilogue_locator);
7980 i = PREV_INSN (insn);
7981 newinsn = emit_insn_before (seq, insn);
7985 #ifdef HAVE_prologue
7986 /* This is probably all useless now that we use locators. */
7991 /* GDB handles `break f' by setting a breakpoint on the first
7992 line note after the prologue. Which means (1) that if
7993 there are line number notes before where we inserted the
7994 prologue we should move them, and (2) we should generate a
7995 note before the end of the first basic block, if there isn't
7998 ??? This behavior is completely broken when dealing with
7999 multiple entry functions. We simply place the note always
8000 into first basic block and let alternate entry points
8004 for (insn = prologue_end; insn; insn = prev)
8006 prev = PREV_INSN (insn);
8007 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
8009 /* Note that we cannot reorder the first insn in the
8010 chain, since rest_of_compilation relies on that
8011 remaining constant. */
8014 reorder_insns (insn, insn, prologue_end);
8018 /* Find the last line number note in the first block. */
8019 for (insn = BB_END (ENTRY_BLOCK_PTR->next_bb);
8020 insn != prologue_end && insn;
8021 insn = PREV_INSN (insn))
8022 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
8025 /* If we didn't find one, make a copy of the first line number
8029 for (insn = next_active_insn (prologue_end);
8031 insn = PREV_INSN (insn))
8032 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
8034 emit_note_copy_after (insn, prologue_end);
8040 #ifdef HAVE_epilogue
8045 /* Similarly, move any line notes that appear after the epilogue.
8046 There is no need, however, to be quite so anal about the existence
8047 of such a note. Also move the NOTE_INSN_FUNCTION_END and (possibly)
8048 NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
8050 for (insn = epilogue_end; insn; insn = next)
8052 next = NEXT_INSN (insn);
8053 if (GET_CODE (insn) == NOTE
8054 && (NOTE_LINE_NUMBER (insn) > 0
8055 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG
8056 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_END))
8057 reorder_insns (insn, insn, PREV_INSN (epilogue_end));
8063 /* Reposition the prologue-end and epilogue-begin notes after instruction
8064 scheduling and delayed branch scheduling. */
8067 reposition_prologue_and_epilogue_notes (rtx f ATTRIBUTE_UNUSED)
8069 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
8070 rtx insn, last, note;
8073 if ((len = VARRAY_SIZE (prologue)) > 0)
8077 /* Scan from the beginning until we reach the last prologue insn.
8078 We apparently can't depend on basic_block_{head,end} after
8080 for (insn = f; insn; insn = NEXT_INSN (insn))
8082 if (GET_CODE (insn) == NOTE)
8084 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END)
8087 else if (contains (insn, prologue))
8097 /* Find the prologue-end note if we haven't already, and
8098 move it to just after the last prologue insn. */
8101 for (note = last; (note = NEXT_INSN (note));)
8102 if (GET_CODE (note) == NOTE
8103 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END)
8107 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
8108 if (GET_CODE (last) == CODE_LABEL)
8109 last = NEXT_INSN (last);
8110 reorder_insns (note, note, last);
8114 if ((len = VARRAY_SIZE (epilogue)) > 0)
8118 /* Scan from the end until we reach the first epilogue insn.
8119 We apparently can't depend on basic_block_{head,end} after
8121 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
8123 if (GET_CODE (insn) == NOTE)
8125 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
8128 else if (contains (insn, epilogue))
8138 /* Find the epilogue-begin note if we haven't already, and
8139 move it to just before the first epilogue insn. */
8142 for (note = insn; (note = PREV_INSN (note));)
8143 if (GET_CODE (note) == NOTE
8144 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG)
8148 if (PREV_INSN (last) != note)
8149 reorder_insns (note, note, PREV_INSN (last));
8152 #endif /* HAVE_prologue or HAVE_epilogue */
8155 /* Called once, at initialization, to initialize function.c. */
8158 init_function_once (void)
8160 VARRAY_INT_INIT (prologue, 0, "prologue");
8161 VARRAY_INT_INIT (epilogue, 0, "epilogue");
8162 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");
8165 /* Returns the name of the current function. */
8167 current_function_name (void)
8169 return (*lang_hooks.decl_printable_name) (cfun->decl, 2);
8172 #include "gt-function.h"