1 /* Expands front end tree to back end RTL for GNU C-Compiler
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file handles the generation of rtl code from tree structure
23 at the level of the function as a whole.
24 It creates the rtl expressions for parameters and auto variables
25 and has full responsibility for allocating stack slots.
27 `expand_function_start' is called at the beginning of a function,
28 before the function body is parsed, and `expand_function_end' is
29 called after parsing the body.
31 Call `assign_stack_local' to allocate a stack slot for a local variable.
32 This is usually done during the RTL generation for the function body,
33 but it can also be done in the reload pass when a pseudo-register does
34 not get a hard register.
36 Call `put_var_into_stack' when you learn, belatedly, that a variable
37 previously given a pseudo-register must in fact go in the stack.
38 This function changes the DECL_RTL to be a stack slot instead of a reg
39 then scans all the RTL instructions so far generated to correct them. */
51 #include "hard-reg-set.h"
52 #include "insn-config.h"
55 #include "basic-block.h"
60 #include "integrate.h"
61 #include "langhooks.h"
63 #ifndef TRAMPOLINE_ALIGNMENT
64 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
67 #ifndef LOCAL_ALIGNMENT
68 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT
71 /* Some systems use __main in a way incompatible with its use in gcc, in these
72 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
73 give the same symbol without quotes for an alternative entry point. You
74 must define both, or neither. */
76 #define NAME__MAIN "__main"
79 /* Round a value to the lowest integer less than it that is a multiple of
80 the required alignment. Avoid using division in case the value is
81 negative. Assume the alignment is a power of two. */
82 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
84 /* Similar, but round to the next highest integer that meets the
86 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
88 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
89 during rtl generation. If they are different register numbers, this is
90 always true. It may also be true if
91 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
92 generation. See fix_lexical_addr for details. */
94 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
95 #define NEED_SEPARATE_AP
98 /* Nonzero if function being compiled doesn't contain any calls
99 (ignoring the prologue and epilogue). This is set prior to
100 local register allocation and is valid for the remaining
102 int current_function_is_leaf
;
104 /* Nonzero if function being compiled doesn't contain any instructions
105 that can throw an exception. This is set prior to final. */
107 int current_function_nothrow
;
109 /* Nonzero if function being compiled doesn't modify the stack pointer
110 (ignoring the prologue and epilogue). This is only valid after
111 life_analysis has run. */
112 int current_function_sp_is_unchanging
;
114 /* Nonzero if the function being compiled is a leaf function which only
115 uses leaf registers. This is valid after reload (specifically after
116 sched2) and is useful only if the port defines LEAF_REGISTERS. */
117 int current_function_uses_only_leaf_regs
;
119 /* Nonzero once virtual register instantiation has been done.
120 assign_stack_local uses frame_pointer_rtx when this is nonzero.
121 calls.c:emit_library_call_value_1 uses it to set up
122 post-instantiation libcalls. */
123 int virtuals_instantiated
;
125 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
126 static int funcdef_no
;
128 /* These variables hold pointers to functions to create and destroy
129 target specific, per-function data structures. */
130 struct machine_function
* (*init_machine_status
) PARAMS ((void));
132 /* The FUNCTION_DECL for an inline function currently being expanded. */
133 tree inline_function_decl
;
135 /* The currently compiled function. */
136 struct function
*cfun
= 0;
138 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */
139 static GTY(()) varray_type prologue
;
140 static GTY(()) varray_type epilogue
;
142 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue
144 static GTY(()) varray_type sibcall_epilogue
;
146 /* In order to evaluate some expressions, such as function calls returning
147 structures in memory, we need to temporarily allocate stack locations.
148 We record each allocated temporary in the following structure.
150 Associated with each temporary slot is a nesting level. When we pop up
151 one level, all temporaries associated with the previous level are freed.
152 Normally, all temporaries are freed after the execution of the statement
153 in which they were created. However, if we are inside a ({...}) grouping,
154 the result may be in a temporary and hence must be preserved. If the
155 result could be in a temporary, we preserve it if we can determine which
156 one it is in. If we cannot determine which temporary may contain the
157 result, all temporaries are preserved. A temporary is preserved by
158 pretending it was allocated at the previous nesting level.
160 Automatic variables are also assigned temporary slots, at the nesting
161 level where they are defined. They are marked a "kept" so that
162 free_temp_slots will not free them. */
164 struct temp_slot
GTY(())
166 /* Points to next temporary slot. */
167 struct temp_slot
*next
;
168 /* The rtx to used to reference the slot. */
170 /* The rtx used to represent the address if not the address of the
171 slot above. May be an EXPR_LIST if multiple addresses exist. */
173 /* The alignment (in bits) of the slot. */
175 /* The size, in units, of the slot. */
177 /* The type of the object in the slot, or zero if it doesn't correspond
178 to a type. We use this to determine whether a slot can be reused.
179 It can be reused if objects of the type of the new slot will always
180 conflict with objects of the type of the old slot. */
182 /* The value of `sequence_rtl_expr' when this temporary is allocated. */
184 /* Nonzero if this temporary is currently in use. */
186 /* Nonzero if this temporary has its address taken. */
188 /* Nesting level at which this slot is being used. */
190 /* Nonzero if this should survive a call to free_temp_slots. */
192 /* The offset of the slot from the frame_pointer, including extra space
193 for alignment. This info is for combine_temp_slots. */
194 HOST_WIDE_INT base_offset
;
195 /* The size of the slot, including extra space for alignment. This
196 info is for combine_temp_slots. */
197 HOST_WIDE_INT full_size
;
200 /* This structure is used to record MEMs or pseudos used to replace VAR, any
201 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to
202 maintain this list in case two operands of an insn were required to match;
203 in that case we must ensure we use the same replacement. */
205 struct fixup_replacement
GTY(())
209 struct fixup_replacement
*next
;
212 struct insns_for_mem_entry
216 /* These are the INSNs which reference the MEM. */
220 /* Forward declarations. */
222 static rtx assign_stack_local_1
PARAMS ((enum machine_mode
, HOST_WIDE_INT
,
223 int, struct function
*));
224 static struct temp_slot
*find_temp_slot_from_address
PARAMS ((rtx
));
225 static void put_reg_into_stack
PARAMS ((struct function
*, rtx
, tree
,
226 enum machine_mode
, enum machine_mode
,
227 int, unsigned int, int,
229 static void schedule_fixup_var_refs
PARAMS ((struct function
*, rtx
, tree
,
232 static void fixup_var_refs
PARAMS ((rtx
, enum machine_mode
, int, rtx
,
234 static struct fixup_replacement
235 *find_fixup_replacement
PARAMS ((struct fixup_replacement
**, rtx
));
236 static void fixup_var_refs_insns
PARAMS ((rtx
, rtx
, enum machine_mode
,
238 static void fixup_var_refs_insns_with_hash
239 PARAMS ((htab_t
, rtx
,
240 enum machine_mode
, int, rtx
));
241 static void fixup_var_refs_insn
PARAMS ((rtx
, rtx
, enum machine_mode
,
243 static void fixup_var_refs_1
PARAMS ((rtx
, enum machine_mode
, rtx
*, rtx
,
244 struct fixup_replacement
**, rtx
));
245 static rtx fixup_memory_subreg
PARAMS ((rtx
, rtx
, enum machine_mode
, int));
246 static rtx walk_fixup_memory_subreg
PARAMS ((rtx
, rtx
, enum machine_mode
,
248 static rtx fixup_stack_1
PARAMS ((rtx
, rtx
));
249 static void optimize_bit_field
PARAMS ((rtx
, rtx
, rtx
*));
250 static void instantiate_decls
PARAMS ((tree
, int));
251 static void instantiate_decls_1
PARAMS ((tree
, int));
252 static void instantiate_decl
PARAMS ((rtx
, HOST_WIDE_INT
, int));
253 static rtx instantiate_new_reg
PARAMS ((rtx
, HOST_WIDE_INT
*));
254 static int instantiate_virtual_regs_1
PARAMS ((rtx
*, rtx
, int));
255 static void delete_handlers
PARAMS ((void));
256 static void pad_to_arg_alignment
PARAMS ((struct args_size
*, int,
257 struct args_size
*));
258 static void pad_below
PARAMS ((struct args_size
*, enum machine_mode
,
260 static rtx round_trampoline_addr
PARAMS ((rtx
));
261 static rtx adjust_trampoline_addr
PARAMS ((rtx
));
262 static tree
*identify_blocks_1
PARAMS ((rtx
, tree
*, tree
*, tree
*));
263 static void reorder_blocks_0
PARAMS ((tree
));
264 static void reorder_blocks_1
PARAMS ((rtx
, tree
, varray_type
*));
265 static void reorder_fix_fragments
PARAMS ((tree
));
266 static tree blocks_nreverse
PARAMS ((tree
));
267 static int all_blocks
PARAMS ((tree
, tree
*));
268 static tree
*get_block_vector
PARAMS ((tree
, int *));
269 extern tree debug_find_var_in_block_tree
PARAMS ((tree
, tree
));
270 /* We always define `record_insns' even if its not used so that we
271 can always export `prologue_epilogue_contains'. */
272 static void record_insns
PARAMS ((rtx
, varray_type
*)) ATTRIBUTE_UNUSED
;
273 static int contains
PARAMS ((rtx
, varray_type
));
275 static void emit_return_into_block
PARAMS ((basic_block
, rtx
));
277 static void put_addressof_into_stack
PARAMS ((rtx
, htab_t
));
278 static bool purge_addressof_1
PARAMS ((rtx
*, rtx
, int, int,
280 static void purge_single_hard_subreg_set
PARAMS ((rtx
));
281 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
282 static rtx keep_stack_depressed
PARAMS ((rtx
));
284 static int is_addressof
PARAMS ((rtx
*, void *));
285 static hashval_t insns_for_mem_hash
PARAMS ((const void *));
286 static int insns_for_mem_comp
PARAMS ((const void *, const void *));
287 static int insns_for_mem_walk
PARAMS ((rtx
*, void *));
288 static void compute_insns_for_mem
PARAMS ((rtx
, rtx
, htab_t
));
289 static void prepare_function_start
PARAMS ((void));
290 static void do_clobber_return_reg
PARAMS ((rtx
, void *));
291 static void do_use_return_reg
PARAMS ((rtx
, void *));
293 /* Pointer to chain of `struct function' for containing functions. */
294 static GTY(()) struct function
*outer_function_chain
;
296 /* Given a function decl for a containing function,
297 return the `struct function' for it. */
300 find_function_data (decl
)
305 for (p
= outer_function_chain
; p
; p
= p
->outer
)
312 /* Save the current context for compilation of a nested function.
313 This is called from language-specific code. The caller should use
314 the enter_nested langhook to save any language-specific state,
315 since this function knows only about language-independent
319 push_function_context_to (context
)
326 if (context
== current_function_decl
)
327 cfun
->contains_functions
= 1;
330 struct function
*containing
= find_function_data (context
);
331 containing
->contains_functions
= 1;
336 init_dummy_function_start ();
339 p
->outer
= outer_function_chain
;
340 outer_function_chain
= p
;
341 p
->fixup_var_refs_queue
= 0;
343 (*lang_hooks
.function
.enter_nested
) (p
);
349 push_function_context ()
351 push_function_context_to (current_function_decl
);
354 /* Restore the last saved context, at the end of a nested function.
355 This function is called from language-specific code. */
358 pop_function_context_from (context
)
359 tree context ATTRIBUTE_UNUSED
;
361 struct function
*p
= outer_function_chain
;
362 struct var_refs_queue
*queue
;
365 outer_function_chain
= p
->outer
;
367 current_function_decl
= p
->decl
;
370 restore_emit_status (p
);
372 (*lang_hooks
.function
.leave_nested
) (p
);
374 /* Finish doing put_var_into_stack for any of our variables which became
375 addressable during the nested function. If only one entry has to be
376 fixed up, just do that one. Otherwise, first make a list of MEMs that
377 are not to be unshared. */
378 if (p
->fixup_var_refs_queue
== 0)
380 else if (p
->fixup_var_refs_queue
->next
== 0)
381 fixup_var_refs (p
->fixup_var_refs_queue
->modified
,
382 p
->fixup_var_refs_queue
->promoted_mode
,
383 p
->fixup_var_refs_queue
->unsignedp
,
384 p
->fixup_var_refs_queue
->modified
, 0);
389 for (queue
= p
->fixup_var_refs_queue
; queue
; queue
= queue
->next
)
390 list
= gen_rtx_EXPR_LIST (VOIDmode
, queue
->modified
, list
);
392 for (queue
= p
->fixup_var_refs_queue
; queue
; queue
= queue
->next
)
393 fixup_var_refs (queue
->modified
, queue
->promoted_mode
,
394 queue
->unsignedp
, list
, 0);
398 p
->fixup_var_refs_queue
= 0;
400 /* Reset variables that have known state during rtx generation. */
401 rtx_equal_function_value_matters
= 1;
402 virtuals_instantiated
= 0;
403 generating_concat_p
= 1;
407 pop_function_context ()
409 pop_function_context_from (current_function_decl
);
412 /* Clear out all parts of the state in F that can safely be discarded
413 after the function has been parsed, but not compiled, to let
414 garbage collection reclaim the memory. */
417 free_after_parsing (f
)
420 /* f->expr->forced_labels is used by code generation. */
421 /* f->emit->regno_reg_rtx is used by code generation. */
422 /* f->varasm is used by code generation. */
423 /* f->eh->eh_return_stub_label is used by code generation. */
425 (*lang_hooks
.function
.final
) (f
);
429 /* Clear out all parts of the state in F that can safely be discarded
430 after the function has been compiled, to let garbage collection
431 reclaim the memory. */
434 free_after_compilation (f
)
443 f
->x_temp_slots
= NULL
;
444 f
->arg_offset_rtx
= NULL
;
445 f
->return_rtx
= NULL
;
446 f
->internal_arg_pointer
= NULL
;
447 f
->x_nonlocal_labels
= NULL
;
448 f
->x_nonlocal_goto_handler_slots
= NULL
;
449 f
->x_nonlocal_goto_handler_labels
= NULL
;
450 f
->x_nonlocal_goto_stack_level
= NULL
;
451 f
->x_cleanup_label
= NULL
;
452 f
->x_return_label
= NULL
;
453 f
->x_save_expr_regs
= NULL
;
454 f
->x_stack_slot_list
= NULL
;
455 f
->x_rtl_expr_chain
= NULL
;
456 f
->x_tail_recursion_label
= NULL
;
457 f
->x_tail_recursion_reentry
= NULL
;
458 f
->x_arg_pointer_save_area
= NULL
;
459 f
->x_clobber_return_insn
= NULL
;
460 f
->x_context_display
= NULL
;
461 f
->x_trampoline_list
= NULL
;
462 f
->x_parm_birth_insn
= NULL
;
463 f
->x_last_parm_insn
= NULL
;
464 f
->x_parm_reg_stack_loc
= NULL
;
465 f
->fixup_var_refs_queue
= NULL
;
466 f
->original_arg_vector
= NULL
;
467 f
->original_decl_initial
= NULL
;
468 f
->inl_last_parm_insn
= NULL
;
469 f
->epilogue_delay_list
= NULL
;
472 /* Allocate fixed slots in the stack frame of the current function. */
474 /* Return size needed for stack frame based on slots so far allocated in
476 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
477 the caller may have to do that. */
480 get_func_frame_size (f
)
483 #ifdef FRAME_GROWS_DOWNWARD
484 return -f
->x_frame_offset
;
486 return f
->x_frame_offset
;
490 /* Return size needed for stack frame based on slots so far allocated.
491 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
492 the caller may have to do that. */
496 return get_func_frame_size (cfun
);
499 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
500 with machine mode MODE.
502 ALIGN controls the amount of alignment for the address of the slot:
503 0 means according to MODE,
504 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
505 positive specifies alignment boundary in bits.
507 We do not round to stack_boundary here.
509 FUNCTION specifies the function to allocate in. */
512 assign_stack_local_1 (mode
, size
, align
, function
)
513 enum machine_mode mode
;
516 struct function
*function
;
519 int bigend_correction
= 0;
521 int frame_off
, frame_alignment
, frame_phase
;
528 alignment
= BIGGEST_ALIGNMENT
;
530 alignment
= GET_MODE_ALIGNMENT (mode
);
532 /* Allow the target to (possibly) increase the alignment of this
534 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 0);
536 alignment
= LOCAL_ALIGNMENT (type
, alignment
);
538 alignment
/= BITS_PER_UNIT
;
540 else if (align
== -1)
542 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
543 size
= CEIL_ROUND (size
, alignment
);
546 alignment
= align
/ BITS_PER_UNIT
;
548 #ifdef FRAME_GROWS_DOWNWARD
549 function
->x_frame_offset
-= size
;
552 /* Ignore alignment we can't do with expected alignment of the boundary. */
553 if (alignment
* BITS_PER_UNIT
> PREFERRED_STACK_BOUNDARY
)
554 alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
556 if (function
->stack_alignment_needed
< alignment
* BITS_PER_UNIT
)
557 function
->stack_alignment_needed
= alignment
* BITS_PER_UNIT
;
559 /* Calculate how many bytes the start of local variables is off from
561 frame_alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
562 frame_off
= STARTING_FRAME_OFFSET
% frame_alignment
;
563 frame_phase
= frame_off
? frame_alignment
- frame_off
: 0;
565 /* Round frame offset to that alignment.
566 We must be careful here, since FRAME_OFFSET might be negative and
567 division with a negative dividend isn't as well defined as we might
568 like. So we instead assume that ALIGNMENT is a power of two and
569 use logical operations which are unambiguous. */
570 #ifdef FRAME_GROWS_DOWNWARD
571 function
->x_frame_offset
= FLOOR_ROUND (function
->x_frame_offset
- frame_phase
, alignment
) + frame_phase
;
573 function
->x_frame_offset
= CEIL_ROUND (function
->x_frame_offset
- frame_phase
, alignment
) + frame_phase
;
576 /* On a big-endian machine, if we are allocating more space than we will use,
577 use the least significant bytes of those that are allocated. */
578 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
)
579 bigend_correction
= size
- GET_MODE_SIZE (mode
);
581 /* If we have already instantiated virtual registers, return the actual
582 address relative to the frame pointer. */
583 if (function
== cfun
&& virtuals_instantiated
)
584 addr
= plus_constant (frame_pointer_rtx
,
585 (frame_offset
+ bigend_correction
586 + STARTING_FRAME_OFFSET
));
588 addr
= plus_constant (virtual_stack_vars_rtx
,
589 function
->x_frame_offset
+ bigend_correction
);
591 #ifndef FRAME_GROWS_DOWNWARD
592 function
->x_frame_offset
+= size
;
595 x
= gen_rtx_MEM (mode
, addr
);
597 function
->x_stack_slot_list
598 = gen_rtx_EXPR_LIST (VOIDmode
, x
, function
->x_stack_slot_list
);
603 /* Wrapper around assign_stack_local_1; assign a local stack slot for the
607 assign_stack_local (mode
, size
, align
)
608 enum machine_mode mode
;
612 return assign_stack_local_1 (mode
, size
, align
, cfun
);
615 /* Allocate a temporary stack slot and record it for possible later
618 MODE is the machine mode to be given to the returned rtx.
620 SIZE is the size in units of the space required. We do no rounding here
621 since assign_stack_local will do any required rounding.
623 KEEP is 1 if this slot is to be retained after a call to
624 free_temp_slots. Automatic variables for a block are allocated
625 with this flag. KEEP is 2 if we allocate a longer term temporary,
626 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3
627 if we are to allocate something at an inner level to be treated as
628 a variable in the block (e.g., a SAVE_EXPR).
630 TYPE is the type that will be used for the stack slot. */
633 assign_stack_temp_for_type (mode
, size
, keep
, type
)
634 enum machine_mode mode
;
640 struct temp_slot
*p
, *best_p
= 0;
643 /* If SIZE is -1 it means that somebody tried to allocate a temporary
644 of a variable size. */
649 align
= BIGGEST_ALIGNMENT
;
651 align
= GET_MODE_ALIGNMENT (mode
);
654 type
= (*lang_hooks
.types
.type_for_mode
) (mode
, 0);
657 align
= LOCAL_ALIGNMENT (type
, align
);
659 /* Try to find an available, already-allocated temporary of the proper
660 mode which meets the size and alignment requirements. Choose the
661 smallest one with the closest alignment. */
662 for (p
= temp_slots
; p
; p
= p
->next
)
663 if (p
->align
>= align
&& p
->size
>= size
&& GET_MODE (p
->slot
) == mode
665 && objects_must_conflict_p (p
->type
, type
)
666 && (best_p
== 0 || best_p
->size
> p
->size
667 || (best_p
->size
== p
->size
&& best_p
->align
> p
->align
)))
669 if (p
->align
== align
&& p
->size
== size
)
677 /* Make our best, if any, the one to use. */
680 /* If there are enough aligned bytes left over, make them into a new
681 temp_slot so that the extra bytes don't get wasted. Do this only
682 for BLKmode slots, so that we can be sure of the alignment. */
683 if (GET_MODE (best_p
->slot
) == BLKmode
)
685 int alignment
= best_p
->align
/ BITS_PER_UNIT
;
686 HOST_WIDE_INT rounded_size
= CEIL_ROUND (size
, alignment
);
688 if (best_p
->size
- rounded_size
>= alignment
)
690 p
= (struct temp_slot
*) ggc_alloc (sizeof (struct temp_slot
));
691 p
->in_use
= p
->addr_taken
= 0;
692 p
->size
= best_p
->size
- rounded_size
;
693 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
694 p
->full_size
= best_p
->full_size
- rounded_size
;
695 p
->slot
= gen_rtx_MEM (BLKmode
,
696 plus_constant (XEXP (best_p
->slot
, 0),
698 p
->align
= best_p
->align
;
701 p
->type
= best_p
->type
;
702 p
->next
= temp_slots
;
705 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, p
->slot
,
708 best_p
->size
= rounded_size
;
709 best_p
->full_size
= rounded_size
;
716 /* If we still didn't find one, make a new temporary. */
719 HOST_WIDE_INT frame_offset_old
= frame_offset
;
721 p
= (struct temp_slot
*) ggc_alloc (sizeof (struct temp_slot
));
723 /* We are passing an explicit alignment request to assign_stack_local.
724 One side effect of that is assign_stack_local will not round SIZE
725 to ensure the frame offset remains suitably aligned.
727 So for requests which depended on the rounding of SIZE, we go ahead
728 and round it now. We also make sure ALIGNMENT is at least
729 BIGGEST_ALIGNMENT. */
730 if (mode
== BLKmode
&& align
< BIGGEST_ALIGNMENT
)
732 p
->slot
= assign_stack_local (mode
,
734 ? CEIL_ROUND (size
, align
/ BITS_PER_UNIT
)
740 /* The following slot size computation is necessary because we don't
741 know the actual size of the temporary slot until assign_stack_local
742 has performed all the frame alignment and size rounding for the
743 requested temporary. Note that extra space added for alignment
744 can be either above or below this stack slot depending on which
745 way the frame grows. We include the extra space if and only if it
746 is above this slot. */
747 #ifdef FRAME_GROWS_DOWNWARD
748 p
->size
= frame_offset_old
- frame_offset
;
753 /* Now define the fields used by combine_temp_slots. */
754 #ifdef FRAME_GROWS_DOWNWARD
755 p
->base_offset
= frame_offset
;
756 p
->full_size
= frame_offset_old
- frame_offset
;
758 p
->base_offset
= frame_offset_old
;
759 p
->full_size
= frame_offset
- frame_offset_old
;
762 p
->next
= temp_slots
;
768 p
->rtl_expr
= seq_rtl_expr
;
773 p
->level
= target_temp_slot_level
;
778 p
->level
= var_temp_slot_level
;
783 p
->level
= temp_slot_level
;
788 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
789 slot
= gen_rtx_MEM (mode
, XEXP (p
->slot
, 0));
790 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, slot
, stack_slot_list
);
792 /* If we know the alias set for the memory that will be used, use
793 it. If there's no TYPE, then we don't know anything about the
794 alias set for the memory. */
795 set_mem_alias_set (slot
, type
? get_alias_set (type
) : 0);
796 set_mem_align (slot
, align
);
798 /* If a type is specified, set the relevant flags. */
801 RTX_UNCHANGING_P (slot
) = (lang_hooks
.honor_readonly
802 && TYPE_READONLY (type
));
803 MEM_VOLATILE_P (slot
) = TYPE_VOLATILE (type
);
804 MEM_SET_IN_STRUCT_P (slot
, AGGREGATE_TYPE_P (type
));
810 /* Allocate a temporary stack slot and record it for possible later
811 reuse. First three arguments are same as in preceding function. */
814 assign_stack_temp (mode
, size
, keep
)
815 enum machine_mode mode
;
819 return assign_stack_temp_for_type (mode
, size
, keep
, NULL_TREE
);
822 /* Assign a temporary.
823 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
824 and so that should be used in error messages. In either case, we
825 allocate of the given type.
826 KEEP is as for assign_stack_temp.
827 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
828 it is 0 if a register is OK.
829 DONT_PROMOTE is 1 if we should not promote values in register
833 assign_temp (type_or_decl
, keep
, memory_required
, dont_promote
)
837 int dont_promote ATTRIBUTE_UNUSED
;
840 enum machine_mode mode
;
841 #ifndef PROMOTE_FOR_CALL_ONLY
845 if (DECL_P (type_or_decl
))
846 decl
= type_or_decl
, type
= TREE_TYPE (decl
);
848 decl
= NULL
, type
= type_or_decl
;
850 mode
= TYPE_MODE (type
);
851 #ifndef PROMOTE_FOR_CALL_ONLY
852 unsignedp
= TREE_UNSIGNED (type
);
855 if (mode
== BLKmode
|| memory_required
)
857 HOST_WIDE_INT size
= int_size_in_bytes (type
);
860 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
861 problems with allocating the stack space. */
865 /* Unfortunately, we don't yet know how to allocate variable-sized
866 temporaries. However, sometimes we have a fixed upper limit on
867 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that
868 instead. This is the case for Chill variable-sized strings. */
869 if (size
== -1 && TREE_CODE (type
) == ARRAY_TYPE
870 && TYPE_ARRAY_MAX_SIZE (type
) != NULL_TREE
871 && host_integerp (TYPE_ARRAY_MAX_SIZE (type
), 1))
872 size
= tree_low_cst (TYPE_ARRAY_MAX_SIZE (type
), 1);
874 /* The size of the temporary may be too large to fit into an integer. */
875 /* ??? Not sure this should happen except for user silliness, so limit
876 this to things that aren't compiler-generated temporaries. The
877 rest of the time we'll abort in assign_stack_temp_for_type. */
878 if (decl
&& size
== -1
879 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
)
881 error_with_decl (decl
, "size of variable `%s' is too large");
885 tmp
= assign_stack_temp_for_type (mode
, size
, keep
, type
);
889 #ifndef PROMOTE_FOR_CALL_ONLY
891 mode
= promote_mode (type
, mode
, &unsignedp
, 0);
894 return gen_reg_rtx (mode
);
897 /* Combine temporary stack slots which are adjacent on the stack.
899 This allows for better use of already allocated stack space. This is only
900 done for BLKmode slots because we can be sure that we won't have alignment
901 problems in this case. */
904 combine_temp_slots ()
906 struct temp_slot
*p
, *q
;
907 struct temp_slot
*prev_p
, *prev_q
;
910 /* We can't combine slots, because the information about which slot
911 is in which alias set will be lost. */
912 if (flag_strict_aliasing
)
915 /* If there are a lot of temp slots, don't do anything unless
916 high levels of optimization. */
917 if (! flag_expensive_optimizations
)
918 for (p
= temp_slots
, num_slots
= 0; p
; p
= p
->next
, num_slots
++)
919 if (num_slots
> 100 || (num_slots
> 10 && optimize
== 0))
922 for (p
= temp_slots
, prev_p
= 0; p
; p
= prev_p
? prev_p
->next
: temp_slots
)
926 if (! p
->in_use
&& GET_MODE (p
->slot
) == BLKmode
)
927 for (q
= p
->next
, prev_q
= p
; q
; q
= prev_q
->next
)
930 if (! q
->in_use
&& GET_MODE (q
->slot
) == BLKmode
)
932 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
934 /* Q comes after P; combine Q into P. */
936 p
->full_size
+= q
->full_size
;
939 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
941 /* P comes after Q; combine P into Q. */
943 q
->full_size
+= p
->full_size
;
948 /* Either delete Q or advance past it. */
950 prev_q
->next
= q
->next
;
954 /* Either delete P or advance past it. */
958 prev_p
->next
= p
->next
;
960 temp_slots
= p
->next
;
967 /* Find the temp slot corresponding to the object at address X. */
969 static struct temp_slot
*
970 find_temp_slot_from_address (x
)
976 for (p
= temp_slots
; p
; p
= p
->next
)
981 else if (XEXP (p
->slot
, 0) == x
983 || (GET_CODE (x
) == PLUS
984 && XEXP (x
, 0) == virtual_stack_vars_rtx
985 && GET_CODE (XEXP (x
, 1)) == CONST_INT
986 && INTVAL (XEXP (x
, 1)) >= p
->base_offset
987 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
))
990 else if (p
->address
!= 0 && GET_CODE (p
->address
) == EXPR_LIST
)
991 for (next
= p
->address
; next
; next
= XEXP (next
, 1))
992 if (XEXP (next
, 0) == x
)
996 /* If we have a sum involving a register, see if it points to a temp
998 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 0)) == REG
999 && (p
= find_temp_slot_from_address (XEXP (x
, 0))) != 0)
1001 else if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == REG
1002 && (p
= find_temp_slot_from_address (XEXP (x
, 1))) != 0)
1008 /* Indicate that NEW is an alternate way of referring to the temp slot
1009 that previously was known by OLD. */
1012 update_temp_slot_address (old
, new)
1015 struct temp_slot
*p
;
1017 if (rtx_equal_p (old
, new))
1020 p
= find_temp_slot_from_address (old
);
1022 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW
1023 is a register, see if one operand of the PLUS is a temporary
1024 location. If so, NEW points into it. Otherwise, if both OLD and
1025 NEW are a PLUS and if there is a register in common between them.
1026 If so, try a recursive call on those values. */
1029 if (GET_CODE (old
) != PLUS
)
1032 if (GET_CODE (new) == REG
)
1034 update_temp_slot_address (XEXP (old
, 0), new);
1035 update_temp_slot_address (XEXP (old
, 1), new);
1038 else if (GET_CODE (new) != PLUS
)
1041 if (rtx_equal_p (XEXP (old
, 0), XEXP (new, 0)))
1042 update_temp_slot_address (XEXP (old
, 1), XEXP (new, 1));
1043 else if (rtx_equal_p (XEXP (old
, 1), XEXP (new, 0)))
1044 update_temp_slot_address (XEXP (old
, 0), XEXP (new, 1));
1045 else if (rtx_equal_p (XEXP (old
, 0), XEXP (new, 1)))
1046 update_temp_slot_address (XEXP (old
, 1), XEXP (new, 0));
1047 else if (rtx_equal_p (XEXP (old
, 1), XEXP (new, 1)))
1048 update_temp_slot_address (XEXP (old
, 0), XEXP (new, 0));
1053 /* Otherwise add an alias for the temp's address. */
1054 else if (p
->address
== 0)
1058 if (GET_CODE (p
->address
) != EXPR_LIST
)
1059 p
->address
= gen_rtx_EXPR_LIST (VOIDmode
, p
->address
, NULL_RTX
);
1061 p
->address
= gen_rtx_EXPR_LIST (VOIDmode
, new, p
->address
);
1065 /* If X could be a reference to a temporary slot, mark the fact that its
1066 address was taken. */
1069 mark_temp_addr_taken (x
)
1072 struct temp_slot
*p
;
1077 /* If X is not in memory or is at a constant address, it cannot be in
1078 a temporary slot. */
1079 if (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1082 p
= find_temp_slot_from_address (XEXP (x
, 0));
1087 /* If X could be a reference to a temporary slot, mark that slot as
1088 belonging to the to one level higher than the current level. If X
1089 matched one of our slots, just mark that one. Otherwise, we can't
1090 easily predict which it is, so upgrade all of them. Kept slots
1091 need not be touched.
1093 This is called when an ({...}) construct occurs and a statement
1094 returns a value in memory. */
1097 preserve_temp_slots (x
)
1100 struct temp_slot
*p
= 0;
1102 /* If there is no result, we still might have some objects whose address
1103 were taken, so we need to make sure they stay around. */
1106 for (p
= temp_slots
; p
; p
= p
->next
)
1107 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1113 /* If X is a register that is being used as a pointer, see if we have
1114 a temporary slot we know it points to. To be consistent with
1115 the code below, we really should preserve all non-kept slots
1116 if we can't find a match, but that seems to be much too costly. */
1117 if (GET_CODE (x
) == REG
&& REG_POINTER (x
))
1118 p
= find_temp_slot_from_address (x
);
1120 /* If X is not in memory or is at a constant address, it cannot be in
1121 a temporary slot, but it can contain something whose address was
1123 if (p
== 0 && (GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0))))
1125 for (p
= temp_slots
; p
; p
= p
->next
)
1126 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->addr_taken
)
1132 /* First see if we can find a match. */
1134 p
= find_temp_slot_from_address (XEXP (x
, 0));
1138 /* Move everything at our level whose address was taken to our new
1139 level in case we used its address. */
1140 struct temp_slot
*q
;
1142 if (p
->level
== temp_slot_level
)
1144 for (q
= temp_slots
; q
; q
= q
->next
)
1145 if (q
!= p
&& q
->addr_taken
&& q
->level
== p
->level
)
1154 /* Otherwise, preserve all non-kept slots at this level. */
1155 for (p
= temp_slots
; p
; p
= p
->next
)
1156 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
)
1160 /* X is the result of an RTL_EXPR. If it is a temporary slot associated
1161 with that RTL_EXPR, promote it into a temporary slot at the present
1162 level so it will not be freed when we free slots made in the
1166 preserve_rtl_expr_result (x
)
1169 struct temp_slot
*p
;
1171 /* If X is not in memory or is at a constant address, it cannot be in
1172 a temporary slot. */
1173 if (x
== 0 || GET_CODE (x
) != MEM
|| CONSTANT_P (XEXP (x
, 0)))
1176 /* If we can find a match, move it to our level unless it is already at
1178 p
= find_temp_slot_from_address (XEXP (x
, 0));
1181 p
->level
= MIN (p
->level
, temp_slot_level
);
1188 /* Free all temporaries used so far. This is normally called at the end
1189 of generating code for a statement. Don't free any temporaries
1190 currently in use for an RTL_EXPR that hasn't yet been emitted.
1191 We could eventually do better than this since it can be reused while
1192 generating the same RTL_EXPR, but this is complex and probably not
1198 struct temp_slot
*p
;
1200 for (p
= temp_slots
; p
; p
= p
->next
)
1201 if (p
->in_use
&& p
->level
== temp_slot_level
&& ! p
->keep
1202 && p
->rtl_expr
== 0)
1205 combine_temp_slots ();
1208 /* Free all temporary slots used in T, an RTL_EXPR node. */
1211 free_temps_for_rtl_expr (t
)
1214 struct temp_slot
*p
;
1216 for (p
= temp_slots
; p
; p
= p
->next
)
1217 if (p
->rtl_expr
== t
)
1219 /* If this slot is below the current TEMP_SLOT_LEVEL, then it
1220 needs to be preserved. This can happen if a temporary in
1221 the RTL_EXPR was addressed; preserve_temp_slots will move
1222 the temporary into a higher level. */
1223 if (temp_slot_level
<= p
->level
)
1226 p
->rtl_expr
= NULL_TREE
;
1229 combine_temp_slots ();
1232 /* Mark all temporaries ever allocated in this function as not suitable
1233 for reuse until the current level is exited. */
1236 mark_all_temps_used ()
1238 struct temp_slot
*p
;
1240 for (p
= temp_slots
; p
; p
= p
->next
)
1242 p
->in_use
= p
->keep
= 1;
1243 p
->level
= MIN (p
->level
, temp_slot_level
);
1247 /* Push deeper into the nesting level for stack temporaries. */
1255 /* Likewise, but save the new level as the place to allocate variables
1260 push_temp_slots_for_block ()
1264 var_temp_slot_level
= temp_slot_level
;
1267 /* Likewise, but save the new level as the place to allocate temporaries
1268 for TARGET_EXPRs. */
1271 push_temp_slots_for_target ()
1275 target_temp_slot_level
= temp_slot_level
;
1278 /* Set and get the value of target_temp_slot_level. The only
1279 permitted use of these functions is to save and restore this value. */
1282 get_target_temp_slot_level ()
1284 return target_temp_slot_level
;
1288 set_target_temp_slot_level (level
)
1291 target_temp_slot_level
= level
;
1295 /* Pop a temporary nesting level. All slots in use in the current level
1301 struct temp_slot
*p
;
1303 for (p
= temp_slots
; p
; p
= p
->next
)
1304 if (p
->in_use
&& p
->level
== temp_slot_level
&& p
->rtl_expr
== 0)
1307 combine_temp_slots ();
1312 /* Initialize temporary slots. */
1317 /* We have not allocated any temporaries yet. */
1319 temp_slot_level
= 0;
1320 var_temp_slot_level
= 0;
1321 target_temp_slot_level
= 0;
1324 /* Retroactively move an auto variable from a register to a stack slot.
1325 This is done when an address-reference to the variable is seen. */
1328 put_var_into_stack (decl
)
1332 enum machine_mode promoted_mode
, decl_mode
;
1333 struct function
*function
= 0;
1335 int can_use_addressof
;
1336 int volatilep
= TREE_CODE (decl
) != SAVE_EXPR
&& TREE_THIS_VOLATILE (decl
);
1337 int usedp
= (TREE_USED (decl
)
1338 || (TREE_CODE (decl
) != SAVE_EXPR
&& DECL_INITIAL (decl
) != 0));
1340 context
= decl_function_context (decl
);
1342 /* Get the current rtl used for this object and its original mode. */
1343 reg
= (TREE_CODE (decl
) == SAVE_EXPR
1344 ? SAVE_EXPR_RTL (decl
)
1345 : DECL_RTL_IF_SET (decl
));
1347 /* No need to do anything if decl has no rtx yet
1348 since in that case caller is setting TREE_ADDRESSABLE
1349 and a stack slot will be assigned when the rtl is made. */
1353 /* Get the declared mode for this object. */
1354 decl_mode
= (TREE_CODE (decl
) == SAVE_EXPR
? TYPE_MODE (TREE_TYPE (decl
))
1355 : DECL_MODE (decl
));
1356 /* Get the mode it's actually stored in. */
1357 promoted_mode
= GET_MODE (reg
);
1359 /* If this variable comes from an outer function, find that
1360 function's saved context. Don't use find_function_data here,
1361 because it might not be in any active function.
1362 FIXME: Is that really supposed to happen?
1363 It does in ObjC at least. */
1364 if (context
!= current_function_decl
&& context
!= inline_function_decl
)
1365 for (function
= outer_function_chain
; function
; function
= function
->outer
)
1366 if (function
->decl
== context
)
1369 /* If this is a variable-size object with a pseudo to address it,
1370 put that pseudo into the stack, if the var is nonlocal. */
1371 if (TREE_CODE (decl
) != SAVE_EXPR
&& DECL_NONLOCAL (decl
)
1372 && GET_CODE (reg
) == MEM
1373 && GET_CODE (XEXP (reg
, 0)) == REG
1374 && REGNO (XEXP (reg
, 0)) > LAST_VIRTUAL_REGISTER
)
1376 reg
= XEXP (reg
, 0);
1377 decl_mode
= promoted_mode
= GET_MODE (reg
);
1383 /* FIXME make it work for promoted modes too */
1384 && decl_mode
== promoted_mode
1385 #ifdef NON_SAVING_SETJMP
1386 && ! (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
1390 /* If we can't use ADDRESSOF, make sure we see through one we already
1392 if (! can_use_addressof
&& GET_CODE (reg
) == MEM
1393 && GET_CODE (XEXP (reg
, 0)) == ADDRESSOF
)
1394 reg
= XEXP (XEXP (reg
, 0), 0);
1396 /* Now we should have a value that resides in one or more pseudo regs. */
1398 if (GET_CODE (reg
) == REG
)
1400 /* If this variable lives in the current function and we don't need
1401 to put things in the stack for the sake of setjmp, try to keep it
1402 in a register until we know we actually need the address. */
1403 if (can_use_addressof
)
1404 gen_mem_addressof (reg
, decl
);
1406 put_reg_into_stack (function
, reg
, TREE_TYPE (decl
), promoted_mode
,
1407 decl_mode
, volatilep
, 0, usedp
, 0);
1409 else if (GET_CODE (reg
) == CONCAT
)
1411 /* A CONCAT contains two pseudos; put them both in the stack.
1412 We do it so they end up consecutive.
1413 We fixup references to the parts only after we fixup references
1414 to the whole CONCAT, lest we do double fixups for the latter
1416 enum machine_mode part_mode
= GET_MODE (XEXP (reg
, 0));
1417 tree part_type
= (*lang_hooks
.types
.type_for_mode
) (part_mode
, 0);
1418 rtx lopart
= XEXP (reg
, 0);
1419 rtx hipart
= XEXP (reg
, 1);
1420 #ifdef FRAME_GROWS_DOWNWARD
1421 /* Since part 0 should have a lower address, do it second. */
1422 put_reg_into_stack (function
, hipart
, part_type
, part_mode
,
1423 part_mode
, volatilep
, 0, 0, 0);
1424 put_reg_into_stack (function
, lopart
, part_type
, part_mode
,
1425 part_mode
, volatilep
, 0, 0, 0);
1427 put_reg_into_stack (function
, lopart
, part_type
, part_mode
,
1428 part_mode
, volatilep
, 0, 0, 0);
1429 put_reg_into_stack (function
, hipart
, part_type
, part_mode
,
1430 part_mode
, volatilep
, 0, 0, 0);
1433 /* Change the CONCAT into a combined MEM for both parts. */
1434 PUT_CODE (reg
, MEM
);
1435 MEM_ATTRS (reg
) = 0;
1437 /* set_mem_attributes uses DECL_RTL to avoid re-generating of
1438 already computed alias sets. Here we want to re-generate. */
1440 SET_DECL_RTL (decl
, NULL
);
1441 set_mem_attributes (reg
, decl
, 1);
1443 SET_DECL_RTL (decl
, reg
);
1445 /* The two parts are in memory order already.
1446 Use the lower parts address as ours. */
1447 XEXP (reg
, 0) = XEXP (XEXP (reg
, 0), 0);
1448 /* Prevent sharing of rtl that might lose. */
1449 if (GET_CODE (XEXP (reg
, 0)) == PLUS
)
1450 XEXP (reg
, 0) = copy_rtx (XEXP (reg
, 0));
1453 schedule_fixup_var_refs (function
, reg
, TREE_TYPE (decl
),
1455 schedule_fixup_var_refs (function
, lopart
, part_type
, part_mode
, 0);
1456 schedule_fixup_var_refs (function
, hipart
, part_type
, part_mode
, 0);
1463 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG
1464 into the stack frame of FUNCTION (0 means the current function).
1465 DECL_MODE is the machine mode of the user-level data type.
1466 PROMOTED_MODE is the machine mode of the register.
1467 VOLATILE_P is nonzero if this is for a "volatile" decl.
1468 USED_P is nonzero if this reg might have already been used in an insn. */
1471 put_reg_into_stack (function
, reg
, type
, promoted_mode
, decl_mode
, volatile_p
,
1472 original_regno
, used_p
, ht
)
1473 struct function
*function
;
1476 enum machine_mode promoted_mode
, decl_mode
;
1478 unsigned int original_regno
;
1482 struct function
*func
= function
? function
: cfun
;
1484 unsigned int regno
= original_regno
;
1487 regno
= REGNO (reg
);
1489 if (regno
< func
->x_max_parm_reg
)
1490 new = func
->x_parm_reg_stack_loc
[regno
];
1493 new = assign_stack_local_1 (decl_mode
, GET_MODE_SIZE (decl_mode
), 0, func
);
1495 PUT_CODE (reg
, MEM
);
1496 PUT_MODE (reg
, decl_mode
);
1497 XEXP (reg
, 0) = XEXP (new, 0);
1498 MEM_ATTRS (reg
) = 0;
1499 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */
1500 MEM_VOLATILE_P (reg
) = volatile_p
;
1502 /* If this is a memory ref that contains aggregate components,
1503 mark it as such for cse and loop optimize. If we are reusing a
1504 previously generated stack slot, then we need to copy the bit in
1505 case it was set for other reasons. For instance, it is set for
1506 __builtin_va_alist. */
1509 MEM_SET_IN_STRUCT_P (reg
,
1510 AGGREGATE_TYPE_P (type
) || MEM_IN_STRUCT_P (new));
1511 set_mem_alias_set (reg
, get_alias_set (type
));
1515 schedule_fixup_var_refs (function
, reg
, type
, promoted_mode
, ht
);
1518 /* Make sure that all refs to the variable, previously made
1519 when it was a register, are fixed up to be valid again.
1520 See function above for meaning of arguments. */
1523 schedule_fixup_var_refs (function
, reg
, type
, promoted_mode
, ht
)
1524 struct function
*function
;
1527 enum machine_mode promoted_mode
;
1530 int unsigned_p
= type
? TREE_UNSIGNED (type
) : 0;
1534 struct var_refs_queue
*temp
;
1537 = (struct var_refs_queue
*) ggc_alloc (sizeof (struct var_refs_queue
));
1538 temp
->modified
= reg
;
1539 temp
->promoted_mode
= promoted_mode
;
1540 temp
->unsignedp
= unsigned_p
;
1541 temp
->next
= function
->fixup_var_refs_queue
;
1542 function
->fixup_var_refs_queue
= temp
;
1545 /* Variable is local; fix it up now. */
1546 fixup_var_refs (reg
, promoted_mode
, unsigned_p
, reg
, ht
);
1550 fixup_var_refs (var
, promoted_mode
, unsignedp
, may_share
, ht
)
1552 enum machine_mode promoted_mode
;
1558 rtx first_insn
= get_insns ();
1559 struct sequence_stack
*stack
= seq_stack
;
1560 tree rtl_exps
= rtl_expr_chain
;
1562 /* If there's a hash table, it must record all uses of VAR. */
1567 fixup_var_refs_insns_with_hash (ht
, var
, promoted_mode
, unsignedp
,
1572 fixup_var_refs_insns (first_insn
, var
, promoted_mode
, unsignedp
,
1573 stack
== 0, may_share
);
1575 /* Scan all pending sequences too. */
1576 for (; stack
; stack
= stack
->next
)
1578 push_to_full_sequence (stack
->first
, stack
->last
);
1579 fixup_var_refs_insns (stack
->first
, var
, promoted_mode
, unsignedp
,
1580 stack
->next
!= 0, may_share
);
1581 /* Update remembered end of sequence
1582 in case we added an insn at the end. */
1583 stack
->last
= get_last_insn ();
1587 /* Scan all waiting RTL_EXPRs too. */
1588 for (pending
= rtl_exps
; pending
; pending
= TREE_CHAIN (pending
))
1590 rtx seq
= RTL_EXPR_SEQUENCE (TREE_VALUE (pending
));
1591 if (seq
!= const0_rtx
&& seq
!= 0)
1593 push_to_sequence (seq
);
1594 fixup_var_refs_insns (seq
, var
, promoted_mode
, unsignedp
, 0,
1601 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is
1602 some part of an insn. Return a struct fixup_replacement whose OLD
1603 value is equal to X. Allocate a new structure if no such entry exists. */
1605 static struct fixup_replacement
*
1606 find_fixup_replacement (replacements
, x
)
1607 struct fixup_replacement
**replacements
;
1610 struct fixup_replacement
*p
;
1612 /* See if we have already replaced this. */
1613 for (p
= *replacements
; p
!= 0 && ! rtx_equal_p (p
->old
, x
); p
= p
->next
)
1618 p
= (struct fixup_replacement
*) xmalloc (sizeof (struct fixup_replacement
));
1621 p
->next
= *replacements
;
1628 /* Scan the insn-chain starting with INSN for refs to VAR and fix them
1629 up. TOPLEVEL is nonzero if this chain is the main chain of insns
1630 for the current function. MAY_SHARE is either a MEM that is not
1631 to be unshared or a list of them. */
1634 fixup_var_refs_insns (insn
, var
, promoted_mode
, unsignedp
, toplevel
, may_share
)
1637 enum machine_mode promoted_mode
;
1644 /* fixup_var_refs_insn might modify insn, so save its next
1646 rtx next
= NEXT_INSN (insn
);
1648 /* CALL_PLACEHOLDERs are special; we have to switch into each of
1649 the three sequences they (potentially) contain, and process
1650 them recursively. The CALL_INSN itself is not interesting. */
1652 if (GET_CODE (insn
) == CALL_INSN
1653 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
1657 /* Look at the Normal call, sibling call and tail recursion
1658 sequences attached to the CALL_PLACEHOLDER. */
1659 for (i
= 0; i
< 3; i
++)
1661 rtx seq
= XEXP (PATTERN (insn
), i
);
1664 push_to_sequence (seq
);
1665 fixup_var_refs_insns (seq
, var
, promoted_mode
, unsignedp
, 0,
1667 XEXP (PATTERN (insn
), i
) = get_insns ();
1673 else if (INSN_P (insn
))
1674 fixup_var_refs_insn (insn
, var
, promoted_mode
, unsignedp
, toplevel
,
1681 /* Look up the insns which reference VAR in HT and fix them up. Other
1682 arguments are the same as fixup_var_refs_insns.
1684 N.B. No need for special processing of CALL_PLACEHOLDERs here,
1685 because the hash table will point straight to the interesting insn
1686 (inside the CALL_PLACEHOLDER). */
1689 fixup_var_refs_insns_with_hash (ht
, var
, promoted_mode
, unsignedp
, may_share
)
1692 enum machine_mode promoted_mode
;
1696 struct insns_for_mem_entry tmp
;
1697 struct insns_for_mem_entry
*ime
;
1701 ime
= (struct insns_for_mem_entry
*) htab_find (ht
, &tmp
);
1702 for (insn_list
= ime
->insns
; insn_list
!= 0; insn_list
= XEXP (insn_list
, 1))
1703 if (INSN_P (XEXP (insn_list
, 0)))
1704 fixup_var_refs_insn (XEXP (insn_list
, 0), var
, promoted_mode
,
1705 unsignedp
, 1, may_share
);
1709 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is
1710 the insn under examination, VAR is the variable to fix up
1711 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and
1712 TOPLEVEL is nonzero if this is the main insn chain for this
1716 fixup_var_refs_insn (insn
, var
, promoted_mode
, unsignedp
, toplevel
, no_share
)
1719 enum machine_mode promoted_mode
;
1725 rtx set
, prev
, prev_set
;
1728 /* Remember the notes in case we delete the insn. */
1729 note
= REG_NOTES (insn
);
1731 /* If this is a CLOBBER of VAR, delete it.
1733 If it has a REG_LIBCALL note, delete the REG_LIBCALL
1734 and REG_RETVAL notes too. */
1735 if (GET_CODE (PATTERN (insn
)) == CLOBBER
1736 && (XEXP (PATTERN (insn
), 0) == var
1737 || (GET_CODE (XEXP (PATTERN (insn
), 0)) == CONCAT
1738 && (XEXP (XEXP (PATTERN (insn
), 0), 0) == var
1739 || XEXP (XEXP (PATTERN (insn
), 0), 1) == var
))))
1741 if ((note
= find_reg_note (insn
, REG_LIBCALL
, NULL_RTX
)) != 0)
1742 /* The REG_LIBCALL note will go away since we are going to
1743 turn INSN into a NOTE, so just delete the
1744 corresponding REG_RETVAL note. */
1745 remove_note (XEXP (note
, 0),
1746 find_reg_note (XEXP (note
, 0), REG_RETVAL
,
1752 /* The insn to load VAR from a home in the arglist
1753 is now a no-op. When we see it, just delete it.
1754 Similarly if this is storing VAR from a register from which
1755 it was loaded in the previous insn. This will occur
1756 when an ADDRESSOF was made for an arglist slot. */
1758 && (set
= single_set (insn
)) != 0
1759 && SET_DEST (set
) == var
1760 /* If this represents the result of an insn group,
1761 don't delete the insn. */
1762 && find_reg_note (insn
, REG_RETVAL
, NULL_RTX
) == 0
1763 && (rtx_equal_p (SET_SRC (set
), var
)
1764 || (GET_CODE (SET_SRC (set
)) == REG
1765 && (prev
= prev_nonnote_insn (insn
)) != 0
1766 && (prev_set
= single_set (prev
)) != 0
1767 && SET_DEST (prev_set
) == SET_SRC (set
)
1768 && rtx_equal_p (SET_SRC (prev_set
), var
))))
1774 struct fixup_replacement
*replacements
= 0;
1775 rtx next_insn
= NEXT_INSN (insn
);
1777 if (SMALL_REGISTER_CLASSES
)
1779 /* If the insn that copies the results of a CALL_INSN
1780 into a pseudo now references VAR, we have to use an
1781 intermediate pseudo since we want the life of the
1782 return value register to be only a single insn.
1784 If we don't use an intermediate pseudo, such things as
1785 address computations to make the address of VAR valid
1786 if it is not can be placed between the CALL_INSN and INSN.
1788 To make sure this doesn't happen, we record the destination
1789 of the CALL_INSN and see if the next insn uses both that
1792 if (call_dest
!= 0 && GET_CODE (insn
) == INSN
1793 && reg_mentioned_p (var
, PATTERN (insn
))
1794 && reg_mentioned_p (call_dest
, PATTERN (insn
)))
1796 rtx temp
= gen_reg_rtx (GET_MODE (call_dest
));
1798 emit_insn_before (gen_move_insn (temp
, call_dest
), insn
);
1800 PATTERN (insn
) = replace_rtx (PATTERN (insn
),
1804 if (GET_CODE (insn
) == CALL_INSN
1805 && GET_CODE (PATTERN (insn
)) == SET
)
1806 call_dest
= SET_DEST (PATTERN (insn
));
1807 else if (GET_CODE (insn
) == CALL_INSN
1808 && GET_CODE (PATTERN (insn
)) == PARALLEL
1809 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == SET
)
1810 call_dest
= SET_DEST (XVECEXP (PATTERN (insn
), 0, 0));
1815 /* See if we have to do anything to INSN now that VAR is in
1816 memory. If it needs to be loaded into a pseudo, use a single
1817 pseudo for the entire insn in case there is a MATCH_DUP
1818 between two operands. We pass a pointer to the head of
1819 a list of struct fixup_replacements. If fixup_var_refs_1
1820 needs to allocate pseudos or replacement MEMs (for SUBREGs),
1821 it will record them in this list.
1823 If it allocated a pseudo for any replacement, we copy into
1826 fixup_var_refs_1 (var
, promoted_mode
, &PATTERN (insn
), insn
,
1827 &replacements
, no_share
);
1829 /* If this is last_parm_insn, and any instructions were output
1830 after it to fix it up, then we must set last_parm_insn to
1831 the last such instruction emitted. */
1832 if (insn
== last_parm_insn
)
1833 last_parm_insn
= PREV_INSN (next_insn
);
1835 while (replacements
)
1837 struct fixup_replacement
*next
;
1839 if (GET_CODE (replacements
->new) == REG
)
1844 /* OLD might be a (subreg (mem)). */
1845 if (GET_CODE (replacements
->old
) == SUBREG
)
1847 = fixup_memory_subreg (replacements
->old
, insn
,
1851 = fixup_stack_1 (replacements
->old
, insn
);
1853 insert_before
= insn
;
1855 /* If we are changing the mode, do a conversion.
1856 This might be wasteful, but combine.c will
1857 eliminate much of the waste. */
1859 if (GET_MODE (replacements
->new)
1860 != GET_MODE (replacements
->old
))
1863 convert_move (replacements
->new,
1864 replacements
->old
, unsignedp
);
1869 seq
= gen_move_insn (replacements
->new,
1872 emit_insn_before (seq
, insert_before
);
1875 next
= replacements
->next
;
1876 free (replacements
);
1877 replacements
= next
;
1881 /* Also fix up any invalid exprs in the REG_NOTES of this insn.
1882 But don't touch other insns referred to by reg-notes;
1883 we will get them elsewhere. */
1886 if (GET_CODE (note
) != INSN_LIST
)
1888 = walk_fixup_memory_subreg (XEXP (note
, 0), insn
,
1890 note
= XEXP (note
, 1);
1894 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE.
1895 See if the rtx expression at *LOC in INSN needs to be changed.
1897 REPLACEMENTS is a pointer to a list head that starts out zero, but may
1898 contain a list of original rtx's and replacements. If we find that we need
1899 to modify this insn by replacing a memory reference with a pseudo or by
1900 making a new MEM to implement a SUBREG, we consult that list to see if
1901 we have already chosen a replacement. If none has already been allocated,
1902 we allocate it and update the list. fixup_var_refs_insn will copy VAR
1903 or the SUBREG, as appropriate, to the pseudo. */
1906 fixup_var_refs_1 (var
, promoted_mode
, loc
, insn
, replacements
, no_share
)
1908 enum machine_mode promoted_mode
;
1911 struct fixup_replacement
**replacements
;
1916 RTX_CODE code
= GET_CODE (x
);
1919 struct fixup_replacement
*replacement
;
1924 if (XEXP (x
, 0) == var
)
1926 /* Prevent sharing of rtl that might lose. */
1927 rtx sub
= copy_rtx (XEXP (var
, 0));
1929 if (! validate_change (insn
, loc
, sub
, 0))
1931 rtx y
= gen_reg_rtx (GET_MODE (sub
));
1934 /* We should be able to replace with a register or all is lost.
1935 Note that we can't use validate_change to verify this, since
1936 we're not caring for replacing all dups simultaneously. */
1937 if (! validate_replace_rtx (*loc
, y
, insn
))
1940 /* Careful! First try to recognize a direct move of the
1941 value, mimicking how things are done in gen_reload wrt
1942 PLUS. Consider what happens when insn is a conditional
1943 move instruction and addsi3 clobbers flags. */
1946 new_insn
= emit_insn (gen_rtx_SET (VOIDmode
, y
, sub
));
1950 if (recog_memoized (new_insn
) < 0)
1952 /* That failed. Fall back on force_operand and hope. */
1955 sub
= force_operand (sub
, y
);
1957 emit_insn (gen_move_insn (y
, sub
));
1963 /* Don't separate setter from user. */
1964 if (PREV_INSN (insn
) && sets_cc0_p (PREV_INSN (insn
)))
1965 insn
= PREV_INSN (insn
);
1968 emit_insn_before (seq
, insn
);
1976 /* If we already have a replacement, use it. Otherwise,
1977 try to fix up this address in case it is invalid. */
1979 replacement
= find_fixup_replacement (replacements
, var
);
1980 if (replacement
->new)
1982 *loc
= replacement
->new;
1986 *loc
= replacement
->new = x
= fixup_stack_1 (x
, insn
);
1988 /* Unless we are forcing memory to register or we changed the mode,
1989 we can leave things the way they are if the insn is valid. */
1991 INSN_CODE (insn
) = -1;
1992 if (! flag_force_mem
&& GET_MODE (x
) == promoted_mode
1993 && recog_memoized (insn
) >= 0)
1996 *loc
= replacement
->new = gen_reg_rtx (promoted_mode
);
2000 /* If X contains VAR, we need to unshare it here so that we update
2001 each occurrence separately. But all identical MEMs in one insn
2002 must be replaced with the same rtx because of the possibility of
2005 if (reg_mentioned_p (var
, x
))
2007 replacement
= find_fixup_replacement (replacements
, x
);
2008 if (replacement
->new == 0)
2009 replacement
->new = copy_most_rtx (x
, no_share
);
2011 *loc
= x
= replacement
->new;
2012 code
= GET_CODE (x
);
2029 /* Note that in some cases those types of expressions are altered
2030 by optimize_bit_field, and do not survive to get here. */
2031 if (XEXP (x
, 0) == var
2032 || (GET_CODE (XEXP (x
, 0)) == SUBREG
2033 && SUBREG_REG (XEXP (x
, 0)) == var
))
2035 /* Get TEM as a valid MEM in the mode presently in the insn.
2037 We don't worry about the possibility of MATCH_DUP here; it
2038 is highly unlikely and would be tricky to handle. */
2041 if (GET_CODE (tem
) == SUBREG
)
2043 if (GET_MODE_BITSIZE (GET_MODE (tem
))
2044 > GET_MODE_BITSIZE (GET_MODE (var
)))
2046 replacement
= find_fixup_replacement (replacements
, var
);
2047 if (replacement
->new == 0)
2048 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2049 SUBREG_REG (tem
) = replacement
->new;
2051 /* The following code works only if we have a MEM, so we
2052 need to handle the subreg here. We directly substitute
2053 it assuming that a subreg must be OK here. We already
2054 scheduled a replacement to copy the mem into the
2060 tem
= fixup_memory_subreg (tem
, insn
, promoted_mode
, 0);
2063 tem
= fixup_stack_1 (tem
, insn
);
2065 /* Unless we want to load from memory, get TEM into the proper mode
2066 for an extract from memory. This can only be done if the
2067 extract is at a constant position and length. */
2069 if (! flag_force_mem
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
2070 && GET_CODE (XEXP (x
, 2)) == CONST_INT
2071 && ! mode_dependent_address_p (XEXP (tem
, 0))
2072 && ! MEM_VOLATILE_P (tem
))
2074 enum machine_mode wanted_mode
= VOIDmode
;
2075 enum machine_mode is_mode
= GET_MODE (tem
);
2076 HOST_WIDE_INT pos
= INTVAL (XEXP (x
, 2));
2078 if (GET_CODE (x
) == ZERO_EXTRACT
)
2080 enum machine_mode new_mode
2081 = mode_for_extraction (EP_extzv
, 1);
2082 if (new_mode
!= MAX_MACHINE_MODE
)
2083 wanted_mode
= new_mode
;
2085 else if (GET_CODE (x
) == SIGN_EXTRACT
)
2087 enum machine_mode new_mode
2088 = mode_for_extraction (EP_extv
, 1);
2089 if (new_mode
!= MAX_MACHINE_MODE
)
2090 wanted_mode
= new_mode
;
2093 /* If we have a narrower mode, we can do something. */
2094 if (wanted_mode
!= VOIDmode
2095 && GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2097 HOST_WIDE_INT offset
= pos
/ BITS_PER_UNIT
;
2098 rtx old_pos
= XEXP (x
, 2);
2101 /* If the bytes and bits are counted differently, we
2102 must adjust the offset. */
2103 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2104 offset
= (GET_MODE_SIZE (is_mode
)
2105 - GET_MODE_SIZE (wanted_mode
) - offset
);
2107 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2109 newmem
= adjust_address_nv (tem
, wanted_mode
, offset
);
2111 /* Make the change and see if the insn remains valid. */
2112 INSN_CODE (insn
) = -1;
2113 XEXP (x
, 0) = newmem
;
2114 XEXP (x
, 2) = GEN_INT (pos
);
2116 if (recog_memoized (insn
) >= 0)
2119 /* Otherwise, restore old position. XEXP (x, 0) will be
2121 XEXP (x
, 2) = old_pos
;
2125 /* If we get here, the bitfield extract insn can't accept a memory
2126 reference. Copy the input into a register. */
2128 tem1
= gen_reg_rtx (GET_MODE (tem
));
2129 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2136 if (SUBREG_REG (x
) == var
)
2138 /* If this is a special SUBREG made because VAR was promoted
2139 from a wider mode, replace it with VAR and call ourself
2140 recursively, this time saying that the object previously
2141 had its current mode (by virtue of the SUBREG). */
2143 if (SUBREG_PROMOTED_VAR_P (x
))
2146 fixup_var_refs_1 (var
, GET_MODE (var
), loc
, insn
, replacements
,
2151 /* If this SUBREG makes VAR wider, it has become a paradoxical
2152 SUBREG with VAR in memory, but these aren't allowed at this
2153 stage of the compilation. So load VAR into a pseudo and take
2154 a SUBREG of that pseudo. */
2155 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (GET_MODE (var
)))
2157 replacement
= find_fixup_replacement (replacements
, var
);
2158 if (replacement
->new == 0)
2159 replacement
->new = gen_reg_rtx (promoted_mode
);
2160 SUBREG_REG (x
) = replacement
->new;
2164 /* See if we have already found a replacement for this SUBREG.
2165 If so, use it. Otherwise, make a MEM and see if the insn
2166 is recognized. If not, or if we should force MEM into a register,
2167 make a pseudo for this SUBREG. */
2168 replacement
= find_fixup_replacement (replacements
, x
);
2169 if (replacement
->new)
2171 *loc
= replacement
->new;
2175 replacement
->new = *loc
= fixup_memory_subreg (x
, insn
,
2178 INSN_CODE (insn
) = -1;
2179 if (! flag_force_mem
&& recog_memoized (insn
) >= 0)
2182 *loc
= replacement
->new = gen_reg_rtx (GET_MODE (x
));
2188 /* First do special simplification of bit-field references. */
2189 if (GET_CODE (SET_DEST (x
)) == SIGN_EXTRACT
2190 || GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
)
2191 optimize_bit_field (x
, insn
, 0);
2192 if (GET_CODE (SET_SRC (x
)) == SIGN_EXTRACT
2193 || GET_CODE (SET_SRC (x
)) == ZERO_EXTRACT
)
2194 optimize_bit_field (x
, insn
, 0);
2196 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object
2197 into a register and then store it back out. */
2198 if (GET_CODE (SET_DEST (x
)) == ZERO_EXTRACT
2199 && GET_CODE (XEXP (SET_DEST (x
), 0)) == SUBREG
2200 && SUBREG_REG (XEXP (SET_DEST (x
), 0)) == var
2201 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x
), 0)))
2202 > GET_MODE_SIZE (GET_MODE (var
))))
2204 replacement
= find_fixup_replacement (replacements
, var
);
2205 if (replacement
->new == 0)
2206 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2208 SUBREG_REG (XEXP (SET_DEST (x
), 0)) = replacement
->new;
2209 emit_insn_after (gen_move_insn (var
, replacement
->new), insn
);
2212 /* If SET_DEST is now a paradoxical SUBREG, put the result of this
2213 insn into a pseudo and store the low part of the pseudo into VAR. */
2214 if (GET_CODE (SET_DEST (x
)) == SUBREG
2215 && SUBREG_REG (SET_DEST (x
)) == var
2216 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x
)))
2217 > GET_MODE_SIZE (GET_MODE (var
))))
2219 SET_DEST (x
) = tem
= gen_reg_rtx (GET_MODE (SET_DEST (x
)));
2220 emit_insn_after (gen_move_insn (var
, gen_lowpart (GET_MODE (var
),
2227 rtx dest
= SET_DEST (x
);
2228 rtx src
= SET_SRC (x
);
2229 rtx outerdest
= dest
;
2231 while (GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
2232 || GET_CODE (dest
) == SIGN_EXTRACT
2233 || GET_CODE (dest
) == ZERO_EXTRACT
)
2234 dest
= XEXP (dest
, 0);
2236 if (GET_CODE (src
) == SUBREG
)
2237 src
= SUBREG_REG (src
);
2239 /* If VAR does not appear at the top level of the SET
2240 just scan the lower levels of the tree. */
2242 if (src
!= var
&& dest
!= var
)
2245 /* We will need to rerecognize this insn. */
2246 INSN_CODE (insn
) = -1;
2248 if (GET_CODE (outerdest
) == ZERO_EXTRACT
&& dest
== var
2249 && mode_for_extraction (EP_insv
, -1) != MAX_MACHINE_MODE
)
2251 /* Since this case will return, ensure we fixup all the
2253 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 1),
2254 insn
, replacements
, no_share
);
2255 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (outerdest
, 2),
2256 insn
, replacements
, no_share
);
2257 fixup_var_refs_1 (var
, promoted_mode
, &SET_SRC (x
),
2258 insn
, replacements
, no_share
);
2260 tem
= XEXP (outerdest
, 0);
2262 /* Clean up (SUBREG:SI (MEM:mode ...) 0)
2263 that may appear inside a ZERO_EXTRACT.
2264 This was legitimate when the MEM was a REG. */
2265 if (GET_CODE (tem
) == SUBREG
2266 && SUBREG_REG (tem
) == var
)
2267 tem
= fixup_memory_subreg (tem
, insn
, promoted_mode
, 0);
2269 tem
= fixup_stack_1 (tem
, insn
);
2271 if (GET_CODE (XEXP (outerdest
, 1)) == CONST_INT
2272 && GET_CODE (XEXP (outerdest
, 2)) == CONST_INT
2273 && ! mode_dependent_address_p (XEXP (tem
, 0))
2274 && ! MEM_VOLATILE_P (tem
))
2276 enum machine_mode wanted_mode
;
2277 enum machine_mode is_mode
= GET_MODE (tem
);
2278 HOST_WIDE_INT pos
= INTVAL (XEXP (outerdest
, 2));
2280 wanted_mode
= mode_for_extraction (EP_insv
, 0);
2282 /* If we have a narrower mode, we can do something. */
2283 if (GET_MODE_SIZE (wanted_mode
) < GET_MODE_SIZE (is_mode
))
2285 HOST_WIDE_INT offset
= pos
/ BITS_PER_UNIT
;
2286 rtx old_pos
= XEXP (outerdest
, 2);
2289 if (BYTES_BIG_ENDIAN
!= BITS_BIG_ENDIAN
)
2290 offset
= (GET_MODE_SIZE (is_mode
)
2291 - GET_MODE_SIZE (wanted_mode
) - offset
);
2293 pos
%= GET_MODE_BITSIZE (wanted_mode
);
2295 newmem
= adjust_address_nv (tem
, wanted_mode
, offset
);
2297 /* Make the change and see if the insn remains valid. */
2298 INSN_CODE (insn
) = -1;
2299 XEXP (outerdest
, 0) = newmem
;
2300 XEXP (outerdest
, 2) = GEN_INT (pos
);
2302 if (recog_memoized (insn
) >= 0)
2305 /* Otherwise, restore old position. XEXP (x, 0) will be
2307 XEXP (outerdest
, 2) = old_pos
;
2311 /* If we get here, the bit-field store doesn't allow memory
2312 or isn't located at a constant position. Load the value into
2313 a register, do the store, and put it back into memory. */
2315 tem1
= gen_reg_rtx (GET_MODE (tem
));
2316 emit_insn_before (gen_move_insn (tem1
, tem
), insn
);
2317 emit_insn_after (gen_move_insn (tem
, tem1
), insn
);
2318 XEXP (outerdest
, 0) = tem1
;
2322 /* STRICT_LOW_PART is a no-op on memory references
2323 and it can cause combinations to be unrecognizable,
2326 if (dest
== var
&& GET_CODE (SET_DEST (x
)) == STRICT_LOW_PART
)
2327 SET_DEST (x
) = XEXP (SET_DEST (x
), 0);
2329 /* A valid insn to copy VAR into or out of a register
2330 must be left alone, to avoid an infinite loop here.
2331 If the reference to VAR is by a subreg, fix that up,
2332 since SUBREG is not valid for a memref.
2333 Also fix up the address of the stack slot.
2335 Note that we must not try to recognize the insn until
2336 after we know that we have valid addresses and no
2337 (subreg (mem ...) ...) constructs, since these interfere
2338 with determining the validity of the insn. */
2340 if ((SET_SRC (x
) == var
2341 || (GET_CODE (SET_SRC (x
)) == SUBREG
2342 && SUBREG_REG (SET_SRC (x
)) == var
))
2343 && (GET_CODE (SET_DEST (x
)) == REG
2344 || (GET_CODE (SET_DEST (x
)) == SUBREG
2345 && GET_CODE (SUBREG_REG (SET_DEST (x
))) == REG
))
2346 && GET_MODE (var
) == promoted_mode
2347 && x
== single_set (insn
))
2351 if (GET_CODE (SET_SRC (x
)) == SUBREG
2352 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x
)))
2353 > GET_MODE_SIZE (GET_MODE (var
))))
2355 /* This (subreg VAR) is now a paradoxical subreg. We need
2356 to replace VAR instead of the subreg. */
2357 replacement
= find_fixup_replacement (replacements
, var
);
2358 if (replacement
->new == NULL_RTX
)
2359 replacement
->new = gen_reg_rtx (GET_MODE (var
));
2360 SUBREG_REG (SET_SRC (x
)) = replacement
->new;
2364 replacement
= find_fixup_replacement (replacements
, SET_SRC (x
));
2365 if (replacement
->new)
2366 SET_SRC (x
) = replacement
->new;
2367 else if (GET_CODE (SET_SRC (x
)) == SUBREG
)
2368 SET_SRC (x
) = replacement
->new
2369 = fixup_memory_subreg (SET_SRC (x
), insn
, promoted_mode
,
2372 SET_SRC (x
) = replacement
->new
2373 = fixup_stack_1 (SET_SRC (x
), insn
);
2376 if (recog_memoized (insn
) >= 0)
2379 /* INSN is not valid, but we know that we want to
2380 copy SET_SRC (x) to SET_DEST (x) in some way. So
2381 we generate the move and see whether it requires more
2382 than one insn. If it does, we emit those insns and
2383 delete INSN. Otherwise, we can just replace the pattern
2384 of INSN; we have already verified above that INSN has
2385 no other function that to do X. */
2387 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2388 if (NEXT_INSN (pat
) != NULL_RTX
)
2390 last
= emit_insn_before (pat
, insn
);
2392 /* INSN might have REG_RETVAL or other important notes, so
2393 we need to store the pattern of the last insn in the
2394 sequence into INSN similarly to the normal case. LAST
2395 should not have REG_NOTES, but we allow them if INSN has
2397 if (REG_NOTES (last
) && REG_NOTES (insn
))
2399 if (REG_NOTES (last
))
2400 REG_NOTES (insn
) = REG_NOTES (last
);
2401 PATTERN (insn
) = PATTERN (last
);
2406 PATTERN (insn
) = PATTERN (pat
);
2411 if ((SET_DEST (x
) == var
2412 || (GET_CODE (SET_DEST (x
)) == SUBREG
2413 && SUBREG_REG (SET_DEST (x
)) == var
))
2414 && (GET_CODE (SET_SRC (x
)) == REG
2415 || (GET_CODE (SET_SRC (x
)) == SUBREG
2416 && GET_CODE (SUBREG_REG (SET_SRC (x
))) == REG
))
2417 && GET_MODE (var
) == promoted_mode
2418 && x
== single_set (insn
))
2422 if (GET_CODE (SET_DEST (x
)) == SUBREG
)
2423 SET_DEST (x
) = fixup_memory_subreg (SET_DEST (x
), insn
,
2426 SET_DEST (x
) = fixup_stack_1 (SET_DEST (x
), insn
);
2428 if (recog_memoized (insn
) >= 0)
2431 pat
= gen_move_insn (SET_DEST (x
), SET_SRC (x
));
2432 if (NEXT_INSN (pat
) != NULL_RTX
)
2434 last
= emit_insn_before (pat
, insn
);
2436 /* INSN might have REG_RETVAL or other important notes, so
2437 we need to store the pattern of the last insn in the
2438 sequence into INSN similarly to the normal case. LAST
2439 should not have REG_NOTES, but we allow them if INSN has
2441 if (REG_NOTES (last
) && REG_NOTES (insn
))
2443 if (REG_NOTES (last
))
2444 REG_NOTES (insn
) = REG_NOTES (last
);
2445 PATTERN (insn
) = PATTERN (last
);
2450 PATTERN (insn
) = PATTERN (pat
);
2455 /* Otherwise, storing into VAR must be handled specially
2456 by storing into a temporary and copying that into VAR
2457 with a new insn after this one. Note that this case
2458 will be used when storing into a promoted scalar since
2459 the insn will now have different modes on the input
2460 and output and hence will be invalid (except for the case
2461 of setting it to a constant, which does not need any
2462 change if it is valid). We generate extra code in that case,
2463 but combine.c will eliminate it. */
2468 rtx fixeddest
= SET_DEST (x
);
2469 enum machine_mode temp_mode
;
2471 /* STRICT_LOW_PART can be discarded, around a MEM. */
2472 if (GET_CODE (fixeddest
) == STRICT_LOW_PART
)
2473 fixeddest
= XEXP (fixeddest
, 0);
2474 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */
2475 if (GET_CODE (fixeddest
) == SUBREG
)
2477 fixeddest
= fixup_memory_subreg (fixeddest
, insn
,
2479 temp_mode
= GET_MODE (fixeddest
);
2483 fixeddest
= fixup_stack_1 (fixeddest
, insn
);
2484 temp_mode
= promoted_mode
;
2487 temp
= gen_reg_rtx (temp_mode
);
2489 emit_insn_after (gen_move_insn (fixeddest
,
2490 gen_lowpart (GET_MODE (fixeddest
),
2494 SET_DEST (x
) = temp
;
2502 /* Nothing special about this RTX; fix its operands. */
2504 fmt
= GET_RTX_FORMAT (code
);
2505 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2508 fixup_var_refs_1 (var
, promoted_mode
, &XEXP (x
, i
), insn
, replacements
,
2510 else if (fmt
[i
] == 'E')
2513 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2514 fixup_var_refs_1 (var
, promoted_mode
, &XVECEXP (x
, i
, j
),
2515 insn
, replacements
, no_share
);
2520 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)).
2521 The REG was placed on the stack, so X now has the form (SUBREG:m1
2524 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns
2525 must be emitted to compute NEWADDR, put them before INSN.
2527 UNCRITICAL nonzero means accept paradoxical subregs.
2528 This is used for subregs found inside REG_NOTES. */
2531 fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
)
2534 enum machine_mode promoted_mode
;
2538 rtx mem
= SUBREG_REG (x
);
2539 rtx addr
= XEXP (mem
, 0);
2540 enum machine_mode mode
= GET_MODE (x
);
2543 /* Paradoxical SUBREGs are usually invalid during RTL generation. */
2544 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (mem
)) && ! uncritical
)
2547 offset
= SUBREG_BYTE (x
);
2548 if (BYTES_BIG_ENDIAN
)
2549 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust
2550 the offset so that it points to the right location within the
2552 offset
-= (GET_MODE_SIZE (promoted_mode
) - GET_MODE_SIZE (GET_MODE (mem
)));
2554 if (!flag_force_addr
2555 && memory_address_p (mode
, plus_constant (addr
, offset
)))
2556 /* Shortcut if no insns need be emitted. */
2557 return adjust_address (mem
, mode
, offset
);
2560 result
= adjust_address (mem
, mode
, offset
);
2564 emit_insn_before (seq
, insn
);
2568 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
2569 Replace subexpressions of X in place.
2570 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
2571 Otherwise return X, with its contents possibly altered.
2573 INSN, PROMOTED_MODE and UNCRITICAL are as for
2574 fixup_memory_subreg. */
2577 walk_fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
)
2580 enum machine_mode promoted_mode
;
2590 code
= GET_CODE (x
);
2592 if (code
== SUBREG
&& GET_CODE (SUBREG_REG (x
)) == MEM
)
2593 return fixup_memory_subreg (x
, insn
, promoted_mode
, uncritical
);
2595 /* Nothing special about this RTX; fix its operands. */
2597 fmt
= GET_RTX_FORMAT (code
);
2598 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2601 XEXP (x
, i
) = walk_fixup_memory_subreg (XEXP (x
, i
), insn
,
2602 promoted_mode
, uncritical
);
2603 else if (fmt
[i
] == 'E')
2606 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2608 = walk_fixup_memory_subreg (XVECEXP (x
, i
, j
), insn
,
2609 promoted_mode
, uncritical
);
2615 /* For each memory ref within X, if it refers to a stack slot
2616 with an out of range displacement, put the address in a temp register
2617 (emitting new insns before INSN to load these registers)
2618 and alter the memory ref to use that register.
2619 Replace each such MEM rtx with a copy, to avoid clobberage. */
2622 fixup_stack_1 (x
, insn
)
2627 RTX_CODE code
= GET_CODE (x
);
2632 rtx ad
= XEXP (x
, 0);
2633 /* If we have address of a stack slot but it's not valid
2634 (displacement is too large), compute the sum in a register. */
2635 if (GET_CODE (ad
) == PLUS
2636 && GET_CODE (XEXP (ad
, 0)) == REG
2637 && ((REGNO (XEXP (ad
, 0)) >= FIRST_VIRTUAL_REGISTER
2638 && REGNO (XEXP (ad
, 0)) <= LAST_VIRTUAL_REGISTER
)
2639 || REGNO (XEXP (ad
, 0)) == FRAME_POINTER_REGNUM
2640 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
2641 || REGNO (XEXP (ad
, 0)) == HARD_FRAME_POINTER_REGNUM
2643 || REGNO (XEXP (ad
, 0)) == STACK_POINTER_REGNUM
2644 || REGNO (XEXP (ad
, 0)) == ARG_POINTER_REGNUM
2645 || XEXP (ad
, 0) == current_function_internal_arg_pointer
)
2646 && GET_CODE (XEXP (ad
, 1)) == CONST_INT
)
2649 if (memory_address_p (GET_MODE (x
), ad
))
2653 temp
= copy_to_reg (ad
);
2656 emit_insn_before (seq
, insn
);
2657 return replace_equiv_address (x
, temp
);
2662 fmt
= GET_RTX_FORMAT (code
);
2663 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
2666 XEXP (x
, i
) = fixup_stack_1 (XEXP (x
, i
), insn
);
2667 else if (fmt
[i
] == 'E')
2670 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2671 XVECEXP (x
, i
, j
) = fixup_stack_1 (XVECEXP (x
, i
, j
), insn
);
2677 /* Optimization: a bit-field instruction whose field
2678 happens to be a byte or halfword in memory
2679 can be changed to a move instruction.
2681 We call here when INSN is an insn to examine or store into a bit-field.
2682 BODY is the SET-rtx to be altered.
2684 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
2685 (Currently this is called only from function.c, and EQUIV_MEM
2689 optimize_bit_field (body
, insn
, equiv_mem
)
2697 enum machine_mode mode
;
2699 if (GET_CODE (SET_DEST (body
)) == SIGN_EXTRACT
2700 || GET_CODE (SET_DEST (body
)) == ZERO_EXTRACT
)
2701 bitfield
= SET_DEST (body
), destflag
= 1;
2703 bitfield
= SET_SRC (body
), destflag
= 0;
2705 /* First check that the field being stored has constant size and position
2706 and is in fact a byte or halfword suitably aligned. */
2708 if (GET_CODE (XEXP (bitfield
, 1)) == CONST_INT
2709 && GET_CODE (XEXP (bitfield
, 2)) == CONST_INT
2710 && ((mode
= mode_for_size (INTVAL (XEXP (bitfield
, 1)), MODE_INT
, 1))
2712 && INTVAL (XEXP (bitfield
, 2)) % INTVAL (XEXP (bitfield
, 1)) == 0)
2716 /* Now check that the containing word is memory, not a register,
2717 and that it is safe to change the machine mode. */
2719 if (GET_CODE (XEXP (bitfield
, 0)) == MEM
)
2720 memref
= XEXP (bitfield
, 0);
2721 else if (GET_CODE (XEXP (bitfield
, 0)) == REG
2723 memref
= equiv_mem
[REGNO (XEXP (bitfield
, 0))];
2724 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2725 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == MEM
)
2726 memref
= SUBREG_REG (XEXP (bitfield
, 0));
2727 else if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
2729 && GET_CODE (SUBREG_REG (XEXP (bitfield
, 0))) == REG
)
2730 memref
= equiv_mem
[REGNO (SUBREG_REG (XEXP (bitfield
, 0)))];
2733 && ! mode_dependent_address_p (XEXP (memref
, 0))
2734 && ! MEM_VOLATILE_P (memref
))
2736 /* Now adjust the address, first for any subreg'ing
2737 that we are now getting rid of,
2738 and then for which byte of the word is wanted. */
2740 HOST_WIDE_INT offset
= INTVAL (XEXP (bitfield
, 2));
2743 /* Adjust OFFSET to count bits from low-address byte. */
2744 if (BITS_BIG_ENDIAN
!= BYTES_BIG_ENDIAN
)
2745 offset
= (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield
, 0)))
2746 - offset
- INTVAL (XEXP (bitfield
, 1)));
2748 /* Adjust OFFSET to count bytes from low-address byte. */
2749 offset
/= BITS_PER_UNIT
;
2750 if (GET_CODE (XEXP (bitfield
, 0)) == SUBREG
)
2752 offset
+= (SUBREG_BYTE (XEXP (bitfield
, 0))
2753 / UNITS_PER_WORD
) * UNITS_PER_WORD
;
2754 if (BYTES_BIG_ENDIAN
)
2755 offset
-= (MIN (UNITS_PER_WORD
,
2756 GET_MODE_SIZE (GET_MODE (XEXP (bitfield
, 0))))
2757 - MIN (UNITS_PER_WORD
,
2758 GET_MODE_SIZE (GET_MODE (memref
))));
2762 memref
= adjust_address (memref
, mode
, offset
);
2763 insns
= get_insns ();
2765 emit_insn_before (insns
, insn
);
2767 /* Store this memory reference where
2768 we found the bit field reference. */
2772 validate_change (insn
, &SET_DEST (body
), memref
, 1);
2773 if (! CONSTANT_ADDRESS_P (SET_SRC (body
)))
2775 rtx src
= SET_SRC (body
);
2776 while (GET_CODE (src
) == SUBREG
2777 && SUBREG_BYTE (src
) == 0)
2778 src
= SUBREG_REG (src
);
2779 if (GET_MODE (src
) != GET_MODE (memref
))
2780 src
= gen_lowpart (GET_MODE (memref
), SET_SRC (body
));
2781 validate_change (insn
, &SET_SRC (body
), src
, 1);
2783 else if (GET_MODE (SET_SRC (body
)) != VOIDmode
2784 && GET_MODE (SET_SRC (body
)) != GET_MODE (memref
))
2785 /* This shouldn't happen because anything that didn't have
2786 one of these modes should have got converted explicitly
2787 and then referenced through a subreg.
2788 This is so because the original bit-field was
2789 handled by agg_mode and so its tree structure had
2790 the same mode that memref now has. */
2795 rtx dest
= SET_DEST (body
);
2797 while (GET_CODE (dest
) == SUBREG
2798 && SUBREG_BYTE (dest
) == 0
2799 && (GET_MODE_CLASS (GET_MODE (dest
))
2800 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest
))))
2801 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest
)))
2803 dest
= SUBREG_REG (dest
);
2805 validate_change (insn
, &SET_DEST (body
), dest
, 1);
2807 if (GET_MODE (dest
) == GET_MODE (memref
))
2808 validate_change (insn
, &SET_SRC (body
), memref
, 1);
2811 /* Convert the mem ref to the destination mode. */
2812 rtx newreg
= gen_reg_rtx (GET_MODE (dest
));
2815 convert_move (newreg
, memref
,
2816 GET_CODE (SET_SRC (body
)) == ZERO_EXTRACT
);
2820 validate_change (insn
, &SET_SRC (body
), newreg
, 1);
2824 /* See if we can convert this extraction or insertion into
2825 a simple move insn. We might not be able to do so if this
2826 was, for example, part of a PARALLEL.
2828 If we succeed, write out any needed conversions. If we fail,
2829 it is hard to guess why we failed, so don't do anything
2830 special; just let the optimization be suppressed. */
2832 if (apply_change_group () && seq
)
2833 emit_insn_before (seq
, insn
);
2838 /* These routines are responsible for converting virtual register references
2839 to the actual hard register references once RTL generation is complete.
2841 The following four variables are used for communication between the
2842 routines. They contain the offsets of the virtual registers from their
2843 respective hard registers. */
2845 static int in_arg_offset
;
2846 static int var_offset
;
2847 static int dynamic_offset
;
2848 static int out_arg_offset
;
2849 static int cfa_offset
;
2851 /* In most machines, the stack pointer register is equivalent to the bottom
2854 #ifndef STACK_POINTER_OFFSET
2855 #define STACK_POINTER_OFFSET 0
2858 /* If not defined, pick an appropriate default for the offset of dynamically
2859 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
2860 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
2862 #ifndef STACK_DYNAMIC_OFFSET
2864 /* The bottom of the stack points to the actual arguments. If
2865 REG_PARM_STACK_SPACE is defined, this includes the space for the register
2866 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
2867 stack space for register parameters is not pushed by the caller, but
2868 rather part of the fixed stack areas and hence not included in
2869 `current_function_outgoing_args_size'. Nevertheless, we must allow
2870 for it when allocating stack dynamic objects. */
2872 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
2873 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2874 ((ACCUMULATE_OUTGOING_ARGS \
2875 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\
2876 + (STACK_POINTER_OFFSET)) \
2879 #define STACK_DYNAMIC_OFFSET(FNDECL) \
2880 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \
2881 + (STACK_POINTER_OFFSET))
2885 /* On most machines, the CFA coincides with the first incoming parm. */
2887 #ifndef ARG_POINTER_CFA_OFFSET
2888 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL)
2891 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its
2892 address taken. DECL is the decl or SAVE_EXPR for the object stored in the
2893 register, for later use if we do need to force REG into the stack. REG is
2894 overwritten by the MEM like in put_reg_into_stack. */
2897 gen_mem_addressof (reg
, decl
)
2901 rtx r
= gen_rtx_ADDRESSOF (Pmode
, gen_reg_rtx (GET_MODE (reg
)),
2904 /* Calculate this before we start messing with decl's RTL. */
2905 HOST_WIDE_INT set
= decl
? get_alias_set (decl
) : 0;
2907 /* If the original REG was a user-variable, then so is the REG whose
2908 address is being taken. Likewise for unchanging. */
2909 REG_USERVAR_P (XEXP (r
, 0)) = REG_USERVAR_P (reg
);
2910 RTX_UNCHANGING_P (XEXP (r
, 0)) = RTX_UNCHANGING_P (reg
);
2912 PUT_CODE (reg
, MEM
);
2913 MEM_ATTRS (reg
) = 0;
2918 tree type
= TREE_TYPE (decl
);
2919 enum machine_mode decl_mode
2920 = (DECL_P (decl
) ? DECL_MODE (decl
) : TYPE_MODE (TREE_TYPE (decl
)));
2921 rtx decl_rtl
= (TREE_CODE (decl
) == SAVE_EXPR
? SAVE_EXPR_RTL (decl
)
2922 : DECL_RTL_IF_SET (decl
));
2924 PUT_MODE (reg
, decl_mode
);
2926 /* Clear DECL_RTL momentarily so functions below will work
2927 properly, then set it again. */
2928 if (DECL_P (decl
) && decl_rtl
== reg
)
2929 SET_DECL_RTL (decl
, 0);
2931 set_mem_attributes (reg
, decl
, 1);
2932 set_mem_alias_set (reg
, set
);
2934 if (DECL_P (decl
) && decl_rtl
== reg
)
2935 SET_DECL_RTL (decl
, reg
);
2937 if (TREE_USED (decl
) || (DECL_P (decl
) && DECL_INITIAL (decl
) != 0))
2938 fixup_var_refs (reg
, GET_MODE (reg
), TREE_UNSIGNED (type
), reg
, 0);
2941 fixup_var_refs (reg
, GET_MODE (reg
), 0, reg
, 0);
2946 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */
2949 flush_addressof (decl
)
2952 if ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
2953 && DECL_RTL (decl
) != 0
2954 && GET_CODE (DECL_RTL (decl
)) == MEM
2955 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
2956 && GET_CODE (XEXP (XEXP (DECL_RTL (decl
), 0), 0)) == REG
)
2957 put_addressof_into_stack (XEXP (DECL_RTL (decl
), 0), 0);
2960 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */
2963 put_addressof_into_stack (r
, ht
)
2968 int volatile_p
, used_p
;
2970 rtx reg
= XEXP (r
, 0);
2972 if (GET_CODE (reg
) != REG
)
2975 decl
= ADDRESSOF_DECL (r
);
2978 type
= TREE_TYPE (decl
);
2979 volatile_p
= (TREE_CODE (decl
) != SAVE_EXPR
2980 && TREE_THIS_VOLATILE (decl
));
2981 used_p
= (TREE_USED (decl
)
2982 || (DECL_P (decl
) && DECL_INITIAL (decl
) != 0));
2991 put_reg_into_stack (0, reg
, type
, GET_MODE (reg
), GET_MODE (reg
),
2992 volatile_p
, ADDRESSOF_REGNO (r
), used_p
, ht
);
2995 /* List of replacements made below in purge_addressof_1 when creating
2996 bitfield insertions. */
2997 static rtx purge_bitfield_addressof_replacements
;
2999 /* List of replacements made below in purge_addressof_1 for patterns
3000 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the
3001 corresponding (ADDRESSOF (REG ...)) and value is a substitution for
3002 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not
3003 enough in complex cases, e.g. when some field values can be
3004 extracted by usage MEM with narrower mode. */
3005 static rtx purge_addressof_replacements
;
3007 /* Helper function for purge_addressof. See if the rtx expression at *LOC
3008 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into
3009 the stack. If the function returns FALSE then the replacement could not
3013 purge_addressof_1 (loc
, insn
, force
, store
, ht
)
3025 /* Re-start here to avoid recursion in common cases. */
3032 code
= GET_CODE (x
);
3034 /* If we don't return in any of the cases below, we will recurse inside
3035 the RTX, which will normally result in any ADDRESSOF being forced into
3039 result
= purge_addressof_1 (&SET_DEST (x
), insn
, force
, 1, ht
);
3040 result
&= purge_addressof_1 (&SET_SRC (x
), insn
, force
, 0, ht
);
3043 else if (code
== ADDRESSOF
)
3047 if (GET_CODE (XEXP (x
, 0)) != MEM
)
3049 put_addressof_into_stack (x
, ht
);
3053 /* We must create a copy of the rtx because it was created by
3054 overwriting a REG rtx which is always shared. */
3055 sub
= copy_rtx (XEXP (XEXP (x
, 0), 0));
3056 if (validate_change (insn
, loc
, sub
, 0)
3057 || validate_replace_rtx (x
, sub
, insn
))
3061 sub
= force_operand (sub
, NULL_RTX
);
3062 if (! validate_change (insn
, loc
, sub
, 0)
3063 && ! validate_replace_rtx (x
, sub
, insn
))
3066 insns
= get_insns ();
3068 emit_insn_before (insns
, insn
);
3072 else if (code
== MEM
&& GET_CODE (XEXP (x
, 0)) == ADDRESSOF
&& ! force
)
3074 rtx sub
= XEXP (XEXP (x
, 0), 0);
3076 if (GET_CODE (sub
) == MEM
)
3077 sub
= adjust_address_nv (sub
, GET_MODE (x
), 0);
3078 else if (GET_CODE (sub
) == REG
3079 && (MEM_VOLATILE_P (x
) || GET_MODE (x
) == BLKmode
))
3081 else if (GET_CODE (sub
) == REG
&& GET_MODE (x
) != GET_MODE (sub
))
3083 int size_x
, size_sub
;
3087 /* When processing REG_NOTES look at the list of
3088 replacements done on the insn to find the register that X
3092 for (tem
= purge_bitfield_addressof_replacements
;
3094 tem
= XEXP (XEXP (tem
, 1), 1))
3095 if (rtx_equal_p (x
, XEXP (tem
, 0)))
3097 *loc
= XEXP (XEXP (tem
, 1), 0);
3101 /* See comment for purge_addressof_replacements. */
3102 for (tem
= purge_addressof_replacements
;
3104 tem
= XEXP (XEXP (tem
, 1), 1))
3105 if (rtx_equal_p (XEXP (x
, 0), XEXP (tem
, 0)))
3107 rtx z
= XEXP (XEXP (tem
, 1), 0);
3109 if (GET_MODE (x
) == GET_MODE (z
)
3110 || (GET_CODE (XEXP (XEXP (tem
, 1), 0)) != REG
3111 && GET_CODE (XEXP (XEXP (tem
, 1), 0)) != SUBREG
))
3114 /* It can happen that the note may speak of things
3115 in a wider (or just different) mode than the
3116 code did. This is especially true of
3119 if (GET_CODE (z
) == SUBREG
&& SUBREG_BYTE (z
) == 0)
3122 if (GET_MODE_SIZE (GET_MODE (x
)) > UNITS_PER_WORD
3123 && (GET_MODE_SIZE (GET_MODE (x
))
3124 > GET_MODE_SIZE (GET_MODE (z
))))
3126 /* This can occur as a result in invalid
3127 pointer casts, e.g. float f; ...
3128 *(long long int *)&f.
3129 ??? We could emit a warning here, but
3130 without a line number that wouldn't be
3132 z
= gen_rtx_SUBREG (GET_MODE (x
), z
, 0);
3135 z
= gen_lowpart (GET_MODE (x
), z
);
3141 /* Sometimes we may not be able to find the replacement. For
3142 example when the original insn was a MEM in a wider mode,
3143 and the note is part of a sign extension of a narrowed
3144 version of that MEM. Gcc testcase compile/990829-1.c can
3145 generate an example of this situation. Rather than complain
3146 we return false, which will prompt our caller to remove the
3151 size_x
= GET_MODE_BITSIZE (GET_MODE (x
));
3152 size_sub
= GET_MODE_BITSIZE (GET_MODE (sub
));
3154 /* Don't even consider working with paradoxical subregs,
3155 or the moral equivalent seen here. */
3156 if (size_x
<= size_sub
3157 && int_mode_for_mode (GET_MODE (sub
)) != BLKmode
)
3159 /* Do a bitfield insertion to mirror what would happen
3166 rtx p
= PREV_INSN (insn
);
3169 val
= gen_reg_rtx (GET_MODE (x
));
3170 if (! validate_change (insn
, loc
, val
, 0))
3172 /* Discard the current sequence and put the
3173 ADDRESSOF on stack. */
3179 emit_insn_before (seq
, insn
);
3180 compute_insns_for_mem (p
? NEXT_INSN (p
) : get_insns (),
3184 store_bit_field (sub
, size_x
, 0, GET_MODE (x
),
3185 val
, GET_MODE_SIZE (GET_MODE (sub
)));
3187 /* Make sure to unshare any shared rtl that store_bit_field
3188 might have created. */
3189 unshare_all_rtl_again (get_insns ());
3193 p
= emit_insn_after (seq
, insn
);
3194 if (NEXT_INSN (insn
))
3195 compute_insns_for_mem (NEXT_INSN (insn
),
3196 p
? NEXT_INSN (p
) : NULL_RTX
,
3201 rtx p
= PREV_INSN (insn
);
3204 val
= extract_bit_field (sub
, size_x
, 0, 1, NULL_RTX
,
3205 GET_MODE (x
), GET_MODE (x
),
3206 GET_MODE_SIZE (GET_MODE (sub
)));
3208 if (! validate_change (insn
, loc
, val
, 0))
3210 /* Discard the current sequence and put the
3211 ADDRESSOF on stack. */
3218 emit_insn_before (seq
, insn
);
3219 compute_insns_for_mem (p
? NEXT_INSN (p
) : get_insns (),
3223 /* Remember the replacement so that the same one can be done
3224 on the REG_NOTES. */
3225 purge_bitfield_addressof_replacements
3226 = gen_rtx_EXPR_LIST (VOIDmode
, x
,
3229 purge_bitfield_addressof_replacements
));
3231 /* We replaced with a reg -- all done. */
3236 else if (validate_change (insn
, loc
, sub
, 0))
3238 /* Remember the replacement so that the same one can be done
3239 on the REG_NOTES. */
3240 if (GET_CODE (sub
) == REG
|| GET_CODE (sub
) == SUBREG
)
3244 for (tem
= purge_addressof_replacements
;
3246 tem
= XEXP (XEXP (tem
, 1), 1))
3247 if (rtx_equal_p (XEXP (x
, 0), XEXP (tem
, 0)))
3249 XEXP (XEXP (tem
, 1), 0) = sub
;
3252 purge_addressof_replacements
3253 = gen_rtx (EXPR_LIST
, VOIDmode
, XEXP (x
, 0),
3254 gen_rtx_EXPR_LIST (VOIDmode
, sub
,
3255 purge_addressof_replacements
));
3263 /* Scan all subexpressions. */
3264 fmt
= GET_RTX_FORMAT (code
);
3265 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3268 result
&= purge_addressof_1 (&XEXP (x
, i
), insn
, force
, 0, ht
);
3269 else if (*fmt
== 'E')
3270 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3271 result
&= purge_addressof_1 (&XVECEXP (x
, i
, j
), insn
, force
, 0, ht
);
3277 /* Return a hash value for K, a REG. */
3280 insns_for_mem_hash (k
)
3283 /* Use the address of the key for the hash value. */
3284 struct insns_for_mem_entry
*m
= (struct insns_for_mem_entry
*) k
;
3285 return htab_hash_pointer (m
->key
);
3288 /* Return nonzero if K1 and K2 (two REGs) are the same. */
3291 insns_for_mem_comp (k1
, k2
)
3295 struct insns_for_mem_entry
*m1
= (struct insns_for_mem_entry
*) k1
;
3296 struct insns_for_mem_entry
*m2
= (struct insns_for_mem_entry
*) k2
;
3297 return m1
->key
== m2
->key
;
3300 struct insns_for_mem_walk_info
3302 /* The hash table that we are using to record which INSNs use which
3306 /* The INSN we are currently processing. */
3309 /* Zero if we are walking to find ADDRESSOFs, one if we are walking
3310 to find the insns that use the REGs in the ADDRESSOFs. */
3314 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG
3315 that might be used in an ADDRESSOF expression, record this INSN in
3316 the hash table given by DATA (which is really a pointer to an
3317 insns_for_mem_walk_info structure). */
3320 insns_for_mem_walk (r
, data
)
3324 struct insns_for_mem_walk_info
*ifmwi
3325 = (struct insns_for_mem_walk_info
*) data
;
3326 struct insns_for_mem_entry tmp
;
3327 tmp
.insns
= NULL_RTX
;
3329 if (ifmwi
->pass
== 0 && *r
&& GET_CODE (*r
) == ADDRESSOF
3330 && GET_CODE (XEXP (*r
, 0)) == REG
)
3333 tmp
.key
= XEXP (*r
, 0);
3334 e
= htab_find_slot (ifmwi
->ht
, &tmp
, INSERT
);
3337 *e
= ggc_alloc (sizeof (tmp
));
3338 memcpy (*e
, &tmp
, sizeof (tmp
));
3341 else if (ifmwi
->pass
== 1 && *r
&& GET_CODE (*r
) == REG
)
3343 struct insns_for_mem_entry
*ifme
;
3345 ifme
= (struct insns_for_mem_entry
*) htab_find (ifmwi
->ht
, &tmp
);
3347 /* If we have not already recorded this INSN, do so now. Since
3348 we process the INSNs in order, we know that if we have
3349 recorded it it must be at the front of the list. */
3350 if (ifme
&& (!ifme
->insns
|| XEXP (ifme
->insns
, 0) != ifmwi
->insn
))
3351 ifme
->insns
= gen_rtx_EXPR_LIST (VOIDmode
, ifmwi
->insn
,
3358 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use
3359 which REGs in HT. */
3362 compute_insns_for_mem (insns
, last_insn
, ht
)
3368 struct insns_for_mem_walk_info ifmwi
;
3371 for (ifmwi
.pass
= 0; ifmwi
.pass
< 2; ++ifmwi
.pass
)
3372 for (insn
= insns
; insn
!= last_insn
; insn
= NEXT_INSN (insn
))
3376 for_each_rtx (&insn
, insns_for_mem_walk
, &ifmwi
);
3380 /* Helper function for purge_addressof called through for_each_rtx.
3381 Returns true iff the rtl is an ADDRESSOF. */
3384 is_addressof (rtl
, data
)
3386 void *data ATTRIBUTE_UNUSED
;
3388 return GET_CODE (*rtl
) == ADDRESSOF
;
3391 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining
3392 (MEM (ADDRESSOF)) patterns, and force any needed registers into the
3396 purge_addressof (insns
)
3402 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That
3403 requires a fixup pass over the instruction stream to correct
3404 INSNs that depended on the REG being a REG, and not a MEM. But,
3405 these fixup passes are slow. Furthermore, most MEMs are not
3406 mentioned in very many instructions. So, we speed up the process
3407 by pre-calculating which REGs occur in which INSNs; that allows
3408 us to perform the fixup passes much more quickly. */
3409 ht
= htab_create_ggc (1000, insns_for_mem_hash
, insns_for_mem_comp
, NULL
);
3410 compute_insns_for_mem (insns
, NULL_RTX
, ht
);
3412 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3413 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
3414 || GET_CODE (insn
) == CALL_INSN
)
3416 if (! purge_addressof_1 (&PATTERN (insn
), insn
,
3417 asm_noperands (PATTERN (insn
)) > 0, 0, ht
))
3418 /* If we could not replace the ADDRESSOFs in the insn,
3419 something is wrong. */
3422 if (! purge_addressof_1 (®_NOTES (insn
), NULL_RTX
, 0, 0, ht
))
3424 /* If we could not replace the ADDRESSOFs in the insn's notes,
3425 we can just remove the offending notes instead. */
3428 for (note
= REG_NOTES (insn
); note
; note
= XEXP (note
, 1))
3430 /* If we find a REG_RETVAL note then the insn is a libcall.
3431 Such insns must have REG_EQUAL notes as well, in order
3432 for later passes of the compiler to work. So it is not
3433 safe to delete the notes here, and instead we abort. */
3434 if (REG_NOTE_KIND (note
) == REG_RETVAL
)
3436 if (for_each_rtx (¬e
, is_addressof
, NULL
))
3437 remove_note (insn
, note
);
3443 purge_bitfield_addressof_replacements
= 0;
3444 purge_addressof_replacements
= 0;
3446 /* REGs are shared. purge_addressof will destructively replace a REG
3447 with a MEM, which creates shared MEMs.
3449 Unfortunately, the children of put_reg_into_stack assume that MEMs
3450 referring to the same stack slot are shared (fixup_var_refs and
3451 the associated hash table code).
3453 So, we have to do another unsharing pass after we have flushed any
3454 REGs that had their address taken into the stack.
3456 It may be worth tracking whether or not we converted any REGs into
3457 MEMs to avoid this overhead when it is not needed. */
3458 unshare_all_rtl_again (get_insns ());
3461 /* Convert a SET of a hard subreg to a set of the appropriate hard
3462 register. A subroutine of purge_hard_subreg_sets. */
3465 purge_single_hard_subreg_set (pattern
)
3468 rtx reg
= SET_DEST (pattern
);
3469 enum machine_mode mode
= GET_MODE (SET_DEST (pattern
));
3472 if (GET_CODE (reg
) == SUBREG
&& GET_CODE (SUBREG_REG (reg
)) == REG
3473 && REGNO (SUBREG_REG (reg
)) < FIRST_PSEUDO_REGISTER
)
3475 offset
= subreg_regno_offset (REGNO (SUBREG_REG (reg
)),
3476 GET_MODE (SUBREG_REG (reg
)),
3479 reg
= SUBREG_REG (reg
);
3483 if (GET_CODE (reg
) == REG
&& REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
3485 reg
= gen_rtx_REG (mode
, REGNO (reg
) + offset
);
3486 SET_DEST (pattern
) = reg
;
3490 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The
3491 only such SETs that we expect to see are those left in because
3492 integrate can't handle sets of parts of a return value register.
3494 We don't use alter_subreg because we only want to eliminate subregs
3495 of hard registers. */
3498 purge_hard_subreg_sets (insn
)
3501 for (; insn
; insn
= NEXT_INSN (insn
))
3505 rtx pattern
= PATTERN (insn
);
3506 switch (GET_CODE (pattern
))
3509 if (GET_CODE (SET_DEST (pattern
)) == SUBREG
)
3510 purge_single_hard_subreg_set (pattern
);
3515 for (j
= XVECLEN (pattern
, 0) - 1; j
>= 0; j
--)
3517 rtx inner_pattern
= XVECEXP (pattern
, 0, j
);
3518 if (GET_CODE (inner_pattern
) == SET
3519 && GET_CODE (SET_DEST (inner_pattern
)) == SUBREG
)
3520 purge_single_hard_subreg_set (inner_pattern
);
3531 /* Pass through the INSNS of function FNDECL and convert virtual register
3532 references to hard register references. */
3535 instantiate_virtual_regs (fndecl
, insns
)
3542 /* Compute the offsets to use for this function. */
3543 in_arg_offset
= FIRST_PARM_OFFSET (fndecl
);
3544 var_offset
= STARTING_FRAME_OFFSET
;
3545 dynamic_offset
= STACK_DYNAMIC_OFFSET (fndecl
);
3546 out_arg_offset
= STACK_POINTER_OFFSET
;
3547 cfa_offset
= ARG_POINTER_CFA_OFFSET (fndecl
);
3549 /* Scan all variables and parameters of this function. For each that is
3550 in memory, instantiate all virtual registers if the result is a valid
3551 address. If not, we do it later. That will handle most uses of virtual
3552 regs on many machines. */
3553 instantiate_decls (fndecl
, 1);
3555 /* Initialize recognition, indicating that volatile is OK. */
3558 /* Scan through all the insns, instantiating every virtual register still
3560 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
3561 if (GET_CODE (insn
) == INSN
|| GET_CODE (insn
) == JUMP_INSN
3562 || GET_CODE (insn
) == CALL_INSN
)
3564 instantiate_virtual_regs_1 (&PATTERN (insn
), insn
, 1);
3565 instantiate_virtual_regs_1 (®_NOTES (insn
), NULL_RTX
, 0);
3566 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
3567 if (GET_CODE (insn
) == CALL_INSN
)
3568 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn
),
3572 /* Instantiate the stack slots for the parm registers, for later use in
3573 addressof elimination. */
3574 for (i
= 0; i
< max_parm_reg
; ++i
)
3575 if (parm_reg_stack_loc
[i
])
3576 instantiate_virtual_regs_1 (&parm_reg_stack_loc
[i
], NULL_RTX
, 0);
3578 /* Now instantiate the remaining register equivalences for debugging info.
3579 These will not be valid addresses. */
3580 instantiate_decls (fndecl
, 0);
3582 /* Indicate that, from now on, assign_stack_local should use
3583 frame_pointer_rtx. */
3584 virtuals_instantiated
= 1;
3587 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
3588 all virtual registers in their DECL_RTL's.
3590 If VALID_ONLY, do this only if the resulting address is still valid.
3591 Otherwise, always do it. */
3594 instantiate_decls (fndecl
, valid_only
)
3600 /* Process all parameters of the function. */
3601 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= TREE_CHAIN (decl
))
3603 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (decl
));
3604 HOST_WIDE_INT size_rtl
;
3606 instantiate_decl (DECL_RTL (decl
), size
, valid_only
);
3608 /* If the parameter was promoted, then the incoming RTL mode may be
3609 larger than the declared type size. We must use the larger of
3611 size_rtl
= GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl
)));
3612 size
= MAX (size_rtl
, size
);
3613 instantiate_decl (DECL_INCOMING_RTL (decl
), size
, valid_only
);
3616 /* Now process all variables defined in the function or its subblocks. */
3617 instantiate_decls_1 (DECL_INITIAL (fndecl
), valid_only
);
3620 /* Subroutine of instantiate_decls: Process all decls in the given
3621 BLOCK node and all its subblocks. */
3624 instantiate_decls_1 (let
, valid_only
)
3630 for (t
= BLOCK_VARS (let
); t
; t
= TREE_CHAIN (t
))
3631 if (DECL_RTL_SET_P (t
))
3632 instantiate_decl (DECL_RTL (t
),
3633 int_size_in_bytes (TREE_TYPE (t
)),
3636 /* Process all subblocks. */
3637 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= TREE_CHAIN (t
))
3638 instantiate_decls_1 (t
, valid_only
);
3641 /* Subroutine of the preceding procedures: Given RTL representing a
3642 decl and the size of the object, do any instantiation required.
3644 If VALID_ONLY is nonzero, it means that the RTL should only be
3645 changed if the new address is valid. */
3648 instantiate_decl (x
, size
, valid_only
)
3653 enum machine_mode mode
;
3656 /* If this is not a MEM, no need to do anything. Similarly if the
3657 address is a constant or a register that is not a virtual register. */
3659 if (x
== 0 || GET_CODE (x
) != MEM
)
3663 if (CONSTANT_P (addr
)
3664 || (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == REG
)
3665 || (GET_CODE (addr
) == REG
3666 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
3667 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
3670 /* If we should only do this if the address is valid, copy the address.
3671 We need to do this so we can undo any changes that might make the
3672 address invalid. This copy is unfortunate, but probably can't be
3676 addr
= copy_rtx (addr
);
3678 instantiate_virtual_regs_1 (&addr
, NULL_RTX
, 0);
3680 if (valid_only
&& size
>= 0)
3682 unsigned HOST_WIDE_INT decl_size
= size
;
3684 /* Now verify that the resulting address is valid for every integer or
3685 floating-point mode up to and including SIZE bytes long. We do this
3686 since the object might be accessed in any mode and frame addresses
3689 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
3690 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= decl_size
;
3691 mode
= GET_MODE_WIDER_MODE (mode
))
3692 if (! memory_address_p (mode
, addr
))
3695 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
3696 mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) <= decl_size
;
3697 mode
= GET_MODE_WIDER_MODE (mode
))
3698 if (! memory_address_p (mode
, addr
))
3702 /* Put back the address now that we have updated it and we either know
3703 it is valid or we don't care whether it is valid. */
3708 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
3709 is a virtual register, return the equivalent hard register and set the
3710 offset indirectly through the pointer. Otherwise, return 0. */
3713 instantiate_new_reg (x
, poffset
)
3715 HOST_WIDE_INT
*poffset
;
3718 HOST_WIDE_INT offset
;
3720 if (x
== virtual_incoming_args_rtx
)
3721 new = arg_pointer_rtx
, offset
= in_arg_offset
;
3722 else if (x
== virtual_stack_vars_rtx
)
3723 new = frame_pointer_rtx
, offset
= var_offset
;
3724 else if (x
== virtual_stack_dynamic_rtx
)
3725 new = stack_pointer_rtx
, offset
= dynamic_offset
;
3726 else if (x
== virtual_outgoing_args_rtx
)
3727 new = stack_pointer_rtx
, offset
= out_arg_offset
;
3728 else if (x
== virtual_cfa_rtx
)
3729 new = arg_pointer_rtx
, offset
= cfa_offset
;
3737 /* Given a pointer to a piece of rtx and an optional pointer to the
3738 containing object, instantiate any virtual registers present in it.
3740 If EXTRA_INSNS, we always do the replacement and generate
3741 any extra insns before OBJECT. If it zero, we do nothing if replacement
3744 Return 1 if we either had nothing to do or if we were able to do the
3745 needed replacement. Return 0 otherwise; we only return zero if
3746 EXTRA_INSNS is zero.
3748 We first try some simple transformations to avoid the creation of extra
3752 instantiate_virtual_regs_1 (loc
, object
, extra_insns
)
3760 HOST_WIDE_INT offset
= 0;
3766 /* Re-start here to avoid recursion in common cases. */
3773 code
= GET_CODE (x
);
3775 /* Check for some special cases. */
3793 /* We are allowed to set the virtual registers. This means that
3794 the actual register should receive the source minus the
3795 appropriate offset. This is used, for example, in the handling
3796 of non-local gotos. */
3797 if ((new = instantiate_new_reg (SET_DEST (x
), &offset
)) != 0)
3799 rtx src
= SET_SRC (x
);
3801 /* We are setting the register, not using it, so the relevant
3802 offset is the negative of the offset to use were we using
3805 instantiate_virtual_regs_1 (&src
, NULL_RTX
, 0);
3807 /* The only valid sources here are PLUS or REG. Just do
3808 the simplest possible thing to handle them. */
3809 if (GET_CODE (src
) != REG
&& GET_CODE (src
) != PLUS
)
3813 if (GET_CODE (src
) != REG
)
3814 temp
= force_operand (src
, NULL_RTX
);
3817 temp
= force_operand (plus_constant (temp
, offset
), NULL_RTX
);
3821 emit_insn_before (seq
, object
);
3824 if (! validate_change (object
, &SET_SRC (x
), temp
, 0)
3831 instantiate_virtual_regs_1 (&SET_DEST (x
), object
, extra_insns
);
3836 /* Handle special case of virtual register plus constant. */
3837 if (CONSTANT_P (XEXP (x
, 1)))
3839 rtx old
, new_offset
;
3841 /* Check for (plus (plus VIRT foo) (const_int)) first. */
3842 if (GET_CODE (XEXP (x
, 0)) == PLUS
)
3844 if ((new = instantiate_new_reg (XEXP (XEXP (x
, 0), 0), &offset
)))
3846 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 1), object
,
3848 new = gen_rtx_PLUS (Pmode
, new, XEXP (XEXP (x
, 0), 1));
3857 #ifdef POINTERS_EXTEND_UNSIGNED
3858 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
3859 we can commute the PLUS and SUBREG because pointers into the
3860 frame are well-behaved. */
3861 else if (GET_CODE (XEXP (x
, 0)) == SUBREG
&& GET_MODE (x
) == ptr_mode
3862 && GET_CODE (XEXP (x
, 1)) == CONST_INT
3864 = instantiate_new_reg (SUBREG_REG (XEXP (x
, 0)),
3866 && validate_change (object
, loc
,
3867 plus_constant (gen_lowpart (ptr_mode
,
3870 + INTVAL (XEXP (x
, 1))),
3874 else if ((new = instantiate_new_reg (XEXP (x
, 0), &offset
)) == 0)
3876 /* We know the second operand is a constant. Unless the
3877 first operand is a REG (which has been already checked),
3878 it needs to be checked. */
3879 if (GET_CODE (XEXP (x
, 0)) != REG
)
3887 new_offset
= plus_constant (XEXP (x
, 1), offset
);
3889 /* If the new constant is zero, try to replace the sum with just
3891 if (new_offset
== const0_rtx
3892 && validate_change (object
, loc
, new, 0))
3895 /* Next try to replace the register and new offset.
3896 There are two changes to validate here and we can't assume that
3897 in the case of old offset equals new just changing the register
3898 will yield a valid insn. In the interests of a little efficiency,
3899 however, we only call validate change once (we don't queue up the
3900 changes and then call apply_change_group). */
3904 ? ! validate_change (object
, &XEXP (x
, 0), new, 0)
3905 : (XEXP (x
, 0) = new,
3906 ! validate_change (object
, &XEXP (x
, 1), new_offset
, 0)))
3914 /* Otherwise copy the new constant into a register and replace
3915 constant with that register. */
3916 temp
= gen_reg_rtx (Pmode
);
3918 if (validate_change (object
, &XEXP (x
, 1), temp
, 0))
3919 emit_insn_before (gen_move_insn (temp
, new_offset
), object
);
3922 /* If that didn't work, replace this expression with a
3923 register containing the sum. */
3926 new = gen_rtx_PLUS (Pmode
, new, new_offset
);
3929 temp
= force_operand (new, NULL_RTX
);
3933 emit_insn_before (seq
, object
);
3934 if (! validate_change (object
, loc
, temp
, 0)
3935 && ! validate_replace_rtx (x
, temp
, object
))
3943 /* Fall through to generic two-operand expression case. */
3949 case DIV
: case UDIV
:
3950 case MOD
: case UMOD
:
3951 case AND
: case IOR
: case XOR
:
3952 case ROTATERT
: case ROTATE
:
3953 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
3955 case GE
: case GT
: case GEU
: case GTU
:
3956 case LE
: case LT
: case LEU
: case LTU
:
3957 if (XEXP (x
, 1) && ! CONSTANT_P (XEXP (x
, 1)))
3958 instantiate_virtual_regs_1 (&XEXP (x
, 1), object
, extra_insns
);
3963 /* Most cases of MEM that convert to valid addresses have already been
3964 handled by our scan of decls. The only special handling we
3965 need here is to make a copy of the rtx to ensure it isn't being
3966 shared if we have to change it to a pseudo.
3968 If the rtx is a simple reference to an address via a virtual register,
3969 it can potentially be shared. In such cases, first try to make it
3970 a valid address, which can also be shared. Otherwise, copy it and
3973 First check for common cases that need no processing. These are
3974 usually due to instantiation already being done on a previous instance
3978 if (CONSTANT_ADDRESS_P (temp
)
3979 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3980 || temp
== arg_pointer_rtx
3982 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3983 || temp
== hard_frame_pointer_rtx
3985 || temp
== frame_pointer_rtx
)
3988 if (GET_CODE (temp
) == PLUS
3989 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
3990 && (XEXP (temp
, 0) == frame_pointer_rtx
3991 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
3992 || XEXP (temp
, 0) == hard_frame_pointer_rtx
3994 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
3995 || XEXP (temp
, 0) == arg_pointer_rtx
4000 if (temp
== virtual_stack_vars_rtx
4001 || temp
== virtual_incoming_args_rtx
4002 || (GET_CODE (temp
) == PLUS
4003 && CONSTANT_ADDRESS_P (XEXP (temp
, 1))
4004 && (XEXP (temp
, 0) == virtual_stack_vars_rtx
4005 || XEXP (temp
, 0) == virtual_incoming_args_rtx
)))
4007 /* This MEM may be shared. If the substitution can be done without
4008 the need to generate new pseudos, we want to do it in place
4009 so all copies of the shared rtx benefit. The call below will
4010 only make substitutions if the resulting address is still
4013 Note that we cannot pass X as the object in the recursive call
4014 since the insn being processed may not allow all valid
4015 addresses. However, if we were not passed on object, we can
4016 only modify X without copying it if X will have a valid
4019 ??? Also note that this can still lose if OBJECT is an insn that
4020 has less restrictions on an address that some other insn.
4021 In that case, we will modify the shared address. This case
4022 doesn't seem very likely, though. One case where this could
4023 happen is in the case of a USE or CLOBBER reference, but we
4024 take care of that below. */
4026 if (instantiate_virtual_regs_1 (&XEXP (x
, 0),
4027 object
? object
: x
, 0))
4030 /* Otherwise make a copy and process that copy. We copy the entire
4031 RTL expression since it might be a PLUS which could also be
4033 *loc
= x
= copy_rtx (x
);
4036 /* Fall through to generic unary operation case. */
4039 case STRICT_LOW_PART
:
4041 case PRE_DEC
: case PRE_INC
: case POST_DEC
: case POST_INC
:
4042 case SIGN_EXTEND
: case ZERO_EXTEND
:
4043 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
4044 case FLOAT
: case FIX
:
4045 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
4049 /* These case either have just one operand or we know that we need not
4050 check the rest of the operands. */
4056 /* If the operand is a MEM, see if the change is a valid MEM. If not,
4057 go ahead and make the invalid one, but do it to a copy. For a REG,
4058 just make the recursive call, since there's no chance of a problem. */
4060 if ((GET_CODE (XEXP (x
, 0)) == MEM
4061 && instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), XEXP (x
, 0),
4063 || (GET_CODE (XEXP (x
, 0)) == REG
4064 && instantiate_virtual_regs_1 (&XEXP (x
, 0), object
, 0)))
4067 XEXP (x
, 0) = copy_rtx (XEXP (x
, 0));
4072 /* Try to replace with a PLUS. If that doesn't work, compute the sum
4073 in front of this insn and substitute the temporary. */
4074 if ((new = instantiate_new_reg (x
, &offset
)) != 0)
4076 temp
= plus_constant (new, offset
);
4077 if (!validate_change (object
, loc
, temp
, 0))
4083 temp
= force_operand (temp
, NULL_RTX
);
4087 emit_insn_before (seq
, object
);
4088 if (! validate_change (object
, loc
, temp
, 0)
4089 && ! validate_replace_rtx (x
, temp
, object
))
4097 if (GET_CODE (XEXP (x
, 0)) == REG
)
4100 else if (GET_CODE (XEXP (x
, 0)) == MEM
)
4102 /* If we have a (addressof (mem ..)), do any instantiation inside
4103 since we know we'll be making the inside valid when we finally
4104 remove the ADDRESSOF. */
4105 instantiate_virtual_regs_1 (&XEXP (XEXP (x
, 0), 0), NULL_RTX
, 0);
4114 /* Scan all subexpressions. */
4115 fmt
= GET_RTX_FORMAT (code
);
4116 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
4119 if (!instantiate_virtual_regs_1 (&XEXP (x
, i
), object
, extra_insns
))
4122 else if (*fmt
== 'E')
4123 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
4124 if (! instantiate_virtual_regs_1 (&XVECEXP (x
, i
, j
), object
,
4131 /* Optimization: assuming this function does not receive nonlocal gotos,
4132 delete the handlers for such, as well as the insns to establish
4133 and disestablish them. */
4139 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4141 /* Delete the handler by turning off the flag that would
4142 prevent jump_optimize from deleting it.
4143 Also permit deletion of the nonlocal labels themselves
4144 if nothing local refers to them. */
4145 if (GET_CODE (insn
) == CODE_LABEL
)
4149 LABEL_PRESERVE_P (insn
) = 0;
4151 /* Remove it from the nonlocal_label list, to avoid confusing
4153 for (t
= nonlocal_labels
, last_t
= 0; t
;
4154 last_t
= t
, t
= TREE_CHAIN (t
))
4155 if (DECL_RTL (TREE_VALUE (t
)) == insn
)
4160 nonlocal_labels
= TREE_CHAIN (nonlocal_labels
);
4162 TREE_CHAIN (last_t
) = TREE_CHAIN (t
);
4165 if (GET_CODE (insn
) == INSN
)
4169 for (t
= nonlocal_goto_handler_slots
; t
!= 0; t
= XEXP (t
, 1))
4170 if (reg_mentioned_p (t
, PATTERN (insn
)))
4176 || (nonlocal_goto_stack_level
!= 0
4177 && reg_mentioned_p (nonlocal_goto_stack_level
,
4179 delete_related_insns (insn
);
4187 return max_parm_reg
;
4190 /* Return the first insn following those generated by `assign_parms'. */
4193 get_first_nonparm_insn ()
4196 return NEXT_INSN (last_parm_insn
);
4197 return get_insns ();
4200 /* Return the first NOTE_INSN_BLOCK_BEG note in the function.
4201 Crash if there is none. */
4204 get_first_block_beg ()
4207 rtx insn
= get_first_nonparm_insn ();
4209 for (searcher
= insn
; searcher
; searcher
= NEXT_INSN (searcher
))
4210 if (GET_CODE (searcher
) == NOTE
4211 && NOTE_LINE_NUMBER (searcher
) == NOTE_INSN_BLOCK_BEG
)
4214 abort (); /* Invalid call to this function. (See comments above.) */
4218 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
4219 This means a type for which function calls must pass an address to the
4220 function or get an address back from the function.
4221 EXP may be a type node or an expression (whose type is tested). */
4224 aggregate_value_p (exp
)
4227 int i
, regno
, nregs
;
4230 tree type
= (TYPE_P (exp
)) ? exp
: TREE_TYPE (exp
);
4232 if (TREE_CODE (type
) == VOID_TYPE
)
4234 if (RETURN_IN_MEMORY (type
))
4236 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
4237 and thus can't be returned in registers. */
4238 if (TREE_ADDRESSABLE (type
))
4240 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
4242 /* Make sure we have suitable call-clobbered regs to return
4243 the value in; if not, we must return it in memory. */
4244 reg
= hard_function_value (type
, 0, 0);
4246 /* If we have something other than a REG (e.g. a PARALLEL), then assume
4248 if (GET_CODE (reg
) != REG
)
4251 regno
= REGNO (reg
);
4252 nregs
= HARD_REGNO_NREGS (regno
, TYPE_MODE (type
));
4253 for (i
= 0; i
< nregs
; i
++)
4254 if (! call_used_regs
[regno
+ i
])
4259 /* Assign RTL expressions to the function's parameters.
4260 This may involve copying them into registers and using
4261 those registers as the RTL for them. */
4264 assign_parms (fndecl
)
4270 CUMULATIVE_ARGS args_so_far
;
4271 enum machine_mode promoted_mode
, passed_mode
;
4272 enum machine_mode nominal_mode
, promoted_nominal_mode
;
4274 /* Total space needed so far for args on the stack,
4275 given as a constant and a tree-expression. */
4276 struct args_size stack_args_size
;
4277 tree fntype
= TREE_TYPE (fndecl
);
4278 tree fnargs
= DECL_ARGUMENTS (fndecl
);
4279 /* This is used for the arg pointer when referring to stack args. */
4280 rtx internal_arg_pointer
;
4281 /* This is a dummy PARM_DECL that we used for the function result if
4282 the function returns a structure. */
4283 tree function_result_decl
= 0;
4284 #ifdef SETUP_INCOMING_VARARGS
4285 int varargs_setup
= 0;
4287 rtx conversion_insns
= 0;
4288 struct args_size alignment_pad
;
4290 /* Nonzero if function takes extra anonymous args.
4291 This means the last named arg must be on the stack
4292 right before the anonymous ones. */
4294 = (TYPE_ARG_TYPES (fntype
) != 0
4295 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype
)))
4296 != void_type_node
));
4298 current_function_stdarg
= stdarg
;
4300 /* If the reg that the virtual arg pointer will be translated into is
4301 not a fixed reg or is the stack pointer, make a copy of the virtual
4302 arg pointer, and address parms via the copy. The frame pointer is
4303 considered fixed even though it is not marked as such.
4305 The second time through, simply use ap to avoid generating rtx. */
4307 if ((ARG_POINTER_REGNUM
== STACK_POINTER_REGNUM
4308 || ! (fixed_regs
[ARG_POINTER_REGNUM
]
4309 || ARG_POINTER_REGNUM
== FRAME_POINTER_REGNUM
)))
4310 internal_arg_pointer
= copy_to_reg (virtual_incoming_args_rtx
);
4312 internal_arg_pointer
= virtual_incoming_args_rtx
;
4313 current_function_internal_arg_pointer
= internal_arg_pointer
;
4315 stack_args_size
.constant
= 0;
4316 stack_args_size
.var
= 0;
4318 /* If struct value address is treated as the first argument, make it so. */
4319 if (aggregate_value_p (DECL_RESULT (fndecl
))
4320 && ! current_function_returns_pcc_struct
4321 && struct_value_incoming_rtx
== 0)
4323 tree type
= build_pointer_type (TREE_TYPE (fntype
));
4325 function_result_decl
= build_decl (PARM_DECL
, NULL_TREE
, type
);
4327 DECL_ARG_TYPE (function_result_decl
) = type
;
4328 TREE_CHAIN (function_result_decl
) = fnargs
;
4329 fnargs
= function_result_decl
;
4332 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
4333 parm_reg_stack_loc
= (rtx
*) ggc_alloc_cleared (max_parm_reg
* sizeof (rtx
));
4335 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
4336 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far
, fntype
, NULL_RTX
);
4338 INIT_CUMULATIVE_ARGS (args_so_far
, fntype
, NULL_RTX
, 0);
4341 /* We haven't yet found an argument that we must push and pretend the
4343 current_function_pretend_args_size
= 0;
4345 for (parm
= fnargs
; parm
; parm
= TREE_CHAIN (parm
))
4347 struct args_size stack_offset
;
4348 struct args_size arg_size
;
4349 int passed_pointer
= 0;
4350 int did_conversion
= 0;
4351 tree passed_type
= DECL_ARG_TYPE (parm
);
4352 tree nominal_type
= TREE_TYPE (parm
);
4354 int last_named
= 0, named_arg
;
4356 /* Set LAST_NAMED if this is last named arg before last
4362 for (tem
= TREE_CHAIN (parm
); tem
; tem
= TREE_CHAIN (tem
))
4363 if (DECL_NAME (tem
))
4369 /* Set NAMED_ARG if this arg should be treated as a named arg. For
4370 most machines, if this is a varargs/stdarg function, then we treat
4371 the last named arg as if it were anonymous too. */
4372 named_arg
= STRICT_ARGUMENT_NAMING
? 1 : ! last_named
;
4374 if (TREE_TYPE (parm
) == error_mark_node
4375 /* This can happen after weird syntax errors
4376 or if an enum type is defined among the parms. */
4377 || TREE_CODE (parm
) != PARM_DECL
4378 || passed_type
== NULL
)
4380 SET_DECL_RTL (parm
, gen_rtx_MEM (BLKmode
, const0_rtx
));
4381 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
4382 TREE_USED (parm
) = 1;
4386 /* Find mode of arg as it is passed, and mode of arg
4387 as it should be during execution of this function. */
4388 passed_mode
= TYPE_MODE (passed_type
);
4389 nominal_mode
= TYPE_MODE (nominal_type
);
4391 /* If the parm's mode is VOID, its value doesn't matter,
4392 and avoid the usual things like emit_move_insn that could crash. */
4393 if (nominal_mode
== VOIDmode
)
4395 SET_DECL_RTL (parm
, const0_rtx
);
4396 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
4400 /* If the parm is to be passed as a transparent union, use the
4401 type of the first field for the tests below. We have already
4402 verified that the modes are the same. */
4403 if (DECL_TRANSPARENT_UNION (parm
)
4404 || (TREE_CODE (passed_type
) == UNION_TYPE
4405 && TYPE_TRANSPARENT_UNION (passed_type
)))
4406 passed_type
= TREE_TYPE (TYPE_FIELDS (passed_type
));
4408 /* See if this arg was passed by invisible reference. It is if
4409 it is an object whose size depends on the contents of the
4410 object itself or if the machine requires these objects be passed
4413 if ((TREE_CODE (TYPE_SIZE (passed_type
)) != INTEGER_CST
4414 && contains_placeholder_p (TYPE_SIZE (passed_type
)))
4415 || TREE_ADDRESSABLE (passed_type
)
4416 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
4417 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far
, passed_mode
,
4418 passed_type
, named_arg
)
4422 passed_type
= nominal_type
= build_pointer_type (passed_type
);
4424 passed_mode
= nominal_mode
= Pmode
;
4426 /* See if the frontend wants to pass this by invisible reference. */
4427 else if (passed_type
!= nominal_type
4428 && POINTER_TYPE_P (passed_type
)
4429 && TREE_TYPE (passed_type
) == nominal_type
)
4431 nominal_type
= passed_type
;
4433 passed_mode
= nominal_mode
= Pmode
;
4436 promoted_mode
= passed_mode
;
4438 #ifdef PROMOTE_FUNCTION_ARGS
4439 /* Compute the mode in which the arg is actually extended to. */
4440 unsignedp
= TREE_UNSIGNED (passed_type
);
4441 promoted_mode
= promote_mode (passed_type
, promoted_mode
, &unsignedp
, 1);
4444 /* Let machine desc say which reg (if any) the parm arrives in.
4445 0 means it arrives on the stack. */
4446 #ifdef FUNCTION_INCOMING_ARG
4447 entry_parm
= FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
4448 passed_type
, named_arg
);
4450 entry_parm
= FUNCTION_ARG (args_so_far
, promoted_mode
,
4451 passed_type
, named_arg
);
4454 if (entry_parm
== 0)
4455 promoted_mode
= passed_mode
;
4457 #ifdef SETUP_INCOMING_VARARGS
4458 /* If this is the last named parameter, do any required setup for
4459 varargs or stdargs. We need to know about the case of this being an
4460 addressable type, in which case we skip the registers it
4461 would have arrived in.
4463 For stdargs, LAST_NAMED will be set for two parameters, the one that
4464 is actually the last named, and the dummy parameter. We only
4465 want to do this action once.
4467 Also, indicate when RTL generation is to be suppressed. */
4468 if (last_named
&& !varargs_setup
)
4470 SETUP_INCOMING_VARARGS (args_so_far
, promoted_mode
, passed_type
,
4471 current_function_pretend_args_size
, 0);
4476 /* Determine parm's home in the stack,
4477 in case it arrives in the stack or we should pretend it did.
4479 Compute the stack position and rtx where the argument arrives
4482 There is one complexity here: If this was a parameter that would
4483 have been passed in registers, but wasn't only because it is
4484 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
4485 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
4486 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
4487 0 as it was the previous time. */
4489 pretend_named
= named_arg
|| PRETEND_OUTGOING_VARARGS_NAMED
;
4490 locate_and_pad_parm (promoted_mode
, passed_type
,
4491 #ifdef STACK_PARMS_IN_REG_PARM_AREA
4494 #ifdef FUNCTION_INCOMING_ARG
4495 FUNCTION_INCOMING_ARG (args_so_far
, promoted_mode
,
4497 pretend_named
) != 0,
4499 FUNCTION_ARG (args_so_far
, promoted_mode
,
4501 pretend_named
) != 0,
4504 fndecl
, &stack_args_size
, &stack_offset
, &arg_size
,
4508 rtx offset_rtx
= ARGS_SIZE_RTX (stack_offset
);
4510 if (offset_rtx
== const0_rtx
)
4511 stack_parm
= gen_rtx_MEM (promoted_mode
, internal_arg_pointer
);
4513 stack_parm
= gen_rtx_MEM (promoted_mode
,
4514 gen_rtx_PLUS (Pmode
,
4515 internal_arg_pointer
,
4518 set_mem_attributes (stack_parm
, parm
, 1);
4521 /* If this parameter was passed both in registers and in the stack,
4522 use the copy on the stack. */
4523 if (MUST_PASS_IN_STACK (promoted_mode
, passed_type
))
4526 #ifdef FUNCTION_ARG_PARTIAL_NREGS
4527 /* If this parm was passed part in regs and part in memory,
4528 pretend it arrived entirely in memory
4529 by pushing the register-part onto the stack.
4531 In the special case of a DImode or DFmode that is split,
4532 we could put it together in a pseudoreg directly,
4533 but for now that's not worth bothering with. */
4537 int nregs
= FUNCTION_ARG_PARTIAL_NREGS (args_so_far
, promoted_mode
,
4538 passed_type
, named_arg
);
4542 current_function_pretend_args_size
4543 = (((nregs
* UNITS_PER_WORD
) + (PARM_BOUNDARY
/ BITS_PER_UNIT
) - 1)
4544 / (PARM_BOUNDARY
/ BITS_PER_UNIT
)
4545 * (PARM_BOUNDARY
/ BITS_PER_UNIT
));
4547 /* Handle calls that pass values in multiple non-contiguous
4548 locations. The Irix 6 ABI has examples of this. */
4549 if (GET_CODE (entry_parm
) == PARALLEL
)
4550 emit_group_store (validize_mem (stack_parm
), entry_parm
,
4551 int_size_in_bytes (TREE_TYPE (parm
)));
4554 move_block_from_reg (REGNO (entry_parm
),
4555 validize_mem (stack_parm
), nregs
,
4556 int_size_in_bytes (TREE_TYPE (parm
)));
4558 entry_parm
= stack_parm
;
4563 /* If we didn't decide this parm came in a register,
4564 by default it came on the stack. */
4565 if (entry_parm
== 0)
4566 entry_parm
= stack_parm
;
4568 /* Record permanently how this parm was passed. */
4569 DECL_INCOMING_RTL (parm
) = entry_parm
;
4571 /* If there is actually space on the stack for this parm,
4572 count it in stack_args_size; otherwise set stack_parm to 0
4573 to indicate there is no preallocated stack slot for the parm. */
4575 if (entry_parm
== stack_parm
4576 || (GET_CODE (entry_parm
) == PARALLEL
4577 && XEXP (XVECEXP (entry_parm
, 0, 0), 0) == NULL_RTX
)
4578 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE)
4579 /* On some machines, even if a parm value arrives in a register
4580 there is still an (uninitialized) stack slot allocated for it.
4582 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell
4583 whether this parameter already has a stack slot allocated,
4584 because an arg block exists only if current_function_args_size
4585 is larger than some threshold, and we haven't calculated that
4586 yet. So, for now, we just assume that stack slots never exist
4588 || REG_PARM_STACK_SPACE (fndecl
) > 0
4592 stack_args_size
.constant
+= arg_size
.constant
;
4594 ADD_PARM_SIZE (stack_args_size
, arg_size
.var
);
4597 /* No stack slot was pushed for this parm. */
4600 /* Update info on where next arg arrives in registers. */
4602 FUNCTION_ARG_ADVANCE (args_so_far
, promoted_mode
,
4603 passed_type
, named_arg
);
4605 /* If we can't trust the parm stack slot to be aligned enough
4606 for its ultimate type, don't use that slot after entry.
4607 We'll make another stack slot, if we need one. */
4609 unsigned int thisparm_boundary
4610 = FUNCTION_ARG_BOUNDARY (promoted_mode
, passed_type
);
4612 if (GET_MODE_ALIGNMENT (nominal_mode
) > thisparm_boundary
)
4616 /* If parm was passed in memory, and we need to convert it on entry,
4617 don't store it back in that same slot. */
4619 && nominal_mode
!= BLKmode
&& nominal_mode
!= passed_mode
)
4622 /* When an argument is passed in multiple locations, we can't
4623 make use of this information, but we can save some copying if
4624 the whole argument is passed in a single register. */
4625 if (GET_CODE (entry_parm
) == PARALLEL
4626 && nominal_mode
!= BLKmode
&& passed_mode
!= BLKmode
)
4628 int i
, len
= XVECLEN (entry_parm
, 0);
4630 for (i
= 0; i
< len
; i
++)
4631 if (XEXP (XVECEXP (entry_parm
, 0, i
), 0) != NULL_RTX
4632 && GET_CODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0)) == REG
4633 && (GET_MODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
4635 && INTVAL (XEXP (XVECEXP (entry_parm
, 0, i
), 1)) == 0)
4637 entry_parm
= XEXP (XVECEXP (entry_parm
, 0, i
), 0);
4638 DECL_INCOMING_RTL (parm
) = entry_parm
;
4643 /* ENTRY_PARM is an RTX for the parameter as it arrives,
4644 in the mode in which it arrives.
4645 STACK_PARM is an RTX for a stack slot where the parameter can live
4646 during the function (in case we want to put it there).
4647 STACK_PARM is 0 if no stack slot was pushed for it.
4649 Now output code if necessary to convert ENTRY_PARM to
4650 the type in which this function declares it,
4651 and store that result in an appropriate place,
4652 which may be a pseudo reg, may be STACK_PARM,
4653 or may be a local stack slot if STACK_PARM is 0.
4655 Set DECL_RTL to that place. */
4657 if (nominal_mode
== BLKmode
|| GET_CODE (entry_parm
) == PARALLEL
)
4659 /* If a BLKmode arrives in registers, copy it to a stack slot.
4660 Handle calls that pass values in multiple non-contiguous
4661 locations. The Irix 6 ABI has examples of this. */
4662 if (GET_CODE (entry_parm
) == REG
4663 || GET_CODE (entry_parm
) == PARALLEL
)
4666 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm
)),
4669 /* Note that we will be storing an integral number of words.
4670 So we have to be careful to ensure that we allocate an
4671 integral number of words. We do this below in the
4672 assign_stack_local if space was not allocated in the argument
4673 list. If it was, this will not work if PARM_BOUNDARY is not
4674 a multiple of BITS_PER_WORD. It isn't clear how to fix this
4675 if it becomes a problem. */
4677 if (stack_parm
== 0)
4680 = assign_stack_local (GET_MODE (entry_parm
),
4682 set_mem_attributes (stack_parm
, parm
, 1);
4685 else if (PARM_BOUNDARY
% BITS_PER_WORD
!= 0)
4688 /* Handle calls that pass values in multiple non-contiguous
4689 locations. The Irix 6 ABI has examples of this. */
4690 if (GET_CODE (entry_parm
) == PARALLEL
)
4691 emit_group_store (validize_mem (stack_parm
), entry_parm
,
4692 int_size_in_bytes (TREE_TYPE (parm
)));
4694 move_block_from_reg (REGNO (entry_parm
),
4695 validize_mem (stack_parm
),
4696 size_stored
/ UNITS_PER_WORD
,
4697 int_size_in_bytes (TREE_TYPE (parm
)));
4699 SET_DECL_RTL (parm
, stack_parm
);
4701 else if (! ((! optimize
4702 && ! DECL_REGISTER (parm
))
4703 || TREE_SIDE_EFFECTS (parm
)
4704 /* If -ffloat-store specified, don't put explicit
4705 float variables into registers. */
4706 || (flag_float_store
4707 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))
4708 /* Always assign pseudo to structure return or item passed
4709 by invisible reference. */
4710 || passed_pointer
|| parm
== function_result_decl
)
4712 /* Store the parm in a pseudoregister during the function, but we
4713 may need to do it in a wider mode. */
4716 unsigned int regno
, regnoi
= 0, regnor
= 0;
4718 unsignedp
= TREE_UNSIGNED (TREE_TYPE (parm
));
4720 promoted_nominal_mode
4721 = promote_mode (TREE_TYPE (parm
), nominal_mode
, &unsignedp
, 0);
4723 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
4724 mark_user_reg (parmreg
);
4726 /* If this was an item that we received a pointer to, set DECL_RTL
4730 rtx x
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type
)),
4732 set_mem_attributes (x
, parm
, 1);
4733 SET_DECL_RTL (parm
, x
);
4737 SET_DECL_RTL (parm
, parmreg
);
4738 maybe_set_unchanging (DECL_RTL (parm
), parm
);
4741 /* Copy the value into the register. */
4742 if (nominal_mode
!= passed_mode
4743 || promoted_nominal_mode
!= promoted_mode
)
4746 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
4747 mode, by the caller. We now have to convert it to
4748 NOMINAL_MODE, if different. However, PARMREG may be in
4749 a different mode than NOMINAL_MODE if it is being stored
4752 If ENTRY_PARM is a hard register, it might be in a register
4753 not valid for operating in its mode (e.g., an odd-numbered
4754 register for a DFmode). In that case, moves are the only
4755 thing valid, so we can't do a convert from there. This
4756 occurs when the calling sequence allow such misaligned
4759 In addition, the conversion may involve a call, which could
4760 clobber parameters which haven't been copied to pseudo
4761 registers yet. Therefore, we must first copy the parm to
4762 a pseudo reg here, and save the conversion until after all
4763 parameters have been moved. */
4765 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
4767 emit_move_insn (tempreg
, validize_mem (entry_parm
));
4769 push_to_sequence (conversion_insns
);
4770 tempreg
= convert_to_mode (nominal_mode
, tempreg
, unsignedp
);
4772 if (GET_CODE (tempreg
) == SUBREG
4773 && GET_MODE (tempreg
) == nominal_mode
4774 && GET_CODE (SUBREG_REG (tempreg
)) == REG
4775 && nominal_mode
== passed_mode
4776 && GET_MODE (SUBREG_REG (tempreg
)) == GET_MODE (entry_parm
)
4777 && GET_MODE_SIZE (GET_MODE (tempreg
))
4778 < GET_MODE_SIZE (GET_MODE (entry_parm
)))
4780 /* The argument is already sign/zero extended, so note it
4782 SUBREG_PROMOTED_VAR_P (tempreg
) = 1;
4783 SUBREG_PROMOTED_UNSIGNED_SET (tempreg
, unsignedp
);
4786 /* TREE_USED gets set erroneously during expand_assignment. */
4787 save_tree_used
= TREE_USED (parm
);
4788 expand_assignment (parm
,
4789 make_tree (nominal_type
, tempreg
), 0, 0);
4790 TREE_USED (parm
) = save_tree_used
;
4791 conversion_insns
= get_insns ();
4796 emit_move_insn (parmreg
, validize_mem (entry_parm
));
4798 /* If we were passed a pointer but the actual value
4799 can safely live in a register, put it in one. */
4800 if (passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
4801 /* If by-reference argument was promoted, demote it. */
4802 && (TYPE_MODE (TREE_TYPE (parm
)) != GET_MODE (DECL_RTL (parm
))
4804 && ! DECL_REGISTER (parm
))
4805 || TREE_SIDE_EFFECTS (parm
)
4806 /* If -ffloat-store specified, don't put explicit
4807 float variables into registers. */
4808 || (flag_float_store
4809 && TREE_CODE (TREE_TYPE (parm
)) == REAL_TYPE
))))
4811 /* We can't use nominal_mode, because it will have been set to
4812 Pmode above. We must use the actual mode of the parm. */
4813 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
4814 mark_user_reg (parmreg
);
4815 if (GET_MODE (parmreg
) != GET_MODE (DECL_RTL (parm
)))
4817 rtx tempreg
= gen_reg_rtx (GET_MODE (DECL_RTL (parm
)));
4818 int unsigned_p
= TREE_UNSIGNED (TREE_TYPE (parm
));
4819 push_to_sequence (conversion_insns
);
4820 emit_move_insn (tempreg
, DECL_RTL (parm
));
4822 convert_to_mode (GET_MODE (parmreg
),
4825 emit_move_insn (parmreg
, DECL_RTL (parm
));
4826 conversion_insns
= get_insns();
4831 emit_move_insn (parmreg
, DECL_RTL (parm
));
4832 SET_DECL_RTL (parm
, parmreg
);
4833 /* STACK_PARM is the pointer, not the parm, and PARMREG is
4837 #ifdef FUNCTION_ARG_CALLEE_COPIES
4838 /* If we are passed an arg by reference and it is our responsibility
4839 to make a copy, do it now.
4840 PASSED_TYPE and PASSED mode now refer to the pointer, not the
4841 original argument, so we must recreate them in the call to
4842 FUNCTION_ARG_CALLEE_COPIES. */
4843 /* ??? Later add code to handle the case that if the argument isn't
4844 modified, don't do the copy. */
4846 else if (passed_pointer
4847 && FUNCTION_ARG_CALLEE_COPIES (args_so_far
,
4848 TYPE_MODE (DECL_ARG_TYPE (parm
)),
4849 DECL_ARG_TYPE (parm
),
4851 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm
)))
4854 tree type
= DECL_ARG_TYPE (parm
);
4856 /* This sequence may involve a library call perhaps clobbering
4857 registers that haven't been copied to pseudos yet. */
4859 push_to_sequence (conversion_insns
);
4861 if (!COMPLETE_TYPE_P (type
)
4862 || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
4863 /* This is a variable sized object. */
4864 copy
= gen_rtx_MEM (BLKmode
,
4865 allocate_dynamic_stack_space
4866 (expr_size (parm
), NULL_RTX
,
4867 TYPE_ALIGN (type
)));
4869 copy
= assign_stack_temp (TYPE_MODE (type
),
4870 int_size_in_bytes (type
), 1);
4871 set_mem_attributes (copy
, parm
, 1);
4873 store_expr (parm
, copy
, 0);
4874 emit_move_insn (parmreg
, XEXP (copy
, 0));
4875 conversion_insns
= get_insns ();
4879 #endif /* FUNCTION_ARG_CALLEE_COPIES */
4881 /* In any case, record the parm's desired stack location
4882 in case we later discover it must live in the stack.
4884 If it is a COMPLEX value, store the stack location for both
4887 if (GET_CODE (parmreg
) == CONCAT
)
4888 regno
= MAX (REGNO (XEXP (parmreg
, 0)), REGNO (XEXP (parmreg
, 1)));
4890 regno
= REGNO (parmreg
);
4892 if (regno
>= max_parm_reg
)
4895 int old_max_parm_reg
= max_parm_reg
;
4897 /* It's slow to expand this one register at a time,
4898 but it's also rare and we need max_parm_reg to be
4899 precisely correct. */
4900 max_parm_reg
= regno
+ 1;
4901 new = (rtx
*) ggc_realloc (parm_reg_stack_loc
,
4902 max_parm_reg
* sizeof (rtx
));
4903 memset ((char *) (new + old_max_parm_reg
), 0,
4904 (max_parm_reg
- old_max_parm_reg
) * sizeof (rtx
));
4905 parm_reg_stack_loc
= new;
4908 if (GET_CODE (parmreg
) == CONCAT
)
4910 enum machine_mode submode
= GET_MODE (XEXP (parmreg
, 0));
4912 regnor
= REGNO (gen_realpart (submode
, parmreg
));
4913 regnoi
= REGNO (gen_imagpart (submode
, parmreg
));
4915 if (stack_parm
!= 0)
4917 parm_reg_stack_loc
[regnor
]
4918 = gen_realpart (submode
, stack_parm
);
4919 parm_reg_stack_loc
[regnoi
]
4920 = gen_imagpart (submode
, stack_parm
);
4924 parm_reg_stack_loc
[regnor
] = 0;
4925 parm_reg_stack_loc
[regnoi
] = 0;
4929 parm_reg_stack_loc
[REGNO (parmreg
)] = stack_parm
;
4931 /* Mark the register as eliminable if we did no conversion
4932 and it was copied from memory at a fixed offset,
4933 and the arg pointer was not copied to a pseudo-reg.
4934 If the arg pointer is a pseudo reg or the offset formed
4935 an invalid address, such memory-equivalences
4936 as we make here would screw up life analysis for it. */
4937 if (nominal_mode
== passed_mode
4940 && GET_CODE (stack_parm
) == MEM
4941 && stack_offset
.var
== 0
4942 && reg_mentioned_p (virtual_incoming_args_rtx
,
4943 XEXP (stack_parm
, 0)))
4945 rtx linsn
= get_last_insn ();
4948 /* Mark complex types separately. */
4949 if (GET_CODE (parmreg
) == CONCAT
)
4950 /* Scan backwards for the set of the real and
4952 for (sinsn
= linsn
; sinsn
!= 0;
4953 sinsn
= prev_nonnote_insn (sinsn
))
4955 set
= single_set (sinsn
);
4957 && SET_DEST (set
) == regno_reg_rtx
[regnoi
])
4959 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4960 parm_reg_stack_loc
[regnoi
],
4963 && SET_DEST (set
) == regno_reg_rtx
[regnor
])
4965 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4966 parm_reg_stack_loc
[regnor
],
4969 else if ((set
= single_set (linsn
)) != 0
4970 && SET_DEST (set
) == parmreg
)
4972 = gen_rtx_EXPR_LIST (REG_EQUIV
,
4973 stack_parm
, REG_NOTES (linsn
));
4976 /* For pointer data type, suggest pointer register. */
4977 if (POINTER_TYPE_P (TREE_TYPE (parm
)))
4978 mark_reg_pointer (parmreg
,
4979 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
4981 /* If something wants our address, try to use ADDRESSOF. */
4982 if (TREE_ADDRESSABLE (parm
))
4984 /* If we end up putting something into the stack,
4985 fixup_var_refs_insns will need to make a pass over
4986 all the instructions. It looks through the pending
4987 sequences -- but it can't see the ones in the
4988 CONVERSION_INSNS, if they're not on the sequence
4989 stack. So, we go back to that sequence, just so that
4990 the fixups will happen. */
4991 push_to_sequence (conversion_insns
);
4992 put_var_into_stack (parm
);
4993 conversion_insns
= get_insns ();
4999 /* Value must be stored in the stack slot STACK_PARM
5000 during function execution. */
5002 if (promoted_mode
!= nominal_mode
)
5004 /* Conversion is required. */
5005 rtx tempreg
= gen_reg_rtx (GET_MODE (entry_parm
));
5007 emit_move_insn (tempreg
, validize_mem (entry_parm
));
5009 push_to_sequence (conversion_insns
);
5010 entry_parm
= convert_to_mode (nominal_mode
, tempreg
,
5011 TREE_UNSIGNED (TREE_TYPE (parm
)));
5013 /* ??? This may need a big-endian conversion on sparc64. */
5014 stack_parm
= adjust_address (stack_parm
, nominal_mode
, 0);
5016 conversion_insns
= get_insns ();
5021 if (entry_parm
!= stack_parm
)
5023 if (stack_parm
== 0)
5026 = assign_stack_local (GET_MODE (entry_parm
),
5027 GET_MODE_SIZE (GET_MODE (entry_parm
)), 0);
5028 set_mem_attributes (stack_parm
, parm
, 1);
5031 if (promoted_mode
!= nominal_mode
)
5033 push_to_sequence (conversion_insns
);
5034 emit_move_insn (validize_mem (stack_parm
),
5035 validize_mem (entry_parm
));
5036 conversion_insns
= get_insns ();
5040 emit_move_insn (validize_mem (stack_parm
),
5041 validize_mem (entry_parm
));
5044 SET_DECL_RTL (parm
, stack_parm
);
5047 /* If this "parameter" was the place where we are receiving the
5048 function's incoming structure pointer, set up the result. */
5049 if (parm
== function_result_decl
)
5051 tree result
= DECL_RESULT (fndecl
);
5052 rtx addr
= DECL_RTL (parm
);
5055 #ifdef POINTERS_EXTEND_UNSIGNED
5056 if (GET_MODE (addr
) != Pmode
)
5057 addr
= convert_memory_address (Pmode
, addr
);
5060 x
= gen_rtx_MEM (DECL_MODE (result
), addr
);
5061 set_mem_attributes (x
, result
, 1);
5062 SET_DECL_RTL (result
, x
);
5065 if (GET_CODE (DECL_RTL (parm
)) == REG
)
5066 REGNO_DECL (REGNO (DECL_RTL (parm
))) = parm
;
5067 else if (GET_CODE (DECL_RTL (parm
)) == CONCAT
)
5069 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm
), 0))) = parm
;
5070 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm
), 1))) = parm
;
5075 /* Output all parameter conversion instructions (possibly including calls)
5076 now that all parameters have been copied out of hard registers. */
5077 emit_insn (conversion_insns
);
5079 last_parm_insn
= get_last_insn ();
5081 current_function_args_size
= stack_args_size
.constant
;
5083 /* Adjust function incoming argument size for alignment and
5086 #ifdef REG_PARM_STACK_SPACE
5087 #ifndef MAYBE_REG_PARM_STACK_SPACE
5088 current_function_args_size
= MAX (current_function_args_size
,
5089 REG_PARM_STACK_SPACE (fndecl
));
5093 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
5095 current_function_args_size
5096 = ((current_function_args_size
+ STACK_BYTES
- 1)
5097 / STACK_BYTES
) * STACK_BYTES
;
5099 #ifdef ARGS_GROW_DOWNWARD
5100 current_function_arg_offset_rtx
5101 = (stack_args_size
.var
== 0 ? GEN_INT (-stack_args_size
.constant
)
5102 : expand_expr (size_diffop (stack_args_size
.var
,
5103 size_int (-stack_args_size
.constant
)),
5104 NULL_RTX
, VOIDmode
, 0));
5106 current_function_arg_offset_rtx
= ARGS_SIZE_RTX (stack_args_size
);
5109 /* See how many bytes, if any, of its args a function should try to pop
5112 current_function_pops_args
= RETURN_POPS_ARGS (fndecl
, TREE_TYPE (fndecl
),
5113 current_function_args_size
);
5115 /* For stdarg.h function, save info about
5116 regs and stack space used by the named args. */
5118 current_function_args_info
= args_so_far
;
5120 /* Set the rtx used for the function return value. Put this in its
5121 own variable so any optimizers that need this information don't have
5122 to include tree.h. Do this here so it gets done when an inlined
5123 function gets output. */
5125 current_function_return_rtx
5126 = (DECL_RTL_SET_P (DECL_RESULT (fndecl
))
5127 ? DECL_RTL (DECL_RESULT (fndecl
)) : NULL_RTX
);
5129 /* If scalar return value was computed in a pseudo-reg, or was a named
5130 return value that got dumped to the stack, copy that to the hard
5132 if (DECL_RTL_SET_P (DECL_RESULT (fndecl
)))
5134 tree decl_result
= DECL_RESULT (fndecl
);
5135 rtx decl_rtl
= DECL_RTL (decl_result
);
5137 if (REG_P (decl_rtl
)
5138 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
5139 : DECL_REGISTER (decl_result
))
5143 #ifdef FUNCTION_OUTGOING_VALUE
5144 real_decl_rtl
= FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result
),
5147 real_decl_rtl
= FUNCTION_VALUE (TREE_TYPE (decl_result
),
5150 REG_FUNCTION_VALUE_P (real_decl_rtl
) = 1;
5151 /* The delay slot scheduler assumes that current_function_return_rtx
5152 holds the hard register containing the return value, not a
5153 temporary pseudo. */
5154 current_function_return_rtx
= real_decl_rtl
;
5159 /* Indicate whether REGNO is an incoming argument to the current function
5160 that was promoted to a wider mode. If so, return the RTX for the
5161 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode
5162 that REGNO is promoted from and whether the promotion was signed or
5165 #ifdef PROMOTE_FUNCTION_ARGS
5168 promoted_input_arg (regno
, pmode
, punsignedp
)
5170 enum machine_mode
*pmode
;
5175 for (arg
= DECL_ARGUMENTS (current_function_decl
); arg
;
5176 arg
= TREE_CHAIN (arg
))
5177 if (GET_CODE (DECL_INCOMING_RTL (arg
)) == REG
5178 && REGNO (DECL_INCOMING_RTL (arg
)) == regno
5179 && TYPE_MODE (DECL_ARG_TYPE (arg
)) == TYPE_MODE (TREE_TYPE (arg
)))
5181 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (arg
));
5182 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (arg
));
5184 mode
= promote_mode (TREE_TYPE (arg
), mode
, &unsignedp
, 1);
5185 if (mode
== GET_MODE (DECL_INCOMING_RTL (arg
))
5186 && mode
!= DECL_MODE (arg
))
5188 *pmode
= DECL_MODE (arg
);
5189 *punsignedp
= unsignedp
;
5190 return DECL_INCOMING_RTL (arg
);
5199 /* Compute the size and offset from the start of the stacked arguments for a
5200 parm passed in mode PASSED_MODE and with type TYPE.
5202 INITIAL_OFFSET_PTR points to the current offset into the stacked
5205 The starting offset and size for this parm are returned in *OFFSET_PTR
5206 and *ARG_SIZE_PTR, respectively.
5208 IN_REGS is nonzero if the argument will be passed in registers. It will
5209 never be set if REG_PARM_STACK_SPACE is not defined.
5211 FNDECL is the function in which the argument was defined.
5213 There are two types of rounding that are done. The first, controlled by
5214 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
5215 list to be aligned to the specific boundary (in bits). This rounding
5216 affects the initial and starting offsets, but not the argument size.
5218 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
5219 optionally rounds the size of the parm to PARM_BOUNDARY. The
5220 initial offset is not affected by this rounding, while the size always
5221 is and the starting offset may be. */
5223 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case;
5224 initial_offset_ptr is positive because locate_and_pad_parm's
5225 callers pass in the total size of args so far as
5226 initial_offset_ptr. arg_size_ptr is always positive. */
5229 locate_and_pad_parm (passed_mode
, type
, in_regs
, fndecl
,
5230 initial_offset_ptr
, offset_ptr
, arg_size_ptr
,
5232 enum machine_mode passed_mode
;
5234 int in_regs ATTRIBUTE_UNUSED
;
5235 tree fndecl ATTRIBUTE_UNUSED
;
5236 struct args_size
*initial_offset_ptr
;
5237 struct args_size
*offset_ptr
;
5238 struct args_size
*arg_size_ptr
;
5239 struct args_size
*alignment_pad
;
5243 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
5244 enum direction where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
5245 int boundary
= FUNCTION_ARG_BOUNDARY (passed_mode
, type
);
5246 #ifdef ARGS_GROW_DOWNWARD
5250 #ifdef REG_PARM_STACK_SPACE
5251 /* If we have found a stack parm before we reach the end of the
5252 area reserved for registers, skip that area. */
5255 int reg_parm_stack_space
= 0;
5257 #ifdef MAYBE_REG_PARM_STACK_SPACE
5258 reg_parm_stack_space
= MAYBE_REG_PARM_STACK_SPACE
;
5260 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
5262 if (reg_parm_stack_space
> 0)
5264 if (initial_offset_ptr
->var
)
5266 initial_offset_ptr
->var
5267 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
5268 ssize_int (reg_parm_stack_space
));
5269 initial_offset_ptr
->constant
= 0;
5271 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
5272 initial_offset_ptr
->constant
= reg_parm_stack_space
;
5275 #endif /* REG_PARM_STACK_SPACE */
5277 arg_size_ptr
->var
= 0;
5278 arg_size_ptr
->constant
= 0;
5279 alignment_pad
->var
= 0;
5280 alignment_pad
->constant
= 0;
5282 #ifdef ARGS_GROW_DOWNWARD
5283 if (initial_offset_ptr
->var
)
5285 offset_ptr
->constant
= 0;
5286 offset_ptr
->var
= size_binop (MINUS_EXPR
, ssize_int (0),
5287 initial_offset_ptr
->var
);
5291 offset_ptr
->constant
= -initial_offset_ptr
->constant
;
5292 offset_ptr
->var
= 0;
5295 if (where_pad
!= none
5296 && (!host_integerp (sizetree
, 1)
5297 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % PARM_BOUNDARY
))
5298 s2
= round_up (s2
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5299 SUB_PARM_SIZE (*offset_ptr
, s2
);
5302 #ifdef REG_PARM_STACK_SPACE
5303 || REG_PARM_STACK_SPACE (fndecl
) > 0
5306 pad_to_arg_alignment (offset_ptr
, boundary
, alignment_pad
);
5308 if (initial_offset_ptr
->var
)
5309 arg_size_ptr
->var
= size_binop (MINUS_EXPR
,
5310 size_binop (MINUS_EXPR
,
5312 initial_offset_ptr
->var
),
5316 arg_size_ptr
->constant
= (-initial_offset_ptr
->constant
5317 - offset_ptr
->constant
);
5319 /* Pad_below needs the pre-rounded size to know how much to pad below.
5320 We only pad parameters which are not in registers as they have their
5321 padding done elsewhere. */
5322 if (where_pad
== downward
5324 pad_below (offset_ptr
, passed_mode
, sizetree
);
5326 #else /* !ARGS_GROW_DOWNWARD */
5328 #ifdef REG_PARM_STACK_SPACE
5329 || REG_PARM_STACK_SPACE (fndecl
) > 0
5332 pad_to_arg_alignment (initial_offset_ptr
, boundary
, alignment_pad
);
5333 *offset_ptr
= *initial_offset_ptr
;
5335 #ifdef PUSH_ROUNDING
5336 if (passed_mode
!= BLKmode
)
5337 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
5340 /* Pad_below needs the pre-rounded size to know how much to pad below
5341 so this must be done before rounding up. */
5342 if (where_pad
== downward
5343 /* However, BLKmode args passed in regs have their padding done elsewhere.
5344 The stack slot must be able to hold the entire register. */
5345 && !(in_regs
&& passed_mode
== BLKmode
))
5346 pad_below (offset_ptr
, passed_mode
, sizetree
);
5348 if (where_pad
!= none
5349 && (!host_integerp (sizetree
, 1)
5350 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % PARM_BOUNDARY
))
5351 sizetree
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5353 ADD_PARM_SIZE (*arg_size_ptr
, sizetree
);
5354 #endif /* ARGS_GROW_DOWNWARD */
5357 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
5358 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
5361 pad_to_arg_alignment (offset_ptr
, boundary
, alignment_pad
)
5362 struct args_size
*offset_ptr
;
5364 struct args_size
*alignment_pad
;
5366 tree save_var
= NULL_TREE
;
5367 HOST_WIDE_INT save_constant
= 0;
5369 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
5371 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5373 save_var
= offset_ptr
->var
;
5374 save_constant
= offset_ptr
->constant
;
5377 alignment_pad
->var
= NULL_TREE
;
5378 alignment_pad
->constant
= 0;
5380 if (boundary
> BITS_PER_UNIT
)
5382 if (offset_ptr
->var
)
5385 #ifdef ARGS_GROW_DOWNWARD
5390 (ARGS_SIZE_TREE (*offset_ptr
),
5391 boundary
/ BITS_PER_UNIT
);
5392 offset_ptr
->constant
= 0; /*?*/
5393 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5394 alignment_pad
->var
= size_binop (MINUS_EXPR
, offset_ptr
->var
,
5399 offset_ptr
->constant
=
5400 #ifdef ARGS_GROW_DOWNWARD
5401 FLOOR_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
5403 CEIL_ROUND (offset_ptr
->constant
, boundary_in_bytes
);
5405 if (boundary
> PARM_BOUNDARY
&& boundary
> STACK_BOUNDARY
)
5406 alignment_pad
->constant
= offset_ptr
->constant
- save_constant
;
5412 pad_below (offset_ptr
, passed_mode
, sizetree
)
5413 struct args_size
*offset_ptr
;
5414 enum machine_mode passed_mode
;
5417 if (passed_mode
!= BLKmode
)
5419 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
5420 offset_ptr
->constant
5421 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
5422 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
5423 - GET_MODE_SIZE (passed_mode
));
5427 if (TREE_CODE (sizetree
) != INTEGER_CST
5428 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
5430 /* Round the size up to multiple of PARM_BOUNDARY bits. */
5431 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
5433 ADD_PARM_SIZE (*offset_ptr
, s2
);
5434 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
5439 /* Walk the tree of blocks describing the binding levels within a function
5440 and warn about uninitialized variables.
5441 This is done after calling flow_analysis and before global_alloc
5442 clobbers the pseudo-regs to hard regs. */
5445 uninitialized_vars_warning (block
)
5449 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
5451 if (warn_uninitialized
5452 && TREE_CODE (decl
) == VAR_DECL
5453 /* These warnings are unreliable for and aggregates
5454 because assigning the fields one by one can fail to convince
5455 flow.c that the entire aggregate was initialized.
5456 Unions are troublesome because members may be shorter. */
5457 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl
))
5458 && DECL_RTL (decl
) != 0
5459 && GET_CODE (DECL_RTL (decl
)) == REG
5460 /* Global optimizations can make it difficult to determine if a
5461 particular variable has been initialized. However, a VAR_DECL
5462 with a nonzero DECL_INITIAL had an initializer, so do not
5463 claim it is potentially uninitialized.
5465 We do not care about the actual value in DECL_INITIAL, so we do
5466 not worry that it may be a dangling pointer. */
5467 && DECL_INITIAL (decl
) == NULL_TREE
5468 && regno_uninitialized (REGNO (DECL_RTL (decl
))))
5469 warning_with_decl (decl
,
5470 "`%s' might be used uninitialized in this function");
5472 && TREE_CODE (decl
) == VAR_DECL
5473 && DECL_RTL (decl
) != 0
5474 && GET_CODE (DECL_RTL (decl
)) == REG
5475 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
5476 warning_with_decl (decl
,
5477 "variable `%s' might be clobbered by `longjmp' or `vfork'");
5479 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
5480 uninitialized_vars_warning (sub
);
5483 /* Do the appropriate part of uninitialized_vars_warning
5484 but for arguments instead of local variables. */
5487 setjmp_args_warning ()
5490 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5491 decl
; decl
= TREE_CHAIN (decl
))
5492 if (DECL_RTL (decl
) != 0
5493 && GET_CODE (DECL_RTL (decl
)) == REG
5494 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl
))))
5495 warning_with_decl (decl
,
5496 "argument `%s' might be clobbered by `longjmp' or `vfork'");
5499 /* If this function call setjmp, put all vars into the stack
5500 unless they were declared `register'. */
5503 setjmp_protect (block
)
5507 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
5508 if ((TREE_CODE (decl
) == VAR_DECL
5509 || TREE_CODE (decl
) == PARM_DECL
)
5510 && DECL_RTL (decl
) != 0
5511 && (GET_CODE (DECL_RTL (decl
)) == REG
5512 || (GET_CODE (DECL_RTL (decl
)) == MEM
5513 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
5514 /* If this variable came from an inline function, it must be
5515 that its life doesn't overlap the setjmp. If there was a
5516 setjmp in the function, it would already be in memory. We
5517 must exclude such variable because their DECL_RTL might be
5518 set to strange things such as virtual_stack_vars_rtx. */
5519 && ! DECL_FROM_INLINE (decl
)
5521 #ifdef NON_SAVING_SETJMP
5522 /* If longjmp doesn't restore the registers,
5523 don't put anything in them. */
5527 ! DECL_REGISTER (decl
)))
5528 put_var_into_stack (decl
);
5529 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= TREE_CHAIN (sub
))
5530 setjmp_protect (sub
);
5533 /* Like the previous function, but for args instead of local variables. */
5536 setjmp_protect_args ()
5539 for (decl
= DECL_ARGUMENTS (current_function_decl
);
5540 decl
; decl
= TREE_CHAIN (decl
))
5541 if ((TREE_CODE (decl
) == VAR_DECL
5542 || TREE_CODE (decl
) == PARM_DECL
)
5543 && DECL_RTL (decl
) != 0
5544 && (GET_CODE (DECL_RTL (decl
)) == REG
5545 || (GET_CODE (DECL_RTL (decl
)) == MEM
5546 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == ADDRESSOF
))
5548 /* If longjmp doesn't restore the registers,
5549 don't put anything in them. */
5550 #ifdef NON_SAVING_SETJMP
5554 ! DECL_REGISTER (decl
)))
5555 put_var_into_stack (decl
);
5558 /* Return the context-pointer register corresponding to DECL,
5559 or 0 if it does not need one. */
5562 lookup_static_chain (decl
)
5565 tree context
= decl_function_context (decl
);
5569 || (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_NO_STATIC_CHAIN (decl
)))
5572 /* We treat inline_function_decl as an alias for the current function
5573 because that is the inline function whose vars, types, etc.
5574 are being merged into the current function.
5575 See expand_inline_function. */
5576 if (context
== current_function_decl
|| context
== inline_function_decl
)
5577 return virtual_stack_vars_rtx
;
5579 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
5580 if (TREE_PURPOSE (link
) == context
)
5581 return RTL_EXPR_RTL (TREE_VALUE (link
));
5586 /* Convert a stack slot address ADDR for variable VAR
5587 (from a containing function)
5588 into an address valid in this function (using a static chain). */
5591 fix_lexical_addr (addr
, var
)
5596 HOST_WIDE_INT displacement
;
5597 tree context
= decl_function_context (var
);
5598 struct function
*fp
;
5601 /* If this is the present function, we need not do anything. */
5602 if (context
== current_function_decl
|| context
== inline_function_decl
)
5605 fp
= find_function_data (context
);
5607 if (GET_CODE (addr
) == ADDRESSOF
&& GET_CODE (XEXP (addr
, 0)) == MEM
)
5608 addr
= XEXP (XEXP (addr
, 0), 0);
5610 /* Decode given address as base reg plus displacement. */
5611 if (GET_CODE (addr
) == REG
)
5612 basereg
= addr
, displacement
= 0;
5613 else if (GET_CODE (addr
) == PLUS
&& GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
5614 basereg
= XEXP (addr
, 0), displacement
= INTVAL (XEXP (addr
, 1));
5618 /* We accept vars reached via the containing function's
5619 incoming arg pointer and via its stack variables pointer. */
5620 if (basereg
== fp
->internal_arg_pointer
)
5622 /* If reached via arg pointer, get the arg pointer value
5623 out of that function's stack frame.
5625 There are two cases: If a separate ap is needed, allocate a
5626 slot in the outer function for it and dereference it that way.
5627 This is correct even if the real ap is actually a pseudo.
5628 Otherwise, just adjust the offset from the frame pointer to
5631 #ifdef NEED_SEPARATE_AP
5634 addr
= get_arg_pointer_save_area (fp
);
5635 addr
= fix_lexical_addr (XEXP (addr
, 0), var
);
5636 addr
= memory_address (Pmode
, addr
);
5638 base
= gen_rtx_MEM (Pmode
, addr
);
5639 set_mem_alias_set (base
, get_frame_alias_set ());
5640 base
= copy_to_reg (base
);
5642 displacement
+= (FIRST_PARM_OFFSET (context
) - STARTING_FRAME_OFFSET
);
5643 base
= lookup_static_chain (var
);
5647 else if (basereg
== virtual_stack_vars_rtx
)
5649 /* This is the same code as lookup_static_chain, duplicated here to
5650 avoid an extra call to decl_function_context. */
5653 for (link
= context_display
; link
; link
= TREE_CHAIN (link
))
5654 if (TREE_PURPOSE (link
) == context
)
5656 base
= RTL_EXPR_RTL (TREE_VALUE (link
));
5664 /* Use same offset, relative to appropriate static chain or argument
5666 return plus_constant (base
, displacement
);
5669 /* Return the address of the trampoline for entering nested fn FUNCTION.
5670 If necessary, allocate a trampoline (in the stack frame)
5671 and emit rtl to initialize its contents (at entry to this function). */
5674 trampoline_address (function
)
5680 struct function
*fp
;
5683 /* Find an existing trampoline and return it. */
5684 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
5685 if (TREE_PURPOSE (link
) == function
)
5687 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0));
5689 for (fp
= outer_function_chain
; fp
; fp
= fp
->outer
)
5690 for (link
= fp
->x_trampoline_list
; link
; link
= TREE_CHAIN (link
))
5691 if (TREE_PURPOSE (link
) == function
)
5693 tramp
= fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link
)), 0),
5695 return adjust_trampoline_addr (tramp
);
5698 /* None exists; we must make one. */
5700 /* Find the `struct function' for the function containing FUNCTION. */
5702 fn_context
= decl_function_context (function
);
5703 if (fn_context
!= current_function_decl
5704 && fn_context
!= inline_function_decl
)
5705 fp
= find_function_data (fn_context
);
5707 /* Allocate run-time space for this trampoline
5708 (usually in the defining function's stack frame). */
5709 #ifdef ALLOCATE_TRAMPOLINE
5710 tramp
= ALLOCATE_TRAMPOLINE (fp
);
5712 /* If rounding needed, allocate extra space
5713 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */
5714 #define TRAMPOLINE_REAL_SIZE \
5715 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1)
5716 tramp
= assign_stack_local_1 (BLKmode
, TRAMPOLINE_REAL_SIZE
, 0,
5720 /* Record the trampoline for reuse and note it for later initialization
5721 by expand_function_end. */
5724 rtlexp
= make_node (RTL_EXPR
);
5725 RTL_EXPR_RTL (rtlexp
) = tramp
;
5726 fp
->x_trampoline_list
= tree_cons (function
, rtlexp
,
5727 fp
->x_trampoline_list
);
5731 /* Make the RTL_EXPR node temporary, not momentary, so that the
5732 trampoline_list doesn't become garbage. */
5733 rtlexp
= make_node (RTL_EXPR
);
5735 RTL_EXPR_RTL (rtlexp
) = tramp
;
5736 trampoline_list
= tree_cons (function
, rtlexp
, trampoline_list
);
5739 tramp
= fix_lexical_addr (XEXP (tramp
, 0), function
);
5740 return adjust_trampoline_addr (tramp
);
5743 /* Given a trampoline address,
5744 round it to multiple of TRAMPOLINE_ALIGNMENT. */
5747 round_trampoline_addr (tramp
)
5750 /* Round address up to desired boundary. */
5751 rtx temp
= gen_reg_rtx (Pmode
);
5752 rtx addend
= GEN_INT (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
- 1);
5753 rtx mask
= GEN_INT (-TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
5755 temp
= expand_simple_binop (Pmode
, PLUS
, tramp
, addend
,
5756 temp
, 0, OPTAB_LIB_WIDEN
);
5757 tramp
= expand_simple_binop (Pmode
, AND
, temp
, mask
,
5758 temp
, 0, OPTAB_LIB_WIDEN
);
5763 /* Given a trampoline address, round it then apply any
5764 platform-specific adjustments so that the result can be used for a
5768 adjust_trampoline_addr (tramp
)
5771 tramp
= round_trampoline_addr (tramp
);
5772 #ifdef TRAMPOLINE_ADJUST_ADDRESS
5773 TRAMPOLINE_ADJUST_ADDRESS (tramp
);
5778 /* Put all this function's BLOCK nodes including those that are chained
5779 onto the first block into a vector, and return it.
5780 Also store in each NOTE for the beginning or end of a block
5781 the index of that block in the vector.
5782 The arguments are BLOCK, the chain of top-level blocks of the function,
5783 and INSNS, the insn chain of the function. */
5789 tree
*block_vector
, *last_block_vector
;
5791 tree block
= DECL_INITIAL (current_function_decl
);
5796 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in
5797 depth-first order. */
5798 block_vector
= get_block_vector (block
, &n_blocks
);
5799 block_stack
= (tree
*) xmalloc (n_blocks
* sizeof (tree
));
5801 last_block_vector
= identify_blocks_1 (get_insns (),
5803 block_vector
+ n_blocks
,
5806 /* If we didn't use all of the subblocks, we've misplaced block notes. */
5807 /* ??? This appears to happen all the time. Latent bugs elsewhere? */
5808 if (0 && last_block_vector
!= block_vector
+ n_blocks
)
5811 free (block_vector
);
5815 /* Subroutine of identify_blocks. Do the block substitution on the
5816 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains.
5818 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair.
5819 BLOCK_VECTOR is incremented for each block seen. */
5822 identify_blocks_1 (insns
, block_vector
, end_block_vector
, orig_block_stack
)
5825 tree
*end_block_vector
;
5826 tree
*orig_block_stack
;
5829 tree
*block_stack
= orig_block_stack
;
5831 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5833 if (GET_CODE (insn
) == NOTE
)
5835 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5839 /* If there are more block notes than BLOCKs, something
5841 if (block_vector
== end_block_vector
)
5844 b
= *block_vector
++;
5845 NOTE_BLOCK (insn
) = b
;
5848 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5850 /* If there are more NOTE_INSN_BLOCK_ENDs than
5851 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */
5852 if (block_stack
== orig_block_stack
)
5855 NOTE_BLOCK (insn
) = *--block_stack
;
5858 else if (GET_CODE (insn
) == CALL_INSN
5859 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
5861 rtx cp
= PATTERN (insn
);
5863 block_vector
= identify_blocks_1 (XEXP (cp
, 0), block_vector
,
5864 end_block_vector
, block_stack
);
5866 block_vector
= identify_blocks_1 (XEXP (cp
, 1), block_vector
,
5867 end_block_vector
, block_stack
);
5869 block_vector
= identify_blocks_1 (XEXP (cp
, 2), block_vector
,
5870 end_block_vector
, block_stack
);
5874 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs,
5875 something is badly wrong. */
5876 if (block_stack
!= orig_block_stack
)
5879 return block_vector
;
5882 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
5883 and create duplicate blocks. */
5884 /* ??? Need an option to either create block fragments or to create
5885 abstract origin duplicates of a source block. It really depends
5886 on what optimization has been performed. */
5891 tree block
= DECL_INITIAL (current_function_decl
);
5892 varray_type block_stack
;
5894 if (block
== NULL_TREE
)
5897 VARRAY_TREE_INIT (block_stack
, 10, "block_stack");
5899 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
5900 reorder_blocks_0 (block
);
5902 /* Prune the old trees away, so that they don't get in the way. */
5903 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
5904 BLOCK_CHAIN (block
) = NULL_TREE
;
5906 /* Recreate the block tree from the note nesting. */
5907 reorder_blocks_1 (get_insns (), block
, &block_stack
);
5908 BLOCK_SUBBLOCKS (block
) = blocks_nreverse (BLOCK_SUBBLOCKS (block
));
5910 /* Remove deleted blocks from the block fragment chains. */
5911 reorder_fix_fragments (block
);
5914 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
5917 reorder_blocks_0 (block
)
5922 TREE_ASM_WRITTEN (block
) = 0;
5923 reorder_blocks_0 (BLOCK_SUBBLOCKS (block
));
5924 block
= BLOCK_CHAIN (block
);
5929 reorder_blocks_1 (insns
, current_block
, p_block_stack
)
5932 varray_type
*p_block_stack
;
5936 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
5938 if (GET_CODE (insn
) == NOTE
)
5940 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_BEG
)
5942 tree block
= NOTE_BLOCK (insn
);
5944 /* If we have seen this block before, that means it now
5945 spans multiple address regions. Create a new fragment. */
5946 if (TREE_ASM_WRITTEN (block
))
5948 tree new_block
= copy_node (block
);
5951 origin
= (BLOCK_FRAGMENT_ORIGIN (block
)
5952 ? BLOCK_FRAGMENT_ORIGIN (block
)
5954 BLOCK_FRAGMENT_ORIGIN (new_block
) = origin
;
5955 BLOCK_FRAGMENT_CHAIN (new_block
)
5956 = BLOCK_FRAGMENT_CHAIN (origin
);
5957 BLOCK_FRAGMENT_CHAIN (origin
) = new_block
;
5959 NOTE_BLOCK (insn
) = new_block
;
5963 BLOCK_SUBBLOCKS (block
) = 0;
5964 TREE_ASM_WRITTEN (block
) = 1;
5965 BLOCK_SUPERCONTEXT (block
) = current_block
;
5966 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
5967 BLOCK_SUBBLOCKS (current_block
) = block
;
5968 current_block
= block
;
5969 VARRAY_PUSH_TREE (*p_block_stack
, block
);
5971 else if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_BLOCK_END
)
5973 NOTE_BLOCK (insn
) = VARRAY_TOP_TREE (*p_block_stack
);
5974 VARRAY_POP (*p_block_stack
);
5975 BLOCK_SUBBLOCKS (current_block
)
5976 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block
));
5977 current_block
= BLOCK_SUPERCONTEXT (current_block
);
5980 else if (GET_CODE (insn
) == CALL_INSN
5981 && GET_CODE (PATTERN (insn
)) == CALL_PLACEHOLDER
)
5983 rtx cp
= PATTERN (insn
);
5984 reorder_blocks_1 (XEXP (cp
, 0), current_block
, p_block_stack
);
5986 reorder_blocks_1 (XEXP (cp
, 1), current_block
, p_block_stack
);
5988 reorder_blocks_1 (XEXP (cp
, 2), current_block
, p_block_stack
);
5993 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer
5994 appears in the block tree, select one of the fragments to become
5995 the new origin block. */
5998 reorder_fix_fragments (block
)
6003 tree dup_origin
= BLOCK_FRAGMENT_ORIGIN (block
);
6004 tree new_origin
= NULL_TREE
;
6008 if (! TREE_ASM_WRITTEN (dup_origin
))
6010 new_origin
= BLOCK_FRAGMENT_CHAIN (dup_origin
);
6012 /* Find the first of the remaining fragments. There must
6013 be at least one -- the current block. */
6014 while (! TREE_ASM_WRITTEN (new_origin
))
6015 new_origin
= BLOCK_FRAGMENT_CHAIN (new_origin
);
6016 BLOCK_FRAGMENT_ORIGIN (new_origin
) = NULL_TREE
;
6019 else if (! dup_origin
)
6022 /* Re-root the rest of the fragments to the new origin. In the
6023 case that DUP_ORIGIN was null, that means BLOCK was the origin
6024 of a chain of fragments and we want to remove those fragments
6025 that didn't make it to the output. */
6028 tree
*pp
= &BLOCK_FRAGMENT_CHAIN (new_origin
);
6033 if (TREE_ASM_WRITTEN (chain
))
6035 BLOCK_FRAGMENT_ORIGIN (chain
) = new_origin
;
6037 pp
= &BLOCK_FRAGMENT_CHAIN (chain
);
6039 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
6044 reorder_fix_fragments (BLOCK_SUBBLOCKS (block
));
6045 block
= BLOCK_CHAIN (block
);
6049 /* Reverse the order of elements in the chain T of blocks,
6050 and return the new head of the chain (old last element). */
6056 tree prev
= 0, decl
, next
;
6057 for (decl
= t
; decl
; decl
= next
)
6059 next
= BLOCK_CHAIN (decl
);
6060 BLOCK_CHAIN (decl
) = prev
;
6066 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
6067 non-NULL, list them all into VECTOR, in a depth-first preorder
6068 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
6072 all_blocks (block
, vector
)
6080 TREE_ASM_WRITTEN (block
) = 0;
6082 /* Record this block. */
6084 vector
[n_blocks
] = block
;
6088 /* Record the subblocks, and their subblocks... */
6089 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
6090 vector
? vector
+ n_blocks
: 0);
6091 block
= BLOCK_CHAIN (block
);
6097 /* Return a vector containing all the blocks rooted at BLOCK. The
6098 number of elements in the vector is stored in N_BLOCKS_P. The
6099 vector is dynamically allocated; it is the caller's responsibility
6100 to call `free' on the pointer returned. */
6103 get_block_vector (block
, n_blocks_p
)
6109 *n_blocks_p
= all_blocks (block
, NULL
);
6110 block_vector
= (tree
*) xmalloc (*n_blocks_p
* sizeof (tree
));
6111 all_blocks (block
, block_vector
);
6113 return block_vector
;
6116 static int next_block_index
= 2;
6118 /* Set BLOCK_NUMBER for all the blocks in FN. */
6128 /* For SDB and XCOFF debugging output, we start numbering the blocks
6129 from 1 within each function, rather than keeping a running
6131 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
6132 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
6133 next_block_index
= 1;
6136 block_vector
= get_block_vector (DECL_INITIAL (fn
), &n_blocks
);
6138 /* The top-level BLOCK isn't numbered at all. */
6139 for (i
= 1; i
< n_blocks
; ++i
)
6140 /* We number the blocks from two. */
6141 BLOCK_NUMBER (block_vector
[i
]) = next_block_index
++;
6143 free (block_vector
);
6148 /* If VAR is present in a subblock of BLOCK, return the subblock. */
6151 debug_find_var_in_block_tree (var
, block
)
6157 for (t
= BLOCK_VARS (block
); t
; t
= TREE_CHAIN (t
))
6161 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= TREE_CHAIN (t
))
6163 tree ret
= debug_find_var_in_block_tree (var
, t
);
6171 /* Allocate a function structure and reset its contents to the defaults. */
6174 prepare_function_start ()
6176 cfun
= (struct function
*) ggc_alloc_cleared (sizeof (struct function
));
6178 init_stmt_for_function ();
6179 init_eh_for_function ();
6181 cse_not_expected
= ! optimize
;
6183 /* Caller save not needed yet. */
6184 caller_save_needed
= 0;
6186 /* No stack slots have been made yet. */
6187 stack_slot_list
= 0;
6189 current_function_has_nonlocal_label
= 0;
6190 current_function_has_nonlocal_goto
= 0;
6192 /* There is no stack slot for handling nonlocal gotos. */
6193 nonlocal_goto_handler_slots
= 0;
6194 nonlocal_goto_stack_level
= 0;
6196 /* No labels have been declared for nonlocal use. */
6197 nonlocal_labels
= 0;
6198 nonlocal_goto_handler_labels
= 0;
6200 /* No function calls so far in this function. */
6201 function_call_count
= 0;
6203 /* No parm regs have been allocated.
6204 (This is important for output_inline_function.) */
6205 max_parm_reg
= LAST_VIRTUAL_REGISTER
+ 1;
6207 /* Initialize the RTL mechanism. */
6210 /* Initialize the queue of pending postincrement and postdecrements,
6211 and some other info in expr.c. */
6214 /* We haven't done register allocation yet. */
6217 init_varasm_status (cfun
);
6219 /* Clear out data used for inlining. */
6220 cfun
->inlinable
= 0;
6221 cfun
->original_decl_initial
= 0;
6222 cfun
->original_arg_vector
= 0;
6224 cfun
->stack_alignment_needed
= STACK_BOUNDARY
;
6225 cfun
->preferred_stack_boundary
= STACK_BOUNDARY
;
6227 /* Set if a call to setjmp is seen. */
6228 current_function_calls_setjmp
= 0;
6230 /* Set if a call to longjmp is seen. */
6231 current_function_calls_longjmp
= 0;
6233 current_function_calls_alloca
= 0;
6234 current_function_contains_functions
= 0;
6235 current_function_is_leaf
= 0;
6236 current_function_nothrow
= 0;
6237 current_function_sp_is_unchanging
= 0;
6238 current_function_uses_only_leaf_regs
= 0;
6239 current_function_has_computed_jump
= 0;
6240 current_function_is_thunk
= 0;
6242 current_function_returns_pcc_struct
= 0;
6243 current_function_returns_struct
= 0;
6244 current_function_epilogue_delay_list
= 0;
6245 current_function_uses_const_pool
= 0;
6246 current_function_uses_pic_offset_table
= 0;
6247 current_function_cannot_inline
= 0;
6249 /* We have not yet needed to make a label to jump to for tail-recursion. */
6250 tail_recursion_label
= 0;
6252 /* We haven't had a need to make a save area for ap yet. */
6253 arg_pointer_save_area
= 0;
6255 /* No stack slots allocated yet. */
6258 /* No SAVE_EXPRs in this function yet. */
6261 /* No RTL_EXPRs in this function yet. */
6264 /* Set up to allocate temporaries. */
6267 /* Indicate that we need to distinguish between the return value of the
6268 present function and the return value of a function being called. */
6269 rtx_equal_function_value_matters
= 1;
6271 /* Indicate that we have not instantiated virtual registers yet. */
6272 virtuals_instantiated
= 0;
6274 /* Indicate that we want CONCATs now. */
6275 generating_concat_p
= 1;
6277 /* Indicate we have no need of a frame pointer yet. */
6278 frame_pointer_needed
= 0;
6280 /* By default assume not stdarg. */
6281 current_function_stdarg
= 0;
6283 /* We haven't made any trampolines for this function yet. */
6284 trampoline_list
= 0;
6286 init_pending_stack_adjust ();
6287 inhibit_defer_pop
= 0;
6289 current_function_outgoing_args_size
= 0;
6291 current_function_funcdef_no
= funcdef_no
++;
6293 cfun
->arc_profile
= profile_arc_flag
|| flag_test_coverage
;
6295 cfun
->arc_profile
= profile_arc_flag
|| flag_test_coverage
;
6297 cfun
->function_frequency
= FUNCTION_FREQUENCY_NORMAL
;
6299 cfun
->max_jumptable_ents
= 0;
6301 (*lang_hooks
.function
.init
) (cfun
);
6302 if (init_machine_status
)
6303 cfun
->machine
= (*init_machine_status
) ();
6306 /* Initialize the rtl expansion mechanism so that we can do simple things
6307 like generate sequences. This is used to provide a context during global
6308 initialization of some passes. */
6310 init_dummy_function_start ()
6312 prepare_function_start ();
6315 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
6316 and initialize static variables for generating RTL for the statements
6320 init_function_start (subr
, filename
, line
)
6322 const char *filename
;
6325 prepare_function_start ();
6327 current_function_name
= (*lang_hooks
.decl_printable_name
) (subr
, 2);
6330 /* Nonzero if this is a nested function that uses a static chain. */
6332 current_function_needs_context
6333 = (decl_function_context (current_function_decl
) != 0
6334 && ! DECL_NO_STATIC_CHAIN (current_function_decl
));
6336 /* Within function body, compute a type's size as soon it is laid out. */
6337 immediate_size_expand
++;
6339 /* Prevent ever trying to delete the first instruction of a function.
6340 Also tell final how to output a linenum before the function prologue.
6341 Note linenums could be missing, e.g. when compiling a Java .class file. */
6343 emit_line_note (filename
, line
);
6345 /* Make sure first insn is a note even if we don't want linenums.
6346 This makes sure the first insn will never be deleted.
6347 Also, final expects a note to appear there. */
6348 emit_note (NULL
, NOTE_INSN_DELETED
);
6350 /* Set flags used by final.c. */
6351 if (aggregate_value_p (DECL_RESULT (subr
)))
6353 #ifdef PCC_STATIC_STRUCT_RETURN
6354 current_function_returns_pcc_struct
= 1;
6356 current_function_returns_struct
= 1;
6359 /* Warn if this value is an aggregate type,
6360 regardless of which calling convention we are using for it. */
6361 if (warn_aggregate_return
6362 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
6363 warning ("function returns an aggregate");
6365 current_function_returns_pointer
6366 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr
)));
6369 /* Make sure all values used by the optimization passes have sane
6372 init_function_for_compilation ()
6376 /* No prologue/epilogue insns yet. */
6377 VARRAY_GROW (prologue
, 0);
6378 VARRAY_GROW (epilogue
, 0);
6379 VARRAY_GROW (sibcall_epilogue
, 0);
6382 /* Expand a call to __main at the beginning of a possible main function. */
6384 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main)
6385 #undef HAS_INIT_SECTION
6386 #define HAS_INIT_SECTION
6390 expand_main_function ()
6392 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
6393 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN
)
6395 int align
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
6399 /* Forcibly align the stack. */
6400 #ifdef STACK_GROWS_DOWNWARD
6401 tmp
= expand_simple_binop (Pmode
, AND
, stack_pointer_rtx
, GEN_INT(-align
),
6402 stack_pointer_rtx
, 1, OPTAB_WIDEN
);
6404 tmp
= expand_simple_binop (Pmode
, PLUS
, stack_pointer_rtx
,
6405 GEN_INT (align
- 1), NULL_RTX
, 1, OPTAB_WIDEN
);
6406 tmp
= expand_simple_binop (Pmode
, AND
, tmp
, GEN_INT (-align
),
6407 stack_pointer_rtx
, 1, OPTAB_WIDEN
);
6409 if (tmp
!= stack_pointer_rtx
)
6410 emit_move_insn (stack_pointer_rtx
, tmp
);
6412 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */
6413 tmp
= force_reg (Pmode
, const0_rtx
);
6414 allocate_dynamic_stack_space (tmp
, NULL_RTX
, BIGGEST_ALIGNMENT
);
6418 for (tmp
= get_last_insn (); tmp
; tmp
= PREV_INSN (tmp
))
6419 if (NOTE_P (tmp
) && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_FUNCTION_BEG
)
6422 emit_insn_before (seq
, tmp
);
6428 #ifndef HAS_INIT_SECTION
6429 emit_library_call (gen_rtx_SYMBOL_REF (Pmode
, NAME__MAIN
), LCT_NORMAL
,
6434 /* The PENDING_SIZES represent the sizes of variable-sized types.
6435 Create RTL for the various sizes now (using temporary variables),
6436 so that we can refer to the sizes from the RTL we are generating
6437 for the current function. The PENDING_SIZES are a TREE_LIST. The
6438 TREE_VALUE of each node is a SAVE_EXPR. */
6441 expand_pending_sizes (pending_sizes
)
6446 /* Evaluate now the sizes of any types declared among the arguments. */
6447 for (tem
= pending_sizes
; tem
; tem
= TREE_CHAIN (tem
))
6449 expand_expr (TREE_VALUE (tem
), const0_rtx
, VOIDmode
, 0);
6450 /* Flush the queue in case this parameter declaration has
6456 /* Start the RTL for a new function, and set variables used for
6458 SUBR is the FUNCTION_DECL node.
6459 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
6460 the function's parameters, which must be run at any return statement. */
6463 expand_function_start (subr
, parms_have_cleanups
)
6465 int parms_have_cleanups
;
6468 rtx last_ptr
= NULL_RTX
;
6470 /* Make sure volatile mem refs aren't considered
6471 valid operands of arithmetic insns. */
6472 init_recog_no_volatile ();
6474 current_function_instrument_entry_exit
6475 = (flag_instrument_function_entry_exit
6476 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
6478 current_function_profile
6480 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
6482 current_function_limit_stack
6483 = (stack_limit_rtx
!= NULL_RTX
&& ! DECL_NO_LIMIT_STACK (subr
));
6485 /* If function gets a static chain arg, store it in the stack frame.
6486 Do this first, so it gets the first stack slot offset. */
6487 if (current_function_needs_context
)
6489 last_ptr
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
6491 /* Delay copying static chain if it is not a register to avoid
6492 conflicts with regs used for parameters. */
6493 if (! SMALL_REGISTER_CLASSES
6494 || GET_CODE (static_chain_incoming_rtx
) == REG
)
6495 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
6498 /* If the parameters of this function need cleaning up, get a label
6499 for the beginning of the code which executes those cleanups. This must
6500 be done before doing anything with return_label. */
6501 if (parms_have_cleanups
)
6502 cleanup_label
= gen_label_rtx ();
6506 /* Make the label for return statements to jump to. Do not special
6507 case machines with special return instructions -- they will be
6508 handled later during jump, ifcvt, or epilogue creation. */
6509 return_label
= gen_label_rtx ();
6511 /* Initialize rtx used to return the value. */
6512 /* Do this before assign_parms so that we copy the struct value address
6513 before any library calls that assign parms might generate. */
6515 /* Decide whether to return the value in memory or in a register. */
6516 if (aggregate_value_p (DECL_RESULT (subr
)))
6518 /* Returning something that won't go in a register. */
6519 rtx value_address
= 0;
6521 #ifdef PCC_STATIC_STRUCT_RETURN
6522 if (current_function_returns_pcc_struct
)
6524 int size
= int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr
)));
6525 value_address
= assemble_static_space (size
);
6530 /* Expect to be passed the address of a place to store the value.
6531 If it is passed as an argument, assign_parms will take care of
6533 if (struct_value_incoming_rtx
)
6535 value_address
= gen_reg_rtx (Pmode
);
6536 emit_move_insn (value_address
, struct_value_incoming_rtx
);
6541 rtx x
= gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr
)), value_address
);
6542 set_mem_attributes (x
, DECL_RESULT (subr
), 1);
6543 SET_DECL_RTL (DECL_RESULT (subr
), x
);
6546 else if (DECL_MODE (DECL_RESULT (subr
)) == VOIDmode
)
6547 /* If return mode is void, this decl rtl should not be used. */
6548 SET_DECL_RTL (DECL_RESULT (subr
), NULL_RTX
);
6551 /* Compute the return values into a pseudo reg, which we will copy
6552 into the true return register after the cleanups are done. */
6554 /* In order to figure out what mode to use for the pseudo, we
6555 figure out what the mode of the eventual return register will
6556 actually be, and use that. */
6558 = hard_function_value (TREE_TYPE (DECL_RESULT (subr
)),
6561 /* Structures that are returned in registers are not aggregate_value_p,
6562 so we may see a PARALLEL or a REG. */
6563 if (REG_P (hard_reg
))
6564 SET_DECL_RTL (DECL_RESULT (subr
), gen_reg_rtx (GET_MODE (hard_reg
)));
6565 else if (GET_CODE (hard_reg
) == PARALLEL
)
6566 SET_DECL_RTL (DECL_RESULT (subr
), gen_group_rtx (hard_reg
));
6570 /* Set DECL_REGISTER flag so that expand_function_end will copy the
6571 result to the real return register(s). */
6572 DECL_REGISTER (DECL_RESULT (subr
)) = 1;
6575 /* Initialize rtx for parameters and local variables.
6576 In some cases this requires emitting insns. */
6578 assign_parms (subr
);
6580 /* Copy the static chain now if it wasn't a register. The delay is to
6581 avoid conflicts with the parameter passing registers. */
6583 if (SMALL_REGISTER_CLASSES
&& current_function_needs_context
)
6584 if (GET_CODE (static_chain_incoming_rtx
) != REG
)
6585 emit_move_insn (last_ptr
, static_chain_incoming_rtx
);
6587 /* The following was moved from init_function_start.
6588 The move is supposed to make sdb output more accurate. */
6589 /* Indicate the beginning of the function body,
6590 as opposed to parm setup. */
6591 emit_note (NULL
, NOTE_INSN_FUNCTION_BEG
);
6593 if (GET_CODE (get_last_insn ()) != NOTE
)
6594 emit_note (NULL
, NOTE_INSN_DELETED
);
6595 parm_birth_insn
= get_last_insn ();
6597 context_display
= 0;
6598 if (current_function_needs_context
)
6600 /* Fetch static chain values for containing functions. */
6601 tem
= decl_function_context (current_function_decl
);
6602 /* Copy the static chain pointer into a pseudo. If we have
6603 small register classes, copy the value from memory if
6604 static_chain_incoming_rtx is a REG. */
6607 /* If the static chain originally came in a register, put it back
6608 there, then move it out in the next insn. The reason for
6609 this peculiar code is to satisfy function integration. */
6610 if (SMALL_REGISTER_CLASSES
6611 && GET_CODE (static_chain_incoming_rtx
) == REG
)
6612 emit_move_insn (static_chain_incoming_rtx
, last_ptr
);
6613 last_ptr
= copy_to_reg (static_chain_incoming_rtx
);
6618 tree rtlexp
= make_node (RTL_EXPR
);
6620 RTL_EXPR_RTL (rtlexp
) = last_ptr
;
6621 context_display
= tree_cons (tem
, rtlexp
, context_display
);
6622 tem
= decl_function_context (tem
);
6625 /* Chain thru stack frames, assuming pointer to next lexical frame
6626 is found at the place we always store it. */
6627 #ifdef FRAME_GROWS_DOWNWARD
6628 last_ptr
= plus_constant (last_ptr
,
6629 -(HOST_WIDE_INT
) GET_MODE_SIZE (Pmode
));
6631 last_ptr
= gen_rtx_MEM (Pmode
, memory_address (Pmode
, last_ptr
));
6632 set_mem_alias_set (last_ptr
, get_frame_alias_set ());
6633 last_ptr
= copy_to_reg (last_ptr
);
6635 /* If we are not optimizing, ensure that we know that this
6636 piece of context is live over the entire function. */
6638 save_expr_regs
= gen_rtx_EXPR_LIST (VOIDmode
, last_ptr
,
6643 if (current_function_instrument_entry_exit
)
6645 rtx fun
= DECL_RTL (current_function_decl
);
6646 if (GET_CODE (fun
) == MEM
)
6647 fun
= XEXP (fun
, 0);
6650 emit_library_call (profile_function_entry_libfunc
, LCT_NORMAL
, VOIDmode
,
6652 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS
,
6654 hard_frame_pointer_rtx
),
6658 if (current_function_profile
)
6661 PROFILE_HOOK (current_function_funcdef_no
);
6665 /* After the display initializations is where the tail-recursion label
6666 should go, if we end up needing one. Ensure we have a NOTE here
6667 since some things (like trampolines) get placed before this. */
6668 tail_recursion_reentry
= emit_note (NULL
, NOTE_INSN_DELETED
);
6670 /* Evaluate now the sizes of any types declared among the arguments. */
6671 expand_pending_sizes (nreverse (get_pending_sizes ()));
6673 /* Make sure there is a line number after the function entry setup code. */
6674 force_next_line_note ();
6677 /* Undo the effects of init_dummy_function_start. */
6679 expand_dummy_function_end ()
6681 /* End any sequences that failed to be closed due to syntax errors. */
6682 while (in_sequence_p ())
6685 /* Outside function body, can't compute type's actual size
6686 until next function's body starts. */
6688 free_after_parsing (cfun
);
6689 free_after_compilation (cfun
);
6693 /* Call DOIT for each hard register used as a return value from
6694 the current function. */
6697 diddle_return_value (doit
, arg
)
6698 void (*doit
) PARAMS ((rtx
, void *));
6701 rtx outgoing
= current_function_return_rtx
;
6706 if (GET_CODE (outgoing
) == REG
)
6707 (*doit
) (outgoing
, arg
);
6708 else if (GET_CODE (outgoing
) == PARALLEL
)
6712 for (i
= 0; i
< XVECLEN (outgoing
, 0); i
++)
6714 rtx x
= XEXP (XVECEXP (outgoing
, 0, i
), 0);
6716 if (GET_CODE (x
) == REG
&& REGNO (x
) < FIRST_PSEUDO_REGISTER
)
6723 do_clobber_return_reg (reg
, arg
)
6725 void *arg ATTRIBUTE_UNUSED
;
6727 emit_insn (gen_rtx_CLOBBER (VOIDmode
, reg
));
6731 clobber_return_register ()
6733 diddle_return_value (do_clobber_return_reg
, NULL
);
6735 /* In case we do use pseudo to return value, clobber it too. */
6736 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
6738 tree decl_result
= DECL_RESULT (current_function_decl
);
6739 rtx decl_rtl
= DECL_RTL (decl_result
);
6740 if (REG_P (decl_rtl
) && REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
)
6742 do_clobber_return_reg (decl_rtl
, NULL
);
6748 do_use_return_reg (reg
, arg
)
6750 void *arg ATTRIBUTE_UNUSED
;
6752 emit_insn (gen_rtx_USE (VOIDmode
, reg
));
6756 use_return_register ()
6758 diddle_return_value (do_use_return_reg
, NULL
);
6761 static GTY(()) rtx initial_trampoline
;
6763 /* Generate RTL for the end of the current function.
6764 FILENAME and LINE are the current position in the source file.
6766 It is up to language-specific callers to do cleanups for parameters--
6767 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */
6770 expand_function_end (filename
, line
, end_bindings
)
6771 const char *filename
;
6778 finish_expr_for_function ();
6780 /* If arg_pointer_save_area was referenced only from a nested
6781 function, we will not have initialized it yet. Do that now. */
6782 if (arg_pointer_save_area
&& ! cfun
->arg_pointer_save_area_init
)
6783 get_arg_pointer_save_area (cfun
);
6785 #ifdef NON_SAVING_SETJMP
6786 /* Don't put any variables in registers if we call setjmp
6787 on a machine that fails to restore the registers. */
6788 if (NON_SAVING_SETJMP
&& current_function_calls_setjmp
)
6790 if (DECL_INITIAL (current_function_decl
) != error_mark_node
)
6791 setjmp_protect (DECL_INITIAL (current_function_decl
));
6793 setjmp_protect_args ();
6797 /* Initialize any trampolines required by this function. */
6798 for (link
= trampoline_list
; link
; link
= TREE_CHAIN (link
))
6800 tree function
= TREE_PURPOSE (link
);
6801 rtx context ATTRIBUTE_UNUSED
= lookup_static_chain (function
);
6802 rtx tramp
= RTL_EXPR_RTL (TREE_VALUE (link
));
6803 #ifdef TRAMPOLINE_TEMPLATE
6808 #ifdef TRAMPOLINE_TEMPLATE
6809 /* First make sure this compilation has a template for
6810 initializing trampolines. */
6811 if (initial_trampoline
== 0)
6814 = gen_rtx_MEM (BLKmode
, assemble_trampoline_template ());
6815 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
6819 /* Generate insns to initialize the trampoline. */
6821 tramp
= round_trampoline_addr (XEXP (tramp
, 0));
6822 #ifdef TRAMPOLINE_TEMPLATE
6823 blktramp
= replace_equiv_address (initial_trampoline
, tramp
);
6824 emit_block_move (blktramp
, initial_trampoline
,
6825 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
6827 INITIALIZE_TRAMPOLINE (tramp
, XEXP (DECL_RTL (function
), 0), context
);
6831 /* Put those insns at entry to the containing function (this one). */
6832 emit_insn_before (seq
, tail_recursion_reentry
);
6835 /* If we are doing stack checking and this function makes calls,
6836 do a stack probe at the start of the function to ensure we have enough
6837 space for another stack frame. */
6838 if (flag_stack_check
&& ! STACK_CHECK_BUILTIN
)
6842 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6843 if (GET_CODE (insn
) == CALL_INSN
)
6846 probe_stack_range (STACK_CHECK_PROTECT
,
6847 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
));
6850 emit_insn_before (seq
, tail_recursion_reentry
);
6855 /* Warn about unused parms if extra warnings were specified. */
6856 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this
6857 warning. WARN_UNUSED_PARAMETER is negative when set by
6859 if (warn_unused_parameter
> 0
6860 || (warn_unused_parameter
< 0 && extra_warnings
))
6864 for (decl
= DECL_ARGUMENTS (current_function_decl
);
6865 decl
; decl
= TREE_CHAIN (decl
))
6866 if (! TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
6867 && DECL_NAME (decl
) && ! DECL_ARTIFICIAL (decl
))
6868 warning_with_decl (decl
, "unused parameter `%s'");
6871 /* Delete handlers for nonlocal gotos if nothing uses them. */
6872 if (nonlocal_goto_handler_slots
!= 0
6873 && ! current_function_has_nonlocal_label
)
6876 /* End any sequences that failed to be closed due to syntax errors. */
6877 while (in_sequence_p ())
6880 /* Outside function body, can't compute type's actual size
6881 until next function's body starts. */
6882 immediate_size_expand
--;
6884 clear_pending_stack_adjust ();
6885 do_pending_stack_adjust ();
6887 /* Mark the end of the function body.
6888 If control reaches this insn, the function can drop through
6889 without returning a value. */
6890 emit_note (NULL
, NOTE_INSN_FUNCTION_END
);
6892 /* Must mark the last line number note in the function, so that the test
6893 coverage code can avoid counting the last line twice. This just tells
6894 the code to ignore the immediately following line note, since there
6895 already exists a copy of this note somewhere above. This line number
6896 note is still needed for debugging though, so we can't delete it. */
6897 if (flag_test_coverage
)
6898 emit_note (NULL
, NOTE_INSN_REPEATED_LINE_NUMBER
);
6900 /* Output a linenumber for the end of the function.
6901 SDB depends on this. */
6902 emit_line_note_force (filename
, line
);
6904 /* Before the return label (if any), clobber the return
6905 registers so that they are not propagated live to the rest of
6906 the function. This can only happen with functions that drop
6907 through; if there had been a return statement, there would
6908 have either been a return rtx, or a jump to the return label.
6910 We delay actual code generation after the current_function_value_rtx
6912 clobber_after
= get_last_insn ();
6914 /* Output the label for the actual return from the function,
6915 if one is expected. This happens either because a function epilogue
6916 is used instead of a return instruction, or because a return was done
6917 with a goto in order to run local cleanups, or because of pcc-style
6918 structure returning. */
6920 emit_label (return_label
);
6922 /* C++ uses this. */
6924 expand_end_bindings (0, 0, 0);
6926 if (current_function_instrument_entry_exit
)
6928 rtx fun
= DECL_RTL (current_function_decl
);
6929 if (GET_CODE (fun
) == MEM
)
6930 fun
= XEXP (fun
, 0);
6933 emit_library_call (profile_function_exit_libfunc
, LCT_NORMAL
, VOIDmode
,
6935 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS
,
6937 hard_frame_pointer_rtx
),
6941 /* Let except.c know where it should emit the call to unregister
6942 the function context for sjlj exceptions. */
6943 if (flag_exceptions
&& USING_SJLJ_EXCEPTIONS
)
6944 sjlj_emit_function_exit_after (get_last_insn ());
6946 /* If we had calls to alloca, and this machine needs
6947 an accurate stack pointer to exit the function,
6948 insert some code to save and restore the stack pointer. */
6949 #ifdef EXIT_IGNORE_STACK
6950 if (! EXIT_IGNORE_STACK
)
6952 if (current_function_calls_alloca
)
6956 emit_stack_save (SAVE_FUNCTION
, &tem
, parm_birth_insn
);
6957 emit_stack_restore (SAVE_FUNCTION
, tem
, NULL_RTX
);
6960 /* If scalar return value was computed in a pseudo-reg, or was a named
6961 return value that got dumped to the stack, copy that to the hard
6963 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
6965 tree decl_result
= DECL_RESULT (current_function_decl
);
6966 rtx decl_rtl
= DECL_RTL (decl_result
);
6968 if (REG_P (decl_rtl
)
6969 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
6970 : DECL_REGISTER (decl_result
))
6972 rtx real_decl_rtl
= current_function_return_rtx
;
6974 /* This should be set in assign_parms. */
6975 if (! REG_FUNCTION_VALUE_P (real_decl_rtl
))
6978 /* If this is a BLKmode structure being returned in registers,
6979 then use the mode computed in expand_return. Note that if
6980 decl_rtl is memory, then its mode may have been changed,
6981 but that current_function_return_rtx has not. */
6982 if (GET_MODE (real_decl_rtl
) == BLKmode
)
6983 PUT_MODE (real_decl_rtl
, GET_MODE (decl_rtl
));
6985 /* If a named return value dumped decl_return to memory, then
6986 we may need to re-do the PROMOTE_MODE signed/unsigned
6988 if (GET_MODE (real_decl_rtl
) != GET_MODE (decl_rtl
))
6990 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (decl_result
));
6992 #ifdef PROMOTE_FUNCTION_RETURN
6993 promote_mode (TREE_TYPE (decl_result
), GET_MODE (decl_rtl
),
6997 convert_move (real_decl_rtl
, decl_rtl
, unsignedp
);
6999 else if (GET_CODE (real_decl_rtl
) == PARALLEL
)
7001 /* If expand_function_start has created a PARALLEL for decl_rtl,
7002 move the result to the real return registers. Otherwise, do
7003 a group load from decl_rtl for a named return. */
7004 if (GET_CODE (decl_rtl
) == PARALLEL
)
7005 emit_group_move (real_decl_rtl
, decl_rtl
);
7007 emit_group_load (real_decl_rtl
, decl_rtl
,
7008 int_size_in_bytes (TREE_TYPE (decl_result
)));
7011 emit_move_insn (real_decl_rtl
, decl_rtl
);
7015 /* If returning a structure, arrange to return the address of the value
7016 in a place where debuggers expect to find it.
7018 If returning a structure PCC style,
7019 the caller also depends on this value.
7020 And current_function_returns_pcc_struct is not necessarily set. */
7021 if (current_function_returns_struct
7022 || current_function_returns_pcc_struct
)
7025 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl
)), 0);
7026 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
7027 #ifdef FUNCTION_OUTGOING_VALUE
7029 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type
),
7030 current_function_decl
);
7033 = FUNCTION_VALUE (build_pointer_type (type
), current_function_decl
);
7036 /* Mark this as a function return value so integrate will delete the
7037 assignment and USE below when inlining this function. */
7038 REG_FUNCTION_VALUE_P (outgoing
) = 1;
7040 #ifdef POINTERS_EXTEND_UNSIGNED
7041 /* The address may be ptr_mode and OUTGOING may be Pmode. */
7042 if (GET_MODE (outgoing
) != GET_MODE (value_address
))
7043 value_address
= convert_memory_address (GET_MODE (outgoing
),
7047 emit_move_insn (outgoing
, value_address
);
7049 /* Show return register used to hold result (in this case the address
7051 current_function_return_rtx
= outgoing
;
7054 /* If this is an implementation of throw, do what's necessary to
7055 communicate between __builtin_eh_return and the epilogue. */
7056 expand_eh_return ();
7058 /* Emit the actual code to clobber return register. */
7063 clobber_return_register ();
7067 after
= emit_insn_after (seq
, clobber_after
);
7069 if (clobber_after
!= after
)
7070 cfun
->x_clobber_return_insn
= after
;
7073 /* ??? This should no longer be necessary since stupid is no longer with
7074 us, but there are some parts of the compiler (eg reload_combine, and
7075 sh mach_dep_reorg) that still try and compute their own lifetime info
7076 instead of using the general framework. */
7077 use_return_register ();
7079 /* Fix up any gotos that jumped out to the outermost
7080 binding level of the function.
7081 Must follow emitting RETURN_LABEL. */
7083 /* If you have any cleanups to do at this point,
7084 and they need to create temporary variables,
7085 then you will lose. */
7086 expand_fixups (get_insns ());
7090 get_arg_pointer_save_area (f
)
7093 rtx ret
= f
->x_arg_pointer_save_area
;
7097 ret
= assign_stack_local_1 (Pmode
, GET_MODE_SIZE (Pmode
), 0, f
);
7098 f
->x_arg_pointer_save_area
= ret
;
7101 if (f
== cfun
&& ! f
->arg_pointer_save_area_init
)
7105 /* Save the arg pointer at the beginning of the function. The
7106 generated stack slot may not be a valid memory address, so we
7107 have to check it and fix it if necessary. */
7109 emit_move_insn (validize_mem (ret
), virtual_incoming_args_rtx
);
7113 push_topmost_sequence ();
7114 emit_insn_after (seq
, get_insns ());
7115 pop_topmost_sequence ();
7121 /* Extend a vector that records the INSN_UIDs of INSNS
7122 (a list of one or more insns). */
7125 record_insns (insns
, vecp
)
7134 while (tmp
!= NULL_RTX
)
7137 tmp
= NEXT_INSN (tmp
);
7140 i
= VARRAY_SIZE (*vecp
);
7141 VARRAY_GROW (*vecp
, i
+ len
);
7143 while (tmp
!= NULL_RTX
)
7145 VARRAY_INT (*vecp
, i
) = INSN_UID (tmp
);
7147 tmp
= NEXT_INSN (tmp
);
7151 /* Determine how many INSN_UIDs in VEC are part of INSN. Because we can
7152 be running after reorg, SEQUENCE rtl is possible. */
7155 contains (insn
, vec
)
7161 if (GET_CODE (insn
) == INSN
7162 && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
7165 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
7166 for (j
= VARRAY_SIZE (vec
) - 1; j
>= 0; --j
)
7167 if (INSN_UID (XVECEXP (PATTERN (insn
), 0, i
)) == VARRAY_INT (vec
, j
))
7173 for (j
= VARRAY_SIZE (vec
) - 1; j
>= 0; --j
)
7174 if (INSN_UID (insn
) == VARRAY_INT (vec
, j
))
7181 prologue_epilogue_contains (insn
)
7184 if (contains (insn
, prologue
))
7186 if (contains (insn
, epilogue
))
7192 sibcall_epilogue_contains (insn
)
7195 if (sibcall_epilogue
)
7196 return contains (insn
, sibcall_epilogue
);
7201 /* Insert gen_return at the end of block BB. This also means updating
7202 block_for_insn appropriately. */
7205 emit_return_into_block (bb
, line_note
)
7211 p
= NEXT_INSN (bb
->end
);
7212 end
= emit_jump_insn_after (gen_return (), bb
->end
);
7214 emit_line_note_after (NOTE_SOURCE_FILE (line_note
),
7215 NOTE_LINE_NUMBER (line_note
), PREV_INSN (bb
->end
));
7217 #endif /* HAVE_return */
7219 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX)
7221 /* These functions convert the epilogue into a variant that does not modify the
7222 stack pointer. This is used in cases where a function returns an object
7223 whose size is not known until it is computed. The called function leaves the
7224 object on the stack, leaves the stack depressed, and returns a pointer to
7227 What we need to do is track all modifications and references to the stack
7228 pointer, deleting the modifications and changing the references to point to
7229 the location the stack pointer would have pointed to had the modifications
7232 These functions need to be portable so we need to make as few assumptions
7233 about the epilogue as we can. However, the epilogue basically contains
7234 three things: instructions to reset the stack pointer, instructions to
7235 reload registers, possibly including the frame pointer, and an
7236 instruction to return to the caller.
7238 If we can't be sure of what a relevant epilogue insn is doing, we abort.
7239 We also make no attempt to validate the insns we make since if they are
7240 invalid, we probably can't do anything valid. The intent is that these
7241 routines get "smarter" as more and more machines start to use them and
7242 they try operating on different epilogues.
7244 We use the following structure to track what the part of the epilogue that
7245 we've already processed has done. We keep two copies of the SP equivalence,
7246 one for use during the insn we are processing and one for use in the next
7247 insn. The difference is because one part of a PARALLEL may adjust SP
7248 and the other may use it. */
7252 rtx sp_equiv_reg
; /* REG that SP is set from, perhaps SP. */
7253 HOST_WIDE_INT sp_offset
; /* Offset from SP_EQUIV_REG of present SP. */
7254 rtx new_sp_equiv_reg
; /* REG to be used at end of insn. */
7255 HOST_WIDE_INT new_sp_offset
; /* Offset to be used at end of insn. */
7256 rtx equiv_reg_src
; /* If nonzero, the value that SP_EQUIV_REG
7257 should be set to once we no longer need
7261 static void handle_epilogue_set
PARAMS ((rtx
, struct epi_info
*));
7262 static void emit_equiv_load
PARAMS ((struct epi_info
*));
7264 /* Modify INSN, a list of one or more insns that is part of the epilogue, to
7265 no modifications to the stack pointer. Return the new list of insns. */
7268 keep_stack_depressed (insns
)
7272 struct epi_info info
;
7275 /* If the epilogue is just a single instruction, it ust be OK as is. */
7277 if (NEXT_INSN (insns
) == NULL_RTX
)
7280 /* Otherwise, start a sequence, initialize the information we have, and
7281 process all the insns we were given. */
7284 info
.sp_equiv_reg
= stack_pointer_rtx
;
7286 info
.equiv_reg_src
= 0;
7290 while (insn
!= NULL_RTX
)
7292 next
= NEXT_INSN (insn
);
7301 /* If this insn references the register that SP is equivalent to and
7302 we have a pending load to that register, we must force out the load
7303 first and then indicate we no longer know what SP's equivalent is. */
7304 if (info
.equiv_reg_src
!= 0
7305 && reg_referenced_p (info
.sp_equiv_reg
, PATTERN (insn
)))
7307 emit_equiv_load (&info
);
7308 info
.sp_equiv_reg
= 0;
7311 info
.new_sp_equiv_reg
= info
.sp_equiv_reg
;
7312 info
.new_sp_offset
= info
.sp_offset
;
7314 /* If this is a (RETURN) and the return address is on the stack,
7315 update the address and change to an indirect jump. */
7316 if (GET_CODE (PATTERN (insn
)) == RETURN
7317 || (GET_CODE (PATTERN (insn
)) == PARALLEL
7318 && GET_CODE (XVECEXP (PATTERN (insn
), 0, 0)) == RETURN
))
7320 rtx retaddr
= INCOMING_RETURN_ADDR_RTX
;
7322 HOST_WIDE_INT offset
= 0;
7323 rtx jump_insn
, jump_set
;
7325 /* If the return address is in a register, we can emit the insn
7326 unchanged. Otherwise, it must be a MEM and we see what the
7327 base register and offset are. In any case, we have to emit any
7328 pending load to the equivalent reg of SP, if any. */
7329 if (GET_CODE (retaddr
) == REG
)
7331 emit_equiv_load (&info
);
7336 else if (GET_CODE (retaddr
) == MEM
7337 && GET_CODE (XEXP (retaddr
, 0)) == REG
)
7338 base
= gen_rtx_REG (Pmode
, REGNO (XEXP (retaddr
, 0))), offset
= 0;
7339 else if (GET_CODE (retaddr
) == MEM
7340 && GET_CODE (XEXP (retaddr
, 0)) == PLUS
7341 && GET_CODE (XEXP (XEXP (retaddr
, 0), 0)) == REG
7342 && GET_CODE (XEXP (XEXP (retaddr
, 0), 1)) == CONST_INT
)
7344 base
= gen_rtx_REG (Pmode
, REGNO (XEXP (XEXP (retaddr
, 0), 0)));
7345 offset
= INTVAL (XEXP (XEXP (retaddr
, 0), 1));
7350 /* If the base of the location containing the return pointer
7351 is SP, we must update it with the replacement address. Otherwise,
7352 just build the necessary MEM. */
7353 retaddr
= plus_constant (base
, offset
);
7354 if (base
== stack_pointer_rtx
)
7355 retaddr
= simplify_replace_rtx (retaddr
, stack_pointer_rtx
,
7356 plus_constant (info
.sp_equiv_reg
,
7359 retaddr
= gen_rtx_MEM (Pmode
, retaddr
);
7361 /* If there is a pending load to the equivalent register for SP
7362 and we reference that register, we must load our address into
7363 a scratch register and then do that load. */
7364 if (info
.equiv_reg_src
7365 && reg_overlap_mentioned_p (info
.equiv_reg_src
, retaddr
))
7370 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
7371 if (HARD_REGNO_MODE_OK (regno
, Pmode
)
7372 && !fixed_regs
[regno
]
7373 && TEST_HARD_REG_BIT (regs_invalidated_by_call
, regno
)
7374 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR
->global_live_at_start
,
7376 && !refers_to_regno_p (regno
,
7377 regno
+ HARD_REGNO_NREGS (regno
,
7379 info
.equiv_reg_src
, NULL
))
7382 if (regno
== FIRST_PSEUDO_REGISTER
)
7385 reg
= gen_rtx_REG (Pmode
, regno
);
7386 emit_move_insn (reg
, retaddr
);
7390 emit_equiv_load (&info
);
7391 jump_insn
= emit_jump_insn (gen_indirect_jump (retaddr
));
7393 /* Show the SET in the above insn is a RETURN. */
7394 jump_set
= single_set (jump_insn
);
7398 SET_IS_RETURN_P (jump_set
) = 1;
7401 /* If SP is not mentioned in the pattern and its equivalent register, if
7402 any, is not modified, just emit it. Otherwise, if neither is set,
7403 replace the reference to SP and emit the insn. If none of those are
7404 true, handle each SET individually. */
7405 else if (!reg_mentioned_p (stack_pointer_rtx
, PATTERN (insn
))
7406 && (info
.sp_equiv_reg
== stack_pointer_rtx
7407 || !reg_set_p (info
.sp_equiv_reg
, insn
)))
7409 else if (! reg_set_p (stack_pointer_rtx
, insn
)
7410 && (info
.sp_equiv_reg
== stack_pointer_rtx
7411 || !reg_set_p (info
.sp_equiv_reg
, insn
)))
7413 if (! validate_replace_rtx (stack_pointer_rtx
,
7414 plus_constant (info
.sp_equiv_reg
,
7421 else if (GET_CODE (PATTERN (insn
)) == SET
)
7422 handle_epilogue_set (PATTERN (insn
), &info
);
7423 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
)
7425 for (j
= 0; j
< XVECLEN (PATTERN (insn
), 0); j
++)
7426 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, j
)) == SET
)
7427 handle_epilogue_set (XVECEXP (PATTERN (insn
), 0, j
), &info
);
7432 info
.sp_equiv_reg
= info
.new_sp_equiv_reg
;
7433 info
.sp_offset
= info
.new_sp_offset
;
7438 insns
= get_insns ();
7443 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info
7444 structure that contains information about what we've seen so far. We
7445 process this SET by either updating that data or by emitting one or
7449 handle_epilogue_set (set
, p
)
7453 /* First handle the case where we are setting SP. Record what it is being
7454 set from. If unknown, abort. */
7455 if (reg_set_p (stack_pointer_rtx
, set
))
7457 if (SET_DEST (set
) != stack_pointer_rtx
)
7460 if (GET_CODE (SET_SRC (set
)) == PLUS
7461 && GET_CODE (XEXP (SET_SRC (set
), 1)) == CONST_INT
)
7463 p
->new_sp_equiv_reg
= XEXP (SET_SRC (set
), 0);
7464 p
->new_sp_offset
= INTVAL (XEXP (SET_SRC (set
), 1));
7467 p
->new_sp_equiv_reg
= SET_SRC (set
), p
->new_sp_offset
= 0;
7469 /* If we are adjusting SP, we adjust from the old data. */
7470 if (p
->new_sp_equiv_reg
== stack_pointer_rtx
)
7472 p
->new_sp_equiv_reg
= p
->sp_equiv_reg
;
7473 p
->new_sp_offset
+= p
->sp_offset
;
7476 if (p
->new_sp_equiv_reg
== 0 || GET_CODE (p
->new_sp_equiv_reg
) != REG
)
7482 /* Next handle the case where we are setting SP's equivalent register.
7483 If we already have a value to set it to, abort. We could update, but
7484 there seems little point in handling that case. Note that we have
7485 to allow for the case where we are setting the register set in
7486 the previous part of a PARALLEL inside a single insn. But use the
7487 old offset for any updates within this insn. */
7488 else if (p
->new_sp_equiv_reg
!= 0 && reg_set_p (p
->new_sp_equiv_reg
, set
))
7490 if (!rtx_equal_p (p
->new_sp_equiv_reg
, SET_DEST (set
))
7491 || p
->equiv_reg_src
!= 0)
7495 = simplify_replace_rtx (SET_SRC (set
), stack_pointer_rtx
,
7496 plus_constant (p
->sp_equiv_reg
,
7500 /* Otherwise, replace any references to SP in the insn to its new value
7501 and emit the insn. */
7504 SET_SRC (set
) = simplify_replace_rtx (SET_SRC (set
), stack_pointer_rtx
,
7505 plus_constant (p
->sp_equiv_reg
,
7507 SET_DEST (set
) = simplify_replace_rtx (SET_DEST (set
), stack_pointer_rtx
,
7508 plus_constant (p
->sp_equiv_reg
,
7514 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */
7520 if (p
->equiv_reg_src
!= 0)
7521 emit_move_insn (p
->sp_equiv_reg
, p
->equiv_reg_src
);
7523 p
->equiv_reg_src
= 0;
7527 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
7528 this into place with notes indicating where the prologue ends and where
7529 the epilogue begins. Update the basic block information when possible. */
7532 thread_prologue_and_epilogue_insns (f
)
7533 rtx f ATTRIBUTE_UNUSED
;
7537 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue)
7540 #ifdef HAVE_prologue
7541 rtx prologue_end
= NULL_RTX
;
7543 #if defined (HAVE_epilogue) || defined(HAVE_return)
7544 rtx epilogue_end
= NULL_RTX
;
7547 #ifdef HAVE_prologue
7551 seq
= gen_prologue ();
7554 /* Retain a map of the prologue insns. */
7555 record_insns (seq
, &prologue
);
7556 prologue_end
= emit_note (NULL
, NOTE_INSN_PROLOGUE_END
);
7561 /* Can't deal with multiple successors of the entry block
7562 at the moment. Function should always have at least one
7564 if (!ENTRY_BLOCK_PTR
->succ
|| ENTRY_BLOCK_PTR
->succ
->succ_next
)
7567 insert_insn_on_edge (seq
, ENTRY_BLOCK_PTR
->succ
);
7572 /* If the exit block has no non-fake predecessors, we don't need
7574 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7575 if ((e
->flags
& EDGE_FAKE
) == 0)
7581 if (optimize
&& HAVE_return
)
7583 /* If we're allowed to generate a simple return instruction,
7584 then by definition we don't need a full epilogue. Examine
7585 the block that falls through to EXIT. If it does not
7586 contain any code, examine its predecessors and try to
7587 emit (conditional) return instructions. */
7593 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7594 if (e
->flags
& EDGE_FALLTHRU
)
7600 /* Verify that there are no active instructions in the last block. */
7602 while (label
&& GET_CODE (label
) != CODE_LABEL
)
7604 if (active_insn_p (label
))
7606 label
= PREV_INSN (label
);
7609 if (last
->head
== label
&& GET_CODE (label
) == CODE_LABEL
)
7611 rtx epilogue_line_note
= NULL_RTX
;
7613 /* Locate the line number associated with the closing brace,
7614 if we can find one. */
7615 for (seq
= get_last_insn ();
7616 seq
&& ! active_insn_p (seq
);
7617 seq
= PREV_INSN (seq
))
7618 if (GET_CODE (seq
) == NOTE
&& NOTE_LINE_NUMBER (seq
) > 0)
7620 epilogue_line_note
= seq
;
7624 for (e
= last
->pred
; e
; e
= e_next
)
7626 basic_block bb
= e
->src
;
7629 e_next
= e
->pred_next
;
7630 if (bb
== ENTRY_BLOCK_PTR
)
7634 if ((GET_CODE (jump
) != JUMP_INSN
) || JUMP_LABEL (jump
) != label
)
7637 /* If we have an unconditional jump, we can replace that
7638 with a simple return instruction. */
7639 if (simplejump_p (jump
))
7641 emit_return_into_block (bb
, epilogue_line_note
);
7645 /* If we have a conditional jump, we can try to replace
7646 that with a conditional return instruction. */
7647 else if (condjump_p (jump
))
7651 ret
= SET_SRC (PATTERN (jump
));
7652 if (GET_CODE (XEXP (ret
, 1)) == LABEL_REF
)
7653 loc
= &XEXP (ret
, 1);
7655 loc
= &XEXP (ret
, 2);
7656 ret
= gen_rtx_RETURN (VOIDmode
);
7658 if (! validate_change (jump
, loc
, ret
, 0))
7660 if (JUMP_LABEL (jump
))
7661 LABEL_NUSES (JUMP_LABEL (jump
))--;
7663 /* If this block has only one successor, it both jumps
7664 and falls through to the fallthru block, so we can't
7666 if (bb
->succ
->succ_next
== NULL
)
7672 /* Fix up the CFG for the successful change we just made. */
7673 redirect_edge_succ (e
, EXIT_BLOCK_PTR
);
7676 /* Emit a return insn for the exit fallthru block. Whether
7677 this is still reachable will be determined later. */
7679 emit_barrier_after (last
->end
);
7680 emit_return_into_block (last
, epilogue_line_note
);
7681 epilogue_end
= last
->end
;
7682 last
->succ
->flags
&= ~EDGE_FALLTHRU
;
7687 #ifdef HAVE_epilogue
7690 /* Find the edge that falls through to EXIT. Other edges may exist
7691 due to RETURN instructions, but those don't need epilogues.
7692 There really shouldn't be a mixture -- either all should have
7693 been converted or none, however... */
7695 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7696 if (e
->flags
& EDGE_FALLTHRU
)
7702 epilogue_end
= emit_note (NULL
, NOTE_INSN_EPILOGUE_BEG
);
7704 seq
= gen_epilogue ();
7706 #ifdef INCOMING_RETURN_ADDR_RTX
7707 /* If this function returns with the stack depressed and we can support
7708 it, massage the epilogue to actually do that. */
7709 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == FUNCTION_TYPE
7710 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl
)))
7711 seq
= keep_stack_depressed (seq
);
7714 emit_jump_insn (seq
);
7716 /* Retain a map of the epilogue insns. */
7717 record_insns (seq
, &epilogue
);
7722 insert_insn_on_edge (seq
, e
);
7729 commit_edge_insertions ();
7731 #ifdef HAVE_sibcall_epilogue
7732 /* Emit sibling epilogues before any sibling call sites. */
7733 for (e
= EXIT_BLOCK_PTR
->pred
; e
; e
= e
->pred_next
)
7735 basic_block bb
= e
->src
;
7740 if (GET_CODE (insn
) != CALL_INSN
7741 || ! SIBLING_CALL_P (insn
))
7745 emit_insn (gen_sibcall_epilogue ());
7749 /* Retain a map of the epilogue insns. Used in life analysis to
7750 avoid getting rid of sibcall epilogue insns. Do this before we
7751 actually emit the sequence. */
7752 record_insns (seq
, &sibcall_epilogue
);
7754 i
= PREV_INSN (insn
);
7755 newinsn
= emit_insn_before (seq
, insn
);
7759 #ifdef HAVE_prologue
7764 /* GDB handles `break f' by setting a breakpoint on the first
7765 line note after the prologue. Which means (1) that if
7766 there are line number notes before where we inserted the
7767 prologue we should move them, and (2) we should generate a
7768 note before the end of the first basic block, if there isn't
7771 ??? This behavior is completely broken when dealing with
7772 multiple entry functions. We simply place the note always
7773 into first basic block and let alternate entry points
7777 for (insn
= prologue_end
; insn
; insn
= prev
)
7779 prev
= PREV_INSN (insn
);
7780 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7782 /* Note that we cannot reorder the first insn in the
7783 chain, since rest_of_compilation relies on that
7784 remaining constant. */
7787 reorder_insns (insn
, insn
, prologue_end
);
7791 /* Find the last line number note in the first block. */
7792 for (insn
= ENTRY_BLOCK_PTR
->next_bb
->end
;
7793 insn
!= prologue_end
&& insn
;
7794 insn
= PREV_INSN (insn
))
7795 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7798 /* If we didn't find one, make a copy of the first line number
7802 for (insn
= next_active_insn (prologue_end
);
7804 insn
= PREV_INSN (insn
))
7805 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7807 emit_line_note_after (NOTE_SOURCE_FILE (insn
),
7808 NOTE_LINE_NUMBER (insn
),
7815 #ifdef HAVE_epilogue
7820 /* Similarly, move any line notes that appear after the epilogue.
7821 There is no need, however, to be quite so anal about the existence
7823 for (insn
= epilogue_end
; insn
; insn
= next
)
7825 next
= NEXT_INSN (insn
);
7826 if (GET_CODE (insn
) == NOTE
&& NOTE_LINE_NUMBER (insn
) > 0)
7827 reorder_insns (insn
, insn
, PREV_INSN (epilogue_end
));
7833 /* Reposition the prologue-end and epilogue-begin notes after instruction
7834 scheduling and delayed branch scheduling. */
7837 reposition_prologue_and_epilogue_notes (f
)
7838 rtx f ATTRIBUTE_UNUSED
;
7840 #if defined (HAVE_prologue) || defined (HAVE_epilogue)
7841 rtx insn
, last
, note
;
7844 if ((len
= VARRAY_SIZE (prologue
)) > 0)
7848 /* Scan from the beginning until we reach the last prologue insn.
7849 We apparently can't depend on basic_block_{head,end} after
7851 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
7853 if (GET_CODE (insn
) == NOTE
)
7855 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_PROLOGUE_END
)
7858 else if (contains (insn
, prologue
))
7870 /* Find the prologue-end note if we haven't already, and
7871 move it to just after the last prologue insn. */
7874 for (note
= last
; (note
= NEXT_INSN (note
));)
7875 if (GET_CODE (note
) == NOTE
7876 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_PROLOGUE_END
)
7880 next
= NEXT_INSN (note
);
7882 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
7883 if (GET_CODE (last
) == CODE_LABEL
)
7884 last
= NEXT_INSN (last
);
7885 reorder_insns (note
, note
, last
);
7889 if ((len
= VARRAY_SIZE (epilogue
)) > 0)
7893 /* Scan from the end until we reach the first epilogue insn.
7894 We apparently can't depend on basic_block_{head,end} after
7896 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
7898 if (GET_CODE (insn
) == NOTE
)
7900 if (NOTE_LINE_NUMBER (insn
) == NOTE_INSN_EPILOGUE_BEG
)
7903 else if (contains (insn
, epilogue
))
7913 /* Find the epilogue-begin note if we haven't already, and
7914 move it to just before the first epilogue insn. */
7917 for (note
= insn
; (note
= PREV_INSN (note
));)
7918 if (GET_CODE (note
) == NOTE
7919 && NOTE_LINE_NUMBER (note
) == NOTE_INSN_EPILOGUE_BEG
)
7923 if (PREV_INSN (last
) != note
)
7924 reorder_insns (note
, note
, PREV_INSN (last
));
7927 #endif /* HAVE_prologue or HAVE_epilogue */
7930 /* Called once, at initialization, to initialize function.c. */
7933 init_function_once ()
7935 VARRAY_INT_INIT (prologue
, 0, "prologue");
7936 VARRAY_INT_INIT (epilogue
, 0, "epilogue");
7937 VARRAY_INT_INIT (sibcall_epilogue
, 0, "sibcall_epilogue");
7940 #include "gt-function.h"