1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file handles the generation of rtl code from tree structure
23 at the level of the function as a whole.
24 It creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 `expand_function_start' is called at the beginning of a function,
28 before the function body is parsed, and `expand_function_end' is
29 called after parsing the body.
31 Call `assign_stack_local' to allocate a stack slot for a local variable.
32 This is usually done during the RTL generation for the function body,
33 but it can also be done in the reload pass when a pseudo-register does
34 not get a hard register.
36 Call `put_var_into_stack' when you learn, belatedly, that a variable
37 previously given a pseudo-register must in fact go in the stack.
38 This function changes the DECL_RTL to be a stack slot instead of a reg
39 then scans all the RTL instructions so far generated to correct them. */
51 #include "hard-reg-set.h"
52 #include "insn-config.h"
55 #include "basic-block.h"
60 #include "integrate.h"
61 #include "langhooks.h"
63 #ifndef TRAMPOLINE_ALIGNMENT
64 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
67 #ifndef LOCAL_ALIGNMENT
68 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
71 /* Some systems use __main in a way incompatible with its use in gcc, in these
72 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
73 give the same symbol without quotes for an alternative entry point. You
74 must define both, or neither. */
76 #define NAME__MAIN "__main"
79 /* Round a value to the lowest integer less than it that is a multiple of
80 the required alignment. Avoid using division in case the value is
81 negative. Assume the alignment is a power of two. */
82 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
84 /* Similar, but round to the next highest integer that meets the
86 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
88 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
89 during rtl generation. If they are different register numbers, this is
90 always true. It may also be true if
91 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
92 generation. See fix_lexical_addr for details. */
94 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
95 #define NEED_SEPARATE_AP
98 /* Nonzero if function being compiled doesn't contain any calls
99 (ignoring the prologue and epilogue). This is set prior to
100 local register allocation and is valid for the remaining
102 int current_function_is_leaf
;
104 /* Nonzero if function being compiled doesn't contain any instructions
105 that can throw an exception. This is set prior to final. */
107 int current_function_nothrow
;
109 /* Nonzero if function being compiled doesn't modify the stack pointer
110 (ignoring the prologue and epilogue). This is only valid after
111 life_analysis has run. */
112 int current_function_sp_is_unchanging
;
114 /* Nonzero if the function being compiled is a leaf function which only
115 uses leaf registers. This is valid after reload (specifically after
116 sched2) and is useful only if the port defines LEAF_REGISTERS. */
117 int current_function_uses_only_leaf_regs
;
119 /* Nonzero once virtual register instantiation has been done.
120 assign_stack_local uses frame_pointer_rtx when this is nonzero.
121 calls.c:emit_library_call_value_1 uses it to set up
122 post-instantiation libcalls. */
123 int virtuals_instantiated
;
125 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
126 static int funcdef_no
;
128 /* These variables hold pointers to functions to create and destroy
129 target specific, per-function data structures. */
130 struct machine_function
* (*init_machine_status
) PARAMS ((void));
132 /* The FUNCTION_DECL for an inline function currently being expanded. */
133 tree inline_function_decl
;
135 /* The currently compiled function. */
136 struct function
*cfun
= 0;
138 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
139 static GTY(()) varray_type prologue
;
140 static GTY(()) varray_type epilogue
;
142 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
144 static GTY(()) varray_type sibcall_epilogue
;
146 /* In order to evaluate some expressions, such as function calls returning
147 structures in memory, we need to temporarily allocate stack locations.
148 We record each allocated temporary in the following structure.
150 Associated with each temporary slot is a nesting level. When we pop up
151 one level, all temporaries associated with the previous level are freed.
152 Normally, all temporaries are freed after the execution of the statement
153 in which they were created. However, if we are inside a ({...}) grouping,
154 the result may be in a temporary and hence must be preserved. If the
155 result could be in a temporary, we preserve it if we can determine which
156 one it is in. If we cannot determine which temporary may contain the
157 result, all temporaries are preserved. A temporary is preserved by
158 pretending it was allocated at the previous nesting level.
160 Automatic variables are also assigned temporary slots, at the nesting
161 level where they are defined. They are marked a "kept" so that
162 free_temp_slots will not free them. */
164 struct temp_slot
GTY(())
166 /* Points to next temporary slot. */
167 struct temp_slot
*next
;
168 /* The rtx to used to reference the slot. */
170 /* The rtx used to represent the address if not the address of the
171 slot above. May be an EXPR_LIST if multiple addresses exist. */
173 /* The alignment (in bits) of the slot. */
175 /* The size, in units, of the slot. */
177 /* The type of the object in the slot, or zero if it doesn't correspond
178 to a type. We use this to determine whether a slot can be reused.
179 It can be reused if objects of the type of the new slot will always
180 conflict with objects of the type of the old slot. */
182 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
184 /* Non-zero if this temporary is currently in use. */
186 /* Non-zero if this temporary has its address taken. */
188 /* Nesting level at which this slot is being used. */
190 /* Non-zero if this should survive a call to free_temp_slots. */
192 /* The offset of the slot from the frame_pointer, including extra space
193 for alignment. This info is for combine_temp_slots. */
194 HOST_WIDE_INT base_offset
;
195 /* The size of the slot, including extra space for alignment. This
196 info is for combine_temp_slots. */
197 HOST_WIDE_INT full_size
;
200 /* This structure is used to record MEMs or pseudos used to replace VAR, any
201 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
202 maintain this list in case two operands of an insn were required to match;
203 in that case we must ensure we use the same replacement. */
205 struct fixup_replacement
GTY(())
209 struct fixup_replacement
*next
;
212 struct insns_for_mem_entry
216 /* These are the INSNs which reference the MEM. */
220 /* Forward declarations. */
222 static rtx assign_stack_local_1
PARAMS ((enum machine_mode
, HOST_WIDE_INT
,
223 int, struct function
*));
224 static struct temp_slot
*find_temp_slot_from_address
PARAMS ((rtx
));
225 static void put_reg_into_stack
PARAMS ((struct function
*, rtx
, tree
,
226 enum machine_mode
, enum machine_mode
,
227 int, unsigned int, int,
229 static void schedule_fixup_var_refs
PARAMS ((struct function
*, rtx
, tree
,
232 static void fixup_var_refs
PARAMS ((rtx
, enum machine_mode
, int, rtx
,
234 static struct fixup_replacement
235 *find_fixup_replacement
PARAMS ((struct fixup_replacement
**, rtx
));
236 static void fixup_var_refs_insns
PARAMS ((rtx
, rtx
, enum machine_mode
,
238 static void fixup_var_refs_insns_with_hash
239 PARAMS ((htab_t
, rtx
,
240 enum machine_mode
, int, rtx
));
241 static void fixup_var_refs_insn
PARAMS ((rtx
, rtx
, enum machine_mode
,
243 static void fixup_var_refs_1
PARAMS ((rtx
, enum machine_mode
, rtx
*, rtx
,
244 struct fixup_replacement
**, rtx
));
245 static rtx fixup_memory_subreg
PARAMS ((rtx
, rtx
, enum machine_mode
, int));
246 static rtx walk_fixup_memory_subreg
PARAMS ((rtx
, rtx
, enum machine_mode
,
248 static rtx fixup_stack_1
PARAMS ((rtx
, rtx
));
249 static void optimize_bit_field
PARAMS ((rtx
, rtx
, rtx
*));
250 static void instantiate_decls
PARAMS ((tree
, int));
251 static void instantiate_decls_1
PARAMS ((tree
, int));
252 static void instantiate_decl
PARAMS ((rtx
, HOST_WIDE_INT
, int));
253 static rtx instantiate_new_reg
PARAMS ((rtx
, HOST_WIDE_INT
*));
254 static int instantiate_virtual_regs_1
PARAMS ((rtx
*, rtx
, int));
255 static void delete_handlers
PARAMS ((void));
256 static void pad_to_arg_alignment
PARAMS ((struct args_size
*, int,
257 struct args_size
*));
258 #ifndef ARGS_GROW_DOWNWARD
259 static void pad_below
PARAMS ((struct args_size
*, enum machine_mode
,
262 static rtx round_trampoline_addr
PARAMS ((rtx
));
263 static rtx adjust_trampoline_addr
PARAMS ((rtx
));
264 static tree
*identify_blocks_1
PARAMS ((rtx
, tree
*, tree
*, tree
*));
265 static void reorder_blocks_0
PARAMS ((tree
));
266 static void reorder_blocks_1
PARAMS ((rtx
, tree
, varray_type
*));
267 static void reorder_fix_fragments
PARAMS ((tree
));
268 static tree blocks_nreverse
PARAMS ((tree
));
269 static int all_blocks
PARAMS ((tree
, tree
*));
270 static tree
*get_block_vector
PARAMS ((tree
, int *));
271 extern tree debug_find_var_in_block_tree
PARAMS ((tree
, tree
));
272 /* We always define `record_insns' even if its not used so that we
273 can always export `prologue_epilogue_contains'. */
274 static void record_insns
PARAMS ((rtx
, varray_type
*)) ATTRIBUTE_UNUSED
;
275 static int contains
PARAMS ((rtx
, varray_type
));
277 static void emit_return_into_block
PARAMS ((basic_block
, rtx
));
279 static void put_addressof_into_stack
PARAMS ((rtx
, htab_t
));
280 static bool purge_addressof_1
PARAMS ((rtx
*, rtx
, int, int,
282 static void purge_single_hard_subreg_set
PARAMS ((rtx
));
283 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
284 static rtx keep_stack_depressed
PARAMS ((rtx
));
286 static int is_addressof
PARAMS ((rtx
*, void *));
287 static hashval_t insns_for_mem_hash
PARAMS ((const void *));
288 static int insns_for_mem_comp
PARAMS ((const void *, const void *));
289 static int insns_for_mem_walk
PARAMS ((rtx
*, void *));
290 static void compute_insns_for_mem
PARAMS ((rtx
, rtx
, htab_t
));
291 static void prepare_function_start
PARAMS ((void));
292 static void do_clobber_return_reg
PARAMS ((rtx
, void *));
293 static void do_use_return_reg
PARAMS ((rtx
, void *));
295 /* Pointer to chain of `struct function' for containing functions. */
296 static GTY(()) struct function
*outer_function_chain
;
298 /* Given a function decl for a containing function,
299 return the `struct function' for it. */
302 find_function_data (decl
)
307 for (p
= outer_function_chain
; p
; p
= p
->outer
)
314 /* Save the current context for compilation of a nested function.
315 This is called from language-specific code. The caller should use
316 the enter_nested langhook to save any language-specific state,
317 since this function knows only about language-independent
321 push_function_context_to (context
)
328 if (context
== current_function_decl
)
329 cfun
->contains_functions
= 1;
332 struct function
*containing
= find_function_data (context
);
333 containing
->contains_functions
= 1;
338 init_dummy_function_start ();
341 p
->outer
= outer_function_chain
;
342 outer_function_chain
= p
;
343 p
->fixup_var_refs_queue
= 0;
345 (*lang_hooks
.function
.enter_nested
) (p
);
351 push_function_context ()
353 push_function_context_to (current_function_decl
);
356 /* Restore the last saved context, at the end of a nested function.
357 This function is called from language-specific code. */
360 pop_function_context_from (context
)
361 tree context ATTRIBUTE_UNUSED
;
363 struct function
*p
= outer_function_chain
;
364 struct var_refs_queue
*queue
;
367 outer_function_chain
= p
->outer
;
369 current_function_decl
= p
->decl
;
372 restore_emit_status (p
);
374 (*lang_hooks
.function
.leave_nested
) (p
);
376 /* Finish doing put_var_into_stack for any of our variables which became
377 addressable during the nested function. If only one entry has to be
378 fixed up, just do that one. Otherwise, first make a list of MEMs that
379 are not to be unshared. */
380 if (p
->fixup_var_refs_queue
== 0)
382 else if (p
->fixup_var_refs_queue
->next
== 0)
383 fixup_var_refs (p
->fixup_var_refs_queue
->modified
,
384 p
->fixup_var_refs_queue
->promoted_mode
,
385 p
->fixup_var_refs_queue
->unsignedp
,
386 p
->fixup_var_refs_queue
->modified
, 0);
391 for (queue
= p
->fixup_var_refs_queue
; queue
; queue
= queue
->next
)
392 list
= gen_rtx_EXPR_LIST (VOIDmode
, queue
->modified
, list
);
394 for (queue
= p
->fixup_var_refs_queue
; queue
; queue
= queue
->next
)
395 fixup_var_refs (queue
->modified
, queue
->promoted_mode
,
396 queue
->unsignedp
, list
, 0);
400 p
->fixup_var_refs_queue
= 0;
402 /* Reset variables that have known state during rtx generation. */
403 rtx_equal_function_value_matters
= 1;
404 virtuals_instantiated
= 0;
405 generating_concat_p
= 1;
409 pop_function_context ()
411 pop_function_context_from (current_function_decl
);
414 /* Clear out all parts of the state in F that can safely be discarded
415 after the function has been parsed, but not compiled, to let
416 garbage collection reclaim the memory. */
419 free_after_parsing (f
)
422 /* f->expr->forced_labels is used by code generation. */
423 /* f->emit->regno_reg_rtx is used by code generation. */
424 /* f->varasm is used by code generation. */
425 /* f->eh->eh_return_stub_label is used by code generation. */
427 (*lang_hooks
.function
.final
) (f
);
431 /* Clear out all parts of the state in F that can safely be discarded
432 after the function has been compiled, to let garbage collection
433 reclaim the memory. */
436 free_after_compilation (f
)
445 f
->x_temp_slots
= NULL
;
446 f
->arg_offset_rtx
= NULL
;
447 f
->return_rtx
= NULL
;
448 f
->internal_arg_pointer
= NULL
;
449 f
->x_nonlocal_labels
= NULL
;
450 f
->x_nonlocal_goto_handler_slots
= NULL
;
451 f
->x_nonlocal_goto_handler_labels
= NULL
;
452 f
->x_nonlocal_goto_stack_level
= NULL
;
453 f
->x_cleanup_label
= NULL
;
454 f
->x_return_label
= NULL
;
455 f
->x_save_expr_regs
= NULL
;
456 f
->x_stack_slot_list
= NULL
;
457 f
->x_rtl_expr_chain
= NULL
;
458 f
->x_tail_recursion_label
= NULL
;
459 f
->x_tail_recursion_reentry
= NULL
;
460 f
->x_arg_pointer_save_area
= NULL
;
461 f
->x_clobber_return_insn
= NULL
;
462 f
->x_context_display
= NULL
;
463 f
->x_trampoline_list
= NULL
;
464 f
->x_parm_birth_insn
= NULL
;
465 f
->x_last_parm_insn
= NULL
;
466 f
->x_parm_reg_stack_loc
= NULL
;
467 f
->fixup_var_refs_queue
= NULL
;
468 f
->original_arg_vector
= NULL
;
469 f
->original_decl_initial
= NULL
;
470 f
->inl_last_parm_insn
= NULL
;
471 f
->epilogue_delay_list
= NULL
;
474 /* Allocate fixed slots in the stack frame of the current function. */
476 /* Return size needed for stack frame based on slots so far allocated in
478 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
479 the caller may have to do that. */
482 get_func_frame_size (f
)
485 #ifdef FRAME_GROWS_DOWNWARD
486 return -f
->x_frame_offset
;
488 return f
->x_frame_offset
;
492 /* Return size needed for stack frame based on slots so far allocated.
493 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
494 the caller may have to do that. */
498 return get_func_frame_size (cfun
);
501 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
502 with machine mode MODE.
504 ALIGN controls the amount of alignment for the address of the slot:
505 0 means according to MODE,
506 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
507 positive specifies alignment boundary in bits.
509 We do not round to stack_boundary here.
511 FUNCTION specifies the function to allocate in. */
514 assign_stack_local_1 (mode
, size
, align
, function
)
515 enum machine_mode mode
;
518 struct function
*function
;
521 int bigend_correction
= 0;
523 int frame_off
, frame_alignment
, frame_phase
;
530 alignment
= BIGGEST_ALIGNMENT
;
532 alignment
= GET_MODE_ALIGNMENT (mode
);
534 /* Allow the target to (possibly) increase the alignment of this
536 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 0);
538 alignment
= LOCAL_ALIGNMENT (type
, alignment
);
540 alignment
/= BITS_PER_UNIT
;
542 else if (align
== -1)
544 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
545 size
= CEIL_ROUND (size
, alignment
);
548 alignment
= align
/ BITS_PER_UNIT
;
550 #ifdef FRAME_GROWS_DOWNWARD
551 function
->x_frame_offset
-= size
;
554 /* Ignore alignment we can't do with expected alignment of the boundary. */
555 if (alignment
* BITS_PER_UNIT
> PREFERRED_STACK_BOUNDARY
)
556 alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
558 if (function
->stack_alignment_needed
< alignment
* BITS_PER_UNIT
)
559 function
->stack_alignment_needed
= alignment
* BITS_PER_UNIT
;
561 /* Calculate how many bytes the start of local variables is off from
563 frame_alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
564 frame_off
= STARTING_FRAME_OFFSET
% frame_alignment
;
565 frame_phase
= frame_off
? frame_alignment
- frame_off
: 0;
567 /* Round frame offset to that alignment.
568 We must be careful here, since FRAME_OFFSET might be negative and
569 division with a negative dividend isn't as well defined as we might
570 like. So we instead assume that ALIGNMENT is a power of two and
571 use logical operations which are unambiguous. */
572 #ifdef FRAME_GROWS_DOWNWARD
573 function
->x_frame_offset
= FLOOR_ROUND (function
->x_frame_offset
- frame_phase
, alignment
) + frame_phase
;
575 function
->x_frame_offset
= CEIL_ROUND (function
->x_frame_offset
- frame_phase
, alignment
) + frame_phase
;
578 /* On a big-endian machine, if we are allocating more space than we will use,
579 use the least significant bytes of those that are allocated. */
580 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
581 bigend_correction
= size
- GET_MODE_SIZE (mode
);
583 /* If we have already instantiated virtual registers, return the actual
584 address relative to the frame pointer. */
585 if (function
== cfun
&& virtuals_instantiated
)
586 addr
= plus_constant (frame_pointer_rtx
,
587 (frame_offset
+ bigend_correction
588 + STARTING_FRAME_OFFSET
));
590 addr
= plus_constant (virtual_stack_vars_rtx
,
591 function
->x_frame_offset
+ bigend_correction
);
593 #ifndef FRAME_GROWS_DOWNWARD
594 function
->x_frame_offset
+= size
;
597 x
= gen_rtx_MEM (mode
, addr
);
599 function
->x_stack_slot_list
600 = gen_rtx_EXPR_LIST (VOIDmode
, x
, function
->x_stack_slot_list
);
605 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
609 assign_stack_local (mode
, size
, align
)
610 enum machine_mode mode
;
614 return assign_stack_local_1 (mode
, size
, align
, cfun
);
617 /* Allocate a temporary stack slot and record it for possible later
620 MODE is the machine mode to be given to the returned rtx.
622 SIZE is the size in units of the space required. We do no rounding here
623 since assign_stack_local will do any required rounding.
625 KEEP is 1 if this slot is to be retained after a call to
626 free_temp_slots. Automatic variables for a block are allocated
627 with this flag. KEEP is 2 if we allocate a longer term temporary,
628 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
629 if we are to allocate something at an inner level to be treated as
630 a variable in the block (e.g., a SAVE_EXPR).
632 TYPE is the type that will be used for the stack slot. */
635 assign_stack_temp_for_type (mode
, size
, keep
, type
)
636 enum machine_mode mode
;
642 struct temp_slot
*p
, *best_p
= 0;
645 /* If SIZE is -1 it means that somebody tried to allocate a temporary
646 of a variable size. */
651 align
= BIGGEST_ALIGNMENT
;
653 align
= GET_MODE_ALIGNMENT (mode
);
656 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 0);
659 align
= LOCAL_ALIGNMENT (type
, align
);
661 /* Try to find an available, already-allocated temporary of the proper
662 mode which meets the size and alignment requirements. Choose the
663 smallest one with the closest alignment. */
664 for (p
= temp_slots
; p
; p
= p
->next
)
665 if (p
->align
>= align
&& p
->size
>= size
&& GET_MODE (p
->slot
) == mode
667 && objects_must_conflict_p (p
->type
, type
)
668 && (best_p
== 0 || best_p
->size
> p
->size
669 || (best_p
->size
== p
->size
&& best_p
->align
> p
->align
)))
671 if (p
->align
== align
&& p
->size
== size
)
679 /* Make our best, if any, the one to use. */
682 /* If there are enough aligned bytes left over, make them into a new
683 temp_slot so that the extra bytes don't get wasted. Do this only
684 for BLKmode slots, so that we can be sure of the alignment. */
685 if (GET_MODE (best_p
->slot
) == BLKmode
)
687 int alignment
= best_p
->align
/ BITS_PER_UNIT
;
688 HOST_WIDE_INT rounded_size
= CEIL_ROUND (size
, alignment
);
690 if (best_p
->size
- rounded_size
>= alignment
)
692 p
= (struct temp_slot
*) ggc_alloc (sizeof (struct temp_slot
));
693 p
->in_use
= p
->addr_taken
= 0;
694 p
->size
= best_p
->size
- rounded_size
;
695 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
696 p
->full_size
= best_p
->full_size
- rounded_size
;
697 p
->slot
= gen_rtx_MEM (BLKmode
,
698 plus_constant (XEXP (best_p
->slot
, 0),
700 p
->align
= best_p
->align
;
703 p
->type
= best_p
->type
;
704 p
->next
= temp_slots
;
707 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, p
->slot
,
710 best_p
->size
= rounded_size
;
711 best_p
->full_size
= rounded_size
;
718 /* If we still didn't find one, make a new temporary. */
721 HOST_WIDE_INT frame_offset_old
= frame_offset
;
723 p
= (struct temp_slot
*) ggc_alloc (sizeof (struct temp_slot
));
725 /* We are passing an explicit alignment request to assign_stack_local.
726 One side effect of that is assign_stack_local will not round SIZE
727 to ensure the frame offset remains suitably aligned.
729 So for requests which depended on the rounding of SIZE, we go ahead
730 and round it now. We also make sure ALIGNMENT is at least
731 BIGGEST_ALIGNMENT. */
732 if (mode
== BLKmode
&& align
< BIGGEST_ALIGNMENT
)
734 p
->slot
= assign_stack_local (mode
,
736 ? CEIL_ROUND (size
, align
/ BITS_PER_UNIT
)
742 /* The following slot size computation is necessary because we don't
743 know the actual size of the temporary slot until assign_stack_local
744 has performed all the frame alignment and size rounding for the
745 requested temporary. Note that extra space added for alignment
746 can be either above or below this stack slot depending on which
747 way the frame grows. We include the extra space if and only if it
748 is above this slot. */
749 #ifdef FRAME_GROWS_DOWNWARD
750 p
->size
= frame_offset_old
- frame_offset
;
755 /* Now define the fields used by combine_temp_slots. */
756 #ifdef FRAME_GROWS_DOWNWARD
757 p
->base_offset
= frame_offset
;
758 p
->full_size
= frame_offset_old
- frame_offset
;
760 p
->base_offset
= frame_offset_old
;
761 p
->full_size
= frame_offset
- frame_offset_old
;
764 p
->next
= temp_slots
;
770 p
->rtl_expr
= seq_rtl_expr
;
775 p
->level
= target_temp_slot_level
;
780 p
->level
= var_temp_slot_level
;
785 p
->level
= temp_slot_level
;
790 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
791 slot
= gen_rtx_MEM (mode
, XEXP (p
->slot
, 0));
792 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, slot
, stack_slot_list
);
794 /* If we know the alias set for the memory that will be used, use
795 it. If there's no TYPE, then we don't know anything about the
796 alias set for the memory. */
797 set_mem_alias_set (slot
, type
? get_alias_set (type
) : 0);
798 set_mem_align (slot
, align
);
800 /* If a type is specified, set the relevant flags. */
803 RTX_UNCHANGING_P (slot
) = TYPE_READONLY (type
);
804 MEM_VOLATILE_P (slot
) = TYPE_VOLATILE (type
);
805 MEM_SET_IN_STRUCT_P (slot
, AGGREGATE_TYPE_P (type
));
811 /* Allocate a temporary stack slot and record it for possible later
812 reuse. First three arguments are same as in preceding function. */
815 assign_stack_temp (mode
, size
, keep
)
816 enum machine_mode mode
;
820 return assign_stack_temp_for_type (mode
, size
, keep
, NULL_TREE
);
823 /* Assign a temporary.
824 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
825 and so that should be used in error messages. In either case, we
826 allocate of the given type.
827 KEEP is as for assign_stack_temp.
828 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
829 it is 0 if a register is OK.
830 DONT_PROMOTE is 1 if we should not promote values in register
834 assign_temp (type_or_decl
, keep
, memory_required
, dont_promote
)
838 int dont_promote ATTRIBUTE_UNUSED
;
841 enum machine_mode mode
;
842 #ifndef PROMOTE_FOR_CALL_ONLY
846 if (DECL_P (type_or_decl
))
847 decl
= type_or_decl
, type
= TREE_TYPE (decl
);
849 decl
= NULL
, type
= type_or_decl
;
851 mode
= TYPE_MODE (type
);
852 #ifndef PROMOTE_FOR_CALL_ONLY
853 unsignedp
= TREE_UNSIGNED (type
);
856 if (mode
== BLKmode
|| memory_required
)
858 HOST_WIDE_INT size
= int_size_in_bytes (type
);
861 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
862 problems with allocating the stack space. */
866 /* Unfortunately, we don't yet know how to allocate variable-sized
867 temporaries. However, sometimes we have a fixed upper limit on
868 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
869 instead. This is the case for Chill variable-sized strings. */
870 if (size
== -1 && TREE_CODE (type
) == ARRAY_TYPE
871 && TYPE_ARRAY_MAX_SIZE (type
) != NULL_TREE
872 && host_integerp (TYPE_ARRAY_MAX_SIZE (type
), 1))
873 size
= tree_low_cst (TYPE_ARRAY_MAX_SIZE (type
), 1);
875 /* The size of the temporary may be too large to fit into an integer. */
876 /* ??? Not sure this should happen except for user silliness, so limit
877 this to things that aren't compiler-generated temporaries. The
878 rest of the time we'll abort in assign_stack_temp_for_type. */
879 if (decl
&& size
== -1
880 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
)
882 error_with_decl (decl
, "size of variable `%s' is too large");
886 tmp
= assign_stack_temp_for_type (mode
, size
, keep
, type
);
890 #ifndef PROMOTE_FOR_CALL_ONLY
892 mode
= promote_mode (type
, mode
, &unsignedp
, 0);
895 return gen_reg_rtx (mode
);
898 /* Combine temporary stack slots which are adjacent on the stack.
900 This allows for better use of already allocated stack space. This is only
901 done for BLKmode slots because we can be sure that we won't have alignment
902 problems in this case. */
905 combine_temp_slots ()
907 struct temp_slot
*p
, *q
;
908 struct temp_slot
*prev_p
, *prev_q
;
911 /* We can't combine slots, because the information about which slot
912 is in which alias set will be lost. */
913 if (flag_strict_aliasing
)
916 /* If there are a lot of temp slots, don't do anything unless
917 high levels of optimization. */
918 if (! flag_expensive_optimizations
)
919 for (p
= temp_slots
, num_slots
= 0; p
; p
= p
->next
, num_slots
++)
920 if (num_slots
> 100 || (num_slots
> 10 && optimize
== 0))
923 for (p
= temp_slots
, prev_p
= 0; p
; p
= prev_p
? prev_p
->next
: temp_slots
)
927 if (! p
->in_use
&& GET_MODE (p
->slot
) == BLKmode
)
928 for (q
= p
->next
, prev_q
= p
; q
; q
= prev_q
->next
)
931 if (! q
->in_use
&& GET_MODE (q
->slot
) == BLKmode
)
933 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
935 /* Q comes after P; combine Q into P. */
937 p
->full_size
+= q
->full_size
;
940 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
942 /* P comes after Q; combine P into Q. */
944 q
->full_size
+= p
->full_size
;
949 /* Either delete Q or advance past it. */
951 prev_q
->next
= q
->next
;
955 /* Either delete P or advance past it. */
959 prev_p
->next
= p
->next
;
961 temp_slots
= p
->next
;
968 /* Find the temp slot corresponding to the object at address X. */
970 static struct temp_slot
*
971 find_temp_slot_from_address (x
)
977 for (p
= temp_slots
; p
; p
= p
->next
)
982 else if (XEXP (p
->slot
, 0) == x
984 || (GET_CODE (x
) == PLUS
985 && XEXP (x
, 0) == virtual_stack_vars_rtx
986 && GET_CODE (XEXP (x
, 1)) == CONST_INT
987 && INTVAL (XEXP (x
, 1)) >= p
->base_offset
988 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
))
991 else if (p
->address
!= 0 && GET_CODE (p
->address
) == EXPR_LIST
)
992 for (next
= p
->address
; next
; next
= XEXP (next
, 1))
993 if (XEXP (next
, 0) == x
)
997 /* If we have a sum involving a register, see if it points to a temp
999 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == REG
1000 && (p
= find_temp_slot_from_address (XEXP (x
, 0))) != 0)
1002 else if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == REG
1003 && (p
= find_temp_slot_from_address (XEXP (x
, 1))) != 0)
1009 /* Indicate that NEW is an alternate way of referring to the temp slot
1010 that previously was known by OLD. */
1013 update_temp_slot_address (old
, new)
1016 struct temp_slot
*p
;
1018 if (rtx_equal_p (old
, new))
1021 p
= find_temp_slot_from_address (old
);
1023 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1024 is a register, see if one operand of the PLUS is a temporary
1025 location. If so, NEW points into it. Otherwise, if both OLD and
1026 NEW are a PLUS and if there is a register in common between them.
1027 If so, try a recursive call on those values. */
1030 if (GET_CODE (old
) != PLUS
)
1033 if (GET_CODE (new) == REG
)
1035 update_temp_slot_address (XEXP (old
, 0), new);
1036 update_temp_slot_address (XEXP (old
, 1), new);
1039 else if (GET_CODE (new) != PLUS
)
1042 if (rtx_equal_p (XEXP (old
, 0), XEXP (new, 0)))
1043 update_temp_slot_address (XEXP (old
, 1), XEXP (new, 1));
1044 else if (rtx_equal_p (XEXP (old
, 1), XEXP (new, 0)))
1045 update_temp_slot_address (XEXP (old
, 0), XEXP (new, 1));
1046 else if (rtx_equal_p (XEXP (old
, 0), XEXP (new, 1)))
1047 update_temp_slot_address (XEXP (old
, 1), XEXP (new, 0));
1048 else if (rtx_equal_p (XEXP (old
, 1), XEXP (new, 1)))
1049 update_temp_slot_address (XEXP (old
, 0), XEXP (new, 0));
1054 /* Otherwise add an alias for the temp's address. */
1055 else if (p
->address
== 0)
1059 if (GET_CODE (p
->address
) != EXPR_LIST
)
1060 p
->address
= gen_rtx_EXPR_LIST (VOIDmode
, p
->address
, NULL_RTX
);
1062 p
->address
= gen_rtx_EXPR_LIST (VOIDmode
, new, p
->address
);
1066 /* If X could be a reference to a temporary slot, mark the fact that its
1067 address was taken. */
1070 mark_temp_addr_taken (x
)
1073 struct temp_slot
*p
;
1078 /* If X is not in memory or is at a constant address, it cannot be in
1079 a temporary slot. */
1080 if (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1083 p
= find_temp_slot_from_address (XEXP (x
, 0));
1088 /* If X could be a reference to a temporary slot, mark that slot as
1089 belonging to the to one level higher than the current level. If X
1090 matched one of our slots, just mark that one. Otherwise, we can't
1091 easily predict which it is, so upgrade all of them. Kept slots
1092 need not be touched.
1094 This is called when an ({...}) construct occurs and a statement
1095 returns a value in memory. */
1098 preserve_temp_slots (x
)
1101 struct temp_slot
*p
= 0;
1103 /* If there is no result, we still might have some objects whose address
1104 were taken, so we need to make sure they stay around. */
1107 for (p
= temp_slots
; p
; p
= p
->next
)
1108 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1114 /* If X is a register that is being used as a pointer, see if we have
1115 a temporary slot we know it points to. To be consistent with
1116 the code below, we really should preserve all non-kept slots
1117 if we can't find a match, but that seems to be much too costly. */
1118 if (GET_CODE (x
) == REG
&& REG_POINTER (x
))
1119 p
= find_temp_slot_from_address (x
);
1121 /* If X is not in memory or is at a constant address, it cannot be in
1122 a temporary slot, but it can contain something whose address was
1124 if (p
== 0 && (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0))))
1126 for (p
= temp_slots
; p
; p
= p
->next
)
1127 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1133 /* First see if we can find a match. */
1135 p
= find_temp_slot_from_address (XEXP (x
, 0));
1139 /* Move everything at our level whose address was taken to our new
1140 level in case we used its address. */
1141 struct temp_slot
*q
;
1143 if (p
->level
== temp_slot_level
)
1145 for (q
= temp_slots
; q
; q
= q
->next
)
1146 if (q
!= p
&& q
->addr_taken
&& q
->level
== p
->level
)
1155 /* Otherwise, preserve all non-kept slots at this level. */
1156 for (p
= temp_slots
; p
; p
= p
->next
)
1157 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
)
1161 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1162 with that RTL_EXPR, promote it into a temporary slot at the present
1163 level so it will not be freed when we free slots made in the
1167 preserve_rtl_expr_result (x
)
1170 struct temp_slot
*p
;
1172 /* If X is not in memory or is at a constant address, it cannot be in
1173 a temporary slot. */
1174 if (x
== 0 || GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1177 /* If we can find a match, move it to our level unless it is already at
1179 p
= find_temp_slot_from_address (XEXP (x
, 0));
1182 p
->level
= MIN (p
->level
, temp_slot_level
);
1189 /* Free all temporaries used so far. This is normally called at the end
1190 of generating code for a statement. Don't free any temporaries
1191 currently in use for an RTL_EXPR that hasn't yet been emitted.
1192 We could eventually do better than this since it can be reused while
1193 generating the same RTL_EXPR, but this is complex and probably not
1199 struct temp_slot
*p
;
1201 for (p
= temp_slots
; p
; p
= p
->next
)
1202 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
1203 && p
->rtl_expr
== 0)
1206 combine_temp_slots ();
1209 /* Free all temporary slots used in T, an RTL_EXPR node. */
1212 free_temps_for_rtl_expr (t
)
1215 struct temp_slot
*p
;
1217 for (p
= temp_slots
; p
; p
= p
->next
)
1218 if (p
->rtl_expr
== t
)
1220 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1221 needs to be preserved. This can happen if a temporary in
1222 the RTL_EXPR was addressed; preserve_temp_slots will move
1223 the temporary into a higher level. */
1224 if (temp_slot_level
<= p
->level
)
1227 p
->rtl_expr
= NULL_TREE
;
1230 combine_temp_slots ();
1233 /* Mark all temporaries ever allocated in this function as not suitable
1234 for reuse until the current level is exited. */
1237 mark_all_temps_used ()
1239 struct temp_slot
*p
;
1241 for (p
= temp_slots
; p
; p
= p
->next
)
1243 p
->in_use
= p
->keep
= 1;
1244 p
->level
= MIN (p
->level
, temp_slot_level
);
1248 /* Push deeper into the nesting level for stack temporaries. */
1256 /* Likewise, but save the new level as the place to allocate variables
1261 push_temp_slots_for_block ()
1265 var_temp_slot_level
= temp_slot_level
;
1268 /* Likewise, but save the new level as the place to allocate temporaries
1269 for TARGET_EXPRs. */
1272 push_temp_slots_for_target ()
1276 target_temp_slot_level
= temp_slot_level
;
1279 /* Set and get the value of target_temp_slot_level. The only
1280 permitted use of these functions is to save and restore this value. */
1283 get_target_temp_slot_level ()
1285 return target_temp_slot_level
;
1289 set_target_temp_slot_level (level
)
1292 target_temp_slot_level
= level
;
1296 /* Pop a temporary nesting level. All slots in use in the current level
1302 struct temp_slot
*p
;
1304 for (p
= temp_slots
; p
; p
= p
->next
)
1305 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->rtl_expr
== 0)
1308 combine_temp_slots ();
1313 /* Initialize temporary slots. */
1318 /* We have not allocated any temporaries yet. */
1320 temp_slot_level
= 0;
1321 var_temp_slot_level
= 0;
1322 target_temp_slot_level
= 0;
1325 /* Retroactively move an auto variable from a register to a stack slot.
1326 This is done when an address-reference to the variable is seen. */
1329 put_var_into_stack (decl
)
1333 enum machine_mode promoted_mode
, decl_mode
;
1334 struct function
*function
= 0;
1336 int can_use_addressof
;
1337 int volatilep
= TREE_CODE (decl
) != SAVE_EXPR
&& TREE_THIS_VOLATILE (decl
);
1338 int usedp
= (TREE_USED (decl
)
1339 || (TREE_CODE (decl
) != SAVE_EXPR
&& DECL_INITIAL (decl
) != 0));
1341 context
= decl_function_context (decl
);
1343 /* Get the current rtl used for this object and its original mode. */
1344 reg
= (TREE_CODE (decl
) == SAVE_EXPR
1345 ? SAVE_EXPR_RTL (decl
)
1346 : DECL_RTL_IF_SET (decl
));
1348 /* No need to do anything if decl has no rtx yet
1349 since in that case caller is setting TREE_ADDRESSABLE
1350 and a stack slot will be assigned when the rtl is made. */
1354 /* Get the declared mode for this object. */
1355 decl_mode
= (TREE_CODE (decl
) == SAVE_EXPR
? TYPE_MODE (TREE_TYPE (decl
))
1356 : DECL_MODE (decl
));
1357 /* Get the mode it's actually stored in. */
1358 promoted_mode
= GET_MODE (reg
);
1360 /* If this variable comes from an outer function, find that
1361 function's saved context. Don't use find_function_data here,
1362 because it might not be in any active function.
1363 FIXME: Is that really supposed to happen?
1364 It does in ObjC at least. */
1365 if (context
!= current_function_decl
&& context
!= inline_function_decl
)
1366 for (function
= outer_function_chain
; function
; function
= function
->outer
)
1367 if (function
->decl
== context
)
1370 /* If this is a variable-size object with a pseudo to address it,
1371 put that pseudo into the stack, if the var is nonlocal. */
1372 if (TREE_CODE (decl
) != SAVE_EXPR
&& DECL_NONLOCAL (decl
)
1373 && GET_CODE (reg
) == MEM
1374 && GET_CODE (XEXP (reg
, 0)) == REG
1375 && REGNO (XEXP (reg
, 0)) > LAST_VIRTUAL_REGISTER
)
1377 reg
= XEXP (reg
, 0);
1378 decl_mode
= promoted_mode
= GET_MODE (reg
);
1384 /* FIXME make it work for promoted modes too */
1385 && decl_mode
== promoted_mode
1386 #ifdef NON_SAVING_SETJMP
1387 && ! (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
1391 /* If we can't use ADDRESSOF, make sure we see through one we already
1393 if (! can_use_addressof
&& GET_CODE (reg
) == MEM
1394 && GET_CODE (XEXP (reg
, 0)) == ADDRESSOF
)
1395 reg
= XEXP (XEXP (reg
, 0), 0);
1397 /* Now we should have a value that resides in one or more pseudo regs. */
1399 if (GET_CODE (reg
) == REG
)
1401 /* If this variable lives in the current function and we don't need
1402 to put things in the stack for the sake of setjmp, try to keep it
1403 in a register until we know we actually need the address. */
1404 if (can_use_addressof
)
1405 gen_mem_addressof (reg
, decl
);
1407 put_reg_into_stack (function
, reg
, TREE_TYPE (decl
), promoted_mode
,
1408 decl_mode
, volatilep
, 0, usedp
, 0);
1410 else if (GET_CODE (reg
) == CONCAT
)
1412 /* A CONCAT contains two pseudos; put them both in the stack.
1413 We do it so they end up consecutive.
1414 We fixup references to the parts only after we fixup references
1415 to the whole CONCAT, lest we do double fixups for the latter
1417 enum machine_mode part_mode
= GET_MODE (XEXP (reg
, 0));
1418 tree part_type
= (*lang_hooks
.types
.type_for_mode
) (part_mode
, 0);
1419 rtx lopart
= XEXP (reg
, 0);
1420 rtx hipart
= XEXP (reg
, 1);
1421 #ifdef FRAME_GROWS_DOWNWARD
1422 /* Since part 0 should have a lower address, do it second. */
1423 put_reg_into_stack (function
, hipart
, part_type
, part_mode
,
1424 part_mode
, volatilep
, 0, 0, 0);
1425 put_reg_into_stack (function
, lopart
, part_type
, part_mode
,
1426 part_mode
, volatilep
, 0, 0, 0);
1428 put_reg_into_stack (function
, lopart
, part_type
, part_mode
,
1429 part_mode
, volatilep
, 0, 0, 0);
1430 put_reg_into_stack (function
, hipart
, part_type
, part_mode
,
1431 part_mode
, volatilep
, 0, 0, 0);
1434 /* Change the CONCAT into a combined MEM for both parts. */
1435 PUT_CODE (reg
, MEM
);
1436 MEM_ATTRS (reg
) = 0;
1438 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1439 already computed alias sets. Here we want to re-generate. */
1441 SET_DECL_RTL (decl
, NULL
);
1442 set_mem_attributes (reg
, decl
, 1);
1444 SET_DECL_RTL (decl
, reg
);
1446 /* The two parts are in memory order already.
1447 Use the lower parts address as ours. */
1448 XEXP (reg
, 0) = XEXP (XEXP (reg
, 0), 0);
1449 /* Prevent sharing of rtl that might lose. */
1450 if (GET_CODE (XEXP (reg
, 0)) == PLUS
)
1451 XEXP (reg
, 0) = copy_rtx (XEXP (reg
, 0));
1454 schedule_fixup_var_refs (function
, reg
, TREE_TYPE (decl
),
1456 schedule_fixup_var_refs (function
, lopart
, part_type
, part_mode
, 0);
1457 schedule_fixup_var_refs (function
, hipart
, part_type
, part_mode
, 0);
1464 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1465 into the stack frame of FUNCTION (0 means the current function).
1466 DECL_MODE is the machine mode of the user-level data type.
1467 PROMOTED_MODE is the machine mode of the register.
1468 VOLATILE_P is nonzero if this is for a "volatile" decl.
1469 USED_P is nonzero if this reg might have already been used in an insn. */
1472 put_reg_into_stack (function
, reg
, type
, promoted_mode
, decl_mode
, volatile_p
,
1473 original_regno
, used_p
, ht
)
1474 struct function
*function
;
1477 enum machine_mode promoted_mode
, decl_mode
;
1479 unsigned int original_regno
;
1483 struct function
*func
= function
? function
: cfun
;
1485 unsigned int regno
= original_regno
;
1488 regno
= REGNO (reg
);
1490 if (regno
< func
->x_max_parm_reg
)
1491 new = func
->x_parm_reg_stack_loc
[regno
];
1494 new = assign_stack_local_1 (decl_mode
, GET_MODE_SIZE (decl_mode
), 0, func
);
1496 PUT_CODE (reg
, MEM
);
1497 PUT_MODE (reg
, decl_mode
);
1498 XEXP (reg
, 0) = XEXP (new, 0);
1499 MEM_ATTRS (reg
) = 0;
1500 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1501 MEM_VOLATILE_P (reg
) = volatile_p
;
1503 /* If this is a memory ref that contains aggregate components,
1504 mark it as such for cse and loop optimize. If we are reusing a
1505 previously generated stack slot, then we need to copy the bit in
1506 case it was set for other reasons. For instance, it is set for
1507 __builtin_va_alist. */
1510 MEM_SET_IN_STRUCT_P (reg
,
1511 AGGREGATE_TYPE_P (type
) || MEM_IN_STRUCT_P (new));
1512 set_mem_alias_set (reg
, get_alias_set (type
));
1516 schedule_fixup_var_refs (function
, reg
, type
, promoted_mode
, ht
);
1519 /* Make sure that all refs to the variable, previously made
1520 when it was a register, are fixed up to be valid again.
1521 See function above for meaning of arguments. */
1524 schedule_fixup_var_refs (function
, reg
, type
, promoted_mode
, ht
)
1525 struct function
*function
;
1528 enum machine_mode promoted_mode
;
1531 int unsigned_p
= type
? TREE_UNSIGNED (type
) : 0;
1535 struct var_refs_queue
*temp
;
1538 = (struct var_refs_queue
*) ggc_alloc (sizeof (struct var_refs_queue
));
1539 temp
->modified
= reg
;
1540 temp
->promoted_mode
= promoted_mode
;
1541 temp
->unsignedp
= unsigned_p
;
1542 temp
->next
= function
->fixup_var_refs_queue
;
1543 function
->fixup_var_refs_queue
= temp
;
1546 /* Variable is local; fix it up now. */
1547 fixup_var_refs (reg
, promoted_mode
, unsigned_p
, reg
, ht
);
1551 fixup_var_refs (var
, promoted_mode
, unsignedp
, may_share
, ht
)
1553 enum machine_mode promoted_mode
;
1559 rtx first_insn
= get_insns ();
1560 struct sequence_stack
*stack
= seq_stack
;
1561 tree rtl_exps
= rtl_expr_chain
;
1563 /* If there's a hash table, it must record all uses of VAR. */
1568 fixup_var_refs_insns_with_hash (ht
, var
, promoted_mode
, unsignedp
,
1573 fixup_var_refs_insns (first_insn
, var
, promoted_mode
, unsignedp
,
1574 stack
== 0, may_share
);
1576 /* Scan all pending sequences too. */
1577 for (; stack
; stack
= stack
->next
)
1579 push_to_full_sequence (stack
->first
, stack
->last
);
1580 fixup_var_refs_insns (stack
->first
, var
, promoted_mode
, unsignedp
,
1581 stack
->next
!= 0, may_share
);
1582 /* Update remembered end of sequence
1583 in case we added an insn at the end. */
1584 stack
->last
= get_last_insn ();
1588 /* Scan all waiting RTL_EXPRs too. */
1589 for (pending
= rtl_exps
; pending
; pending
= TREE_CHAIN (pending
))
1591 rtx seq
= RTL_EXPR_SEQUENCE (TREE_VALUE (pending
));
1592 if (seq
!= const0_rtx
&& seq
!= 0)
1594 push_to_sequence (seq
);
1595 fixup_var_refs_insns (seq
, var
, promoted_mode
, unsignedp
, 0,
1602 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1603 some part of an insn. Return a struct fixup_replacement whose OLD
1604 value is equal to X. Allocate a new structure if no such entry exists. */
1606 static struct fixup_replacement
*
1607 find_fixup_replacement (replacements
, x
)
1608 struct fixup_replacement
**replacements
;
1611 struct fixup_replacement
*p
;
1613 /* See if we have already replaced this. */
1614 for (p
= *replacements
; p
!= 0 && ! rtx_equal_p (p
->old
, x
); p
= p
->next
)
1619 p
= (struct fixup_replacement
*) xmalloc (sizeof (struct fixup_replacement
));
1622 p
->next
= *replacements
;
1629 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1630 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1631 for the current function. MAY_SHARE is either a MEM that is not
1632 to be unshared or a list of them. */
1635 fixup_var_refs_insns (insn
, var
, promoted_mode
, unsignedp
, toplevel
, may_share
)
1638 enum machine_mode promoted_mode
;
1645 /* fixup_var_refs_insn might modify insn, so save its next
1647 rtx next
= NEXT_INSN (insn
);
1649 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1650 the three sequences they (potentially) contain, and process
1651 them recursively. The CALL_INSN itself is not interesting. */
1653 if (GET_CODE (insn
) == CALL_INSN
1654 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
1658 /* Look at the Normal call, sibling call and tail recursion
1659 sequences attached to the CALL_PLACEHOLDER. */
1660 for (i
= 0; i
< 3; i
++)
1662 rtx seq
= XEXP (PATTERN (insn
), i
);
1665 push_to_sequence (seq
);
1666 fixup_var_refs_insns (seq
, var
, promoted_mode
, unsignedp
, 0,
1668 XEXP (PATTERN (insn
), i
) = get_insns ();
1674 else if (INSN_P (insn
))
1675 fixup_var_refs_insn (insn
, var
, promoted_mode
, unsignedp
, toplevel
,
1682 /* Look up the insns which reference VAR in HT and fix them up. Other
1683 arguments are the same as fixup_var_refs_insns.
1685 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1686 because the hash table will point straight to the interesting insn
1687 (inside the CALL_PLACEHOLDER). */
1690 fixup_var_refs_insns_with_hash (ht
, var
, promoted_mode
, unsignedp
, may_share
)
1693 enum machine_mode promoted_mode
;
1697 struct insns_for_mem_entry tmp
;
1698 struct insns_for_mem_entry
*ime
;
1702 ime
= (struct insns_for_mem_entry
*) htab_find (ht
, &tmp
);
1703 for (insn_list
= ime
->insns
; insn_list
!= 0; insn_list
= XEXP (insn_list
, 1))
1704 if (INSN_P (XEXP (insn_list
, 0)))
1705 fixup_var_refs_insn (XEXP (insn_list
, 0), var
, promoted_mode
,
1706 unsignedp
, 1, may_share
);
1710 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1711 the insn under examination, VAR is the variable to fix up
1712 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1713 TOPLEVEL is nonzero if this is the main insn chain for this
1717 fixup_var_refs_insn (insn
, var
, promoted_mode
, unsignedp
, toplevel
, no_share
)
1720 enum machine_mode promoted_mode
;
1726 rtx set
, prev
, prev_set
;
1729 /* Remember the notes in case we delete the insn. */
1730 note
= REG_NOTES (insn
);
1732 /* If this is a CLOBBER of VAR, delete it.
1734 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1735 and REG_RETVAL notes too. */
1736 if (GET_CODE (PATTERN (insn
)) == CLOBBER
1737 && (XEXP (PATTERN (insn
), 0) == var
1738 || (GET_CODE (XEXP (PATTERN (insn
), 0)) == CONCAT
1739 && (XEXP (XEXP (PATTERN (insn
), 0), 0) == var
1740 || XEXP (XEXP (PATTERN (insn
), 0), 1) == var
))))
1742 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)) != 0)
1743 /* The REG_LIBCALL note will go away since we are going to
1744 turn INSN into a NOTE, so just delete the
1745 corresponding REG_RETVAL note. */
1746 remove_note (XEXP (note
, 0),
1747 find_reg_note (XEXP (note
, 0), REG_RETVAL
,
1753 /* The insn to load VAR from a home in the arglist
1754 is now a no-op. When we see it, just delete it.
1755 Similarly if this is storing VAR from a register from which
1756 it was loaded in the previous insn. This will occur
1757 when an ADDRESSOF was made for an arglist slot. */
1759 && (set
= single_set (insn
)) != 0
1760 && SET_DEST (set
) == var
1761 /* If this represents the result of an insn group,
1762 don't delete the insn. */
1763 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
) == 0
1764 && (rtx_equal_p (SET_SRC (set
), var
)
1765 || (GET_CODE (SET_SRC (set
)) == REG
1766 && (prev
= prev_nonnote_insn (insn
)) != 0
1767 && (prev_set
= single_set (prev
)) != 0
1768 && SET_DEST (prev_set
) == SET_SRC (set
)
1769 && rtx_equal_p (SET_SRC (prev_set
), var
))))
1775 struct fixup_replacement
*replacements
= 0;
1776 rtx next_insn
= NEXT_INSN (insn
);
1778 if (SMALL_REGISTER_CLASSES
)
1780 /* If the insn that copies the results of a CALL_INSN
1781 into a pseudo now references VAR, we have to use an
1782 intermediate pseudo since we want the life of the
1783 return value register to be only a single insn.
1785 If we don't use an intermediate pseudo, such things as
1786 address computations to make the address of VAR valid
1787 if it is not can be placed between the CALL_INSN and INSN.
1789 To make sure this doesn't happen, we record the destination
1790 of the CALL_INSN and see if the next insn uses both that
1793 if (call_dest
!= 0 && GET_CODE (insn
) == INSN
1794 && reg_mentioned_p (var
, PATTERN (insn
))
1795 && reg_mentioned_p (call_dest
, PATTERN (insn
)))
1797 rtx temp
= gen_reg_rtx (GET_MODE (call_dest
));
1799 emit_insn_before (gen_move_insn (temp
, call_dest
), insn
);
1801 PATTERN (insn
) = replace_rtx (PATTERN (insn
),
1805 if (GET_CODE (insn
) == CALL_INSN
1806 && GET_CODE (PATTERN (insn
)) == SET
)
1807 call_dest
= SET_DEST (PATTERN (insn
));
1808 else if (GET_CODE (insn
) == CALL_INSN
1809 && GET_CODE (PATTERN (insn
)) == PARALLEL
1810 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1811 call_dest
= SET_DEST (XVECEXP (PATTERN (insn
), 0, 0));
1816 /* See if we have to do anything to INSN now that VAR is in
1817 memory. If it needs to be loaded into a pseudo, use a single
1818 pseudo for the entire insn in case there is a MATCH_DUP
1819 between two operands. We pass a pointer to the head of
1820 a list of struct fixup_replacements. If fixup_var_refs_1
1821 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1822 it will record them in this list.
1824 If it allocated a pseudo for any replacement, we copy into
1827 fixup_var_refs_1 (var
, promoted_mode
, &PATTERN (insn
), insn
,
1828 &replacements
, no_share
);
1830 /* If this is last_parm_insn, and any instructions were output
1831 after it to fix it up, then we must set last_parm_insn to
1832 the last such instruction emitted. */
1833 if (insn
== last_parm_insn
)
1834 last_parm_insn
= PREV_INSN (next_insn
);
1836 while (replacements
)
1838 struct fixup_replacement
*next
;
1840 if (GET_CODE (replacements
->new) == REG
)
1845 /* OLD might be a (subreg (mem)). */
1846 if (GET_CODE (replacements
->old
) == SUBREG
)
1848 = fixup_memory_subreg (replacements
->old
, insn
,
1852 = fixup_stack_1 (replacements
->old
, insn
);
1854 insert_before
= insn
;
1856 /* If we are changing the mode, do a conversion.
1857 This might be wasteful, but combine.c will
1858 eliminate much of the waste. */
1860 if (GET_MODE (replacements
->new)
1861 != GET_MODE (replacements
->old
))
1864 convert_move (replacements
->new,
1865 replacements
->old
, unsignedp
);
1870 seq
= gen_move_insn (replacements
->new,
1873 emit_insn_before (seq
, insert_before
);
1876 next
= replacements
->next
;
1877 free (replacements
);
1878 replacements
= next
;
1882 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1883 But don't touch other insns referred to by reg-notes;
1884 we will get them elsewhere. */
1887 if (GET_CODE (note
) != INSN_LIST
)
1889 = walk_fixup_memory_subreg (XEXP (note
, 0), insn
,
1891 note
= XEXP (note
, 1);
1895 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1896 See if the rtx expression at *LOC in INSN needs to be changed.
1898 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1899 contain a list of original rtx's and replacements. If we find that we need
1900 to modify this insn by replacing a memory reference with a pseudo or by
1901 making a new MEM to implement a SUBREG, we consult that list to see if
1902 we have already chosen a replacement. If none has already been allocated,
1903 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1904 or the SUBREG, as appropriate, to the pseudo. */
1907 fixup_var_refs_1 (var
, promoted_mode
, loc
, insn
, replacements
, no_share
)
1909 enum machine_mode promoted_mode
;
1912 struct fixup_replacement
**replacements
;
1917 RTX_CODE code
= GET_CODE (x
);
1920 struct fixup_replacement
*replacement
;
1925 if (XEXP (x
, 0) == var
)
1927 /* Prevent sharing of rtl that might lose. */
1928 rtx sub
= copy_rtx (XEXP (var
, 0));
1930 if (! validate_change (insn
, loc
, sub
, 0))
1932 rtx y
= gen_reg_rtx (GET_MODE (sub
));
1935 /* We should be able to replace with a register or all is lost.
1936 Note that we can't use validate_change to verify this, since
1937 we're not caring for replacing all dups simultaneously. */
1938 if (! validate_replace_rtx (*loc
, y
, insn
))
1941 /* Careful! First try to recognize a direct move of the
1942 value, mimicking how things are done in gen_reload wrt
1943 PLUS. Consider what happens when insn is a conditional
1944 move instruction and addsi3 clobbers flags. */
1947 new_insn
= emit_insn (gen_rtx_SET (VOIDmode
, y
, sub
));
1951 if (recog_memoized (new_insn
) < 0)
1953 /* That failed. Fall back on force_operand and hope. */
1956 sub
= force_operand (sub
, y
);
1958 emit_insn (gen_move_insn (y
, sub
));
1964 /* Don't separate setter from user. */
1965 if (PREV_INSN (insn
) && sets_cc0_p (PREV_INSN (insn
)))
1966 insn
= PREV_INSN (insn
);
1969 emit_insn_before (seq
, insn
);
1977 /* If we already have a replacement, use it. Otherwise,
1978 try to fix up this address in case it is invalid. */
1980 replacement
= find_fixup_replacement (replacements
, var
);
1981 if (replacement
->new)
1983 *loc
= replacement
->new;
1987 *loc
= replacement
->new = x
= fixup_stack_1 (x
, insn
);
1989 /* Unless we are forcing memory to register or we changed the mode,
1990 we can leave things the way they are if the insn is valid. */
1992 INSN_CODE (insn
) = -1;
1993 if (! flag_force_mem
&& GET_MODE (x
) == promoted_mode
1994 && recog_memoized (insn
) >= 0)
1997 *loc
= replacement
->new = gen_reg_rtx (promoted_mode
);
2001 /* If X contains VAR, we need to unshare it here so that we update
2002 each occurrence separately. But all identical MEMs in one insn
2003 must be replaced with the same rtx because of the possibility of
2006 if (reg_mentioned_p (var
, x
))
2008 replacement
= find_fixup_replacement (replacements
, x
);
2009 if (replacement
->new == 0)
2010 replacement
->new = copy_most_rtx (x
, no_share
);
2012 *loc
= x
= replacement
->new;
2013 code
= GET_CODE (x
);
2030 /* Note that in some cases those types of expressions are altered
2031 by optimize_bit_field, and do not survive to get here. */
2032 if (XEXP (x
, 0) == var
2033 || (GET_CODE (XEXP (x
, 0)) == SUBREG
2034 && SUBREG_REG (XEXP (x
, 0)) == var
))
2036 /* Get TEM as a valid MEM in the mode presently in the insn.
2038 We don't worry about the possibility of MATCH_DUP here; it
2039 is highly unlikely and would be tricky to handle. */
2042 if (GET_CODE (tem
) == SUBREG
)
2044 if (GET_MODE_BITSIZE (GET_MODE (tem
))
2045 > GET_MODE_BITSIZE (GET_MODE (var
)))
2047 replacement
= find_fixup_replacement (replacements
, var
);
2048 if (replacement
->new == 0)
2049 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2050 SUBREG_REG (tem
) = replacement
->new;
2052 /* The following code works only if we have a MEM, so we
2053 need to handle the subreg here. We directly substitute
2054 it assuming that a subreg must be OK here. We already
2055 scheduled a replacement to copy the mem into the
2061 tem
= fixup_memory_subreg (tem
, insn
, promoted_mode
, 0);
2064 tem
= fixup_stack_1 (tem
, insn
);
2066 /* Unless we want to load from memory, get TEM into the proper mode
2067 for an extract from memory. This can only be done if the
2068 extract is at a constant position and length. */
2070 if (! flag_force_mem
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
2071 && GET_CODE (XEXP (x
, 2)) == CONST_INT
2072 && ! mode_dependent_address_p (XEXP (tem
, 0))
2073 && ! MEM_VOLATILE_P (tem
))
2075 enum machine_mode wanted_mode
= VOIDmode
;
2076 enum machine_mode is_mode
= GET_MODE (tem
);
2077 HOST_WIDE_INT pos
= INTVAL (XEXP (x
, 2));
2079 if (GET_CODE (x
) == ZERO_EXTRACT
)
2081 enum machine_mode new_mode
2082 = mode_for_extraction (EP_extzv
, 1);
2083 if (new_mode
!= MAX_MACHINE_MODE
)
2084 wanted_mode
= new_mode
;
2086 else if (GET_CODE (x
) == SIGN_EXTRACT
)
2088 enum machine_mode new_mode
2089 = mode_for_extraction (EP_extv
, 1);
2090 if (new_mode
!= MAX_MACHINE_MODE
)
2091 wanted_mode
= new_mode
;
2094 /* If we have a narrower mode, we can do something. */
2095 if (wanted_mode
!= VOIDmode
2096 && GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2098 HOST_WIDE_INT offset
= pos
/ BITS_PER_UNIT
;
2099 rtx old_pos
= XEXP (x
, 2);
2102 /* If the bytes and bits are counted differently, we
2103 must adjust the offset. */
2104 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2105 offset
= (GET_MODE_SIZE (is_mode
)
2106 - GET_MODE_SIZE (wanted_mode
) - offset
);
2108 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2110 newmem
= adjust_address_nv (tem
, wanted_mode
, offset
);
2112 /* Make the change and see if the insn remains valid. */
2113 INSN_CODE (insn
) = -1;
2114 XEXP (x
, 0) = newmem
;
2115 XEXP (x
, 2) = GEN_INT (pos
);
2117 if (recog_memoized (insn
) >= 0)
2120 /* Otherwise, restore old position. XEXP (x, 0) will be
2122 XEXP (x
, 2) = old_pos
;
2126 /* If we get here, the bitfield extract insn can't accept a memory
2127 reference. Copy the input into a register. */
2129 tem1
= gen_reg_rtx (GET_MODE (tem
));
2130 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2137 if (SUBREG_REG (x
) == var
)
2139 /* If this is a special SUBREG made because VAR was promoted
2140 from a wider mode, replace it with VAR and call ourself
2141 recursively, this time saying that the object previously
2142 had its current mode (by virtue of the SUBREG). */
2144 if (SUBREG_PROMOTED_VAR_P (x
))
2147 fixup_var_refs_1 (var
, GET_MODE (var
), loc
, insn
, replacements
,
2152 /* If this SUBREG makes VAR wider, it has become a paradoxical
2153 SUBREG with VAR in memory, but these aren't allowed at this
2154 stage of the compilation. So load VAR into a pseudo and take
2155 a SUBREG of that pseudo. */
2156 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (GET_MODE (var
)))
2158 replacement
= find_fixup_replacement (replacements
, var
);
2159 if (replacement
->new == 0)
2160 replacement
->new = gen_reg_rtx (promoted_mode
);
2161 SUBREG_REG (x
) = replacement
->new;
2165 /* See if we have already found a replacement for this SUBREG.
2166 If so, use it. Otherwise, make a MEM and see if the insn
2167 is recognized. If not, or if we should force MEM into a register,
2168 make a pseudo for this SUBREG. */
2169 replacement
= find_fixup_replacement (replacements
, x
);
2170 if (replacement
->new)
2172 *loc
= replacement
->new;
2176 replacement
->new = *loc
= fixup_memory_subreg (x
, insn
,
2179 INSN_CODE (insn
) = -1;
2180 if (! flag_force_mem
&& recog_memoized (insn
) >= 0)
2183 *loc
= replacement
->new = gen_reg_rtx (GET_MODE (x
));
2189 /* First do special simplification of bit-field references. */
2190 if (GET_CODE (SET_DEST (x
)) == SIGN_EXTRACT
2191 || GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2192 optimize_bit_field (x
, insn
, 0);
2193 if (GET_CODE (SET_SRC (x
)) == SIGN_EXTRACT
2194 || GET_CODE (SET_SRC (x
)) == ZERO_EXTRACT
)
2195 optimize_bit_field (x
, insn
, 0);
2197 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2198 into a register and then store it back out. */
2199 if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
2200 && GET_CODE (XEXP (SET_DEST (x
), 0)) == SUBREG
2201 && SUBREG_REG (XEXP (SET_DEST (x
), 0)) == var
2202 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x
), 0)))
2203 > GET_MODE_SIZE (GET_MODE (var
))))
2205 replacement
= find_fixup_replacement (replacements
, var
);
2206 if (replacement
->new == 0)
2207 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2209 SUBREG_REG (XEXP (SET_DEST (x
), 0)) = replacement
->new;
2210 emit_insn_after (gen_move_insn (var
, replacement
->new), insn
);
2213 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2214 insn into a pseudo and store the low part of the pseudo into VAR. */
2215 if (GET_CODE (SET_DEST (x
)) == SUBREG
2216 && SUBREG_REG (SET_DEST (x
)) == var
2217 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x
)))
2218 > GET_MODE_SIZE (GET_MODE (var
))))
2220 SET_DEST (x
) = tem
= gen_reg_rtx (GET_MODE (SET_DEST (x
)));
2221 emit_insn_after (gen_move_insn (var
, gen_lowpart (GET_MODE (var
),
2228 rtx dest
= SET_DEST (x
);
2229 rtx src
= SET_SRC (x
);
2230 rtx outerdest
= dest
;
2232 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
2233 || GET_CODE (dest
) == SIGN_EXTRACT
2234 || GET_CODE (dest
) == ZERO_EXTRACT
)
2235 dest
= XEXP (dest
, 0);
2237 if (GET_CODE (src
) == SUBREG
)
2238 src
= SUBREG_REG (src
);
2240 /* If VAR does not appear at the top level of the SET
2241 just scan the lower levels of the tree. */
2243 if (src
!= var
&& dest
!= var
)
2246 /* We will need to rerecognize this insn. */
2247 INSN_CODE (insn
) = -1;
2249 if (GET_CODE (outerdest
) == ZERO_EXTRACT
&& dest
== var
2250 && mode_for_extraction (EP_insv
, -1) != MAX_MACHINE_MODE
)
2252 /* Since this case will return, ensure we fixup all the
2254 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 1),
2255 insn
, replacements
, no_share
);
2256 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 2),
2257 insn
, replacements
, no_share
);
2258 fixup_var_refs_1 (var
, promoted_mode
, &SET_SRC (x
),
2259 insn
, replacements
, no_share
);
2261 tem
= XEXP (outerdest
, 0);
2263 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2264 that may appear inside a ZERO_EXTRACT.
2265 This was legitimate when the MEM was a REG. */
2266 if (GET_CODE (tem
) == SUBREG
2267 && SUBREG_REG (tem
) == var
)
2268 tem
= fixup_memory_subreg (tem
, insn
, promoted_mode
, 0);
2270 tem
= fixup_stack_1 (tem
, insn
);
2272 if (GET_CODE (XEXP (outerdest
, 1)) == CONST_INT
2273 && GET_CODE (XEXP (outerdest
, 2)) == CONST_INT
2274 && ! mode_dependent_address_p (XEXP (tem
, 0))
2275 && ! MEM_VOLATILE_P (tem
))
2277 enum machine_mode wanted_mode
;
2278 enum machine_mode is_mode
= GET_MODE (tem
);
2279 HOST_WIDE_INT pos
= INTVAL (XEXP (outerdest
, 2));
2281 wanted_mode
= mode_for_extraction (EP_insv
, 0);
2283 /* If we have a narrower mode, we can do something. */
2284 if (GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2286 HOST_WIDE_INT offset
= pos
/ BITS_PER_UNIT
;
2287 rtx old_pos
= XEXP (outerdest
, 2);
2290 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2291 offset
= (GET_MODE_SIZE (is_mode
)
2292 - GET_MODE_SIZE (wanted_mode
) - offset
);
2294 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2296 newmem
= adjust_address_nv (tem
, wanted_mode
, offset
);
2298 /* Make the change and see if the insn remains valid. */
2299 INSN_CODE (insn
) = -1;
2300 XEXP (outerdest
, 0) = newmem
;
2301 XEXP (outerdest
, 2) = GEN_INT (pos
);
2303 if (recog_memoized (insn
) >= 0)
2306 /* Otherwise, restore old position. XEXP (x, 0) will be
2308 XEXP (outerdest
, 2) = old_pos
;
2312 /* If we get here, the bit-field store doesn't allow memory
2313 or isn't located at a constant position. Load the value into
2314 a register, do the store, and put it back into memory. */
2316 tem1
= gen_reg_rtx (GET_MODE (tem
));
2317 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2318 emit_insn_after (gen_move_insn (tem
, tem1
), insn
);
2319 XEXP (outerdest
, 0) = tem1
;
2323 /* STRICT_LOW_PART is a no-op on memory references
2324 and it can cause combinations to be unrecognizable,
2327 if (dest
== var
&& GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2328 SET_DEST (x
) = XEXP (SET_DEST (x
), 0);
2330 /* A valid insn to copy VAR into or out of a register
2331 must be left alone, to avoid an infinite loop here.
2332 If the reference to VAR is by a subreg, fix that up,
2333 since SUBREG is not valid for a memref.
2334 Also fix up the address of the stack slot.
2336 Note that we must not try to recognize the insn until
2337 after we know that we have valid addresses and no
2338 (subreg (mem ...) ...) constructs, since these interfere
2339 with determining the validity of the insn. */
2341 if ((SET_SRC (x
) == var
2342 || (GET_CODE (SET_SRC (x
)) == SUBREG
2343 && SUBREG_REG (SET_SRC (x
)) == var
))
2344 && (GET_CODE (SET_DEST (x
)) == REG
2345 || (GET_CODE (SET_DEST (x
)) == SUBREG
2346 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
))
2347 && GET_MODE (var
) == promoted_mode
2348 && x
== single_set (insn
))
2352 if (GET_CODE (SET_SRC (x
)) == SUBREG
2353 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x
)))
2354 > GET_MODE_SIZE (GET_MODE (var
))))
2356 /* This (subreg VAR) is now a paradoxical subreg. We need
2357 to replace VAR instead of the subreg. */
2358 replacement
= find_fixup_replacement (replacements
, var
);
2359 if (replacement
->new == NULL_RTX
)
2360 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2361 SUBREG_REG (SET_SRC (x
)) = replacement
->new;
2365 replacement
= find_fixup_replacement (replacements
, SET_SRC (x
));
2366 if (replacement
->new)
2367 SET_SRC (x
) = replacement
->new;
2368 else if (GET_CODE (SET_SRC (x
)) == SUBREG
)
2369 SET_SRC (x
) = replacement
->new
2370 = fixup_memory_subreg (SET_SRC (x
), insn
, promoted_mode
,
2373 SET_SRC (x
) = replacement
->new
2374 = fixup_stack_1 (SET_SRC (x
), insn
);
2377 if (recog_memoized (insn
) >= 0)
2380 /* INSN is not valid, but we know that we want to
2381 copy SET_SRC (x) to SET_DEST (x) in some way. So
2382 we generate the move and see whether it requires more
2383 than one insn. If it does, we emit those insns and
2384 delete INSN. Otherwise, we an just replace the pattern
2385 of INSN; we have already verified above that INSN has
2386 no other function that to do X. */
2388 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2389 if (NEXT_INSN (pat
) != NULL_RTX
)
2391 last
= emit_insn_before (pat
, insn
);
2393 /* INSN might have REG_RETVAL or other important notes, so
2394 we need to store the pattern of the last insn in the
2395 sequence into INSN similarly to the normal case. LAST
2396 should not have REG_NOTES, but we allow them if INSN has
2398 if (REG_NOTES (last
) && REG_NOTES (insn
))
2400 if (REG_NOTES (last
))
2401 REG_NOTES (insn
) = REG_NOTES (last
);
2402 PATTERN (insn
) = PATTERN (last
);
2407 PATTERN (insn
) = PATTERN (pat
);
2412 if ((SET_DEST (x
) == var
2413 || (GET_CODE (SET_DEST (x
)) == SUBREG
2414 && SUBREG_REG (SET_DEST (x
)) == var
))
2415 && (GET_CODE (SET_SRC (x
)) == REG
2416 || (GET_CODE (SET_SRC (x
)) == SUBREG
2417 && GET_CODE (SUBREG_REG (SET_SRC (x
))) == REG
))
2418 && GET_MODE (var
) == promoted_mode
2419 && x
== single_set (insn
))
2423 if (GET_CODE (SET_DEST (x
)) == SUBREG
)
2424 SET_DEST (x
) = fixup_memory_subreg (SET_DEST (x
), insn
,
2427 SET_DEST (x
) = fixup_stack_1 (SET_DEST (x
), insn
);
2429 if (recog_memoized (insn
) >= 0)
2432 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2433 if (NEXT_INSN (pat
) != NULL_RTX
)
2435 last
= emit_insn_before (pat
, insn
);
2437 /* INSN might have REG_RETVAL or other important notes, so
2438 we need to store the pattern of the last insn in the
2439 sequence into INSN similarly to the normal case. LAST
2440 should not have REG_NOTES, but we allow them if INSN has
2442 if (REG_NOTES (last
) && REG_NOTES (insn
))
2444 if (REG_NOTES (last
))
2445 REG_NOTES (insn
) = REG_NOTES (last
);
2446 PATTERN (insn
) = PATTERN (last
);
2451 PATTERN (insn
) = PATTERN (pat
);
2456 /* Otherwise, storing into VAR must be handled specially
2457 by storing into a temporary and copying that into VAR
2458 with a new insn after this one. Note that this case
2459 will be used when storing into a promoted scalar since
2460 the insn will now have different modes on the input
2461 and output and hence will be invalid (except for the case
2462 of setting it to a constant, which does not need any
2463 change if it is valid). We generate extra code in that case,
2464 but combine.c will eliminate it. */
2469 rtx fixeddest
= SET_DEST (x
);
2470 enum machine_mode temp_mode
;
2472 /* STRICT_LOW_PART can be discarded, around a MEM. */
2473 if (GET_CODE (fixeddest
) == STRICT_LOW_PART
)
2474 fixeddest
= XEXP (fixeddest
, 0);
2475 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2476 if (GET_CODE (fixeddest
) == SUBREG
)
2478 fixeddest
= fixup_memory_subreg (fixeddest
, insn
,
2480 temp_mode
= GET_MODE (fixeddest
);
2484 fixeddest
= fixup_stack_1 (fixeddest
, insn
);
2485 temp_mode
= promoted_mode
;
2488 temp
= gen_reg_rtx (temp_mode
);
2490 emit_insn_after (gen_move_insn (fixeddest
,
2491 gen_lowpart (GET_MODE (fixeddest
),
2495 SET_DEST (x
) = temp
;
2503 /* Nothing special about this RTX; fix its operands. */
2505 fmt
= GET_RTX_FORMAT (code
);
2506 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2509 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (x
, i
), insn
, replacements
,
2511 else if (fmt
[i
] == 'E')
2514 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2515 fixup_var_refs_1 (var
, promoted_mode
, &XVECEXP (x
, i
, j
),
2516 insn
, replacements
, no_share
);
2521 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2522 The REG was placed on the stack, so X now has the form (SUBREG:m1
2525 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2526 must be emitted to compute NEWADDR, put them before INSN.
2528 UNCRITICAL nonzero means accept paradoxical subregs.
2529 This is used for subregs found inside REG_NOTES. */
2532 fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
)
2535 enum machine_mode promoted_mode
;
2539 rtx mem
= SUBREG_REG (x
);
2540 rtx addr
= XEXP (mem
, 0);
2541 enum machine_mode mode
= GET_MODE (x
);
2544 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2545 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (mem
)) && ! uncritical
)
2548 offset
= SUBREG_BYTE (x
);
2549 if (BYTES_BIG_ENDIAN
)
2550 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2551 the offset so that it points to the right location within the
2553 offset
-= (GET_MODE_SIZE (promoted_mode
) - GET_MODE_SIZE (GET_MODE (mem
)));
2555 if (!flag_force_addr
2556 && memory_address_p (mode
, plus_constant (addr
, offset
)))
2557 /* Shortcut if no insns need be emitted. */
2558 return adjust_address (mem
, mode
, offset
);
2561 result
= adjust_address (mem
, mode
, offset
);
2565 emit_insn_before (seq
, insn
);
2569 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2570 Replace subexpressions of X in place.
2571 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2572 Otherwise return X, with its contents possibly altered.
2574 INSN, PROMOTED_MODE and UNCRITICAL are as for
2575 fixup_memory_subreg. */
2578 walk_fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
)
2581 enum machine_mode promoted_mode
;
2591 code
= GET_CODE (x
);
2593 if (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == MEM
)
2594 return fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
);
2596 /* Nothing special about this RTX; fix its operands. */
2598 fmt
= GET_RTX_FORMAT (code
);
2599 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2602 XEXP (x
, i
) = walk_fixup_memory_subreg (XEXP (x
, i
), insn
,
2603 promoted_mode
, uncritical
);
2604 else if (fmt
[i
] == 'E')
2607 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2609 = walk_fixup_memory_subreg (XVECEXP (x
, i
, j
), insn
,
2610 promoted_mode
, uncritical
);
2616 /* For each memory ref within X, if it refers to a stack slot
2617 with an out of range displacement, put the address in a temp register
2618 (emitting new insns before INSN to load these registers)
2619 and alter the memory ref to use that register.
2620 Replace each such MEM rtx with a copy, to avoid clobberage. */
2623 fixup_stack_1 (x
, insn
)
2628 RTX_CODE code
= GET_CODE (x
);
2633 rtx ad
= XEXP (x
, 0);
2634 /* If we have address of a stack slot but it's not valid
2635 (displacement is too large), compute the sum in a register. */
2636 if (GET_CODE (ad
) == PLUS
2637 && GET_CODE (XEXP (ad
, 0)) == REG
2638 && ((REGNO (XEXP (ad
, 0)) >= FIRST_VIRTUAL_REGISTER
2639 && REGNO (XEXP (ad
, 0)) <= LAST_VIRTUAL_REGISTER
)
2640 || REGNO (XEXP (ad
, 0)) == FRAME_POINTER_REGNUM
2641 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2642 || REGNO (XEXP (ad
, 0)) == HARD_FRAME_POINTER_REGNUM
2644 || REGNO (XEXP (ad
, 0)) == STACK_POINTER_REGNUM
2645 || REGNO (XEXP (ad
, 0)) == ARG_POINTER_REGNUM
2646 || XEXP (ad
, 0) == current_function_internal_arg_pointer
)
2647 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
)
2650 if (memory_address_p (GET_MODE (x
), ad
))
2654 temp
= copy_to_reg (ad
);
2657 emit_insn_before (seq
, insn
);
2658 return replace_equiv_address (x
, temp
);
2663 fmt
= GET_RTX_FORMAT (code
);
2664 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2667 XEXP (x
, i
) = fixup_stack_1 (XEXP (x
, i
), insn
);
2668 else if (fmt
[i
] == 'E')
2671 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2672 XVECEXP (x
, i
, j
) = fixup_stack_1 (XVECEXP (x
, i
, j
), insn
);
2678 /* Optimization: a bit-field instruction whose field
2679 happens to be a byte or halfword in memory
2680 can be changed to a move instruction.
2682 We call here when INSN is an insn to examine or store into a bit-field.
2683 BODY is the SET-rtx to be altered.
2685 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2686 (Currently this is called only from function.c, and EQUIV_MEM
2690 optimize_bit_field (body
, insn
, equiv_mem
)
2698 enum machine_mode mode
;
2700 if (GET_CODE (SET_DEST (body
)) == SIGN_EXTRACT
2701 || GET_CODE (SET_DEST (body
)) == ZERO_EXTRACT
)
2702 bitfield
= SET_DEST (body
), destflag
= 1;
2704 bitfield
= SET_SRC (body
), destflag
= 0;
2706 /* First check that the field being stored has constant size and position
2707 and is in fact a byte or halfword suitably aligned. */
2709 if (GET_CODE (XEXP (bitfield
, 1)) == CONST_INT
2710 && GET_CODE (XEXP (bitfield
, 2)) == CONST_INT
2711 && ((mode
= mode_for_size (INTVAL (XEXP (bitfield
, 1)), MODE_INT
, 1))
2713 && INTVAL (XEXP (bitfield
, 2)) % INTVAL (XEXP (bitfield
, 1)) == 0)
2717 /* Now check that the containing word is memory, not a register,
2718 and that it is safe to change the machine mode. */
2720 if (GET_CODE (XEXP (bitfield
, 0)) == MEM
)
2721 memref
= XEXP (bitfield
, 0);
2722 else if (GET_CODE (XEXP (bitfield
, 0)) == REG
2724 memref
= equiv_mem
[REGNO (XEXP (bitfield
, 0))];
2725 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2726 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == MEM
)
2727 memref
= SUBREG_REG (XEXP (bitfield
, 0));
2728 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2730 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == REG
)
2731 memref
= equiv_mem
[REGNO (SUBREG_REG (XEXP (bitfield
, 0)))];
2734 && ! mode_dependent_address_p (XEXP (memref
, 0))
2735 && ! MEM_VOLATILE_P (memref
))
2737 /* Now adjust the address, first for any subreg'ing
2738 that we are now getting rid of,
2739 and then for which byte of the word is wanted. */
2741 HOST_WIDE_INT offset
= INTVAL (XEXP (bitfield
, 2));
2744 /* Adjust OFFSET to count bits from low-address byte. */
2745 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
2746 offset
= (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield
, 0)))
2747 - offset
- INTVAL (XEXP (bitfield
, 1)));
2749 /* Adjust OFFSET to count bytes from low-address byte. */
2750 offset
/= BITS_PER_UNIT
;
2751 if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
)
2753 offset
+= (SUBREG_BYTE (XEXP (bitfield
, 0))
2754 / UNITS_PER_WORD
) * UNITS_PER_WORD
;
2755 if (BYTES_BIG_ENDIAN
)
2756 offset
-= (MIN (UNITS_PER_WORD
,
2757 GET_MODE_SIZE (GET_MODE (XEXP (bitfield
, 0))))
2758 - MIN (UNITS_PER_WORD
,
2759 GET_MODE_SIZE (GET_MODE (memref
))));
2763 memref
= adjust_address (memref
, mode
, offset
);
2764 insns
= get_insns ();
2766 emit_insn_before (insns
, insn
);
2768 /* Store this memory reference where
2769 we found the bit field reference. */
2773 validate_change (insn
, &SET_DEST (body
), memref
, 1);
2774 if (! CONSTANT_ADDRESS_P (SET_SRC (body
)))
2776 rtx src
= SET_SRC (body
);
2777 while (GET_CODE (src
) == SUBREG
2778 && SUBREG_BYTE (src
) == 0)
2779 src
= SUBREG_REG (src
);
2780 if (GET_MODE (src
) != GET_MODE (memref
))
2781 src
= gen_lowpart (GET_MODE (memref
), SET_SRC (body
));
2782 validate_change (insn
, &SET_SRC (body
), src
, 1);
2784 else if (GET_MODE (SET_SRC (body
)) != VOIDmode
2785 && GET_MODE (SET_SRC (body
)) != GET_MODE (memref
))
2786 /* This shouldn't happen because anything that didn't have
2787 one of these modes should have got converted explicitly
2788 and then referenced through a subreg.
2789 This is so because the original bit-field was
2790 handled by agg_mode and so its tree structure had
2791 the same mode that memref now has. */
2796 rtx dest
= SET_DEST (body
);
2798 while (GET_CODE (dest
) == SUBREG
2799 && SUBREG_BYTE (dest
) == 0
2800 && (GET_MODE_CLASS (GET_MODE (dest
))
2801 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest
))))
2802 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
2804 dest
= SUBREG_REG (dest
);
2806 validate_change (insn
, &SET_DEST (body
), dest
, 1);
2808 if (GET_MODE (dest
) == GET_MODE (memref
))
2809 validate_change (insn
, &SET_SRC (body
), memref
, 1);
2812 /* Convert the mem ref to the destination mode. */
2813 rtx newreg
= gen_reg_rtx (GET_MODE (dest
));
2816 convert_move (newreg
, memref
,
2817 GET_CODE (SET_SRC (body
)) == ZERO_EXTRACT
);
2821 validate_change (insn
, &SET_SRC (body
), newreg
, 1);
2825 /* See if we can convert this extraction or insertion into
2826 a simple move insn. We might not be able to do so if this
2827 was, for example, part of a PARALLEL.
2829 If we succeed, write out any needed conversions. If we fail,
2830 it is hard to guess why we failed, so don't do anything
2831 special; just let the optimization be suppressed. */
2833 if (apply_change_group () && seq
)
2834 emit_insn_before (seq
, insn
);
2839 /* These routines are responsible for converting virtual register references
2840 to the actual hard register references once RTL generation is complete.
2842 The following four variables are used for communication between the
2843 routines. They contain the offsets of the virtual registers from their
2844 respective hard registers. */
2846 static int in_arg_offset
;
2847 static int var_offset
;
2848 static int dynamic_offset
;
2849 static int out_arg_offset
;
2850 static int cfa_offset
;
2852 /* In most machines, the stack pointer register is equivalent to the bottom
2855 #ifndef STACK_POINTER_OFFSET
2856 #define STACK_POINTER_OFFSET 0
2859 /* If not defined, pick an appropriate default for the offset of dynamically
2860 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2861 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2863 #ifndef STACK_DYNAMIC_OFFSET
2865 /* The bottom of the stack points to the actual arguments. If
2866 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2867 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2868 stack space for register parameters is not pushed by the caller, but
2869 rather part of the fixed stack areas and hence not included in
2870 `current_function_outgoing_args_size'. Nevertheless, we must allow
2871 for it when allocating stack dynamic objects. */
2873 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2874 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2875 ((ACCUMULATE_OUTGOING_ARGS \
2876 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2877 + (STACK_POINTER_OFFSET)) \
2880 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2881 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2882 + (STACK_POINTER_OFFSET))
2886 /* On most machines, the CFA coincides with the first incoming parm. */
2888 #ifndef ARG_POINTER_CFA_OFFSET
2889 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2892 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2893 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2894 register, for later use if we do need to force REG into the stack. REG is
2895 overwritten by the MEM like in put_reg_into_stack. */
2898 gen_mem_addressof (reg
, decl
)
2902 rtx r
= gen_rtx_ADDRESSOF (Pmode
, gen_reg_rtx (GET_MODE (reg
)),
2905 /* Calculate this before we start messing with decl's RTL. */
2906 HOST_WIDE_INT set
= decl
? get_alias_set (decl
) : 0;
2908 /* If the original REG was a user-variable, then so is the REG whose
2909 address is being taken. Likewise for unchanging. */
2910 REG_USERVAR_P (XEXP (r
, 0)) = REG_USERVAR_P (reg
);
2911 RTX_UNCHANGING_P (XEXP (r
, 0)) = RTX_UNCHANGING_P (reg
);
2913 PUT_CODE (reg
, MEM
);
2914 MEM_ATTRS (reg
) = 0;
2919 tree type
= TREE_TYPE (decl
);
2920 enum machine_mode decl_mode
2921 = (DECL_P (decl
) ? DECL_MODE (decl
) : TYPE_MODE (TREE_TYPE (decl
)));
2922 rtx decl_rtl
= (TREE_CODE (decl
) == SAVE_EXPR
? SAVE_EXPR_RTL (decl
)
2923 : DECL_RTL_IF_SET (decl
));
2925 PUT_MODE (reg
, decl_mode
);
2927 /* Clear DECL_RTL momentarily so functions below will work
2928 properly, then set it again. */
2929 if (DECL_P (decl
) && decl_rtl
== reg
)
2930 SET_DECL_RTL (decl
, 0);
2932 set_mem_attributes (reg
, decl
, 1);
2933 set_mem_alias_set (reg
, set
);
2935 if (DECL_P (decl
) && decl_rtl
== reg
)
2936 SET_DECL_RTL (decl
, reg
);
2938 if (TREE_USED (decl
) || (DECL_P (decl
) && DECL_INITIAL (decl
) != 0))
2939 fixup_var_refs (reg
, GET_MODE (reg
), TREE_UNSIGNED (type
), reg
, 0);
2942 fixup_var_refs (reg
, GET_MODE (reg
), 0, reg
, 0);
2947 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2950 flush_addressof (decl
)
2953 if ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
2954 && DECL_RTL (decl
) != 0
2955 && GET_CODE (DECL_RTL (decl
)) == MEM
2956 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
2957 && GET_CODE (XEXP (XEXP (DECL_RTL (decl
), 0), 0)) == REG
)
2958 put_addressof_into_stack (XEXP (DECL_RTL (decl
), 0), 0);
2961 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2964 put_addressof_into_stack (r
, ht
)
2969 int volatile_p
, used_p
;
2971 rtx reg
= XEXP (r
, 0);
2973 if (GET_CODE (reg
) != REG
)
2976 decl
= ADDRESSOF_DECL (r
);
2979 type
= TREE_TYPE (decl
);
2980 volatile_p
= (TREE_CODE (decl
) != SAVE_EXPR
2981 && TREE_THIS_VOLATILE (decl
));
2982 used_p
= (TREE_USED (decl
)
2983 || (DECL_P (decl
) && DECL_INITIAL (decl
) != 0));
2992 put_reg_into_stack (0, reg
, type
, GET_MODE (reg
), GET_MODE (reg
),
2993 volatile_p
, ADDRESSOF_REGNO (r
), used_p
, ht
);
2996 /* List of replacements made below in purge_addressof_1 when creating
2997 bitfield insertions. */
2998 static rtx purge_bitfield_addressof_replacements
;
3000 /* List of replacements made below in purge_addressof_1 for patterns
3001 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
3002 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
3003 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
3004 enough in complex cases, e.g. when some field values can be
3005 extracted by usage MEM with narrower mode. */
3006 static rtx purge_addressof_replacements
;
3008 /* Helper function for purge_addressof. See if the rtx expression at *LOC
3009 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
3010 the stack. If the function returns FALSE then the replacement could not
3014 purge_addressof_1 (loc
, insn
, force
, store
, ht
)
3026 /* Re-start here to avoid recursion in common cases. */
3033 code
= GET_CODE (x
);
3035 /* If we don't return in any of the cases below, we will recurse inside
3036 the RTX, which will normally result in any ADDRESSOF being forced into
3040 result
= purge_addressof_1 (&SET_DEST (x
), insn
, force
, 1, ht
);
3041 result
&= purge_addressof_1 (&SET_SRC (x
), insn
, force
, 0, ht
);
3044 else if (code
== ADDRESSOF
)
3048 if (GET_CODE (XEXP (x
, 0)) != MEM
)
3050 put_addressof_into_stack (x
, ht
);
3054 /* We must create a copy of the rtx because it was created by
3055 overwriting a REG rtx which is always shared. */
3056 sub
= copy_rtx (XEXP (XEXP (x
, 0), 0));
3057 if (validate_change (insn
, loc
, sub
, 0)
3058 || validate_replace_rtx (x
, sub
, insn
))
3062 sub
= force_operand (sub
, NULL_RTX
);
3063 if (! validate_change (insn
, loc
, sub
, 0)
3064 && ! validate_replace_rtx (x
, sub
, insn
))
3067 insns
= get_insns ();
3069 emit_insn_before (insns
, insn
);
3073 else if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == ADDRESSOF
&& ! force
)
3075 rtx sub
= XEXP (XEXP (x
, 0), 0);
3077 if (GET_CODE (sub
) == MEM
)
3078 sub
= adjust_address_nv (sub
, GET_MODE (x
), 0);
3079 else if (GET_CODE (sub
) == REG
3080 && (MEM_VOLATILE_P (x
) || GET_MODE (x
) == BLKmode
))
3082 else if (GET_CODE (sub
) == REG
&& GET_MODE (x
) != GET_MODE (sub
))
3084 int size_x
, size_sub
;
3088 /* When processing REG_NOTES look at the list of
3089 replacements done on the insn to find the register that X
3093 for (tem
= purge_bitfield_addressof_replacements
;
3095 tem
= XEXP (XEXP (tem
, 1), 1))
3096 if (rtx_equal_p (x
, XEXP (tem
, 0)))
3098 *loc
= XEXP (XEXP (tem
, 1), 0);
3102 /* See comment for purge_addressof_replacements. */
3103 for (tem
= purge_addressof_replacements
;
3105 tem
= XEXP (XEXP (tem
, 1), 1))
3106 if (rtx_equal_p (XEXP (x
, 0), XEXP (tem
, 0)))
3108 rtx z
= XEXP (XEXP (tem
, 1), 0);
3110 if (GET_MODE (x
) == GET_MODE (z
)
3111 || (GET_CODE (XEXP (XEXP (tem
, 1), 0)) != REG
3112 && GET_CODE (XEXP (XEXP (tem
, 1), 0)) != SUBREG
))
3115 /* It can happen that the note may speak of things
3116 in a wider (or just different) mode than the
3117 code did. This is especially true of
3120 if (GET_CODE (z
) == SUBREG
&& SUBREG_BYTE (z
) == 0)
3123 if (GET_MODE_SIZE (GET_MODE (x
)) > UNITS_PER_WORD
3124 && (GET_MODE_SIZE (GET_MODE (x
))
3125 > GET_MODE_SIZE (GET_MODE (z
))))
3127 /* This can occur as a result in invalid
3128 pointer casts, e.g. float f; ...
3129 *(long long int *)&f.
3130 ??? We could emit a warning here, but
3131 without a line number that wouldn't be
3133 z
= gen_rtx_SUBREG (GET_MODE (x
), z
, 0);
3136 z
= gen_lowpart (GET_MODE (x
), z
);
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 /* Don't even consider working with paradoxical subregs,
3156 or the moral equivalent seen here. */
3157 if (size_x
<= size_sub
3158 && int_mode_for_mode (GET_MODE (sub
)) != BLKmode
)
3160 /* Do a bitfield insertion to mirror what would happen
3167 rtx p
= PREV_INSN (insn
);
3170 val
= gen_reg_rtx (GET_MODE (x
));
3171 if (! validate_change (insn
, loc
, val
, 0))
3173 /* Discard the current sequence and put the
3174 ADDRESSOF on stack. */
3180 emit_insn_before (seq
, insn
);
3181 compute_insns_for_mem (p
? NEXT_INSN (p
) : get_insns (),
3185 store_bit_field (sub
, size_x
, 0, GET_MODE (x
),
3186 val
, GET_MODE_SIZE (GET_MODE (sub
)));
3188 /* Make sure to unshare any shared rtl that store_bit_field
3189 might have created. */
3190 unshare_all_rtl_again (get_insns ());
3194 p
= emit_insn_after (seq
, insn
);
3195 if (NEXT_INSN (insn
))
3196 compute_insns_for_mem (NEXT_INSN (insn
),
3197 p
? NEXT_INSN (p
) : NULL_RTX
,
3202 rtx p
= PREV_INSN (insn
);
3205 val
= extract_bit_field (sub
, size_x
, 0, 1, NULL_RTX
,
3206 GET_MODE (x
), GET_MODE (x
),
3207 GET_MODE_SIZE (GET_MODE (sub
)));
3209 if (! validate_change (insn
, loc
, val
, 0))
3211 /* Discard the current sequence and put the
3212 ADDRESSOF on stack. */
3219 emit_insn_before (seq
, insn
);
3220 compute_insns_for_mem (p
? NEXT_INSN (p
) : get_insns (),
3224 /* Remember the replacement so that the same one can be done
3225 on the REG_NOTES. */
3226 purge_bitfield_addressof_replacements
3227 = gen_rtx_EXPR_LIST (VOIDmode
, x
,
3230 purge_bitfield_addressof_replacements
));
3232 /* We replaced with a reg -- all done. */
3237 else if (validate_change (insn
, loc
, sub
, 0))
3239 /* Remember the replacement so that the same one can be done
3240 on the REG_NOTES. */
3241 if (GET_CODE (sub
) == REG
|| GET_CODE (sub
) == SUBREG
)
3245 for (tem
= purge_addressof_replacements
;
3247 tem
= XEXP (XEXP (tem
, 1), 1))
3248 if (rtx_equal_p (XEXP (x
, 0), XEXP (tem
, 0)))
3250 XEXP (XEXP (tem
, 1), 0) = sub
;
3253 purge_addressof_replacements
3254 = gen_rtx (EXPR_LIST
, VOIDmode
, XEXP (x
, 0),
3255 gen_rtx_EXPR_LIST (VOIDmode
, sub
,
3256 purge_addressof_replacements
));
3264 /* Scan all subexpressions. */
3265 fmt
= GET_RTX_FORMAT (code
);
3266 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3269 result
&= purge_addressof_1 (&XEXP (x
, i
), insn
, force
, 0, ht
);
3270 else if (*fmt
== 'E')
3271 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3272 result
&= purge_addressof_1 (&XVECEXP (x
, i
, j
), insn
, force
, 0, ht
);
3278 /* Return a hash value for K, a REG. */
3281 insns_for_mem_hash (k
)
3284 /* Use the address of the key for the hash value. */
3285 struct insns_for_mem_entry
*m
= (struct insns_for_mem_entry
*) k
;
3286 return (hashval_t
) m
->key
;
3289 /* Return non-zero if K1 and K2 (two REGs) are the same. */
3292 insns_for_mem_comp (k1
, k2
)
3296 struct insns_for_mem_entry
*m1
= (struct insns_for_mem_entry
*) k1
;
3297 struct insns_for_mem_entry
*m2
= (struct insns_for_mem_entry
*) k2
;
3298 return m1
->key
== m2
->key
;
3301 struct insns_for_mem_walk_info
3303 /* The hash table that we are using to record which INSNs use which
3307 /* The INSN we are currently processing. */
3310 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3311 to find the insns that use the REGs in the ADDRESSOFs. */
3315 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3316 that might be used in an ADDRESSOF expression, record this INSN in
3317 the hash table given by DATA (which is really a pointer to an
3318 insns_for_mem_walk_info structure). */
3321 insns_for_mem_walk (r
, data
)
3325 struct insns_for_mem_walk_info
*ifmwi
3326 = (struct insns_for_mem_walk_info
*) data
;
3327 struct insns_for_mem_entry tmp
;
3328 tmp
.insns
= NULL_RTX
;
3330 if (ifmwi
->pass
== 0 && *r
&& GET_CODE (*r
) == ADDRESSOF
3331 && GET_CODE (XEXP (*r
, 0)) == REG
)
3334 tmp
.key
= XEXP (*r
, 0);
3335 e
= htab_find_slot (ifmwi
->ht
, &tmp
, INSERT
);
3338 *e
= ggc_alloc (sizeof (tmp
));
3339 memcpy (*e
, &tmp
, sizeof (tmp
));
3342 else if (ifmwi
->pass
== 1 && *r
&& GET_CODE (*r
) == REG
)
3344 struct insns_for_mem_entry
*ifme
;
3346 ifme
= (struct insns_for_mem_entry
*) htab_find (ifmwi
->ht
, &tmp
);
3348 /* If we have not already recorded this INSN, do so now. Since
3349 we process the INSNs in order, we know that if we have
3350 recorded it it must be at the front of the list. */
3351 if (ifme
&& (!ifme
->insns
|| XEXP (ifme
->insns
, 0) != ifmwi
->insn
))
3352 ifme
->insns
= gen_rtx_EXPR_LIST (VOIDmode
, ifmwi
->insn
,
3359 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3360 which REGs in HT. */
3363 compute_insns_for_mem (insns
, last_insn
, 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 (rtl
, data
)
3387 void *data ATTRIBUTE_UNUSED
;
3389 return GET_CODE (*rtl
) == ADDRESSOF
;
3392 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3393 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3397 purge_addressof (insns
)
3403 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3404 requires a fixup pass over the instruction stream to correct
3405 INSNs that depended on the REG being a REG, and not a MEM. But,
3406 these fixup passes are slow. Furthermore, most MEMs are not
3407 mentioned in very many instructions. So, we speed up the process
3408 by pre-calculating which REGs occur in which INSNs; that allows
3409 us to perform the fixup passes much more quickly. */
3410 ht
= htab_create_ggc (1000, insns_for_mem_hash
, insns_for_mem_comp
, NULL
);
3411 compute_insns_for_mem (insns
, NULL_RTX
, ht
);
3413 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3414 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
3415 || GET_CODE (insn
) == CALL_INSN
)
3417 if (! purge_addressof_1 (&PATTERN (insn
), insn
,
3418 asm_noperands (PATTERN (insn
)) > 0, 0, ht
))
3419 /* If we could not replace the ADDRESSOFs in the insn,
3420 something is wrong. */
3423 if (! purge_addressof_1 (®_NOTES (insn
), NULL_RTX
, 0, 0, ht
))
3425 /* If we could not replace the ADDRESSOFs in the insn's notes,
3426 we can just remove the offending notes instead. */
3429 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
3431 /* If we find a REG_RETVAL note then the insn is a libcall.
3432 Such insns must have REG_EQUAL notes as well, in order
3433 for later passes of the compiler to work. So it is not
3434 safe to delete the notes here, and instead we abort. */
3435 if (REG_NOTE_KIND (note
) == REG_RETVAL
)
3437 if (for_each_rtx (¬e
, is_addressof
, NULL
))
3438 remove_note (insn
, note
);
3444 purge_bitfield_addressof_replacements
= 0;
3445 purge_addressof_replacements
= 0;
3447 /* REGs are shared. purge_addressof will destructively replace a REG
3448 with a MEM, which creates shared MEMs.
3450 Unfortunately, the children of put_reg_into_stack assume that MEMs
3451 referring to the same stack slot are shared (fixup_var_refs and
3452 the associated hash table code).
3454 So, we have to do another unsharing pass after we have flushed any
3455 REGs that had their address taken into the stack.
3457 It may be worth tracking whether or not we converted any REGs into
3458 MEMs to avoid this overhead when it is not needed. */
3459 unshare_all_rtl_again (get_insns ());
3462 /* Convert a SET of a hard subreg to a set of the appropriate hard
3463 register. A subroutine of purge_hard_subreg_sets. */
3466 purge_single_hard_subreg_set (pattern
)
3469 rtx reg
= SET_DEST (pattern
);
3470 enum machine_mode mode
= GET_MODE (SET_DEST (pattern
));
3473 if (GET_CODE (reg
) == SUBREG
&& GET_CODE (SUBREG_REG (reg
)) == REG
3474 && REGNO (SUBREG_REG (reg
)) < FIRST_PSEUDO_REGISTER
)
3476 offset
= subreg_regno_offset (REGNO (SUBREG_REG (reg
)),
3477 GET_MODE (SUBREG_REG (reg
)),
3480 reg
= SUBREG_REG (reg
);
3484 if (GET_CODE (reg
) == REG
&& REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
3486 reg
= gen_rtx_REG (mode
, REGNO (reg
) + offset
);
3487 SET_DEST (pattern
) = reg
;
3491 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3492 only such SETs that we expect to see are those left in because
3493 integrate can't handle sets of parts of a return value register.
3495 We don't use alter_subreg because we only want to eliminate subregs
3496 of hard registers. */
3499 purge_hard_subreg_sets (insn
)
3502 for (; insn
; insn
= NEXT_INSN (insn
))
3506 rtx pattern
= PATTERN (insn
);
3507 switch (GET_CODE (pattern
))
3510 if (GET_CODE (SET_DEST (pattern
)) == SUBREG
)
3511 purge_single_hard_subreg_set (pattern
);
3516 for (j
= XVECLEN (pattern
, 0) - 1; j
>= 0; j
--)
3518 rtx inner_pattern
= XVECEXP (pattern
, 0, j
);
3519 if (GET_CODE (inner_pattern
) == SET
3520 && GET_CODE (SET_DEST (inner_pattern
)) == SUBREG
)
3521 purge_single_hard_subreg_set (inner_pattern
);
3532 /* Pass through the INSNS of function FNDECL and convert virtual register
3533 references to hard register references. */
3536 instantiate_virtual_regs (fndecl
, insns
)
3543 /* Compute the offsets to use for this function. */
3544 in_arg_offset
= FIRST_PARM_OFFSET (fndecl
);
3545 var_offset
= STARTING_FRAME_OFFSET
;
3546 dynamic_offset
= STACK_DYNAMIC_OFFSET (fndecl
);
3547 out_arg_offset
= STACK_POINTER_OFFSET
;
3548 cfa_offset
= ARG_POINTER_CFA_OFFSET (fndecl
);
3550 /* Scan all variables and parameters of this function. For each that is
3551 in memory, instantiate all virtual registers if the result is a valid
3552 address. If not, we do it later. That will handle most uses of virtual
3553 regs on many machines. */
3554 instantiate_decls (fndecl
, 1);
3556 /* Initialize recognition, indicating that volatile is OK. */
3559 /* Scan through all the insns, instantiating every virtual register still
3561 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3562 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
3563 || GET_CODE (insn
) == CALL_INSN
)
3565 instantiate_virtual_regs_1 (&PATTERN (insn
), insn
, 1);
3566 instantiate_virtual_regs_1 (®_NOTES (insn
), NULL_RTX
, 0);
3567 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3568 if (GET_CODE (insn
) == CALL_INSN
)
3569 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn
),
3573 /* Instantiate the stack slots for the parm registers, for later use in
3574 addressof elimination. */
3575 for (i
= 0; i
< max_parm_reg
; ++i
)
3576 if (parm_reg_stack_loc
[i
])
3577 instantiate_virtual_regs_1 (&parm_reg_stack_loc
[i
], NULL_RTX
, 0);
3579 /* Now instantiate the remaining register equivalences for debugging info.
3580 These will not be valid addresses. */
3581 instantiate_decls (fndecl
, 0);
3583 /* Indicate that, from now on, assign_stack_local should use
3584 frame_pointer_rtx. */
3585 virtuals_instantiated
= 1;
3588 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3589 all virtual registers in their DECL_RTL's.
3591 If VALID_ONLY, do this only if the resulting address is still valid.
3592 Otherwise, always do it. */
3595 instantiate_decls (fndecl
, valid_only
)
3601 /* Process all parameters of the function. */
3602 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= TREE_CHAIN (decl
))
3604 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (decl
));
3605 HOST_WIDE_INT size_rtl
;
3607 instantiate_decl (DECL_RTL (decl
), size
, valid_only
);
3609 /* If the parameter was promoted, then the incoming RTL mode may be
3610 larger than the declared type size. We must use the larger of
3612 size_rtl
= GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl
)));
3613 size
= MAX (size_rtl
, size
);
3614 instantiate_decl (DECL_INCOMING_RTL (decl
), size
, valid_only
);
3617 /* Now process all variables defined in the function or its subblocks. */
3618 instantiate_decls_1 (DECL_INITIAL (fndecl
), valid_only
);
3621 /* Subroutine of instantiate_decls: Process all decls in the given
3622 BLOCK node and all its subblocks. */
3625 instantiate_decls_1 (let
, valid_only
)
3631 for (t
= BLOCK_VARS (let
); t
; t
= TREE_CHAIN (t
))
3632 if (DECL_RTL_SET_P (t
))
3633 instantiate_decl (DECL_RTL (t
),
3634 int_size_in_bytes (TREE_TYPE (t
)),
3637 /* Process all subblocks. */
3638 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= TREE_CHAIN (t
))
3639 instantiate_decls_1 (t
, valid_only
);
3642 /* Subroutine of the preceding procedures: Given RTL representing a
3643 decl and the size of the object, do any instantiation required.
3645 If VALID_ONLY is non-zero, it means that the RTL should only be
3646 changed if the new address is valid. */
3649 instantiate_decl (x
, size
, valid_only
)
3654 enum machine_mode mode
;
3657 /* If this is not a MEM, no need to do anything. Similarly if the
3658 address is a constant or a register that is not a virtual register. */
3660 if (x
== 0 || GET_CODE (x
) != MEM
)
3664 if (CONSTANT_P (addr
)
3665 || (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == REG
)
3666 || (GET_CODE (addr
) == REG
3667 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
3668 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
3671 /* If we should only do this if the address is valid, copy the address.
3672 We need to do this so we can undo any changes that might make the
3673 address invalid. This copy is unfortunate, but probably can't be
3677 addr
= copy_rtx (addr
);
3679 instantiate_virtual_regs_1 (&addr
, NULL_RTX
, 0);
3681 if (valid_only
&& size
>= 0)
3683 unsigned HOST_WIDE_INT decl_size
= size
;
3685 /* Now verify that the resulting address is valid for every integer or
3686 floating-point mode up to and including SIZE bytes long. We do this
3687 since the object might be accessed in any mode and frame addresses
3690 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3691 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= decl_size
;
3692 mode
= GET_MODE_WIDER_MODE (mode
))
3693 if (! memory_address_p (mode
, addr
))
3696 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
3697 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= decl_size
;
3698 mode
= GET_MODE_WIDER_MODE (mode
))
3699 if (! memory_address_p (mode
, addr
))
3703 /* Put back the address now that we have updated it and we either know
3704 it is valid or we don't care whether it is valid. */
3709 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3710 is a virtual register, return the equivalent hard register and set the
3711 offset indirectly through the pointer. Otherwise, return 0. */
3714 instantiate_new_reg (x
, poffset
)
3716 HOST_WIDE_INT
*poffset
;
3719 HOST_WIDE_INT offset
;
3721 if (x
== virtual_incoming_args_rtx
)
3722 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3723 else if (x
== virtual_stack_vars_rtx
)
3724 new = frame_pointer_rtx
, offset
= var_offset
;
3725 else if (x
== virtual_stack_dynamic_rtx
)
3726 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3727 else if (x
== virtual_outgoing_args_rtx
)
3728 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3729 else if (x
== virtual_cfa_rtx
)
3730 new = arg_pointer_rtx
, offset
= cfa_offset
;
3738 /* Given a pointer to a piece of rtx and an optional pointer to the
3739 containing object, instantiate any virtual registers present in it.
3741 If EXTRA_INSNS, we always do the replacement and generate
3742 any extra insns before OBJECT. If it zero, we do nothing if replacement
3745 Return 1 if we either had nothing to do or if we were able to do the
3746 needed replacement. Return 0 otherwise; we only return zero if
3747 EXTRA_INSNS is zero.
3749 We first try some simple transformations to avoid the creation of extra
3753 instantiate_virtual_regs_1 (loc
, object
, extra_insns
)
3761 HOST_WIDE_INT offset
= 0;
3767 /* Re-start here to avoid recursion in common cases. */
3774 code
= GET_CODE (x
);
3776 /* Check for some special cases. */
3794 /* We are allowed to set the virtual registers. This means that
3795 the actual register should receive the source minus the
3796 appropriate offset. This is used, for example, in the handling
3797 of non-local gotos. */
3798 if ((new = instantiate_new_reg (SET_DEST (x
), &offset
)) != 0)
3800 rtx src
= SET_SRC (x
);
3802 /* We are setting the register, not using it, so the relevant
3803 offset is the negative of the offset to use were we using
3806 instantiate_virtual_regs_1 (&src
, NULL_RTX
, 0);
3808 /* The only valid sources here are PLUS or REG. Just do
3809 the simplest possible thing to handle them. */
3810 if (GET_CODE (src
) != REG
&& GET_CODE (src
) != PLUS
)
3814 if (GET_CODE (src
) != REG
)
3815 temp
= force_operand (src
, NULL_RTX
);
3818 temp
= force_operand (plus_constant (temp
, offset
), NULL_RTX
);
3822 emit_insn_before (seq
, object
);
3825 if (! validate_change (object
, &SET_SRC (x
), temp
, 0)
3832 instantiate_virtual_regs_1 (&SET_DEST (x
), object
, extra_insns
);
3837 /* Handle special case of virtual register plus constant. */
3838 if (CONSTANT_P (XEXP (x
, 1)))
3840 rtx old
, new_offset
;
3842 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3843 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
3845 if ((new = instantiate_new_reg (XEXP (XEXP (x
, 0), 0), &offset
)))
3847 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 1), object
,
3849 new = gen_rtx_PLUS (Pmode
, new, XEXP (XEXP (x
, 0), 1));
3858 #ifdef POINTERS_EXTEND_UNSIGNED
3859 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3860 we can commute the PLUS and SUBREG because pointers into the
3861 frame are well-behaved. */
3862 else if (GET_CODE (XEXP (x
, 0)) == SUBREG
&& GET_MODE (x
) == ptr_mode
3863 && GET_CODE (XEXP (x
, 1)) == CONST_INT
3865 = instantiate_new_reg (SUBREG_REG (XEXP (x
, 0)),
3867 && validate_change (object
, loc
,
3868 plus_constant (gen_lowpart (ptr_mode
,
3871 + INTVAL (XEXP (x
, 1))),
3875 else if ((new = instantiate_new_reg (XEXP (x
, 0), &offset
)) == 0)
3877 /* We know the second operand is a constant. Unless the
3878 first operand is a REG (which has been already checked),
3879 it needs to be checked. */
3880 if (GET_CODE (XEXP (x
, 0)) != REG
)
3888 new_offset
= plus_constant (XEXP (x
, 1), offset
);
3890 /* If the new constant is zero, try to replace the sum with just
3892 if (new_offset
== const0_rtx
3893 && validate_change (object
, loc
, new, 0))
3896 /* Next try to replace the register and new offset.
3897 There are two changes to validate here and we can't assume that
3898 in the case of old offset equals new just changing the register
3899 will yield a valid insn. In the interests of a little efficiency,
3900 however, we only call validate change once (we don't queue up the
3901 changes and then call apply_change_group). */
3905 ? ! validate_change (object
, &XEXP (x
, 0), new, 0)
3906 : (XEXP (x
, 0) = new,
3907 ! validate_change (object
, &XEXP (x
, 1), new_offset
, 0)))
3915 /* Otherwise copy the new constant into a register and replace
3916 constant with that register. */
3917 temp
= gen_reg_rtx (Pmode
);
3919 if (validate_change (object
, &XEXP (x
, 1), temp
, 0))
3920 emit_insn_before (gen_move_insn (temp
, new_offset
), object
);
3923 /* If that didn't work, replace this expression with a
3924 register containing the sum. */
3927 new = gen_rtx_PLUS (Pmode
, new, new_offset
);
3930 temp
= force_operand (new, NULL_RTX
);
3934 emit_insn_before (seq
, object
);
3935 if (! validate_change (object
, loc
, temp
, 0)
3936 && ! validate_replace_rtx (x
, temp
, object
))
3944 /* Fall through to generic two-operand expression case. */
3950 case DIV
: case UDIV
:
3951 case MOD
: case UMOD
:
3952 case AND
: case IOR
: case XOR
:
3953 case ROTATERT
: case ROTATE
:
3954 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
3956 case GE
: case GT
: case GEU
: case GTU
:
3957 case LE
: case LT
: case LEU
: case LTU
:
3958 if (XEXP (x
, 1) && ! CONSTANT_P (XEXP (x
, 1)))
3959 instantiate_virtual_regs_1 (&XEXP (x
, 1), object
, extra_insns
);
3964 /* Most cases of MEM that convert to valid addresses have already been
3965 handled by our scan of decls. The only special handling we
3966 need here is to make a copy of the rtx to ensure it isn't being
3967 shared if we have to change it to a pseudo.
3969 If the rtx is a simple reference to an address via a virtual register,
3970 it can potentially be shared. In such cases, first try to make it
3971 a valid address, which can also be shared. Otherwise, copy it and
3974 First check for common cases that need no processing. These are
3975 usually due to instantiation already being done on a previous instance
3979 if (CONSTANT_ADDRESS_P (temp
)
3980 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3981 || temp
== arg_pointer_rtx
3983 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3984 || temp
== hard_frame_pointer_rtx
3986 || temp
== frame_pointer_rtx
)
3989 if (GET_CODE (temp
) == PLUS
3990 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3991 && (XEXP (temp
, 0) == frame_pointer_rtx
3992 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3993 || XEXP (temp
, 0) == hard_frame_pointer_rtx
3995 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3996 || XEXP (temp
, 0) == arg_pointer_rtx
4001 if (temp
== virtual_stack_vars_rtx
4002 || temp
== virtual_incoming_args_rtx
4003 || (GET_CODE (temp
) == PLUS
4004 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
4005 && (XEXP (temp
, 0) == virtual_stack_vars_rtx
4006 || XEXP (temp
, 0) == virtual_incoming_args_rtx
)))
4008 /* This MEM may be shared. If the substitution can be done without
4009 the need to generate new pseudos, we want to do it in place
4010 so all copies of the shared rtx benefit. The call below will
4011 only make substitutions if the resulting address is still
4014 Note that we cannot pass X as the object in the recursive call
4015 since the insn being processed may not allow all valid
4016 addresses. However, if we were not passed on object, we can
4017 only modify X without copying it if X will have a valid
4020 ??? Also note that this can still lose if OBJECT is an insn that
4021 has less restrictions on an address that some other insn.
4022 In that case, we will modify the shared address. This case
4023 doesn't seem very likely, though. One case where this could
4024 happen is in the case of a USE or CLOBBER reference, but we
4025 take care of that below. */
4027 if (instantiate_virtual_regs_1 (&XEXP (x
, 0),
4028 object
? object
: x
, 0))
4031 /* Otherwise make a copy and process that copy. We copy the entire
4032 RTL expression since it might be a PLUS which could also be
4034 *loc
= x
= copy_rtx (x
);
4037 /* Fall through to generic unary operation case. */
4040 case STRICT_LOW_PART
:
4042 case PRE_DEC
: case PRE_INC
: case POST_DEC
: case POST_INC
:
4043 case SIGN_EXTEND
: case ZERO_EXTEND
:
4044 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
4045 case FLOAT
: case FIX
:
4046 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
4050 /* These case either have just one operand or we know that we need not
4051 check the rest of the operands. */
4057 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4058 go ahead and make the invalid one, but do it to a copy. For a REG,
4059 just make the recursive call, since there's no chance of a problem. */
4061 if ((GET_CODE (XEXP (x
, 0)) == MEM
4062 && instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), XEXP (x
, 0),
4064 || (GET_CODE (XEXP (x
, 0)) == REG
4065 && instantiate_virtual_regs_1 (&XEXP (x
, 0), object
, 0)))
4068 XEXP (x
, 0) = copy_rtx (XEXP (x
, 0));
4073 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4074 in front of this insn and substitute the temporary. */
4075 if ((new = instantiate_new_reg (x
, &offset
)) != 0)
4077 temp
= plus_constant (new, offset
);
4078 if (!validate_change (object
, loc
, temp
, 0))
4084 temp
= force_operand (temp
, NULL_RTX
);
4088 emit_insn_before (seq
, object
);
4089 if (! validate_change (object
, loc
, temp
, 0)
4090 && ! validate_replace_rtx (x
, temp
, object
))
4098 if (GET_CODE (XEXP (x
, 0)) == REG
)
4101 else if (GET_CODE (XEXP (x
, 0)) == MEM
)
4103 /* If we have a (addressof (mem ..)), do any instantiation inside
4104 since we know we'll be making the inside valid when we finally
4105 remove the ADDRESSOF. */
4106 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), NULL_RTX
, 0);
4115 /* Scan all subexpressions. */
4116 fmt
= GET_RTX_FORMAT (code
);
4117 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
4120 if (!instantiate_virtual_regs_1 (&XEXP (x
, i
), object
, extra_insns
))
4123 else if (*fmt
== 'E')
4124 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4125 if (! instantiate_virtual_regs_1 (&XVECEXP (x
, i
, j
), object
,
4132 /* Optimization: assuming this function does not receive nonlocal gotos,
4133 delete the handlers for such, as well as the insns to establish
4134 and disestablish them. */
4140 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4142 /* Delete the handler by turning off the flag that would
4143 prevent jump_optimize from deleting it.
4144 Also permit deletion of the nonlocal labels themselves
4145 if nothing local refers to them. */
4146 if (GET_CODE (insn
) == CODE_LABEL
)
4150 LABEL_PRESERVE_P (insn
) = 0;
4152 /* Remove it from the nonlocal_label list, to avoid confusing
4154 for (t
= nonlocal_labels
, last_t
= 0; t
;
4155 last_t
= t
, t
= TREE_CHAIN (t
))
4156 if (DECL_RTL (TREE_VALUE (t
)) == insn
)
4161 nonlocal_labels
= TREE_CHAIN (nonlocal_labels
);
4163 TREE_CHAIN (last_t
) = TREE_CHAIN (t
);
4166 if (GET_CODE (insn
) == INSN
)
4170 for (t
= nonlocal_goto_handler_slots
; t
!= 0; t
= XEXP (t
, 1))
4171 if (reg_mentioned_p (t
, PATTERN (insn
)))
4177 || (nonlocal_goto_stack_level
!= 0
4178 && reg_mentioned_p (nonlocal_goto_stack_level
,
4180 delete_related_insns (insn
);
4188 return max_parm_reg
;
4191 /* Return the first insn following those generated by `assign_parms'. */
4194 get_first_nonparm_insn ()
4197 return NEXT_INSN (last_parm_insn
);
4198 return get_insns ();
4201 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4202 Crash if there is none. */
4205 get_first_block_beg ()
4208 rtx insn
= get_first_nonparm_insn ();
4210 for (searcher
= insn
; searcher
; searcher
= NEXT_INSN (searcher
))
4211 if (GET_CODE (searcher
) == NOTE
4212 && NOTE_LINE_NUMBER (searcher
) == NOTE_INSN_BLOCK_BEG
)
4215 abort (); /* Invalid call to this function. (See comments above.) */
4219 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4220 This means a type for which function calls must pass an address to the
4221 function or get an address back from the function.
4222 EXP may be a type node or an expression (whose type is tested). */
4225 aggregate_value_p (exp
)
4228 int i
, regno
, nregs
;
4231 tree type
= (TYPE_P (exp
)) ? exp
: TREE_TYPE (exp
);
4233 if (TREE_CODE (type
) == VOID_TYPE
)
4235 if (RETURN_IN_MEMORY (type
))
4237 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4238 and thus can't be returned in registers. */
4239 if (TREE_ADDRESSABLE (type
))
4241 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
4243 /* Make sure we have suitable call-clobbered regs to return
4244 the value in; if not, we must return it in memory. */
4245 reg
= hard_function_value (type
, 0, 0);
4247 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4249 if (GET_CODE (reg
) != REG
)
4252 regno
= REGNO (reg
);
4253 nregs
= HARD_REGNO_NREGS (regno
, TYPE_MODE (type
));
4254 for (i
= 0; i
< nregs
; i
++)
4255 if (! call_used_regs
[regno
+ i
])
4260 /* Assign RTL expressions to the function's parameters.
4261 This may involve copying them into registers and using
4262 those registers as the RTL for them. */
4265 assign_parms (fndecl
)
4271 CUMULATIVE_ARGS args_so_far
;
4272 enum machine_mode promoted_mode
, passed_mode
;
4273 enum machine_mode nominal_mode
, promoted_nominal_mode
;
4275 /* Total space needed so far for args on the stack,
4276 given as a constant and a tree-expression. */
4277 struct args_size stack_args_size
;
4278 tree fntype
= TREE_TYPE (fndecl
);
4279 tree fnargs
= DECL_ARGUMENTS (fndecl
);
4280 /* This is used for the arg pointer when referring to stack args. */
4281 rtx internal_arg_pointer
;
4282 /* This is a dummy PARM_DECL that we used for the function result if
4283 the function returns a structure. */
4284 tree function_result_decl
= 0;
4285 #ifdef SETUP_INCOMING_VARARGS
4286 int varargs_setup
= 0;
4288 rtx conversion_insns
= 0;
4289 struct args_size alignment_pad
;
4291 /* Nonzero if function takes extra anonymous args.
4292 This means the last named arg must be on the stack
4293 right before the anonymous ones. */
4295 = (TYPE_ARG_TYPES (fntype
) != 0
4296 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
4297 != void_type_node
));
4299 current_function_stdarg
= stdarg
;
4301 /* If the reg that the virtual arg pointer will be translated into is
4302 not a fixed reg or is the stack pointer, make a copy of the virtual
4303 arg pointer, and address parms via the copy. The frame pointer is
4304 considered fixed even though it is not marked as such.
4306 The second time through, simply use ap to avoid generating rtx. */
4308 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
4309 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
4310 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
)))
4311 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
4313 internal_arg_pointer
= virtual_incoming_args_rtx
;
4314 current_function_internal_arg_pointer
= internal_arg_pointer
;
4316 stack_args_size
.constant
= 0;
4317 stack_args_size
.var
= 0;
4319 /* If struct value address is treated as the first argument, make it so. */
4320 if (aggregate_value_p (DECL_RESULT (fndecl
))
4321 && ! current_function_returns_pcc_struct
4322 && struct_value_incoming_rtx
== 0)
4324 tree type
= build_pointer_type (TREE_TYPE (fntype
));
4326 function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
4328 DECL_ARG_TYPE (function_result_decl
) = type
;
4329 TREE_CHAIN (function_result_decl
) = fnargs
;
4330 fnargs
= function_result_decl
;
4333 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
4334 parm_reg_stack_loc
= (rtx
*) ggc_alloc_cleared (max_parm_reg
* sizeof (rtx
));
4336 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4337 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far
, fntype
, NULL_RTX
);
4339 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, 0);
4342 /* We haven't yet found an argument that we must push and pretend the
4344 current_function_pretend_args_size
= 0;
4346 for (parm
= fnargs
; parm
; parm
= TREE_CHAIN (parm
))
4348 struct args_size stack_offset
;
4349 struct args_size arg_size
;
4350 int passed_pointer
= 0;
4351 int did_conversion
= 0;
4352 tree passed_type
= DECL_ARG_TYPE (parm
);
4353 tree nominal_type
= TREE_TYPE (parm
);
4355 int last_named
= 0, named_arg
;
4357 /* Set LAST_NAMED if this is last named arg before last
4363 for (tem
= TREE_CHAIN (parm
); tem
; tem
= TREE_CHAIN (tem
))
4364 if (DECL_NAME (tem
))
4370 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4371 most machines, if this is a varargs/stdarg function, then we treat
4372 the last named arg as if it were anonymous too. */
4373 named_arg
= STRICT_ARGUMENT_NAMING
? 1 : ! last_named
;
4375 if (TREE_TYPE (parm
) == error_mark_node
4376 /* This can happen after weird syntax errors
4377 or if an enum type is defined among the parms. */
4378 || TREE_CODE (parm
) != PARM_DECL
4379 || passed_type
== NULL
)
4381 SET_DECL_RTL (parm
, gen_rtx_MEM (BLKmode
, const0_rtx
));
4382 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
4383 TREE_USED (parm
) = 1;
4387 /* Find mode of arg as it is passed, and mode of arg
4388 as it should be during execution of this function. */
4389 passed_mode
= TYPE_MODE (passed_type
);
4390 nominal_mode
= TYPE_MODE (nominal_type
);
4392 /* If the parm's mode is VOID, its value doesn't matter,
4393 and avoid the usual things like emit_move_insn that could crash. */
4394 if (nominal_mode
== VOIDmode
)
4396 SET_DECL_RTL (parm
, const0_rtx
);
4397 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
4401 /* If the parm is to be passed as a transparent union, use the
4402 type of the first field for the tests below. We have already
4403 verified that the modes are the same. */
4404 if (DECL_TRANSPARENT_UNION (parm
)
4405 || (TREE_CODE (passed_type
) == UNION_TYPE
4406 && TYPE_TRANSPARENT_UNION (passed_type
)))
4407 passed_type
= TREE_TYPE (TYPE_FIELDS (passed_type
));
4409 /* See if this arg was passed by invisible reference. It is if
4410 it is an object whose size depends on the contents of the
4411 object itself or if the machine requires these objects be passed
4414 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
4415 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
4416 || TREE_ADDRESSABLE (passed_type
)
4417 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4418 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
, passed_mode
,
4419 passed_type
, named_arg
)
4423 passed_type
= nominal_type
= build_pointer_type (passed_type
);
4425 passed_mode
= nominal_mode
= Pmode
;
4427 /* See if the frontend wants to pass this by invisible reference. */
4428 else if (passed_type
!= nominal_type
4429 && POINTER_TYPE_P (passed_type
)
4430 && TREE_TYPE (passed_type
) == nominal_type
)
4432 nominal_type
= passed_type
;
4434 passed_mode
= nominal_mode
= Pmode
;
4437 promoted_mode
= passed_mode
;
4439 #ifdef PROMOTE_FUNCTION_ARGS
4440 /* Compute the mode in which the arg is actually extended to. */
4441 unsignedp
= TREE_UNSIGNED (passed_type
);
4442 promoted_mode
= promote_mode (passed_type
, promoted_mode
, &unsignedp
, 1);
4445 /* Let machine desc say which reg (if any) the parm arrives in.
4446 0 means it arrives on the stack. */
4447 #ifdef FUNCTION_INCOMING_ARG
4448 entry_parm
= FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
4449 passed_type
, named_arg
);
4451 entry_parm
= FUNCTION_ARG (args_so_far
, promoted_mode
,
4452 passed_type
, named_arg
);
4455 if (entry_parm
== 0)
4456 promoted_mode
= passed_mode
;
4458 #ifdef SETUP_INCOMING_VARARGS
4459 /* If this is the last named parameter, do any required setup for
4460 varargs or stdargs. We need to know about the case of this being an
4461 addressable type, in which case we skip the registers it
4462 would have arrived in.
4464 For stdargs, LAST_NAMED will be set for two parameters, the one that
4465 is actually the last named, and the dummy parameter. We only
4466 want to do this action once.
4468 Also, indicate when RTL generation is to be suppressed. */
4469 if (last_named
&& !varargs_setup
)
4471 SETUP_INCOMING_VARARGS (args_so_far
, promoted_mode
, passed_type
,
4472 current_function_pretend_args_size
, 0);
4477 /* Determine parm's home in the stack,
4478 in case it arrives in the stack or we should pretend it did.
4480 Compute the stack position and rtx where the argument arrives
4483 There is one complexity here: If this was a parameter that would
4484 have been passed in registers, but wasn't only because it is
4485 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4486 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4487 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4488 0 as it was the previous time. */
4490 pretend_named
= named_arg
|| PRETEND_OUTGOING_VARARGS_NAMED
;
4491 locate_and_pad_parm (promoted_mode
, passed_type
,
4492 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4495 #ifdef FUNCTION_INCOMING_ARG
4496 FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
4498 pretend_named
) != 0,
4500 FUNCTION_ARG (args_so_far
, promoted_mode
,
4502 pretend_named
) != 0,
4505 fndecl
, &stack_args_size
, &stack_offset
, &arg_size
,
4509 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
4511 if (offset_rtx
== const0_rtx
)
4512 stack_parm
= gen_rtx_MEM (promoted_mode
, internal_arg_pointer
);
4514 stack_parm
= gen_rtx_MEM (promoted_mode
,
4515 gen_rtx_PLUS (Pmode
,
4516 internal_arg_pointer
,
4519 set_mem_attributes (stack_parm
, parm
, 1);
4522 /* If this parameter was passed both in registers and in the stack,
4523 use the copy on the stack. */
4524 if (MUST_PASS_IN_STACK (promoted_mode
, passed_type
))
4527 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4528 /* If this parm was passed part in regs and part in memory,
4529 pretend it arrived entirely in memory
4530 by pushing the register-part onto the stack.
4532 In the special case of a DImode or DFmode that is split,
4533 we could put it together in a pseudoreg directly,
4534 but for now that's not worth bothering with. */
4538 int nregs
= FUNCTION_ARG_PARTIAL_NREGS (args_so_far
, promoted_mode
,
4539 passed_type
, named_arg
);
4543 current_function_pretend_args_size
4544 = (((nregs
* UNITS_PER_WORD
) + (PARM_BOUNDARY
/ BITS_PER_UNIT
) - 1)
4545 / (PARM_BOUNDARY
/ BITS_PER_UNIT
)
4546 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4548 /* Handle calls that pass values in multiple non-contiguous
4549 locations. The Irix 6 ABI has examples of this. */
4550 if (GET_CODE (entry_parm
) == PARALLEL
)
4551 emit_group_store (validize_mem (stack_parm
), entry_parm
,
4552 int_size_in_bytes (TREE_TYPE (parm
)));
4555 move_block_from_reg (REGNO (entry_parm
),
4556 validize_mem (stack_parm
), nregs
,
4557 int_size_in_bytes (TREE_TYPE (parm
)));
4559 entry_parm
= stack_parm
;
4564 /* If we didn't decide this parm came in a register,
4565 by default it came on the stack. */
4566 if (entry_parm
== 0)
4567 entry_parm
= stack_parm
;
4569 /* Record permanently how this parm was passed. */
4570 DECL_INCOMING_RTL (parm
) = entry_parm
;
4572 /* If there is actually space on the stack for this parm,
4573 count it in stack_args_size; otherwise set stack_parm to 0
4574 to indicate there is no preallocated stack slot for the parm. */
4576 if (entry_parm
== stack_parm
4577 || (GET_CODE (entry_parm
) == PARALLEL
4578 && XEXP (XVECEXP (entry_parm
, 0, 0), 0) == NULL_RTX
)
4579 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4580 /* On some machines, even if a parm value arrives in a register
4581 there is still an (uninitialized) stack slot allocated for it.
4583 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4584 whether this parameter already has a stack slot allocated,
4585 because an arg block exists only if current_function_args_size
4586 is larger than some threshold, and we haven't calculated that
4587 yet. So, for now, we just assume that stack slots never exist
4589 || REG_PARM_STACK_SPACE (fndecl
) > 0
4593 stack_args_size
.constant
+= arg_size
.constant
;
4595 ADD_PARM_SIZE (stack_args_size
, arg_size
.var
);
4598 /* No stack slot was pushed for this parm. */
4601 /* Update info on where next arg arrives in registers. */
4603 FUNCTION_ARG_ADVANCE (args_so_far
, promoted_mode
,
4604 passed_type
, named_arg
);
4606 /* If we can't trust the parm stack slot to be aligned enough
4607 for its ultimate type, don't use that slot after entry.
4608 We'll make another stack slot, if we need one. */
4610 unsigned int thisparm_boundary
4611 = FUNCTION_ARG_BOUNDARY (promoted_mode
, passed_type
);
4613 if (GET_MODE_ALIGNMENT (nominal_mode
) > thisparm_boundary
)
4617 /* If parm was passed in memory, and we need to convert it on entry,
4618 don't store it back in that same slot. */
4620 && nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
)
4623 /* When an argument is passed in multiple locations, we can't
4624 make use of this information, but we can save some copying if
4625 the whole argument is passed in a single register. */
4626 if (GET_CODE (entry_parm
) == PARALLEL
4627 && nominal_mode
!= BLKmode
&& passed_mode
!= BLKmode
)
4629 int i
, len
= XVECLEN (entry_parm
, 0);
4631 for (i
= 0; i
< len
; i
++)
4632 if (XEXP (XVECEXP (entry_parm
, 0, i
), 0) != NULL_RTX
4633 && GET_CODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0)) == REG
4634 && (GET_MODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
4636 && INTVAL (XEXP (XVECEXP (entry_parm
, 0, i
), 1)) == 0)
4638 entry_parm
= XEXP (XVECEXP (entry_parm
, 0, i
), 0);
4639 DECL_INCOMING_RTL (parm
) = entry_parm
;
4644 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4645 in the mode in which it arrives.
4646 STACK_PARM is an RTX for a stack slot where the parameter can live
4647 during the function (in case we want to put it there).
4648 STACK_PARM is 0 if no stack slot was pushed for it.
4650 Now output code if necessary to convert ENTRY_PARM to
4651 the type in which this function declares it,
4652 and store that result in an appropriate place,
4653 which may be a pseudo reg, may be STACK_PARM,
4654 or may be a local stack slot if STACK_PARM is 0.
4656 Set DECL_RTL to that place. */
4658 if (nominal_mode
== BLKmode
|| GET_CODE (entry_parm
) == PARALLEL
)
4660 /* If a BLKmode arrives in registers, copy it to a stack slot.
4661 Handle calls that pass values in multiple non-contiguous
4662 locations. The Irix 6 ABI has examples of this. */
4663 if (GET_CODE (entry_parm
) == REG
4664 || GET_CODE (entry_parm
) == PARALLEL
)
4667 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm
)),
4670 /* Note that we will be storing an integral number of words.
4671 So we have to be careful to ensure that we allocate an
4672 integral number of words. We do this below in the
4673 assign_stack_local if space was not allocated in the argument
4674 list. If it was, this will not work if PARM_BOUNDARY is not
4675 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4676 if it becomes a problem. */
4678 if (stack_parm
== 0)
4681 = assign_stack_local (GET_MODE (entry_parm
),
4683 set_mem_attributes (stack_parm
, parm
, 1);
4686 else if (PARM_BOUNDARY
% BITS_PER_WORD
!= 0)
4689 /* Handle calls that pass values in multiple non-contiguous
4690 locations. The Irix 6 ABI has examples of this. */
4691 if (GET_CODE (entry_parm
) == PARALLEL
)
4692 emit_group_store (validize_mem (stack_parm
), entry_parm
,
4693 int_size_in_bytes (TREE_TYPE (parm
)));
4695 move_block_from_reg (REGNO (entry_parm
),
4696 validize_mem (stack_parm
),
4697 size_stored
/ UNITS_PER_WORD
,
4698 int_size_in_bytes (TREE_TYPE (parm
)));
4700 SET_DECL_RTL (parm
, stack_parm
);
4702 else if (! ((! optimize
4703 && ! DECL_REGISTER (parm
))
4704 || TREE_SIDE_EFFECTS (parm
)
4705 /* If -ffloat-store specified, don't put explicit
4706 float variables into registers. */
4707 || (flag_float_store
4708 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))
4709 /* Always assign pseudo to structure return or item passed
4710 by invisible reference. */
4711 || passed_pointer
|| parm
== function_result_decl
)
4713 /* Store the parm in a pseudoregister during the function, but we
4714 may need to do it in a wider mode. */
4717 unsigned int regno
, regnoi
= 0, regnor
= 0;
4719 unsignedp
= TREE_UNSIGNED (TREE_TYPE (parm
));
4721 promoted_nominal_mode
4722 = promote_mode (TREE_TYPE (parm
), nominal_mode
, &unsignedp
, 0);
4724 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
4725 mark_user_reg (parmreg
);
4727 /* If this was an item that we received a pointer to, set DECL_RTL
4731 rtx x
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type
)),
4733 set_mem_attributes (x
, parm
, 1);
4734 SET_DECL_RTL (parm
, x
);
4738 SET_DECL_RTL (parm
, parmreg
);
4739 maybe_set_unchanging (DECL_RTL (parm
), parm
);
4742 /* Copy the value into the register. */
4743 if (nominal_mode
!= passed_mode
4744 || promoted_nominal_mode
!= promoted_mode
)
4747 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4748 mode, by the caller. We now have to convert it to
4749 NOMINAL_MODE, if different. However, PARMREG may be in
4750 a different mode than NOMINAL_MODE if it is being stored
4753 If ENTRY_PARM is a hard register, it might be in a register
4754 not valid for operating in its mode (e.g., an odd-numbered
4755 register for a DFmode). In that case, moves are the only
4756 thing valid, so we can't do a convert from there. This
4757 occurs when the calling sequence allow such misaligned
4760 In addition, the conversion may involve a call, which could
4761 clobber parameters which haven't been copied to pseudo
4762 registers yet. Therefore, we must first copy the parm to
4763 a pseudo reg here, and save the conversion until after all
4764 parameters have been moved. */
4766 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4768 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4770 push_to_sequence (conversion_insns
);
4771 tempreg
= convert_to_mode (nominal_mode
, tempreg
, unsignedp
);
4773 if (GET_CODE (tempreg
) == SUBREG
4774 && GET_MODE (tempreg
) == nominal_mode
4775 && GET_CODE (SUBREG_REG (tempreg
)) == REG
4776 && nominal_mode
== passed_mode
4777 && GET_MODE (SUBREG_REG (tempreg
)) == GET_MODE (entry_parm
)
4778 && GET_MODE_SIZE (GET_MODE (tempreg
))
4779 < GET_MODE_SIZE (GET_MODE (entry_parm
)))
4781 /* The argument is already sign/zero extended, so note it
4783 SUBREG_PROMOTED_VAR_P (tempreg
) = 1;
4784 SUBREG_PROMOTED_UNSIGNED_SET (tempreg
, unsignedp
);
4787 /* TREE_USED gets set erroneously during expand_assignment. */
4788 save_tree_used
= TREE_USED (parm
);
4789 expand_assignment (parm
,
4790 make_tree (nominal_type
, tempreg
), 0, 0);
4791 TREE_USED (parm
) = save_tree_used
;
4792 conversion_insns
= get_insns ();
4797 emit_move_insn (parmreg
, validize_mem (entry_parm
));
4799 /* If we were passed a pointer but the actual value
4800 can safely live in a register, put it in one. */
4801 if (passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
4802 /* If by-reference argument was promoted, demote it. */
4803 && (TYPE_MODE (TREE_TYPE (parm
)) != GET_MODE (DECL_RTL (parm
))
4805 && ! DECL_REGISTER (parm
))
4806 || TREE_SIDE_EFFECTS (parm
)
4807 /* If -ffloat-store specified, don't put explicit
4808 float variables into registers. */
4809 || (flag_float_store
4810 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))))
4812 /* We can't use nominal_mode, because it will have been set to
4813 Pmode above. We must use the actual mode of the parm. */
4814 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
4815 mark_user_reg (parmreg
);
4816 if (GET_MODE (parmreg
) != GET_MODE (DECL_RTL (parm
)))
4818 rtx tempreg
= gen_reg_rtx (GET_MODE (DECL_RTL (parm
)));
4819 int unsigned_p
= TREE_UNSIGNED (TREE_TYPE (parm
));
4820 push_to_sequence (conversion_insns
);
4821 emit_move_insn (tempreg
, DECL_RTL (parm
));
4823 convert_to_mode (GET_MODE (parmreg
),
4826 emit_move_insn (parmreg
, DECL_RTL (parm
));
4827 conversion_insns
= get_insns();
4832 emit_move_insn (parmreg
, DECL_RTL (parm
));
4833 SET_DECL_RTL (parm
, parmreg
);
4834 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4838 #ifdef FUNCTION_ARG_CALLEE_COPIES
4839 /* If we are passed an arg by reference and it is our responsibility
4840 to make a copy, do it now.
4841 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4842 original argument, so we must recreate them in the call to
4843 FUNCTION_ARG_CALLEE_COPIES. */
4844 /* ??? Later add code to handle the case that if the argument isn't
4845 modified, don't do the copy. */
4847 else if (passed_pointer
4848 && FUNCTION_ARG_CALLEE_COPIES (args_so_far
,
4849 TYPE_MODE (DECL_ARG_TYPE (parm
)),
4850 DECL_ARG_TYPE (parm
),
4852 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm
)))
4855 tree type
= DECL_ARG_TYPE (parm
);
4857 /* This sequence may involve a library call perhaps clobbering
4858 registers that haven't been copied to pseudos yet. */
4860 push_to_sequence (conversion_insns
);
4862 if (!COMPLETE_TYPE_P (type
)
4863 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4864 /* This is a variable sized object. */
4865 copy
= gen_rtx_MEM (BLKmode
,
4866 allocate_dynamic_stack_space
4867 (expr_size (parm
), NULL_RTX
,
4868 TYPE_ALIGN (type
)));
4870 copy
= assign_stack_temp (TYPE_MODE (type
),
4871 int_size_in_bytes (type
), 1);
4872 set_mem_attributes (copy
, parm
, 1);
4874 store_expr (parm
, copy
, 0);
4875 emit_move_insn (parmreg
, XEXP (copy
, 0));
4876 conversion_insns
= get_insns ();
4880 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4882 /* In any case, record the parm's desired stack location
4883 in case we later discover it must live in the stack.
4885 If it is a COMPLEX value, store the stack location for both
4888 if (GET_CODE (parmreg
) == CONCAT
)
4889 regno
= MAX (REGNO (XEXP (parmreg
, 0)), REGNO (XEXP (parmreg
, 1)));
4891 regno
= REGNO (parmreg
);
4893 if (regno
>= max_parm_reg
)
4896 int old_max_parm_reg
= max_parm_reg
;
4898 /* It's slow to expand this one register at a time,
4899 but it's also rare and we need max_parm_reg to be
4900 precisely correct. */
4901 max_parm_reg
= regno
+ 1;
4902 new = (rtx
*) ggc_realloc (parm_reg_stack_loc
,
4903 max_parm_reg
* sizeof (rtx
));
4904 memset ((char *) (new + old_max_parm_reg
), 0,
4905 (max_parm_reg
- old_max_parm_reg
) * sizeof (rtx
));
4906 parm_reg_stack_loc
= new;
4909 if (GET_CODE (parmreg
) == CONCAT
)
4911 enum machine_mode submode
= GET_MODE (XEXP (parmreg
, 0));
4913 regnor
= REGNO (gen_realpart (submode
, parmreg
));
4914 regnoi
= REGNO (gen_imagpart (submode
, parmreg
));
4916 if (stack_parm
!= 0)
4918 parm_reg_stack_loc
[regnor
]
4919 = gen_realpart (submode
, stack_parm
);
4920 parm_reg_stack_loc
[regnoi
]
4921 = gen_imagpart (submode
, stack_parm
);
4925 parm_reg_stack_loc
[regnor
] = 0;
4926 parm_reg_stack_loc
[regnoi
] = 0;
4930 parm_reg_stack_loc
[REGNO (parmreg
)] = stack_parm
;
4932 /* Mark the register as eliminable if we did no conversion
4933 and it was copied from memory at a fixed offset,
4934 and the arg pointer was not copied to a pseudo-reg.
4935 If the arg pointer is a pseudo reg or the offset formed
4936 an invalid address, such memory-equivalences
4937 as we make here would screw up life analysis for it. */
4938 if (nominal_mode
== passed_mode
4941 && GET_CODE (stack_parm
) == MEM
4942 && stack_offset
.var
== 0
4943 && reg_mentioned_p (virtual_incoming_args_rtx
,
4944 XEXP (stack_parm
, 0)))
4946 rtx linsn
= get_last_insn ();
4949 /* Mark complex types separately. */
4950 if (GET_CODE (parmreg
) == CONCAT
)
4951 /* Scan backwards for the set of the real and
4953 for (sinsn
= linsn
; sinsn
!= 0;
4954 sinsn
= prev_nonnote_insn (sinsn
))
4956 set
= single_set (sinsn
);
4958 && SET_DEST (set
) == regno_reg_rtx
[regnoi
])
4960 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4961 parm_reg_stack_loc
[regnoi
],
4964 && SET_DEST (set
) == regno_reg_rtx
[regnor
])
4966 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4967 parm_reg_stack_loc
[regnor
],
4970 else if ((set
= single_set (linsn
)) != 0
4971 && SET_DEST (set
) == parmreg
)
4973 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4974 stack_parm
, REG_NOTES (linsn
));
4977 /* For pointer data type, suggest pointer register. */
4978 if (POINTER_TYPE_P (TREE_TYPE (parm
)))
4979 mark_reg_pointer (parmreg
,
4980 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
4982 /* If something wants our address, try to use ADDRESSOF. */
4983 if (TREE_ADDRESSABLE (parm
))
4985 /* If we end up putting something into the stack,
4986 fixup_var_refs_insns will need to make a pass over
4987 all the instructions. It looks through the pending
4988 sequences -- but it can't see the ones in the
4989 CONVERSION_INSNS, if they're not on the sequence
4990 stack. So, we go back to that sequence, just so that
4991 the fixups will happen. */
4992 push_to_sequence (conversion_insns
);
4993 put_var_into_stack (parm
);
4994 conversion_insns
= get_insns ();
5000 /* Value must be stored in the stack slot STACK_PARM
5001 during function execution. */
5003 if (promoted_mode
!= nominal_mode
)
5005 /* Conversion is required. */
5006 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
5008 emit_move_insn (tempreg
, validize_mem (entry_parm
));
5010 push_to_sequence (conversion_insns
);
5011 entry_parm
= convert_to_mode (nominal_mode
, tempreg
,
5012 TREE_UNSIGNED (TREE_TYPE (parm
)));
5014 /* ??? This may need a big-endian conversion on sparc64. */
5015 stack_parm
= adjust_address (stack_parm
, nominal_mode
, 0);
5017 conversion_insns
= get_insns ();
5022 if (entry_parm
!= stack_parm
)
5024 if (stack_parm
== 0)
5027 = assign_stack_local (GET_MODE (entry_parm
),
5028 GET_MODE_SIZE (GET_MODE (entry_parm
)), 0);
5029 set_mem_attributes (stack_parm
, parm
, 1);
5032 if (promoted_mode
!= nominal_mode
)
5034 push_to_sequence (conversion_insns
);
5035 emit_move_insn (validize_mem (stack_parm
),
5036 validize_mem (entry_parm
));
5037 conversion_insns
= get_insns ();
5041 emit_move_insn (validize_mem (stack_parm
),
5042 validize_mem (entry_parm
));
5045 SET_DECL_RTL (parm
, stack_parm
);
5048 /* If this "parameter" was the place where we are receiving the
5049 function's incoming structure pointer, set up the result. */
5050 if (parm
== function_result_decl
)
5052 tree result
= DECL_RESULT (fndecl
);
5053 rtx addr
= DECL_RTL (parm
);
5056 #ifdef POINTERS_EXTEND_UNSIGNED
5057 if (GET_MODE (addr
) != Pmode
)
5058 addr
= convert_memory_address (Pmode
, addr
);
5061 x
= gen_rtx_MEM (DECL_MODE (result
), addr
);
5062 set_mem_attributes (x
, result
, 1);
5063 SET_DECL_RTL (result
, x
);
5066 if (GET_CODE (DECL_RTL (parm
)) == REG
)
5067 REGNO_DECL (REGNO (DECL_RTL (parm
))) = parm
;
5068 else if (GET_CODE (DECL_RTL (parm
)) == CONCAT
)
5070 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm
), 0))) = parm
;
5071 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm
), 1))) = parm
;
5076 /* Output all parameter conversion instructions (possibly including calls)
5077 now that all parameters have been copied out of hard registers. */
5078 emit_insn (conversion_insns
);
5080 last_parm_insn
= get_last_insn ();
5082 current_function_args_size
= stack_args_size
.constant
;
5084 /* Adjust function incoming argument size for alignment and
5087 #ifdef REG_PARM_STACK_SPACE
5088 #ifndef MAYBE_REG_PARM_STACK_SPACE
5089 current_function_args_size
= MAX (current_function_args_size
,
5090 REG_PARM_STACK_SPACE (fndecl
));
5094 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5096 current_function_args_size
5097 = ((current_function_args_size
+ STACK_BYTES
- 1)
5098 / STACK_BYTES
) * STACK_BYTES
;
5100 #ifdef ARGS_GROW_DOWNWARD
5101 current_function_arg_offset_rtx
5102 = (stack_args_size
.var
== 0 ? GEN_INT (-stack_args_size
.constant
)
5103 : expand_expr (size_diffop (stack_args_size
.var
,
5104 size_int (-stack_args_size
.constant
)),
5105 NULL_RTX
, VOIDmode
, 0));
5107 current_function_arg_offset_rtx
= ARGS_SIZE_RTX (stack_args_size
);
5110 /* See how many bytes, if any, of its args a function should try to pop
5113 current_function_pops_args
= RETURN_POPS_ARGS (fndecl
, TREE_TYPE (fndecl
),
5114 current_function_args_size
);
5116 /* For stdarg.h function, save info about
5117 regs and stack space used by the named args. */
5119 current_function_args_info
= args_so_far
;
5121 /* Set the rtx used for the function return value. Put this in its
5122 own variable so any optimizers that need this information don't have
5123 to include tree.h. Do this here so it gets done when an inlined
5124 function gets output. */
5126 current_function_return_rtx
5127 = (DECL_RTL_SET_P (DECL_RESULT (fndecl
))
5128 ? DECL_RTL (DECL_RESULT (fndecl
)) : NULL_RTX
);
5130 /* If scalar return value was computed in a pseudo-reg, or was a named
5131 return value that got dumped to the stack, copy that to the hard
5133 if (DECL_RTL_SET_P (DECL_RESULT (fndecl
)))
5135 tree decl_result
= DECL_RESULT (fndecl
);
5136 rtx decl_rtl
= DECL_RTL (decl_result
);
5138 if (REG_P (decl_rtl
)
5139 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
5140 : DECL_REGISTER (decl_result
))
5144 #ifdef FUNCTION_OUTGOING_VALUE
5145 real_decl_rtl
= FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result
),
5148 real_decl_rtl
= FUNCTION_VALUE (TREE_TYPE (decl_result
),
5151 REG_FUNCTION_VALUE_P (real_decl_rtl
) = 1;
5152 /* The delay slot scheduler assumes that current_function_return_rtx
5153 holds the hard register containing the return value, not a
5154 temporary pseudo. */
5155 current_function_return_rtx
= real_decl_rtl
;
5160 /* Indicate whether REGNO is an incoming argument to the current function
5161 that was promoted to a wider mode. If so, return the RTX for the
5162 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5163 that REGNO is promoted from and whether the promotion was signed or
5166 #ifdef PROMOTE_FUNCTION_ARGS
5169 promoted_input_arg (regno
, pmode
, punsignedp
)
5171 enum machine_mode
*pmode
;
5176 for (arg
= DECL_ARGUMENTS (current_function_decl
); arg
;
5177 arg
= TREE_CHAIN (arg
))
5178 if (GET_CODE (DECL_INCOMING_RTL (arg
)) == REG
5179 && REGNO (DECL_INCOMING_RTL (arg
)) == regno
5180 && TYPE_MODE (DECL_ARG_TYPE (arg
)) == TYPE_MODE (TREE_TYPE (arg
)))
5182 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (arg
));
5183 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (arg
));
5185 mode
= promote_mode (TREE_TYPE (arg
), mode
, &unsignedp
, 1);
5186 if (mode
== GET_MODE (DECL_INCOMING_RTL (arg
))
5187 && mode
!= DECL_MODE (arg
))
5189 *pmode
= DECL_MODE (arg
);
5190 *punsignedp
= unsignedp
;
5191 return DECL_INCOMING_RTL (arg
);
5200 /* Compute the size and offset from the start of the stacked arguments for a
5201 parm passed in mode PASSED_MODE and with type TYPE.
5203 INITIAL_OFFSET_PTR points to the current offset into the stacked
5206 The starting offset and size for this parm are returned in *OFFSET_PTR
5207 and *ARG_SIZE_PTR, respectively.
5209 IN_REGS is non-zero if the argument will be passed in registers. It will
5210 never be set if REG_PARM_STACK_SPACE is not defined.
5212 FNDECL is the function in which the argument was defined.
5214 There are two types of rounding that are done. The first, controlled by
5215 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5216 list to be aligned to the specific boundary (in bits). This rounding
5217 affects the initial and starting offsets, but not the argument size.
5219 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5220 optionally rounds the size of the parm to PARM_BOUNDARY. The
5221 initial offset is not affected by this rounding, while the size always
5222 is and the starting offset may be. */
5224 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5225 initial_offset_ptr is positive because locate_and_pad_parm's
5226 callers pass in the total size of args so far as
5227 initial_offset_ptr. arg_size_ptr is always positive. */
5230 locate_and_pad_parm (passed_mode
, type
, in_regs
, fndecl
,
5231 initial_offset_ptr
, offset_ptr
, arg_size_ptr
,
5233 enum machine_mode passed_mode
;
5235 int in_regs ATTRIBUTE_UNUSED
;
5236 tree fndecl ATTRIBUTE_UNUSED
;
5237 struct args_size
*initial_offset_ptr
;
5238 struct args_size
*offset_ptr
;
5239 struct args_size
*arg_size_ptr
;
5240 struct args_size
*alignment_pad
;
5244 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
5245 enum direction where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
5246 int boundary
= FUNCTION_ARG_BOUNDARY (passed_mode
, type
);
5248 #ifdef REG_PARM_STACK_SPACE
5249 /* If we have found a stack parm before we reach the end of the
5250 area reserved for registers, skip that area. */
5253 int reg_parm_stack_space
= 0;
5255 #ifdef MAYBE_REG_PARM_STACK_SPACE
5256 reg_parm_stack_space
= MAYBE_REG_PARM_STACK_SPACE
;
5258 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
5260 if (reg_parm_stack_space
> 0)
5262 if (initial_offset_ptr
->var
)
5264 initial_offset_ptr
->var
5265 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
5266 ssize_int (reg_parm_stack_space
));
5267 initial_offset_ptr
->constant
= 0;
5269 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
5270 initial_offset_ptr
->constant
= reg_parm_stack_space
;
5273 #endif /* REG_PARM_STACK_SPACE */
5275 arg_size_ptr
->var
= 0;
5276 arg_size_ptr
->constant
= 0;
5277 alignment_pad
->var
= 0;
5278 alignment_pad
->constant
= 0;
5280 #ifdef ARGS_GROW_DOWNWARD
5281 if (initial_offset_ptr
->var
)
5283 offset_ptr
->constant
= 0;
5284 offset_ptr
->var
= size_binop (MINUS_EXPR
, ssize_int (0),
5285 initial_offset_ptr
->var
);
5289 offset_ptr
->constant
= -initial_offset_ptr
->constant
;
5290 offset_ptr
->var
= 0;
5292 if (where_pad
!= none
5293 && (!host_integerp (sizetree
, 1)
5294 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % PARM_BOUNDARY
))
5295 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5296 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
5297 if (where_pad
!= downward
)
5298 pad_to_arg_alignment (offset_ptr
, boundary
, alignment_pad
);
5299 if (initial_offset_ptr
->var
)
5300 arg_size_ptr
->var
= size_binop (MINUS_EXPR
,
5301 size_binop (MINUS_EXPR
,
5303 initial_offset_ptr
->var
),
5307 arg_size_ptr
->constant
= (-initial_offset_ptr
->constant
5308 - offset_ptr
->constant
);
5310 #else /* !ARGS_GROW_DOWNWARD */
5312 #ifdef REG_PARM_STACK_SPACE
5313 || REG_PARM_STACK_SPACE (fndecl
) > 0
5316 pad_to_arg_alignment (initial_offset_ptr
, boundary
, alignment_pad
);
5317 *offset_ptr
= *initial_offset_ptr
;
5319 #ifdef PUSH_ROUNDING
5320 if (passed_mode
!= BLKmode
)
5321 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
5324 /* Pad_below needs the pre-rounded size to know how much to pad below
5325 so this must be done before rounding up. */
5326 if (where_pad
== downward
5327 /* However, BLKmode args passed in regs have their padding done elsewhere.
5328 The stack slot must be able to hold the entire register. */
5329 && !(in_regs
&& passed_mode
== BLKmode
))
5330 pad_below (offset_ptr
, passed_mode
, sizetree
);
5332 if (where_pad
!= none
5333 && (!host_integerp (sizetree
, 1)
5334 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % PARM_BOUNDARY
))
5335 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5337 ADD_PARM_SIZE (*arg_size_ptr
, sizetree
);
5338 #endif /* ARGS_GROW_DOWNWARD */
5341 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5342 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5345 pad_to_arg_alignment (offset_ptr
, boundary
, alignment_pad
)
5346 struct args_size
*offset_ptr
;
5348 struct args_size
*alignment_pad
;
5350 tree save_var
= NULL_TREE
;
5351 HOST_WIDE_INT save_constant
= 0;
5353 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
5355 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5357 save_var
= offset_ptr
->var
;
5358 save_constant
= offset_ptr
->constant
;
5361 alignment_pad
->var
= NULL_TREE
;
5362 alignment_pad
->constant
= 0;
5364 if (boundary
> BITS_PER_UNIT
)
5366 if (offset_ptr
->var
)
5369 #ifdef ARGS_GROW_DOWNWARD
5374 (ARGS_SIZE_TREE (*offset_ptr
),
5375 boundary
/ BITS_PER_UNIT
);
5376 offset_ptr
->constant
= 0; /*?*/
5377 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5378 alignment_pad
->var
= size_binop (MINUS_EXPR
, offset_ptr
->var
,
5383 offset_ptr
->constant
=
5384 #ifdef ARGS_GROW_DOWNWARD
5385 FLOOR_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
5387 CEIL_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
5389 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5390 alignment_pad
->constant
= offset_ptr
->constant
- save_constant
;
5395 #ifndef ARGS_GROW_DOWNWARD
5397 pad_below (offset_ptr
, passed_mode
, sizetree
)
5398 struct args_size
*offset_ptr
;
5399 enum machine_mode passed_mode
;
5402 if (passed_mode
!= BLKmode
)
5404 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
5405 offset_ptr
->constant
5406 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
5407 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
5408 - GET_MODE_SIZE (passed_mode
));
5412 if (TREE_CODE (sizetree
) != INTEGER_CST
5413 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
5415 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5416 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5418 ADD_PARM_SIZE (*offset_ptr
, s2
);
5419 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
5425 /* Walk the tree of blocks describing the binding levels within a function
5426 and warn about uninitialized variables.
5427 This is done after calling flow_analysis and before global_alloc
5428 clobbers the pseudo-regs to hard regs. */
5431 uninitialized_vars_warning (block
)
5435 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
5437 if (warn_uninitialized
5438 && TREE_CODE (decl
) == VAR_DECL
5439 /* These warnings are unreliable for and aggregates
5440 because assigning the fields one by one can fail to convince
5441 flow.c that the entire aggregate was initialized.
5442 Unions are troublesome because members may be shorter. */
5443 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl
))
5444 && DECL_RTL (decl
) != 0
5445 && GET_CODE (DECL_RTL (decl
)) == REG
5446 /* Global optimizations can make it difficult to determine if a
5447 particular variable has been initialized. However, a VAR_DECL
5448 with a nonzero DECL_INITIAL had an initializer, so do not
5449 claim it is potentially uninitialized.
5451 We do not care about the actual value in DECL_INITIAL, so we do
5452 not worry that it may be a dangling pointer. */
5453 && DECL_INITIAL (decl
) == NULL_TREE
5454 && regno_uninitialized (REGNO (DECL_RTL (decl
))))
5455 warning_with_decl (decl
,
5456 "`%s' might be used uninitialized in this function");
5458 && TREE_CODE (decl
) == VAR_DECL
5459 && DECL_RTL (decl
) != 0
5460 && GET_CODE (DECL_RTL (decl
)) == REG
5461 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
5462 warning_with_decl (decl
,
5463 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5465 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
5466 uninitialized_vars_warning (sub
);
5469 /* Do the appropriate part of uninitialized_vars_warning
5470 but for arguments instead of local variables. */
5473 setjmp_args_warning ()
5476 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5477 decl
; decl
= TREE_CHAIN (decl
))
5478 if (DECL_RTL (decl
) != 0
5479 && GET_CODE (DECL_RTL (decl
)) == REG
5480 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
5481 warning_with_decl (decl
,
5482 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5485 /* If this function call setjmp, put all vars into the stack
5486 unless they were declared `register'. */
5489 setjmp_protect (block
)
5493 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
5494 if ((TREE_CODE (decl
) == VAR_DECL
5495 || TREE_CODE (decl
) == PARM_DECL
)
5496 && DECL_RTL (decl
) != 0
5497 && (GET_CODE (DECL_RTL (decl
)) == REG
5498 || (GET_CODE (DECL_RTL (decl
)) == MEM
5499 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
5500 /* If this variable came from an inline function, it must be
5501 that its life doesn't overlap the setjmp. If there was a
5502 setjmp in the function, it would already be in memory. We
5503 must exclude such variable because their DECL_RTL might be
5504 set to strange things such as virtual_stack_vars_rtx. */
5505 && ! DECL_FROM_INLINE (decl
)
5507 #ifdef NON_SAVING_SETJMP
5508 /* If longjmp doesn't restore the registers,
5509 don't put anything in them. */
5513 ! DECL_REGISTER (decl
)))
5514 put_var_into_stack (decl
);
5515 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
5516 setjmp_protect (sub
);
5519 /* Like the previous function, but for args instead of local variables. */
5522 setjmp_protect_args ()
5525 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5526 decl
; decl
= TREE_CHAIN (decl
))
5527 if ((TREE_CODE (decl
) == VAR_DECL
5528 || TREE_CODE (decl
) == PARM_DECL
)
5529 && DECL_RTL (decl
) != 0
5530 && (GET_CODE (DECL_RTL (decl
)) == REG
5531 || (GET_CODE (DECL_RTL (decl
)) == MEM
5532 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
5534 /* If longjmp doesn't restore the registers,
5535 don't put anything in them. */
5536 #ifdef NON_SAVING_SETJMP
5540 ! DECL_REGISTER (decl
)))
5541 put_var_into_stack (decl
);
5544 /* Return the context-pointer register corresponding to DECL,
5545 or 0 if it does not need one. */
5548 lookup_static_chain (decl
)
5551 tree context
= decl_function_context (decl
);
5555 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_NO_STATIC_CHAIN (decl
)))
5558 /* We treat inline_function_decl as an alias for the current function
5559 because that is the inline function whose vars, types, etc.
5560 are being merged into the current function.
5561 See expand_inline_function. */
5562 if (context
== current_function_decl
|| context
== inline_function_decl
)
5563 return virtual_stack_vars_rtx
;
5565 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
5566 if (TREE_PURPOSE (link
) == context
)
5567 return RTL_EXPR_RTL (TREE_VALUE (link
));
5572 /* Convert a stack slot address ADDR for variable VAR
5573 (from a containing function)
5574 into an address valid in this function (using a static chain). */
5577 fix_lexical_addr (addr
, var
)
5582 HOST_WIDE_INT displacement
;
5583 tree context
= decl_function_context (var
);
5584 struct function
*fp
;
5587 /* If this is the present function, we need not do anything. */
5588 if (context
== current_function_decl
|| context
== inline_function_decl
)
5591 fp
= find_function_data (context
);
5593 if (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == MEM
)
5594 addr
= XEXP (XEXP (addr
, 0), 0);
5596 /* Decode given address as base reg plus displacement. */
5597 if (GET_CODE (addr
) == REG
)
5598 basereg
= addr
, displacement
= 0;
5599 else if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
5600 basereg
= XEXP (addr
, 0), displacement
= INTVAL (XEXP (addr
, 1));
5604 /* We accept vars reached via the containing function's
5605 incoming arg pointer and via its stack variables pointer. */
5606 if (basereg
== fp
->internal_arg_pointer
)
5608 /* If reached via arg pointer, get the arg pointer value
5609 out of that function's stack frame.
5611 There are two cases: If a separate ap is needed, allocate a
5612 slot in the outer function for it and dereference it that way.
5613 This is correct even if the real ap is actually a pseudo.
5614 Otherwise, just adjust the offset from the frame pointer to
5617 #ifdef NEED_SEPARATE_AP
5620 addr
= get_arg_pointer_save_area (fp
);
5621 addr
= fix_lexical_addr (XEXP (addr
, 0), var
);
5622 addr
= memory_address (Pmode
, addr
);
5624 base
= gen_rtx_MEM (Pmode
, addr
);
5625 set_mem_alias_set (base
, get_frame_alias_set ());
5626 base
= copy_to_reg (base
);
5628 displacement
+= (FIRST_PARM_OFFSET (context
) - STARTING_FRAME_OFFSET
);
5629 base
= lookup_static_chain (var
);
5633 else if (basereg
== virtual_stack_vars_rtx
)
5635 /* This is the same code as lookup_static_chain, duplicated here to
5636 avoid an extra call to decl_function_context. */
5639 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
5640 if (TREE_PURPOSE (link
) == context
)
5642 base
= RTL_EXPR_RTL (TREE_VALUE (link
));
5650 /* Use same offset, relative to appropriate static chain or argument
5652 return plus_constant (base
, displacement
);
5655 /* Return the address of the trampoline for entering nested fn FUNCTION.
5656 If necessary, allocate a trampoline (in the stack frame)
5657 and emit rtl to initialize its contents (at entry to this function). */
5660 trampoline_address (function
)
5666 struct function
*fp
;
5669 /* Find an existing trampoline and return it. */
5670 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
5671 if (TREE_PURPOSE (link
) == function
)
5673 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0));
5675 for (fp
= outer_function_chain
; fp
; fp
= fp
->outer
)
5676 for (link
= fp
->x_trampoline_list
; link
; link
= TREE_CHAIN (link
))
5677 if (TREE_PURPOSE (link
) == function
)
5679 tramp
= fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0),
5681 return adjust_trampoline_addr (tramp
);
5684 /* None exists; we must make one. */
5686 /* Find the `struct function' for the function containing FUNCTION. */
5688 fn_context
= decl_function_context (function
);
5689 if (fn_context
!= current_function_decl
5690 && fn_context
!= inline_function_decl
)
5691 fp
= find_function_data (fn_context
);
5693 /* Allocate run-time space for this trampoline
5694 (usually in the defining function's stack frame). */
5695 #ifdef ALLOCATE_TRAMPOLINE
5696 tramp
= ALLOCATE_TRAMPOLINE (fp
);
5698 /* If rounding needed, allocate extra space
5699 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5700 #define TRAMPOLINE_REAL_SIZE \
5701 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5702 tramp
= assign_stack_local_1 (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0,
5706 /* Record the trampoline for reuse and note it for later initialization
5707 by expand_function_end. */
5710 rtlexp
= make_node (RTL_EXPR
);
5711 RTL_EXPR_RTL (rtlexp
) = tramp
;
5712 fp
->x_trampoline_list
= tree_cons (function
, rtlexp
,
5713 fp
->x_trampoline_list
);
5717 /* Make the RTL_EXPR node temporary, not momentary, so that the
5718 trampoline_list doesn't become garbage. */
5719 rtlexp
= make_node (RTL_EXPR
);
5721 RTL_EXPR_RTL (rtlexp
) = tramp
;
5722 trampoline_list
= tree_cons (function
, rtlexp
, trampoline_list
);
5725 tramp
= fix_lexical_addr (XEXP (tramp
, 0), function
);
5726 return adjust_trampoline_addr (tramp
);
5729 /* Given a trampoline address,
5730 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5733 round_trampoline_addr (tramp
)
5736 /* Round address up to desired boundary. */
5737 rtx temp
= gen_reg_rtx (Pmode
);
5738 rtx addend
= GEN_INT (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
- 1);
5739 rtx mask
= GEN_INT (-TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
5741 temp
= expand_simple_binop (Pmode
, PLUS
, tramp
, addend
,
5742 temp
, 0, OPTAB_LIB_WIDEN
);
5743 tramp
= expand_simple_binop (Pmode
, AND
, temp
, mask
,
5744 temp
, 0, OPTAB_LIB_WIDEN
);
5749 /* Given a trampoline address, round it then apply any
5750 platform-specific adjustments so that the result can be used for a
5754 adjust_trampoline_addr (tramp
)
5757 tramp
= round_trampoline_addr (tramp
);
5758 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5759 TRAMPOLINE_ADJUST_ADDRESS (tramp
);
5764 /* Put all this function's BLOCK nodes including those that are chained
5765 onto the first block into a vector, and return it.
5766 Also store in each NOTE for the beginning or end of a block
5767 the index of that block in the vector.
5768 The arguments are BLOCK, the chain of top-level blocks of the function,
5769 and INSNS, the insn chain of the function. */
5775 tree
*block_vector
, *last_block_vector
;
5777 tree block
= DECL_INITIAL (current_function_decl
);
5782 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5783 depth-first order. */
5784 block_vector
= get_block_vector (block
, &n_blocks
);
5785 block_stack
= (tree
*) xmalloc (n_blocks
* sizeof (tree
));
5787 last_block_vector
= identify_blocks_1 (get_insns (),
5789 block_vector
+ n_blocks
,
5792 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5793 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5794 if (0 && last_block_vector
!= block_vector
+ n_blocks
)
5797 free (block_vector
);
5801 /* Subroutine of identify_blocks. Do the block substitution on the
5802 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5804 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5805 BLOCK_VECTOR is incremented for each block seen. */
5808 identify_blocks_1 (insns
, block_vector
, end_block_vector
, orig_block_stack
)
5811 tree
*end_block_vector
;
5812 tree
*orig_block_stack
;
5815 tree
*block_stack
= orig_block_stack
;
5817 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5819 if (GET_CODE (insn
) == NOTE
)
5821 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5825 /* If there are more block notes than BLOCKs, something
5827 if (block_vector
== end_block_vector
)
5830 b
= *block_vector
++;
5831 NOTE_BLOCK (insn
) = b
;
5834 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5836 /* If there are more NOTE_INSN_BLOCK_ENDs than
5837 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5838 if (block_stack
== orig_block_stack
)
5841 NOTE_BLOCK (insn
) = *--block_stack
;
5844 else if (GET_CODE (insn
) == CALL_INSN
5845 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
5847 rtx cp
= PATTERN (insn
);
5849 block_vector
= identify_blocks_1 (XEXP (cp
, 0), block_vector
,
5850 end_block_vector
, block_stack
);
5852 block_vector
= identify_blocks_1 (XEXP (cp
, 1), block_vector
,
5853 end_block_vector
, block_stack
);
5855 block_vector
= identify_blocks_1 (XEXP (cp
, 2), block_vector
,
5856 end_block_vector
, block_stack
);
5860 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5861 something is badly wrong. */
5862 if (block_stack
!= orig_block_stack
)
5865 return block_vector
;
5868 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5869 and create duplicate blocks. */
5870 /* ??? Need an option to either create block fragments or to create
5871 abstract origin duplicates of a source block. It really depends
5872 on what optimization has been performed. */
5877 tree block
= DECL_INITIAL (current_function_decl
);
5878 varray_type block_stack
;
5880 if (block
== NULL_TREE
)
5883 VARRAY_TREE_INIT (block_stack
, 10, "block_stack");
5885 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5886 reorder_blocks_0 (block
);
5888 /* Prune the old trees away, so that they don't get in the way. */
5889 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
5890 BLOCK_CHAIN (block
) = NULL_TREE
;
5892 /* Recreate the block tree from the note nesting. */
5893 reorder_blocks_1 (get_insns (), block
, &block_stack
);
5894 BLOCK_SUBBLOCKS (block
) = blocks_nreverse (BLOCK_SUBBLOCKS (block
));
5896 /* Remove deleted blocks from the block fragment chains. */
5897 reorder_fix_fragments (block
);
5900 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5903 reorder_blocks_0 (block
)
5908 TREE_ASM_WRITTEN (block
) = 0;
5909 reorder_blocks_0 (BLOCK_SUBBLOCKS (block
));
5910 block
= BLOCK_CHAIN (block
);
5915 reorder_blocks_1 (insns
, current_block
, p_block_stack
)
5918 varray_type
*p_block_stack
;
5922 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5924 if (GET_CODE (insn
) == NOTE
)
5926 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5928 tree block
= NOTE_BLOCK (insn
);
5930 /* If we have seen this block before, that means it now
5931 spans multiple address regions. Create a new fragment. */
5932 if (TREE_ASM_WRITTEN (block
))
5934 tree new_block
= copy_node (block
);
5937 origin
= (BLOCK_FRAGMENT_ORIGIN (block
)
5938 ? BLOCK_FRAGMENT_ORIGIN (block
)
5940 BLOCK_FRAGMENT_ORIGIN (new_block
) = origin
;
5941 BLOCK_FRAGMENT_CHAIN (new_block
)
5942 = BLOCK_FRAGMENT_CHAIN (origin
);
5943 BLOCK_FRAGMENT_CHAIN (origin
) = new_block
;
5945 NOTE_BLOCK (insn
) = new_block
;
5949 BLOCK_SUBBLOCKS (block
) = 0;
5950 TREE_ASM_WRITTEN (block
) = 1;
5951 BLOCK_SUPERCONTEXT (block
) = current_block
;
5952 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
5953 BLOCK_SUBBLOCKS (current_block
) = block
;
5954 current_block
= block
;
5955 VARRAY_PUSH_TREE (*p_block_stack
, block
);
5957 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5959 NOTE_BLOCK (insn
) = VARRAY_TOP_TREE (*p_block_stack
);
5960 VARRAY_POP (*p_block_stack
);
5961 BLOCK_SUBBLOCKS (current_block
)
5962 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
5963 current_block
= BLOCK_SUPERCONTEXT (current_block
);
5966 else if (GET_CODE (insn
) == CALL_INSN
5967 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
5969 rtx cp
= PATTERN (insn
);
5970 reorder_blocks_1 (XEXP (cp
, 0), current_block
, p_block_stack
);
5972 reorder_blocks_1 (XEXP (cp
, 1), current_block
, p_block_stack
);
5974 reorder_blocks_1 (XEXP (cp
, 2), current_block
, p_block_stack
);
5979 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
5980 appears in the block tree, select one of the fragments to become
5981 the new origin block. */
5984 reorder_fix_fragments (block
)
5989 tree dup_origin
= BLOCK_FRAGMENT_ORIGIN (block
);
5990 tree new_origin
= NULL_TREE
;
5994 if (! TREE_ASM_WRITTEN (dup_origin
))
5996 new_origin
= BLOCK_FRAGMENT_CHAIN (dup_origin
);
5998 /* Find the first of the remaining fragments. There must
5999 be at least one -- the current block. */
6000 while (! TREE_ASM_WRITTEN (new_origin
))
6001 new_origin
= BLOCK_FRAGMENT_CHAIN (new_origin
);
6002 BLOCK_FRAGMENT_ORIGIN (new_origin
) = NULL_TREE
;
6005 else if (! dup_origin
)
6008 /* Re-root the rest of the fragments to the new origin. In the
6009 case that DUP_ORIGIN was null, that means BLOCK was the origin
6010 of a chain of fragments and we want to remove those fragments
6011 that didn't make it to the output. */
6014 tree
*pp
= &BLOCK_FRAGMENT_CHAIN (new_origin
);
6019 if (TREE_ASM_WRITTEN (chain
))
6021 BLOCK_FRAGMENT_ORIGIN (chain
) = new_origin
;
6023 pp
= &BLOCK_FRAGMENT_CHAIN (chain
);
6025 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
6030 reorder_fix_fragments (BLOCK_SUBBLOCKS (block
));
6031 block
= BLOCK_CHAIN (block
);
6035 /* Reverse the order of elements in the chain T of blocks,
6036 and return the new head of the chain (old last element). */
6042 tree prev
= 0, decl
, next
;
6043 for (decl
= t
; decl
; decl
= next
)
6045 next
= BLOCK_CHAIN (decl
);
6046 BLOCK_CHAIN (decl
) = prev
;
6052 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6053 non-NULL, list them all into VECTOR, in a depth-first preorder
6054 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6058 all_blocks (block
, vector
)
6066 TREE_ASM_WRITTEN (block
) = 0;
6068 /* Record this block. */
6070 vector
[n_blocks
] = block
;
6074 /* Record the subblocks, and their subblocks... */
6075 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
6076 vector
? vector
+ n_blocks
: 0);
6077 block
= BLOCK_CHAIN (block
);
6083 /* Return a vector containing all the blocks rooted at BLOCK. The
6084 number of elements in the vector is stored in N_BLOCKS_P. The
6085 vector is dynamically allocated; it is the caller's responsibility
6086 to call `free' on the pointer returned. */
6089 get_block_vector (block
, n_blocks_p
)
6095 *n_blocks_p
= all_blocks (block
, NULL
);
6096 block_vector
= (tree
*) xmalloc (*n_blocks_p
* sizeof (tree
));
6097 all_blocks (block
, block_vector
);
6099 return block_vector
;
6102 static int next_block_index
= 2;
6104 /* Set BLOCK_NUMBER for all the blocks in FN. */
6114 /* For SDB and XCOFF debugging output, we start numbering the blocks
6115 from 1 within each function, rather than keeping a running
6117 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6118 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
6119 next_block_index
= 1;
6122 block_vector
= get_block_vector (DECL_INITIAL (fn
), &n_blocks
);
6124 /* The top-level BLOCK isn't numbered at all. */
6125 for (i
= 1; i
< n_blocks
; ++i
)
6126 /* We number the blocks from two. */
6127 BLOCK_NUMBER (block_vector
[i
]) = next_block_index
++;
6129 free (block_vector
);
6134 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6137 debug_find_var_in_block_tree (var
, block
)
6143 for (t
= BLOCK_VARS (block
); t
; t
= TREE_CHAIN (t
))
6147 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= TREE_CHAIN (t
))
6149 tree ret
= debug_find_var_in_block_tree (var
, t
);
6157 /* Allocate a function structure and reset its contents to the defaults. */
6160 prepare_function_start ()
6162 cfun
= (struct function
*) ggc_alloc_cleared (sizeof (struct function
));
6164 init_stmt_for_function ();
6165 init_eh_for_function ();
6167 cse_not_expected
= ! optimize
;
6169 /* Caller save not needed yet. */
6170 caller_save_needed
= 0;
6172 /* No stack slots have been made yet. */
6173 stack_slot_list
= 0;
6175 current_function_has_nonlocal_label
= 0;
6176 current_function_has_nonlocal_goto
= 0;
6178 /* There is no stack slot for handling nonlocal gotos. */
6179 nonlocal_goto_handler_slots
= 0;
6180 nonlocal_goto_stack_level
= 0;
6182 /* No labels have been declared for nonlocal use. */
6183 nonlocal_labels
= 0;
6184 nonlocal_goto_handler_labels
= 0;
6186 /* No function calls so far in this function. */
6187 function_call_count
= 0;
6189 /* No parm regs have been allocated.
6190 (This is important for output_inline_function.) */
6191 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
6193 /* Initialize the RTL mechanism. */
6196 /* Initialize the queue of pending postincrement and postdecrements,
6197 and some other info in expr.c. */
6200 /* We haven't done register allocation yet. */
6203 init_varasm_status (cfun
);
6205 /* Clear out data used for inlining. */
6206 cfun
->inlinable
= 0;
6207 cfun
->original_decl_initial
= 0;
6208 cfun
->original_arg_vector
= 0;
6210 cfun
->stack_alignment_needed
= STACK_BOUNDARY
;
6211 cfun
->preferred_stack_boundary
= STACK_BOUNDARY
;
6213 /* Set if a call to setjmp is seen. */
6214 current_function_calls_setjmp
= 0;
6216 /* Set if a call to longjmp is seen. */
6217 current_function_calls_longjmp
= 0;
6219 current_function_calls_alloca
= 0;
6220 current_function_contains_functions
= 0;
6221 current_function_is_leaf
= 0;
6222 current_function_nothrow
= 0;
6223 current_function_sp_is_unchanging
= 0;
6224 current_function_uses_only_leaf_regs
= 0;
6225 current_function_has_computed_jump
= 0;
6226 current_function_is_thunk
= 0;
6228 current_function_returns_pcc_struct
= 0;
6229 current_function_returns_struct
= 0;
6230 current_function_epilogue_delay_list
= 0;
6231 current_function_uses_const_pool
= 0;
6232 current_function_uses_pic_offset_table
= 0;
6233 current_function_cannot_inline
= 0;
6235 /* We have not yet needed to make a label to jump to for tail-recursion. */
6236 tail_recursion_label
= 0;
6238 /* We haven't had a need to make a save area for ap yet. */
6239 arg_pointer_save_area
= 0;
6241 /* No stack slots allocated yet. */
6244 /* No SAVE_EXPRs in this function yet. */
6247 /* No RTL_EXPRs in this function yet. */
6250 /* Set up to allocate temporaries. */
6253 /* Indicate that we need to distinguish between the return value of the
6254 present function and the return value of a function being called. */
6255 rtx_equal_function_value_matters
= 1;
6257 /* Indicate that we have not instantiated virtual registers yet. */
6258 virtuals_instantiated
= 0;
6260 /* Indicate that we want CONCATs now. */
6261 generating_concat_p
= 1;
6263 /* Indicate we have no need of a frame pointer yet. */
6264 frame_pointer_needed
= 0;
6266 /* By default assume not stdarg. */
6267 current_function_stdarg
= 0;
6269 /* We haven't made any trampolines for this function yet. */
6270 trampoline_list
= 0;
6272 init_pending_stack_adjust ();
6273 inhibit_defer_pop
= 0;
6275 current_function_outgoing_args_size
= 0;
6277 current_function_funcdef_no
= funcdef_no
++;
6279 cfun
->arc_profile
= profile_arc_flag
|| flag_test_coverage
;
6281 cfun
->arc_profile
= profile_arc_flag
|| flag_test_coverage
;
6283 cfun
->function_frequency
= FUNCTION_FREQUENCY_NORMAL
;
6285 (*lang_hooks
.function
.init
) (cfun
);
6286 if (init_machine_status
)
6287 cfun
->machine
= (*init_machine_status
) ();
6290 /* Initialize the rtl expansion mechanism so that we can do simple things
6291 like generate sequences. This is used to provide a context during global
6292 initialization of some passes. */
6294 init_dummy_function_start ()
6296 prepare_function_start ();
6299 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6300 and initialize static variables for generating RTL for the statements
6304 init_function_start (subr
, filename
, line
)
6306 const char *filename
;
6309 prepare_function_start ();
6311 current_function_name
= (*lang_hooks
.decl_printable_name
) (subr
, 2);
6314 /* Nonzero if this is a nested function that uses a static chain. */
6316 current_function_needs_context
6317 = (decl_function_context (current_function_decl
) != 0
6318 && ! DECL_NO_STATIC_CHAIN (current_function_decl
));
6320 /* Within function body, compute a type's size as soon it is laid out. */
6321 immediate_size_expand
++;
6323 /* Prevent ever trying to delete the first instruction of a function.
6324 Also tell final how to output a linenum before the function prologue.
6325 Note linenums could be missing, e.g. when compiling a Java .class file. */
6327 emit_line_note (filename
, line
);
6329 /* Make sure first insn is a note even if we don't want linenums.
6330 This makes sure the first insn will never be deleted.
6331 Also, final expects a note to appear there. */
6332 emit_note (NULL
, NOTE_INSN_DELETED
);
6334 /* Set flags used by final.c. */
6335 if (aggregate_value_p (DECL_RESULT (subr
)))
6337 #ifdef PCC_STATIC_STRUCT_RETURN
6338 current_function_returns_pcc_struct
= 1;
6340 current_function_returns_struct
= 1;
6343 /* Warn if this value is an aggregate type,
6344 regardless of which calling convention we are using for it. */
6345 if (warn_aggregate_return
6346 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
6347 warning ("function returns an aggregate");
6349 current_function_returns_pointer
6350 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
6353 /* Make sure all values used by the optimization passes have sane
6356 init_function_for_compilation ()
6360 /* No prologue/epilogue insns yet. */
6361 VARRAY_GROW (prologue
, 0);
6362 VARRAY_GROW (epilogue
, 0);
6363 VARRAY_GROW (sibcall_epilogue
, 0);
6366 /* Expand a call to __main at the beginning of a possible main function. */
6368 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6369 #undef HAS_INIT_SECTION
6370 #define HAS_INIT_SECTION
6374 expand_main_function ()
6376 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6377 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
)
6379 int align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
6383 /* Forcibly align the stack. */
6384 #ifdef STACK_GROWS_DOWNWARD
6385 tmp
= expand_simple_binop (Pmode
, AND
, stack_pointer_rtx
, GEN_INT(-align
),
6386 stack_pointer_rtx
, 1, OPTAB_WIDEN
);
6388 tmp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
6389 GEN_INT (align
- 1), NULL_RTX
, 1, OPTAB_WIDEN
);
6390 tmp
= expand_simple_binop (Pmode
, AND
, tmp
, GEN_INT (-align
),
6391 stack_pointer_rtx
, 1, OPTAB_WIDEN
);
6393 if (tmp
!= stack_pointer_rtx
)
6394 emit_move_insn (stack_pointer_rtx
, tmp
);
6396 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6397 tmp
= force_reg (Pmode
, const0_rtx
);
6398 allocate_dynamic_stack_space (tmp
, NULL_RTX
, BIGGEST_ALIGNMENT
);
6402 for (tmp
= get_last_insn (); tmp
; tmp
= PREV_INSN (tmp
))
6403 if (NOTE_P (tmp
) && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_FUNCTION_BEG
)
6406 emit_insn_before (seq
, tmp
);
6412 #ifndef HAS_INIT_SECTION
6413 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, NAME__MAIN
), LCT_NORMAL
,
6418 /* The PENDING_SIZES represent the sizes of variable-sized types.
6419 Create RTL for the various sizes now (using temporary variables),
6420 so that we can refer to the sizes from the RTL we are generating
6421 for the current function. The PENDING_SIZES are a TREE_LIST. The
6422 TREE_VALUE of each node is a SAVE_EXPR. */
6425 expand_pending_sizes (pending_sizes
)
6430 /* Evaluate now the sizes of any types declared among the arguments. */
6431 for (tem
= pending_sizes
; tem
; tem
= TREE_CHAIN (tem
))
6433 expand_expr (TREE_VALUE (tem
), const0_rtx
, VOIDmode
, 0);
6434 /* Flush the queue in case this parameter declaration has
6440 /* Start the RTL for a new function, and set variables used for
6442 SUBR is the FUNCTION_DECL node.
6443 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6444 the function's parameters, which must be run at any return statement. */
6447 expand_function_start (subr
, parms_have_cleanups
)
6449 int parms_have_cleanups
;
6452 rtx last_ptr
= NULL_RTX
;
6454 /* Make sure volatile mem refs aren't considered
6455 valid operands of arithmetic insns. */
6456 init_recog_no_volatile ();
6458 current_function_instrument_entry_exit
6459 = (flag_instrument_function_entry_exit
6460 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
6462 current_function_profile
6464 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
6466 current_function_limit_stack
6467 = (stack_limit_rtx
!= NULL_RTX
&& ! DECL_NO_LIMIT_STACK (subr
));
6469 /* If function gets a static chain arg, store it in the stack frame.
6470 Do this first, so it gets the first stack slot offset. */
6471 if (current_function_needs_context
)
6473 last_ptr
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
6475 /* Delay copying static chain if it is not a register to avoid
6476 conflicts with regs used for parameters. */
6477 if (! SMALL_REGISTER_CLASSES
6478 || GET_CODE (static_chain_incoming_rtx
) == REG
)
6479 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
6482 /* If the parameters of this function need cleaning up, get a label
6483 for the beginning of the code which executes those cleanups. This must
6484 be done before doing anything with return_label. */
6485 if (parms_have_cleanups
)
6486 cleanup_label
= gen_label_rtx ();
6490 /* Make the label for return statements to jump to. Do not special
6491 case machines with special return instructions -- they will be
6492 handled later during jump, ifcvt, or epilogue creation. */
6493 return_label
= gen_label_rtx ();
6495 /* Initialize rtx used to return the value. */
6496 /* Do this before assign_parms so that we copy the struct value address
6497 before any library calls that assign parms might generate. */
6499 /* Decide whether to return the value in memory or in a register. */
6500 if (aggregate_value_p (DECL_RESULT (subr
)))
6502 /* Returning something that won't go in a register. */
6503 rtx value_address
= 0;
6505 #ifdef PCC_STATIC_STRUCT_RETURN
6506 if (current_function_returns_pcc_struct
)
6508 int size
= int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr
)));
6509 value_address
= assemble_static_space (size
);
6514 /* Expect to be passed the address of a place to store the value.
6515 If it is passed as an argument, assign_parms will take care of
6517 if (struct_value_incoming_rtx
)
6519 value_address
= gen_reg_rtx (Pmode
);
6520 emit_move_insn (value_address
, struct_value_incoming_rtx
);
6525 rtx x
= gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr
)), value_address
);
6526 set_mem_attributes (x
, DECL_RESULT (subr
), 1);
6527 SET_DECL_RTL (DECL_RESULT (subr
), x
);
6530 else if (DECL_MODE (DECL_RESULT (subr
)) == VOIDmode
)
6531 /* If return mode is void, this decl rtl should not be used. */
6532 SET_DECL_RTL (DECL_RESULT (subr
), NULL_RTX
);
6535 /* Compute the return values into a pseudo reg, which we will copy
6536 into the true return register after the cleanups are done. */
6538 /* In order to figure out what mode to use for the pseudo, we
6539 figure out what the mode of the eventual return register will
6540 actually be, and use that. */
6542 = hard_function_value (TREE_TYPE (DECL_RESULT (subr
)),
6545 /* Structures that are returned in registers are not aggregate_value_p,
6546 so we may see a PARALLEL. Don't play pseudo games with this. */
6547 if (! REG_P (hard_reg
))
6548 SET_DECL_RTL (DECL_RESULT (subr
), hard_reg
);
6551 /* Create the pseudo. */
6552 SET_DECL_RTL (DECL_RESULT (subr
), gen_reg_rtx (GET_MODE (hard_reg
)));
6554 /* Needed because we may need to move this to memory
6555 in case it's a named return value whose address is taken. */
6556 DECL_REGISTER (DECL_RESULT (subr
)) = 1;
6560 /* Initialize rtx for parameters and local variables.
6561 In some cases this requires emitting insns. */
6563 assign_parms (subr
);
6565 /* Copy the static chain now if it wasn't a register. The delay is to
6566 avoid conflicts with the parameter passing registers. */
6568 if (SMALL_REGISTER_CLASSES
&& current_function_needs_context
)
6569 if (GET_CODE (static_chain_incoming_rtx
) != REG
)
6570 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
6572 /* The following was moved from init_function_start.
6573 The move is supposed to make sdb output more accurate. */
6574 /* Indicate the beginning of the function body,
6575 as opposed to parm setup. */
6576 emit_note (NULL
, NOTE_INSN_FUNCTION_BEG
);
6578 if (GET_CODE (get_last_insn ()) != NOTE
)
6579 emit_note (NULL
, NOTE_INSN_DELETED
);
6580 parm_birth_insn
= get_last_insn ();
6582 context_display
= 0;
6583 if (current_function_needs_context
)
6585 /* Fetch static chain values for containing functions. */
6586 tem
= decl_function_context (current_function_decl
);
6587 /* Copy the static chain pointer into a pseudo. If we have
6588 small register classes, copy the value from memory if
6589 static_chain_incoming_rtx is a REG. */
6592 /* If the static chain originally came in a register, put it back
6593 there, then move it out in the next insn. The reason for
6594 this peculiar code is to satisfy function integration. */
6595 if (SMALL_REGISTER_CLASSES
6596 && GET_CODE (static_chain_incoming_rtx
) == REG
)
6597 emit_move_insn (static_chain_incoming_rtx
, last_ptr
);
6598 last_ptr
= copy_to_reg (static_chain_incoming_rtx
);
6603 tree rtlexp
= make_node (RTL_EXPR
);
6605 RTL_EXPR_RTL (rtlexp
) = last_ptr
;
6606 context_display
= tree_cons (tem
, rtlexp
, context_display
);
6607 tem
= decl_function_context (tem
);
6610 /* Chain thru stack frames, assuming pointer to next lexical frame
6611 is found at the place we always store it. */
6612 #ifdef FRAME_GROWS_DOWNWARD
6613 last_ptr
= plus_constant (last_ptr
,
6614 -(HOST_WIDE_INT
) GET_MODE_SIZE (Pmode
));
6616 last_ptr
= gen_rtx_MEM (Pmode
, memory_address (Pmode
, last_ptr
));
6617 set_mem_alias_set (last_ptr
, get_frame_alias_set ());
6618 last_ptr
= copy_to_reg (last_ptr
);
6620 /* If we are not optimizing, ensure that we know that this
6621 piece of context is live over the entire function. */
6623 save_expr_regs
= gen_rtx_EXPR_LIST (VOIDmode
, last_ptr
,
6628 if (current_function_instrument_entry_exit
)
6630 rtx fun
= DECL_RTL (current_function_decl
);
6631 if (GET_CODE (fun
) == MEM
)
6632 fun
= XEXP (fun
, 0);
6635 emit_library_call (profile_function_entry_libfunc
, LCT_NORMAL
, VOIDmode
,
6637 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS
,
6639 hard_frame_pointer_rtx
),
6643 if (current_function_profile
)
6646 PROFILE_HOOK (current_function_funcdef_no
);
6650 /* After the display initializations is where the tail-recursion label
6651 should go, if we end up needing one. Ensure we have a NOTE here
6652 since some things (like trampolines) get placed before this. */
6653 tail_recursion_reentry
= emit_note (NULL
, NOTE_INSN_DELETED
);
6655 /* Evaluate now the sizes of any types declared among the arguments. */
6656 expand_pending_sizes (nreverse (get_pending_sizes ()));
6658 /* Make sure there is a line number after the function entry setup code. */
6659 force_next_line_note ();
6662 /* Undo the effects of init_dummy_function_start. */
6664 expand_dummy_function_end ()
6666 /* End any sequences that failed to be closed due to syntax errors. */
6667 while (in_sequence_p ())
6670 /* Outside function body, can't compute type's actual size
6671 until next function's body starts. */
6673 free_after_parsing (cfun
);
6674 free_after_compilation (cfun
);
6678 /* Call DOIT for each hard register used as a return value from
6679 the current function. */
6682 diddle_return_value (doit
, arg
)
6683 void (*doit
) PARAMS ((rtx
, void *));
6686 rtx outgoing
= current_function_return_rtx
;
6691 if (GET_CODE (outgoing
) == REG
)
6692 (*doit
) (outgoing
, arg
);
6693 else if (GET_CODE (outgoing
) == PARALLEL
)
6697 for (i
= 0; i
< XVECLEN (outgoing
, 0); i
++)
6699 rtx x
= XEXP (XVECEXP (outgoing
, 0, i
), 0);
6701 if (GET_CODE (x
) == REG
&& REGNO (x
) < FIRST_PSEUDO_REGISTER
)
6708 do_clobber_return_reg (reg
, arg
)
6710 void *arg ATTRIBUTE_UNUSED
;
6712 emit_insn (gen_rtx_CLOBBER (VOIDmode
, reg
));
6716 clobber_return_register ()
6718 diddle_return_value (do_clobber_return_reg
, NULL
);
6720 /* In case we do use pseudo to return value, clobber it too. */
6721 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
6723 tree decl_result
= DECL_RESULT (current_function_decl
);
6724 rtx decl_rtl
= DECL_RTL (decl_result
);
6725 if (REG_P (decl_rtl
) && REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
)
6727 do_clobber_return_reg (decl_rtl
, NULL
);
6733 do_use_return_reg (reg
, arg
)
6735 void *arg ATTRIBUTE_UNUSED
;
6737 emit_insn (gen_rtx_USE (VOIDmode
, reg
));
6741 use_return_register ()
6743 diddle_return_value (do_use_return_reg
, NULL
);
6746 static GTY(()) rtx initial_trampoline
;
6748 /* Generate RTL for the end of the current function.
6749 FILENAME and LINE are the current position in the source file.
6751 It is up to language-specific callers to do cleanups for parameters--
6752 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6755 expand_function_end (filename
, line
, end_bindings
)
6756 const char *filename
;
6763 finish_expr_for_function ();
6765 /* If arg_pointer_save_area was referenced only from a nested
6766 function, we will not have initialized it yet. Do that now. */
6767 if (arg_pointer_save_area
&& ! cfun
->arg_pointer_save_area_init
)
6768 get_arg_pointer_save_area (cfun
);
6770 #ifdef NON_SAVING_SETJMP
6771 /* Don't put any variables in registers if we call setjmp
6772 on a machine that fails to restore the registers. */
6773 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
6775 if (DECL_INITIAL (current_function_decl
) != error_mark_node
)
6776 setjmp_protect (DECL_INITIAL (current_function_decl
));
6778 setjmp_protect_args ();
6782 /* Initialize any trampolines required by this function. */
6783 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
6785 tree function
= TREE_PURPOSE (link
);
6786 rtx context ATTRIBUTE_UNUSED
= lookup_static_chain (function
);
6787 rtx tramp
= RTL_EXPR_RTL (TREE_VALUE (link
));
6788 #ifdef TRAMPOLINE_TEMPLATE
6793 #ifdef TRAMPOLINE_TEMPLATE
6794 /* First make sure this compilation has a template for
6795 initializing trampolines. */
6796 if (initial_trampoline
== 0)
6799 = gen_rtx_MEM (BLKmode
, assemble_trampoline_template ());
6800 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
6804 /* Generate insns to initialize the trampoline. */
6806 tramp
= round_trampoline_addr (XEXP (tramp
, 0));
6807 #ifdef TRAMPOLINE_TEMPLATE
6808 blktramp
= replace_equiv_address (initial_trampoline
, tramp
);
6809 emit_block_move (blktramp
, initial_trampoline
,
6810 GEN_INT (TRAMPOLINE_SIZE
));
6812 INITIALIZE_TRAMPOLINE (tramp
, XEXP (DECL_RTL (function
), 0), context
);
6816 /* Put those insns at entry to the containing function (this one). */
6817 emit_insn_before (seq
, tail_recursion_reentry
);
6820 /* If we are doing stack checking and this function makes calls,
6821 do a stack probe at the start of the function to ensure we have enough
6822 space for another stack frame. */
6823 if (flag_stack_check
&& ! STACK_CHECK_BUILTIN
)
6827 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6828 if (GET_CODE (insn
) == CALL_INSN
)
6831 probe_stack_range (STACK_CHECK_PROTECT
,
6832 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
));
6835 emit_insn_before (seq
, tail_recursion_reentry
);
6840 /* Warn about unused parms if extra warnings were specified. */
6841 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
6842 warning. WARN_UNUSED_PARAMETER is negative when set by
6844 if (warn_unused_parameter
> 0
6845 || (warn_unused_parameter
< 0 && extra_warnings
))
6849 for (decl
= DECL_ARGUMENTS (current_function_decl
);
6850 decl
; decl
= TREE_CHAIN (decl
))
6851 if (! TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
6852 && DECL_NAME (decl
) && ! DECL_ARTIFICIAL (decl
))
6853 warning_with_decl (decl
, "unused parameter `%s'");
6856 /* Delete handlers for nonlocal gotos if nothing uses them. */
6857 if (nonlocal_goto_handler_slots
!= 0
6858 && ! current_function_has_nonlocal_label
)
6861 /* End any sequences that failed to be closed due to syntax errors. */
6862 while (in_sequence_p ())
6865 /* Outside function body, can't compute type's actual size
6866 until next function's body starts. */
6867 immediate_size_expand
--;
6869 clear_pending_stack_adjust ();
6870 do_pending_stack_adjust ();
6872 /* Mark the end of the function body.
6873 If control reaches this insn, the function can drop through
6874 without returning a value. */
6875 emit_note (NULL
, NOTE_INSN_FUNCTION_END
);
6877 /* Must mark the last line number note in the function, so that the test
6878 coverage code can avoid counting the last line twice. This just tells
6879 the code to ignore the immediately following line note, since there
6880 already exists a copy of this note somewhere above. This line number
6881 note is still needed for debugging though, so we can't delete it. */
6882 if (flag_test_coverage
)
6883 emit_note (NULL
, NOTE_INSN_REPEATED_LINE_NUMBER
);
6885 /* Output a linenumber for the end of the function.
6886 SDB depends on this. */
6887 emit_line_note_force (filename
, line
);
6889 /* Before the return label (if any), clobber the return
6890 registers so that they are not propagated live to the rest of
6891 the function. This can only happen with functions that drop
6892 through; if there had been a return statement, there would
6893 have either been a return rtx, or a jump to the return label.
6895 We delay actual code generation after the current_function_value_rtx
6897 clobber_after
= get_last_insn ();
6899 /* Output the label for the actual return from the function,
6900 if one is expected. This happens either because a function epilogue
6901 is used instead of a return instruction, or because a return was done
6902 with a goto in order to run local cleanups, or because of pcc-style
6903 structure returning. */
6905 emit_label (return_label
);
6907 /* C++ uses this. */
6909 expand_end_bindings (0, 0, 0);
6911 if (current_function_instrument_entry_exit
)
6913 rtx fun
= DECL_RTL (current_function_decl
);
6914 if (GET_CODE (fun
) == MEM
)
6915 fun
= XEXP (fun
, 0);
6918 emit_library_call (profile_function_exit_libfunc
, LCT_NORMAL
, VOIDmode
,
6920 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS
,
6922 hard_frame_pointer_rtx
),
6926 /* Let except.c know where it should emit the call to unregister
6927 the function context for sjlj exceptions. */
6928 if (flag_exceptions
&& USING_SJLJ_EXCEPTIONS
)
6929 sjlj_emit_function_exit_after (get_last_insn ());
6931 /* If we had calls to alloca, and this machine needs
6932 an accurate stack pointer to exit the function,
6933 insert some code to save and restore the stack pointer. */
6934 #ifdef EXIT_IGNORE_STACK
6935 if (! EXIT_IGNORE_STACK
)
6937 if (current_function_calls_alloca
)
6941 emit_stack_save (SAVE_FUNCTION
, &tem
, parm_birth_insn
);
6942 emit_stack_restore (SAVE_FUNCTION
, tem
, NULL_RTX
);
6945 /* If scalar return value was computed in a pseudo-reg, or was a named
6946 return value that got dumped to the stack, copy that to the hard
6948 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
6950 tree decl_result
= DECL_RESULT (current_function_decl
);
6951 rtx decl_rtl
= DECL_RTL (decl_result
);
6953 if (REG_P (decl_rtl
)
6954 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
6955 : DECL_REGISTER (decl_result
))
6957 rtx real_decl_rtl
= current_function_return_rtx
;
6959 /* This should be set in assign_parms. */
6960 if (! REG_FUNCTION_VALUE_P (real_decl_rtl
))
6963 /* If this is a BLKmode structure being returned in registers,
6964 then use the mode computed in expand_return. Note that if
6965 decl_rtl is memory, then its mode may have been changed,
6966 but that current_function_return_rtx has not. */
6967 if (GET_MODE (real_decl_rtl
) == BLKmode
)
6968 PUT_MODE (real_decl_rtl
, GET_MODE (decl_rtl
));
6970 /* If a named return value dumped decl_return to memory, then
6971 we may need to re-do the PROMOTE_MODE signed/unsigned
6973 if (GET_MODE (real_decl_rtl
) != GET_MODE (decl_rtl
))
6975 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (decl_result
));
6977 #ifdef PROMOTE_FUNCTION_RETURN
6978 promote_mode (TREE_TYPE (decl_result
), GET_MODE (decl_rtl
),
6982 convert_move (real_decl_rtl
, decl_rtl
, unsignedp
);
6984 else if (GET_CODE (real_decl_rtl
) == PARALLEL
)
6985 emit_group_load (real_decl_rtl
, decl_rtl
,
6986 int_size_in_bytes (TREE_TYPE (decl_result
)));
6988 emit_move_insn (real_decl_rtl
, decl_rtl
);
6992 /* If returning a structure, arrange to return the address of the value
6993 in a place where debuggers expect to find it.
6995 If returning a structure PCC style,
6996 the caller also depends on this value.
6997 And current_function_returns_pcc_struct is not necessarily set. */
6998 if (current_function_returns_struct
6999 || current_function_returns_pcc_struct
)
7002 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl
)), 0);
7003 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
7004 #ifdef FUNCTION_OUTGOING_VALUE
7006 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type
),
7007 current_function_decl
);
7010 = FUNCTION_VALUE (build_pointer_type (type
), current_function_decl
);
7013 /* Mark this as a function return value so integrate will delete the
7014 assignment and USE below when inlining this function. */
7015 REG_FUNCTION_VALUE_P (outgoing
) = 1;
7017 #ifdef POINTERS_EXTEND_UNSIGNED
7018 /* The address may be ptr_mode and OUTGOING may be Pmode. */
7019 if (GET_MODE (outgoing
) != GET_MODE (value_address
))
7020 value_address
= convert_memory_address (GET_MODE (outgoing
),
7024 emit_move_insn (outgoing
, value_address
);
7026 /* Show return register used to hold result (in this case the address
7028 current_function_return_rtx
= outgoing
;
7031 /* If this is an implementation of throw, do what's necessary to
7032 communicate between __builtin_eh_return and the epilogue. */
7033 expand_eh_return ();
7035 /* Emit the actual code to clobber return register. */
7040 clobber_return_register ();
7044 after
= emit_insn_after (seq
, clobber_after
);
7046 if (clobber_after
!= after
)
7047 cfun
->x_clobber_return_insn
= after
;
7050 /* ??? This should no longer be necessary since stupid is no longer with
7051 us, but there are some parts of the compiler (eg reload_combine, and
7052 sh mach_dep_reorg) that still try and compute their own lifetime info
7053 instead of using the general framework. */
7054 use_return_register ();
7056 /* Fix up any gotos that jumped out to the outermost
7057 binding level of the function.
7058 Must follow emitting RETURN_LABEL. */
7060 /* If you have any cleanups to do at this point,
7061 and they need to create temporary variables,
7062 then you will lose. */
7063 expand_fixups (get_insns ());
7067 get_arg_pointer_save_area (f
)
7070 rtx ret
= f
->x_arg_pointer_save_area
;
7074 ret
= assign_stack_local_1 (Pmode
, GET_MODE_SIZE (Pmode
), 0, f
);
7075 f
->x_arg_pointer_save_area
= ret
;
7078 if (f
== cfun
&& ! f
->arg_pointer_save_area_init
)
7082 /* Save the arg pointer at the beginning of the function. The
7083 generated stack slot may not be a valid memory address, so we
7084 have to check it and fix it if necessary. */
7086 emit_move_insn (validize_mem (ret
), virtual_incoming_args_rtx
);
7090 push_topmost_sequence ();
7091 emit_insn_after (seq
, get_insns ());
7092 pop_topmost_sequence ();
7098 /* Extend a vector that records the INSN_UIDs of INSNS
7099 (a list of one or more insns). */
7102 record_insns (insns
, vecp
)
7111 while (tmp
!= NULL_RTX
)
7114 tmp
= NEXT_INSN (tmp
);
7117 i
= VARRAY_SIZE (*vecp
);
7118 VARRAY_GROW (*vecp
, i
+ len
);
7120 while (tmp
!= NULL_RTX
)
7122 VARRAY_INT (*vecp
, i
) = INSN_UID (tmp
);
7124 tmp
= NEXT_INSN (tmp
);
7128 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
7129 be running after reorg, SEQUENCE rtl is possible. */
7132 contains (insn
, vec
)
7138 if (GET_CODE (insn
) == INSN
7139 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
7142 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
7143 for (j
= VARRAY_SIZE (vec
) - 1; j
>= 0; --j
)
7144 if (INSN_UID (XVECEXP (PATTERN (insn
), 0, i
)) == VARRAY_INT (vec
, j
))
7150 for (j
= VARRAY_SIZE (vec
) - 1; j
>= 0; --j
)
7151 if (INSN_UID (insn
) == VARRAY_INT (vec
, j
))
7158 prologue_epilogue_contains (insn
)
7161 if (contains (insn
, prologue
))
7163 if (contains (insn
, epilogue
))
7169 sibcall_epilogue_contains (insn
)
7172 if (sibcall_epilogue
)
7173 return contains (insn
, sibcall_epilogue
);
7178 /* Insert gen_return at the end of block BB. This also means updating
7179 block_for_insn appropriately. */
7182 emit_return_into_block (bb
, line_note
)
7188 p
= NEXT_INSN (bb
->end
);
7189 end
= emit_jump_insn_after (gen_return (), bb
->end
);
7191 emit_line_note_after (NOTE_SOURCE_FILE (line_note
),
7192 NOTE_LINE_NUMBER (line_note
), PREV_INSN (bb
->end
));
7194 #endif /* HAVE_return */
7196 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7198 /* These functions convert the epilogue into a variant that does not modify the
7199 stack pointer. This is used in cases where a function returns an object
7200 whose size is not known until it is computed. The called function leaves the
7201 object on the stack, leaves the stack depressed, and returns a pointer to
7204 What we need to do is track all modifications and references to the stack
7205 pointer, deleting the modifications and changing the references to point to
7206 the location the stack pointer would have pointed to had the modifications
7209 These functions need to be portable so we need to make as few assumptions
7210 about the epilogue as we can. However, the epilogue basically contains
7211 three things: instructions to reset the stack pointer, instructions to
7212 reload registers, possibly including the frame pointer, and an
7213 instruction to return to the caller.
7215 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7216 We also make no attempt to validate the insns we make since if they are
7217 invalid, we probably can't do anything valid. The intent is that these
7218 routines get "smarter" as more and more machines start to use them and
7219 they try operating on different epilogues.
7221 We use the following structure to track what the part of the epilogue that
7222 we've already processed has done. We keep two copies of the SP equivalence,
7223 one for use during the insn we are processing and one for use in the next
7224 insn. The difference is because one part of a PARALLEL may adjust SP
7225 and the other may use it. */
7229 rtx sp_equiv_reg
; /* REG that SP is set from, perhaps SP. */
7230 HOST_WIDE_INT sp_offset
; /* Offset from SP_EQUIV_REG of present SP. */
7231 rtx new_sp_equiv_reg
; /* REG to be used at end of insn. */
7232 HOST_WIDE_INT new_sp_offset
; /* Offset to be used at end of insn. */
7233 rtx equiv_reg_src
; /* If nonzero, the value that SP_EQUIV_REG
7234 should be set to once we no longer need
7238 static void handle_epilogue_set
PARAMS ((rtx
, struct epi_info
*));
7239 static void emit_equiv_load
PARAMS ((struct epi_info
*));
7241 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
7242 no modifications to the stack pointer. Return the new list of insns. */
7245 keep_stack_depressed (insns
)
7249 struct epi_info info
;
7252 /* If the epilogue is just a single instruction, it ust be OK as is. */
7254 if (NEXT_INSN (insns
) == NULL_RTX
)
7257 /* Otherwise, start a sequence, initialize the information we have, and
7258 process all the insns we were given. */
7261 info
.sp_equiv_reg
= stack_pointer_rtx
;
7263 info
.equiv_reg_src
= 0;
7267 while (insn
!= NULL_RTX
)
7269 next
= NEXT_INSN (insn
);
7278 /* If this insn references the register that SP is equivalent to and
7279 we have a pending load to that register, we must force out the load
7280 first and then indicate we no longer know what SP's equivalent is. */
7281 if (info
.equiv_reg_src
!= 0
7282 && reg_referenced_p (info
.sp_equiv_reg
, PATTERN (insn
)))
7284 emit_equiv_load (&info
);
7285 info
.sp_equiv_reg
= 0;
7288 info
.new_sp_equiv_reg
= info
.sp_equiv_reg
;
7289 info
.new_sp_offset
= info
.sp_offset
;
7291 /* If this is a (RETURN) and the return address is on the stack,
7292 update the address and change to an indirect jump. */
7293 if (GET_CODE (PATTERN (insn
)) == RETURN
7294 || (GET_CODE (PATTERN (insn
)) == PARALLEL
7295 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == RETURN
))
7297 rtx retaddr
= INCOMING_RETURN_ADDR_RTX
;
7299 HOST_WIDE_INT offset
= 0;
7300 rtx jump_insn
, jump_set
;
7302 /* If the return address is in a register, we can emit the insn
7303 unchanged. Otherwise, it must be a MEM and we see what the
7304 base register and offset are. In any case, we have to emit any
7305 pending load to the equivalent reg of SP, if any. */
7306 if (GET_CODE (retaddr
) == REG
)
7308 emit_equiv_load (&info
);
7313 else if (GET_CODE (retaddr
) == MEM
7314 && GET_CODE (XEXP (retaddr
, 0)) == REG
)
7315 base
= gen_rtx_REG (Pmode
, REGNO (XEXP (retaddr
, 0))), offset
= 0;
7316 else if (GET_CODE (retaddr
) == MEM
7317 && GET_CODE (XEXP (retaddr
, 0)) == PLUS
7318 && GET_CODE (XEXP (XEXP (retaddr
, 0), 0)) == REG
7319 && GET_CODE (XEXP (XEXP (retaddr
, 0), 1)) == CONST_INT
)
7321 base
= gen_rtx_REG (Pmode
, REGNO (XEXP (XEXP (retaddr
, 0), 0)));
7322 offset
= INTVAL (XEXP (XEXP (retaddr
, 0), 1));
7327 /* If the base of the location containing the return pointer
7328 is SP, we must update it with the replacement address. Otherwise,
7329 just build the necessary MEM. */
7330 retaddr
= plus_constant (base
, offset
);
7331 if (base
== stack_pointer_rtx
)
7332 retaddr
= simplify_replace_rtx (retaddr
, stack_pointer_rtx
,
7333 plus_constant (info
.sp_equiv_reg
,
7336 retaddr
= gen_rtx_MEM (Pmode
, retaddr
);
7338 /* If there is a pending load to the equivalent register for SP
7339 and we reference that register, we must load our address into
7340 a scratch register and then do that load. */
7341 if (info
.equiv_reg_src
7342 && reg_overlap_mentioned_p (info
.equiv_reg_src
, retaddr
))
7347 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
7348 if (HARD_REGNO_MODE_OK (regno
, Pmode
)
7349 && !fixed_regs
[regno
]
7350 && TEST_HARD_REG_BIT (regs_invalidated_by_call
, regno
)
7351 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR
->global_live_at_start
,
7353 && !refers_to_regno_p (regno
,
7354 regno
+ HARD_REGNO_NREGS (regno
,
7356 info
.equiv_reg_src
, NULL
))
7359 if (regno
== FIRST_PSEUDO_REGISTER
)
7362 reg
= gen_rtx_REG (Pmode
, regno
);
7363 emit_move_insn (reg
, retaddr
);
7367 emit_equiv_load (&info
);
7368 jump_insn
= emit_jump_insn (gen_indirect_jump (retaddr
));
7370 /* Show the SET in the above insn is a RETURN. */
7371 jump_set
= single_set (jump_insn
);
7375 SET_IS_RETURN_P (jump_set
) = 1;
7378 /* If SP is not mentioned in the pattern and its equivalent register, if
7379 any, is not modified, just emit it. Otherwise, if neither is set,
7380 replace the reference to SP and emit the insn. If none of those are
7381 true, handle each SET individually. */
7382 else if (!reg_mentioned_p (stack_pointer_rtx
, PATTERN (insn
))
7383 && (info
.sp_equiv_reg
== stack_pointer_rtx
7384 || !reg_set_p (info
.sp_equiv_reg
, insn
)))
7386 else if (! reg_set_p (stack_pointer_rtx
, insn
)
7387 && (info
.sp_equiv_reg
== stack_pointer_rtx
7388 || !reg_set_p (info
.sp_equiv_reg
, insn
)))
7390 if (! validate_replace_rtx (stack_pointer_rtx
,
7391 plus_constant (info
.sp_equiv_reg
,
7398 else if (GET_CODE (PATTERN (insn
)) == SET
)
7399 handle_epilogue_set (PATTERN (insn
), &info
);
7400 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
7402 for (j
= 0; j
< XVECLEN (PATTERN (insn
), 0); j
++)
7403 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, j
)) == SET
)
7404 handle_epilogue_set (XVECEXP (PATTERN (insn
), 0, j
), &info
);
7409 info
.sp_equiv_reg
= info
.new_sp_equiv_reg
;
7410 info
.sp_offset
= info
.new_sp_offset
;
7415 insns
= get_insns ();
7420 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7421 structure that contains information about what we've seen so far. We
7422 process this SET by either updating that data or by emitting one or
7426 handle_epilogue_set (set
, p
)
7430 /* First handle the case where we are setting SP. Record what it is being
7431 set from. If unknown, abort. */
7432 if (reg_set_p (stack_pointer_rtx
, set
))
7434 if (SET_DEST (set
) != stack_pointer_rtx
)
7437 if (GET_CODE (SET_SRC (set
)) == PLUS
7438 && GET_CODE (XEXP (SET_SRC (set
), 1)) == CONST_INT
)
7440 p
->new_sp_equiv_reg
= XEXP (SET_SRC (set
), 0);
7441 p
->new_sp_offset
= INTVAL (XEXP (SET_SRC (set
), 1));
7444 p
->new_sp_equiv_reg
= SET_SRC (set
), p
->new_sp_offset
= 0;
7446 /* If we are adjusting SP, we adjust from the old data. */
7447 if (p
->new_sp_equiv_reg
== stack_pointer_rtx
)
7449 p
->new_sp_equiv_reg
= p
->sp_equiv_reg
;
7450 p
->new_sp_offset
+= p
->sp_offset
;
7453 if (p
->new_sp_equiv_reg
== 0 || GET_CODE (p
->new_sp_equiv_reg
) != REG
)
7459 /* Next handle the case where we are setting SP's equivalent register.
7460 If we already have a value to set it to, abort. We could update, but
7461 there seems little point in handling that case. Note that we have
7462 to allow for the case where we are setting the register set in
7463 the previous part of a PARALLEL inside a single insn. But use the
7464 old offset for any updates within this insn. */
7465 else if (p
->new_sp_equiv_reg
!= 0 && reg_set_p (p
->new_sp_equiv_reg
, set
))
7467 if (!rtx_equal_p (p
->new_sp_equiv_reg
, SET_DEST (set
))
7468 || p
->equiv_reg_src
!= 0)
7472 = simplify_replace_rtx (SET_SRC (set
), stack_pointer_rtx
,
7473 plus_constant (p
->sp_equiv_reg
,
7477 /* Otherwise, replace any references to SP in the insn to its new value
7478 and emit the insn. */
7481 SET_SRC (set
) = simplify_replace_rtx (SET_SRC (set
), stack_pointer_rtx
,
7482 plus_constant (p
->sp_equiv_reg
,
7484 SET_DEST (set
) = simplify_replace_rtx (SET_DEST (set
), stack_pointer_rtx
,
7485 plus_constant (p
->sp_equiv_reg
,
7491 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7497 if (p
->equiv_reg_src
!= 0)
7498 emit_move_insn (p
->sp_equiv_reg
, p
->equiv_reg_src
);
7500 p
->equiv_reg_src
= 0;
7504 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7505 this into place with notes indicating where the prologue ends and where
7506 the epilogue begins. Update the basic block information when possible. */
7509 thread_prologue_and_epilogue_insns (f
)
7510 rtx f ATTRIBUTE_UNUSED
;
7514 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7517 #ifdef HAVE_prologue
7518 rtx prologue_end
= NULL_RTX
;
7520 #if defined (HAVE_epilogue) || defined(HAVE_return)
7521 rtx epilogue_end
= NULL_RTX
;
7524 #ifdef HAVE_prologue
7528 seq
= gen_prologue ();
7531 /* Retain a map of the prologue insns. */
7532 record_insns (seq
, &prologue
);
7533 prologue_end
= emit_note (NULL
, NOTE_INSN_PROLOGUE_END
);
7538 /* Can't deal with multiple successors of the entry block
7539 at the moment. Function should always have at least one
7541 if (!ENTRY_BLOCK_PTR
->succ
|| ENTRY_BLOCK_PTR
->succ
->succ_next
)
7544 insert_insn_on_edge (seq
, ENTRY_BLOCK_PTR
->succ
);
7549 /* If the exit block has no non-fake predecessors, we don't need
7551 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7552 if ((e
->flags
& EDGE_FAKE
) == 0)
7558 if (optimize
&& HAVE_return
)
7560 /* If we're allowed to generate a simple return instruction,
7561 then by definition we don't need a full epilogue. Examine
7562 the block that falls through to EXIT. If it does not
7563 contain any code, examine its predecessors and try to
7564 emit (conditional) return instructions. */
7570 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7571 if (e
->flags
& EDGE_FALLTHRU
)
7577 /* Verify that there are no active instructions in the last block. */
7579 while (label
&& GET_CODE (label
) != CODE_LABEL
)
7581 if (active_insn_p (label
))
7583 label
= PREV_INSN (label
);
7586 if (last
->head
== label
&& GET_CODE (label
) == CODE_LABEL
)
7588 rtx epilogue_line_note
= NULL_RTX
;
7590 /* Locate the line number associated with the closing brace,
7591 if we can find one. */
7592 for (seq
= get_last_insn ();
7593 seq
&& ! active_insn_p (seq
);
7594 seq
= PREV_INSN (seq
))
7595 if (GET_CODE (seq
) == NOTE
&& NOTE_LINE_NUMBER (seq
) > 0)
7597 epilogue_line_note
= seq
;
7601 for (e
= last
->pred
; e
; e
= e_next
)
7603 basic_block bb
= e
->src
;
7606 e_next
= e
->pred_next
;
7607 if (bb
== ENTRY_BLOCK_PTR
)
7611 if ((GET_CODE (jump
) != JUMP_INSN
) || JUMP_LABEL (jump
) != label
)
7614 /* If we have an unconditional jump, we can replace that
7615 with a simple return instruction. */
7616 if (simplejump_p (jump
))
7618 emit_return_into_block (bb
, epilogue_line_note
);
7622 /* If we have a conditional jump, we can try to replace
7623 that with a conditional return instruction. */
7624 else if (condjump_p (jump
))
7628 ret
= SET_SRC (PATTERN (jump
));
7629 if (GET_CODE (XEXP (ret
, 1)) == LABEL_REF
)
7630 loc
= &XEXP (ret
, 1);
7632 loc
= &XEXP (ret
, 2);
7633 ret
= gen_rtx_RETURN (VOIDmode
);
7635 if (! validate_change (jump
, loc
, ret
, 0))
7637 if (JUMP_LABEL (jump
))
7638 LABEL_NUSES (JUMP_LABEL (jump
))--;
7640 /* If this block has only one successor, it both jumps
7641 and falls through to the fallthru block, so we can't
7643 if (bb
->succ
->succ_next
== NULL
)
7649 /* Fix up the CFG for the successful change we just made. */
7650 redirect_edge_succ (e
, EXIT_BLOCK_PTR
);
7653 /* Emit a return insn for the exit fallthru block. Whether
7654 this is still reachable will be determined later. */
7656 emit_barrier_after (last
->end
);
7657 emit_return_into_block (last
, epilogue_line_note
);
7658 epilogue_end
= last
->end
;
7659 last
->succ
->flags
&= ~EDGE_FALLTHRU
;
7664 #ifdef HAVE_epilogue
7667 /* Find the edge that falls through to EXIT. Other edges may exist
7668 due to RETURN instructions, but those don't need epilogues.
7669 There really shouldn't be a mixture -- either all should have
7670 been converted or none, however... */
7672 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7673 if (e
->flags
& EDGE_FALLTHRU
)
7679 epilogue_end
= emit_note (NULL
, NOTE_INSN_EPILOGUE_BEG
);
7681 seq
= gen_epilogue ();
7683 #ifdef INCOMING_RETURN_ADDR_RTX
7684 /* If this function returns with the stack depressed and we can support
7685 it, massage the epilogue to actually do that. */
7686 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == FUNCTION_TYPE
7687 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl
)))
7688 seq
= keep_stack_depressed (seq
);
7691 emit_jump_insn (seq
);
7693 /* Retain a map of the epilogue insns. */
7694 record_insns (seq
, &epilogue
);
7699 insert_insn_on_edge (seq
, e
);
7706 commit_edge_insertions ();
7708 #ifdef HAVE_sibcall_epilogue
7709 /* Emit sibling epilogues before any sibling call sites. */
7710 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7712 basic_block bb
= e
->src
;
7717 if (GET_CODE (insn
) != CALL_INSN
7718 || ! SIBLING_CALL_P (insn
))
7722 emit_insn (gen_sibcall_epilogue ());
7726 /* Retain a map of the epilogue insns. Used in life analysis to
7727 avoid getting rid of sibcall epilogue insns. Do this before we
7728 actually emit the sequence. */
7729 record_insns (seq
, &sibcall_epilogue
);
7731 i
= PREV_INSN (insn
);
7732 newinsn
= emit_insn_before (seq
, insn
);
7736 #ifdef HAVE_prologue
7741 /* GDB handles `break f' by setting a breakpoint on the first
7742 line note after the prologue. Which means (1) that if
7743 there are line number notes before where we inserted the
7744 prologue we should move them, and (2) we should generate a
7745 note before the end of the first basic block, if there isn't
7748 ??? This behaviour is completely broken when dealing with
7749 multiple entry functions. We simply place the note always
7750 into first basic block and let alternate entry points
7754 for (insn
= prologue_end
; insn
; insn
= prev
)
7756 prev
= PREV_INSN (insn
);
7757 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7759 /* Note that we cannot reorder the first insn in the
7760 chain, since rest_of_compilation relies on that
7761 remaining constant. */
7764 reorder_insns (insn
, insn
, prologue_end
);
7768 /* Find the last line number note in the first block. */
7769 for (insn
= ENTRY_BLOCK_PTR
->next_bb
->end
;
7770 insn
!= prologue_end
&& insn
;
7771 insn
= PREV_INSN (insn
))
7772 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7775 /* If we didn't find one, make a copy of the first line number
7779 for (insn
= next_active_insn (prologue_end
);
7781 insn
= PREV_INSN (insn
))
7782 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7784 emit_line_note_after (NOTE_SOURCE_FILE (insn
),
7785 NOTE_LINE_NUMBER (insn
),
7792 #ifdef HAVE_epilogue
7797 /* Similarly, move any line notes that appear after the epilogue.
7798 There is no need, however, to be quite so anal about the existence
7800 for (insn
= epilogue_end
; insn
; insn
= next
)
7802 next
= NEXT_INSN (insn
);
7803 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7804 reorder_insns (insn
, insn
, PREV_INSN (epilogue_end
));
7810 /* Reposition the prologue-end and epilogue-begin notes after instruction
7811 scheduling and delayed branch scheduling. */
7814 reposition_prologue_and_epilogue_notes (f
)
7815 rtx f ATTRIBUTE_UNUSED
;
7817 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7818 rtx insn
, last
, note
;
7821 if ((len
= VARRAY_SIZE (prologue
)) > 0)
7825 /* Scan from the beginning until we reach the last prologue insn.
7826 We apparently can't depend on basic_block_{head,end} after
7828 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
7830 if (GET_CODE (insn
) == NOTE
)
7832 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
7835 else if (contains (insn
, prologue
))
7847 /* Find the prologue-end note if we haven't already, and
7848 move it to just after the last prologue insn. */
7851 for (note
= last
; (note
= NEXT_INSN (note
));)
7852 if (GET_CODE (note
) == NOTE
7853 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_PROLOGUE_END
)
7857 next
= NEXT_INSN (note
);
7859 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7860 if (GET_CODE (last
) == CODE_LABEL
)
7861 last
= NEXT_INSN (last
);
7862 reorder_insns (note
, note
, last
);
7866 if ((len
= VARRAY_SIZE (epilogue
)) > 0)
7870 /* Scan from the end until we reach the first epilogue insn.
7871 We apparently can't depend on basic_block_{head,end} after
7873 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
7875 if (GET_CODE (insn
) == NOTE
)
7877 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EPILOGUE_BEG
)
7880 else if (contains (insn
, epilogue
))
7890 /* Find the epilogue-begin note if we haven't already, and
7891 move it to just before the first epilogue insn. */
7894 for (note
= insn
; (note
= PREV_INSN (note
));)
7895 if (GET_CODE (note
) == NOTE
7896 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_EPILOGUE_BEG
)
7900 if (PREV_INSN (last
) != note
)
7901 reorder_insns (note
, note
, PREV_INSN (last
));
7904 #endif /* HAVE_prologue or HAVE_epilogue */
7907 /* Called once, at initialization, to initialize function.c. */
7910 init_function_once ()
7912 VARRAY_INT_INIT (prologue
, 0, "prologue");
7913 VARRAY_INT_INIT (epilogue
, 0, "epilogue");
7914 VARRAY_INT_INIT (sibcall_epilogue
, 0, "sibcall_epilogue");
7917 #include "gt-function.h"