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. */
43 #include "coretypes.h"
53 #include "hard-reg-set.h"
54 #include "insn-config.h"
57 #include "basic-block.h"
62 #include "integrate.h"
63 #include "langhooks.h"
65 #ifndef TRAMPOLINE_ALIGNMENT
66 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
69 #ifndef LOCAL_ALIGNMENT
70 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
73 /* Some systems use __main in a way incompatible with its use in gcc, in these
74 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
75 give the same symbol without quotes for an alternative entry point. You
76 must define both, or neither. */
78 #define NAME__MAIN "__main"
81 /* Round a value to the lowest integer less than it that is a multiple of
82 the required alignment. Avoid using division in case the value is
83 negative. Assume the alignment is a power of two. */
84 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
86 /* Similar, but round to the next highest integer that meets the
88 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
90 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
91 during rtl generation. If they are different register numbers, this is
92 always true. It may also be true if
93 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
94 generation. See fix_lexical_addr for details. */
96 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
97 #define NEED_SEPARATE_AP
100 /* Nonzero if function being compiled doesn't contain any calls
101 (ignoring the prologue and epilogue). This is set prior to
102 local register allocation and is valid for the remaining
104 int current_function_is_leaf
;
106 /* Nonzero if function being compiled doesn't contain any instructions
107 that can throw an exception. This is set prior to final. */
109 int current_function_nothrow
;
111 /* Nonzero if function being compiled doesn't modify the stack pointer
112 (ignoring the prologue and epilogue). This is only valid after
113 life_analysis has run. */
114 int current_function_sp_is_unchanging
;
116 /* Nonzero if the function being compiled is a leaf function which only
117 uses leaf registers. This is valid after reload (specifically after
118 sched2) and is useful only if the port defines LEAF_REGISTERS. */
119 int current_function_uses_only_leaf_regs
;
121 /* Nonzero once virtual register instantiation has been done.
122 assign_stack_local uses frame_pointer_rtx when this is nonzero.
123 calls.c:emit_library_call_value_1 uses it to set up
124 post-instantiation libcalls. */
125 int virtuals_instantiated
;
127 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
128 static GTY(()) int funcdef_no
;
130 /* These variables hold pointers to functions to create and destroy
131 target specific, per-function data structures. */
132 struct machine_function
* (*init_machine_status
) PARAMS ((void));
134 /* The FUNCTION_DECL for an inline function currently being expanded. */
135 tree inline_function_decl
;
137 /* The currently compiled function. */
138 struct function
*cfun
= 0;
140 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
141 static GTY(()) varray_type prologue
;
142 static GTY(()) varray_type epilogue
;
144 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
146 static GTY(()) varray_type sibcall_epilogue
;
148 /* In order to evaluate some expressions, such as function calls returning
149 structures in memory, we need to temporarily allocate stack locations.
150 We record each allocated temporary in the following structure.
152 Associated with each temporary slot is a nesting level. When we pop up
153 one level, all temporaries associated with the previous level are freed.
154 Normally, all temporaries are freed after the execution of the statement
155 in which they were created. However, if we are inside a ({...}) grouping,
156 the result may be in a temporary and hence must be preserved. If the
157 result could be in a temporary, we preserve it if we can determine which
158 one it is in. If we cannot determine which temporary may contain the
159 result, all temporaries are preserved. A temporary is preserved by
160 pretending it was allocated at the previous nesting level.
162 Automatic variables are also assigned temporary slots, at the nesting
163 level where they are defined. They are marked a "kept" so that
164 free_temp_slots will not free them. */
166 struct temp_slot
GTY(())
168 /* Points to next temporary slot. */
169 struct temp_slot
*next
;
170 /* The rtx to used to reference the slot. */
172 /* The rtx used to represent the address if not the address of the
173 slot above. May be an EXPR_LIST if multiple addresses exist. */
175 /* The alignment (in bits) of the slot. */
177 /* The size, in units, of the slot. */
179 /* The type of the object in the slot, or zero if it doesn't correspond
180 to a type. We use this to determine whether a slot can be reused.
181 It can be reused if objects of the type of the new slot will always
182 conflict with objects of the type of the old slot. */
184 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
186 /* Nonzero if this temporary is currently in use. */
188 /* Nonzero if this temporary has its address taken. */
190 /* Nesting level at which this slot is being used. */
192 /* Nonzero if this should survive a call to free_temp_slots. */
194 /* The offset of the slot from the frame_pointer, including extra space
195 for alignment. This info is for combine_temp_slots. */
196 HOST_WIDE_INT base_offset
;
197 /* The size of the slot, including extra space for alignment. This
198 info is for combine_temp_slots. */
199 HOST_WIDE_INT full_size
;
202 /* This structure is used to record MEMs or pseudos used to replace VAR, any
203 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
204 maintain this list in case two operands of an insn were required to match;
205 in that case we must ensure we use the same replacement. */
207 struct fixup_replacement
GTY(())
211 struct fixup_replacement
*next
;
214 struct insns_for_mem_entry
218 /* These are the INSNs which reference the MEM. */
222 /* Forward declarations. */
224 static rtx assign_stack_local_1
PARAMS ((enum machine_mode
, HOST_WIDE_INT
,
225 int, struct function
*));
226 static struct temp_slot
*find_temp_slot_from_address
PARAMS ((rtx
));
227 static void put_reg_into_stack
PARAMS ((struct function
*, rtx
, tree
,
228 enum machine_mode
, enum machine_mode
,
229 int, unsigned int, int,
231 static void schedule_fixup_var_refs
PARAMS ((struct function
*, rtx
, tree
,
234 static void fixup_var_refs
PARAMS ((rtx
, enum machine_mode
, int, rtx
,
236 static struct fixup_replacement
237 *find_fixup_replacement
PARAMS ((struct fixup_replacement
**, rtx
));
238 static void fixup_var_refs_insns
PARAMS ((rtx
, rtx
, enum machine_mode
,
240 static void fixup_var_refs_insns_with_hash
241 PARAMS ((htab_t
, rtx
,
242 enum machine_mode
, int, rtx
));
243 static void fixup_var_refs_insn
PARAMS ((rtx
, rtx
, enum machine_mode
,
245 static void fixup_var_refs_1
PARAMS ((rtx
, enum machine_mode
, rtx
*, rtx
,
246 struct fixup_replacement
**, rtx
));
247 static rtx fixup_memory_subreg
PARAMS ((rtx
, rtx
, enum machine_mode
, int));
248 static rtx walk_fixup_memory_subreg
PARAMS ((rtx
, rtx
, enum machine_mode
,
250 static rtx fixup_stack_1
PARAMS ((rtx
, rtx
));
251 static void optimize_bit_field
PARAMS ((rtx
, rtx
, rtx
*));
252 static void instantiate_decls
PARAMS ((tree
, int));
253 static void instantiate_decls_1
PARAMS ((tree
, int));
254 static void instantiate_decl
PARAMS ((rtx
, HOST_WIDE_INT
, int));
255 static rtx instantiate_new_reg
PARAMS ((rtx
, HOST_WIDE_INT
*));
256 static int instantiate_virtual_regs_1
PARAMS ((rtx
*, rtx
, int));
257 static void delete_handlers
PARAMS ((void));
258 static void pad_to_arg_alignment
PARAMS ((struct args_size
*, int,
259 struct args_size
*));
260 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
->computed_goto_common_label
= NULL
;
456 f
->computed_goto_common_reg
= NULL
;
457 f
->x_save_expr_regs
= NULL
;
458 f
->x_stack_slot_list
= NULL
;
459 f
->x_rtl_expr_chain
= NULL
;
460 f
->x_tail_recursion_label
= NULL
;
461 f
->x_tail_recursion_reentry
= NULL
;
462 f
->x_arg_pointer_save_area
= NULL
;
463 f
->x_clobber_return_insn
= NULL
;
464 f
->x_context_display
= NULL
;
465 f
->x_trampoline_list
= NULL
;
466 f
->x_parm_birth_insn
= NULL
;
467 f
->x_last_parm_insn
= NULL
;
468 f
->x_parm_reg_stack_loc
= NULL
;
469 f
->fixup_var_refs_queue
= NULL
;
470 f
->original_arg_vector
= NULL
;
471 f
->original_decl_initial
= NULL
;
472 f
->inl_last_parm_insn
= NULL
;
473 f
->epilogue_delay_list
= NULL
;
476 /* Allocate fixed slots in the stack frame of the current function. */
478 /* Return size needed for stack frame based on slots so far allocated in
480 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
481 the caller may have to do that. */
484 get_func_frame_size (f
)
487 #ifdef FRAME_GROWS_DOWNWARD
488 return -f
->x_frame_offset
;
490 return f
->x_frame_offset
;
494 /* Return size needed for stack frame based on slots so far allocated.
495 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
496 the caller may have to do that. */
500 return get_func_frame_size (cfun
);
503 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
504 with machine mode MODE.
506 ALIGN controls the amount of alignment for the address of the slot:
507 0 means according to MODE,
508 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
509 positive specifies alignment boundary in bits.
511 We do not round to stack_boundary here.
513 FUNCTION specifies the function to allocate in. */
516 assign_stack_local_1 (mode
, size
, align
, function
)
517 enum machine_mode mode
;
520 struct function
*function
;
523 int bigend_correction
= 0;
525 int frame_off
, frame_alignment
, frame_phase
;
532 alignment
= BIGGEST_ALIGNMENT
;
534 alignment
= GET_MODE_ALIGNMENT (mode
);
536 /* Allow the target to (possibly) increase the alignment of this
538 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 0);
540 alignment
= LOCAL_ALIGNMENT (type
, alignment
);
542 alignment
/= BITS_PER_UNIT
;
544 else if (align
== -1)
546 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
547 size
= CEIL_ROUND (size
, alignment
);
550 alignment
= align
/ BITS_PER_UNIT
;
552 #ifdef FRAME_GROWS_DOWNWARD
553 function
->x_frame_offset
-= size
;
556 /* Ignore alignment we can't do with expected alignment of the boundary. */
557 if (alignment
* BITS_PER_UNIT
> PREFERRED_STACK_BOUNDARY
)
558 alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
560 if (function
->stack_alignment_needed
< alignment
* BITS_PER_UNIT
)
561 function
->stack_alignment_needed
= alignment
* BITS_PER_UNIT
;
563 /* Calculate how many bytes the start of local variables is off from
565 frame_alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
566 frame_off
= STARTING_FRAME_OFFSET
% frame_alignment
;
567 frame_phase
= frame_off
? frame_alignment
- frame_off
: 0;
569 /* Round frame offset to that alignment.
570 We must be careful here, since FRAME_OFFSET might be negative and
571 division with a negative dividend isn't as well defined as we might
572 like. So we instead assume that ALIGNMENT is a power of two and
573 use logical operations which are unambiguous. */
574 #ifdef FRAME_GROWS_DOWNWARD
575 function
->x_frame_offset
= FLOOR_ROUND (function
->x_frame_offset
- frame_phase
, alignment
) + frame_phase
;
577 function
->x_frame_offset
= CEIL_ROUND (function
->x_frame_offset
- frame_phase
, alignment
) + frame_phase
;
580 /* On a big-endian machine, if we are allocating more space than we will use,
581 use the least significant bytes of those that are allocated. */
582 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
583 bigend_correction
= size
- GET_MODE_SIZE (mode
);
585 /* If we have already instantiated virtual registers, return the actual
586 address relative to the frame pointer. */
587 if (function
== cfun
&& virtuals_instantiated
)
588 addr
= plus_constant (frame_pointer_rtx
,
589 (frame_offset
+ bigend_correction
590 + STARTING_FRAME_OFFSET
));
592 addr
= plus_constant (virtual_stack_vars_rtx
,
593 function
->x_frame_offset
+ bigend_correction
);
595 #ifndef FRAME_GROWS_DOWNWARD
596 function
->x_frame_offset
+= size
;
599 x
= gen_rtx_MEM (mode
, addr
);
601 function
->x_stack_slot_list
602 = gen_rtx_EXPR_LIST (VOIDmode
, x
, function
->x_stack_slot_list
);
607 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
611 assign_stack_local (mode
, size
, align
)
612 enum machine_mode mode
;
616 return assign_stack_local_1 (mode
, size
, align
, cfun
);
619 /* Allocate a temporary stack slot and record it for possible later
622 MODE is the machine mode to be given to the returned rtx.
624 SIZE is the size in units of the space required. We do no rounding here
625 since assign_stack_local will do any required rounding.
627 KEEP is 1 if this slot is to be retained after a call to
628 free_temp_slots. Automatic variables for a block are allocated
629 with this flag. KEEP is 2 if we allocate a longer term temporary,
630 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
631 if we are to allocate something at an inner level to be treated as
632 a variable in the block (e.g., a SAVE_EXPR).
634 TYPE is the type that will be used for the stack slot. */
637 assign_stack_temp_for_type (mode
, size
, keep
, type
)
638 enum machine_mode mode
;
644 struct temp_slot
*p
, *best_p
= 0;
647 /* If SIZE is -1 it means that somebody tried to allocate a temporary
648 of a variable size. */
653 align
= BIGGEST_ALIGNMENT
;
655 align
= GET_MODE_ALIGNMENT (mode
);
658 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 0);
661 align
= LOCAL_ALIGNMENT (type
, align
);
663 /* Try to find an available, already-allocated temporary of the proper
664 mode which meets the size and alignment requirements. Choose the
665 smallest one with the closest alignment. */
666 for (p
= temp_slots
; p
; p
= p
->next
)
667 if (p
->align
>= align
&& p
->size
>= size
&& GET_MODE (p
->slot
) == mode
669 && objects_must_conflict_p (p
->type
, type
)
670 && (best_p
== 0 || best_p
->size
> p
->size
671 || (best_p
->size
== p
->size
&& best_p
->align
> p
->align
)))
673 if (p
->align
== align
&& p
->size
== size
)
681 /* Make our best, if any, the one to use. */
684 /* If there are enough aligned bytes left over, make them into a new
685 temp_slot so that the extra bytes don't get wasted. Do this only
686 for BLKmode slots, so that we can be sure of the alignment. */
687 if (GET_MODE (best_p
->slot
) == BLKmode
)
689 int alignment
= best_p
->align
/ BITS_PER_UNIT
;
690 HOST_WIDE_INT rounded_size
= CEIL_ROUND (size
, alignment
);
692 if (best_p
->size
- rounded_size
>= alignment
)
694 p
= (struct temp_slot
*) ggc_alloc (sizeof (struct temp_slot
));
695 p
->in_use
= p
->addr_taken
= 0;
696 p
->size
= best_p
->size
- rounded_size
;
697 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
698 p
->full_size
= best_p
->full_size
- rounded_size
;
699 p
->slot
= gen_rtx_MEM (BLKmode
,
700 plus_constant (XEXP (best_p
->slot
, 0),
702 p
->align
= best_p
->align
;
705 p
->type
= best_p
->type
;
706 p
->next
= temp_slots
;
709 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, p
->slot
,
712 best_p
->size
= rounded_size
;
713 best_p
->full_size
= rounded_size
;
720 /* If we still didn't find one, make a new temporary. */
723 HOST_WIDE_INT frame_offset_old
= frame_offset
;
725 p
= (struct temp_slot
*) ggc_alloc (sizeof (struct temp_slot
));
727 /* We are passing an explicit alignment request to assign_stack_local.
728 One side effect of that is assign_stack_local will not round SIZE
729 to ensure the frame offset remains suitably aligned.
731 So for requests which depended on the rounding of SIZE, we go ahead
732 and round it now. We also make sure ALIGNMENT is at least
733 BIGGEST_ALIGNMENT. */
734 if (mode
== BLKmode
&& align
< BIGGEST_ALIGNMENT
)
736 p
->slot
= assign_stack_local (mode
,
738 ? CEIL_ROUND (size
, (int) align
/ BITS_PER_UNIT
)
744 /* The following slot size computation is necessary because we don't
745 know the actual size of the temporary slot until assign_stack_local
746 has performed all the frame alignment and size rounding for the
747 requested temporary. Note that extra space added for alignment
748 can be either above or below this stack slot depending on which
749 way the frame grows. We include the extra space if and only if it
750 is above this slot. */
751 #ifdef FRAME_GROWS_DOWNWARD
752 p
->size
= frame_offset_old
- frame_offset
;
757 /* Now define the fields used by combine_temp_slots. */
758 #ifdef FRAME_GROWS_DOWNWARD
759 p
->base_offset
= frame_offset
;
760 p
->full_size
= frame_offset_old
- frame_offset
;
762 p
->base_offset
= frame_offset_old
;
763 p
->full_size
= frame_offset
- frame_offset_old
;
766 p
->next
= temp_slots
;
772 p
->rtl_expr
= seq_rtl_expr
;
777 p
->level
= target_temp_slot_level
;
782 p
->level
= var_temp_slot_level
;
787 p
->level
= temp_slot_level
;
792 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
793 slot
= gen_rtx_MEM (mode
, XEXP (p
->slot
, 0));
794 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, slot
, stack_slot_list
);
796 /* If we know the alias set for the memory that will be used, use
797 it. If there's no TYPE, then we don't know anything about the
798 alias set for the memory. */
799 set_mem_alias_set (slot
, type
? get_alias_set (type
) : 0);
800 set_mem_align (slot
, align
);
802 /* If a type is specified, set the relevant flags. */
805 RTX_UNCHANGING_P (slot
) = (lang_hooks
.honor_readonly
806 && TYPE_READONLY (type
));
807 MEM_VOLATILE_P (slot
) = TYPE_VOLATILE (type
);
808 MEM_SET_IN_STRUCT_P (slot
, AGGREGATE_TYPE_P (type
));
814 /* Allocate a temporary stack slot and record it for possible later
815 reuse. First three arguments are same as in preceding function. */
818 assign_stack_temp (mode
, size
, keep
)
819 enum machine_mode mode
;
823 return assign_stack_temp_for_type (mode
, size
, keep
, NULL_TREE
);
826 /* Assign a temporary.
827 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
828 and so that should be used in error messages. In either case, we
829 allocate of the given type.
830 KEEP is as for assign_stack_temp.
831 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
832 it is 0 if a register is OK.
833 DONT_PROMOTE is 1 if we should not promote values in register
837 assign_temp (type_or_decl
, keep
, memory_required
, dont_promote
)
841 int dont_promote ATTRIBUTE_UNUSED
;
844 enum machine_mode mode
;
845 #ifndef PROMOTE_FOR_CALL_ONLY
849 if (DECL_P (type_or_decl
))
850 decl
= type_or_decl
, type
= TREE_TYPE (decl
);
852 decl
= NULL
, type
= type_or_decl
;
854 mode
= TYPE_MODE (type
);
855 #ifndef PROMOTE_FOR_CALL_ONLY
856 unsignedp
= TREE_UNSIGNED (type
);
859 if (mode
== BLKmode
|| memory_required
)
861 HOST_WIDE_INT size
= int_size_in_bytes (type
);
864 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
865 problems with allocating the stack space. */
869 /* Unfortunately, we don't yet know how to allocate variable-sized
870 temporaries. However, sometimes we have a fixed upper limit on
871 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
872 instead. This is the case for Chill variable-sized strings. */
873 if (size
== -1 && TREE_CODE (type
) == ARRAY_TYPE
874 && TYPE_ARRAY_MAX_SIZE (type
) != NULL_TREE
875 && host_integerp (TYPE_ARRAY_MAX_SIZE (type
), 1))
876 size
= tree_low_cst (TYPE_ARRAY_MAX_SIZE (type
), 1);
878 /* The size of the temporary may be too large to fit into an integer. */
879 /* ??? Not sure this should happen except for user silliness, so limit
880 this to things that aren't compiler-generated temporaries. The
881 rest of the time we'll abort in assign_stack_temp_for_type. */
882 if (decl
&& size
== -1
883 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
)
885 error_with_decl (decl
, "size of variable `%s' is too large");
889 tmp
= assign_stack_temp_for_type (mode
, size
, keep
, type
);
893 #ifndef PROMOTE_FOR_CALL_ONLY
895 mode
= promote_mode (type
, mode
, &unsignedp
, 0);
898 return gen_reg_rtx (mode
);
901 /* Combine temporary stack slots which are adjacent on the stack.
903 This allows for better use of already allocated stack space. This is only
904 done for BLKmode slots because we can be sure that we won't have alignment
905 problems in this case. */
908 combine_temp_slots ()
910 struct temp_slot
*p
, *q
;
911 struct temp_slot
*prev_p
, *prev_q
;
914 /* We can't combine slots, because the information about which slot
915 is in which alias set will be lost. */
916 if (flag_strict_aliasing
)
919 /* If there are a lot of temp slots, don't do anything unless
920 high levels of optimization. */
921 if (! flag_expensive_optimizations
)
922 for (p
= temp_slots
, num_slots
= 0; p
; p
= p
->next
, num_slots
++)
923 if (num_slots
> 100 || (num_slots
> 10 && optimize
== 0))
926 for (p
= temp_slots
, prev_p
= 0; p
; p
= prev_p
? prev_p
->next
: temp_slots
)
930 if (! p
->in_use
&& GET_MODE (p
->slot
) == BLKmode
)
931 for (q
= p
->next
, prev_q
= p
; q
; q
= prev_q
->next
)
934 if (! q
->in_use
&& GET_MODE (q
->slot
) == BLKmode
)
936 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
938 /* Q comes after P; combine Q into P. */
940 p
->full_size
+= q
->full_size
;
943 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
945 /* P comes after Q; combine P into Q. */
947 q
->full_size
+= p
->full_size
;
952 /* Either delete Q or advance past it. */
954 prev_q
->next
= q
->next
;
958 /* Either delete P or advance past it. */
962 prev_p
->next
= p
->next
;
964 temp_slots
= p
->next
;
971 /* Find the temp slot corresponding to the object at address X. */
973 static struct temp_slot
*
974 find_temp_slot_from_address (x
)
980 for (p
= temp_slots
; p
; p
= p
->next
)
985 else if (XEXP (p
->slot
, 0) == x
987 || (GET_CODE (x
) == PLUS
988 && XEXP (x
, 0) == virtual_stack_vars_rtx
989 && GET_CODE (XEXP (x
, 1)) == CONST_INT
990 && INTVAL (XEXP (x
, 1)) >= p
->base_offset
991 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
))
994 else if (p
->address
!= 0 && GET_CODE (p
->address
) == EXPR_LIST
)
995 for (next
= p
->address
; next
; next
= XEXP (next
, 1))
996 if (XEXP (next
, 0) == x
)
1000 /* If we have a sum involving a register, see if it points to a temp
1002 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == REG
1003 && (p
= find_temp_slot_from_address (XEXP (x
, 0))) != 0)
1005 else if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == REG
1006 && (p
= find_temp_slot_from_address (XEXP (x
, 1))) != 0)
1012 /* Indicate that NEW is an alternate way of referring to the temp slot
1013 that previously was known by OLD. */
1016 update_temp_slot_address (old
, new)
1019 struct temp_slot
*p
;
1021 if (rtx_equal_p (old
, new))
1024 p
= find_temp_slot_from_address (old
);
1026 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1027 is a register, see if one operand of the PLUS is a temporary
1028 location. If so, NEW points into it. Otherwise, if both OLD and
1029 NEW are a PLUS and if there is a register in common between them.
1030 If so, try a recursive call on those values. */
1033 if (GET_CODE (old
) != PLUS
)
1036 if (GET_CODE (new) == REG
)
1038 update_temp_slot_address (XEXP (old
, 0), new);
1039 update_temp_slot_address (XEXP (old
, 1), new);
1042 else if (GET_CODE (new) != PLUS
)
1045 if (rtx_equal_p (XEXP (old
, 0), XEXP (new, 0)))
1046 update_temp_slot_address (XEXP (old
, 1), XEXP (new, 1));
1047 else if (rtx_equal_p (XEXP (old
, 1), XEXP (new, 0)))
1048 update_temp_slot_address (XEXP (old
, 0), XEXP (new, 1));
1049 else if (rtx_equal_p (XEXP (old
, 0), XEXP (new, 1)))
1050 update_temp_slot_address (XEXP (old
, 1), XEXP (new, 0));
1051 else if (rtx_equal_p (XEXP (old
, 1), XEXP (new, 1)))
1052 update_temp_slot_address (XEXP (old
, 0), XEXP (new, 0));
1057 /* Otherwise add an alias for the temp's address. */
1058 else if (p
->address
== 0)
1062 if (GET_CODE (p
->address
) != EXPR_LIST
)
1063 p
->address
= gen_rtx_EXPR_LIST (VOIDmode
, p
->address
, NULL_RTX
);
1065 p
->address
= gen_rtx_EXPR_LIST (VOIDmode
, new, p
->address
);
1069 /* If X could be a reference to a temporary slot, mark the fact that its
1070 address was taken. */
1073 mark_temp_addr_taken (x
)
1076 struct temp_slot
*p
;
1081 /* If X is not in memory or is at a constant address, it cannot be in
1082 a temporary slot. */
1083 if (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1086 p
= find_temp_slot_from_address (XEXP (x
, 0));
1091 /* If X could be a reference to a temporary slot, mark that slot as
1092 belonging to the to one level higher than the current level. If X
1093 matched one of our slots, just mark that one. Otherwise, we can't
1094 easily predict which it is, so upgrade all of them. Kept slots
1095 need not be touched.
1097 This is called when an ({...}) construct occurs and a statement
1098 returns a value in memory. */
1101 preserve_temp_slots (x
)
1104 struct temp_slot
*p
= 0;
1106 /* If there is no result, we still might have some objects whose address
1107 were taken, so we need to make sure they stay around. */
1110 for (p
= temp_slots
; p
; p
= p
->next
)
1111 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1117 /* If X is a register that is being used as a pointer, see if we have
1118 a temporary slot we know it points to. To be consistent with
1119 the code below, we really should preserve all non-kept slots
1120 if we can't find a match, but that seems to be much too costly. */
1121 if (GET_CODE (x
) == REG
&& REG_POINTER (x
))
1122 p
= find_temp_slot_from_address (x
);
1124 /* If X is not in memory or is at a constant address, it cannot be in
1125 a temporary slot, but it can contain something whose address was
1127 if (p
== 0 && (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0))))
1129 for (p
= temp_slots
; p
; p
= p
->next
)
1130 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1136 /* First see if we can find a match. */
1138 p
= find_temp_slot_from_address (XEXP (x
, 0));
1142 /* Move everything at our level whose address was taken to our new
1143 level in case we used its address. */
1144 struct temp_slot
*q
;
1146 if (p
->level
== temp_slot_level
)
1148 for (q
= temp_slots
; q
; q
= q
->next
)
1149 if (q
!= p
&& q
->addr_taken
&& q
->level
== p
->level
)
1158 /* Otherwise, preserve all non-kept slots at this level. */
1159 for (p
= temp_slots
; p
; p
= p
->next
)
1160 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
)
1164 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1165 with that RTL_EXPR, promote it into a temporary slot at the present
1166 level so it will not be freed when we free slots made in the
1170 preserve_rtl_expr_result (x
)
1173 struct temp_slot
*p
;
1175 /* If X is not in memory or is at a constant address, it cannot be in
1176 a temporary slot. */
1177 if (x
== 0 || GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1180 /* If we can find a match, move it to our level unless it is already at
1182 p
= find_temp_slot_from_address (XEXP (x
, 0));
1185 p
->level
= MIN (p
->level
, temp_slot_level
);
1192 /* Free all temporaries used so far. This is normally called at the end
1193 of generating code for a statement. Don't free any temporaries
1194 currently in use for an RTL_EXPR that hasn't yet been emitted.
1195 We could eventually do better than this since it can be reused while
1196 generating the same RTL_EXPR, but this is complex and probably not
1202 struct temp_slot
*p
;
1204 for (p
= temp_slots
; p
; p
= p
->next
)
1205 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
1206 && p
->rtl_expr
== 0)
1209 combine_temp_slots ();
1212 /* Free all temporary slots used in T, an RTL_EXPR node. */
1215 free_temps_for_rtl_expr (t
)
1218 struct temp_slot
*p
;
1220 for (p
= temp_slots
; p
; p
= p
->next
)
1221 if (p
->rtl_expr
== t
)
1223 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1224 needs to be preserved. This can happen if a temporary in
1225 the RTL_EXPR was addressed; preserve_temp_slots will move
1226 the temporary into a higher level. */
1227 if (temp_slot_level
<= p
->level
)
1230 p
->rtl_expr
= NULL_TREE
;
1233 combine_temp_slots ();
1236 /* Mark all temporaries ever allocated in this function as not suitable
1237 for reuse until the current level is exited. */
1240 mark_all_temps_used ()
1242 struct temp_slot
*p
;
1244 for (p
= temp_slots
; p
; p
= p
->next
)
1246 p
->in_use
= p
->keep
= 1;
1247 p
->level
= MIN (p
->level
, temp_slot_level
);
1251 /* Push deeper into the nesting level for stack temporaries. */
1259 /* Pop a temporary nesting level. All slots in use in the current level
1265 struct temp_slot
*p
;
1267 for (p
= temp_slots
; p
; p
= p
->next
)
1268 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->rtl_expr
== 0)
1271 combine_temp_slots ();
1276 /* Initialize temporary slots. */
1281 /* We have not allocated any temporaries yet. */
1283 temp_slot_level
= 0;
1284 var_temp_slot_level
= 0;
1285 target_temp_slot_level
= 0;
1288 /* Retroactively move an auto variable from a register to a stack slot.
1289 This is done when an address-reference to the variable is seen. */
1292 put_var_into_stack (decl
)
1296 enum machine_mode promoted_mode
, decl_mode
;
1297 struct function
*function
= 0;
1299 int can_use_addressof
;
1300 int volatilep
= TREE_CODE (decl
) != SAVE_EXPR
&& TREE_THIS_VOLATILE (decl
);
1301 int usedp
= (TREE_USED (decl
)
1302 || (TREE_CODE (decl
) != SAVE_EXPR
&& DECL_INITIAL (decl
) != 0));
1304 context
= decl_function_context (decl
);
1306 /* Get the current rtl used for this object and its original mode. */
1307 reg
= (TREE_CODE (decl
) == SAVE_EXPR
1308 ? SAVE_EXPR_RTL (decl
)
1309 : DECL_RTL_IF_SET (decl
));
1311 /* No need to do anything if decl has no rtx yet
1312 since in that case caller is setting TREE_ADDRESSABLE
1313 and a stack slot will be assigned when the rtl is made. */
1317 /* Get the declared mode for this object. */
1318 decl_mode
= (TREE_CODE (decl
) == SAVE_EXPR
? TYPE_MODE (TREE_TYPE (decl
))
1319 : DECL_MODE (decl
));
1320 /* Get the mode it's actually stored in. */
1321 promoted_mode
= GET_MODE (reg
);
1323 /* If this variable comes from an outer function, find that
1324 function's saved context. Don't use find_function_data here,
1325 because it might not be in any active function.
1326 FIXME: Is that really supposed to happen?
1327 It does in ObjC at least. */
1328 if (context
!= current_function_decl
&& context
!= inline_function_decl
)
1329 for (function
= outer_function_chain
; function
; function
= function
->outer
)
1330 if (function
->decl
== context
)
1333 /* If this is a variable-size object with a pseudo to address it,
1334 put that pseudo into the stack, if the var is nonlocal. */
1335 if (TREE_CODE (decl
) != SAVE_EXPR
&& DECL_NONLOCAL (decl
)
1336 && GET_CODE (reg
) == MEM
1337 && GET_CODE (XEXP (reg
, 0)) == REG
1338 && REGNO (XEXP (reg
, 0)) > LAST_VIRTUAL_REGISTER
)
1340 reg
= XEXP (reg
, 0);
1341 decl_mode
= promoted_mode
= GET_MODE (reg
);
1347 /* FIXME make it work for promoted modes too */
1348 && decl_mode
== promoted_mode
1349 #ifdef NON_SAVING_SETJMP
1350 && ! (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
1354 /* If we can't use ADDRESSOF, make sure we see through one we already
1356 if (! can_use_addressof
&& GET_CODE (reg
) == MEM
1357 && GET_CODE (XEXP (reg
, 0)) == ADDRESSOF
)
1358 reg
= XEXP (XEXP (reg
, 0), 0);
1360 /* Now we should have a value that resides in one or more pseudo regs. */
1362 if (GET_CODE (reg
) == REG
)
1364 /* If this variable lives in the current function and we don't need
1365 to put things in the stack for the sake of setjmp, try to keep it
1366 in a register until we know we actually need the address. */
1367 if (can_use_addressof
)
1368 gen_mem_addressof (reg
, decl
);
1370 put_reg_into_stack (function
, reg
, TREE_TYPE (decl
), promoted_mode
,
1371 decl_mode
, volatilep
, 0, usedp
, 0);
1373 else if (GET_CODE (reg
) == CONCAT
)
1375 /* A CONCAT contains two pseudos; put them both in the stack.
1376 We do it so they end up consecutive.
1377 We fixup references to the parts only after we fixup references
1378 to the whole CONCAT, lest we do double fixups for the latter
1380 enum machine_mode part_mode
= GET_MODE (XEXP (reg
, 0));
1381 tree part_type
= (*lang_hooks
.types
.type_for_mode
) (part_mode
, 0);
1382 rtx lopart
= XEXP (reg
, 0);
1383 rtx hipart
= XEXP (reg
, 1);
1384 #ifdef FRAME_GROWS_DOWNWARD
1385 /* Since part 0 should have a lower address, do it second. */
1386 put_reg_into_stack (function
, hipart
, part_type
, part_mode
,
1387 part_mode
, volatilep
, 0, 0, 0);
1388 put_reg_into_stack (function
, lopart
, part_type
, part_mode
,
1389 part_mode
, volatilep
, 0, 0, 0);
1391 put_reg_into_stack (function
, lopart
, part_type
, part_mode
,
1392 part_mode
, volatilep
, 0, 0, 0);
1393 put_reg_into_stack (function
, hipart
, part_type
, part_mode
,
1394 part_mode
, volatilep
, 0, 0, 0);
1397 /* Change the CONCAT into a combined MEM for both parts. */
1398 PUT_CODE (reg
, MEM
);
1399 MEM_ATTRS (reg
) = 0;
1401 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1402 already computed alias sets. Here we want to re-generate. */
1404 SET_DECL_RTL (decl
, NULL
);
1405 set_mem_attributes (reg
, decl
, 1);
1407 SET_DECL_RTL (decl
, reg
);
1409 /* The two parts are in memory order already.
1410 Use the lower parts address as ours. */
1411 XEXP (reg
, 0) = XEXP (XEXP (reg
, 0), 0);
1412 /* Prevent sharing of rtl that might lose. */
1413 if (GET_CODE (XEXP (reg
, 0)) == PLUS
)
1414 XEXP (reg
, 0) = copy_rtx (XEXP (reg
, 0));
1417 schedule_fixup_var_refs (function
, reg
, TREE_TYPE (decl
),
1419 schedule_fixup_var_refs (function
, lopart
, part_type
, part_mode
, 0);
1420 schedule_fixup_var_refs (function
, hipart
, part_type
, part_mode
, 0);
1427 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1428 into the stack frame of FUNCTION (0 means the current function).
1429 DECL_MODE is the machine mode of the user-level data type.
1430 PROMOTED_MODE is the machine mode of the register.
1431 VOLATILE_P is nonzero if this is for a "volatile" decl.
1432 USED_P is nonzero if this reg might have already been used in an insn. */
1435 put_reg_into_stack (function
, reg
, type
, promoted_mode
, decl_mode
, volatile_p
,
1436 original_regno
, used_p
, ht
)
1437 struct function
*function
;
1440 enum machine_mode promoted_mode
, decl_mode
;
1442 unsigned int original_regno
;
1446 struct function
*func
= function
? function
: cfun
;
1448 unsigned int regno
= original_regno
;
1451 regno
= REGNO (reg
);
1453 if (regno
< func
->x_max_parm_reg
)
1454 new = func
->x_parm_reg_stack_loc
[regno
];
1457 new = assign_stack_local_1 (decl_mode
, GET_MODE_SIZE (decl_mode
), 0, func
);
1459 PUT_CODE (reg
, MEM
);
1460 PUT_MODE (reg
, decl_mode
);
1461 XEXP (reg
, 0) = XEXP (new, 0);
1462 MEM_ATTRS (reg
) = 0;
1463 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1464 MEM_VOLATILE_P (reg
) = volatile_p
;
1466 /* If this is a memory ref that contains aggregate components,
1467 mark it as such for cse and loop optimize. If we are reusing a
1468 previously generated stack slot, then we need to copy the bit in
1469 case it was set for other reasons. For instance, it is set for
1470 __builtin_va_alist. */
1473 MEM_SET_IN_STRUCT_P (reg
,
1474 AGGREGATE_TYPE_P (type
) || MEM_IN_STRUCT_P (new));
1475 set_mem_alias_set (reg
, get_alias_set (type
));
1479 schedule_fixup_var_refs (function
, reg
, type
, promoted_mode
, ht
);
1482 /* Make sure that all refs to the variable, previously made
1483 when it was a register, are fixed up to be valid again.
1484 See function above for meaning of arguments. */
1487 schedule_fixup_var_refs (function
, reg
, type
, promoted_mode
, ht
)
1488 struct function
*function
;
1491 enum machine_mode promoted_mode
;
1494 int unsigned_p
= type
? TREE_UNSIGNED (type
) : 0;
1498 struct var_refs_queue
*temp
;
1501 = (struct var_refs_queue
*) ggc_alloc (sizeof (struct var_refs_queue
));
1502 temp
->modified
= reg
;
1503 temp
->promoted_mode
= promoted_mode
;
1504 temp
->unsignedp
= unsigned_p
;
1505 temp
->next
= function
->fixup_var_refs_queue
;
1506 function
->fixup_var_refs_queue
= temp
;
1509 /* Variable is local; fix it up now. */
1510 fixup_var_refs (reg
, promoted_mode
, unsigned_p
, reg
, ht
);
1514 fixup_var_refs (var
, promoted_mode
, unsignedp
, may_share
, ht
)
1516 enum machine_mode promoted_mode
;
1522 rtx first_insn
= get_insns ();
1523 struct sequence_stack
*stack
= seq_stack
;
1524 tree rtl_exps
= rtl_expr_chain
;
1526 /* If there's a hash table, it must record all uses of VAR. */
1531 fixup_var_refs_insns_with_hash (ht
, var
, promoted_mode
, unsignedp
,
1536 fixup_var_refs_insns (first_insn
, var
, promoted_mode
, unsignedp
,
1537 stack
== 0, may_share
);
1539 /* Scan all pending sequences too. */
1540 for (; stack
; stack
= stack
->next
)
1542 push_to_full_sequence (stack
->first
, stack
->last
);
1543 fixup_var_refs_insns (stack
->first
, var
, promoted_mode
, unsignedp
,
1544 stack
->next
!= 0, may_share
);
1545 /* Update remembered end of sequence
1546 in case we added an insn at the end. */
1547 stack
->last
= get_last_insn ();
1551 /* Scan all waiting RTL_EXPRs too. */
1552 for (pending
= rtl_exps
; pending
; pending
= TREE_CHAIN (pending
))
1554 rtx seq
= RTL_EXPR_SEQUENCE (TREE_VALUE (pending
));
1555 if (seq
!= const0_rtx
&& seq
!= 0)
1557 push_to_sequence (seq
);
1558 fixup_var_refs_insns (seq
, var
, promoted_mode
, unsignedp
, 0,
1565 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1566 some part of an insn. Return a struct fixup_replacement whose OLD
1567 value is equal to X. Allocate a new structure if no such entry exists. */
1569 static struct fixup_replacement
*
1570 find_fixup_replacement (replacements
, x
)
1571 struct fixup_replacement
**replacements
;
1574 struct fixup_replacement
*p
;
1576 /* See if we have already replaced this. */
1577 for (p
= *replacements
; p
!= 0 && ! rtx_equal_p (p
->old
, x
); p
= p
->next
)
1582 p
= (struct fixup_replacement
*) xmalloc (sizeof (struct fixup_replacement
));
1585 p
->next
= *replacements
;
1592 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1593 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1594 for the current function. MAY_SHARE is either a MEM that is not
1595 to be unshared or a list of them. */
1598 fixup_var_refs_insns (insn
, var
, promoted_mode
, unsignedp
, toplevel
, may_share
)
1601 enum machine_mode promoted_mode
;
1608 /* fixup_var_refs_insn might modify insn, so save its next
1610 rtx next
= NEXT_INSN (insn
);
1612 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1613 the three sequences they (potentially) contain, and process
1614 them recursively. The CALL_INSN itself is not interesting. */
1616 if (GET_CODE (insn
) == CALL_INSN
1617 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
1621 /* Look at the Normal call, sibling call and tail recursion
1622 sequences attached to the CALL_PLACEHOLDER. */
1623 for (i
= 0; i
< 3; i
++)
1625 rtx seq
= XEXP (PATTERN (insn
), i
);
1628 push_to_sequence (seq
);
1629 fixup_var_refs_insns (seq
, var
, promoted_mode
, unsignedp
, 0,
1631 XEXP (PATTERN (insn
), i
) = get_insns ();
1637 else if (INSN_P (insn
))
1638 fixup_var_refs_insn (insn
, var
, promoted_mode
, unsignedp
, toplevel
,
1645 /* Look up the insns which reference VAR in HT and fix them up. Other
1646 arguments are the same as fixup_var_refs_insns.
1648 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1649 because the hash table will point straight to the interesting insn
1650 (inside the CALL_PLACEHOLDER). */
1653 fixup_var_refs_insns_with_hash (ht
, var
, promoted_mode
, unsignedp
, may_share
)
1656 enum machine_mode promoted_mode
;
1660 struct insns_for_mem_entry tmp
;
1661 struct insns_for_mem_entry
*ime
;
1665 ime
= (struct insns_for_mem_entry
*) htab_find (ht
, &tmp
);
1666 for (insn_list
= ime
->insns
; insn_list
!= 0; insn_list
= XEXP (insn_list
, 1))
1667 if (INSN_P (XEXP (insn_list
, 0)))
1668 fixup_var_refs_insn (XEXP (insn_list
, 0), var
, promoted_mode
,
1669 unsignedp
, 1, may_share
);
1673 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1674 the insn under examination, VAR is the variable to fix up
1675 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1676 TOPLEVEL is nonzero if this is the main insn chain for this
1680 fixup_var_refs_insn (insn
, var
, promoted_mode
, unsignedp
, toplevel
, no_share
)
1683 enum machine_mode promoted_mode
;
1689 rtx set
, prev
, prev_set
;
1692 /* Remember the notes in case we delete the insn. */
1693 note
= REG_NOTES (insn
);
1695 /* If this is a CLOBBER of VAR, delete it.
1697 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1698 and REG_RETVAL notes too. */
1699 if (GET_CODE (PATTERN (insn
)) == CLOBBER
1700 && (XEXP (PATTERN (insn
), 0) == var
1701 || (GET_CODE (XEXP (PATTERN (insn
), 0)) == CONCAT
1702 && (XEXP (XEXP (PATTERN (insn
), 0), 0) == var
1703 || XEXP (XEXP (PATTERN (insn
), 0), 1) == var
))))
1705 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)) != 0)
1706 /* The REG_LIBCALL note will go away since we are going to
1707 turn INSN into a NOTE, so just delete the
1708 corresponding REG_RETVAL note. */
1709 remove_note (XEXP (note
, 0),
1710 find_reg_note (XEXP (note
, 0), REG_RETVAL
,
1716 /* The insn to load VAR from a home in the arglist
1717 is now a no-op. When we see it, just delete it.
1718 Similarly if this is storing VAR from a register from which
1719 it was loaded in the previous insn. This will occur
1720 when an ADDRESSOF was made for an arglist slot. */
1722 && (set
= single_set (insn
)) != 0
1723 && SET_DEST (set
) == var
1724 /* If this represents the result of an insn group,
1725 don't delete the insn. */
1726 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
) == 0
1727 && (rtx_equal_p (SET_SRC (set
), var
)
1728 || (GET_CODE (SET_SRC (set
)) == REG
1729 && (prev
= prev_nonnote_insn (insn
)) != 0
1730 && (prev_set
= single_set (prev
)) != 0
1731 && SET_DEST (prev_set
) == SET_SRC (set
)
1732 && rtx_equal_p (SET_SRC (prev_set
), var
))))
1738 struct fixup_replacement
*replacements
= 0;
1739 rtx next_insn
= NEXT_INSN (insn
);
1741 if (SMALL_REGISTER_CLASSES
)
1743 /* If the insn that copies the results of a CALL_INSN
1744 into a pseudo now references VAR, we have to use an
1745 intermediate pseudo since we want the life of the
1746 return value register to be only a single insn.
1748 If we don't use an intermediate pseudo, such things as
1749 address computations to make the address of VAR valid
1750 if it is not can be placed between the CALL_INSN and INSN.
1752 To make sure this doesn't happen, we record the destination
1753 of the CALL_INSN and see if the next insn uses both that
1756 if (call_dest
!= 0 && GET_CODE (insn
) == INSN
1757 && reg_mentioned_p (var
, PATTERN (insn
))
1758 && reg_mentioned_p (call_dest
, PATTERN (insn
)))
1760 rtx temp
= gen_reg_rtx (GET_MODE (call_dest
));
1762 emit_insn_before (gen_move_insn (temp
, call_dest
), insn
);
1764 PATTERN (insn
) = replace_rtx (PATTERN (insn
),
1768 if (GET_CODE (insn
) == CALL_INSN
1769 && GET_CODE (PATTERN (insn
)) == SET
)
1770 call_dest
= SET_DEST (PATTERN (insn
));
1771 else if (GET_CODE (insn
) == CALL_INSN
1772 && GET_CODE (PATTERN (insn
)) == PARALLEL
1773 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1774 call_dest
= SET_DEST (XVECEXP (PATTERN (insn
), 0, 0));
1779 /* See if we have to do anything to INSN now that VAR is in
1780 memory. If it needs to be loaded into a pseudo, use a single
1781 pseudo for the entire insn in case there is a MATCH_DUP
1782 between two operands. We pass a pointer to the head of
1783 a list of struct fixup_replacements. If fixup_var_refs_1
1784 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1785 it will record them in this list.
1787 If it allocated a pseudo for any replacement, we copy into
1790 fixup_var_refs_1 (var
, promoted_mode
, &PATTERN (insn
), insn
,
1791 &replacements
, no_share
);
1793 /* If this is last_parm_insn, and any instructions were output
1794 after it to fix it up, then we must set last_parm_insn to
1795 the last such instruction emitted. */
1796 if (insn
== last_parm_insn
)
1797 last_parm_insn
= PREV_INSN (next_insn
);
1799 while (replacements
)
1801 struct fixup_replacement
*next
;
1803 if (GET_CODE (replacements
->new) == REG
)
1808 /* OLD might be a (subreg (mem)). */
1809 if (GET_CODE (replacements
->old
) == SUBREG
)
1811 = fixup_memory_subreg (replacements
->old
, insn
,
1815 = fixup_stack_1 (replacements
->old
, insn
);
1817 insert_before
= insn
;
1819 /* If we are changing the mode, do a conversion.
1820 This might be wasteful, but combine.c will
1821 eliminate much of the waste. */
1823 if (GET_MODE (replacements
->new)
1824 != GET_MODE (replacements
->old
))
1827 convert_move (replacements
->new,
1828 replacements
->old
, unsignedp
);
1833 seq
= gen_move_insn (replacements
->new,
1836 emit_insn_before (seq
, insert_before
);
1839 next
= replacements
->next
;
1840 free (replacements
);
1841 replacements
= next
;
1845 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1846 But don't touch other insns referred to by reg-notes;
1847 we will get them elsewhere. */
1850 if (GET_CODE (note
) != INSN_LIST
)
1852 = walk_fixup_memory_subreg (XEXP (note
, 0), insn
,
1854 note
= XEXP (note
, 1);
1858 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1859 See if the rtx expression at *LOC in INSN needs to be changed.
1861 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1862 contain a list of original rtx's and replacements. If we find that we need
1863 to modify this insn by replacing a memory reference with a pseudo or by
1864 making a new MEM to implement a SUBREG, we consult that list to see if
1865 we have already chosen a replacement. If none has already been allocated,
1866 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1867 or the SUBREG, as appropriate, to the pseudo. */
1870 fixup_var_refs_1 (var
, promoted_mode
, loc
, insn
, replacements
, no_share
)
1872 enum machine_mode promoted_mode
;
1875 struct fixup_replacement
**replacements
;
1880 RTX_CODE code
= GET_CODE (x
);
1883 struct fixup_replacement
*replacement
;
1888 if (XEXP (x
, 0) == var
)
1890 /* Prevent sharing of rtl that might lose. */
1891 rtx sub
= copy_rtx (XEXP (var
, 0));
1893 if (! validate_change (insn
, loc
, sub
, 0))
1895 rtx y
= gen_reg_rtx (GET_MODE (sub
));
1898 /* We should be able to replace with a register or all is lost.
1899 Note that we can't use validate_change to verify this, since
1900 we're not caring for replacing all dups simultaneously. */
1901 if (! validate_replace_rtx (*loc
, y
, insn
))
1904 /* Careful! First try to recognize a direct move of the
1905 value, mimicking how things are done in gen_reload wrt
1906 PLUS. Consider what happens when insn is a conditional
1907 move instruction and addsi3 clobbers flags. */
1910 new_insn
= emit_insn (gen_rtx_SET (VOIDmode
, y
, sub
));
1914 if (recog_memoized (new_insn
) < 0)
1916 /* That failed. Fall back on force_operand and hope. */
1919 sub
= force_operand (sub
, y
);
1921 emit_insn (gen_move_insn (y
, sub
));
1927 /* Don't separate setter from user. */
1928 if (PREV_INSN (insn
) && sets_cc0_p (PREV_INSN (insn
)))
1929 insn
= PREV_INSN (insn
);
1932 emit_insn_before (seq
, insn
);
1940 /* If we already have a replacement, use it. Otherwise,
1941 try to fix up this address in case it is invalid. */
1943 replacement
= find_fixup_replacement (replacements
, var
);
1944 if (replacement
->new)
1946 *loc
= replacement
->new;
1950 *loc
= replacement
->new = x
= fixup_stack_1 (x
, insn
);
1952 /* Unless we are forcing memory to register or we changed the mode,
1953 we can leave things the way they are if the insn is valid. */
1955 INSN_CODE (insn
) = -1;
1956 if (! flag_force_mem
&& GET_MODE (x
) == promoted_mode
1957 && recog_memoized (insn
) >= 0)
1960 *loc
= replacement
->new = gen_reg_rtx (promoted_mode
);
1964 /* If X contains VAR, we need to unshare it here so that we update
1965 each occurrence separately. But all identical MEMs in one insn
1966 must be replaced with the same rtx because of the possibility of
1969 if (reg_mentioned_p (var
, x
))
1971 replacement
= find_fixup_replacement (replacements
, x
);
1972 if (replacement
->new == 0)
1973 replacement
->new = copy_most_rtx (x
, no_share
);
1975 *loc
= x
= replacement
->new;
1976 code
= GET_CODE (x
);
1993 /* Note that in some cases those types of expressions are altered
1994 by optimize_bit_field, and do not survive to get here. */
1995 if (XEXP (x
, 0) == var
1996 || (GET_CODE (XEXP (x
, 0)) == SUBREG
1997 && SUBREG_REG (XEXP (x
, 0)) == var
))
1999 /* Get TEM as a valid MEM in the mode presently in the insn.
2001 We don't worry about the possibility of MATCH_DUP here; it
2002 is highly unlikely and would be tricky to handle. */
2005 if (GET_CODE (tem
) == SUBREG
)
2007 if (GET_MODE_BITSIZE (GET_MODE (tem
))
2008 > GET_MODE_BITSIZE (GET_MODE (var
)))
2010 replacement
= find_fixup_replacement (replacements
, var
);
2011 if (replacement
->new == 0)
2012 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2013 SUBREG_REG (tem
) = replacement
->new;
2015 /* The following code works only if we have a MEM, so we
2016 need to handle the subreg here. We directly substitute
2017 it assuming that a subreg must be OK here. We already
2018 scheduled a replacement to copy the mem into the
2024 tem
= fixup_memory_subreg (tem
, insn
, promoted_mode
, 0);
2027 tem
= fixup_stack_1 (tem
, insn
);
2029 /* Unless we want to load from memory, get TEM into the proper mode
2030 for an extract from memory. This can only be done if the
2031 extract is at a constant position and length. */
2033 if (! flag_force_mem
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
2034 && GET_CODE (XEXP (x
, 2)) == CONST_INT
2035 && ! mode_dependent_address_p (XEXP (tem
, 0))
2036 && ! MEM_VOLATILE_P (tem
))
2038 enum machine_mode wanted_mode
= VOIDmode
;
2039 enum machine_mode is_mode
= GET_MODE (tem
);
2040 HOST_WIDE_INT pos
= INTVAL (XEXP (x
, 2));
2042 if (GET_CODE (x
) == ZERO_EXTRACT
)
2044 enum machine_mode new_mode
2045 = mode_for_extraction (EP_extzv
, 1);
2046 if (new_mode
!= MAX_MACHINE_MODE
)
2047 wanted_mode
= new_mode
;
2049 else if (GET_CODE (x
) == SIGN_EXTRACT
)
2051 enum machine_mode new_mode
2052 = mode_for_extraction (EP_extv
, 1);
2053 if (new_mode
!= MAX_MACHINE_MODE
)
2054 wanted_mode
= new_mode
;
2057 /* If we have a narrower mode, we can do something. */
2058 if (wanted_mode
!= VOIDmode
2059 && GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2061 HOST_WIDE_INT offset
= pos
/ BITS_PER_UNIT
;
2062 rtx old_pos
= XEXP (x
, 2);
2065 /* If the bytes and bits are counted differently, we
2066 must adjust the offset. */
2067 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2068 offset
= (GET_MODE_SIZE (is_mode
)
2069 - GET_MODE_SIZE (wanted_mode
) - offset
);
2071 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2073 newmem
= adjust_address_nv (tem
, wanted_mode
, offset
);
2075 /* Make the change and see if the insn remains valid. */
2076 INSN_CODE (insn
) = -1;
2077 XEXP (x
, 0) = newmem
;
2078 XEXP (x
, 2) = GEN_INT (pos
);
2080 if (recog_memoized (insn
) >= 0)
2083 /* Otherwise, restore old position. XEXP (x, 0) will be
2085 XEXP (x
, 2) = old_pos
;
2089 /* If we get here, the bitfield extract insn can't accept a memory
2090 reference. Copy the input into a register. */
2092 tem1
= gen_reg_rtx (GET_MODE (tem
));
2093 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2100 if (SUBREG_REG (x
) == var
)
2102 /* If this is a special SUBREG made because VAR was promoted
2103 from a wider mode, replace it with VAR and call ourself
2104 recursively, this time saying that the object previously
2105 had its current mode (by virtue of the SUBREG). */
2107 if (SUBREG_PROMOTED_VAR_P (x
))
2110 fixup_var_refs_1 (var
, GET_MODE (var
), loc
, insn
, replacements
,
2115 /* If this SUBREG makes VAR wider, it has become a paradoxical
2116 SUBREG with VAR in memory, but these aren't allowed at this
2117 stage of the compilation. So load VAR into a pseudo and take
2118 a SUBREG of that pseudo. */
2119 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (GET_MODE (var
)))
2121 replacement
= find_fixup_replacement (replacements
, var
);
2122 if (replacement
->new == 0)
2123 replacement
->new = gen_reg_rtx (promoted_mode
);
2124 SUBREG_REG (x
) = replacement
->new;
2128 /* See if we have already found a replacement for this SUBREG.
2129 If so, use it. Otherwise, make a MEM and see if the insn
2130 is recognized. If not, or if we should force MEM into a register,
2131 make a pseudo for this SUBREG. */
2132 replacement
= find_fixup_replacement (replacements
, x
);
2133 if (replacement
->new)
2135 *loc
= replacement
->new;
2139 replacement
->new = *loc
= fixup_memory_subreg (x
, insn
,
2142 INSN_CODE (insn
) = -1;
2143 if (! flag_force_mem
&& recog_memoized (insn
) >= 0)
2146 *loc
= replacement
->new = gen_reg_rtx (GET_MODE (x
));
2152 /* First do special simplification of bit-field references. */
2153 if (GET_CODE (SET_DEST (x
)) == SIGN_EXTRACT
2154 || GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2155 optimize_bit_field (x
, insn
, 0);
2156 if (GET_CODE (SET_SRC (x
)) == SIGN_EXTRACT
2157 || GET_CODE (SET_SRC (x
)) == ZERO_EXTRACT
)
2158 optimize_bit_field (x
, insn
, 0);
2160 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2161 into a register and then store it back out. */
2162 if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
2163 && GET_CODE (XEXP (SET_DEST (x
), 0)) == SUBREG
2164 && SUBREG_REG (XEXP (SET_DEST (x
), 0)) == var
2165 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x
), 0)))
2166 > GET_MODE_SIZE (GET_MODE (var
))))
2168 replacement
= find_fixup_replacement (replacements
, var
);
2169 if (replacement
->new == 0)
2170 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2172 SUBREG_REG (XEXP (SET_DEST (x
), 0)) = replacement
->new;
2173 emit_insn_after (gen_move_insn (var
, replacement
->new), insn
);
2176 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2177 insn into a pseudo and store the low part of the pseudo into VAR. */
2178 if (GET_CODE (SET_DEST (x
)) == SUBREG
2179 && SUBREG_REG (SET_DEST (x
)) == var
2180 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x
)))
2181 > GET_MODE_SIZE (GET_MODE (var
))))
2183 SET_DEST (x
) = tem
= gen_reg_rtx (GET_MODE (SET_DEST (x
)));
2184 emit_insn_after (gen_move_insn (var
, gen_lowpart (GET_MODE (var
),
2191 rtx dest
= SET_DEST (x
);
2192 rtx src
= SET_SRC (x
);
2193 rtx outerdest
= dest
;
2195 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
2196 || GET_CODE (dest
) == SIGN_EXTRACT
2197 || GET_CODE (dest
) == ZERO_EXTRACT
)
2198 dest
= XEXP (dest
, 0);
2200 if (GET_CODE (src
) == SUBREG
)
2201 src
= SUBREG_REG (src
);
2203 /* If VAR does not appear at the top level of the SET
2204 just scan the lower levels of the tree. */
2206 if (src
!= var
&& dest
!= var
)
2209 /* We will need to rerecognize this insn. */
2210 INSN_CODE (insn
) = -1;
2212 if (GET_CODE (outerdest
) == ZERO_EXTRACT
&& dest
== var
2213 && mode_for_extraction (EP_insv
, -1) != MAX_MACHINE_MODE
)
2215 /* Since this case will return, ensure we fixup all the
2217 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 1),
2218 insn
, replacements
, no_share
);
2219 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 2),
2220 insn
, replacements
, no_share
);
2221 fixup_var_refs_1 (var
, promoted_mode
, &SET_SRC (x
),
2222 insn
, replacements
, no_share
);
2224 tem
= XEXP (outerdest
, 0);
2226 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2227 that may appear inside a ZERO_EXTRACT.
2228 This was legitimate when the MEM was a REG. */
2229 if (GET_CODE (tem
) == SUBREG
2230 && SUBREG_REG (tem
) == var
)
2231 tem
= fixup_memory_subreg (tem
, insn
, promoted_mode
, 0);
2233 tem
= fixup_stack_1 (tem
, insn
);
2235 if (GET_CODE (XEXP (outerdest
, 1)) == CONST_INT
2236 && GET_CODE (XEXP (outerdest
, 2)) == CONST_INT
2237 && ! mode_dependent_address_p (XEXP (tem
, 0))
2238 && ! MEM_VOLATILE_P (tem
))
2240 enum machine_mode wanted_mode
;
2241 enum machine_mode is_mode
= GET_MODE (tem
);
2242 HOST_WIDE_INT pos
= INTVAL (XEXP (outerdest
, 2));
2244 wanted_mode
= mode_for_extraction (EP_insv
, 0);
2246 /* If we have a narrower mode, we can do something. */
2247 if (GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2249 HOST_WIDE_INT offset
= pos
/ BITS_PER_UNIT
;
2250 rtx old_pos
= XEXP (outerdest
, 2);
2253 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2254 offset
= (GET_MODE_SIZE (is_mode
)
2255 - GET_MODE_SIZE (wanted_mode
) - offset
);
2257 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2259 newmem
= adjust_address_nv (tem
, wanted_mode
, offset
);
2261 /* Make the change and see if the insn remains valid. */
2262 INSN_CODE (insn
) = -1;
2263 XEXP (outerdest
, 0) = newmem
;
2264 XEXP (outerdest
, 2) = GEN_INT (pos
);
2266 if (recog_memoized (insn
) >= 0)
2269 /* Otherwise, restore old position. XEXP (x, 0) will be
2271 XEXP (outerdest
, 2) = old_pos
;
2275 /* If we get here, the bit-field store doesn't allow memory
2276 or isn't located at a constant position. Load the value into
2277 a register, do the store, and put it back into memory. */
2279 tem1
= gen_reg_rtx (GET_MODE (tem
));
2280 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2281 emit_insn_after (gen_move_insn (tem
, tem1
), insn
);
2282 XEXP (outerdest
, 0) = tem1
;
2286 /* STRICT_LOW_PART is a no-op on memory references
2287 and it can cause combinations to be unrecognizable,
2290 if (dest
== var
&& GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2291 SET_DEST (x
) = XEXP (SET_DEST (x
), 0);
2293 /* A valid insn to copy VAR into or out of a register
2294 must be left alone, to avoid an infinite loop here.
2295 If the reference to VAR is by a subreg, fix that up,
2296 since SUBREG is not valid for a memref.
2297 Also fix up the address of the stack slot.
2299 Note that we must not try to recognize the insn until
2300 after we know that we have valid addresses and no
2301 (subreg (mem ...) ...) constructs, since these interfere
2302 with determining the validity of the insn. */
2304 if ((SET_SRC (x
) == var
2305 || (GET_CODE (SET_SRC (x
)) == SUBREG
2306 && SUBREG_REG (SET_SRC (x
)) == var
))
2307 && (GET_CODE (SET_DEST (x
)) == REG
2308 || (GET_CODE (SET_DEST (x
)) == SUBREG
2309 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
))
2310 && GET_MODE (var
) == promoted_mode
2311 && x
== single_set (insn
))
2315 if (GET_CODE (SET_SRC (x
)) == SUBREG
2316 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x
)))
2317 > GET_MODE_SIZE (GET_MODE (var
))))
2319 /* This (subreg VAR) is now a paradoxical subreg. We need
2320 to replace VAR instead of the subreg. */
2321 replacement
= find_fixup_replacement (replacements
, var
);
2322 if (replacement
->new == NULL_RTX
)
2323 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2324 SUBREG_REG (SET_SRC (x
)) = replacement
->new;
2328 replacement
= find_fixup_replacement (replacements
, SET_SRC (x
));
2329 if (replacement
->new)
2330 SET_SRC (x
) = replacement
->new;
2331 else if (GET_CODE (SET_SRC (x
)) == SUBREG
)
2332 SET_SRC (x
) = replacement
->new
2333 = fixup_memory_subreg (SET_SRC (x
), insn
, promoted_mode
,
2336 SET_SRC (x
) = replacement
->new
2337 = fixup_stack_1 (SET_SRC (x
), insn
);
2340 if (recog_memoized (insn
) >= 0)
2343 /* INSN is not valid, but we know that we want to
2344 copy SET_SRC (x) to SET_DEST (x) in some way. So
2345 we generate the move and see whether it requires more
2346 than one insn. If it does, we emit those insns and
2347 delete INSN. Otherwise, we can just replace the pattern
2348 of INSN; we have already verified above that INSN has
2349 no other function that to do X. */
2351 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2352 if (NEXT_INSN (pat
) != NULL_RTX
)
2354 last
= emit_insn_before (pat
, insn
);
2356 /* INSN might have REG_RETVAL or other important notes, so
2357 we need to store the pattern of the last insn in the
2358 sequence into INSN similarly to the normal case. LAST
2359 should not have REG_NOTES, but we allow them if INSN has
2361 if (REG_NOTES (last
) && REG_NOTES (insn
))
2363 if (REG_NOTES (last
))
2364 REG_NOTES (insn
) = REG_NOTES (last
);
2365 PATTERN (insn
) = PATTERN (last
);
2370 PATTERN (insn
) = PATTERN (pat
);
2375 if ((SET_DEST (x
) == var
2376 || (GET_CODE (SET_DEST (x
)) == SUBREG
2377 && SUBREG_REG (SET_DEST (x
)) == var
))
2378 && (GET_CODE (SET_SRC (x
)) == REG
2379 || (GET_CODE (SET_SRC (x
)) == SUBREG
2380 && GET_CODE (SUBREG_REG (SET_SRC (x
))) == REG
))
2381 && GET_MODE (var
) == promoted_mode
2382 && x
== single_set (insn
))
2386 if (GET_CODE (SET_DEST (x
)) == SUBREG
)
2387 SET_DEST (x
) = fixup_memory_subreg (SET_DEST (x
), insn
,
2390 SET_DEST (x
) = fixup_stack_1 (SET_DEST (x
), insn
);
2392 if (recog_memoized (insn
) >= 0)
2395 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2396 if (NEXT_INSN (pat
) != NULL_RTX
)
2398 last
= emit_insn_before (pat
, insn
);
2400 /* INSN might have REG_RETVAL or other important notes, so
2401 we need to store the pattern of the last insn in the
2402 sequence into INSN similarly to the normal case. LAST
2403 should not have REG_NOTES, but we allow them if INSN has
2405 if (REG_NOTES (last
) && REG_NOTES (insn
))
2407 if (REG_NOTES (last
))
2408 REG_NOTES (insn
) = REG_NOTES (last
);
2409 PATTERN (insn
) = PATTERN (last
);
2414 PATTERN (insn
) = PATTERN (pat
);
2419 /* Otherwise, storing into VAR must be handled specially
2420 by storing into a temporary and copying that into VAR
2421 with a new insn after this one. Note that this case
2422 will be used when storing into a promoted scalar since
2423 the insn will now have different modes on the input
2424 and output and hence will be invalid (except for the case
2425 of setting it to a constant, which does not need any
2426 change if it is valid). We generate extra code in that case,
2427 but combine.c will eliminate it. */
2432 rtx fixeddest
= SET_DEST (x
);
2433 enum machine_mode temp_mode
;
2435 /* STRICT_LOW_PART can be discarded, around a MEM. */
2436 if (GET_CODE (fixeddest
) == STRICT_LOW_PART
)
2437 fixeddest
= XEXP (fixeddest
, 0);
2438 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2439 if (GET_CODE (fixeddest
) == SUBREG
)
2441 fixeddest
= fixup_memory_subreg (fixeddest
, insn
,
2443 temp_mode
= GET_MODE (fixeddest
);
2447 fixeddest
= fixup_stack_1 (fixeddest
, insn
);
2448 temp_mode
= promoted_mode
;
2451 temp
= gen_reg_rtx (temp_mode
);
2453 emit_insn_after (gen_move_insn (fixeddest
,
2454 gen_lowpart (GET_MODE (fixeddest
),
2458 SET_DEST (x
) = temp
;
2466 /* Nothing special about this RTX; fix its operands. */
2468 fmt
= GET_RTX_FORMAT (code
);
2469 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2472 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (x
, i
), insn
, replacements
,
2474 else if (fmt
[i
] == 'E')
2477 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2478 fixup_var_refs_1 (var
, promoted_mode
, &XVECEXP (x
, i
, j
),
2479 insn
, replacements
, no_share
);
2484 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2485 The REG was placed on the stack, so X now has the form (SUBREG:m1
2488 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2489 must be emitted to compute NEWADDR, put them before INSN.
2491 UNCRITICAL nonzero means accept paradoxical subregs.
2492 This is used for subregs found inside REG_NOTES. */
2495 fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
)
2498 enum machine_mode promoted_mode
;
2502 rtx mem
= SUBREG_REG (x
);
2503 rtx addr
= XEXP (mem
, 0);
2504 enum machine_mode mode
= GET_MODE (x
);
2507 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2508 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (mem
)) && ! uncritical
)
2511 offset
= SUBREG_BYTE (x
);
2512 if (BYTES_BIG_ENDIAN
)
2513 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2514 the offset so that it points to the right location within the
2516 offset
-= (GET_MODE_SIZE (promoted_mode
) - GET_MODE_SIZE (GET_MODE (mem
)));
2518 if (!flag_force_addr
2519 && memory_address_p (mode
, plus_constant (addr
, offset
)))
2520 /* Shortcut if no insns need be emitted. */
2521 return adjust_address (mem
, mode
, offset
);
2524 result
= adjust_address (mem
, mode
, offset
);
2528 emit_insn_before (seq
, insn
);
2532 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2533 Replace subexpressions of X in place.
2534 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2535 Otherwise return X, with its contents possibly altered.
2537 INSN, PROMOTED_MODE and UNCRITICAL are as for
2538 fixup_memory_subreg. */
2541 walk_fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
)
2544 enum machine_mode promoted_mode
;
2554 code
= GET_CODE (x
);
2556 if (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == MEM
)
2557 return fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
);
2559 /* Nothing special about this RTX; fix its operands. */
2561 fmt
= GET_RTX_FORMAT (code
);
2562 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2565 XEXP (x
, i
) = walk_fixup_memory_subreg (XEXP (x
, i
), insn
,
2566 promoted_mode
, uncritical
);
2567 else if (fmt
[i
] == 'E')
2570 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2572 = walk_fixup_memory_subreg (XVECEXP (x
, i
, j
), insn
,
2573 promoted_mode
, uncritical
);
2579 /* For each memory ref within X, if it refers to a stack slot
2580 with an out of range displacement, put the address in a temp register
2581 (emitting new insns before INSN to load these registers)
2582 and alter the memory ref to use that register.
2583 Replace each such MEM rtx with a copy, to avoid clobberage. */
2586 fixup_stack_1 (x
, insn
)
2591 RTX_CODE code
= GET_CODE (x
);
2596 rtx ad
= XEXP (x
, 0);
2597 /* If we have address of a stack slot but it's not valid
2598 (displacement is too large), compute the sum in a register. */
2599 if (GET_CODE (ad
) == PLUS
2600 && GET_CODE (XEXP (ad
, 0)) == REG
2601 && ((REGNO (XEXP (ad
, 0)) >= FIRST_VIRTUAL_REGISTER
2602 && REGNO (XEXP (ad
, 0)) <= LAST_VIRTUAL_REGISTER
)
2603 || REGNO (XEXP (ad
, 0)) == FRAME_POINTER_REGNUM
2604 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2605 || REGNO (XEXP (ad
, 0)) == HARD_FRAME_POINTER_REGNUM
2607 || REGNO (XEXP (ad
, 0)) == STACK_POINTER_REGNUM
2608 || REGNO (XEXP (ad
, 0)) == ARG_POINTER_REGNUM
2609 || XEXP (ad
, 0) == current_function_internal_arg_pointer
)
2610 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
)
2613 if (memory_address_p (GET_MODE (x
), ad
))
2617 temp
= copy_to_reg (ad
);
2620 emit_insn_before (seq
, insn
);
2621 return replace_equiv_address (x
, temp
);
2626 fmt
= GET_RTX_FORMAT (code
);
2627 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2630 XEXP (x
, i
) = fixup_stack_1 (XEXP (x
, i
), insn
);
2631 else if (fmt
[i
] == 'E')
2634 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2635 XVECEXP (x
, i
, j
) = fixup_stack_1 (XVECEXP (x
, i
, j
), insn
);
2641 /* Optimization: a bit-field instruction whose field
2642 happens to be a byte or halfword in memory
2643 can be changed to a move instruction.
2645 We call here when INSN is an insn to examine or store into a bit-field.
2646 BODY is the SET-rtx to be altered.
2648 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2649 (Currently this is called only from function.c, and EQUIV_MEM
2653 optimize_bit_field (body
, insn
, equiv_mem
)
2661 enum machine_mode mode
;
2663 if (GET_CODE (SET_DEST (body
)) == SIGN_EXTRACT
2664 || GET_CODE (SET_DEST (body
)) == ZERO_EXTRACT
)
2665 bitfield
= SET_DEST (body
), destflag
= 1;
2667 bitfield
= SET_SRC (body
), destflag
= 0;
2669 /* First check that the field being stored has constant size and position
2670 and is in fact a byte or halfword suitably aligned. */
2672 if (GET_CODE (XEXP (bitfield
, 1)) == CONST_INT
2673 && GET_CODE (XEXP (bitfield
, 2)) == CONST_INT
2674 && ((mode
= mode_for_size (INTVAL (XEXP (bitfield
, 1)), MODE_INT
, 1))
2676 && INTVAL (XEXP (bitfield
, 2)) % INTVAL (XEXP (bitfield
, 1)) == 0)
2680 /* Now check that the containing word is memory, not a register,
2681 and that it is safe to change the machine mode. */
2683 if (GET_CODE (XEXP (bitfield
, 0)) == MEM
)
2684 memref
= XEXP (bitfield
, 0);
2685 else if (GET_CODE (XEXP (bitfield
, 0)) == REG
2687 memref
= equiv_mem
[REGNO (XEXP (bitfield
, 0))];
2688 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2689 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == MEM
)
2690 memref
= SUBREG_REG (XEXP (bitfield
, 0));
2691 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2693 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == REG
)
2694 memref
= equiv_mem
[REGNO (SUBREG_REG (XEXP (bitfield
, 0)))];
2697 && ! mode_dependent_address_p (XEXP (memref
, 0))
2698 && ! MEM_VOLATILE_P (memref
))
2700 /* Now adjust the address, first for any subreg'ing
2701 that we are now getting rid of,
2702 and then for which byte of the word is wanted. */
2704 HOST_WIDE_INT offset
= INTVAL (XEXP (bitfield
, 2));
2707 /* Adjust OFFSET to count bits from low-address byte. */
2708 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
2709 offset
= (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield
, 0)))
2710 - offset
- INTVAL (XEXP (bitfield
, 1)));
2712 /* Adjust OFFSET to count bytes from low-address byte. */
2713 offset
/= BITS_PER_UNIT
;
2714 if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
)
2716 offset
+= (SUBREG_BYTE (XEXP (bitfield
, 0))
2717 / UNITS_PER_WORD
) * UNITS_PER_WORD
;
2718 if (BYTES_BIG_ENDIAN
)
2719 offset
-= (MIN (UNITS_PER_WORD
,
2720 GET_MODE_SIZE (GET_MODE (XEXP (bitfield
, 0))))
2721 - MIN (UNITS_PER_WORD
,
2722 GET_MODE_SIZE (GET_MODE (memref
))));
2726 memref
= adjust_address (memref
, mode
, offset
);
2727 insns
= get_insns ();
2729 emit_insn_before (insns
, insn
);
2731 /* Store this memory reference where
2732 we found the bit field reference. */
2736 validate_change (insn
, &SET_DEST (body
), memref
, 1);
2737 if (! CONSTANT_ADDRESS_P (SET_SRC (body
)))
2739 rtx src
= SET_SRC (body
);
2740 while (GET_CODE (src
) == SUBREG
2741 && SUBREG_BYTE (src
) == 0)
2742 src
= SUBREG_REG (src
);
2743 if (GET_MODE (src
) != GET_MODE (memref
))
2744 src
= gen_lowpart (GET_MODE (memref
), SET_SRC (body
));
2745 validate_change (insn
, &SET_SRC (body
), src
, 1);
2747 else if (GET_MODE (SET_SRC (body
)) != VOIDmode
2748 && GET_MODE (SET_SRC (body
)) != GET_MODE (memref
))
2749 /* This shouldn't happen because anything that didn't have
2750 one of these modes should have got converted explicitly
2751 and then referenced through a subreg.
2752 This is so because the original bit-field was
2753 handled by agg_mode and so its tree structure had
2754 the same mode that memref now has. */
2759 rtx dest
= SET_DEST (body
);
2761 while (GET_CODE (dest
) == SUBREG
2762 && SUBREG_BYTE (dest
) == 0
2763 && (GET_MODE_CLASS (GET_MODE (dest
))
2764 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest
))))
2765 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
2767 dest
= SUBREG_REG (dest
);
2769 validate_change (insn
, &SET_DEST (body
), dest
, 1);
2771 if (GET_MODE (dest
) == GET_MODE (memref
))
2772 validate_change (insn
, &SET_SRC (body
), memref
, 1);
2775 /* Convert the mem ref to the destination mode. */
2776 rtx newreg
= gen_reg_rtx (GET_MODE (dest
));
2779 convert_move (newreg
, memref
,
2780 GET_CODE (SET_SRC (body
)) == ZERO_EXTRACT
);
2784 validate_change (insn
, &SET_SRC (body
), newreg
, 1);
2788 /* See if we can convert this extraction or insertion into
2789 a simple move insn. We might not be able to do so if this
2790 was, for example, part of a PARALLEL.
2792 If we succeed, write out any needed conversions. If we fail,
2793 it is hard to guess why we failed, so don't do anything
2794 special; just let the optimization be suppressed. */
2796 if (apply_change_group () && seq
)
2797 emit_insn_before (seq
, insn
);
2802 /* These routines are responsible for converting virtual register references
2803 to the actual hard register references once RTL generation is complete.
2805 The following four variables are used for communication between the
2806 routines. They contain the offsets of the virtual registers from their
2807 respective hard registers. */
2809 static int in_arg_offset
;
2810 static int var_offset
;
2811 static int dynamic_offset
;
2812 static int out_arg_offset
;
2813 static int cfa_offset
;
2815 /* In most machines, the stack pointer register is equivalent to the bottom
2818 #ifndef STACK_POINTER_OFFSET
2819 #define STACK_POINTER_OFFSET 0
2822 /* If not defined, pick an appropriate default for the offset of dynamically
2823 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2824 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2826 #ifndef STACK_DYNAMIC_OFFSET
2828 /* The bottom of the stack points to the actual arguments. If
2829 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2830 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2831 stack space for register parameters is not pushed by the caller, but
2832 rather part of the fixed stack areas and hence not included in
2833 `current_function_outgoing_args_size'. Nevertheless, we must allow
2834 for it when allocating stack dynamic objects. */
2836 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2837 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2838 ((ACCUMULATE_OUTGOING_ARGS \
2839 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2840 + (STACK_POINTER_OFFSET)) \
2843 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2844 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2845 + (STACK_POINTER_OFFSET))
2849 /* On most machines, the CFA coincides with the first incoming parm. */
2851 #ifndef ARG_POINTER_CFA_OFFSET
2852 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2855 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2856 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2857 register, for later use if we do need to force REG into the stack. REG is
2858 overwritten by the MEM like in put_reg_into_stack. */
2861 gen_mem_addressof (reg
, decl
)
2865 rtx r
= gen_rtx_ADDRESSOF (Pmode
, gen_reg_rtx (GET_MODE (reg
)),
2868 /* Calculate this before we start messing with decl's RTL. */
2869 HOST_WIDE_INT set
= decl
? get_alias_set (decl
) : 0;
2871 /* If the original REG was a user-variable, then so is the REG whose
2872 address is being taken. Likewise for unchanging. */
2873 REG_USERVAR_P (XEXP (r
, 0)) = REG_USERVAR_P (reg
);
2874 RTX_UNCHANGING_P (XEXP (r
, 0)) = RTX_UNCHANGING_P (reg
);
2876 PUT_CODE (reg
, MEM
);
2877 MEM_ATTRS (reg
) = 0;
2882 tree type
= TREE_TYPE (decl
);
2883 enum machine_mode decl_mode
2884 = (DECL_P (decl
) ? DECL_MODE (decl
) : TYPE_MODE (TREE_TYPE (decl
)));
2885 rtx decl_rtl
= (TREE_CODE (decl
) == SAVE_EXPR
? SAVE_EXPR_RTL (decl
)
2886 : DECL_RTL_IF_SET (decl
));
2888 PUT_MODE (reg
, decl_mode
);
2890 /* Clear DECL_RTL momentarily so functions below will work
2891 properly, then set it again. */
2892 if (DECL_P (decl
) && decl_rtl
== reg
)
2893 SET_DECL_RTL (decl
, 0);
2895 set_mem_attributes (reg
, decl
, 1);
2896 set_mem_alias_set (reg
, set
);
2898 if (DECL_P (decl
) && decl_rtl
== reg
)
2899 SET_DECL_RTL (decl
, reg
);
2901 if (TREE_USED (decl
) || (DECL_P (decl
) && DECL_INITIAL (decl
) != 0))
2902 fixup_var_refs (reg
, GET_MODE (reg
), TREE_UNSIGNED (type
), reg
, 0);
2905 fixup_var_refs (reg
, GET_MODE (reg
), 0, reg
, 0);
2910 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2913 flush_addressof (decl
)
2916 if ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
2917 && DECL_RTL (decl
) != 0
2918 && GET_CODE (DECL_RTL (decl
)) == MEM
2919 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
2920 && GET_CODE (XEXP (XEXP (DECL_RTL (decl
), 0), 0)) == REG
)
2921 put_addressof_into_stack (XEXP (DECL_RTL (decl
), 0), 0);
2924 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2927 put_addressof_into_stack (r
, ht
)
2932 int volatile_p
, used_p
;
2934 rtx reg
= XEXP (r
, 0);
2936 if (GET_CODE (reg
) != REG
)
2939 decl
= ADDRESSOF_DECL (r
);
2942 type
= TREE_TYPE (decl
);
2943 volatile_p
= (TREE_CODE (decl
) != SAVE_EXPR
2944 && TREE_THIS_VOLATILE (decl
));
2945 used_p
= (TREE_USED (decl
)
2946 || (DECL_P (decl
) && DECL_INITIAL (decl
) != 0));
2955 put_reg_into_stack (0, reg
, type
, GET_MODE (reg
), GET_MODE (reg
),
2956 volatile_p
, ADDRESSOF_REGNO (r
), used_p
, ht
);
2959 /* List of replacements made below in purge_addressof_1 when creating
2960 bitfield insertions. */
2961 static rtx purge_bitfield_addressof_replacements
;
2963 /* List of replacements made below in purge_addressof_1 for patterns
2964 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
2965 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
2966 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
2967 enough in complex cases, e.g. when some field values can be
2968 extracted by usage MEM with narrower mode. */
2969 static rtx purge_addressof_replacements
;
2971 /* Helper function for purge_addressof. See if the rtx expression at *LOC
2972 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
2973 the stack. If the function returns FALSE then the replacement could not
2977 purge_addressof_1 (loc
, insn
, force
, store
, ht
)
2989 /* Re-start here to avoid recursion in common cases. */
2996 code
= GET_CODE (x
);
2998 /* If we don't return in any of the cases below, we will recurse inside
2999 the RTX, which will normally result in any ADDRESSOF being forced into
3003 result
= purge_addressof_1 (&SET_DEST (x
), insn
, force
, 1, ht
);
3004 result
&= purge_addressof_1 (&SET_SRC (x
), insn
, force
, 0, ht
);
3007 else if (code
== ADDRESSOF
)
3011 if (GET_CODE (XEXP (x
, 0)) != MEM
)
3012 put_addressof_into_stack (x
, ht
);
3014 /* We must create a copy of the rtx because it was created by
3015 overwriting a REG rtx which is always shared. */
3016 sub
= copy_rtx (XEXP (XEXP (x
, 0), 0));
3017 if (validate_change (insn
, loc
, sub
, 0)
3018 || validate_replace_rtx (x
, sub
, insn
))
3022 sub
= force_operand (sub
, NULL_RTX
);
3023 if (! validate_change (insn
, loc
, sub
, 0)
3024 && ! validate_replace_rtx (x
, sub
, insn
))
3027 insns
= get_insns ();
3029 emit_insn_before (insns
, insn
);
3033 else if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == ADDRESSOF
&& ! force
)
3035 rtx sub
= XEXP (XEXP (x
, 0), 0);
3037 if (GET_CODE (sub
) == MEM
)
3038 sub
= adjust_address_nv (sub
, GET_MODE (x
), 0);
3039 else if (GET_CODE (sub
) == REG
3040 && (MEM_VOLATILE_P (x
) || GET_MODE (x
) == BLKmode
))
3042 else if (GET_CODE (sub
) == REG
&& GET_MODE (x
) != GET_MODE (sub
))
3044 int size_x
, size_sub
;
3048 /* When processing REG_NOTES look at the list of
3049 replacements done on the insn to find the register that X
3053 for (tem
= purge_bitfield_addressof_replacements
;
3055 tem
= XEXP (XEXP (tem
, 1), 1))
3056 if (rtx_equal_p (x
, XEXP (tem
, 0)))
3058 *loc
= XEXP (XEXP (tem
, 1), 0);
3062 /* See comment for purge_addressof_replacements. */
3063 for (tem
= purge_addressof_replacements
;
3065 tem
= XEXP (XEXP (tem
, 1), 1))
3066 if (rtx_equal_p (XEXP (x
, 0), XEXP (tem
, 0)))
3068 rtx z
= XEXP (XEXP (tem
, 1), 0);
3070 if (GET_MODE (x
) == GET_MODE (z
)
3071 || (GET_CODE (XEXP (XEXP (tem
, 1), 0)) != REG
3072 && GET_CODE (XEXP (XEXP (tem
, 1), 0)) != SUBREG
))
3075 /* It can happen that the note may speak of things
3076 in a wider (or just different) mode than the
3077 code did. This is especially true of
3080 if (GET_CODE (z
) == SUBREG
&& SUBREG_BYTE (z
) == 0)
3083 if (GET_MODE_SIZE (GET_MODE (x
)) > UNITS_PER_WORD
3084 && (GET_MODE_SIZE (GET_MODE (x
))
3085 > GET_MODE_SIZE (GET_MODE (z
))))
3087 /* This can occur as a result in invalid
3088 pointer casts, e.g. float f; ...
3089 *(long long int *)&f.
3090 ??? We could emit a warning here, but
3091 without a line number that wouldn't be
3093 z
= gen_rtx_SUBREG (GET_MODE (x
), z
, 0);
3096 z
= gen_lowpart (GET_MODE (x
), z
);
3102 /* Sometimes we may not be able to find the replacement. For
3103 example when the original insn was a MEM in a wider mode,
3104 and the note is part of a sign extension of a narrowed
3105 version of that MEM. Gcc testcase compile/990829-1.c can
3106 generate an example of this situation. Rather than complain
3107 we return false, which will prompt our caller to remove the
3112 size_x
= GET_MODE_BITSIZE (GET_MODE (x
));
3113 size_sub
= GET_MODE_BITSIZE (GET_MODE (sub
));
3115 /* Don't even consider working with paradoxical subregs,
3116 or the moral equivalent seen here. */
3117 if (size_x
<= size_sub
3118 && int_mode_for_mode (GET_MODE (sub
)) != BLKmode
)
3120 /* Do a bitfield insertion to mirror what would happen
3127 rtx p
= PREV_INSN (insn
);
3130 val
= gen_reg_rtx (GET_MODE (x
));
3131 if (! validate_change (insn
, loc
, val
, 0))
3133 /* Discard the current sequence and put the
3134 ADDRESSOF on stack. */
3140 emit_insn_before (seq
, insn
);
3141 compute_insns_for_mem (p
? NEXT_INSN (p
) : get_insns (),
3145 store_bit_field (sub
, size_x
, 0, GET_MODE (x
),
3146 val
, GET_MODE_SIZE (GET_MODE (sub
)));
3148 /* Make sure to unshare any shared rtl that store_bit_field
3149 might have created. */
3150 unshare_all_rtl_again (get_insns ());
3154 p
= emit_insn_after (seq
, insn
);
3155 if (NEXT_INSN (insn
))
3156 compute_insns_for_mem (NEXT_INSN (insn
),
3157 p
? NEXT_INSN (p
) : NULL_RTX
,
3162 rtx p
= PREV_INSN (insn
);
3165 val
= extract_bit_field (sub
, size_x
, 0, 1, NULL_RTX
,
3166 GET_MODE (x
), GET_MODE (x
),
3167 GET_MODE_SIZE (GET_MODE (sub
)));
3169 if (! validate_change (insn
, loc
, val
, 0))
3171 /* Discard the current sequence and put the
3172 ADDRESSOF on stack. */
3179 emit_insn_before (seq
, insn
);
3180 compute_insns_for_mem (p
? NEXT_INSN (p
) : get_insns (),
3184 /* Remember the replacement so that the same one can be done
3185 on the REG_NOTES. */
3186 purge_bitfield_addressof_replacements
3187 = gen_rtx_EXPR_LIST (VOIDmode
, x
,
3190 purge_bitfield_addressof_replacements
));
3192 /* We replaced with a reg -- all done. */
3197 else if (validate_change (insn
, loc
, sub
, 0))
3199 /* Remember the replacement so that the same one can be done
3200 on the REG_NOTES. */
3201 if (GET_CODE (sub
) == REG
|| GET_CODE (sub
) == SUBREG
)
3205 for (tem
= purge_addressof_replacements
;
3207 tem
= XEXP (XEXP (tem
, 1), 1))
3208 if (rtx_equal_p (XEXP (x
, 0), XEXP (tem
, 0)))
3210 XEXP (XEXP (tem
, 1), 0) = sub
;
3213 purge_addressof_replacements
3214 = gen_rtx (EXPR_LIST
, VOIDmode
, XEXP (x
, 0),
3215 gen_rtx_EXPR_LIST (VOIDmode
, sub
,
3216 purge_addressof_replacements
));
3224 /* Scan all subexpressions. */
3225 fmt
= GET_RTX_FORMAT (code
);
3226 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3229 result
&= purge_addressof_1 (&XEXP (x
, i
), insn
, force
, 0, ht
);
3230 else if (*fmt
== 'E')
3231 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3232 result
&= purge_addressof_1 (&XVECEXP (x
, i
, j
), insn
, force
, 0, ht
);
3238 /* Return a hash value for K, a REG. */
3241 insns_for_mem_hash (k
)
3244 /* Use the address of the key for the hash value. */
3245 struct insns_for_mem_entry
*m
= (struct insns_for_mem_entry
*) k
;
3246 return htab_hash_pointer (m
->key
);
3249 /* Return nonzero if K1 and K2 (two REGs) are the same. */
3252 insns_for_mem_comp (k1
, k2
)
3256 struct insns_for_mem_entry
*m1
= (struct insns_for_mem_entry
*) k1
;
3257 struct insns_for_mem_entry
*m2
= (struct insns_for_mem_entry
*) k2
;
3258 return m1
->key
== m2
->key
;
3261 struct insns_for_mem_walk_info
3263 /* The hash table that we are using to record which INSNs use which
3267 /* The INSN we are currently processing. */
3270 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3271 to find the insns that use the REGs in the ADDRESSOFs. */
3275 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3276 that might be used in an ADDRESSOF expression, record this INSN in
3277 the hash table given by DATA (which is really a pointer to an
3278 insns_for_mem_walk_info structure). */
3281 insns_for_mem_walk (r
, data
)
3285 struct insns_for_mem_walk_info
*ifmwi
3286 = (struct insns_for_mem_walk_info
*) data
;
3287 struct insns_for_mem_entry tmp
;
3288 tmp
.insns
= NULL_RTX
;
3290 if (ifmwi
->pass
== 0 && *r
&& GET_CODE (*r
) == ADDRESSOF
3291 && GET_CODE (XEXP (*r
, 0)) == REG
)
3294 tmp
.key
= XEXP (*r
, 0);
3295 e
= htab_find_slot (ifmwi
->ht
, &tmp
, INSERT
);
3298 *e
= ggc_alloc (sizeof (tmp
));
3299 memcpy (*e
, &tmp
, sizeof (tmp
));
3302 else if (ifmwi
->pass
== 1 && *r
&& GET_CODE (*r
) == REG
)
3304 struct insns_for_mem_entry
*ifme
;
3306 ifme
= (struct insns_for_mem_entry
*) htab_find (ifmwi
->ht
, &tmp
);
3308 /* If we have not already recorded this INSN, do so now. Since
3309 we process the INSNs in order, we know that if we have
3310 recorded it it must be at the front of the list. */
3311 if (ifme
&& (!ifme
->insns
|| XEXP (ifme
->insns
, 0) != ifmwi
->insn
))
3312 ifme
->insns
= gen_rtx_EXPR_LIST (VOIDmode
, ifmwi
->insn
,
3319 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3320 which REGs in HT. */
3323 compute_insns_for_mem (insns
, last_insn
, ht
)
3329 struct insns_for_mem_walk_info ifmwi
;
3332 for (ifmwi
.pass
= 0; ifmwi
.pass
< 2; ++ifmwi
.pass
)
3333 for (insn
= insns
; insn
!= last_insn
; insn
= NEXT_INSN (insn
))
3337 for_each_rtx (&insn
, insns_for_mem_walk
, &ifmwi
);
3341 /* Helper function for purge_addressof called through for_each_rtx.
3342 Returns true iff the rtl is an ADDRESSOF. */
3345 is_addressof (rtl
, data
)
3347 void *data ATTRIBUTE_UNUSED
;
3349 return GET_CODE (*rtl
) == ADDRESSOF
;
3352 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3353 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3357 purge_addressof (insns
)
3363 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3364 requires a fixup pass over the instruction stream to correct
3365 INSNs that depended on the REG being a REG, and not a MEM. But,
3366 these fixup passes are slow. Furthermore, most MEMs are not
3367 mentioned in very many instructions. So, we speed up the process
3368 by pre-calculating which REGs occur in which INSNs; that allows
3369 us to perform the fixup passes much more quickly. */
3370 ht
= htab_create_ggc (1000, insns_for_mem_hash
, insns_for_mem_comp
, NULL
);
3371 compute_insns_for_mem (insns
, NULL_RTX
, ht
);
3373 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3376 if (! purge_addressof_1 (&PATTERN (insn
), insn
,
3377 asm_noperands (PATTERN (insn
)) > 0, 0, ht
))
3378 /* If we could not replace the ADDRESSOFs in the insn,
3379 something is wrong. */
3382 if (! purge_addressof_1 (®_NOTES (insn
), NULL_RTX
, 0, 0, ht
))
3384 /* If we could not replace the ADDRESSOFs in the insn's notes,
3385 we can just remove the offending notes instead. */
3388 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
3390 /* If we find a REG_RETVAL note then the insn is a libcall.
3391 Such insns must have REG_EQUAL notes as well, in order
3392 for later passes of the compiler to work. So it is not
3393 safe to delete the notes here, and instead we abort. */
3394 if (REG_NOTE_KIND (note
) == REG_RETVAL
)
3396 if (for_each_rtx (¬e
, is_addressof
, NULL
))
3397 remove_note (insn
, note
);
3403 purge_bitfield_addressof_replacements
= 0;
3404 purge_addressof_replacements
= 0;
3406 /* REGs are shared. purge_addressof will destructively replace a REG
3407 with a MEM, which creates shared MEMs.
3409 Unfortunately, the children of put_reg_into_stack assume that MEMs
3410 referring to the same stack slot are shared (fixup_var_refs and
3411 the associated hash table code).
3413 So, we have to do another unsharing pass after we have flushed any
3414 REGs that had their address taken into the stack.
3416 It may be worth tracking whether or not we converted any REGs into
3417 MEMs to avoid this overhead when it is not needed. */
3418 unshare_all_rtl_again (get_insns ());
3421 /* Convert a SET of a hard subreg to a set of the appropriate hard
3422 register. A subroutine of purge_hard_subreg_sets. */
3425 purge_single_hard_subreg_set (pattern
)
3428 rtx reg
= SET_DEST (pattern
);
3429 enum machine_mode mode
= GET_MODE (SET_DEST (pattern
));
3432 if (GET_CODE (reg
) == SUBREG
&& GET_CODE (SUBREG_REG (reg
)) == REG
3433 && REGNO (SUBREG_REG (reg
)) < FIRST_PSEUDO_REGISTER
)
3435 offset
= subreg_regno_offset (REGNO (SUBREG_REG (reg
)),
3436 GET_MODE (SUBREG_REG (reg
)),
3439 reg
= SUBREG_REG (reg
);
3443 if (GET_CODE (reg
) == REG
&& REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
3445 reg
= gen_rtx_REG (mode
, REGNO (reg
) + offset
);
3446 SET_DEST (pattern
) = reg
;
3450 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3451 only such SETs that we expect to see are those left in because
3452 integrate can't handle sets of parts of a return value register.
3454 We don't use alter_subreg because we only want to eliminate subregs
3455 of hard registers. */
3458 purge_hard_subreg_sets (insn
)
3461 for (; insn
; insn
= NEXT_INSN (insn
))
3465 rtx pattern
= PATTERN (insn
);
3466 switch (GET_CODE (pattern
))
3469 if (GET_CODE (SET_DEST (pattern
)) == SUBREG
)
3470 purge_single_hard_subreg_set (pattern
);
3475 for (j
= XVECLEN (pattern
, 0) - 1; j
>= 0; j
--)
3477 rtx inner_pattern
= XVECEXP (pattern
, 0, j
);
3478 if (GET_CODE (inner_pattern
) == SET
3479 && GET_CODE (SET_DEST (inner_pattern
)) == SUBREG
)
3480 purge_single_hard_subreg_set (inner_pattern
);
3491 /* Pass through the INSNS of function FNDECL and convert virtual register
3492 references to hard register references. */
3495 instantiate_virtual_regs (fndecl
, insns
)
3502 /* Compute the offsets to use for this function. */
3503 in_arg_offset
= FIRST_PARM_OFFSET (fndecl
);
3504 var_offset
= STARTING_FRAME_OFFSET
;
3505 dynamic_offset
= STACK_DYNAMIC_OFFSET (fndecl
);
3506 out_arg_offset
= STACK_POINTER_OFFSET
;
3507 cfa_offset
= ARG_POINTER_CFA_OFFSET (fndecl
);
3509 /* Scan all variables and parameters of this function. For each that is
3510 in memory, instantiate all virtual registers if the result is a valid
3511 address. If not, we do it later. That will handle most uses of virtual
3512 regs on many machines. */
3513 instantiate_decls (fndecl
, 1);
3515 /* Initialize recognition, indicating that volatile is OK. */
3518 /* Scan through all the insns, instantiating every virtual register still
3520 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3521 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
3522 || GET_CODE (insn
) == CALL_INSN
)
3524 instantiate_virtual_regs_1 (&PATTERN (insn
), insn
, 1);
3525 instantiate_virtual_regs_1 (®_NOTES (insn
), NULL_RTX
, 0);
3526 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3527 if (GET_CODE (insn
) == CALL_INSN
)
3528 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn
),
3532 /* Instantiate the stack slots for the parm registers, for later use in
3533 addressof elimination. */
3534 for (i
= 0; i
< max_parm_reg
; ++i
)
3535 if (parm_reg_stack_loc
[i
])
3536 instantiate_virtual_regs_1 (&parm_reg_stack_loc
[i
], NULL_RTX
, 0);
3538 /* Now instantiate the remaining register equivalences for debugging info.
3539 These will not be valid addresses. */
3540 instantiate_decls (fndecl
, 0);
3542 /* Indicate that, from now on, assign_stack_local should use
3543 frame_pointer_rtx. */
3544 virtuals_instantiated
= 1;
3547 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3548 all virtual registers in their DECL_RTL's.
3550 If VALID_ONLY, do this only if the resulting address is still valid.
3551 Otherwise, always do it. */
3554 instantiate_decls (fndecl
, valid_only
)
3560 /* Process all parameters of the function. */
3561 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= TREE_CHAIN (decl
))
3563 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (decl
));
3564 HOST_WIDE_INT size_rtl
;
3566 instantiate_decl (DECL_RTL (decl
), size
, valid_only
);
3568 /* If the parameter was promoted, then the incoming RTL mode may be
3569 larger than the declared type size. We must use the larger of
3571 size_rtl
= GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl
)));
3572 size
= MAX (size_rtl
, size
);
3573 instantiate_decl (DECL_INCOMING_RTL (decl
), size
, valid_only
);
3576 /* Now process all variables defined in the function or its subblocks. */
3577 instantiate_decls_1 (DECL_INITIAL (fndecl
), valid_only
);
3580 /* Subroutine of instantiate_decls: Process all decls in the given
3581 BLOCK node and all its subblocks. */
3584 instantiate_decls_1 (let
, valid_only
)
3590 for (t
= BLOCK_VARS (let
); t
; t
= TREE_CHAIN (t
))
3591 if (DECL_RTL_SET_P (t
))
3592 instantiate_decl (DECL_RTL (t
),
3593 int_size_in_bytes (TREE_TYPE (t
)),
3596 /* Process all subblocks. */
3597 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= TREE_CHAIN (t
))
3598 instantiate_decls_1 (t
, valid_only
);
3601 /* Subroutine of the preceding procedures: Given RTL representing a
3602 decl and the size of the object, do any instantiation required.
3604 If VALID_ONLY is nonzero, it means that the RTL should only be
3605 changed if the new address is valid. */
3608 instantiate_decl (x
, size
, valid_only
)
3613 enum machine_mode mode
;
3616 /* If this is not a MEM, no need to do anything. Similarly if the
3617 address is a constant or a register that is not a virtual register. */
3619 if (x
== 0 || GET_CODE (x
) != MEM
)
3623 if (CONSTANT_P (addr
)
3624 || (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == REG
)
3625 || (GET_CODE (addr
) == REG
3626 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
3627 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
3630 /* If we should only do this if the address is valid, copy the address.
3631 We need to do this so we can undo any changes that might make the
3632 address invalid. This copy is unfortunate, but probably can't be
3636 addr
= copy_rtx (addr
);
3638 instantiate_virtual_regs_1 (&addr
, NULL_RTX
, 0);
3640 if (valid_only
&& size
>= 0)
3642 unsigned HOST_WIDE_INT decl_size
= size
;
3644 /* Now verify that the resulting address is valid for every integer or
3645 floating-point mode up to and including SIZE bytes long. We do this
3646 since the object might be accessed in any mode and frame addresses
3649 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3650 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= decl_size
;
3651 mode
= GET_MODE_WIDER_MODE (mode
))
3652 if (! memory_address_p (mode
, addr
))
3655 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
3656 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= decl_size
;
3657 mode
= GET_MODE_WIDER_MODE (mode
))
3658 if (! memory_address_p (mode
, addr
))
3662 /* Put back the address now that we have updated it and we either know
3663 it is valid or we don't care whether it is valid. */
3668 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3669 is a virtual register, return the equivalent hard register and set the
3670 offset indirectly through the pointer. Otherwise, return 0. */
3673 instantiate_new_reg (x
, poffset
)
3675 HOST_WIDE_INT
*poffset
;
3678 HOST_WIDE_INT offset
;
3680 if (x
== virtual_incoming_args_rtx
)
3681 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3682 else if (x
== virtual_stack_vars_rtx
)
3683 new = frame_pointer_rtx
, offset
= var_offset
;
3684 else if (x
== virtual_stack_dynamic_rtx
)
3685 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3686 else if (x
== virtual_outgoing_args_rtx
)
3687 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3688 else if (x
== virtual_cfa_rtx
)
3689 new = arg_pointer_rtx
, offset
= cfa_offset
;
3697 /* Given a pointer to a piece of rtx and an optional pointer to the
3698 containing object, instantiate any virtual registers present in it.
3700 If EXTRA_INSNS, we always do the replacement and generate
3701 any extra insns before OBJECT. If it zero, we do nothing if replacement
3704 Return 1 if we either had nothing to do or if we were able to do the
3705 needed replacement. Return 0 otherwise; we only return zero if
3706 EXTRA_INSNS is zero.
3708 We first try some simple transformations to avoid the creation of extra
3712 instantiate_virtual_regs_1 (loc
, object
, extra_insns
)
3720 HOST_WIDE_INT offset
= 0;
3726 /* Re-start here to avoid recursion in common cases. */
3733 code
= GET_CODE (x
);
3735 /* Check for some special cases. */
3753 /* We are allowed to set the virtual registers. This means that
3754 the actual register should receive the source minus the
3755 appropriate offset. This is used, for example, in the handling
3756 of non-local gotos. */
3757 if ((new = instantiate_new_reg (SET_DEST (x
), &offset
)) != 0)
3759 rtx src
= SET_SRC (x
);
3761 /* We are setting the register, not using it, so the relevant
3762 offset is the negative of the offset to use were we using
3765 instantiate_virtual_regs_1 (&src
, NULL_RTX
, 0);
3767 /* The only valid sources here are PLUS or REG. Just do
3768 the simplest possible thing to handle them. */
3769 if (GET_CODE (src
) != REG
&& GET_CODE (src
) != PLUS
)
3773 if (GET_CODE (src
) != REG
)
3774 temp
= force_operand (src
, NULL_RTX
);
3777 temp
= force_operand (plus_constant (temp
, offset
), NULL_RTX
);
3781 emit_insn_before (seq
, object
);
3784 if (! validate_change (object
, &SET_SRC (x
), temp
, 0)
3791 instantiate_virtual_regs_1 (&SET_DEST (x
), object
, extra_insns
);
3796 /* Handle special case of virtual register plus constant. */
3797 if (CONSTANT_P (XEXP (x
, 1)))
3799 rtx old
, new_offset
;
3801 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3802 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
3804 if ((new = instantiate_new_reg (XEXP (XEXP (x
, 0), 0), &offset
)))
3806 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 1), object
,
3808 new = gen_rtx_PLUS (Pmode
, new, XEXP (XEXP (x
, 0), 1));
3817 #ifdef POINTERS_EXTEND_UNSIGNED
3818 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3819 we can commute the PLUS and SUBREG because pointers into the
3820 frame are well-behaved. */
3821 else if (GET_CODE (XEXP (x
, 0)) == SUBREG
&& GET_MODE (x
) == ptr_mode
3822 && GET_CODE (XEXP (x
, 1)) == CONST_INT
3824 = instantiate_new_reg (SUBREG_REG (XEXP (x
, 0)),
3826 && validate_change (object
, loc
,
3827 plus_constant (gen_lowpart (ptr_mode
,
3830 + INTVAL (XEXP (x
, 1))),
3834 else if ((new = instantiate_new_reg (XEXP (x
, 0), &offset
)) == 0)
3836 /* We know the second operand is a constant. Unless the
3837 first operand is a REG (which has been already checked),
3838 it needs to be checked. */
3839 if (GET_CODE (XEXP (x
, 0)) != REG
)
3847 new_offset
= plus_constant (XEXP (x
, 1), offset
);
3849 /* If the new constant is zero, try to replace the sum with just
3851 if (new_offset
== const0_rtx
3852 && validate_change (object
, loc
, new, 0))
3855 /* Next try to replace the register and new offset.
3856 There are two changes to validate here and we can't assume that
3857 in the case of old offset equals new just changing the register
3858 will yield a valid insn. In the interests of a little efficiency,
3859 however, we only call validate change once (we don't queue up the
3860 changes and then call apply_change_group). */
3864 ? ! validate_change (object
, &XEXP (x
, 0), new, 0)
3865 : (XEXP (x
, 0) = new,
3866 ! validate_change (object
, &XEXP (x
, 1), new_offset
, 0)))
3874 /* Otherwise copy the new constant into a register and replace
3875 constant with that register. */
3876 temp
= gen_reg_rtx (Pmode
);
3878 if (validate_change (object
, &XEXP (x
, 1), temp
, 0))
3879 emit_insn_before (gen_move_insn (temp
, new_offset
), object
);
3882 /* If that didn't work, replace this expression with a
3883 register containing the sum. */
3886 new = gen_rtx_PLUS (Pmode
, new, new_offset
);
3889 temp
= force_operand (new, NULL_RTX
);
3893 emit_insn_before (seq
, object
);
3894 if (! validate_change (object
, loc
, temp
, 0)
3895 && ! validate_replace_rtx (x
, temp
, object
))
3903 /* Fall through to generic two-operand expression case. */
3909 case DIV
: case UDIV
:
3910 case MOD
: case UMOD
:
3911 case AND
: case IOR
: case XOR
:
3912 case ROTATERT
: case ROTATE
:
3913 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
3915 case GE
: case GT
: case GEU
: case GTU
:
3916 case LE
: case LT
: case LEU
: case LTU
:
3917 if (XEXP (x
, 1) && ! CONSTANT_P (XEXP (x
, 1)))
3918 instantiate_virtual_regs_1 (&XEXP (x
, 1), object
, extra_insns
);
3923 /* Most cases of MEM that convert to valid addresses have already been
3924 handled by our scan of decls. The only special handling we
3925 need here is to make a copy of the rtx to ensure it isn't being
3926 shared if we have to change it to a pseudo.
3928 If the rtx is a simple reference to an address via a virtual register,
3929 it can potentially be shared. In such cases, first try to make it
3930 a valid address, which can also be shared. Otherwise, copy it and
3933 First check for common cases that need no processing. These are
3934 usually due to instantiation already being done on a previous instance
3938 if (CONSTANT_ADDRESS_P (temp
)
3939 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3940 || temp
== arg_pointer_rtx
3942 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3943 || temp
== hard_frame_pointer_rtx
3945 || temp
== frame_pointer_rtx
)
3948 if (GET_CODE (temp
) == PLUS
3949 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3950 && (XEXP (temp
, 0) == frame_pointer_rtx
3951 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3952 || XEXP (temp
, 0) == hard_frame_pointer_rtx
3954 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3955 || XEXP (temp
, 0) == arg_pointer_rtx
3960 if (temp
== virtual_stack_vars_rtx
3961 || temp
== virtual_incoming_args_rtx
3962 || (GET_CODE (temp
) == PLUS
3963 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3964 && (XEXP (temp
, 0) == virtual_stack_vars_rtx
3965 || XEXP (temp
, 0) == virtual_incoming_args_rtx
)))
3967 /* This MEM may be shared. If the substitution can be done without
3968 the need to generate new pseudos, we want to do it in place
3969 so all copies of the shared rtx benefit. The call below will
3970 only make substitutions if the resulting address is still
3973 Note that we cannot pass X as the object in the recursive call
3974 since the insn being processed may not allow all valid
3975 addresses. However, if we were not passed on object, we can
3976 only modify X without copying it if X will have a valid
3979 ??? Also note that this can still lose if OBJECT is an insn that
3980 has less restrictions on an address that some other insn.
3981 In that case, we will modify the shared address. This case
3982 doesn't seem very likely, though. One case where this could
3983 happen is in the case of a USE or CLOBBER reference, but we
3984 take care of that below. */
3986 if (instantiate_virtual_regs_1 (&XEXP (x
, 0),
3987 object
? object
: x
, 0))
3990 /* Otherwise make a copy and process that copy. We copy the entire
3991 RTL expression since it might be a PLUS which could also be
3993 *loc
= x
= copy_rtx (x
);
3996 /* Fall through to generic unary operation case. */
3999 case STRICT_LOW_PART
:
4001 case PRE_DEC
: case PRE_INC
: case POST_DEC
: case POST_INC
:
4002 case SIGN_EXTEND
: case ZERO_EXTEND
:
4003 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
4004 case FLOAT
: case FIX
:
4005 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
4010 case POPCOUNT
: case PARITY
:
4011 /* These case either have just one operand or we know that we need not
4012 check the rest of the operands. */
4018 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4019 go ahead and make the invalid one, but do it to a copy. For a REG,
4020 just make the recursive call, since there's no chance of a problem. */
4022 if ((GET_CODE (XEXP (x
, 0)) == MEM
4023 && instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), XEXP (x
, 0),
4025 || (GET_CODE (XEXP (x
, 0)) == REG
4026 && instantiate_virtual_regs_1 (&XEXP (x
, 0), object
, 0)))
4029 XEXP (x
, 0) = copy_rtx (XEXP (x
, 0));
4034 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4035 in front of this insn and substitute the temporary. */
4036 if ((new = instantiate_new_reg (x
, &offset
)) != 0)
4038 temp
= plus_constant (new, offset
);
4039 if (!validate_change (object
, loc
, temp
, 0))
4045 temp
= force_operand (temp
, NULL_RTX
);
4049 emit_insn_before (seq
, object
);
4050 if (! validate_change (object
, loc
, temp
, 0)
4051 && ! validate_replace_rtx (x
, temp
, object
))
4059 if (GET_CODE (XEXP (x
, 0)) == REG
)
4062 else if (GET_CODE (XEXP (x
, 0)) == MEM
)
4064 /* If we have a (addressof (mem ..)), do any instantiation inside
4065 since we know we'll be making the inside valid when we finally
4066 remove the ADDRESSOF. */
4067 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), NULL_RTX
, 0);
4076 /* Scan all subexpressions. */
4077 fmt
= GET_RTX_FORMAT (code
);
4078 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
4081 if (!instantiate_virtual_regs_1 (&XEXP (x
, i
), object
, extra_insns
))
4084 else if (*fmt
== 'E')
4085 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4086 if (! instantiate_virtual_regs_1 (&XVECEXP (x
, i
, j
), object
,
4093 /* Optimization: assuming this function does not receive nonlocal gotos,
4094 delete the handlers for such, as well as the insns to establish
4095 and disestablish them. */
4101 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4103 /* Delete the handler by turning off the flag that would
4104 prevent jump_optimize from deleting it.
4105 Also permit deletion of the nonlocal labels themselves
4106 if nothing local refers to them. */
4107 if (GET_CODE (insn
) == CODE_LABEL
)
4111 LABEL_PRESERVE_P (insn
) = 0;
4113 /* Remove it from the nonlocal_label list, to avoid confusing
4115 for (t
= nonlocal_labels
, last_t
= 0; t
;
4116 last_t
= t
, t
= TREE_CHAIN (t
))
4117 if (DECL_RTL (TREE_VALUE (t
)) == insn
)
4122 nonlocal_labels
= TREE_CHAIN (nonlocal_labels
);
4124 TREE_CHAIN (last_t
) = TREE_CHAIN (t
);
4127 if (GET_CODE (insn
) == INSN
)
4131 for (t
= nonlocal_goto_handler_slots
; t
!= 0; t
= XEXP (t
, 1))
4132 if (reg_mentioned_p (t
, PATTERN (insn
)))
4138 || (nonlocal_goto_stack_level
!= 0
4139 && reg_mentioned_p (nonlocal_goto_stack_level
,
4141 delete_related_insns (insn
);
4146 /* Return the first insn following those generated by `assign_parms'. */
4149 get_first_nonparm_insn ()
4152 return NEXT_INSN (last_parm_insn
);
4153 return get_insns ();
4156 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4157 This means a type for which function calls must pass an address to the
4158 function or get an address back from the function.
4159 EXP may be a type node or an expression (whose type is tested). */
4162 aggregate_value_p (exp
)
4165 int i
, regno
, nregs
;
4168 tree type
= (TYPE_P (exp
)) ? exp
: TREE_TYPE (exp
);
4170 if (TREE_CODE (type
) == VOID_TYPE
)
4172 if (RETURN_IN_MEMORY (type
))
4174 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4175 and thus can't be returned in registers. */
4176 if (TREE_ADDRESSABLE (type
))
4178 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
4180 /* Make sure we have suitable call-clobbered regs to return
4181 the value in; if not, we must return it in memory. */
4182 reg
= hard_function_value (type
, 0, 0);
4184 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4186 if (GET_CODE (reg
) != REG
)
4189 regno
= REGNO (reg
);
4190 nregs
= HARD_REGNO_NREGS (regno
, TYPE_MODE (type
));
4191 for (i
= 0; i
< nregs
; i
++)
4192 if (! call_used_regs
[regno
+ i
])
4197 /* Assign RTL expressions to the function's parameters.
4198 This may involve copying them into registers and using
4199 those registers as the RTL for them. */
4202 assign_parms (fndecl
)
4208 CUMULATIVE_ARGS args_so_far
;
4209 enum machine_mode promoted_mode
, passed_mode
;
4210 enum machine_mode nominal_mode
, promoted_nominal_mode
;
4212 /* Total space needed so far for args on the stack,
4213 given as a constant and a tree-expression. */
4214 struct args_size stack_args_size
;
4215 tree fntype
= TREE_TYPE (fndecl
);
4216 tree fnargs
= DECL_ARGUMENTS (fndecl
);
4217 /* This is used for the arg pointer when referring to stack args. */
4218 rtx internal_arg_pointer
;
4219 /* This is a dummy PARM_DECL that we used for the function result if
4220 the function returns a structure. */
4221 tree function_result_decl
= 0;
4222 #ifdef SETUP_INCOMING_VARARGS
4223 int varargs_setup
= 0;
4225 rtx conversion_insns
= 0;
4226 struct args_size alignment_pad
;
4228 /* Nonzero if function takes extra anonymous args.
4229 This means the last named arg must be on the stack
4230 right before the anonymous ones. */
4232 = (TYPE_ARG_TYPES (fntype
) != 0
4233 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
4234 != void_type_node
));
4236 current_function_stdarg
= stdarg
;
4238 /* If the reg that the virtual arg pointer will be translated into is
4239 not a fixed reg or is the stack pointer, make a copy of the virtual
4240 arg pointer, and address parms via the copy. The frame pointer is
4241 considered fixed even though it is not marked as such.
4243 The second time through, simply use ap to avoid generating rtx. */
4245 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
4246 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
4247 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
)))
4248 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
4250 internal_arg_pointer
= virtual_incoming_args_rtx
;
4251 current_function_internal_arg_pointer
= internal_arg_pointer
;
4253 stack_args_size
.constant
= 0;
4254 stack_args_size
.var
= 0;
4256 /* If struct value address is treated as the first argument, make it so. */
4257 if (aggregate_value_p (DECL_RESULT (fndecl
))
4258 && ! current_function_returns_pcc_struct
4259 && struct_value_incoming_rtx
== 0)
4261 tree type
= build_pointer_type (TREE_TYPE (fntype
));
4263 function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
4265 DECL_ARG_TYPE (function_result_decl
) = type
;
4266 TREE_CHAIN (function_result_decl
) = fnargs
;
4267 fnargs
= function_result_decl
;
4270 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
4271 parm_reg_stack_loc
= (rtx
*) ggc_alloc_cleared (max_parm_reg
* sizeof (rtx
));
4273 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4274 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far
, fntype
, NULL_RTX
);
4276 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, fndecl
);
4279 /* We haven't yet found an argument that we must push and pretend the
4281 current_function_pretend_args_size
= 0;
4283 for (parm
= fnargs
; parm
; parm
= TREE_CHAIN (parm
))
4285 struct args_size stack_offset
;
4286 struct args_size arg_size
;
4287 int passed_pointer
= 0;
4288 int did_conversion
= 0;
4289 tree passed_type
= DECL_ARG_TYPE (parm
);
4290 tree nominal_type
= TREE_TYPE (parm
);
4292 int last_named
= 0, named_arg
;
4294 /* Set LAST_NAMED if this is last named arg before last
4300 for (tem
= TREE_CHAIN (parm
); tem
; tem
= TREE_CHAIN (tem
))
4301 if (DECL_NAME (tem
))
4307 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4308 most machines, if this is a varargs/stdarg function, then we treat
4309 the last named arg as if it were anonymous too. */
4310 named_arg
= STRICT_ARGUMENT_NAMING
? 1 : ! last_named
;
4312 if (TREE_TYPE (parm
) == error_mark_node
4313 /* This can happen after weird syntax errors
4314 or if an enum type is defined among the parms. */
4315 || TREE_CODE (parm
) != PARM_DECL
4316 || passed_type
== NULL
)
4318 SET_DECL_RTL (parm
, gen_rtx_MEM (BLKmode
, const0_rtx
));
4319 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
4320 TREE_USED (parm
) = 1;
4324 /* Find mode of arg as it is passed, and mode of arg
4325 as it should be during execution of this function. */
4326 passed_mode
= TYPE_MODE (passed_type
);
4327 nominal_mode
= TYPE_MODE (nominal_type
);
4329 /* If the parm's mode is VOID, its value doesn't matter,
4330 and avoid the usual things like emit_move_insn that could crash. */
4331 if (nominal_mode
== VOIDmode
)
4333 SET_DECL_RTL (parm
, const0_rtx
);
4334 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
4338 /* If the parm is to be passed as a transparent union, use the
4339 type of the first field for the tests below. We have already
4340 verified that the modes are the same. */
4341 if (DECL_TRANSPARENT_UNION (parm
)
4342 || (TREE_CODE (passed_type
) == UNION_TYPE
4343 && TYPE_TRANSPARENT_UNION (passed_type
)))
4344 passed_type
= TREE_TYPE (TYPE_FIELDS (passed_type
));
4346 /* See if this arg was passed by invisible reference. It is if
4347 it is an object whose size depends on the contents of the
4348 object itself or if the machine requires these objects be passed
4351 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
4352 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
4353 || TREE_ADDRESSABLE (passed_type
)
4354 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4355 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
, passed_mode
,
4356 passed_type
, named_arg
)
4360 passed_type
= nominal_type
= build_pointer_type (passed_type
);
4362 passed_mode
= nominal_mode
= Pmode
;
4364 /* See if the frontend wants to pass this by invisible reference. */
4365 else if (passed_type
!= nominal_type
4366 && POINTER_TYPE_P (passed_type
)
4367 && TREE_TYPE (passed_type
) == nominal_type
)
4369 nominal_type
= passed_type
;
4371 passed_mode
= nominal_mode
= Pmode
;
4374 promoted_mode
= passed_mode
;
4376 #ifdef PROMOTE_FUNCTION_ARGS
4377 /* Compute the mode in which the arg is actually extended to. */
4378 unsignedp
= TREE_UNSIGNED (passed_type
);
4379 promoted_mode
= promote_mode (passed_type
, promoted_mode
, &unsignedp
, 1);
4382 /* Let machine desc say which reg (if any) the parm arrives in.
4383 0 means it arrives on the stack. */
4384 #ifdef FUNCTION_INCOMING_ARG
4385 entry_parm
= FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
4386 passed_type
, named_arg
);
4388 entry_parm
= FUNCTION_ARG (args_so_far
, promoted_mode
,
4389 passed_type
, named_arg
);
4392 if (entry_parm
== 0)
4393 promoted_mode
= passed_mode
;
4395 #ifdef SETUP_INCOMING_VARARGS
4396 /* If this is the last named parameter, do any required setup for
4397 varargs or stdargs. We need to know about the case of this being an
4398 addressable type, in which case we skip the registers it
4399 would have arrived in.
4401 For stdargs, LAST_NAMED will be set for two parameters, the one that
4402 is actually the last named, and the dummy parameter. We only
4403 want to do this action once.
4405 Also, indicate when RTL generation is to be suppressed. */
4406 if (last_named
&& !varargs_setup
)
4408 SETUP_INCOMING_VARARGS (args_so_far
, promoted_mode
, passed_type
,
4409 current_function_pretend_args_size
, 0);
4414 /* Determine parm's home in the stack,
4415 in case it arrives in the stack or we should pretend it did.
4417 Compute the stack position and rtx where the argument arrives
4420 There is one complexity here: If this was a parameter that would
4421 have been passed in registers, but wasn't only because it is
4422 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4423 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4424 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4425 0 as it was the previous time. */
4427 pretend_named
= named_arg
|| PRETEND_OUTGOING_VARARGS_NAMED
;
4428 locate_and_pad_parm (promoted_mode
, passed_type
,
4429 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4432 #ifdef FUNCTION_INCOMING_ARG
4433 FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
4435 pretend_named
) != 0,
4437 FUNCTION_ARG (args_so_far
, promoted_mode
,
4439 pretend_named
) != 0,
4442 fndecl
, &stack_args_size
, &stack_offset
, &arg_size
,
4446 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
4448 if (offset_rtx
== const0_rtx
)
4449 stack_parm
= gen_rtx_MEM (promoted_mode
, internal_arg_pointer
);
4451 stack_parm
= gen_rtx_MEM (promoted_mode
,
4452 gen_rtx_PLUS (Pmode
,
4453 internal_arg_pointer
,
4456 set_mem_attributes (stack_parm
, parm
, 1);
4459 /* If this parameter was passed both in registers and in the stack,
4460 use the copy on the stack. */
4461 if (MUST_PASS_IN_STACK (promoted_mode
, passed_type
))
4464 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4465 /* If this parm was passed part in regs and part in memory,
4466 pretend it arrived entirely in memory
4467 by pushing the register-part onto the stack.
4469 In the special case of a DImode or DFmode that is split,
4470 we could put it together in a pseudoreg directly,
4471 but for now that's not worth bothering with. */
4475 int nregs
= FUNCTION_ARG_PARTIAL_NREGS (args_so_far
, promoted_mode
,
4476 passed_type
, named_arg
);
4480 #if defined (REG_PARM_STACK_SPACE) && !defined (MAYBE_REG_PARM_STACK_SPACE)
4481 /* When REG_PARM_STACK_SPACE is nonzero, stack space for
4482 split parameters was allocated by our caller, so we
4483 won't be pushing it in the prolog. */
4484 if (REG_PARM_STACK_SPACE (fndecl
) == 0)
4486 current_function_pretend_args_size
4487 = (((nregs
* UNITS_PER_WORD
) + (PARM_BOUNDARY
/ BITS_PER_UNIT
) - 1)
4488 / (PARM_BOUNDARY
/ BITS_PER_UNIT
)
4489 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4491 /* Handle calls that pass values in multiple non-contiguous
4492 locations. The Irix 6 ABI has examples of this. */
4493 if (GET_CODE (entry_parm
) == PARALLEL
)
4494 emit_group_store (validize_mem (stack_parm
), entry_parm
,
4495 int_size_in_bytes (TREE_TYPE (parm
)));
4498 move_block_from_reg (REGNO (entry_parm
),
4499 validize_mem (stack_parm
), nregs
,
4500 int_size_in_bytes (TREE_TYPE (parm
)));
4502 entry_parm
= stack_parm
;
4507 /* If we didn't decide this parm came in a register,
4508 by default it came on the stack. */
4509 if (entry_parm
== 0)
4510 entry_parm
= stack_parm
;
4512 /* Record permanently how this parm was passed. */
4513 DECL_INCOMING_RTL (parm
) = entry_parm
;
4515 /* If there is actually space on the stack for this parm,
4516 count it in stack_args_size; otherwise set stack_parm to 0
4517 to indicate there is no preallocated stack slot for the parm. */
4519 if (entry_parm
== stack_parm
4520 || (GET_CODE (entry_parm
) == PARALLEL
4521 && XEXP (XVECEXP (entry_parm
, 0, 0), 0) == NULL_RTX
)
4522 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4523 /* On some machines, even if a parm value arrives in a register
4524 there is still an (uninitialized) stack slot allocated for it.
4526 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4527 whether this parameter already has a stack slot allocated,
4528 because an arg block exists only if current_function_args_size
4529 is larger than some threshold, and we haven't calculated that
4530 yet. So, for now, we just assume that stack slots never exist
4532 || REG_PARM_STACK_SPACE (fndecl
) > 0
4536 stack_args_size
.constant
+= arg_size
.constant
;
4538 ADD_PARM_SIZE (stack_args_size
, arg_size
.var
);
4541 /* No stack slot was pushed for this parm. */
4544 /* Update info on where next arg arrives in registers. */
4546 FUNCTION_ARG_ADVANCE (args_so_far
, promoted_mode
,
4547 passed_type
, named_arg
);
4549 /* If we can't trust the parm stack slot to be aligned enough
4550 for its ultimate type, don't use that slot after entry.
4551 We'll make another stack slot, if we need one. */
4553 unsigned int thisparm_boundary
4554 = FUNCTION_ARG_BOUNDARY (promoted_mode
, passed_type
);
4556 if (GET_MODE_ALIGNMENT (nominal_mode
) > thisparm_boundary
)
4560 /* If parm was passed in memory, and we need to convert it on entry,
4561 don't store it back in that same slot. */
4563 && nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
)
4566 /* When an argument is passed in multiple locations, we can't
4567 make use of this information, but we can save some copying if
4568 the whole argument is passed in a single register. */
4569 if (GET_CODE (entry_parm
) == PARALLEL
4570 && nominal_mode
!= BLKmode
&& passed_mode
!= BLKmode
)
4572 int i
, len
= XVECLEN (entry_parm
, 0);
4574 for (i
= 0; i
< len
; i
++)
4575 if (XEXP (XVECEXP (entry_parm
, 0, i
), 0) != NULL_RTX
4576 && GET_CODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0)) == REG
4577 && (GET_MODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
4579 && INTVAL (XEXP (XVECEXP (entry_parm
, 0, i
), 1)) == 0)
4581 entry_parm
= XEXP (XVECEXP (entry_parm
, 0, i
), 0);
4582 DECL_INCOMING_RTL (parm
) = entry_parm
;
4587 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4588 in the mode in which it arrives.
4589 STACK_PARM is an RTX for a stack slot where the parameter can live
4590 during the function (in case we want to put it there).
4591 STACK_PARM is 0 if no stack slot was pushed for it.
4593 Now output code if necessary to convert ENTRY_PARM to
4594 the type in which this function declares it,
4595 and store that result in an appropriate place,
4596 which may be a pseudo reg, may be STACK_PARM,
4597 or may be a local stack slot if STACK_PARM is 0.
4599 Set DECL_RTL to that place. */
4601 if (nominal_mode
== BLKmode
|| GET_CODE (entry_parm
) == PARALLEL
)
4603 /* If a BLKmode arrives in registers, copy it to a stack slot.
4604 Handle calls that pass values in multiple non-contiguous
4605 locations. The Irix 6 ABI has examples of this. */
4606 if (GET_CODE (entry_parm
) == REG
4607 || GET_CODE (entry_parm
) == PARALLEL
)
4610 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm
)),
4613 /* Note that we will be storing an integral number of words.
4614 So we have to be careful to ensure that we allocate an
4615 integral number of words. We do this below in the
4616 assign_stack_local if space was not allocated in the argument
4617 list. If it was, this will not work if PARM_BOUNDARY is not
4618 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4619 if it becomes a problem. */
4621 if (stack_parm
== 0)
4624 = assign_stack_local (GET_MODE (entry_parm
),
4626 set_mem_attributes (stack_parm
, parm
, 1);
4629 else if (PARM_BOUNDARY
% BITS_PER_WORD
!= 0)
4632 /* Handle calls that pass values in multiple non-contiguous
4633 locations. The Irix 6 ABI has examples of this. */
4634 if (GET_CODE (entry_parm
) == PARALLEL
)
4635 emit_group_store (validize_mem (stack_parm
), entry_parm
,
4636 int_size_in_bytes (TREE_TYPE (parm
)));
4638 move_block_from_reg (REGNO (entry_parm
),
4639 validize_mem (stack_parm
),
4640 size_stored
/ UNITS_PER_WORD
,
4641 int_size_in_bytes (TREE_TYPE (parm
)));
4643 SET_DECL_RTL (parm
, stack_parm
);
4645 else if (! ((! optimize
4646 && ! DECL_REGISTER (parm
))
4647 || TREE_SIDE_EFFECTS (parm
)
4648 /* If -ffloat-store specified, don't put explicit
4649 float variables into registers. */
4650 || (flag_float_store
4651 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))
4652 /* Always assign pseudo to structure return or item passed
4653 by invisible reference. */
4654 || passed_pointer
|| parm
== function_result_decl
)
4656 /* Store the parm in a pseudoregister during the function, but we
4657 may need to do it in a wider mode. */
4660 unsigned int regno
, regnoi
= 0, regnor
= 0;
4662 unsignedp
= TREE_UNSIGNED (TREE_TYPE (parm
));
4664 promoted_nominal_mode
4665 = promote_mode (TREE_TYPE (parm
), nominal_mode
, &unsignedp
, 0);
4667 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
4668 mark_user_reg (parmreg
);
4670 /* If this was an item that we received a pointer to, set DECL_RTL
4674 rtx x
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type
)),
4676 set_mem_attributes (x
, parm
, 1);
4677 SET_DECL_RTL (parm
, x
);
4681 SET_DECL_RTL (parm
, parmreg
);
4682 maybe_set_unchanging (DECL_RTL (parm
), parm
);
4685 /* Copy the value into the register. */
4686 if (nominal_mode
!= passed_mode
4687 || promoted_nominal_mode
!= promoted_mode
)
4690 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4691 mode, by the caller. We now have to convert it to
4692 NOMINAL_MODE, if different. However, PARMREG may be in
4693 a different mode than NOMINAL_MODE if it is being stored
4696 If ENTRY_PARM is a hard register, it might be in a register
4697 not valid for operating in its mode (e.g., an odd-numbered
4698 register for a DFmode). In that case, moves are the only
4699 thing valid, so we can't do a convert from there. This
4700 occurs when the calling sequence allow such misaligned
4703 In addition, the conversion may involve a call, which could
4704 clobber parameters which haven't been copied to pseudo
4705 registers yet. Therefore, we must first copy the parm to
4706 a pseudo reg here, and save the conversion until after all
4707 parameters have been moved. */
4709 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4711 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4713 push_to_sequence (conversion_insns
);
4714 tempreg
= convert_to_mode (nominal_mode
, tempreg
, unsignedp
);
4716 if (GET_CODE (tempreg
) == SUBREG
4717 && GET_MODE (tempreg
) == nominal_mode
4718 && GET_CODE (SUBREG_REG (tempreg
)) == REG
4719 && nominal_mode
== passed_mode
4720 && GET_MODE (SUBREG_REG (tempreg
)) == GET_MODE (entry_parm
)
4721 && GET_MODE_SIZE (GET_MODE (tempreg
))
4722 < GET_MODE_SIZE (GET_MODE (entry_parm
)))
4724 /* The argument is already sign/zero extended, so note it
4726 SUBREG_PROMOTED_VAR_P (tempreg
) = 1;
4727 SUBREG_PROMOTED_UNSIGNED_SET (tempreg
, unsignedp
);
4730 /* TREE_USED gets set erroneously during expand_assignment. */
4731 save_tree_used
= TREE_USED (parm
);
4732 expand_assignment (parm
,
4733 make_tree (nominal_type
, tempreg
), 0, 0);
4734 TREE_USED (parm
) = save_tree_used
;
4735 conversion_insns
= get_insns ();
4740 emit_move_insn (parmreg
, validize_mem (entry_parm
));
4742 /* If we were passed a pointer but the actual value
4743 can safely live in a register, put it in one. */
4744 if (passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
4745 /* If by-reference argument was promoted, demote it. */
4746 && (TYPE_MODE (TREE_TYPE (parm
)) != GET_MODE (DECL_RTL (parm
))
4748 && ! DECL_REGISTER (parm
))
4749 || TREE_SIDE_EFFECTS (parm
)
4750 /* If -ffloat-store specified, don't put explicit
4751 float variables into registers. */
4752 || (flag_float_store
4753 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))))
4755 /* We can't use nominal_mode, because it will have been set to
4756 Pmode above. We must use the actual mode of the parm. */
4757 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
4758 mark_user_reg (parmreg
);
4759 if (GET_MODE (parmreg
) != GET_MODE (DECL_RTL (parm
)))
4761 rtx tempreg
= gen_reg_rtx (GET_MODE (DECL_RTL (parm
)));
4762 int unsigned_p
= TREE_UNSIGNED (TREE_TYPE (parm
));
4763 push_to_sequence (conversion_insns
);
4764 emit_move_insn (tempreg
, DECL_RTL (parm
));
4766 convert_to_mode (GET_MODE (parmreg
),
4769 emit_move_insn (parmreg
, DECL_RTL (parm
));
4770 conversion_insns
= get_insns();
4775 emit_move_insn (parmreg
, DECL_RTL (parm
));
4776 SET_DECL_RTL (parm
, parmreg
);
4777 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4781 #ifdef FUNCTION_ARG_CALLEE_COPIES
4782 /* If we are passed an arg by reference and it is our responsibility
4783 to make a copy, do it now.
4784 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4785 original argument, so we must recreate them in the call to
4786 FUNCTION_ARG_CALLEE_COPIES. */
4787 /* ??? Later add code to handle the case that if the argument isn't
4788 modified, don't do the copy. */
4790 else if (passed_pointer
4791 && FUNCTION_ARG_CALLEE_COPIES (args_so_far
,
4792 TYPE_MODE (DECL_ARG_TYPE (parm
)),
4793 DECL_ARG_TYPE (parm
),
4795 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm
)))
4798 tree type
= DECL_ARG_TYPE (parm
);
4800 /* This sequence may involve a library call perhaps clobbering
4801 registers that haven't been copied to pseudos yet. */
4803 push_to_sequence (conversion_insns
);
4805 if (!COMPLETE_TYPE_P (type
)
4806 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4807 /* This is a variable sized object. */
4808 copy
= gen_rtx_MEM (BLKmode
,
4809 allocate_dynamic_stack_space
4810 (expr_size (parm
), NULL_RTX
,
4811 TYPE_ALIGN (type
)));
4813 copy
= assign_stack_temp (TYPE_MODE (type
),
4814 int_size_in_bytes (type
), 1);
4815 set_mem_attributes (copy
, parm
, 1);
4817 store_expr (parm
, copy
, 0);
4818 emit_move_insn (parmreg
, XEXP (copy
, 0));
4819 conversion_insns
= get_insns ();
4823 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4825 /* In any case, record the parm's desired stack location
4826 in case we later discover it must live in the stack.
4828 If it is a COMPLEX value, store the stack location for both
4831 if (GET_CODE (parmreg
) == CONCAT
)
4832 regno
= MAX (REGNO (XEXP (parmreg
, 0)), REGNO (XEXP (parmreg
, 1)));
4834 regno
= REGNO (parmreg
);
4836 if (regno
>= max_parm_reg
)
4839 int old_max_parm_reg
= max_parm_reg
;
4841 /* It's slow to expand this one register at a time,
4842 but it's also rare and we need max_parm_reg to be
4843 precisely correct. */
4844 max_parm_reg
= regno
+ 1;
4845 new = (rtx
*) ggc_realloc (parm_reg_stack_loc
,
4846 max_parm_reg
* sizeof (rtx
));
4847 memset ((char *) (new + old_max_parm_reg
), 0,
4848 (max_parm_reg
- old_max_parm_reg
) * sizeof (rtx
));
4849 parm_reg_stack_loc
= new;
4852 if (GET_CODE (parmreg
) == CONCAT
)
4854 enum machine_mode submode
= GET_MODE (XEXP (parmreg
, 0));
4856 regnor
= REGNO (gen_realpart (submode
, parmreg
));
4857 regnoi
= REGNO (gen_imagpart (submode
, parmreg
));
4859 if (stack_parm
!= 0)
4861 parm_reg_stack_loc
[regnor
]
4862 = gen_realpart (submode
, stack_parm
);
4863 parm_reg_stack_loc
[regnoi
]
4864 = gen_imagpart (submode
, stack_parm
);
4868 parm_reg_stack_loc
[regnor
] = 0;
4869 parm_reg_stack_loc
[regnoi
] = 0;
4873 parm_reg_stack_loc
[REGNO (parmreg
)] = stack_parm
;
4875 /* Mark the register as eliminable if we did no conversion
4876 and it was copied from memory at a fixed offset,
4877 and the arg pointer was not copied to a pseudo-reg.
4878 If the arg pointer is a pseudo reg or the offset formed
4879 an invalid address, such memory-equivalences
4880 as we make here would screw up life analysis for it. */
4881 if (nominal_mode
== passed_mode
4884 && GET_CODE (stack_parm
) == MEM
4885 && stack_offset
.var
== 0
4886 && reg_mentioned_p (virtual_incoming_args_rtx
,
4887 XEXP (stack_parm
, 0)))
4889 rtx linsn
= get_last_insn ();
4892 /* Mark complex types separately. */
4893 if (GET_CODE (parmreg
) == CONCAT
)
4894 /* Scan backwards for the set of the real and
4896 for (sinsn
= linsn
; sinsn
!= 0;
4897 sinsn
= prev_nonnote_insn (sinsn
))
4899 set
= single_set (sinsn
);
4901 && SET_DEST (set
) == regno_reg_rtx
[regnoi
])
4903 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4904 parm_reg_stack_loc
[regnoi
],
4907 && SET_DEST (set
) == regno_reg_rtx
[regnor
])
4909 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4910 parm_reg_stack_loc
[regnor
],
4913 else if ((set
= single_set (linsn
)) != 0
4914 && SET_DEST (set
) == parmreg
)
4916 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4917 stack_parm
, REG_NOTES (linsn
));
4920 /* For pointer data type, suggest pointer register. */
4921 if (POINTER_TYPE_P (TREE_TYPE (parm
)))
4922 mark_reg_pointer (parmreg
,
4923 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
4925 /* If something wants our address, try to use ADDRESSOF. */
4926 if (TREE_ADDRESSABLE (parm
))
4928 /* If we end up putting something into the stack,
4929 fixup_var_refs_insns will need to make a pass over
4930 all the instructions. It looks through the pending
4931 sequences -- but it can't see the ones in the
4932 CONVERSION_INSNS, if they're not on the sequence
4933 stack. So, we go back to that sequence, just so that
4934 the fixups will happen. */
4935 push_to_sequence (conversion_insns
);
4936 put_var_into_stack (parm
);
4937 conversion_insns
= get_insns ();
4943 /* Value must be stored in the stack slot STACK_PARM
4944 during function execution. */
4946 if (promoted_mode
!= nominal_mode
)
4948 /* Conversion is required. */
4949 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4951 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4953 push_to_sequence (conversion_insns
);
4954 entry_parm
= convert_to_mode (nominal_mode
, tempreg
,
4955 TREE_UNSIGNED (TREE_TYPE (parm
)));
4957 /* ??? This may need a big-endian conversion on sparc64. */
4958 stack_parm
= adjust_address (stack_parm
, nominal_mode
, 0);
4960 conversion_insns
= get_insns ();
4965 if (entry_parm
!= stack_parm
)
4967 if (stack_parm
== 0)
4970 = assign_stack_local (GET_MODE (entry_parm
),
4971 GET_MODE_SIZE (GET_MODE (entry_parm
)), 0);
4972 set_mem_attributes (stack_parm
, parm
, 1);
4975 if (promoted_mode
!= nominal_mode
)
4977 push_to_sequence (conversion_insns
);
4978 emit_move_insn (validize_mem (stack_parm
),
4979 validize_mem (entry_parm
));
4980 conversion_insns
= get_insns ();
4984 emit_move_insn (validize_mem (stack_parm
),
4985 validize_mem (entry_parm
));
4988 SET_DECL_RTL (parm
, stack_parm
);
4991 /* If this "parameter" was the place where we are receiving the
4992 function's incoming structure pointer, set up the result. */
4993 if (parm
== function_result_decl
)
4995 tree result
= DECL_RESULT (fndecl
);
4996 rtx addr
= DECL_RTL (parm
);
4999 #ifdef POINTERS_EXTEND_UNSIGNED
5000 if (GET_MODE (addr
) != Pmode
)
5001 addr
= convert_memory_address (Pmode
, addr
);
5004 x
= gen_rtx_MEM (DECL_MODE (result
), addr
);
5005 set_mem_attributes (x
, result
, 1);
5006 SET_DECL_RTL (result
, x
);
5010 /* Output all parameter conversion instructions (possibly including calls)
5011 now that all parameters have been copied out of hard registers. */
5012 emit_insn (conversion_insns
);
5014 last_parm_insn
= get_last_insn ();
5016 current_function_args_size
= stack_args_size
.constant
;
5018 /* Adjust function incoming argument size for alignment and
5021 #ifdef REG_PARM_STACK_SPACE
5022 #ifndef MAYBE_REG_PARM_STACK_SPACE
5023 current_function_args_size
= MAX (current_function_args_size
,
5024 REG_PARM_STACK_SPACE (fndecl
));
5028 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5030 current_function_args_size
5031 = ((current_function_args_size
+ STACK_BYTES
- 1)
5032 / STACK_BYTES
) * STACK_BYTES
;
5034 #ifdef ARGS_GROW_DOWNWARD
5035 current_function_arg_offset_rtx
5036 = (stack_args_size
.var
== 0 ? GEN_INT (-stack_args_size
.constant
)
5037 : expand_expr (size_diffop (stack_args_size
.var
,
5038 size_int (-stack_args_size
.constant
)),
5039 NULL_RTX
, VOIDmode
, 0));
5041 current_function_arg_offset_rtx
= ARGS_SIZE_RTX (stack_args_size
);
5044 /* See how many bytes, if any, of its args a function should try to pop
5047 current_function_pops_args
= RETURN_POPS_ARGS (fndecl
, TREE_TYPE (fndecl
),
5048 current_function_args_size
);
5050 /* For stdarg.h function, save info about
5051 regs and stack space used by the named args. */
5053 current_function_args_info
= args_so_far
;
5055 /* Set the rtx used for the function return value. Put this in its
5056 own variable so any optimizers that need this information don't have
5057 to include tree.h. Do this here so it gets done when an inlined
5058 function gets output. */
5060 current_function_return_rtx
5061 = (DECL_RTL_SET_P (DECL_RESULT (fndecl
))
5062 ? DECL_RTL (DECL_RESULT (fndecl
)) : NULL_RTX
);
5064 /* If scalar return value was computed in a pseudo-reg, or was a named
5065 return value that got dumped to the stack, copy that to the hard
5067 if (DECL_RTL_SET_P (DECL_RESULT (fndecl
)))
5069 tree decl_result
= DECL_RESULT (fndecl
);
5070 rtx decl_rtl
= DECL_RTL (decl_result
);
5072 if (REG_P (decl_rtl
)
5073 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
5074 : DECL_REGISTER (decl_result
))
5078 #ifdef FUNCTION_OUTGOING_VALUE
5079 real_decl_rtl
= FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result
),
5082 real_decl_rtl
= FUNCTION_VALUE (TREE_TYPE (decl_result
),
5085 REG_FUNCTION_VALUE_P (real_decl_rtl
) = 1;
5086 /* The delay slot scheduler assumes that current_function_return_rtx
5087 holds the hard register containing the return value, not a
5088 temporary pseudo. */
5089 current_function_return_rtx
= real_decl_rtl
;
5094 /* Indicate whether REGNO is an incoming argument to the current function
5095 that was promoted to a wider mode. If so, return the RTX for the
5096 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5097 that REGNO is promoted from and whether the promotion was signed or
5100 #ifdef PROMOTE_FUNCTION_ARGS
5103 promoted_input_arg (regno
, pmode
, punsignedp
)
5105 enum machine_mode
*pmode
;
5110 for (arg
= DECL_ARGUMENTS (current_function_decl
); arg
;
5111 arg
= TREE_CHAIN (arg
))
5112 if (GET_CODE (DECL_INCOMING_RTL (arg
)) == REG
5113 && REGNO (DECL_INCOMING_RTL (arg
)) == regno
5114 && TYPE_MODE (DECL_ARG_TYPE (arg
)) == TYPE_MODE (TREE_TYPE (arg
)))
5116 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (arg
));
5117 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (arg
));
5119 mode
= promote_mode (TREE_TYPE (arg
), mode
, &unsignedp
, 1);
5120 if (mode
== GET_MODE (DECL_INCOMING_RTL (arg
))
5121 && mode
!= DECL_MODE (arg
))
5123 *pmode
= DECL_MODE (arg
);
5124 *punsignedp
= unsignedp
;
5125 return DECL_INCOMING_RTL (arg
);
5134 /* Compute the size and offset from the start of the stacked arguments for a
5135 parm passed in mode PASSED_MODE and with type TYPE.
5137 INITIAL_OFFSET_PTR points to the current offset into the stacked
5140 The starting offset and size for this parm are returned in *OFFSET_PTR
5141 and *ARG_SIZE_PTR, respectively.
5143 IN_REGS is nonzero if the argument will be passed in registers. It will
5144 never be set if REG_PARM_STACK_SPACE is not defined.
5146 FNDECL is the function in which the argument was defined.
5148 There are two types of rounding that are done. The first, controlled by
5149 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5150 list to be aligned to the specific boundary (in bits). This rounding
5151 affects the initial and starting offsets, but not the argument size.
5153 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5154 optionally rounds the size of the parm to PARM_BOUNDARY. The
5155 initial offset is not affected by this rounding, while the size always
5156 is and the starting offset may be. */
5158 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5159 initial_offset_ptr is positive because locate_and_pad_parm's
5160 callers pass in the total size of args so far as
5161 initial_offset_ptr. arg_size_ptr is always positive. */
5164 locate_and_pad_parm (passed_mode
, type
, in_regs
, fndecl
,
5165 initial_offset_ptr
, offset_ptr
, arg_size_ptr
,
5167 enum machine_mode passed_mode
;
5169 int in_regs ATTRIBUTE_UNUSED
;
5170 tree fndecl ATTRIBUTE_UNUSED
;
5171 struct args_size
*initial_offset_ptr
;
5172 struct args_size
*offset_ptr
;
5173 struct args_size
*arg_size_ptr
;
5174 struct args_size
*alignment_pad
;
5178 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
5179 enum direction where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
5180 int boundary
= FUNCTION_ARG_BOUNDARY (passed_mode
, type
);
5181 #ifdef ARGS_GROW_DOWNWARD
5185 #ifdef REG_PARM_STACK_SPACE
5186 /* If we have found a stack parm before we reach the end of the
5187 area reserved for registers, skip that area. */
5190 int reg_parm_stack_space
= 0;
5192 #ifdef MAYBE_REG_PARM_STACK_SPACE
5193 reg_parm_stack_space
= MAYBE_REG_PARM_STACK_SPACE
;
5195 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
5197 if (reg_parm_stack_space
> 0)
5199 if (initial_offset_ptr
->var
)
5201 initial_offset_ptr
->var
5202 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
5203 ssize_int (reg_parm_stack_space
));
5204 initial_offset_ptr
->constant
= 0;
5206 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
5207 initial_offset_ptr
->constant
= reg_parm_stack_space
;
5210 #endif /* REG_PARM_STACK_SPACE */
5212 arg_size_ptr
->var
= 0;
5213 arg_size_ptr
->constant
= 0;
5214 alignment_pad
->var
= 0;
5215 alignment_pad
->constant
= 0;
5217 #ifdef ARGS_GROW_DOWNWARD
5218 if (initial_offset_ptr
->var
)
5220 offset_ptr
->constant
= 0;
5221 offset_ptr
->var
= size_binop (MINUS_EXPR
, ssize_int (0),
5222 initial_offset_ptr
->var
);
5226 offset_ptr
->constant
= -initial_offset_ptr
->constant
;
5227 offset_ptr
->var
= 0;
5230 if (where_pad
!= none
5231 && (!host_integerp (sizetree
, 1)
5232 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % PARM_BOUNDARY
))
5233 s2
= round_up (s2
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5234 SUB_PARM_SIZE (*offset_ptr
, s2
);
5237 #ifdef REG_PARM_STACK_SPACE
5238 || REG_PARM_STACK_SPACE (fndecl
) > 0
5241 pad_to_arg_alignment (offset_ptr
, boundary
, alignment_pad
);
5243 if (initial_offset_ptr
->var
)
5244 arg_size_ptr
->var
= size_binop (MINUS_EXPR
,
5245 size_binop (MINUS_EXPR
,
5247 initial_offset_ptr
->var
),
5251 arg_size_ptr
->constant
= (-initial_offset_ptr
->constant
5252 - offset_ptr
->constant
);
5254 /* Pad_below needs the pre-rounded size to know how much to pad below.
5255 We only pad parameters which are not in registers as they have their
5256 padding done elsewhere. */
5257 if (where_pad
== downward
5259 pad_below (offset_ptr
, passed_mode
, sizetree
);
5261 #else /* !ARGS_GROW_DOWNWARD */
5263 #ifdef REG_PARM_STACK_SPACE
5264 || REG_PARM_STACK_SPACE (fndecl
) > 0
5267 pad_to_arg_alignment (initial_offset_ptr
, boundary
, alignment_pad
);
5268 *offset_ptr
= *initial_offset_ptr
;
5270 #ifdef PUSH_ROUNDING
5271 if (passed_mode
!= BLKmode
)
5272 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
5275 /* Pad_below needs the pre-rounded size to know how much to pad below
5276 so this must be done before rounding up. */
5277 if (where_pad
== downward
5278 /* However, BLKmode args passed in regs have their padding done elsewhere.
5279 The stack slot must be able to hold the entire register. */
5280 && !(in_regs
&& passed_mode
== BLKmode
))
5281 pad_below (offset_ptr
, passed_mode
, sizetree
);
5283 if (where_pad
!= none
5284 && (!host_integerp (sizetree
, 1)
5285 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % PARM_BOUNDARY
))
5286 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5288 ADD_PARM_SIZE (*arg_size_ptr
, sizetree
);
5289 #endif /* ARGS_GROW_DOWNWARD */
5292 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5293 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5296 pad_to_arg_alignment (offset_ptr
, boundary
, alignment_pad
)
5297 struct args_size
*offset_ptr
;
5299 struct args_size
*alignment_pad
;
5301 tree save_var
= NULL_TREE
;
5302 HOST_WIDE_INT save_constant
= 0;
5304 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
5306 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5308 save_var
= offset_ptr
->var
;
5309 save_constant
= offset_ptr
->constant
;
5312 alignment_pad
->var
= NULL_TREE
;
5313 alignment_pad
->constant
= 0;
5315 if (boundary
> BITS_PER_UNIT
)
5317 if (offset_ptr
->var
)
5320 #ifdef ARGS_GROW_DOWNWARD
5325 (ARGS_SIZE_TREE (*offset_ptr
),
5326 boundary
/ BITS_PER_UNIT
);
5327 offset_ptr
->constant
= 0; /*?*/
5328 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5329 alignment_pad
->var
= size_binop (MINUS_EXPR
, offset_ptr
->var
,
5334 offset_ptr
->constant
=
5335 #ifdef ARGS_GROW_DOWNWARD
5336 FLOOR_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
5338 CEIL_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
5340 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5341 alignment_pad
->constant
= offset_ptr
->constant
- save_constant
;
5347 pad_below (offset_ptr
, passed_mode
, sizetree
)
5348 struct args_size
*offset_ptr
;
5349 enum machine_mode passed_mode
;
5352 if (passed_mode
!= BLKmode
)
5354 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
5355 offset_ptr
->constant
5356 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
5357 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
5358 - GET_MODE_SIZE (passed_mode
));
5362 if (TREE_CODE (sizetree
) != INTEGER_CST
5363 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
5365 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5366 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5368 ADD_PARM_SIZE (*offset_ptr
, s2
);
5369 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
5374 /* Walk the tree of blocks describing the binding levels within a function
5375 and warn about uninitialized variables.
5376 This is done after calling flow_analysis and before global_alloc
5377 clobbers the pseudo-regs to hard regs. */
5380 uninitialized_vars_warning (block
)
5384 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
5386 if (warn_uninitialized
5387 && TREE_CODE (decl
) == VAR_DECL
5388 /* These warnings are unreliable for and aggregates
5389 because assigning the fields one by one can fail to convince
5390 flow.c that the entire aggregate was initialized.
5391 Unions are troublesome because members may be shorter. */
5392 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl
))
5393 && DECL_RTL (decl
) != 0
5394 && GET_CODE (DECL_RTL (decl
)) == REG
5395 /* Global optimizations can make it difficult to determine if a
5396 particular variable has been initialized. However, a VAR_DECL
5397 with a nonzero DECL_INITIAL had an initializer, so do not
5398 claim it is potentially uninitialized.
5400 We do not care about the actual value in DECL_INITIAL, so we do
5401 not worry that it may be a dangling pointer. */
5402 && DECL_INITIAL (decl
) == NULL_TREE
5403 && regno_uninitialized (REGNO (DECL_RTL (decl
))))
5404 warning_with_decl (decl
,
5405 "`%s' might be used uninitialized in this function");
5407 && TREE_CODE (decl
) == VAR_DECL
5408 && DECL_RTL (decl
) != 0
5409 && GET_CODE (DECL_RTL (decl
)) == REG
5410 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
5411 warning_with_decl (decl
,
5412 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5414 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
5415 uninitialized_vars_warning (sub
);
5418 /* Do the appropriate part of uninitialized_vars_warning
5419 but for arguments instead of local variables. */
5422 setjmp_args_warning ()
5425 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5426 decl
; decl
= TREE_CHAIN (decl
))
5427 if (DECL_RTL (decl
) != 0
5428 && GET_CODE (DECL_RTL (decl
)) == REG
5429 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
5430 warning_with_decl (decl
,
5431 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5434 /* If this function call setjmp, put all vars into the stack
5435 unless they were declared `register'. */
5438 setjmp_protect (block
)
5442 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
5443 if ((TREE_CODE (decl
) == VAR_DECL
5444 || TREE_CODE (decl
) == PARM_DECL
)
5445 && DECL_RTL (decl
) != 0
5446 && (GET_CODE (DECL_RTL (decl
)) == REG
5447 || (GET_CODE (DECL_RTL (decl
)) == MEM
5448 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
5449 /* If this variable came from an inline function, it must be
5450 that its life doesn't overlap the setjmp. If there was a
5451 setjmp in the function, it would already be in memory. We
5452 must exclude such variable because their DECL_RTL might be
5453 set to strange things such as virtual_stack_vars_rtx. */
5454 && ! DECL_FROM_INLINE (decl
)
5456 #ifdef NON_SAVING_SETJMP
5457 /* If longjmp doesn't restore the registers,
5458 don't put anything in them. */
5462 ! DECL_REGISTER (decl
)))
5463 put_var_into_stack (decl
);
5464 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
5465 setjmp_protect (sub
);
5468 /* Like the previous function, but for args instead of local variables. */
5471 setjmp_protect_args ()
5474 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5475 decl
; decl
= TREE_CHAIN (decl
))
5476 if ((TREE_CODE (decl
) == VAR_DECL
5477 || TREE_CODE (decl
) == PARM_DECL
)
5478 && DECL_RTL (decl
) != 0
5479 && (GET_CODE (DECL_RTL (decl
)) == REG
5480 || (GET_CODE (DECL_RTL (decl
)) == MEM
5481 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
5483 /* If longjmp doesn't restore the registers,
5484 don't put anything in them. */
5485 #ifdef NON_SAVING_SETJMP
5489 ! DECL_REGISTER (decl
)))
5490 put_var_into_stack (decl
);
5493 /* Return the context-pointer register corresponding to DECL,
5494 or 0 if it does not need one. */
5497 lookup_static_chain (decl
)
5500 tree context
= decl_function_context (decl
);
5504 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_NO_STATIC_CHAIN (decl
)))
5507 /* We treat inline_function_decl as an alias for the current function
5508 because that is the inline function whose vars, types, etc.
5509 are being merged into the current function.
5510 See expand_inline_function. */
5511 if (context
== current_function_decl
|| context
== inline_function_decl
)
5512 return virtual_stack_vars_rtx
;
5514 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
5515 if (TREE_PURPOSE (link
) == context
)
5516 return RTL_EXPR_RTL (TREE_VALUE (link
));
5521 /* Convert a stack slot address ADDR for variable VAR
5522 (from a containing function)
5523 into an address valid in this function (using a static chain). */
5526 fix_lexical_addr (addr
, var
)
5531 HOST_WIDE_INT displacement
;
5532 tree context
= decl_function_context (var
);
5533 struct function
*fp
;
5536 /* If this is the present function, we need not do anything. */
5537 if (context
== current_function_decl
|| context
== inline_function_decl
)
5540 fp
= find_function_data (context
);
5542 if (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == MEM
)
5543 addr
= XEXP (XEXP (addr
, 0), 0);
5545 /* Decode given address as base reg plus displacement. */
5546 if (GET_CODE (addr
) == REG
)
5547 basereg
= addr
, displacement
= 0;
5548 else if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
5549 basereg
= XEXP (addr
, 0), displacement
= INTVAL (XEXP (addr
, 1));
5553 /* We accept vars reached via the containing function's
5554 incoming arg pointer and via its stack variables pointer. */
5555 if (basereg
== fp
->internal_arg_pointer
)
5557 /* If reached via arg pointer, get the arg pointer value
5558 out of that function's stack frame.
5560 There are two cases: If a separate ap is needed, allocate a
5561 slot in the outer function for it and dereference it that way.
5562 This is correct even if the real ap is actually a pseudo.
5563 Otherwise, just adjust the offset from the frame pointer to
5566 #ifdef NEED_SEPARATE_AP
5569 addr
= get_arg_pointer_save_area (fp
);
5570 addr
= fix_lexical_addr (XEXP (addr
, 0), var
);
5571 addr
= memory_address (Pmode
, addr
);
5573 base
= gen_rtx_MEM (Pmode
, addr
);
5574 set_mem_alias_set (base
, get_frame_alias_set ());
5575 base
= copy_to_reg (base
);
5577 displacement
+= (FIRST_PARM_OFFSET (context
) - STARTING_FRAME_OFFSET
);
5578 base
= lookup_static_chain (var
);
5582 else if (basereg
== virtual_stack_vars_rtx
)
5584 /* This is the same code as lookup_static_chain, duplicated here to
5585 avoid an extra call to decl_function_context. */
5588 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
5589 if (TREE_PURPOSE (link
) == context
)
5591 base
= RTL_EXPR_RTL (TREE_VALUE (link
));
5599 /* Use same offset, relative to appropriate static chain or argument
5601 return plus_constant (base
, displacement
);
5604 /* Return the address of the trampoline for entering nested fn FUNCTION.
5605 If necessary, allocate a trampoline (in the stack frame)
5606 and emit rtl to initialize its contents (at entry to this function). */
5609 trampoline_address (function
)
5615 struct function
*fp
;
5618 /* Find an existing trampoline and return it. */
5619 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
5620 if (TREE_PURPOSE (link
) == function
)
5622 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0));
5624 for (fp
= outer_function_chain
; fp
; fp
= fp
->outer
)
5625 for (link
= fp
->x_trampoline_list
; link
; link
= TREE_CHAIN (link
))
5626 if (TREE_PURPOSE (link
) == function
)
5628 tramp
= fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0),
5630 return adjust_trampoline_addr (tramp
);
5633 /* None exists; we must make one. */
5635 /* Find the `struct function' for the function containing FUNCTION. */
5637 fn_context
= decl_function_context (function
);
5638 if (fn_context
!= current_function_decl
5639 && fn_context
!= inline_function_decl
)
5640 fp
= find_function_data (fn_context
);
5642 /* Allocate run-time space for this trampoline
5643 (usually in the defining function's stack frame). */
5644 #ifdef ALLOCATE_TRAMPOLINE
5645 tramp
= ALLOCATE_TRAMPOLINE (fp
);
5647 /* If rounding needed, allocate extra space
5648 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5649 #define TRAMPOLINE_REAL_SIZE \
5650 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5651 tramp
= assign_stack_local_1 (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0,
5655 /* Record the trampoline for reuse and note it for later initialization
5656 by expand_function_end. */
5659 rtlexp
= make_node (RTL_EXPR
);
5660 RTL_EXPR_RTL (rtlexp
) = tramp
;
5661 fp
->x_trampoline_list
= tree_cons (function
, rtlexp
,
5662 fp
->x_trampoline_list
);
5666 /* Make the RTL_EXPR node temporary, not momentary, so that the
5667 trampoline_list doesn't become garbage. */
5668 rtlexp
= make_node (RTL_EXPR
);
5670 RTL_EXPR_RTL (rtlexp
) = tramp
;
5671 trampoline_list
= tree_cons (function
, rtlexp
, trampoline_list
);
5674 tramp
= fix_lexical_addr (XEXP (tramp
, 0), function
);
5675 return adjust_trampoline_addr (tramp
);
5678 /* Given a trampoline address,
5679 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5682 round_trampoline_addr (tramp
)
5685 /* Round address up to desired boundary. */
5686 rtx temp
= gen_reg_rtx (Pmode
);
5687 rtx addend
= GEN_INT (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
- 1);
5688 rtx mask
= GEN_INT (-TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
5690 temp
= expand_simple_binop (Pmode
, PLUS
, tramp
, addend
,
5691 temp
, 0, OPTAB_LIB_WIDEN
);
5692 tramp
= expand_simple_binop (Pmode
, AND
, temp
, mask
,
5693 temp
, 0, OPTAB_LIB_WIDEN
);
5698 /* Given a trampoline address, round it then apply any
5699 platform-specific adjustments so that the result can be used for a
5703 adjust_trampoline_addr (tramp
)
5706 tramp
= round_trampoline_addr (tramp
);
5707 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5708 TRAMPOLINE_ADJUST_ADDRESS (tramp
);
5713 /* Put all this function's BLOCK nodes including those that are chained
5714 onto the first block into a vector, and return it.
5715 Also store in each NOTE for the beginning or end of a block
5716 the index of that block in the vector.
5717 The arguments are BLOCK, the chain of top-level blocks of the function,
5718 and INSNS, the insn chain of the function. */
5724 tree
*block_vector
, *last_block_vector
;
5726 tree block
= DECL_INITIAL (current_function_decl
);
5731 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5732 depth-first order. */
5733 block_vector
= get_block_vector (block
, &n_blocks
);
5734 block_stack
= (tree
*) xmalloc (n_blocks
* sizeof (tree
));
5736 last_block_vector
= identify_blocks_1 (get_insns (),
5738 block_vector
+ n_blocks
,
5741 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5742 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5743 if (0 && last_block_vector
!= block_vector
+ n_blocks
)
5746 free (block_vector
);
5750 /* Subroutine of identify_blocks. Do the block substitution on the
5751 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5753 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5754 BLOCK_VECTOR is incremented for each block seen. */
5757 identify_blocks_1 (insns
, block_vector
, end_block_vector
, orig_block_stack
)
5760 tree
*end_block_vector
;
5761 tree
*orig_block_stack
;
5764 tree
*block_stack
= orig_block_stack
;
5766 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5768 if (GET_CODE (insn
) == NOTE
)
5770 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5774 /* If there are more block notes than BLOCKs, something
5776 if (block_vector
== end_block_vector
)
5779 b
= *block_vector
++;
5780 NOTE_BLOCK (insn
) = b
;
5783 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5785 /* If there are more NOTE_INSN_BLOCK_ENDs than
5786 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5787 if (block_stack
== orig_block_stack
)
5790 NOTE_BLOCK (insn
) = *--block_stack
;
5793 else if (GET_CODE (insn
) == CALL_INSN
5794 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
5796 rtx cp
= PATTERN (insn
);
5798 block_vector
= identify_blocks_1 (XEXP (cp
, 0), block_vector
,
5799 end_block_vector
, block_stack
);
5801 block_vector
= identify_blocks_1 (XEXP (cp
, 1), block_vector
,
5802 end_block_vector
, block_stack
);
5804 block_vector
= identify_blocks_1 (XEXP (cp
, 2), block_vector
,
5805 end_block_vector
, block_stack
);
5809 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5810 something is badly wrong. */
5811 if (block_stack
!= orig_block_stack
)
5814 return block_vector
;
5817 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5818 and create duplicate blocks. */
5819 /* ??? Need an option to either create block fragments or to create
5820 abstract origin duplicates of a source block. It really depends
5821 on what optimization has been performed. */
5826 tree block
= DECL_INITIAL (current_function_decl
);
5827 varray_type block_stack
;
5829 if (block
== NULL_TREE
)
5832 VARRAY_TREE_INIT (block_stack
, 10, "block_stack");
5834 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5835 reorder_blocks_0 (block
);
5837 /* Prune the old trees away, so that they don't get in the way. */
5838 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
5839 BLOCK_CHAIN (block
) = NULL_TREE
;
5841 /* Recreate the block tree from the note nesting. */
5842 reorder_blocks_1 (get_insns (), block
, &block_stack
);
5843 BLOCK_SUBBLOCKS (block
) = blocks_nreverse (BLOCK_SUBBLOCKS (block
));
5845 /* Remove deleted blocks from the block fragment chains. */
5846 reorder_fix_fragments (block
);
5849 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5852 reorder_blocks_0 (block
)
5857 TREE_ASM_WRITTEN (block
) = 0;
5858 reorder_blocks_0 (BLOCK_SUBBLOCKS (block
));
5859 block
= BLOCK_CHAIN (block
);
5864 reorder_blocks_1 (insns
, current_block
, p_block_stack
)
5867 varray_type
*p_block_stack
;
5871 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5873 if (GET_CODE (insn
) == NOTE
)
5875 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5877 tree block
= NOTE_BLOCK (insn
);
5879 /* If we have seen this block before, that means it now
5880 spans multiple address regions. Create a new fragment. */
5881 if (TREE_ASM_WRITTEN (block
))
5883 tree new_block
= copy_node (block
);
5886 origin
= (BLOCK_FRAGMENT_ORIGIN (block
)
5887 ? BLOCK_FRAGMENT_ORIGIN (block
)
5889 BLOCK_FRAGMENT_ORIGIN (new_block
) = origin
;
5890 BLOCK_FRAGMENT_CHAIN (new_block
)
5891 = BLOCK_FRAGMENT_CHAIN (origin
);
5892 BLOCK_FRAGMENT_CHAIN (origin
) = new_block
;
5894 NOTE_BLOCK (insn
) = new_block
;
5898 BLOCK_SUBBLOCKS (block
) = 0;
5899 TREE_ASM_WRITTEN (block
) = 1;
5900 BLOCK_SUPERCONTEXT (block
) = current_block
;
5901 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
5902 BLOCK_SUBBLOCKS (current_block
) = block
;
5903 current_block
= block
;
5904 VARRAY_PUSH_TREE (*p_block_stack
, block
);
5906 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5908 NOTE_BLOCK (insn
) = VARRAY_TOP_TREE (*p_block_stack
);
5909 VARRAY_POP (*p_block_stack
);
5910 BLOCK_SUBBLOCKS (current_block
)
5911 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
5912 current_block
= BLOCK_SUPERCONTEXT (current_block
);
5915 else if (GET_CODE (insn
) == CALL_INSN
5916 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
5918 rtx cp
= PATTERN (insn
);
5919 reorder_blocks_1 (XEXP (cp
, 0), current_block
, p_block_stack
);
5921 reorder_blocks_1 (XEXP (cp
, 1), current_block
, p_block_stack
);
5923 reorder_blocks_1 (XEXP (cp
, 2), current_block
, p_block_stack
);
5928 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
5929 appears in the block tree, select one of the fragments to become
5930 the new origin block. */
5933 reorder_fix_fragments (block
)
5938 tree dup_origin
= BLOCK_FRAGMENT_ORIGIN (block
);
5939 tree new_origin
= NULL_TREE
;
5943 if (! TREE_ASM_WRITTEN (dup_origin
))
5945 new_origin
= BLOCK_FRAGMENT_CHAIN (dup_origin
);
5947 /* Find the first of the remaining fragments. There must
5948 be at least one -- the current block. */
5949 while (! TREE_ASM_WRITTEN (new_origin
))
5950 new_origin
= BLOCK_FRAGMENT_CHAIN (new_origin
);
5951 BLOCK_FRAGMENT_ORIGIN (new_origin
) = NULL_TREE
;
5954 else if (! dup_origin
)
5957 /* Re-root the rest of the fragments to the new origin. In the
5958 case that DUP_ORIGIN was null, that means BLOCK was the origin
5959 of a chain of fragments and we want to remove those fragments
5960 that didn't make it to the output. */
5963 tree
*pp
= &BLOCK_FRAGMENT_CHAIN (new_origin
);
5968 if (TREE_ASM_WRITTEN (chain
))
5970 BLOCK_FRAGMENT_ORIGIN (chain
) = new_origin
;
5972 pp
= &BLOCK_FRAGMENT_CHAIN (chain
);
5974 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
5979 reorder_fix_fragments (BLOCK_SUBBLOCKS (block
));
5980 block
= BLOCK_CHAIN (block
);
5984 /* Reverse the order of elements in the chain T of blocks,
5985 and return the new head of the chain (old last element). */
5991 tree prev
= 0, decl
, next
;
5992 for (decl
= t
; decl
; decl
= next
)
5994 next
= BLOCK_CHAIN (decl
);
5995 BLOCK_CHAIN (decl
) = prev
;
6001 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6002 non-NULL, list them all into VECTOR, in a depth-first preorder
6003 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6007 all_blocks (block
, vector
)
6015 TREE_ASM_WRITTEN (block
) = 0;
6017 /* Record this block. */
6019 vector
[n_blocks
] = block
;
6023 /* Record the subblocks, and their subblocks... */
6024 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
6025 vector
? vector
+ n_blocks
: 0);
6026 block
= BLOCK_CHAIN (block
);
6032 /* Return a vector containing all the blocks rooted at BLOCK. The
6033 number of elements in the vector is stored in N_BLOCKS_P. The
6034 vector is dynamically allocated; it is the caller's responsibility
6035 to call `free' on the pointer returned. */
6038 get_block_vector (block
, n_blocks_p
)
6044 *n_blocks_p
= all_blocks (block
, NULL
);
6045 block_vector
= (tree
*) xmalloc (*n_blocks_p
* sizeof (tree
));
6046 all_blocks (block
, block_vector
);
6048 return block_vector
;
6051 static int next_block_index
= 2;
6053 /* Set BLOCK_NUMBER for all the blocks in FN. */
6063 /* For SDB and XCOFF debugging output, we start numbering the blocks
6064 from 1 within each function, rather than keeping a running
6066 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6067 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
6068 next_block_index
= 1;
6071 block_vector
= get_block_vector (DECL_INITIAL (fn
), &n_blocks
);
6073 /* The top-level BLOCK isn't numbered at all. */
6074 for (i
= 1; i
< n_blocks
; ++i
)
6075 /* We number the blocks from two. */
6076 BLOCK_NUMBER (block_vector
[i
]) = next_block_index
++;
6078 free (block_vector
);
6083 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6086 debug_find_var_in_block_tree (var
, block
)
6092 for (t
= BLOCK_VARS (block
); t
; t
= TREE_CHAIN (t
))
6096 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= TREE_CHAIN (t
))
6098 tree ret
= debug_find_var_in_block_tree (var
, t
);
6106 /* Allocate a function structure and reset its contents to the defaults. */
6109 prepare_function_start ()
6111 cfun
= (struct function
*) ggc_alloc_cleared (sizeof (struct function
));
6113 init_stmt_for_function ();
6114 init_eh_for_function ();
6116 cse_not_expected
= ! optimize
;
6118 /* Caller save not needed yet. */
6119 caller_save_needed
= 0;
6121 /* No stack slots have been made yet. */
6122 stack_slot_list
= 0;
6124 current_function_has_nonlocal_label
= 0;
6125 current_function_has_nonlocal_goto
= 0;
6127 /* There is no stack slot for handling nonlocal gotos. */
6128 nonlocal_goto_handler_slots
= 0;
6129 nonlocal_goto_stack_level
= 0;
6131 /* No labels have been declared for nonlocal use. */
6132 nonlocal_labels
= 0;
6133 nonlocal_goto_handler_labels
= 0;
6135 /* No function calls so far in this function. */
6136 function_call_count
= 0;
6138 /* No parm regs have been allocated.
6139 (This is important for output_inline_function.) */
6140 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
6142 /* Initialize the RTL mechanism. */
6145 /* Initialize the queue of pending postincrement and postdecrements,
6146 and some other info in expr.c. */
6149 /* We haven't done register allocation yet. */
6152 init_varasm_status (cfun
);
6154 /* Clear out data used for inlining. */
6155 cfun
->inlinable
= 0;
6156 cfun
->original_decl_initial
= 0;
6157 cfun
->original_arg_vector
= 0;
6159 cfun
->stack_alignment_needed
= STACK_BOUNDARY
;
6160 cfun
->preferred_stack_boundary
= STACK_BOUNDARY
;
6162 /* Set if a call to setjmp is seen. */
6163 current_function_calls_setjmp
= 0;
6165 /* Set if a call to longjmp is seen. */
6166 current_function_calls_longjmp
= 0;
6168 current_function_calls_alloca
= 0;
6169 current_function_calls_eh_return
= 0;
6170 current_function_calls_constant_p
= 0;
6171 current_function_contains_functions
= 0;
6172 current_function_is_leaf
= 0;
6173 current_function_nothrow
= 0;
6174 current_function_sp_is_unchanging
= 0;
6175 current_function_uses_only_leaf_regs
= 0;
6176 current_function_has_computed_jump
= 0;
6177 current_function_is_thunk
= 0;
6179 current_function_returns_pcc_struct
= 0;
6180 current_function_returns_struct
= 0;
6181 current_function_epilogue_delay_list
= 0;
6182 current_function_uses_const_pool
= 0;
6183 current_function_uses_pic_offset_table
= 0;
6184 current_function_cannot_inline
= 0;
6186 /* We have not yet needed to make a label to jump to for tail-recursion. */
6187 tail_recursion_label
= 0;
6189 /* We haven't had a need to make a save area for ap yet. */
6190 arg_pointer_save_area
= 0;
6192 /* No stack slots allocated yet. */
6195 /* No SAVE_EXPRs in this function yet. */
6198 /* No RTL_EXPRs in this function yet. */
6201 /* Set up to allocate temporaries. */
6204 /* Indicate that we need to distinguish between the return value of the
6205 present function and the return value of a function being called. */
6206 rtx_equal_function_value_matters
= 1;
6208 /* Indicate that we have not instantiated virtual registers yet. */
6209 virtuals_instantiated
= 0;
6211 /* Indicate that we want CONCATs now. */
6212 generating_concat_p
= 1;
6214 /* Indicate we have no need of a frame pointer yet. */
6215 frame_pointer_needed
= 0;
6217 /* By default assume not stdarg. */
6218 current_function_stdarg
= 0;
6220 /* We haven't made any trampolines for this function yet. */
6221 trampoline_list
= 0;
6223 init_pending_stack_adjust ();
6224 inhibit_defer_pop
= 0;
6226 current_function_outgoing_args_size
= 0;
6228 current_function_funcdef_no
= funcdef_no
++;
6230 cfun
->arc_profile
= profile_arc_flag
|| flag_test_coverage
;
6232 cfun
->function_frequency
= FUNCTION_FREQUENCY_NORMAL
;
6234 cfun
->max_jumptable_ents
= 0;
6236 (*lang_hooks
.function
.init
) (cfun
);
6237 if (init_machine_status
)
6238 cfun
->machine
= (*init_machine_status
) ();
6241 /* Initialize the rtl expansion mechanism so that we can do simple things
6242 like generate sequences. This is used to provide a context during global
6243 initialization of some passes. */
6245 init_dummy_function_start ()
6247 prepare_function_start ();
6250 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6251 and initialize static variables for generating RTL for the statements
6255 init_function_start (subr
, filename
, line
)
6257 const char *filename
;
6260 prepare_function_start ();
6262 current_function_name
= (*lang_hooks
.decl_printable_name
) (subr
, 2);
6265 /* Nonzero if this is a nested function that uses a static chain. */
6267 current_function_needs_context
6268 = (decl_function_context (current_function_decl
) != 0
6269 && ! DECL_NO_STATIC_CHAIN (current_function_decl
));
6271 /* Within function body, compute a type's size as soon it is laid out. */
6272 immediate_size_expand
++;
6274 /* Prevent ever trying to delete the first instruction of a function.
6275 Also tell final how to output a linenum before the function prologue.
6276 Note linenums could be missing, e.g. when compiling a Java .class file. */
6278 emit_line_note (filename
, line
);
6280 /* Make sure first insn is a note even if we don't want linenums.
6281 This makes sure the first insn will never be deleted.
6282 Also, final expects a note to appear there. */
6283 emit_note (NULL
, NOTE_INSN_DELETED
);
6285 /* Set flags used by final.c. */
6286 if (aggregate_value_p (DECL_RESULT (subr
)))
6288 #ifdef PCC_STATIC_STRUCT_RETURN
6289 current_function_returns_pcc_struct
= 1;
6291 current_function_returns_struct
= 1;
6294 /* Warn if this value is an aggregate type,
6295 regardless of which calling convention we are using for it. */
6296 if (warn_aggregate_return
6297 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
6298 warning ("function returns an aggregate");
6300 current_function_returns_pointer
6301 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
6304 /* Make sure all values used by the optimization passes have sane
6307 init_function_for_compilation ()
6311 /* No prologue/epilogue insns yet. */
6312 VARRAY_GROW (prologue
, 0);
6313 VARRAY_GROW (epilogue
, 0);
6314 VARRAY_GROW (sibcall_epilogue
, 0);
6317 /* Expand a call to __main at the beginning of a possible main function. */
6319 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6320 #undef HAS_INIT_SECTION
6321 #define HAS_INIT_SECTION
6325 expand_main_function ()
6327 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6328 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
)
6330 int align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
6334 /* Forcibly align the stack. */
6335 #ifdef STACK_GROWS_DOWNWARD
6336 tmp
= expand_simple_binop (Pmode
, AND
, stack_pointer_rtx
, GEN_INT(-align
),
6337 stack_pointer_rtx
, 1, OPTAB_WIDEN
);
6339 tmp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
6340 GEN_INT (align
- 1), NULL_RTX
, 1, OPTAB_WIDEN
);
6341 tmp
= expand_simple_binop (Pmode
, AND
, tmp
, GEN_INT (-align
),
6342 stack_pointer_rtx
, 1, OPTAB_WIDEN
);
6344 if (tmp
!= stack_pointer_rtx
)
6345 emit_move_insn (stack_pointer_rtx
, tmp
);
6347 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6348 tmp
= force_reg (Pmode
, const0_rtx
);
6349 allocate_dynamic_stack_space (tmp
, NULL_RTX
, BIGGEST_ALIGNMENT
);
6353 for (tmp
= get_last_insn (); tmp
; tmp
= PREV_INSN (tmp
))
6354 if (NOTE_P (tmp
) && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_FUNCTION_BEG
)
6357 emit_insn_before (seq
, tmp
);
6363 #ifndef HAS_INIT_SECTION
6364 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, NAME__MAIN
), LCT_NORMAL
,
6369 /* The PENDING_SIZES represent the sizes of variable-sized types.
6370 Create RTL for the various sizes now (using temporary variables),
6371 so that we can refer to the sizes from the RTL we are generating
6372 for the current function. The PENDING_SIZES are a TREE_LIST. The
6373 TREE_VALUE of each node is a SAVE_EXPR. */
6376 expand_pending_sizes (pending_sizes
)
6381 /* Evaluate now the sizes of any types declared among the arguments. */
6382 for (tem
= pending_sizes
; tem
; tem
= TREE_CHAIN (tem
))
6384 expand_expr (TREE_VALUE (tem
), const0_rtx
, VOIDmode
, 0);
6385 /* Flush the queue in case this parameter declaration has
6391 /* Start the RTL for a new function, and set variables used for
6393 SUBR is the FUNCTION_DECL node.
6394 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6395 the function's parameters, which must be run at any return statement. */
6398 expand_function_start (subr
, parms_have_cleanups
)
6400 int parms_have_cleanups
;
6403 rtx last_ptr
= NULL_RTX
;
6405 /* Make sure volatile mem refs aren't considered
6406 valid operands of arithmetic insns. */
6407 init_recog_no_volatile ();
6409 current_function_instrument_entry_exit
6410 = (flag_instrument_function_entry_exit
6411 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
6413 current_function_profile
6415 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
6417 current_function_limit_stack
6418 = (stack_limit_rtx
!= NULL_RTX
&& ! DECL_NO_LIMIT_STACK (subr
));
6420 /* If function gets a static chain arg, store it in the stack frame.
6421 Do this first, so it gets the first stack slot offset. */
6422 if (current_function_needs_context
)
6424 last_ptr
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
6426 /* Delay copying static chain if it is not a register to avoid
6427 conflicts with regs used for parameters. */
6428 if (! SMALL_REGISTER_CLASSES
6429 || GET_CODE (static_chain_incoming_rtx
) == REG
)
6430 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
6433 /* If the parameters of this function need cleaning up, get a label
6434 for the beginning of the code which executes those cleanups. This must
6435 be done before doing anything with return_label. */
6436 if (parms_have_cleanups
)
6437 cleanup_label
= gen_label_rtx ();
6441 /* Make the label for return statements to jump to. Do not special
6442 case machines with special return instructions -- they will be
6443 handled later during jump, ifcvt, or epilogue creation. */
6444 return_label
= gen_label_rtx ();
6446 /* Initialize rtx used to return the value. */
6447 /* Do this before assign_parms so that we copy the struct value address
6448 before any library calls that assign parms might generate. */
6450 /* Decide whether to return the value in memory or in a register. */
6451 if (aggregate_value_p (DECL_RESULT (subr
)))
6453 /* Returning something that won't go in a register. */
6454 rtx value_address
= 0;
6456 #ifdef PCC_STATIC_STRUCT_RETURN
6457 if (current_function_returns_pcc_struct
)
6459 int size
= int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr
)));
6460 value_address
= assemble_static_space (size
);
6465 /* Expect to be passed the address of a place to store the value.
6466 If it is passed as an argument, assign_parms will take care of
6468 if (struct_value_incoming_rtx
)
6470 value_address
= gen_reg_rtx (Pmode
);
6471 emit_move_insn (value_address
, struct_value_incoming_rtx
);
6476 rtx x
= gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr
)), value_address
);
6477 set_mem_attributes (x
, DECL_RESULT (subr
), 1);
6478 SET_DECL_RTL (DECL_RESULT (subr
), x
);
6481 else if (DECL_MODE (DECL_RESULT (subr
)) == VOIDmode
)
6482 /* If return mode is void, this decl rtl should not be used. */
6483 SET_DECL_RTL (DECL_RESULT (subr
), NULL_RTX
);
6486 /* Compute the return values into a pseudo reg, which we will copy
6487 into the true return register after the cleanups are done. */
6489 /* In order to figure out what mode to use for the pseudo, we
6490 figure out what the mode of the eventual return register will
6491 actually be, and use that. */
6493 = hard_function_value (TREE_TYPE (DECL_RESULT (subr
)),
6496 /* Structures that are returned in registers are not aggregate_value_p,
6497 so we may see a PARALLEL or a REG. */
6498 if (REG_P (hard_reg
))
6499 SET_DECL_RTL (DECL_RESULT (subr
), gen_reg_rtx (GET_MODE (hard_reg
)));
6500 else if (GET_CODE (hard_reg
) == PARALLEL
)
6501 SET_DECL_RTL (DECL_RESULT (subr
), gen_group_rtx (hard_reg
));
6505 /* Set DECL_REGISTER flag so that expand_function_end will copy the
6506 result to the real return register(s). */
6507 DECL_REGISTER (DECL_RESULT (subr
)) = 1;
6510 /* Initialize rtx for parameters and local variables.
6511 In some cases this requires emitting insns. */
6513 assign_parms (subr
);
6515 /* Copy the static chain now if it wasn't a register. The delay is to
6516 avoid conflicts with the parameter passing registers. */
6518 if (SMALL_REGISTER_CLASSES
&& current_function_needs_context
)
6519 if (GET_CODE (static_chain_incoming_rtx
) != REG
)
6520 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
6522 /* The following was moved from init_function_start.
6523 The move is supposed to make sdb output more accurate. */
6524 /* Indicate the beginning of the function body,
6525 as opposed to parm setup. */
6526 emit_note (NULL
, NOTE_INSN_FUNCTION_BEG
);
6528 if (GET_CODE (get_last_insn ()) != NOTE
)
6529 emit_note (NULL
, NOTE_INSN_DELETED
);
6530 parm_birth_insn
= get_last_insn ();
6532 context_display
= 0;
6533 if (current_function_needs_context
)
6535 /* Fetch static chain values for containing functions. */
6536 tem
= decl_function_context (current_function_decl
);
6537 /* Copy the static chain pointer into a pseudo. If we have
6538 small register classes, copy the value from memory if
6539 static_chain_incoming_rtx is a REG. */
6542 /* If the static chain originally came in a register, put it back
6543 there, then move it out in the next insn. The reason for
6544 this peculiar code is to satisfy function integration. */
6545 if (SMALL_REGISTER_CLASSES
6546 && GET_CODE (static_chain_incoming_rtx
) == REG
)
6547 emit_move_insn (static_chain_incoming_rtx
, last_ptr
);
6548 last_ptr
= copy_to_reg (static_chain_incoming_rtx
);
6553 tree rtlexp
= make_node (RTL_EXPR
);
6555 RTL_EXPR_RTL (rtlexp
) = last_ptr
;
6556 context_display
= tree_cons (tem
, rtlexp
, context_display
);
6557 tem
= decl_function_context (tem
);
6560 /* Chain thru stack frames, assuming pointer to next lexical frame
6561 is found at the place we always store it. */
6562 #ifdef FRAME_GROWS_DOWNWARD
6563 last_ptr
= plus_constant (last_ptr
,
6564 -(HOST_WIDE_INT
) GET_MODE_SIZE (Pmode
));
6566 last_ptr
= gen_rtx_MEM (Pmode
, memory_address (Pmode
, last_ptr
));
6567 set_mem_alias_set (last_ptr
, get_frame_alias_set ());
6568 last_ptr
= copy_to_reg (last_ptr
);
6570 /* If we are not optimizing, ensure that we know that this
6571 piece of context is live over the entire function. */
6573 save_expr_regs
= gen_rtx_EXPR_LIST (VOIDmode
, last_ptr
,
6578 if (current_function_instrument_entry_exit
)
6580 rtx fun
= DECL_RTL (current_function_decl
);
6581 if (GET_CODE (fun
) == MEM
)
6582 fun
= XEXP (fun
, 0);
6585 emit_library_call (profile_function_entry_libfunc
, LCT_NORMAL
, VOIDmode
,
6587 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS
,
6589 hard_frame_pointer_rtx
),
6593 if (current_function_profile
)
6596 PROFILE_HOOK (current_function_funcdef_no
);
6600 /* After the display initializations is where the tail-recursion label
6601 should go, if we end up needing one. Ensure we have a NOTE here
6602 since some things (like trampolines) get placed before this. */
6603 tail_recursion_reentry
= emit_note (NULL
, NOTE_INSN_DELETED
);
6605 /* Evaluate now the sizes of any types declared among the arguments. */
6606 expand_pending_sizes (nreverse (get_pending_sizes ()));
6608 /* Make sure there is a line number after the function entry setup code. */
6609 force_next_line_note ();
6612 /* Undo the effects of init_dummy_function_start. */
6614 expand_dummy_function_end ()
6616 /* End any sequences that failed to be closed due to syntax errors. */
6617 while (in_sequence_p ())
6620 /* Outside function body, can't compute type's actual size
6621 until next function's body starts. */
6623 free_after_parsing (cfun
);
6624 free_after_compilation (cfun
);
6628 /* Call DOIT for each hard register used as a return value from
6629 the current function. */
6632 diddle_return_value (doit
, arg
)
6633 void (*doit
) PARAMS ((rtx
, void *));
6636 rtx outgoing
= current_function_return_rtx
;
6641 if (GET_CODE (outgoing
) == REG
)
6642 (*doit
) (outgoing
, arg
);
6643 else if (GET_CODE (outgoing
) == PARALLEL
)
6647 for (i
= 0; i
< XVECLEN (outgoing
, 0); i
++)
6649 rtx x
= XEXP (XVECEXP (outgoing
, 0, i
), 0);
6651 if (GET_CODE (x
) == REG
&& REGNO (x
) < FIRST_PSEUDO_REGISTER
)
6658 do_clobber_return_reg (reg
, arg
)
6660 void *arg ATTRIBUTE_UNUSED
;
6662 emit_insn (gen_rtx_CLOBBER (VOIDmode
, reg
));
6666 clobber_return_register ()
6668 diddle_return_value (do_clobber_return_reg
, NULL
);
6670 /* In case we do use pseudo to return value, clobber it too. */
6671 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
6673 tree decl_result
= DECL_RESULT (current_function_decl
);
6674 rtx decl_rtl
= DECL_RTL (decl_result
);
6675 if (REG_P (decl_rtl
) && REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
)
6677 do_clobber_return_reg (decl_rtl
, NULL
);
6683 do_use_return_reg (reg
, arg
)
6685 void *arg ATTRIBUTE_UNUSED
;
6687 emit_insn (gen_rtx_USE (VOIDmode
, reg
));
6691 use_return_register ()
6693 diddle_return_value (do_use_return_reg
, NULL
);
6696 static GTY(()) rtx initial_trampoline
;
6698 /* Generate RTL for the end of the current function.
6699 FILENAME and LINE are the current position in the source file.
6701 It is up to language-specific callers to do cleanups for parameters--
6702 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6705 expand_function_end (filename
, line
, end_bindings
)
6706 const char *filename
;
6713 finish_expr_for_function ();
6715 /* If arg_pointer_save_area was referenced only from a nested
6716 function, we will not have initialized it yet. Do that now. */
6717 if (arg_pointer_save_area
&& ! cfun
->arg_pointer_save_area_init
)
6718 get_arg_pointer_save_area (cfun
);
6720 #ifdef NON_SAVING_SETJMP
6721 /* Don't put any variables in registers if we call setjmp
6722 on a machine that fails to restore the registers. */
6723 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
6725 if (DECL_INITIAL (current_function_decl
) != error_mark_node
)
6726 setjmp_protect (DECL_INITIAL (current_function_decl
));
6728 setjmp_protect_args ();
6732 /* Initialize any trampolines required by this function. */
6733 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
6735 tree function
= TREE_PURPOSE (link
);
6736 rtx context ATTRIBUTE_UNUSED
= lookup_static_chain (function
);
6737 rtx tramp
= RTL_EXPR_RTL (TREE_VALUE (link
));
6738 #ifdef TRAMPOLINE_TEMPLATE
6743 #ifdef TRAMPOLINE_TEMPLATE
6744 /* First make sure this compilation has a template for
6745 initializing trampolines. */
6746 if (initial_trampoline
== 0)
6749 = gen_rtx_MEM (BLKmode
, assemble_trampoline_template ());
6750 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
6754 /* Generate insns to initialize the trampoline. */
6756 tramp
= round_trampoline_addr (XEXP (tramp
, 0));
6757 #ifdef TRAMPOLINE_TEMPLATE
6758 blktramp
= replace_equiv_address (initial_trampoline
, tramp
);
6759 emit_block_move (blktramp
, initial_trampoline
,
6760 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
6762 INITIALIZE_TRAMPOLINE (tramp
, XEXP (DECL_RTL (function
), 0), context
);
6766 /* Put those insns at entry to the containing function (this one). */
6767 emit_insn_before (seq
, tail_recursion_reentry
);
6770 /* If we are doing stack checking and this function makes calls,
6771 do a stack probe at the start of the function to ensure we have enough
6772 space for another stack frame. */
6773 if (flag_stack_check
&& ! STACK_CHECK_BUILTIN
)
6777 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6778 if (GET_CODE (insn
) == CALL_INSN
)
6781 probe_stack_range (STACK_CHECK_PROTECT
,
6782 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
));
6785 emit_insn_before (seq
, tail_recursion_reentry
);
6790 /* Warn about unused parms if extra warnings were specified. */
6791 /* Either ``-Wextra -Wunused'' or ``-Wunused-parameter'' enables this
6792 warning. WARN_UNUSED_PARAMETER is negative when set by
6793 -Wunused. Note that -Wall implies -Wunused, so ``-Wall -Wextra'' will
6794 also give these warnings. */
6795 if (warn_unused_parameter
> 0
6796 || (warn_unused_parameter
< 0 && extra_warnings
))
6800 for (decl
= DECL_ARGUMENTS (current_function_decl
);
6801 decl
; decl
= TREE_CHAIN (decl
))
6802 if (! TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
6803 && DECL_NAME (decl
) && ! DECL_ARTIFICIAL (decl
))
6804 warning_with_decl (decl
, "unused parameter `%s'");
6807 /* Delete handlers for nonlocal gotos if nothing uses them. */
6808 if (nonlocal_goto_handler_slots
!= 0
6809 && ! current_function_has_nonlocal_label
)
6812 /* End any sequences that failed to be closed due to syntax errors. */
6813 while (in_sequence_p ())
6816 /* Outside function body, can't compute type's actual size
6817 until next function's body starts. */
6818 immediate_size_expand
--;
6820 clear_pending_stack_adjust ();
6821 do_pending_stack_adjust ();
6823 /* Mark the end of the function body.
6824 If control reaches this insn, the function can drop through
6825 without returning a value. */
6826 emit_note (NULL
, NOTE_INSN_FUNCTION_END
);
6828 /* Must mark the last line number note in the function, so that the test
6829 coverage code can avoid counting the last line twice. This just tells
6830 the code to ignore the immediately following line note, since there
6831 already exists a copy of this note somewhere above. This line number
6832 note is still needed for debugging though, so we can't delete it. */
6833 if (flag_test_coverage
)
6834 emit_note (NULL
, NOTE_INSN_REPEATED_LINE_NUMBER
);
6836 /* Output a linenumber for the end of the function.
6837 SDB depends on this. */
6838 emit_line_note_force (filename
, line
);
6840 /* Before the return label (if any), clobber the return
6841 registers so that they are not propagated live to the rest of
6842 the function. This can only happen with functions that drop
6843 through; if there had been a return statement, there would
6844 have either been a return rtx, or a jump to the return label.
6846 We delay actual code generation after the current_function_value_rtx
6848 clobber_after
= get_last_insn ();
6850 /* Output the label for the actual return from the function,
6851 if one is expected. This happens either because a function epilogue
6852 is used instead of a return instruction, or because a return was done
6853 with a goto in order to run local cleanups, or because of pcc-style
6854 structure returning. */
6856 emit_label (return_label
);
6858 /* C++ uses this. */
6860 expand_end_bindings (0, 0, 0);
6862 if (current_function_instrument_entry_exit
)
6864 rtx fun
= DECL_RTL (current_function_decl
);
6865 if (GET_CODE (fun
) == MEM
)
6866 fun
= XEXP (fun
, 0);
6869 emit_library_call (profile_function_exit_libfunc
, LCT_NORMAL
, VOIDmode
,
6871 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS
,
6873 hard_frame_pointer_rtx
),
6877 /* Let except.c know where it should emit the call to unregister
6878 the function context for sjlj exceptions. */
6879 if (flag_exceptions
&& USING_SJLJ_EXCEPTIONS
)
6880 sjlj_emit_function_exit_after (get_last_insn ());
6882 /* If we had calls to alloca, and this machine needs
6883 an accurate stack pointer to exit the function,
6884 insert some code to save and restore the stack pointer. */
6885 #ifdef EXIT_IGNORE_STACK
6886 if (! EXIT_IGNORE_STACK
)
6888 if (current_function_calls_alloca
)
6892 emit_stack_save (SAVE_FUNCTION
, &tem
, parm_birth_insn
);
6893 emit_stack_restore (SAVE_FUNCTION
, tem
, NULL_RTX
);
6896 /* If scalar return value was computed in a pseudo-reg, or was a named
6897 return value that got dumped to the stack, copy that to the hard
6899 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
6901 tree decl_result
= DECL_RESULT (current_function_decl
);
6902 rtx decl_rtl
= DECL_RTL (decl_result
);
6904 if (REG_P (decl_rtl
)
6905 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
6906 : DECL_REGISTER (decl_result
))
6908 rtx real_decl_rtl
= current_function_return_rtx
;
6910 /* This should be set in assign_parms. */
6911 if (! REG_FUNCTION_VALUE_P (real_decl_rtl
))
6914 /* If this is a BLKmode structure being returned in registers,
6915 then use the mode computed in expand_return. Note that if
6916 decl_rtl is memory, then its mode may have been changed,
6917 but that current_function_return_rtx has not. */
6918 if (GET_MODE (real_decl_rtl
) == BLKmode
)
6919 PUT_MODE (real_decl_rtl
, GET_MODE (decl_rtl
));
6921 /* If a named return value dumped decl_return to memory, then
6922 we may need to re-do the PROMOTE_MODE signed/unsigned
6924 if (GET_MODE (real_decl_rtl
) != GET_MODE (decl_rtl
))
6926 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (decl_result
));
6928 #ifdef PROMOTE_FUNCTION_RETURN
6929 promote_mode (TREE_TYPE (decl_result
), GET_MODE (decl_rtl
),
6933 convert_move (real_decl_rtl
, decl_rtl
, unsignedp
);
6935 else if (GET_CODE (real_decl_rtl
) == PARALLEL
)
6937 /* If expand_function_start has created a PARALLEL for decl_rtl,
6938 move the result to the real return registers. Otherwise, do
6939 a group load from decl_rtl for a named return. */
6940 if (GET_CODE (decl_rtl
) == PARALLEL
)
6941 emit_group_move (real_decl_rtl
, decl_rtl
);
6943 emit_group_load (real_decl_rtl
, decl_rtl
,
6944 int_size_in_bytes (TREE_TYPE (decl_result
)));
6947 emit_move_insn (real_decl_rtl
, decl_rtl
);
6951 /* If returning a structure, arrange to return the address of the value
6952 in a place where debuggers expect to find it.
6954 If returning a structure PCC style,
6955 the caller also depends on this value.
6956 And current_function_returns_pcc_struct is not necessarily set. */
6957 if (current_function_returns_struct
6958 || current_function_returns_pcc_struct
)
6961 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl
)), 0);
6962 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
6963 #ifdef FUNCTION_OUTGOING_VALUE
6965 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type
),
6966 current_function_decl
);
6969 = FUNCTION_VALUE (build_pointer_type (type
), current_function_decl
);
6972 /* Mark this as a function return value so integrate will delete the
6973 assignment and USE below when inlining this function. */
6974 REG_FUNCTION_VALUE_P (outgoing
) = 1;
6976 #ifdef POINTERS_EXTEND_UNSIGNED
6977 /* The address may be ptr_mode and OUTGOING may be Pmode. */
6978 if (GET_MODE (outgoing
) != GET_MODE (value_address
))
6979 value_address
= convert_memory_address (GET_MODE (outgoing
),
6983 emit_move_insn (outgoing
, value_address
);
6985 /* Show return register used to hold result (in this case the address
6987 current_function_return_rtx
= outgoing
;
6990 /* If this is an implementation of throw, do what's necessary to
6991 communicate between __builtin_eh_return and the epilogue. */
6992 expand_eh_return ();
6994 /* Emit the actual code to clobber return register. */
6999 clobber_return_register ();
7003 after
= emit_insn_after (seq
, clobber_after
);
7005 if (clobber_after
!= after
)
7006 cfun
->x_clobber_return_insn
= after
;
7009 /* ??? This should no longer be necessary since stupid is no longer with
7010 us, but there are some parts of the compiler (eg reload_combine, and
7011 sh mach_dep_reorg) that still try and compute their own lifetime info
7012 instead of using the general framework. */
7013 use_return_register ();
7015 /* Fix up any gotos that jumped out to the outermost
7016 binding level of the function.
7017 Must follow emitting RETURN_LABEL. */
7019 /* If you have any cleanups to do at this point,
7020 and they need to create temporary variables,
7021 then you will lose. */
7022 expand_fixups (get_insns ());
7026 get_arg_pointer_save_area (f
)
7029 rtx ret
= f
->x_arg_pointer_save_area
;
7033 ret
= assign_stack_local_1 (Pmode
, GET_MODE_SIZE (Pmode
), 0, f
);
7034 f
->x_arg_pointer_save_area
= ret
;
7037 if (f
== cfun
&& ! f
->arg_pointer_save_area_init
)
7041 /* Save the arg pointer at the beginning of the function. The
7042 generated stack slot may not be a valid memory address, so we
7043 have to check it and fix it if necessary. */
7045 emit_move_insn (validize_mem (ret
), virtual_incoming_args_rtx
);
7049 push_topmost_sequence ();
7050 emit_insn_after (seq
, get_insns ());
7051 pop_topmost_sequence ();
7057 /* Extend a vector that records the INSN_UIDs of INSNS
7058 (a list of one or more insns). */
7061 record_insns (insns
, vecp
)
7070 while (tmp
!= NULL_RTX
)
7073 tmp
= NEXT_INSN (tmp
);
7076 i
= VARRAY_SIZE (*vecp
);
7077 VARRAY_GROW (*vecp
, i
+ len
);
7079 while (tmp
!= NULL_RTX
)
7081 VARRAY_INT (*vecp
, i
) = INSN_UID (tmp
);
7083 tmp
= NEXT_INSN (tmp
);
7087 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
7088 be running after reorg, SEQUENCE rtl is possible. */
7091 contains (insn
, vec
)
7097 if (GET_CODE (insn
) == INSN
7098 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
7101 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
7102 for (j
= VARRAY_SIZE (vec
) - 1; j
>= 0; --j
)
7103 if (INSN_UID (XVECEXP (PATTERN (insn
), 0, i
)) == VARRAY_INT (vec
, j
))
7109 for (j
= VARRAY_SIZE (vec
) - 1; j
>= 0; --j
)
7110 if (INSN_UID (insn
) == VARRAY_INT (vec
, j
))
7117 prologue_epilogue_contains (insn
)
7120 if (contains (insn
, prologue
))
7122 if (contains (insn
, epilogue
))
7128 sibcall_epilogue_contains (insn
)
7131 if (sibcall_epilogue
)
7132 return contains (insn
, sibcall_epilogue
);
7137 /* Insert gen_return at the end of block BB. This also means updating
7138 block_for_insn appropriately. */
7141 emit_return_into_block (bb
, line_note
)
7145 emit_jump_insn_after (gen_return (), bb
->end
);
7147 emit_line_note_after (NOTE_SOURCE_FILE (line_note
),
7148 NOTE_LINE_NUMBER (line_note
), PREV_INSN (bb
->end
));
7150 #endif /* HAVE_return */
7152 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7154 /* These functions convert the epilogue into a variant that does not modify the
7155 stack pointer. This is used in cases where a function returns an object
7156 whose size is not known until it is computed. The called function leaves the
7157 object on the stack, leaves the stack depressed, and returns a pointer to
7160 What we need to do is track all modifications and references to the stack
7161 pointer, deleting the modifications and changing the references to point to
7162 the location the stack pointer would have pointed to had the modifications
7165 These functions need to be portable so we need to make as few assumptions
7166 about the epilogue as we can. However, the epilogue basically contains
7167 three things: instructions to reset the stack pointer, instructions to
7168 reload registers, possibly including the frame pointer, and an
7169 instruction to return to the caller.
7171 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7172 We also make no attempt to validate the insns we make since if they are
7173 invalid, we probably can't do anything valid. The intent is that these
7174 routines get "smarter" as more and more machines start to use them and
7175 they try operating on different epilogues.
7177 We use the following structure to track what the part of the epilogue that
7178 we've already processed has done. We keep two copies of the SP equivalence,
7179 one for use during the insn we are processing and one for use in the next
7180 insn. The difference is because one part of a PARALLEL may adjust SP
7181 and the other may use it. */
7185 rtx sp_equiv_reg
; /* REG that SP is set from, perhaps SP. */
7186 HOST_WIDE_INT sp_offset
; /* Offset from SP_EQUIV_REG of present SP. */
7187 rtx new_sp_equiv_reg
; /* REG to be used at end of insn. */
7188 HOST_WIDE_INT new_sp_offset
; /* Offset to be used at end of insn. */
7189 rtx equiv_reg_src
; /* If nonzero, the value that SP_EQUIV_REG
7190 should be set to once we no longer need
7194 static void handle_epilogue_set
PARAMS ((rtx
, struct epi_info
*));
7195 static void emit_equiv_load
PARAMS ((struct epi_info
*));
7197 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
7198 no modifications to the stack pointer. Return the new list of insns. */
7201 keep_stack_depressed (insns
)
7205 struct epi_info info
;
7208 /* If the epilogue is just a single instruction, it ust be OK as is. */
7210 if (NEXT_INSN (insns
) == NULL_RTX
)
7213 /* Otherwise, start a sequence, initialize the information we have, and
7214 process all the insns we were given. */
7217 info
.sp_equiv_reg
= stack_pointer_rtx
;
7219 info
.equiv_reg_src
= 0;
7223 while (insn
!= NULL_RTX
)
7225 next
= NEXT_INSN (insn
);
7234 /* If this insn references the register that SP is equivalent to and
7235 we have a pending load to that register, we must force out the load
7236 first and then indicate we no longer know what SP's equivalent is. */
7237 if (info
.equiv_reg_src
!= 0
7238 && reg_referenced_p (info
.sp_equiv_reg
, PATTERN (insn
)))
7240 emit_equiv_load (&info
);
7241 info
.sp_equiv_reg
= 0;
7244 info
.new_sp_equiv_reg
= info
.sp_equiv_reg
;
7245 info
.new_sp_offset
= info
.sp_offset
;
7247 /* If this is a (RETURN) and the return address is on the stack,
7248 update the address and change to an indirect jump. */
7249 if (GET_CODE (PATTERN (insn
)) == RETURN
7250 || (GET_CODE (PATTERN (insn
)) == PARALLEL
7251 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == RETURN
))
7253 rtx retaddr
= INCOMING_RETURN_ADDR_RTX
;
7255 HOST_WIDE_INT offset
= 0;
7256 rtx jump_insn
, jump_set
;
7258 /* If the return address is in a register, we can emit the insn
7259 unchanged. Otherwise, it must be a MEM and we see what the
7260 base register and offset are. In any case, we have to emit any
7261 pending load to the equivalent reg of SP, if any. */
7262 if (GET_CODE (retaddr
) == REG
)
7264 emit_equiv_load (&info
);
7269 else if (GET_CODE (retaddr
) == MEM
7270 && GET_CODE (XEXP (retaddr
, 0)) == REG
)
7271 base
= gen_rtx_REG (Pmode
, REGNO (XEXP (retaddr
, 0))), offset
= 0;
7272 else if (GET_CODE (retaddr
) == MEM
7273 && GET_CODE (XEXP (retaddr
, 0)) == PLUS
7274 && GET_CODE (XEXP (XEXP (retaddr
, 0), 0)) == REG
7275 && GET_CODE (XEXP (XEXP (retaddr
, 0), 1)) == CONST_INT
)
7277 base
= gen_rtx_REG (Pmode
, REGNO (XEXP (XEXP (retaddr
, 0), 0)));
7278 offset
= INTVAL (XEXP (XEXP (retaddr
, 0), 1));
7283 /* If the base of the location containing the return pointer
7284 is SP, we must update it with the replacement address. Otherwise,
7285 just build the necessary MEM. */
7286 retaddr
= plus_constant (base
, offset
);
7287 if (base
== stack_pointer_rtx
)
7288 retaddr
= simplify_replace_rtx (retaddr
, stack_pointer_rtx
,
7289 plus_constant (info
.sp_equiv_reg
,
7292 retaddr
= gen_rtx_MEM (Pmode
, retaddr
);
7294 /* If there is a pending load to the equivalent register for SP
7295 and we reference that register, we must load our address into
7296 a scratch register and then do that load. */
7297 if (info
.equiv_reg_src
7298 && reg_overlap_mentioned_p (info
.equiv_reg_src
, retaddr
))
7303 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
7304 if (HARD_REGNO_MODE_OK (regno
, Pmode
)
7305 && !fixed_regs
[regno
]
7306 && TEST_HARD_REG_BIT (regs_invalidated_by_call
, regno
)
7307 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR
->global_live_at_start
,
7309 && !refers_to_regno_p (regno
,
7310 regno
+ HARD_REGNO_NREGS (regno
,
7312 info
.equiv_reg_src
, NULL
))
7315 if (regno
== FIRST_PSEUDO_REGISTER
)
7318 reg
= gen_rtx_REG (Pmode
, regno
);
7319 emit_move_insn (reg
, retaddr
);
7323 emit_equiv_load (&info
);
7324 jump_insn
= emit_jump_insn (gen_indirect_jump (retaddr
));
7326 /* Show the SET in the above insn is a RETURN. */
7327 jump_set
= single_set (jump_insn
);
7331 SET_IS_RETURN_P (jump_set
) = 1;
7334 /* If SP is not mentioned in the pattern and its equivalent register, if
7335 any, is not modified, just emit it. Otherwise, if neither is set,
7336 replace the reference to SP and emit the insn. If none of those are
7337 true, handle each SET individually. */
7338 else if (!reg_mentioned_p (stack_pointer_rtx
, PATTERN (insn
))
7339 && (info
.sp_equiv_reg
== stack_pointer_rtx
7340 || !reg_set_p (info
.sp_equiv_reg
, insn
)))
7342 else if (! reg_set_p (stack_pointer_rtx
, insn
)
7343 && (info
.sp_equiv_reg
== stack_pointer_rtx
7344 || !reg_set_p (info
.sp_equiv_reg
, insn
)))
7346 if (! validate_replace_rtx (stack_pointer_rtx
,
7347 plus_constant (info
.sp_equiv_reg
,
7354 else if (GET_CODE (PATTERN (insn
)) == SET
)
7355 handle_epilogue_set (PATTERN (insn
), &info
);
7356 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
7358 for (j
= 0; j
< XVECLEN (PATTERN (insn
), 0); j
++)
7359 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, j
)) == SET
)
7360 handle_epilogue_set (XVECEXP (PATTERN (insn
), 0, j
), &info
);
7365 info
.sp_equiv_reg
= info
.new_sp_equiv_reg
;
7366 info
.sp_offset
= info
.new_sp_offset
;
7371 insns
= get_insns ();
7376 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7377 structure that contains information about what we've seen so far. We
7378 process this SET by either updating that data or by emitting one or
7382 handle_epilogue_set (set
, p
)
7386 /* First handle the case where we are setting SP. Record what it is being
7387 set from. If unknown, abort. */
7388 if (reg_set_p (stack_pointer_rtx
, set
))
7390 if (SET_DEST (set
) != stack_pointer_rtx
)
7393 if (GET_CODE (SET_SRC (set
)) == PLUS
7394 && GET_CODE (XEXP (SET_SRC (set
), 1)) == CONST_INT
)
7396 p
->new_sp_equiv_reg
= XEXP (SET_SRC (set
), 0);
7397 p
->new_sp_offset
= INTVAL (XEXP (SET_SRC (set
), 1));
7400 p
->new_sp_equiv_reg
= SET_SRC (set
), p
->new_sp_offset
= 0;
7402 /* If we are adjusting SP, we adjust from the old data. */
7403 if (p
->new_sp_equiv_reg
== stack_pointer_rtx
)
7405 p
->new_sp_equiv_reg
= p
->sp_equiv_reg
;
7406 p
->new_sp_offset
+= p
->sp_offset
;
7409 if (p
->new_sp_equiv_reg
== 0 || GET_CODE (p
->new_sp_equiv_reg
) != REG
)
7415 /* Next handle the case where we are setting SP's equivalent register.
7416 If we already have a value to set it to, abort. We could update, but
7417 there seems little point in handling that case. Note that we have
7418 to allow for the case where we are setting the register set in
7419 the previous part of a PARALLEL inside a single insn. But use the
7420 old offset for any updates within this insn. */
7421 else if (p
->new_sp_equiv_reg
!= 0 && reg_set_p (p
->new_sp_equiv_reg
, set
))
7423 if (!rtx_equal_p (p
->new_sp_equiv_reg
, SET_DEST (set
))
7424 || p
->equiv_reg_src
!= 0)
7428 = simplify_replace_rtx (SET_SRC (set
), stack_pointer_rtx
,
7429 plus_constant (p
->sp_equiv_reg
,
7433 /* Otherwise, replace any references to SP in the insn to its new value
7434 and emit the insn. */
7437 SET_SRC (set
) = simplify_replace_rtx (SET_SRC (set
), stack_pointer_rtx
,
7438 plus_constant (p
->sp_equiv_reg
,
7440 SET_DEST (set
) = simplify_replace_rtx (SET_DEST (set
), stack_pointer_rtx
,
7441 plus_constant (p
->sp_equiv_reg
,
7447 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7453 if (p
->equiv_reg_src
!= 0)
7454 emit_move_insn (p
->sp_equiv_reg
, p
->equiv_reg_src
);
7456 p
->equiv_reg_src
= 0;
7460 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7461 this into place with notes indicating where the prologue ends and where
7462 the epilogue begins. Update the basic block information when possible. */
7465 thread_prologue_and_epilogue_insns (f
)
7466 rtx f ATTRIBUTE_UNUSED
;
7470 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7473 #ifdef HAVE_prologue
7474 rtx prologue_end
= NULL_RTX
;
7476 #if defined (HAVE_epilogue) || defined(HAVE_return)
7477 rtx epilogue_end
= NULL_RTX
;
7480 #ifdef HAVE_prologue
7484 seq
= gen_prologue ();
7487 /* Retain a map of the prologue insns. */
7488 record_insns (seq
, &prologue
);
7489 prologue_end
= emit_note (NULL
, NOTE_INSN_PROLOGUE_END
);
7494 /* Can't deal with multiple successors of the entry block
7495 at the moment. Function should always have at least one
7497 if (!ENTRY_BLOCK_PTR
->succ
|| ENTRY_BLOCK_PTR
->succ
->succ_next
)
7500 insert_insn_on_edge (seq
, ENTRY_BLOCK_PTR
->succ
);
7505 /* If the exit block has no non-fake predecessors, we don't need
7507 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7508 if ((e
->flags
& EDGE_FAKE
) == 0)
7514 if (optimize
&& HAVE_return
)
7516 /* If we're allowed to generate a simple return instruction,
7517 then by definition we don't need a full epilogue. Examine
7518 the block that falls through to EXIT. If it does not
7519 contain any code, examine its predecessors and try to
7520 emit (conditional) return instructions. */
7526 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7527 if (e
->flags
& EDGE_FALLTHRU
)
7533 /* Verify that there are no active instructions in the last block. */
7535 while (label
&& GET_CODE (label
) != CODE_LABEL
)
7537 if (active_insn_p (label
))
7539 label
= PREV_INSN (label
);
7542 if (last
->head
== label
&& GET_CODE (label
) == CODE_LABEL
)
7544 rtx epilogue_line_note
= NULL_RTX
;
7546 /* Locate the line number associated with the closing brace,
7547 if we can find one. */
7548 for (seq
= get_last_insn ();
7549 seq
&& ! active_insn_p (seq
);
7550 seq
= PREV_INSN (seq
))
7551 if (GET_CODE (seq
) == NOTE
&& NOTE_LINE_NUMBER (seq
) > 0)
7553 epilogue_line_note
= seq
;
7557 for (e
= last
->pred
; e
; e
= e_next
)
7559 basic_block bb
= e
->src
;
7562 e_next
= e
->pred_next
;
7563 if (bb
== ENTRY_BLOCK_PTR
)
7567 if ((GET_CODE (jump
) != JUMP_INSN
) || JUMP_LABEL (jump
) != label
)
7570 /* If we have an unconditional jump, we can replace that
7571 with a simple return instruction. */
7572 if (simplejump_p (jump
))
7574 emit_return_into_block (bb
, epilogue_line_note
);
7578 /* If we have a conditional jump, we can try to replace
7579 that with a conditional return instruction. */
7580 else if (condjump_p (jump
))
7584 ret
= SET_SRC (PATTERN (jump
));
7585 if (GET_CODE (XEXP (ret
, 1)) == LABEL_REF
)
7586 loc
= &XEXP (ret
, 1);
7588 loc
= &XEXP (ret
, 2);
7589 ret
= gen_rtx_RETURN (VOIDmode
);
7591 if (! validate_change (jump
, loc
, ret
, 0))
7593 if (JUMP_LABEL (jump
))
7594 LABEL_NUSES (JUMP_LABEL (jump
))--;
7596 /* If this block has only one successor, it both jumps
7597 and falls through to the fallthru block, so we can't
7599 if (bb
->succ
->succ_next
== NULL
)
7605 /* Fix up the CFG for the successful change we just made. */
7606 redirect_edge_succ (e
, EXIT_BLOCK_PTR
);
7609 /* Emit a return insn for the exit fallthru block. Whether
7610 this is still reachable will be determined later. */
7612 emit_barrier_after (last
->end
);
7613 emit_return_into_block (last
, epilogue_line_note
);
7614 epilogue_end
= last
->end
;
7615 last
->succ
->flags
&= ~EDGE_FALLTHRU
;
7620 #ifdef HAVE_epilogue
7623 /* Find the edge that falls through to EXIT. Other edges may exist
7624 due to RETURN instructions, but those don't need epilogues.
7625 There really shouldn't be a mixture -- either all should have
7626 been converted or none, however... */
7628 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7629 if (e
->flags
& EDGE_FALLTHRU
)
7635 epilogue_end
= emit_note (NULL
, NOTE_INSN_EPILOGUE_BEG
);
7637 seq
= gen_epilogue ();
7639 #ifdef INCOMING_RETURN_ADDR_RTX
7640 /* If this function returns with the stack depressed and we can support
7641 it, massage the epilogue to actually do that. */
7642 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == FUNCTION_TYPE
7643 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl
)))
7644 seq
= keep_stack_depressed (seq
);
7647 emit_jump_insn (seq
);
7649 /* Retain a map of the epilogue insns. */
7650 record_insns (seq
, &epilogue
);
7655 insert_insn_on_edge (seq
, e
);
7662 commit_edge_insertions ();
7664 #ifdef HAVE_sibcall_epilogue
7665 /* Emit sibling epilogues before any sibling call sites. */
7666 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7668 basic_block bb
= e
->src
;
7673 if (GET_CODE (insn
) != CALL_INSN
7674 || ! SIBLING_CALL_P (insn
))
7678 emit_insn (gen_sibcall_epilogue ());
7682 /* Retain a map of the epilogue insns. Used in life analysis to
7683 avoid getting rid of sibcall epilogue insns. Do this before we
7684 actually emit the sequence. */
7685 record_insns (seq
, &sibcall_epilogue
);
7687 i
= PREV_INSN (insn
);
7688 newinsn
= emit_insn_before (seq
, insn
);
7692 #ifdef HAVE_prologue
7697 /* GDB handles `break f' by setting a breakpoint on the first
7698 line note after the prologue. Which means (1) that if
7699 there are line number notes before where we inserted the
7700 prologue we should move them, and (2) we should generate a
7701 note before the end of the first basic block, if there isn't
7704 ??? This behavior is completely broken when dealing with
7705 multiple entry functions. We simply place the note always
7706 into first basic block and let alternate entry points
7710 for (insn
= prologue_end
; insn
; insn
= prev
)
7712 prev
= PREV_INSN (insn
);
7713 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7715 /* Note that we cannot reorder the first insn in the
7716 chain, since rest_of_compilation relies on that
7717 remaining constant. */
7720 reorder_insns (insn
, insn
, prologue_end
);
7724 /* Find the last line number note in the first block. */
7725 for (insn
= ENTRY_BLOCK_PTR
->next_bb
->end
;
7726 insn
!= prologue_end
&& insn
;
7727 insn
= PREV_INSN (insn
))
7728 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7731 /* If we didn't find one, make a copy of the first line number
7735 for (insn
= next_active_insn (prologue_end
);
7737 insn
= PREV_INSN (insn
))
7738 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7740 emit_line_note_after (NOTE_SOURCE_FILE (insn
),
7741 NOTE_LINE_NUMBER (insn
),
7748 #ifdef HAVE_epilogue
7753 /* Similarly, move any line notes that appear after the epilogue.
7754 There is no need, however, to be quite so anal about the existence
7756 for (insn
= epilogue_end
; insn
; insn
= next
)
7758 next
= NEXT_INSN (insn
);
7759 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7760 reorder_insns (insn
, insn
, PREV_INSN (epilogue_end
));
7766 /* Reposition the prologue-end and epilogue-begin notes after instruction
7767 scheduling and delayed branch scheduling. */
7770 reposition_prologue_and_epilogue_notes (f
)
7771 rtx f ATTRIBUTE_UNUSED
;
7773 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7774 rtx insn
, last
, note
;
7777 if ((len
= VARRAY_SIZE (prologue
)) > 0)
7781 /* Scan from the beginning until we reach the last prologue insn.
7782 We apparently can't depend on basic_block_{head,end} after
7784 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
7786 if (GET_CODE (insn
) == NOTE
)
7788 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
7791 else if (contains (insn
, prologue
))
7801 /* Find the prologue-end note if we haven't already, and
7802 move it to just after the last prologue insn. */
7805 for (note
= last
; (note
= NEXT_INSN (note
));)
7806 if (GET_CODE (note
) == NOTE
7807 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_PROLOGUE_END
)
7811 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7812 if (GET_CODE (last
) == CODE_LABEL
)
7813 last
= NEXT_INSN (last
);
7814 reorder_insns (note
, note
, last
);
7818 if ((len
= VARRAY_SIZE (epilogue
)) > 0)
7822 /* Scan from the end until we reach the first epilogue insn.
7823 We apparently can't depend on basic_block_{head,end} after
7825 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
7827 if (GET_CODE (insn
) == NOTE
)
7829 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EPILOGUE_BEG
)
7832 else if (contains (insn
, epilogue
))
7842 /* Find the epilogue-begin note if we haven't already, and
7843 move it to just before the first epilogue insn. */
7846 for (note
= insn
; (note
= PREV_INSN (note
));)
7847 if (GET_CODE (note
) == NOTE
7848 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_EPILOGUE_BEG
)
7852 if (PREV_INSN (last
) != note
)
7853 reorder_insns (note
, note
, PREV_INSN (last
));
7856 #endif /* HAVE_prologue or HAVE_epilogue */
7859 /* Called once, at initialization, to initialize function.c. */
7862 init_function_once ()
7864 VARRAY_INT_INIT (prologue
, 0, "prologue");
7865 VARRAY_INT_INIT (epilogue
, 0, "epilogue");
7866 VARRAY_INT_INIT (sibcall_epilogue
, 0, "sibcall_epilogue");
7869 #include "gt-function.h"