1 /* Expands front end tree to back end RTL for GCC.
2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011, 2012 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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. */
38 #include "coretypes.h"
40 #include "rtl-error.h"
49 #include "hard-reg-set.h"
50 #include "insn-config.h"
53 #include "basic-block.h"
57 #include "langhooks.h"
59 #include "common/common-target.h"
60 #include "cfglayout.h"
62 #include "tree-pass.h"
68 #include "bb-reorder.h"
70 /* So we can assign to cfun in this file. */
73 #ifndef STACK_ALIGNMENT_NEEDED
74 #define STACK_ALIGNMENT_NEEDED 1
77 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
79 /* Some systems use __main in a way incompatible with its use in gcc, in these
80 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
81 give the same symbol without quotes for an alternative entry point. You
82 must define both, or neither. */
84 #define NAME__MAIN "__main"
87 /* Round a value to the lowest integer less than it that is a multiple of
88 the required alignment. Avoid using division in case the value is
89 negative. Assume the alignment is a power of two. */
90 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
92 /* Similar, but round to the next highest integer that meets the
94 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
96 /* Nonzero if function being compiled doesn't contain any calls
97 (ignoring the prologue and epilogue). This is set prior to
98 local register allocation and is valid for the remaining
100 int current_function_is_leaf
;
102 /* Nonzero if function being compiled doesn't modify the stack pointer
103 (ignoring the prologue and epilogue). This is only valid after
104 pass_stack_ptr_mod has run. */
105 int current_function_sp_is_unchanging
;
107 /* Nonzero if the function being compiled is a leaf function which only
108 uses leaf registers. This is valid after reload (specifically after
109 sched2) and is useful only if the port defines LEAF_REGISTERS. */
110 int current_function_uses_only_leaf_regs
;
112 /* Nonzero once virtual register instantiation has been done.
113 assign_stack_local uses frame_pointer_rtx when this is nonzero.
114 calls.c:emit_library_call_value_1 uses it to set up
115 post-instantiation libcalls. */
116 int virtuals_instantiated
;
118 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
119 static GTY(()) int funcdef_no
;
121 /* These variables hold pointers to functions to create and destroy
122 target specific, per-function data structures. */
123 struct machine_function
* (*init_machine_status
) (void);
125 /* The currently compiled function. */
126 struct function
*cfun
= 0;
128 /* These hashes record the prologue and epilogue insns. */
129 static GTY((if_marked ("ggc_marked_p"), param_is (struct rtx_def
)))
130 htab_t prologue_insn_hash
;
131 static GTY((if_marked ("ggc_marked_p"), param_is (struct rtx_def
)))
132 htab_t epilogue_insn_hash
;
135 htab_t types_used_by_vars_hash
= NULL
;
136 VEC(tree
,gc
) *types_used_by_cur_var_decl
;
138 /* Forward declarations. */
140 static struct temp_slot
*find_temp_slot_from_address (rtx
);
141 static void pad_to_arg_alignment (struct args_size
*, int, struct args_size
*);
142 static void pad_below (struct args_size
*, enum machine_mode
, tree
);
143 static void reorder_blocks_1 (rtx
, tree
, VEC(tree
,heap
) **);
144 static int all_blocks (tree
, tree
*);
145 static tree
*get_block_vector (tree
, int *);
146 extern tree
debug_find_var_in_block_tree (tree
, tree
);
147 /* We always define `record_insns' even if it's not used so that we
148 can always export `prologue_epilogue_contains'. */
149 static void record_insns (rtx
, rtx
, htab_t
*) ATTRIBUTE_UNUSED
;
150 static bool contains (const_rtx
, htab_t
);
151 static void prepare_function_start (void);
152 static void do_clobber_return_reg (rtx
, void *);
153 static void do_use_return_reg (rtx
, void *);
154 static void set_insn_locators (rtx
, int) ATTRIBUTE_UNUSED
;
156 /* Stack of nested functions. */
157 /* Keep track of the cfun stack. */
159 typedef struct function
*function_p
;
161 DEF_VEC_P(function_p
);
162 DEF_VEC_ALLOC_P(function_p
,heap
);
163 static VEC(function_p
,heap
) *function_context_stack
;
165 /* Save the current context for compilation of a nested function.
166 This is called from language-specific code. */
169 push_function_context (void)
172 allocate_struct_function (NULL
, false);
174 VEC_safe_push (function_p
, heap
, function_context_stack
, cfun
);
178 /* Restore the last saved context, at the end of a nested function.
179 This function is called from language-specific code. */
182 pop_function_context (void)
184 struct function
*p
= VEC_pop (function_p
, function_context_stack
);
186 current_function_decl
= p
->decl
;
188 /* Reset variables that have known state during rtx generation. */
189 virtuals_instantiated
= 0;
190 generating_concat_p
= 1;
193 /* Clear out all parts of the state in F that can safely be discarded
194 after the function has been parsed, but not compiled, to let
195 garbage collection reclaim the memory. */
198 free_after_parsing (struct function
*f
)
203 /* Clear out all parts of the state in F that can safely be discarded
204 after the function has been compiled, to let garbage collection
205 reclaim the memory. */
208 free_after_compilation (struct function
*f
)
210 prologue_insn_hash
= NULL
;
211 epilogue_insn_hash
= NULL
;
213 free (crtl
->emit
.regno_pointer_align
);
215 memset (crtl
, 0, sizeof (struct rtl_data
));
220 regno_reg_rtx
= NULL
;
221 insn_locators_free ();
224 /* Return size needed for stack frame based on slots so far allocated.
225 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
226 the caller may have to do that. */
229 get_frame_size (void)
231 if (FRAME_GROWS_DOWNWARD
)
232 return -frame_offset
;
237 /* Issue an error message and return TRUE if frame OFFSET overflows in
238 the signed target pointer arithmetics for function FUNC. Otherwise
242 frame_offset_overflow (HOST_WIDE_INT offset
, tree func
)
244 unsigned HOST_WIDE_INT size
= FRAME_GROWS_DOWNWARD
? -offset
: offset
;
246 if (size
> ((unsigned HOST_WIDE_INT
) 1 << (GET_MODE_BITSIZE (Pmode
) - 1))
247 /* Leave room for the fixed part of the frame. */
248 - 64 * UNITS_PER_WORD
)
250 error_at (DECL_SOURCE_LOCATION (func
),
251 "total size of local objects too large");
258 /* Return stack slot alignment in bits for TYPE and MODE. */
261 get_stack_local_alignment (tree type
, enum machine_mode mode
)
263 unsigned int alignment
;
266 alignment
= BIGGEST_ALIGNMENT
;
268 alignment
= GET_MODE_ALIGNMENT (mode
);
270 /* Allow the frond-end to (possibly) increase the alignment of this
273 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
275 return STACK_SLOT_ALIGNMENT (type
, mode
, alignment
);
278 /* Determine whether it is possible to fit a stack slot of size SIZE and
279 alignment ALIGNMENT into an area in the stack frame that starts at
280 frame offset START and has a length of LENGTH. If so, store the frame
281 offset to be used for the stack slot in *POFFSET and return true;
282 return false otherwise. This function will extend the frame size when
283 given a start/length pair that lies at the end of the frame. */
286 try_fit_stack_local (HOST_WIDE_INT start
, HOST_WIDE_INT length
,
287 HOST_WIDE_INT size
, unsigned int alignment
,
288 HOST_WIDE_INT
*poffset
)
290 HOST_WIDE_INT this_frame_offset
;
291 int frame_off
, frame_alignment
, frame_phase
;
293 /* Calculate how many bytes the start of local variables is off from
295 frame_alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
296 frame_off
= STARTING_FRAME_OFFSET
% frame_alignment
;
297 frame_phase
= frame_off
? frame_alignment
- frame_off
: 0;
299 /* Round the frame offset to the specified alignment. */
301 /* We must be careful here, since FRAME_OFFSET might be negative and
302 division with a negative dividend isn't as well defined as we might
303 like. So we instead assume that ALIGNMENT is a power of two and
304 use logical operations which are unambiguous. */
305 if (FRAME_GROWS_DOWNWARD
)
307 = (FLOOR_ROUND (start
+ length
- size
- frame_phase
,
308 (unsigned HOST_WIDE_INT
) alignment
)
312 = (CEIL_ROUND (start
- frame_phase
,
313 (unsigned HOST_WIDE_INT
) alignment
)
316 /* See if it fits. If this space is at the edge of the frame,
317 consider extending the frame to make it fit. Our caller relies on
318 this when allocating a new slot. */
319 if (frame_offset
== start
&& this_frame_offset
< frame_offset
)
320 frame_offset
= this_frame_offset
;
321 else if (this_frame_offset
< start
)
323 else if (start
+ length
== frame_offset
324 && this_frame_offset
+ size
> start
+ length
)
325 frame_offset
= this_frame_offset
+ size
;
326 else if (this_frame_offset
+ size
> start
+ length
)
329 *poffset
= this_frame_offset
;
333 /* Create a new frame_space structure describing free space in the stack
334 frame beginning at START and ending at END, and chain it into the
335 function's frame_space_list. */
338 add_frame_space (HOST_WIDE_INT start
, HOST_WIDE_INT end
)
340 struct frame_space
*space
= ggc_alloc_frame_space ();
341 space
->next
= crtl
->frame_space_list
;
342 crtl
->frame_space_list
= space
;
343 space
->start
= start
;
344 space
->length
= end
- start
;
347 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
348 with machine mode MODE.
350 ALIGN controls the amount of alignment for the address of the slot:
351 0 means according to MODE,
352 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
353 -2 means use BITS_PER_UNIT,
354 positive specifies alignment boundary in bits.
356 KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce
357 alignment and ASLK_RECORD_PAD bit set if we should remember
358 extra space we allocated for alignment purposes. When we are
359 called from assign_stack_temp_for_type, it is not set so we don't
360 track the same stack slot in two independent lists.
362 We do not round to stack_boundary here. */
365 assign_stack_local_1 (enum machine_mode mode
, HOST_WIDE_INT size
,
369 int bigend_correction
= 0;
370 HOST_WIDE_INT slot_offset
= 0, old_frame_offset
;
371 unsigned int alignment
, alignment_in_bits
;
375 alignment
= get_stack_local_alignment (NULL
, mode
);
376 alignment
/= BITS_PER_UNIT
;
378 else if (align
== -1)
380 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
381 size
= CEIL_ROUND (size
, alignment
);
383 else if (align
== -2)
384 alignment
= 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
386 alignment
= align
/ BITS_PER_UNIT
;
388 alignment_in_bits
= alignment
* BITS_PER_UNIT
;
390 /* Ignore alignment if it exceeds MAX_SUPPORTED_STACK_ALIGNMENT. */
391 if (alignment_in_bits
> MAX_SUPPORTED_STACK_ALIGNMENT
)
393 alignment_in_bits
= MAX_SUPPORTED_STACK_ALIGNMENT
;
394 alignment
= alignment_in_bits
/ BITS_PER_UNIT
;
397 if (SUPPORTS_STACK_ALIGNMENT
)
399 if (crtl
->stack_alignment_estimated
< alignment_in_bits
)
401 if (!crtl
->stack_realign_processed
)
402 crtl
->stack_alignment_estimated
= alignment_in_bits
;
405 /* If stack is realigned and stack alignment value
406 hasn't been finalized, it is OK not to increase
407 stack_alignment_estimated. The bigger alignment
408 requirement is recorded in stack_alignment_needed
410 gcc_assert (!crtl
->stack_realign_finalized
);
411 if (!crtl
->stack_realign_needed
)
413 /* It is OK to reduce the alignment as long as the
414 requested size is 0 or the estimated stack
415 alignment >= mode alignment. */
416 gcc_assert ((kind
& ASLK_REDUCE_ALIGN
)
418 || (crtl
->stack_alignment_estimated
419 >= GET_MODE_ALIGNMENT (mode
)));
420 alignment_in_bits
= crtl
->stack_alignment_estimated
;
421 alignment
= alignment_in_bits
/ BITS_PER_UNIT
;
427 if (crtl
->stack_alignment_needed
< alignment_in_bits
)
428 crtl
->stack_alignment_needed
= alignment_in_bits
;
429 if (crtl
->max_used_stack_slot_alignment
< alignment_in_bits
)
430 crtl
->max_used_stack_slot_alignment
= alignment_in_bits
;
432 if (mode
!= BLKmode
|| size
!= 0)
434 if (kind
& ASLK_RECORD_PAD
)
436 struct frame_space
**psp
;
438 for (psp
= &crtl
->frame_space_list
; *psp
; psp
= &(*psp
)->next
)
440 struct frame_space
*space
= *psp
;
441 if (!try_fit_stack_local (space
->start
, space
->length
, size
,
442 alignment
, &slot_offset
))
445 if (slot_offset
> space
->start
)
446 add_frame_space (space
->start
, slot_offset
);
447 if (slot_offset
+ size
< space
->start
+ space
->length
)
448 add_frame_space (slot_offset
+ size
,
449 space
->start
+ space
->length
);
454 else if (!STACK_ALIGNMENT_NEEDED
)
456 slot_offset
= frame_offset
;
460 old_frame_offset
= frame_offset
;
462 if (FRAME_GROWS_DOWNWARD
)
464 frame_offset
-= size
;
465 try_fit_stack_local (frame_offset
, size
, size
, alignment
, &slot_offset
);
467 if (kind
& ASLK_RECORD_PAD
)
469 if (slot_offset
> frame_offset
)
470 add_frame_space (frame_offset
, slot_offset
);
471 if (slot_offset
+ size
< old_frame_offset
)
472 add_frame_space (slot_offset
+ size
, old_frame_offset
);
477 frame_offset
+= size
;
478 try_fit_stack_local (old_frame_offset
, size
, size
, alignment
, &slot_offset
);
480 if (kind
& ASLK_RECORD_PAD
)
482 if (slot_offset
> old_frame_offset
)
483 add_frame_space (old_frame_offset
, slot_offset
);
484 if (slot_offset
+ size
< frame_offset
)
485 add_frame_space (slot_offset
+ size
, frame_offset
);
490 /* On a big-endian machine, if we are allocating more space than we will use,
491 use the least significant bytes of those that are allocated. */
492 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
&& GET_MODE_SIZE (mode
) < size
)
493 bigend_correction
= size
- GET_MODE_SIZE (mode
);
495 /* If we have already instantiated virtual registers, return the actual
496 address relative to the frame pointer. */
497 if (virtuals_instantiated
)
498 addr
= plus_constant (Pmode
, frame_pointer_rtx
,
500 (slot_offset
+ bigend_correction
501 + STARTING_FRAME_OFFSET
, Pmode
));
503 addr
= plus_constant (Pmode
, virtual_stack_vars_rtx
,
505 (slot_offset
+ bigend_correction
,
508 x
= gen_rtx_MEM (mode
, addr
);
509 set_mem_align (x
, alignment_in_bits
);
510 MEM_NOTRAP_P (x
) = 1;
513 = gen_rtx_EXPR_LIST (VOIDmode
, x
, stack_slot_list
);
515 if (frame_offset_overflow (frame_offset
, current_function_decl
))
521 /* Wrap up assign_stack_local_1 with last parameter as false. */
524 assign_stack_local (enum machine_mode mode
, HOST_WIDE_INT size
, int align
)
526 return assign_stack_local_1 (mode
, size
, align
, ASLK_RECORD_PAD
);
529 /* In order to evaluate some expressions, such as function calls returning
530 structures in memory, we need to temporarily allocate stack locations.
531 We record each allocated temporary in the following structure.
533 Associated with each temporary slot is a nesting level. When we pop up
534 one level, all temporaries associated with the previous level are freed.
535 Normally, all temporaries are freed after the execution of the statement
536 in which they were created. However, if we are inside a ({...}) grouping,
537 the result may be in a temporary and hence must be preserved. If the
538 result could be in a temporary, we preserve it if we can determine which
539 one it is in. If we cannot determine which temporary may contain the
540 result, all temporaries are preserved. A temporary is preserved by
541 pretending it was allocated at the previous nesting level. */
543 struct GTY(()) temp_slot
{
544 /* Points to next temporary slot. */
545 struct temp_slot
*next
;
546 /* Points to previous temporary slot. */
547 struct temp_slot
*prev
;
548 /* The rtx to used to reference the slot. */
550 /* The size, in units, of the slot. */
552 /* The type of the object in the slot, or zero if it doesn't correspond
553 to a type. We use this to determine whether a slot can be reused.
554 It can be reused if objects of the type of the new slot will always
555 conflict with objects of the type of the old slot. */
557 /* The alignment (in bits) of the slot. */
559 /* Nonzero if this temporary is currently in use. */
561 /* Nesting level at which this slot is being used. */
563 /* The offset of the slot from the frame_pointer, including extra space
564 for alignment. This info is for combine_temp_slots. */
565 HOST_WIDE_INT base_offset
;
566 /* The size of the slot, including extra space for alignment. This
567 info is for combine_temp_slots. */
568 HOST_WIDE_INT full_size
;
571 /* A table of addresses that represent a stack slot. The table is a mapping
572 from address RTXen to a temp slot. */
573 static GTY((param_is(struct temp_slot_address_entry
))) htab_t temp_slot_address_table
;
575 /* Entry for the above hash table. */
576 struct GTY(()) temp_slot_address_entry
{
579 struct temp_slot
*temp_slot
;
582 /* Removes temporary slot TEMP from LIST. */
585 cut_slot_from_list (struct temp_slot
*temp
, struct temp_slot
**list
)
588 temp
->next
->prev
= temp
->prev
;
590 temp
->prev
->next
= temp
->next
;
594 temp
->prev
= temp
->next
= NULL
;
597 /* Inserts temporary slot TEMP to LIST. */
600 insert_slot_to_list (struct temp_slot
*temp
, struct temp_slot
**list
)
604 (*list
)->prev
= temp
;
609 /* Returns the list of used temp slots at LEVEL. */
611 static struct temp_slot
**
612 temp_slots_at_level (int level
)
614 if (level
>= (int) VEC_length (temp_slot_p
, used_temp_slots
))
615 VEC_safe_grow_cleared (temp_slot_p
, gc
, used_temp_slots
, level
+ 1);
617 return &(VEC_address (temp_slot_p
, used_temp_slots
)[level
]);
620 /* Returns the maximal temporary slot level. */
623 max_slot_level (void)
625 if (!used_temp_slots
)
628 return VEC_length (temp_slot_p
, used_temp_slots
) - 1;
631 /* Moves temporary slot TEMP to LEVEL. */
634 move_slot_to_level (struct temp_slot
*temp
, int level
)
636 cut_slot_from_list (temp
, temp_slots_at_level (temp
->level
));
637 insert_slot_to_list (temp
, temp_slots_at_level (level
));
641 /* Make temporary slot TEMP available. */
644 make_slot_available (struct temp_slot
*temp
)
646 cut_slot_from_list (temp
, temp_slots_at_level (temp
->level
));
647 insert_slot_to_list (temp
, &avail_temp_slots
);
652 /* Compute the hash value for an address -> temp slot mapping.
653 The value is cached on the mapping entry. */
655 temp_slot_address_compute_hash (struct temp_slot_address_entry
*t
)
657 int do_not_record
= 0;
658 return hash_rtx (t
->address
, GET_MODE (t
->address
),
659 &do_not_record
, NULL
, false);
662 /* Return the hash value for an address -> temp slot mapping. */
664 temp_slot_address_hash (const void *p
)
666 const struct temp_slot_address_entry
*t
;
667 t
= (const struct temp_slot_address_entry
*) p
;
671 /* Compare two address -> temp slot mapping entries. */
673 temp_slot_address_eq (const void *p1
, const void *p2
)
675 const struct temp_slot_address_entry
*t1
, *t2
;
676 t1
= (const struct temp_slot_address_entry
*) p1
;
677 t2
= (const struct temp_slot_address_entry
*) p2
;
678 return exp_equiv_p (t1
->address
, t2
->address
, 0, true);
681 /* Add ADDRESS as an alias of TEMP_SLOT to the addess -> temp slot mapping. */
683 insert_temp_slot_address (rtx address
, struct temp_slot
*temp_slot
)
686 struct temp_slot_address_entry
*t
= ggc_alloc_temp_slot_address_entry ();
687 t
->address
= address
;
688 t
->temp_slot
= temp_slot
;
689 t
->hash
= temp_slot_address_compute_hash (t
);
690 slot
= htab_find_slot_with_hash (temp_slot_address_table
, t
, t
->hash
, INSERT
);
694 /* Remove an address -> temp slot mapping entry if the temp slot is
695 not in use anymore. Callback for remove_unused_temp_slot_addresses. */
697 remove_unused_temp_slot_addresses_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
699 const struct temp_slot_address_entry
*t
;
700 t
= (const struct temp_slot_address_entry
*) *slot
;
701 if (! t
->temp_slot
->in_use
)
706 /* Remove all mappings of addresses to unused temp slots. */
708 remove_unused_temp_slot_addresses (void)
710 htab_traverse (temp_slot_address_table
,
711 remove_unused_temp_slot_addresses_1
,
715 /* Find the temp slot corresponding to the object at address X. */
717 static struct temp_slot
*
718 find_temp_slot_from_address (rtx x
)
721 struct temp_slot_address_entry tmp
, *t
;
723 /* First try the easy way:
724 See if X exists in the address -> temp slot mapping. */
726 tmp
.temp_slot
= NULL
;
727 tmp
.hash
= temp_slot_address_compute_hash (&tmp
);
728 t
= (struct temp_slot_address_entry
*)
729 htab_find_with_hash (temp_slot_address_table
, &tmp
, tmp
.hash
);
733 /* If we have a sum involving a register, see if it points to a temp
735 if (GET_CODE (x
) == PLUS
&& REG_P (XEXP (x
, 0))
736 && (p
= find_temp_slot_from_address (XEXP (x
, 0))) != 0)
738 else if (GET_CODE (x
) == PLUS
&& REG_P (XEXP (x
, 1))
739 && (p
= find_temp_slot_from_address (XEXP (x
, 1))) != 0)
742 /* Last resort: Address is a virtual stack var address. */
743 if (GET_CODE (x
) == PLUS
744 && XEXP (x
, 0) == virtual_stack_vars_rtx
745 && CONST_INT_P (XEXP (x
, 1)))
748 for (i
= max_slot_level (); i
>= 0; i
--)
749 for (p
= *temp_slots_at_level (i
); p
; p
= p
->next
)
751 if (INTVAL (XEXP (x
, 1)) >= p
->base_offset
752 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
)
760 /* Allocate a temporary stack slot and record it for possible later
763 MODE is the machine mode to be given to the returned rtx.
765 SIZE is the size in units of the space required. We do no rounding here
766 since assign_stack_local will do any required rounding.
768 TYPE is the type that will be used for the stack slot. */
771 assign_stack_temp_for_type (enum machine_mode mode
, HOST_WIDE_INT size
,
775 struct temp_slot
*p
, *best_p
= 0, *selected
= NULL
, **pp
;
778 /* If SIZE is -1 it means that somebody tried to allocate a temporary
779 of a variable size. */
780 gcc_assert (size
!= -1);
782 align
= get_stack_local_alignment (type
, mode
);
784 /* Try to find an available, already-allocated temporary of the proper
785 mode which meets the size and alignment requirements. Choose the
786 smallest one with the closest alignment.
788 If assign_stack_temp is called outside of the tree->rtl expansion,
789 we cannot reuse the stack slots (that may still refer to
790 VIRTUAL_STACK_VARS_REGNUM). */
791 if (!virtuals_instantiated
)
793 for (p
= avail_temp_slots
; p
; p
= p
->next
)
795 if (p
->align
>= align
&& p
->size
>= size
796 && GET_MODE (p
->slot
) == mode
797 && objects_must_conflict_p (p
->type
, type
)
798 && (best_p
== 0 || best_p
->size
> p
->size
799 || (best_p
->size
== p
->size
&& best_p
->align
> p
->align
)))
801 if (p
->align
== align
&& p
->size
== size
)
804 cut_slot_from_list (selected
, &avail_temp_slots
);
813 /* Make our best, if any, the one to use. */
817 cut_slot_from_list (selected
, &avail_temp_slots
);
819 /* If there are enough aligned bytes left over, make them into a new
820 temp_slot so that the extra bytes don't get wasted. Do this only
821 for BLKmode slots, so that we can be sure of the alignment. */
822 if (GET_MODE (best_p
->slot
) == BLKmode
)
824 int alignment
= best_p
->align
/ BITS_PER_UNIT
;
825 HOST_WIDE_INT rounded_size
= CEIL_ROUND (size
, alignment
);
827 if (best_p
->size
- rounded_size
>= alignment
)
829 p
= ggc_alloc_temp_slot ();
831 p
->size
= best_p
->size
- rounded_size
;
832 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
833 p
->full_size
= best_p
->full_size
- rounded_size
;
834 p
->slot
= adjust_address_nv (best_p
->slot
, BLKmode
, rounded_size
);
835 p
->align
= best_p
->align
;
836 p
->type
= best_p
->type
;
837 insert_slot_to_list (p
, &avail_temp_slots
);
839 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, p
->slot
,
842 best_p
->size
= rounded_size
;
843 best_p
->full_size
= rounded_size
;
848 /* If we still didn't find one, make a new temporary. */
851 HOST_WIDE_INT frame_offset_old
= frame_offset
;
853 p
= ggc_alloc_temp_slot ();
855 /* We are passing an explicit alignment request to assign_stack_local.
856 One side effect of that is assign_stack_local will not round SIZE
857 to ensure the frame offset remains suitably aligned.
859 So for requests which depended on the rounding of SIZE, we go ahead
860 and round it now. We also make sure ALIGNMENT is at least
861 BIGGEST_ALIGNMENT. */
862 gcc_assert (mode
!= BLKmode
|| align
== BIGGEST_ALIGNMENT
);
863 p
->slot
= assign_stack_local_1 (mode
,
873 /* The following slot size computation is necessary because we don't
874 know the actual size of the temporary slot until assign_stack_local
875 has performed all the frame alignment and size rounding for the
876 requested temporary. Note that extra space added for alignment
877 can be either above or below this stack slot depending on which
878 way the frame grows. We include the extra space if and only if it
879 is above this slot. */
880 if (FRAME_GROWS_DOWNWARD
)
881 p
->size
= frame_offset_old
- frame_offset
;
885 /* Now define the fields used by combine_temp_slots. */
886 if (FRAME_GROWS_DOWNWARD
)
888 p
->base_offset
= frame_offset
;
889 p
->full_size
= frame_offset_old
- frame_offset
;
893 p
->base_offset
= frame_offset_old
;
894 p
->full_size
= frame_offset
- frame_offset_old
;
903 p
->level
= temp_slot_level
;
905 pp
= temp_slots_at_level (p
->level
);
906 insert_slot_to_list (p
, pp
);
907 insert_temp_slot_address (XEXP (p
->slot
, 0), p
);
909 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
910 slot
= gen_rtx_MEM (mode
, XEXP (p
->slot
, 0));
911 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, slot
, stack_slot_list
);
913 /* If we know the alias set for the memory that will be used, use
914 it. If there's no TYPE, then we don't know anything about the
915 alias set for the memory. */
916 set_mem_alias_set (slot
, type
? get_alias_set (type
) : 0);
917 set_mem_align (slot
, align
);
919 /* If a type is specified, set the relevant flags. */
921 MEM_VOLATILE_P (slot
) = TYPE_VOLATILE (type
);
922 MEM_NOTRAP_P (slot
) = 1;
927 /* Allocate a temporary stack slot and record it for possible later
928 reuse. First two arguments are same as in preceding function. */
931 assign_stack_temp (enum machine_mode mode
, HOST_WIDE_INT size
)
933 return assign_stack_temp_for_type (mode
, size
, NULL_TREE
);
936 /* Assign a temporary.
937 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
938 and so that should be used in error messages. In either case, we
939 allocate of the given type.
940 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
941 it is 0 if a register is OK.
942 DONT_PROMOTE is 1 if we should not promote values in register
946 assign_temp (tree type_or_decl
, int memory_required
,
947 int dont_promote ATTRIBUTE_UNUSED
)
950 enum machine_mode mode
;
955 if (DECL_P (type_or_decl
))
956 decl
= type_or_decl
, type
= TREE_TYPE (decl
);
958 decl
= NULL
, type
= type_or_decl
;
960 mode
= TYPE_MODE (type
);
962 unsignedp
= TYPE_UNSIGNED (type
);
965 if (mode
== BLKmode
|| memory_required
)
967 HOST_WIDE_INT size
= int_size_in_bytes (type
);
970 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
971 problems with allocating the stack space. */
975 /* Unfortunately, we don't yet know how to allocate variable-sized
976 temporaries. However, sometimes we can find a fixed upper limit on
977 the size, so try that instead. */
979 size
= max_int_size_in_bytes (type
);
981 /* The size of the temporary may be too large to fit into an integer. */
982 /* ??? Not sure this should happen except for user silliness, so limit
983 this to things that aren't compiler-generated temporaries. The
984 rest of the time we'll die in assign_stack_temp_for_type. */
985 if (decl
&& size
== -1
986 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
)
988 error ("size of variable %q+D is too large", decl
);
992 tmp
= assign_stack_temp_for_type (mode
, size
, type
);
998 mode
= promote_mode (type
, mode
, &unsignedp
);
1001 return gen_reg_rtx (mode
);
1004 /* Combine temporary stack slots which are adjacent on the stack.
1006 This allows for better use of already allocated stack space. This is only
1007 done for BLKmode slots because we can be sure that we won't have alignment
1008 problems in this case. */
1011 combine_temp_slots (void)
1013 struct temp_slot
*p
, *q
, *next
, *next_q
;
1016 /* We can't combine slots, because the information about which slot
1017 is in which alias set will be lost. */
1018 if (flag_strict_aliasing
)
1021 /* If there are a lot of temp slots, don't do anything unless
1022 high levels of optimization. */
1023 if (! flag_expensive_optimizations
)
1024 for (p
= avail_temp_slots
, num_slots
= 0; p
; p
= p
->next
, num_slots
++)
1025 if (num_slots
> 100 || (num_slots
> 10 && optimize
== 0))
1028 for (p
= avail_temp_slots
; p
; p
= next
)
1034 if (GET_MODE (p
->slot
) != BLKmode
)
1037 for (q
= p
->next
; q
; q
= next_q
)
1043 if (GET_MODE (q
->slot
) != BLKmode
)
1046 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
1048 /* Q comes after P; combine Q into P. */
1050 p
->full_size
+= q
->full_size
;
1053 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
1055 /* P comes after Q; combine P into Q. */
1057 q
->full_size
+= p
->full_size
;
1062 cut_slot_from_list (q
, &avail_temp_slots
);
1065 /* Either delete P or advance past it. */
1067 cut_slot_from_list (p
, &avail_temp_slots
);
1071 /* Indicate that NEW_RTX is an alternate way of referring to the temp
1072 slot that previously was known by OLD_RTX. */
1075 update_temp_slot_address (rtx old_rtx
, rtx new_rtx
)
1077 struct temp_slot
*p
;
1079 if (rtx_equal_p (old_rtx
, new_rtx
))
1082 p
= find_temp_slot_from_address (old_rtx
);
1084 /* If we didn't find one, see if both OLD_RTX is a PLUS. If so, and
1085 NEW_RTX is a register, see if one operand of the PLUS is a
1086 temporary location. If so, NEW_RTX points into it. Otherwise,
1087 if both OLD_RTX and NEW_RTX are a PLUS and if there is a register
1088 in common between them. If so, try a recursive call on those
1092 if (GET_CODE (old_rtx
) != PLUS
)
1095 if (REG_P (new_rtx
))
1097 update_temp_slot_address (XEXP (old_rtx
, 0), new_rtx
);
1098 update_temp_slot_address (XEXP (old_rtx
, 1), new_rtx
);
1101 else if (GET_CODE (new_rtx
) != PLUS
)
1104 if (rtx_equal_p (XEXP (old_rtx
, 0), XEXP (new_rtx
, 0)))
1105 update_temp_slot_address (XEXP (old_rtx
, 1), XEXP (new_rtx
, 1));
1106 else if (rtx_equal_p (XEXP (old_rtx
, 1), XEXP (new_rtx
, 0)))
1107 update_temp_slot_address (XEXP (old_rtx
, 0), XEXP (new_rtx
, 1));
1108 else if (rtx_equal_p (XEXP (old_rtx
, 0), XEXP (new_rtx
, 1)))
1109 update_temp_slot_address (XEXP (old_rtx
, 1), XEXP (new_rtx
, 0));
1110 else if (rtx_equal_p (XEXP (old_rtx
, 1), XEXP (new_rtx
, 1)))
1111 update_temp_slot_address (XEXP (old_rtx
, 0), XEXP (new_rtx
, 0));
1116 /* Otherwise add an alias for the temp's address. */
1117 insert_temp_slot_address (new_rtx
, p
);
1120 /* If X could be a reference to a temporary slot, mark that slot as
1121 belonging to the to one level higher than the current level. If X
1122 matched one of our slots, just mark that one. Otherwise, we can't
1123 easily predict which it is, so upgrade all of them.
1125 This is called when an ({...}) construct occurs and a statement
1126 returns a value in memory. */
1129 preserve_temp_slots (rtx x
)
1131 struct temp_slot
*p
= 0, *next
;
1136 /* If X is a register that is being used as a pointer, see if we have
1137 a temporary slot we know it points to. */
1138 if (REG_P (x
) && REG_POINTER (x
))
1139 p
= find_temp_slot_from_address (x
);
1141 /* If X is not in memory or is at a constant address, it cannot be in
1142 a temporary slot. */
1143 if (p
== 0 && (!MEM_P (x
) || CONSTANT_P (XEXP (x
, 0))))
1146 /* First see if we can find a match. */
1148 p
= find_temp_slot_from_address (XEXP (x
, 0));
1152 if (p
->level
== temp_slot_level
)
1153 move_slot_to_level (p
, temp_slot_level
- 1);
1157 /* Otherwise, preserve all non-kept slots at this level. */
1158 for (p
= *temp_slots_at_level (temp_slot_level
); p
; p
= next
)
1161 move_slot_to_level (p
, temp_slot_level
- 1);
1165 /* Free all temporaries used so far. This is normally called at the
1166 end of generating code for a statement. */
1169 free_temp_slots (void)
1171 struct temp_slot
*p
, *next
;
1172 bool some_available
= false;
1174 for (p
= *temp_slots_at_level (temp_slot_level
); p
; p
= next
)
1177 make_slot_available (p
);
1178 some_available
= true;
1183 remove_unused_temp_slot_addresses ();
1184 combine_temp_slots ();
1188 /* Push deeper into the nesting level for stack temporaries. */
1191 push_temp_slots (void)
1196 /* Pop a temporary nesting level. All slots in use in the current level
1200 pop_temp_slots (void)
1206 /* Initialize temporary slots. */
1209 init_temp_slots (void)
1211 /* We have not allocated any temporaries yet. */
1212 avail_temp_slots
= 0;
1213 used_temp_slots
= 0;
1214 temp_slot_level
= 0;
1216 /* Set up the table to map addresses to temp slots. */
1217 if (! temp_slot_address_table
)
1218 temp_slot_address_table
= htab_create_ggc (32,
1219 temp_slot_address_hash
,
1220 temp_slot_address_eq
,
1223 htab_empty (temp_slot_address_table
);
1226 /* Functions and data structures to keep track of the values hard regs
1227 had at the start of the function. */
1229 /* Private type used by get_hard_reg_initial_reg, get_hard_reg_initial_val,
1230 and has_hard_reg_initial_val.. */
1231 typedef struct GTY(()) initial_value_pair
{
1234 } initial_value_pair
;
1235 /* ??? This could be a VEC but there is currently no way to define an
1236 opaque VEC type. This could be worked around by defining struct
1237 initial_value_pair in function.h. */
1238 typedef struct GTY(()) initial_value_struct
{
1241 initial_value_pair
* GTY ((length ("%h.num_entries"))) entries
;
1242 } initial_value_struct
;
1244 /* If a pseudo represents an initial hard reg (or expression), return
1245 it, else return NULL_RTX. */
1248 get_hard_reg_initial_reg (rtx reg
)
1250 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1256 for (i
= 0; i
< ivs
->num_entries
; i
++)
1257 if (rtx_equal_p (ivs
->entries
[i
].pseudo
, reg
))
1258 return ivs
->entries
[i
].hard_reg
;
1263 /* Make sure that there's a pseudo register of mode MODE that stores the
1264 initial value of hard register REGNO. Return an rtx for such a pseudo. */
1267 get_hard_reg_initial_val (enum machine_mode mode
, unsigned int regno
)
1269 struct initial_value_struct
*ivs
;
1272 rv
= has_hard_reg_initial_val (mode
, regno
);
1276 ivs
= crtl
->hard_reg_initial_vals
;
1279 ivs
= ggc_alloc_initial_value_struct ();
1280 ivs
->num_entries
= 0;
1281 ivs
->max_entries
= 5;
1282 ivs
->entries
= ggc_alloc_vec_initial_value_pair (5);
1283 crtl
->hard_reg_initial_vals
= ivs
;
1286 if (ivs
->num_entries
>= ivs
->max_entries
)
1288 ivs
->max_entries
+= 5;
1289 ivs
->entries
= GGC_RESIZEVEC (initial_value_pair
, ivs
->entries
,
1293 ivs
->entries
[ivs
->num_entries
].hard_reg
= gen_rtx_REG (mode
, regno
);
1294 ivs
->entries
[ivs
->num_entries
].pseudo
= gen_reg_rtx (mode
);
1296 return ivs
->entries
[ivs
->num_entries
++].pseudo
;
1299 /* See if get_hard_reg_initial_val has been used to create a pseudo
1300 for the initial value of hard register REGNO in mode MODE. Return
1301 the associated pseudo if so, otherwise return NULL. */
1304 has_hard_reg_initial_val (enum machine_mode mode
, unsigned int regno
)
1306 struct initial_value_struct
*ivs
;
1309 ivs
= crtl
->hard_reg_initial_vals
;
1311 for (i
= 0; i
< ivs
->num_entries
; i
++)
1312 if (GET_MODE (ivs
->entries
[i
].hard_reg
) == mode
1313 && REGNO (ivs
->entries
[i
].hard_reg
) == regno
)
1314 return ivs
->entries
[i
].pseudo
;
1320 emit_initial_value_sets (void)
1322 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1330 for (i
= 0; i
< ivs
->num_entries
; i
++)
1331 emit_move_insn (ivs
->entries
[i
].pseudo
, ivs
->entries
[i
].hard_reg
);
1335 emit_insn_at_entry (seq
);
1339 /* Return the hardreg-pseudoreg initial values pair entry I and
1340 TRUE if I is a valid entry, or FALSE if I is not a valid entry. */
1342 initial_value_entry (int i
, rtx
*hreg
, rtx
*preg
)
1344 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1345 if (!ivs
|| i
>= ivs
->num_entries
)
1348 *hreg
= ivs
->entries
[i
].hard_reg
;
1349 *preg
= ivs
->entries
[i
].pseudo
;
1353 /* These routines are responsible for converting virtual register references
1354 to the actual hard register references once RTL generation is complete.
1356 The following four variables are used for communication between the
1357 routines. They contain the offsets of the virtual registers from their
1358 respective hard registers. */
1360 static int in_arg_offset
;
1361 static int var_offset
;
1362 static int dynamic_offset
;
1363 static int out_arg_offset
;
1364 static int cfa_offset
;
1366 /* In most machines, the stack pointer register is equivalent to the bottom
1369 #ifndef STACK_POINTER_OFFSET
1370 #define STACK_POINTER_OFFSET 0
1373 /* If not defined, pick an appropriate default for the offset of dynamically
1374 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
1375 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
1377 #ifndef STACK_DYNAMIC_OFFSET
1379 /* The bottom of the stack points to the actual arguments. If
1380 REG_PARM_STACK_SPACE is defined, this includes the space for the register
1381 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
1382 stack space for register parameters is not pushed by the caller, but
1383 rather part of the fixed stack areas and hence not included in
1384 `crtl->outgoing_args_size'. Nevertheless, we must allow
1385 for it when allocating stack dynamic objects. */
1387 #if defined(REG_PARM_STACK_SPACE)
1388 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1389 ((ACCUMULATE_OUTGOING_ARGS \
1390 ? (crtl->outgoing_args_size \
1391 + (OUTGOING_REG_PARM_STACK_SPACE ((!(FNDECL) ? NULL_TREE : TREE_TYPE (FNDECL))) ? 0 \
1392 : REG_PARM_STACK_SPACE (FNDECL))) \
1393 : 0) + (STACK_POINTER_OFFSET))
1395 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1396 ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0) \
1397 + (STACK_POINTER_OFFSET))
1402 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
1403 is a virtual register, return the equivalent hard register and set the
1404 offset indirectly through the pointer. Otherwise, return 0. */
1407 instantiate_new_reg (rtx x
, HOST_WIDE_INT
*poffset
)
1410 HOST_WIDE_INT offset
;
1412 if (x
== virtual_incoming_args_rtx
)
1414 if (stack_realign_drap
)
1416 /* Replace virtual_incoming_args_rtx with internal arg
1417 pointer if DRAP is used to realign stack. */
1418 new_rtx
= crtl
->args
.internal_arg_pointer
;
1422 new_rtx
= arg_pointer_rtx
, offset
= in_arg_offset
;
1424 else if (x
== virtual_stack_vars_rtx
)
1425 new_rtx
= frame_pointer_rtx
, offset
= var_offset
;
1426 else if (x
== virtual_stack_dynamic_rtx
)
1427 new_rtx
= stack_pointer_rtx
, offset
= dynamic_offset
;
1428 else if (x
== virtual_outgoing_args_rtx
)
1429 new_rtx
= stack_pointer_rtx
, offset
= out_arg_offset
;
1430 else if (x
== virtual_cfa_rtx
)
1432 #ifdef FRAME_POINTER_CFA_OFFSET
1433 new_rtx
= frame_pointer_rtx
;
1435 new_rtx
= arg_pointer_rtx
;
1437 offset
= cfa_offset
;
1439 else if (x
== virtual_preferred_stack_boundary_rtx
)
1441 new_rtx
= GEN_INT (crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
);
1451 /* A subroutine of instantiate_virtual_regs, called via for_each_rtx.
1452 Instantiate any virtual registers present inside of *LOC. The expression
1453 is simplified, as much as possible, but is not to be considered "valid"
1454 in any sense implied by the target. If any change is made, set CHANGED
1458 instantiate_virtual_regs_in_rtx (rtx
*loc
, void *data
)
1460 HOST_WIDE_INT offset
;
1461 bool *changed
= (bool *) data
;
1468 switch (GET_CODE (x
))
1471 new_rtx
= instantiate_new_reg (x
, &offset
);
1474 *loc
= plus_constant (GET_MODE (x
), new_rtx
, offset
);
1481 new_rtx
= instantiate_new_reg (XEXP (x
, 0), &offset
);
1484 new_rtx
= plus_constant (GET_MODE (x
), new_rtx
, offset
);
1485 *loc
= simplify_gen_binary (PLUS
, GET_MODE (x
), new_rtx
, XEXP (x
, 1));
1491 /* FIXME -- from old code */
1492 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
1493 we can commute the PLUS and SUBREG because pointers into the
1494 frame are well-behaved. */
1504 /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
1505 matches the predicate for insn CODE operand OPERAND. */
1508 safe_insn_predicate (int code
, int operand
, rtx x
)
1510 return code
< 0 || insn_operand_matches ((enum insn_code
) code
, operand
, x
);
1513 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1514 registers present inside of insn. The result will be a valid insn. */
1517 instantiate_virtual_regs_in_insn (rtx insn
)
1519 HOST_WIDE_INT offset
;
1521 bool any_change
= false;
1522 rtx set
, new_rtx
, x
, seq
;
1524 /* There are some special cases to be handled first. */
1525 set
= single_set (insn
);
1528 /* We're allowed to assign to a virtual register. This is interpreted
1529 to mean that the underlying register gets assigned the inverse
1530 transformation. This is used, for example, in the handling of
1532 new_rtx
= instantiate_new_reg (SET_DEST (set
), &offset
);
1537 for_each_rtx (&SET_SRC (set
), instantiate_virtual_regs_in_rtx
, NULL
);
1538 x
= simplify_gen_binary (PLUS
, GET_MODE (new_rtx
), SET_SRC (set
),
1540 x
= force_operand (x
, new_rtx
);
1542 emit_move_insn (new_rtx
, x
);
1547 emit_insn_before (seq
, insn
);
1552 /* Handle a straight copy from a virtual register by generating a
1553 new add insn. The difference between this and falling through
1554 to the generic case is avoiding a new pseudo and eliminating a
1555 move insn in the initial rtl stream. */
1556 new_rtx
= instantiate_new_reg (SET_SRC (set
), &offset
);
1557 if (new_rtx
&& offset
!= 0
1558 && REG_P (SET_DEST (set
))
1559 && REGNO (SET_DEST (set
)) > LAST_VIRTUAL_REGISTER
)
1563 x
= expand_simple_binop (GET_MODE (SET_DEST (set
)), PLUS
,
1564 new_rtx
, GEN_INT (offset
), SET_DEST (set
),
1565 1, OPTAB_LIB_WIDEN
);
1566 if (x
!= SET_DEST (set
))
1567 emit_move_insn (SET_DEST (set
), x
);
1572 emit_insn_before (seq
, insn
);
1577 extract_insn (insn
);
1578 insn_code
= INSN_CODE (insn
);
1580 /* Handle a plus involving a virtual register by determining if the
1581 operands remain valid if they're modified in place. */
1582 if (GET_CODE (SET_SRC (set
)) == PLUS
1583 && recog_data
.n_operands
>= 3
1584 && recog_data
.operand_loc
[1] == &XEXP (SET_SRC (set
), 0)
1585 && recog_data
.operand_loc
[2] == &XEXP (SET_SRC (set
), 1)
1586 && CONST_INT_P (recog_data
.operand
[2])
1587 && (new_rtx
= instantiate_new_reg (recog_data
.operand
[1], &offset
)))
1589 offset
+= INTVAL (recog_data
.operand
[2]);
1591 /* If the sum is zero, then replace with a plain move. */
1593 && REG_P (SET_DEST (set
))
1594 && REGNO (SET_DEST (set
)) > LAST_VIRTUAL_REGISTER
)
1597 emit_move_insn (SET_DEST (set
), new_rtx
);
1601 emit_insn_before (seq
, insn
);
1606 x
= gen_int_mode (offset
, recog_data
.operand_mode
[2]);
1608 /* Using validate_change and apply_change_group here leaves
1609 recog_data in an invalid state. Since we know exactly what
1610 we want to check, do those two by hand. */
1611 if (safe_insn_predicate (insn_code
, 1, new_rtx
)
1612 && safe_insn_predicate (insn_code
, 2, x
))
1614 *recog_data
.operand_loc
[1] = recog_data
.operand
[1] = new_rtx
;
1615 *recog_data
.operand_loc
[2] = recog_data
.operand
[2] = x
;
1618 /* Fall through into the regular operand fixup loop in
1619 order to take care of operands other than 1 and 2. */
1625 extract_insn (insn
);
1626 insn_code
= INSN_CODE (insn
);
1629 /* In the general case, we expect virtual registers to appear only in
1630 operands, and then only as either bare registers or inside memories. */
1631 for (i
= 0; i
< recog_data
.n_operands
; ++i
)
1633 x
= recog_data
.operand
[i
];
1634 switch (GET_CODE (x
))
1638 rtx addr
= XEXP (x
, 0);
1639 bool changed
= false;
1641 for_each_rtx (&addr
, instantiate_virtual_regs_in_rtx
, &changed
);
1646 x
= replace_equiv_address (x
, addr
);
1647 /* It may happen that the address with the virtual reg
1648 was valid (e.g. based on the virtual stack reg, which might
1649 be acceptable to the predicates with all offsets), whereas
1650 the address now isn't anymore, for instance when the address
1651 is still offsetted, but the base reg isn't virtual-stack-reg
1652 anymore. Below we would do a force_reg on the whole operand,
1653 but this insn might actually only accept memory. Hence,
1654 before doing that last resort, try to reload the address into
1655 a register, so this operand stays a MEM. */
1656 if (!safe_insn_predicate (insn_code
, i
, x
))
1658 addr
= force_reg (GET_MODE (addr
), addr
);
1659 x
= replace_equiv_address (x
, addr
);
1664 emit_insn_before (seq
, insn
);
1669 new_rtx
= instantiate_new_reg (x
, &offset
);
1670 if (new_rtx
== NULL
)
1678 /* Careful, special mode predicates may have stuff in
1679 insn_data[insn_code].operand[i].mode that isn't useful
1680 to us for computing a new value. */
1681 /* ??? Recognize address_operand and/or "p" constraints
1682 to see if (plus new offset) is a valid before we put
1683 this through expand_simple_binop. */
1684 x
= expand_simple_binop (GET_MODE (x
), PLUS
, new_rtx
,
1685 GEN_INT (offset
), NULL_RTX
,
1686 1, OPTAB_LIB_WIDEN
);
1689 emit_insn_before (seq
, insn
);
1694 new_rtx
= instantiate_new_reg (SUBREG_REG (x
), &offset
);
1695 if (new_rtx
== NULL
)
1700 new_rtx
= expand_simple_binop (GET_MODE (new_rtx
), PLUS
, new_rtx
,
1701 GEN_INT (offset
), NULL_RTX
,
1702 1, OPTAB_LIB_WIDEN
);
1705 emit_insn_before (seq
, insn
);
1707 x
= simplify_gen_subreg (recog_data
.operand_mode
[i
], new_rtx
,
1708 GET_MODE (new_rtx
), SUBREG_BYTE (x
));
1716 /* At this point, X contains the new value for the operand.
1717 Validate the new value vs the insn predicate. Note that
1718 asm insns will have insn_code -1 here. */
1719 if (!safe_insn_predicate (insn_code
, i
, x
))
1724 gcc_assert (REGNO (x
) <= LAST_VIRTUAL_REGISTER
);
1725 x
= copy_to_reg (x
);
1728 x
= force_reg (insn_data
[insn_code
].operand
[i
].mode
, x
);
1732 emit_insn_before (seq
, insn
);
1735 *recog_data
.operand_loc
[i
] = recog_data
.operand
[i
] = x
;
1741 /* Propagate operand changes into the duplicates. */
1742 for (i
= 0; i
< recog_data
.n_dups
; ++i
)
1743 *recog_data
.dup_loc
[i
]
1744 = copy_rtx (recog_data
.operand
[(unsigned)recog_data
.dup_num
[i
]]);
1746 /* Force re-recognition of the instruction for validation. */
1747 INSN_CODE (insn
) = -1;
1750 if (asm_noperands (PATTERN (insn
)) >= 0)
1752 if (!check_asm_operands (PATTERN (insn
)))
1754 error_for_asm (insn
, "impossible constraint in %<asm%>");
1755 delete_insn_and_edges (insn
);
1760 if (recog_memoized (insn
) < 0)
1761 fatal_insn_not_found (insn
);
1765 /* Subroutine of instantiate_decls. Given RTL representing a decl,
1766 do any instantiation required. */
1769 instantiate_decl_rtl (rtx x
)
1776 /* If this is a CONCAT, recurse for the pieces. */
1777 if (GET_CODE (x
) == CONCAT
)
1779 instantiate_decl_rtl (XEXP (x
, 0));
1780 instantiate_decl_rtl (XEXP (x
, 1));
1784 /* If this is not a MEM, no need to do anything. Similarly if the
1785 address is a constant or a register that is not a virtual register. */
1790 if (CONSTANT_P (addr
)
1792 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
1793 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
1796 for_each_rtx (&XEXP (x
, 0), instantiate_virtual_regs_in_rtx
, NULL
);
1799 /* Helper for instantiate_decls called via walk_tree: Process all decls
1800 in the given DECL_VALUE_EXPR. */
1803 instantiate_expr (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
1811 if (DECL_RTL_SET_P (t
))
1812 instantiate_decl_rtl (DECL_RTL (t
));
1813 if (TREE_CODE (t
) == PARM_DECL
&& DECL_NAMELESS (t
)
1814 && DECL_INCOMING_RTL (t
))
1815 instantiate_decl_rtl (DECL_INCOMING_RTL (t
));
1816 if ((TREE_CODE (t
) == VAR_DECL
1817 || TREE_CODE (t
) == RESULT_DECL
)
1818 && DECL_HAS_VALUE_EXPR_P (t
))
1820 tree v
= DECL_VALUE_EXPR (t
);
1821 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1828 /* Subroutine of instantiate_decls: Process all decls in the given
1829 BLOCK node and all its subblocks. */
1832 instantiate_decls_1 (tree let
)
1836 for (t
= BLOCK_VARS (let
); t
; t
= DECL_CHAIN (t
))
1838 if (DECL_RTL_SET_P (t
))
1839 instantiate_decl_rtl (DECL_RTL (t
));
1840 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HAS_VALUE_EXPR_P (t
))
1842 tree v
= DECL_VALUE_EXPR (t
);
1843 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1847 /* Process all subblocks. */
1848 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= BLOCK_CHAIN (t
))
1849 instantiate_decls_1 (t
);
1852 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
1853 all virtual registers in their DECL_RTL's. */
1856 instantiate_decls (tree fndecl
)
1861 /* Process all parameters of the function. */
1862 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= DECL_CHAIN (decl
))
1864 instantiate_decl_rtl (DECL_RTL (decl
));
1865 instantiate_decl_rtl (DECL_INCOMING_RTL (decl
));
1866 if (DECL_HAS_VALUE_EXPR_P (decl
))
1868 tree v
= DECL_VALUE_EXPR (decl
);
1869 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1873 if ((decl
= DECL_RESULT (fndecl
))
1874 && TREE_CODE (decl
) == RESULT_DECL
)
1876 if (DECL_RTL_SET_P (decl
))
1877 instantiate_decl_rtl (DECL_RTL (decl
));
1878 if (DECL_HAS_VALUE_EXPR_P (decl
))
1880 tree v
= DECL_VALUE_EXPR (decl
);
1881 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1885 /* Now process all variables defined in the function or its subblocks. */
1886 instantiate_decls_1 (DECL_INITIAL (fndecl
));
1888 FOR_EACH_LOCAL_DECL (cfun
, ix
, decl
)
1889 if (DECL_RTL_SET_P (decl
))
1890 instantiate_decl_rtl (DECL_RTL (decl
));
1891 VEC_free (tree
, gc
, cfun
->local_decls
);
1894 /* Pass through the INSNS of function FNDECL and convert virtual register
1895 references to hard register references. */
1898 instantiate_virtual_regs (void)
1902 /* Compute the offsets to use for this function. */
1903 in_arg_offset
= FIRST_PARM_OFFSET (current_function_decl
);
1904 var_offset
= STARTING_FRAME_OFFSET
;
1905 dynamic_offset
= STACK_DYNAMIC_OFFSET (current_function_decl
);
1906 out_arg_offset
= STACK_POINTER_OFFSET
;
1907 #ifdef FRAME_POINTER_CFA_OFFSET
1908 cfa_offset
= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
1910 cfa_offset
= ARG_POINTER_CFA_OFFSET (current_function_decl
);
1913 /* Initialize recognition, indicating that volatile is OK. */
1916 /* Scan through all the insns, instantiating every virtual register still
1918 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
1921 /* These patterns in the instruction stream can never be recognized.
1922 Fortunately, they shouldn't contain virtual registers either. */
1923 if (GET_CODE (PATTERN (insn
)) == USE
1924 || GET_CODE (PATTERN (insn
)) == CLOBBER
1925 || GET_CODE (PATTERN (insn
)) == ADDR_VEC
1926 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
1927 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
)
1929 else if (DEBUG_INSN_P (insn
))
1930 for_each_rtx (&INSN_VAR_LOCATION (insn
),
1931 instantiate_virtual_regs_in_rtx
, NULL
);
1933 instantiate_virtual_regs_in_insn (insn
);
1935 if (INSN_DELETED_P (insn
))
1938 for_each_rtx (®_NOTES (insn
), instantiate_virtual_regs_in_rtx
, NULL
);
1940 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
1942 for_each_rtx (&CALL_INSN_FUNCTION_USAGE (insn
),
1943 instantiate_virtual_regs_in_rtx
, NULL
);
1946 /* Instantiate the virtual registers in the DECLs for debugging purposes. */
1947 instantiate_decls (current_function_decl
);
1949 targetm
.instantiate_decls ();
1951 /* Indicate that, from now on, assign_stack_local should use
1952 frame_pointer_rtx. */
1953 virtuals_instantiated
= 1;
1958 struct rtl_opt_pass pass_instantiate_virtual_regs
=
1964 instantiate_virtual_regs
, /* execute */
1967 0, /* static_pass_number */
1968 TV_NONE
, /* tv_id */
1969 0, /* properties_required */
1970 0, /* properties_provided */
1971 0, /* properties_destroyed */
1972 0, /* todo_flags_start */
1973 0 /* todo_flags_finish */
1978 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
1979 This means a type for which function calls must pass an address to the
1980 function or get an address back from the function.
1981 EXP may be a type node or an expression (whose type is tested). */
1984 aggregate_value_p (const_tree exp
, const_tree fntype
)
1986 const_tree type
= (TYPE_P (exp
)) ? exp
: TREE_TYPE (exp
);
1987 int i
, regno
, nregs
;
1991 switch (TREE_CODE (fntype
))
1995 tree fndecl
= get_callee_fndecl (fntype
);
1997 ? TREE_TYPE (fndecl
)
1998 : TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (fntype
))));
2002 fntype
= TREE_TYPE (fntype
);
2007 case IDENTIFIER_NODE
:
2011 /* We don't expect other tree types here. */
2015 if (VOID_TYPE_P (type
))
2018 /* If a record should be passed the same as its first (and only) member
2019 don't pass it as an aggregate. */
2020 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_TRANSPARENT_AGGR (type
))
2021 return aggregate_value_p (first_field (type
), fntype
);
2023 /* If the front end has decided that this needs to be passed by
2024 reference, do so. */
2025 if ((TREE_CODE (exp
) == PARM_DECL
|| TREE_CODE (exp
) == RESULT_DECL
)
2026 && DECL_BY_REFERENCE (exp
))
2029 /* Function types that are TREE_ADDRESSABLE force return in memory. */
2030 if (fntype
&& TREE_ADDRESSABLE (fntype
))
2033 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
2034 and thus can't be returned in registers. */
2035 if (TREE_ADDRESSABLE (type
))
2038 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
2041 if (targetm
.calls
.return_in_memory (type
, fntype
))
2044 /* Make sure we have suitable call-clobbered regs to return
2045 the value in; if not, we must return it in memory. */
2046 reg
= hard_function_value (type
, 0, fntype
, 0);
2048 /* If we have something other than a REG (e.g. a PARALLEL), then assume
2053 regno
= REGNO (reg
);
2054 nregs
= hard_regno_nregs
[regno
][TYPE_MODE (type
)];
2055 for (i
= 0; i
< nregs
; i
++)
2056 if (! call_used_regs
[regno
+ i
])
2062 /* Return true if we should assign DECL a pseudo register; false if it
2063 should live on the local stack. */
2066 use_register_for_decl (const_tree decl
)
2068 if (!targetm
.calls
.allocate_stack_slots_for_args())
2071 /* Honor volatile. */
2072 if (TREE_SIDE_EFFECTS (decl
))
2075 /* Honor addressability. */
2076 if (TREE_ADDRESSABLE (decl
))
2079 /* Only register-like things go in registers. */
2080 if (DECL_MODE (decl
) == BLKmode
)
2083 /* If -ffloat-store specified, don't put explicit float variables
2085 /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
2086 propagates values across these stores, and it probably shouldn't. */
2087 if (flag_float_store
&& FLOAT_TYPE_P (TREE_TYPE (decl
)))
2090 /* If we're not interested in tracking debugging information for
2091 this decl, then we can certainly put it in a register. */
2092 if (DECL_IGNORED_P (decl
))
2098 if (!DECL_REGISTER (decl
))
2101 switch (TREE_CODE (TREE_TYPE (decl
)))
2105 case QUAL_UNION_TYPE
:
2106 /* When not optimizing, disregard register keyword for variables with
2107 types containing methods, otherwise the methods won't be callable
2108 from the debugger. */
2109 if (TYPE_METHODS (TREE_TYPE (decl
)))
2119 /* Return true if TYPE should be passed by invisible reference. */
2122 pass_by_reference (CUMULATIVE_ARGS
*ca
, enum machine_mode mode
,
2123 tree type
, bool named_arg
)
2127 /* If this type contains non-trivial constructors, then it is
2128 forbidden for the middle-end to create any new copies. */
2129 if (TREE_ADDRESSABLE (type
))
2132 /* GCC post 3.4 passes *all* variable sized types by reference. */
2133 if (!TYPE_SIZE (type
) || TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
2136 /* If a record type should be passed the same as its first (and only)
2137 member, use the type and mode of that member. */
2138 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_TRANSPARENT_AGGR (type
))
2140 type
= TREE_TYPE (first_field (type
));
2141 mode
= TYPE_MODE (type
);
2145 return targetm
.calls
.pass_by_reference (pack_cumulative_args (ca
), mode
,
2149 /* Return true if TYPE, which is passed by reference, should be callee
2150 copied instead of caller copied. */
2153 reference_callee_copied (CUMULATIVE_ARGS
*ca
, enum machine_mode mode
,
2154 tree type
, bool named_arg
)
2156 if (type
&& TREE_ADDRESSABLE (type
))
2158 return targetm
.calls
.callee_copies (pack_cumulative_args (ca
), mode
, type
,
2162 /* Structures to communicate between the subroutines of assign_parms.
2163 The first holds data persistent across all parameters, the second
2164 is cleared out for each parameter. */
2166 struct assign_parm_data_all
2168 /* When INIT_CUMULATIVE_ARGS gets revamped, allocating CUMULATIVE_ARGS
2169 should become a job of the target or otherwise encapsulated. */
2170 CUMULATIVE_ARGS args_so_far_v
;
2171 cumulative_args_t args_so_far
;
2172 struct args_size stack_args_size
;
2173 tree function_result_decl
;
2175 rtx first_conversion_insn
;
2176 rtx last_conversion_insn
;
2177 HOST_WIDE_INT pretend_args_size
;
2178 HOST_WIDE_INT extra_pretend_bytes
;
2179 int reg_parm_stack_space
;
2182 struct assign_parm_data_one
2188 enum machine_mode nominal_mode
;
2189 enum machine_mode passed_mode
;
2190 enum machine_mode promoted_mode
;
2191 struct locate_and_pad_arg_data locate
;
2193 BOOL_BITFIELD named_arg
: 1;
2194 BOOL_BITFIELD passed_pointer
: 1;
2195 BOOL_BITFIELD on_stack
: 1;
2196 BOOL_BITFIELD loaded_in_reg
: 1;
2199 /* A subroutine of assign_parms. Initialize ALL. */
2202 assign_parms_initialize_all (struct assign_parm_data_all
*all
)
2204 tree fntype ATTRIBUTE_UNUSED
;
2206 memset (all
, 0, sizeof (*all
));
2208 fntype
= TREE_TYPE (current_function_decl
);
2210 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
2211 INIT_CUMULATIVE_INCOMING_ARGS (all
->args_so_far_v
, fntype
, NULL_RTX
);
2213 INIT_CUMULATIVE_ARGS (all
->args_so_far_v
, fntype
, NULL_RTX
,
2214 current_function_decl
, -1);
2216 all
->args_so_far
= pack_cumulative_args (&all
->args_so_far_v
);
2218 #ifdef REG_PARM_STACK_SPACE
2219 all
->reg_parm_stack_space
= REG_PARM_STACK_SPACE (current_function_decl
);
2223 /* If ARGS contains entries with complex types, split the entry into two
2224 entries of the component type. Return a new list of substitutions are
2225 needed, else the old list. */
2228 split_complex_args (VEC(tree
, heap
) **args
)
2233 FOR_EACH_VEC_ELT (tree
, *args
, i
, p
)
2235 tree type
= TREE_TYPE (p
);
2236 if (TREE_CODE (type
) == COMPLEX_TYPE
2237 && targetm
.calls
.split_complex_arg (type
))
2240 tree subtype
= TREE_TYPE (type
);
2241 bool addressable
= TREE_ADDRESSABLE (p
);
2243 /* Rewrite the PARM_DECL's type with its component. */
2245 TREE_TYPE (p
) = subtype
;
2246 DECL_ARG_TYPE (p
) = TREE_TYPE (DECL_ARG_TYPE (p
));
2247 DECL_MODE (p
) = VOIDmode
;
2248 DECL_SIZE (p
) = NULL
;
2249 DECL_SIZE_UNIT (p
) = NULL
;
2250 /* If this arg must go in memory, put it in a pseudo here.
2251 We can't allow it to go in memory as per normal parms,
2252 because the usual place might not have the imag part
2253 adjacent to the real part. */
2254 DECL_ARTIFICIAL (p
) = addressable
;
2255 DECL_IGNORED_P (p
) = addressable
;
2256 TREE_ADDRESSABLE (p
) = 0;
2258 VEC_replace (tree
, *args
, i
, p
);
2260 /* Build a second synthetic decl. */
2261 decl
= build_decl (EXPR_LOCATION (p
),
2262 PARM_DECL
, NULL_TREE
, subtype
);
2263 DECL_ARG_TYPE (decl
) = DECL_ARG_TYPE (p
);
2264 DECL_ARTIFICIAL (decl
) = addressable
;
2265 DECL_IGNORED_P (decl
) = addressable
;
2266 layout_decl (decl
, 0);
2267 VEC_safe_insert (tree
, heap
, *args
, ++i
, decl
);
2272 /* A subroutine of assign_parms. Adjust the parameter list to incorporate
2273 the hidden struct return argument, and (abi willing) complex args.
2274 Return the new parameter list. */
2276 static VEC(tree
, heap
) *
2277 assign_parms_augmented_arg_list (struct assign_parm_data_all
*all
)
2279 tree fndecl
= current_function_decl
;
2280 tree fntype
= TREE_TYPE (fndecl
);
2281 VEC(tree
, heap
) *fnargs
= NULL
;
2284 for (arg
= DECL_ARGUMENTS (fndecl
); arg
; arg
= DECL_CHAIN (arg
))
2285 VEC_safe_push (tree
, heap
, fnargs
, arg
);
2287 all
->orig_fnargs
= DECL_ARGUMENTS (fndecl
);
2289 /* If struct value address is treated as the first argument, make it so. */
2290 if (aggregate_value_p (DECL_RESULT (fndecl
), fndecl
)
2291 && ! cfun
->returns_pcc_struct
2292 && targetm
.calls
.struct_value_rtx (TREE_TYPE (fndecl
), 1) == 0)
2294 tree type
= build_pointer_type (TREE_TYPE (fntype
));
2297 decl
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
2298 PARM_DECL
, get_identifier (".result_ptr"), type
);
2299 DECL_ARG_TYPE (decl
) = type
;
2300 DECL_ARTIFICIAL (decl
) = 1;
2301 DECL_NAMELESS (decl
) = 1;
2302 TREE_CONSTANT (decl
) = 1;
2304 DECL_CHAIN (decl
) = all
->orig_fnargs
;
2305 all
->orig_fnargs
= decl
;
2306 VEC_safe_insert (tree
, heap
, fnargs
, 0, decl
);
2308 all
->function_result_decl
= decl
;
2311 /* If the target wants to split complex arguments into scalars, do so. */
2312 if (targetm
.calls
.split_complex_arg
)
2313 split_complex_args (&fnargs
);
2318 /* A subroutine of assign_parms. Examine PARM and pull out type and mode
2319 data for the parameter. Incorporate ABI specifics such as pass-by-
2320 reference and type promotion. */
2323 assign_parm_find_data_types (struct assign_parm_data_all
*all
, tree parm
,
2324 struct assign_parm_data_one
*data
)
2326 tree nominal_type
, passed_type
;
2327 enum machine_mode nominal_mode
, passed_mode
, promoted_mode
;
2330 memset (data
, 0, sizeof (*data
));
2332 /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */
2334 data
->named_arg
= 1; /* No variadic parms. */
2335 else if (DECL_CHAIN (parm
))
2336 data
->named_arg
= 1; /* Not the last non-variadic parm. */
2337 else if (targetm
.calls
.strict_argument_naming (all
->args_so_far
))
2338 data
->named_arg
= 1; /* Only variadic ones are unnamed. */
2340 data
->named_arg
= 0; /* Treat as variadic. */
2342 nominal_type
= TREE_TYPE (parm
);
2343 passed_type
= DECL_ARG_TYPE (parm
);
2345 /* Look out for errors propagating this far. Also, if the parameter's
2346 type is void then its value doesn't matter. */
2347 if (TREE_TYPE (parm
) == error_mark_node
2348 /* This can happen after weird syntax errors
2349 or if an enum type is defined among the parms. */
2350 || TREE_CODE (parm
) != PARM_DECL
2351 || passed_type
== NULL
2352 || VOID_TYPE_P (nominal_type
))
2354 nominal_type
= passed_type
= void_type_node
;
2355 nominal_mode
= passed_mode
= promoted_mode
= VOIDmode
;
2359 /* Find mode of arg as it is passed, and mode of arg as it should be
2360 during execution of this function. */
2361 passed_mode
= TYPE_MODE (passed_type
);
2362 nominal_mode
= TYPE_MODE (nominal_type
);
2364 /* If the parm is to be passed as a transparent union or record, use the
2365 type of the first field for the tests below. We have already verified
2366 that the modes are the same. */
2367 if ((TREE_CODE (passed_type
) == UNION_TYPE
2368 || TREE_CODE (passed_type
) == RECORD_TYPE
)
2369 && TYPE_TRANSPARENT_AGGR (passed_type
))
2370 passed_type
= TREE_TYPE (first_field (passed_type
));
2372 /* See if this arg was passed by invisible reference. */
2373 if (pass_by_reference (&all
->args_so_far_v
, passed_mode
,
2374 passed_type
, data
->named_arg
))
2376 passed_type
= nominal_type
= build_pointer_type (passed_type
);
2377 data
->passed_pointer
= true;
2378 passed_mode
= nominal_mode
= Pmode
;
2381 /* Find mode as it is passed by the ABI. */
2382 unsignedp
= TYPE_UNSIGNED (passed_type
);
2383 promoted_mode
= promote_function_mode (passed_type
, passed_mode
, &unsignedp
,
2384 TREE_TYPE (current_function_decl
), 0);
2387 data
->nominal_type
= nominal_type
;
2388 data
->passed_type
= passed_type
;
2389 data
->nominal_mode
= nominal_mode
;
2390 data
->passed_mode
= passed_mode
;
2391 data
->promoted_mode
= promoted_mode
;
2394 /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
2397 assign_parms_setup_varargs (struct assign_parm_data_all
*all
,
2398 struct assign_parm_data_one
*data
, bool no_rtl
)
2400 int varargs_pretend_bytes
= 0;
2402 targetm
.calls
.setup_incoming_varargs (all
->args_so_far
,
2403 data
->promoted_mode
,
2405 &varargs_pretend_bytes
, no_rtl
);
2407 /* If the back-end has requested extra stack space, record how much is
2408 needed. Do not change pretend_args_size otherwise since it may be
2409 nonzero from an earlier partial argument. */
2410 if (varargs_pretend_bytes
> 0)
2411 all
->pretend_args_size
= varargs_pretend_bytes
;
2414 /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
2415 the incoming location of the current parameter. */
2418 assign_parm_find_entry_rtl (struct assign_parm_data_all
*all
,
2419 struct assign_parm_data_one
*data
)
2421 HOST_WIDE_INT pretend_bytes
= 0;
2425 if (data
->promoted_mode
== VOIDmode
)
2427 data
->entry_parm
= data
->stack_parm
= const0_rtx
;
2431 entry_parm
= targetm
.calls
.function_incoming_arg (all
->args_so_far
,
2432 data
->promoted_mode
,
2436 if (entry_parm
== 0)
2437 data
->promoted_mode
= data
->passed_mode
;
2439 /* Determine parm's home in the stack, in case it arrives in the stack
2440 or we should pretend it did. Compute the stack position and rtx where
2441 the argument arrives and its size.
2443 There is one complexity here: If this was a parameter that would
2444 have been passed in registers, but wasn't only because it is
2445 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
2446 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
2447 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
2448 as it was the previous time. */
2449 in_regs
= entry_parm
!= 0;
2450 #ifdef STACK_PARMS_IN_REG_PARM_AREA
2453 if (!in_regs
&& !data
->named_arg
)
2455 if (targetm
.calls
.pretend_outgoing_varargs_named (all
->args_so_far
))
2458 tem
= targetm
.calls
.function_incoming_arg (all
->args_so_far
,
2459 data
->promoted_mode
,
2460 data
->passed_type
, true);
2461 in_regs
= tem
!= NULL
;
2465 /* If this parameter was passed both in registers and in the stack, use
2466 the copy on the stack. */
2467 if (targetm
.calls
.must_pass_in_stack (data
->promoted_mode
,
2475 partial
= targetm
.calls
.arg_partial_bytes (all
->args_so_far
,
2476 data
->promoted_mode
,
2479 data
->partial
= partial
;
2481 /* The caller might already have allocated stack space for the
2482 register parameters. */
2483 if (partial
!= 0 && all
->reg_parm_stack_space
== 0)
2485 /* Part of this argument is passed in registers and part
2486 is passed on the stack. Ask the prologue code to extend
2487 the stack part so that we can recreate the full value.
2489 PRETEND_BYTES is the size of the registers we need to store.
2490 CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
2491 stack space that the prologue should allocate.
2493 Internally, gcc assumes that the argument pointer is aligned
2494 to STACK_BOUNDARY bits. This is used both for alignment
2495 optimizations (see init_emit) and to locate arguments that are
2496 aligned to more than PARM_BOUNDARY bits. We must preserve this
2497 invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
2498 a stack boundary. */
2500 /* We assume at most one partial arg, and it must be the first
2501 argument on the stack. */
2502 gcc_assert (!all
->extra_pretend_bytes
&& !all
->pretend_args_size
);
2504 pretend_bytes
= partial
;
2505 all
->pretend_args_size
= CEIL_ROUND (pretend_bytes
, STACK_BYTES
);
2507 /* We want to align relative to the actual stack pointer, so
2508 don't include this in the stack size until later. */
2509 all
->extra_pretend_bytes
= all
->pretend_args_size
;
2513 locate_and_pad_parm (data
->promoted_mode
, data
->passed_type
, in_regs
,
2514 entry_parm
? data
->partial
: 0, current_function_decl
,
2515 &all
->stack_args_size
, &data
->locate
);
2517 /* Update parm_stack_boundary if this parameter is passed in the
2519 if (!in_regs
&& crtl
->parm_stack_boundary
< data
->locate
.boundary
)
2520 crtl
->parm_stack_boundary
= data
->locate
.boundary
;
2522 /* Adjust offsets to include the pretend args. */
2523 pretend_bytes
= all
->extra_pretend_bytes
- pretend_bytes
;
2524 data
->locate
.slot_offset
.constant
+= pretend_bytes
;
2525 data
->locate
.offset
.constant
+= pretend_bytes
;
2527 data
->entry_parm
= entry_parm
;
2530 /* A subroutine of assign_parms. If there is actually space on the stack
2531 for this parm, count it in stack_args_size and return true. */
2534 assign_parm_is_stack_parm (struct assign_parm_data_all
*all
,
2535 struct assign_parm_data_one
*data
)
2537 /* Trivially true if we've no incoming register. */
2538 if (data
->entry_parm
== NULL
)
2540 /* Also true if we're partially in registers and partially not,
2541 since we've arranged to drop the entire argument on the stack. */
2542 else if (data
->partial
!= 0)
2544 /* Also true if the target says that it's passed in both registers
2545 and on the stack. */
2546 else if (GET_CODE (data
->entry_parm
) == PARALLEL
2547 && XEXP (XVECEXP (data
->entry_parm
, 0, 0), 0) == NULL_RTX
)
2549 /* Also true if the target says that there's stack allocated for
2550 all register parameters. */
2551 else if (all
->reg_parm_stack_space
> 0)
2553 /* Otherwise, no, this parameter has no ABI defined stack slot. */
2557 all
->stack_args_size
.constant
+= data
->locate
.size
.constant
;
2558 if (data
->locate
.size
.var
)
2559 ADD_PARM_SIZE (all
->stack_args_size
, data
->locate
.size
.var
);
2564 /* A subroutine of assign_parms. Given that this parameter is allocated
2565 stack space by the ABI, find it. */
2568 assign_parm_find_stack_rtl (tree parm
, struct assign_parm_data_one
*data
)
2570 rtx offset_rtx
, stack_parm
;
2571 unsigned int align
, boundary
;
2573 /* If we're passing this arg using a reg, make its stack home the
2574 aligned stack slot. */
2575 if (data
->entry_parm
)
2576 offset_rtx
= ARGS_SIZE_RTX (data
->locate
.slot_offset
);
2578 offset_rtx
= ARGS_SIZE_RTX (data
->locate
.offset
);
2580 stack_parm
= crtl
->args
.internal_arg_pointer
;
2581 if (offset_rtx
!= const0_rtx
)
2582 stack_parm
= gen_rtx_PLUS (Pmode
, stack_parm
, offset_rtx
);
2583 stack_parm
= gen_rtx_MEM (data
->promoted_mode
, stack_parm
);
2585 if (!data
->passed_pointer
)
2587 set_mem_attributes (stack_parm
, parm
, 1);
2588 /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
2589 while promoted mode's size is needed. */
2590 if (data
->promoted_mode
!= BLKmode
2591 && data
->promoted_mode
!= DECL_MODE (parm
))
2593 set_mem_size (stack_parm
, GET_MODE_SIZE (data
->promoted_mode
));
2594 if (MEM_EXPR (stack_parm
) && MEM_OFFSET_KNOWN_P (stack_parm
))
2596 int offset
= subreg_lowpart_offset (DECL_MODE (parm
),
2597 data
->promoted_mode
);
2599 set_mem_offset (stack_parm
, MEM_OFFSET (stack_parm
) - offset
);
2604 boundary
= data
->locate
.boundary
;
2605 align
= BITS_PER_UNIT
;
2607 /* If we're padding upward, we know that the alignment of the slot
2608 is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
2609 intentionally forcing upward padding. Otherwise we have to come
2610 up with a guess at the alignment based on OFFSET_RTX. */
2611 if (data
->locate
.where_pad
!= downward
|| data
->entry_parm
)
2613 else if (CONST_INT_P (offset_rtx
))
2615 align
= INTVAL (offset_rtx
) * BITS_PER_UNIT
| boundary
;
2616 align
= align
& -align
;
2618 set_mem_align (stack_parm
, align
);
2620 if (data
->entry_parm
)
2621 set_reg_attrs_for_parm (data
->entry_parm
, stack_parm
);
2623 data
->stack_parm
= stack_parm
;
2626 /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
2627 always valid and contiguous. */
2630 assign_parm_adjust_entry_rtl (struct assign_parm_data_one
*data
)
2632 rtx entry_parm
= data
->entry_parm
;
2633 rtx stack_parm
= data
->stack_parm
;
2635 /* If this parm was passed part in regs and part in memory, pretend it
2636 arrived entirely in memory by pushing the register-part onto the stack.
2637 In the special case of a DImode or DFmode that is split, we could put
2638 it together in a pseudoreg directly, but for now that's not worth
2640 if (data
->partial
!= 0)
2642 /* Handle calls that pass values in multiple non-contiguous
2643 locations. The Irix 6 ABI has examples of this. */
2644 if (GET_CODE (entry_parm
) == PARALLEL
)
2645 emit_group_store (validize_mem (stack_parm
), entry_parm
,
2647 int_size_in_bytes (data
->passed_type
));
2650 gcc_assert (data
->partial
% UNITS_PER_WORD
== 0);
2651 move_block_from_reg (REGNO (entry_parm
), validize_mem (stack_parm
),
2652 data
->partial
/ UNITS_PER_WORD
);
2655 entry_parm
= stack_parm
;
2658 /* If we didn't decide this parm came in a register, by default it came
2660 else if (entry_parm
== NULL
)
2661 entry_parm
= stack_parm
;
2663 /* When an argument is passed in multiple locations, we can't make use
2664 of this information, but we can save some copying if the whole argument
2665 is passed in a single register. */
2666 else if (GET_CODE (entry_parm
) == PARALLEL
2667 && data
->nominal_mode
!= BLKmode
2668 && data
->passed_mode
!= BLKmode
)
2670 size_t i
, len
= XVECLEN (entry_parm
, 0);
2672 for (i
= 0; i
< len
; i
++)
2673 if (XEXP (XVECEXP (entry_parm
, 0, i
), 0) != NULL_RTX
2674 && REG_P (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
2675 && (GET_MODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
2676 == data
->passed_mode
)
2677 && INTVAL (XEXP (XVECEXP (entry_parm
, 0, i
), 1)) == 0)
2679 entry_parm
= XEXP (XVECEXP (entry_parm
, 0, i
), 0);
2684 data
->entry_parm
= entry_parm
;
2687 /* A subroutine of assign_parms. Reconstitute any values which were
2688 passed in multiple registers and would fit in a single register. */
2691 assign_parm_remove_parallels (struct assign_parm_data_one
*data
)
2693 rtx entry_parm
= data
->entry_parm
;
2695 /* Convert the PARALLEL to a REG of the same mode as the parallel.
2696 This can be done with register operations rather than on the
2697 stack, even if we will store the reconstituted parameter on the
2699 if (GET_CODE (entry_parm
) == PARALLEL
&& GET_MODE (entry_parm
) != BLKmode
)
2701 rtx parmreg
= gen_reg_rtx (GET_MODE (entry_parm
));
2702 emit_group_store (parmreg
, entry_parm
, data
->passed_type
,
2703 GET_MODE_SIZE (GET_MODE (entry_parm
)));
2704 entry_parm
= parmreg
;
2707 data
->entry_parm
= entry_parm
;
2710 /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
2711 always valid and properly aligned. */
2714 assign_parm_adjust_stack_rtl (struct assign_parm_data_one
*data
)
2716 rtx stack_parm
= data
->stack_parm
;
2718 /* If we can't trust the parm stack slot to be aligned enough for its
2719 ultimate type, don't use that slot after entry. We'll make another
2720 stack slot, if we need one. */
2722 && ((STRICT_ALIGNMENT
2723 && GET_MODE_ALIGNMENT (data
->nominal_mode
) > MEM_ALIGN (stack_parm
))
2724 || (data
->nominal_type
2725 && TYPE_ALIGN (data
->nominal_type
) > MEM_ALIGN (stack_parm
)
2726 && MEM_ALIGN (stack_parm
) < PREFERRED_STACK_BOUNDARY
)))
2729 /* If parm was passed in memory, and we need to convert it on entry,
2730 don't store it back in that same slot. */
2731 else if (data
->entry_parm
== stack_parm
2732 && data
->nominal_mode
!= BLKmode
2733 && data
->nominal_mode
!= data
->passed_mode
)
2736 /* If stack protection is in effect for this function, don't leave any
2737 pointers in their passed stack slots. */
2738 else if (crtl
->stack_protect_guard
2739 && (flag_stack_protect
== 2
2740 || data
->passed_pointer
2741 || POINTER_TYPE_P (data
->nominal_type
)))
2744 data
->stack_parm
= stack_parm
;
2747 /* A subroutine of assign_parms. Return true if the current parameter
2748 should be stored as a BLKmode in the current frame. */
2751 assign_parm_setup_block_p (struct assign_parm_data_one
*data
)
2753 if (data
->nominal_mode
== BLKmode
)
2755 if (GET_MODE (data
->entry_parm
) == BLKmode
)
2758 #ifdef BLOCK_REG_PADDING
2759 /* Only assign_parm_setup_block knows how to deal with register arguments
2760 that are padded at the least significant end. */
2761 if (REG_P (data
->entry_parm
)
2762 && GET_MODE_SIZE (data
->promoted_mode
) < UNITS_PER_WORD
2763 && (BLOCK_REG_PADDING (data
->passed_mode
, data
->passed_type
, 1)
2764 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
2771 /* A subroutine of assign_parms. Arrange for the parameter to be
2772 present and valid in DATA->STACK_RTL. */
2775 assign_parm_setup_block (struct assign_parm_data_all
*all
,
2776 tree parm
, struct assign_parm_data_one
*data
)
2778 rtx entry_parm
= data
->entry_parm
;
2779 rtx stack_parm
= data
->stack_parm
;
2781 HOST_WIDE_INT size_stored
;
2783 if (GET_CODE (entry_parm
) == PARALLEL
)
2784 entry_parm
= emit_group_move_into_temps (entry_parm
);
2786 size
= int_size_in_bytes (data
->passed_type
);
2787 size_stored
= CEIL_ROUND (size
, UNITS_PER_WORD
);
2788 if (stack_parm
== 0)
2790 DECL_ALIGN (parm
) = MAX (DECL_ALIGN (parm
), BITS_PER_WORD
);
2791 stack_parm
= assign_stack_local (BLKmode
, size_stored
,
2793 if (GET_MODE_SIZE (GET_MODE (entry_parm
)) == size
)
2794 PUT_MODE (stack_parm
, GET_MODE (entry_parm
));
2795 set_mem_attributes (stack_parm
, parm
, 1);
2798 /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
2799 calls that pass values in multiple non-contiguous locations. */
2800 if (REG_P (entry_parm
) || GET_CODE (entry_parm
) == PARALLEL
)
2804 /* Note that we will be storing an integral number of words.
2805 So we have to be careful to ensure that we allocate an
2806 integral number of words. We do this above when we call
2807 assign_stack_local if space was not allocated in the argument
2808 list. If it was, this will not work if PARM_BOUNDARY is not
2809 a multiple of BITS_PER_WORD. It isn't clear how to fix this
2810 if it becomes a problem. Exception is when BLKmode arrives
2811 with arguments not conforming to word_mode. */
2813 if (data
->stack_parm
== 0)
2815 else if (GET_CODE (entry_parm
) == PARALLEL
)
2818 gcc_assert (!size
|| !(PARM_BOUNDARY
% BITS_PER_WORD
));
2820 mem
= validize_mem (stack_parm
);
2822 /* Handle values in multiple non-contiguous locations. */
2823 if (GET_CODE (entry_parm
) == PARALLEL
)
2825 push_to_sequence2 (all
->first_conversion_insn
,
2826 all
->last_conversion_insn
);
2827 emit_group_store (mem
, entry_parm
, data
->passed_type
, size
);
2828 all
->first_conversion_insn
= get_insns ();
2829 all
->last_conversion_insn
= get_last_insn ();
2836 /* If SIZE is that of a mode no bigger than a word, just use
2837 that mode's store operation. */
2838 else if (size
<= UNITS_PER_WORD
)
2840 enum machine_mode mode
2841 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2844 #ifdef BLOCK_REG_PADDING
2845 && (size
== UNITS_PER_WORD
2846 || (BLOCK_REG_PADDING (mode
, data
->passed_type
, 1)
2847 != (BYTES_BIG_ENDIAN
? upward
: downward
)))
2853 /* We are really truncating a word_mode value containing
2854 SIZE bytes into a value of mode MODE. If such an
2855 operation requires no actual instructions, we can refer
2856 to the value directly in mode MODE, otherwise we must
2857 start with the register in word_mode and explicitly
2859 if (TRULY_NOOP_TRUNCATION (size
* BITS_PER_UNIT
, BITS_PER_WORD
))
2860 reg
= gen_rtx_REG (mode
, REGNO (entry_parm
));
2863 reg
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
2864 reg
= convert_to_mode (mode
, copy_to_reg (reg
), 1);
2866 emit_move_insn (change_address (mem
, mode
, 0), reg
);
2869 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
2870 machine must be aligned to the left before storing
2871 to memory. Note that the previous test doesn't
2872 handle all cases (e.g. SIZE == 3). */
2873 else if (size
!= UNITS_PER_WORD
2874 #ifdef BLOCK_REG_PADDING
2875 && (BLOCK_REG_PADDING (mode
, data
->passed_type
, 1)
2883 int by
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
2884 rtx reg
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
2886 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, by
, NULL_RTX
, 1);
2887 tem
= change_address (mem
, word_mode
, 0);
2888 emit_move_insn (tem
, x
);
2891 move_block_from_reg (REGNO (entry_parm
), mem
,
2892 size_stored
/ UNITS_PER_WORD
);
2895 move_block_from_reg (REGNO (entry_parm
), mem
,
2896 size_stored
/ UNITS_PER_WORD
);
2898 else if (data
->stack_parm
== 0)
2900 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
2901 emit_block_move (stack_parm
, data
->entry_parm
, GEN_INT (size
),
2903 all
->first_conversion_insn
= get_insns ();
2904 all
->last_conversion_insn
= get_last_insn ();
2908 data
->stack_parm
= stack_parm
;
2909 SET_DECL_RTL (parm
, stack_parm
);
2912 /* A subroutine of assign_parms. Allocate a pseudo to hold the current
2913 parameter. Get it there. Perform all ABI specified conversions. */
2916 assign_parm_setup_reg (struct assign_parm_data_all
*all
, tree parm
,
2917 struct assign_parm_data_one
*data
)
2919 rtx parmreg
, validated_mem
;
2920 rtx equiv_stack_parm
;
2921 enum machine_mode promoted_nominal_mode
;
2922 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (parm
));
2923 bool did_conversion
= false;
2924 bool need_conversion
, moved
;
2926 /* Store the parm in a pseudoregister during the function, but we may
2927 need to do it in a wider mode. Using 2 here makes the result
2928 consistent with promote_decl_mode and thus expand_expr_real_1. */
2929 promoted_nominal_mode
2930 = promote_function_mode (data
->nominal_type
, data
->nominal_mode
, &unsignedp
,
2931 TREE_TYPE (current_function_decl
), 2);
2933 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
2935 if (!DECL_ARTIFICIAL (parm
))
2936 mark_user_reg (parmreg
);
2938 /* If this was an item that we received a pointer to,
2939 set DECL_RTL appropriately. */
2940 if (data
->passed_pointer
)
2942 rtx x
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data
->passed_type
)), parmreg
);
2943 set_mem_attributes (x
, parm
, 1);
2944 SET_DECL_RTL (parm
, x
);
2947 SET_DECL_RTL (parm
, parmreg
);
2949 assign_parm_remove_parallels (data
);
2951 /* Copy the value into the register, thus bridging between
2952 assign_parm_find_data_types and expand_expr_real_1. */
2954 equiv_stack_parm
= data
->stack_parm
;
2955 validated_mem
= validize_mem (data
->entry_parm
);
2957 need_conversion
= (data
->nominal_mode
!= data
->passed_mode
2958 || promoted_nominal_mode
!= data
->promoted_mode
);
2962 && GET_MODE_CLASS (data
->nominal_mode
) == MODE_INT
2963 && data
->nominal_mode
== data
->passed_mode
2964 && data
->nominal_mode
== GET_MODE (data
->entry_parm
))
2966 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
2967 mode, by the caller. We now have to convert it to
2968 NOMINAL_MODE, if different. However, PARMREG may be in
2969 a different mode than NOMINAL_MODE if it is being stored
2972 If ENTRY_PARM is a hard register, it might be in a register
2973 not valid for operating in its mode (e.g., an odd-numbered
2974 register for a DFmode). In that case, moves are the only
2975 thing valid, so we can't do a convert from there. This
2976 occurs when the calling sequence allow such misaligned
2979 In addition, the conversion may involve a call, which could
2980 clobber parameters which haven't been copied to pseudo
2983 First, we try to emit an insn which performs the necessary
2984 conversion. We verify that this insn does not clobber any
2987 enum insn_code icode
;
2990 icode
= can_extend_p (promoted_nominal_mode
, data
->passed_mode
,
2994 op1
= validated_mem
;
2995 if (icode
!= CODE_FOR_nothing
2996 && insn_operand_matches (icode
, 0, op0
)
2997 && insn_operand_matches (icode
, 1, op1
))
2999 enum rtx_code code
= unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
;
3001 HARD_REG_SET hardregs
;
3004 insn
= gen_extend_insn (op0
, op1
, promoted_nominal_mode
,
3005 data
->passed_mode
, unsignedp
);
3007 insns
= get_insns ();
3010 CLEAR_HARD_REG_SET (hardregs
);
3011 for (insn
= insns
; insn
&& moved
; insn
= NEXT_INSN (insn
))
3014 note_stores (PATTERN (insn
), record_hard_reg_sets
,
3016 if (!hard_reg_set_empty_p (hardregs
))
3025 if (equiv_stack_parm
!= NULL_RTX
)
3026 equiv_stack_parm
= gen_rtx_fmt_e (code
, GET_MODE (parmreg
),
3033 /* Nothing to do. */
3035 else if (need_conversion
)
3037 /* We did not have an insn to convert directly, or the sequence
3038 generated appeared unsafe. We must first copy the parm to a
3039 pseudo reg, and save the conversion until after all
3040 parameters have been moved. */
3043 rtx tempreg
= gen_reg_rtx (GET_MODE (data
->entry_parm
));
3045 emit_move_insn (tempreg
, validated_mem
);
3047 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3048 tempreg
= convert_to_mode (data
->nominal_mode
, tempreg
, unsignedp
);
3050 if (GET_CODE (tempreg
) == SUBREG
3051 && GET_MODE (tempreg
) == data
->nominal_mode
3052 && REG_P (SUBREG_REG (tempreg
))
3053 && data
->nominal_mode
== data
->passed_mode
3054 && GET_MODE (SUBREG_REG (tempreg
)) == GET_MODE (data
->entry_parm
)
3055 && GET_MODE_SIZE (GET_MODE (tempreg
))
3056 < GET_MODE_SIZE (GET_MODE (data
->entry_parm
)))
3058 /* The argument is already sign/zero extended, so note it
3060 SUBREG_PROMOTED_VAR_P (tempreg
) = 1;
3061 SUBREG_PROMOTED_UNSIGNED_SET (tempreg
, unsignedp
);
3064 /* TREE_USED gets set erroneously during expand_assignment. */
3065 save_tree_used
= TREE_USED (parm
);
3066 expand_assignment (parm
, make_tree (data
->nominal_type
, tempreg
), false);
3067 TREE_USED (parm
) = save_tree_used
;
3068 all
->first_conversion_insn
= get_insns ();
3069 all
->last_conversion_insn
= get_last_insn ();
3072 did_conversion
= true;
3075 emit_move_insn (parmreg
, validated_mem
);
3077 /* If we were passed a pointer but the actual value can safely live
3078 in a register, put it in one. */
3079 if (data
->passed_pointer
3080 && TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
3081 /* If by-reference argument was promoted, demote it. */
3082 && (TYPE_MODE (TREE_TYPE (parm
)) != GET_MODE (DECL_RTL (parm
))
3083 || use_register_for_decl (parm
)))
3085 /* We can't use nominal_mode, because it will have been set to
3086 Pmode above. We must use the actual mode of the parm. */
3087 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
3088 mark_user_reg (parmreg
);
3090 if (GET_MODE (parmreg
) != GET_MODE (DECL_RTL (parm
)))
3092 rtx tempreg
= gen_reg_rtx (GET_MODE (DECL_RTL (parm
)));
3093 int unsigned_p
= TYPE_UNSIGNED (TREE_TYPE (parm
));
3095 push_to_sequence2 (all
->first_conversion_insn
,
3096 all
->last_conversion_insn
);
3097 emit_move_insn (tempreg
, DECL_RTL (parm
));
3098 tempreg
= convert_to_mode (GET_MODE (parmreg
), tempreg
, unsigned_p
);
3099 emit_move_insn (parmreg
, tempreg
);
3100 all
->first_conversion_insn
= get_insns ();
3101 all
->last_conversion_insn
= get_last_insn ();
3104 did_conversion
= true;
3107 emit_move_insn (parmreg
, DECL_RTL (parm
));
3109 SET_DECL_RTL (parm
, parmreg
);
3111 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3113 data
->stack_parm
= NULL
;
3116 /* Mark the register as eliminable if we did no conversion and it was
3117 copied from memory at a fixed offset, and the arg pointer was not
3118 copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
3119 offset formed an invalid address, such memory-equivalences as we
3120 make here would screw up life analysis for it. */
3121 if (data
->nominal_mode
== data
->passed_mode
3123 && data
->stack_parm
!= 0
3124 && MEM_P (data
->stack_parm
)
3125 && data
->locate
.offset
.var
== 0
3126 && reg_mentioned_p (virtual_incoming_args_rtx
,
3127 XEXP (data
->stack_parm
, 0)))
3129 rtx linsn
= get_last_insn ();
3132 /* Mark complex types separately. */
3133 if (GET_CODE (parmreg
) == CONCAT
)
3135 enum machine_mode submode
3136 = GET_MODE_INNER (GET_MODE (parmreg
));
3137 int regnor
= REGNO (XEXP (parmreg
, 0));
3138 int regnoi
= REGNO (XEXP (parmreg
, 1));
3139 rtx stackr
= adjust_address_nv (data
->stack_parm
, submode
, 0);
3140 rtx stacki
= adjust_address_nv (data
->stack_parm
, submode
,
3141 GET_MODE_SIZE (submode
));
3143 /* Scan backwards for the set of the real and
3145 for (sinsn
= linsn
; sinsn
!= 0;
3146 sinsn
= prev_nonnote_insn (sinsn
))
3148 set
= single_set (sinsn
);
3152 if (SET_DEST (set
) == regno_reg_rtx
[regnoi
])
3153 set_unique_reg_note (sinsn
, REG_EQUIV
, stacki
);
3154 else if (SET_DEST (set
) == regno_reg_rtx
[regnor
])
3155 set_unique_reg_note (sinsn
, REG_EQUIV
, stackr
);
3159 set_dst_reg_note (linsn
, REG_EQUIV
, equiv_stack_parm
, parmreg
);
3162 /* For pointer data type, suggest pointer register. */
3163 if (POINTER_TYPE_P (TREE_TYPE (parm
)))
3164 mark_reg_pointer (parmreg
,
3165 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
3168 /* A subroutine of assign_parms. Allocate stack space to hold the current
3169 parameter. Get it there. Perform all ABI specified conversions. */
3172 assign_parm_setup_stack (struct assign_parm_data_all
*all
, tree parm
,
3173 struct assign_parm_data_one
*data
)
3175 /* Value must be stored in the stack slot STACK_PARM during function
3177 bool to_conversion
= false;
3179 assign_parm_remove_parallels (data
);
3181 if (data
->promoted_mode
!= data
->nominal_mode
)
3183 /* Conversion is required. */
3184 rtx tempreg
= gen_reg_rtx (GET_MODE (data
->entry_parm
));
3186 emit_move_insn (tempreg
, validize_mem (data
->entry_parm
));
3188 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3189 to_conversion
= true;
3191 data
->entry_parm
= convert_to_mode (data
->nominal_mode
, tempreg
,
3192 TYPE_UNSIGNED (TREE_TYPE (parm
)));
3194 if (data
->stack_parm
)
3196 int offset
= subreg_lowpart_offset (data
->nominal_mode
,
3197 GET_MODE (data
->stack_parm
));
3198 /* ??? This may need a big-endian conversion on sparc64. */
3200 = adjust_address (data
->stack_parm
, data
->nominal_mode
, 0);
3201 if (offset
&& MEM_OFFSET_KNOWN_P (data
->stack_parm
))
3202 set_mem_offset (data
->stack_parm
,
3203 MEM_OFFSET (data
->stack_parm
) + offset
);
3207 if (data
->entry_parm
!= data
->stack_parm
)
3211 if (data
->stack_parm
== 0)
3213 int align
= STACK_SLOT_ALIGNMENT (data
->passed_type
,
3214 GET_MODE (data
->entry_parm
),
3215 TYPE_ALIGN (data
->passed_type
));
3217 = assign_stack_local (GET_MODE (data
->entry_parm
),
3218 GET_MODE_SIZE (GET_MODE (data
->entry_parm
)),
3220 set_mem_attributes (data
->stack_parm
, parm
, 1);
3223 dest
= validize_mem (data
->stack_parm
);
3224 src
= validize_mem (data
->entry_parm
);
3228 /* Use a block move to handle potentially misaligned entry_parm. */
3230 push_to_sequence2 (all
->first_conversion_insn
,
3231 all
->last_conversion_insn
);
3232 to_conversion
= true;
3234 emit_block_move (dest
, src
,
3235 GEN_INT (int_size_in_bytes (data
->passed_type
)),
3239 emit_move_insn (dest
, src
);
3244 all
->first_conversion_insn
= get_insns ();
3245 all
->last_conversion_insn
= get_last_insn ();
3249 SET_DECL_RTL (parm
, data
->stack_parm
);
3252 /* A subroutine of assign_parms. If the ABI splits complex arguments, then
3253 undo the frobbing that we did in assign_parms_augmented_arg_list. */
3256 assign_parms_unsplit_complex (struct assign_parm_data_all
*all
,
3257 VEC(tree
, heap
) *fnargs
)
3260 tree orig_fnargs
= all
->orig_fnargs
;
3263 for (parm
= orig_fnargs
; parm
; parm
= TREE_CHAIN (parm
), ++i
)
3265 if (TREE_CODE (TREE_TYPE (parm
)) == COMPLEX_TYPE
3266 && targetm
.calls
.split_complex_arg (TREE_TYPE (parm
)))
3268 rtx tmp
, real
, imag
;
3269 enum machine_mode inner
= GET_MODE_INNER (DECL_MODE (parm
));
3271 real
= DECL_RTL (VEC_index (tree
, fnargs
, i
));
3272 imag
= DECL_RTL (VEC_index (tree
, fnargs
, i
+ 1));
3273 if (inner
!= GET_MODE (real
))
3275 real
= gen_lowpart_SUBREG (inner
, real
);
3276 imag
= gen_lowpart_SUBREG (inner
, imag
);
3279 if (TREE_ADDRESSABLE (parm
))
3282 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (parm
));
3283 int align
= STACK_SLOT_ALIGNMENT (TREE_TYPE (parm
),
3285 TYPE_ALIGN (TREE_TYPE (parm
)));
3287 /* split_complex_arg put the real and imag parts in
3288 pseudos. Move them to memory. */
3289 tmp
= assign_stack_local (DECL_MODE (parm
), size
, align
);
3290 set_mem_attributes (tmp
, parm
, 1);
3291 rmem
= adjust_address_nv (tmp
, inner
, 0);
3292 imem
= adjust_address_nv (tmp
, inner
, GET_MODE_SIZE (inner
));
3293 push_to_sequence2 (all
->first_conversion_insn
,
3294 all
->last_conversion_insn
);
3295 emit_move_insn (rmem
, real
);
3296 emit_move_insn (imem
, imag
);
3297 all
->first_conversion_insn
= get_insns ();
3298 all
->last_conversion_insn
= get_last_insn ();
3302 tmp
= gen_rtx_CONCAT (DECL_MODE (parm
), real
, imag
);
3303 SET_DECL_RTL (parm
, tmp
);
3305 real
= DECL_INCOMING_RTL (VEC_index (tree
, fnargs
, i
));
3306 imag
= DECL_INCOMING_RTL (VEC_index (tree
, fnargs
, i
+ 1));
3307 if (inner
!= GET_MODE (real
))
3309 real
= gen_lowpart_SUBREG (inner
, real
);
3310 imag
= gen_lowpart_SUBREG (inner
, imag
);
3312 tmp
= gen_rtx_CONCAT (DECL_MODE (parm
), real
, imag
);
3313 set_decl_incoming_rtl (parm
, tmp
, false);
3319 /* Assign RTL expressions to the function's parameters. This may involve
3320 copying them into registers and using those registers as the DECL_RTL. */
3323 assign_parms (tree fndecl
)
3325 struct assign_parm_data_all all
;
3327 VEC(tree
, heap
) *fnargs
;
3330 crtl
->args
.internal_arg_pointer
3331 = targetm
.calls
.internal_arg_pointer ();
3333 assign_parms_initialize_all (&all
);
3334 fnargs
= assign_parms_augmented_arg_list (&all
);
3336 FOR_EACH_VEC_ELT (tree
, fnargs
, i
, parm
)
3338 struct assign_parm_data_one data
;
3340 /* Extract the type of PARM; adjust it according to ABI. */
3341 assign_parm_find_data_types (&all
, parm
, &data
);
3343 /* Early out for errors and void parameters. */
3344 if (data
.passed_mode
== VOIDmode
)
3346 SET_DECL_RTL (parm
, const0_rtx
);
3347 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
3351 /* Estimate stack alignment from parameter alignment. */
3352 if (SUPPORTS_STACK_ALIGNMENT
)
3355 = targetm
.calls
.function_arg_boundary (data
.promoted_mode
,
3357 align
= MINIMUM_ALIGNMENT (data
.passed_type
, data
.promoted_mode
,
3359 if (TYPE_ALIGN (data
.nominal_type
) > align
)
3360 align
= MINIMUM_ALIGNMENT (data
.nominal_type
,
3361 TYPE_MODE (data
.nominal_type
),
3362 TYPE_ALIGN (data
.nominal_type
));
3363 if (crtl
->stack_alignment_estimated
< align
)
3365 gcc_assert (!crtl
->stack_realign_processed
);
3366 crtl
->stack_alignment_estimated
= align
;
3370 if (cfun
->stdarg
&& !DECL_CHAIN (parm
))
3371 assign_parms_setup_varargs (&all
, &data
, false);
3373 /* Find out where the parameter arrives in this function. */
3374 assign_parm_find_entry_rtl (&all
, &data
);
3376 /* Find out where stack space for this parameter might be. */
3377 if (assign_parm_is_stack_parm (&all
, &data
))
3379 assign_parm_find_stack_rtl (parm
, &data
);
3380 assign_parm_adjust_entry_rtl (&data
);
3383 /* Record permanently how this parm was passed. */
3384 if (data
.passed_pointer
)
3387 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data
.passed_type
)),
3389 set_decl_incoming_rtl (parm
, incoming_rtl
, true);
3392 set_decl_incoming_rtl (parm
, data
.entry_parm
, false);
3394 /* Update info on where next arg arrives in registers. */
3395 targetm
.calls
.function_arg_advance (all
.args_so_far
, data
.promoted_mode
,
3396 data
.passed_type
, data
.named_arg
);
3398 assign_parm_adjust_stack_rtl (&data
);
3400 if (assign_parm_setup_block_p (&data
))
3401 assign_parm_setup_block (&all
, parm
, &data
);
3402 else if (data
.passed_pointer
|| use_register_for_decl (parm
))
3403 assign_parm_setup_reg (&all
, parm
, &data
);
3405 assign_parm_setup_stack (&all
, parm
, &data
);
3408 if (targetm
.calls
.split_complex_arg
)
3409 assign_parms_unsplit_complex (&all
, fnargs
);
3411 VEC_free (tree
, heap
, fnargs
);
3413 /* Output all parameter conversion instructions (possibly including calls)
3414 now that all parameters have been copied out of hard registers. */
3415 emit_insn (all
.first_conversion_insn
);
3417 /* Estimate reload stack alignment from scalar return mode. */
3418 if (SUPPORTS_STACK_ALIGNMENT
)
3420 if (DECL_RESULT (fndecl
))
3422 tree type
= TREE_TYPE (DECL_RESULT (fndecl
));
3423 enum machine_mode mode
= TYPE_MODE (type
);
3427 && !AGGREGATE_TYPE_P (type
))
3429 unsigned int align
= GET_MODE_ALIGNMENT (mode
);
3430 if (crtl
->stack_alignment_estimated
< align
)
3432 gcc_assert (!crtl
->stack_realign_processed
);
3433 crtl
->stack_alignment_estimated
= align
;
3439 /* If we are receiving a struct value address as the first argument, set up
3440 the RTL for the function result. As this might require code to convert
3441 the transmitted address to Pmode, we do this here to ensure that possible
3442 preliminary conversions of the address have been emitted already. */
3443 if (all
.function_result_decl
)
3445 tree result
= DECL_RESULT (current_function_decl
);
3446 rtx addr
= DECL_RTL (all
.function_result_decl
);
3449 if (DECL_BY_REFERENCE (result
))
3451 SET_DECL_VALUE_EXPR (result
, all
.function_result_decl
);
3456 SET_DECL_VALUE_EXPR (result
,
3457 build1 (INDIRECT_REF
, TREE_TYPE (result
),
3458 all
.function_result_decl
));
3459 addr
= convert_memory_address (Pmode
, addr
);
3460 x
= gen_rtx_MEM (DECL_MODE (result
), addr
);
3461 set_mem_attributes (x
, result
, 1);
3464 DECL_HAS_VALUE_EXPR_P (result
) = 1;
3466 SET_DECL_RTL (result
, x
);
3469 /* We have aligned all the args, so add space for the pretend args. */
3470 crtl
->args
.pretend_args_size
= all
.pretend_args_size
;
3471 all
.stack_args_size
.constant
+= all
.extra_pretend_bytes
;
3472 crtl
->args
.size
= all
.stack_args_size
.constant
;
3474 /* Adjust function incoming argument size for alignment and
3477 #ifdef REG_PARM_STACK_SPACE
3478 crtl
->args
.size
= MAX (crtl
->args
.size
,
3479 REG_PARM_STACK_SPACE (fndecl
));
3482 crtl
->args
.size
= CEIL_ROUND (crtl
->args
.size
,
3483 PARM_BOUNDARY
/ BITS_PER_UNIT
);
3485 #ifdef ARGS_GROW_DOWNWARD
3486 crtl
->args
.arg_offset_rtx
3487 = (all
.stack_args_size
.var
== 0 ? GEN_INT (-all
.stack_args_size
.constant
)
3488 : expand_expr (size_diffop (all
.stack_args_size
.var
,
3489 size_int (-all
.stack_args_size
.constant
)),
3490 NULL_RTX
, VOIDmode
, EXPAND_NORMAL
));
3492 crtl
->args
.arg_offset_rtx
= ARGS_SIZE_RTX (all
.stack_args_size
);
3495 /* See how many bytes, if any, of its args a function should try to pop
3498 crtl
->args
.pops_args
= targetm
.calls
.return_pops_args (fndecl
,
3502 /* For stdarg.h function, save info about
3503 regs and stack space used by the named args. */
3505 crtl
->args
.info
= all
.args_so_far_v
;
3507 /* Set the rtx used for the function return value. Put this in its
3508 own variable so any optimizers that need this information don't have
3509 to include tree.h. Do this here so it gets done when an inlined
3510 function gets output. */
3513 = (DECL_RTL_SET_P (DECL_RESULT (fndecl
))
3514 ? DECL_RTL (DECL_RESULT (fndecl
)) : NULL_RTX
);
3516 /* If scalar return value was computed in a pseudo-reg, or was a named
3517 return value that got dumped to the stack, copy that to the hard
3519 if (DECL_RTL_SET_P (DECL_RESULT (fndecl
)))
3521 tree decl_result
= DECL_RESULT (fndecl
);
3522 rtx decl_rtl
= DECL_RTL (decl_result
);
3524 if (REG_P (decl_rtl
)
3525 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
3526 : DECL_REGISTER (decl_result
))
3530 real_decl_rtl
= targetm
.calls
.function_value (TREE_TYPE (decl_result
),
3532 REG_FUNCTION_VALUE_P (real_decl_rtl
) = 1;
3533 /* The delay slot scheduler assumes that crtl->return_rtx
3534 holds the hard register containing the return value, not a
3535 temporary pseudo. */
3536 crtl
->return_rtx
= real_decl_rtl
;
3541 /* A subroutine of gimplify_parameters, invoked via walk_tree.
3542 For all seen types, gimplify their sizes. */
3545 gimplify_parm_type (tree
*tp
, int *walk_subtrees
, void *data
)
3552 if (POINTER_TYPE_P (t
))
3554 else if (TYPE_SIZE (t
) && !TREE_CONSTANT (TYPE_SIZE (t
))
3555 && !TYPE_SIZES_GIMPLIFIED (t
))
3557 gimplify_type_sizes (t
, (gimple_seq
*) data
);
3565 /* Gimplify the parameter list for current_function_decl. This involves
3566 evaluating SAVE_EXPRs of variable sized parameters and generating code
3567 to implement callee-copies reference parameters. Returns a sequence of
3568 statements to add to the beginning of the function. */
3571 gimplify_parameters (void)
3573 struct assign_parm_data_all all
;
3575 gimple_seq stmts
= NULL
;
3576 VEC(tree
, heap
) *fnargs
;
3579 assign_parms_initialize_all (&all
);
3580 fnargs
= assign_parms_augmented_arg_list (&all
);
3582 FOR_EACH_VEC_ELT (tree
, fnargs
, i
, parm
)
3584 struct assign_parm_data_one data
;
3586 /* Extract the type of PARM; adjust it according to ABI. */
3587 assign_parm_find_data_types (&all
, parm
, &data
);
3589 /* Early out for errors and void parameters. */
3590 if (data
.passed_mode
== VOIDmode
|| DECL_SIZE (parm
) == NULL
)
3593 /* Update info on where next arg arrives in registers. */
3594 targetm
.calls
.function_arg_advance (all
.args_so_far
, data
.promoted_mode
,
3595 data
.passed_type
, data
.named_arg
);
3597 /* ??? Once upon a time variable_size stuffed parameter list
3598 SAVE_EXPRs (amongst others) onto a pending sizes list. This
3599 turned out to be less than manageable in the gimple world.
3600 Now we have to hunt them down ourselves. */
3601 walk_tree_without_duplicates (&data
.passed_type
,
3602 gimplify_parm_type
, &stmts
);
3604 if (TREE_CODE (DECL_SIZE_UNIT (parm
)) != INTEGER_CST
)
3606 gimplify_one_sizepos (&DECL_SIZE (parm
), &stmts
);
3607 gimplify_one_sizepos (&DECL_SIZE_UNIT (parm
), &stmts
);
3610 if (data
.passed_pointer
)
3612 tree type
= TREE_TYPE (data
.passed_type
);
3613 if (reference_callee_copied (&all
.args_so_far_v
, TYPE_MODE (type
),
3614 type
, data
.named_arg
))
3618 /* For constant-sized objects, this is trivial; for
3619 variable-sized objects, we have to play games. */
3620 if (TREE_CODE (DECL_SIZE_UNIT (parm
)) == INTEGER_CST
3621 && !(flag_stack_check
== GENERIC_STACK_CHECK
3622 && compare_tree_int (DECL_SIZE_UNIT (parm
),
3623 STACK_CHECK_MAX_VAR_SIZE
) > 0))
3625 local
= create_tmp_var (type
, get_name (parm
));
3626 DECL_IGNORED_P (local
) = 0;
3627 /* If PARM was addressable, move that flag over
3628 to the local copy, as its address will be taken,
3629 not the PARMs. Keep the parms address taken
3630 as we'll query that flag during gimplification. */
3631 if (TREE_ADDRESSABLE (parm
))
3632 TREE_ADDRESSABLE (local
) = 1;
3633 else if (TREE_CODE (type
) == COMPLEX_TYPE
3634 || TREE_CODE (type
) == VECTOR_TYPE
)
3635 DECL_GIMPLE_REG_P (local
) = 1;
3639 tree ptr_type
, addr
;
3641 ptr_type
= build_pointer_type (type
);
3642 addr
= create_tmp_reg (ptr_type
, get_name (parm
));
3643 DECL_IGNORED_P (addr
) = 0;
3644 local
= build_fold_indirect_ref (addr
);
3646 t
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
3647 t
= build_call_expr (t
, 2, DECL_SIZE_UNIT (parm
),
3648 size_int (DECL_ALIGN (parm
)));
3650 /* The call has been built for a variable-sized object. */
3651 CALL_ALLOCA_FOR_VAR_P (t
) = 1;
3652 t
= fold_convert (ptr_type
, t
);
3653 t
= build2 (MODIFY_EXPR
, TREE_TYPE (addr
), addr
, t
);
3654 gimplify_and_add (t
, &stmts
);
3657 gimplify_assign (local
, parm
, &stmts
);
3659 SET_DECL_VALUE_EXPR (parm
, local
);
3660 DECL_HAS_VALUE_EXPR_P (parm
) = 1;
3665 VEC_free (tree
, heap
, fnargs
);
3670 /* Compute the size and offset from the start of the stacked arguments for a
3671 parm passed in mode PASSED_MODE and with type TYPE.
3673 INITIAL_OFFSET_PTR points to the current offset into the stacked
3676 The starting offset and size for this parm are returned in
3677 LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
3678 nonzero, the offset is that of stack slot, which is returned in
3679 LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
3680 padding required from the initial offset ptr to the stack slot.
3682 IN_REGS is nonzero if the argument will be passed in registers. It will
3683 never be set if REG_PARM_STACK_SPACE is not defined.
3685 FNDECL is the function in which the argument was defined.
3687 There are two types of rounding that are done. The first, controlled by
3688 TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the
3689 argument list to be aligned to the specific boundary (in bits). This
3690 rounding affects the initial and starting offsets, but not the argument
3693 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3694 optionally rounds the size of the parm to PARM_BOUNDARY. The
3695 initial offset is not affected by this rounding, while the size always
3696 is and the starting offset may be. */
3698 /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
3699 INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
3700 callers pass in the total size of args so far as
3701 INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
3704 locate_and_pad_parm (enum machine_mode passed_mode
, tree type
, int in_regs
,
3705 int partial
, tree fndecl ATTRIBUTE_UNUSED
,
3706 struct args_size
*initial_offset_ptr
,
3707 struct locate_and_pad_arg_data
*locate
)
3710 enum direction where_pad
;
3711 unsigned int boundary
, round_boundary
;
3712 int reg_parm_stack_space
= 0;
3713 int part_size_in_regs
;
3715 #ifdef REG_PARM_STACK_SPACE
3716 reg_parm_stack_space
= REG_PARM_STACK_SPACE (fndecl
);
3718 /* If we have found a stack parm before we reach the end of the
3719 area reserved for registers, skip that area. */
3722 if (reg_parm_stack_space
> 0)
3724 if (initial_offset_ptr
->var
)
3726 initial_offset_ptr
->var
3727 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
3728 ssize_int (reg_parm_stack_space
));
3729 initial_offset_ptr
->constant
= 0;
3731 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
3732 initial_offset_ptr
->constant
= reg_parm_stack_space
;
3735 #endif /* REG_PARM_STACK_SPACE */
3737 part_size_in_regs
= (reg_parm_stack_space
== 0 ? partial
: 0);
3740 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
3741 where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
3742 boundary
= targetm
.calls
.function_arg_boundary (passed_mode
, type
);
3743 round_boundary
= targetm
.calls
.function_arg_round_boundary (passed_mode
,
3745 locate
->where_pad
= where_pad
;
3747 /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */
3748 if (boundary
> MAX_SUPPORTED_STACK_ALIGNMENT
)
3749 boundary
= MAX_SUPPORTED_STACK_ALIGNMENT
;
3751 locate
->boundary
= boundary
;
3753 if (SUPPORTS_STACK_ALIGNMENT
)
3755 /* stack_alignment_estimated can't change after stack has been
3757 if (crtl
->stack_alignment_estimated
< boundary
)
3759 if (!crtl
->stack_realign_processed
)
3760 crtl
->stack_alignment_estimated
= boundary
;
3763 /* If stack is realigned and stack alignment value
3764 hasn't been finalized, it is OK not to increase
3765 stack_alignment_estimated. The bigger alignment
3766 requirement is recorded in stack_alignment_needed
3768 gcc_assert (!crtl
->stack_realign_finalized
3769 && crtl
->stack_realign_needed
);
3774 /* Remember if the outgoing parameter requires extra alignment on the
3775 calling function side. */
3776 if (crtl
->stack_alignment_needed
< boundary
)
3777 crtl
->stack_alignment_needed
= boundary
;
3778 if (crtl
->preferred_stack_boundary
< boundary
)
3779 crtl
->preferred_stack_boundary
= boundary
;
3781 #ifdef ARGS_GROW_DOWNWARD
3782 locate
->slot_offset
.constant
= -initial_offset_ptr
->constant
;
3783 if (initial_offset_ptr
->var
)
3784 locate
->slot_offset
.var
= size_binop (MINUS_EXPR
, ssize_int (0),
3785 initial_offset_ptr
->var
);
3789 if (where_pad
!= none
3790 && (!host_integerp (sizetree
, 1)
3791 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % round_boundary
))
3792 s2
= round_up (s2
, round_boundary
/ BITS_PER_UNIT
);
3793 SUB_PARM_SIZE (locate
->slot_offset
, s2
);
3796 locate
->slot_offset
.constant
+= part_size_in_regs
;
3799 #ifdef REG_PARM_STACK_SPACE
3800 || REG_PARM_STACK_SPACE (fndecl
) > 0
3803 pad_to_arg_alignment (&locate
->slot_offset
, boundary
,
3804 &locate
->alignment_pad
);
3806 locate
->size
.constant
= (-initial_offset_ptr
->constant
3807 - locate
->slot_offset
.constant
);
3808 if (initial_offset_ptr
->var
)
3809 locate
->size
.var
= size_binop (MINUS_EXPR
,
3810 size_binop (MINUS_EXPR
,
3812 initial_offset_ptr
->var
),
3813 locate
->slot_offset
.var
);
3815 /* Pad_below needs the pre-rounded size to know how much to pad
3817 locate
->offset
= locate
->slot_offset
;
3818 if (where_pad
== downward
)
3819 pad_below (&locate
->offset
, passed_mode
, sizetree
);
3821 #else /* !ARGS_GROW_DOWNWARD */
3823 #ifdef REG_PARM_STACK_SPACE
3824 || REG_PARM_STACK_SPACE (fndecl
) > 0
3827 pad_to_arg_alignment (initial_offset_ptr
, boundary
,
3828 &locate
->alignment_pad
);
3829 locate
->slot_offset
= *initial_offset_ptr
;
3831 #ifdef PUSH_ROUNDING
3832 if (passed_mode
!= BLKmode
)
3833 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
3836 /* Pad_below needs the pre-rounded size to know how much to pad below
3837 so this must be done before rounding up. */
3838 locate
->offset
= locate
->slot_offset
;
3839 if (where_pad
== downward
)
3840 pad_below (&locate
->offset
, passed_mode
, sizetree
);
3842 if (where_pad
!= none
3843 && (!host_integerp (sizetree
, 1)
3844 || (tree_low_cst (sizetree
, 1) * BITS_PER_UNIT
) % round_boundary
))
3845 sizetree
= round_up (sizetree
, round_boundary
/ BITS_PER_UNIT
);
3847 ADD_PARM_SIZE (locate
->size
, sizetree
);
3849 locate
->size
.constant
-= part_size_in_regs
;
3850 #endif /* ARGS_GROW_DOWNWARD */
3852 #ifdef FUNCTION_ARG_OFFSET
3853 locate
->offset
.constant
+= FUNCTION_ARG_OFFSET (passed_mode
, type
);
3857 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
3858 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
3861 pad_to_arg_alignment (struct args_size
*offset_ptr
, int boundary
,
3862 struct args_size
*alignment_pad
)
3864 tree save_var
= NULL_TREE
;
3865 HOST_WIDE_INT save_constant
= 0;
3866 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
3867 HOST_WIDE_INT sp_offset
= STACK_POINTER_OFFSET
;
3869 #ifdef SPARC_STACK_BOUNDARY_HACK
3870 /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
3871 the real alignment of %sp. However, when it does this, the
3872 alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
3873 if (SPARC_STACK_BOUNDARY_HACK
)
3877 if (boundary
> PARM_BOUNDARY
)
3879 save_var
= offset_ptr
->var
;
3880 save_constant
= offset_ptr
->constant
;
3883 alignment_pad
->var
= NULL_TREE
;
3884 alignment_pad
->constant
= 0;
3886 if (boundary
> BITS_PER_UNIT
)
3888 if (offset_ptr
->var
)
3890 tree sp_offset_tree
= ssize_int (sp_offset
);
3891 tree offset
= size_binop (PLUS_EXPR
,
3892 ARGS_SIZE_TREE (*offset_ptr
),
3894 #ifdef ARGS_GROW_DOWNWARD
3895 tree rounded
= round_down (offset
, boundary
/ BITS_PER_UNIT
);
3897 tree rounded
= round_up (offset
, boundary
/ BITS_PER_UNIT
);
3900 offset_ptr
->var
= size_binop (MINUS_EXPR
, rounded
, sp_offset_tree
);
3901 /* ARGS_SIZE_TREE includes constant term. */
3902 offset_ptr
->constant
= 0;
3903 if (boundary
> PARM_BOUNDARY
)
3904 alignment_pad
->var
= size_binop (MINUS_EXPR
, offset_ptr
->var
,
3909 offset_ptr
->constant
= -sp_offset
+
3910 #ifdef ARGS_GROW_DOWNWARD
3911 FLOOR_ROUND (offset_ptr
->constant
+ sp_offset
, boundary_in_bytes
);
3913 CEIL_ROUND (offset_ptr
->constant
+ sp_offset
, boundary_in_bytes
);
3915 if (boundary
> PARM_BOUNDARY
)
3916 alignment_pad
->constant
= offset_ptr
->constant
- save_constant
;
3922 pad_below (struct args_size
*offset_ptr
, enum machine_mode passed_mode
, tree sizetree
)
3924 if (passed_mode
!= BLKmode
)
3926 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
3927 offset_ptr
->constant
3928 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
3929 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
3930 - GET_MODE_SIZE (passed_mode
));
3934 if (TREE_CODE (sizetree
) != INTEGER_CST
3935 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
3937 /* Round the size up to multiple of PARM_BOUNDARY bits. */
3938 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
3940 ADD_PARM_SIZE (*offset_ptr
, s2
);
3941 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
3947 /* True if register REGNO was alive at a place where `setjmp' was
3948 called and was set more than once or is an argument. Such regs may
3949 be clobbered by `longjmp'. */
3952 regno_clobbered_at_setjmp (bitmap setjmp_crosses
, int regno
)
3954 /* There appear to be cases where some local vars never reach the
3955 backend but have bogus regnos. */
3956 if (regno
>= max_reg_num ())
3959 return ((REG_N_SETS (regno
) > 1
3960 || REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR
), regno
))
3961 && REGNO_REG_SET_P (setjmp_crosses
, regno
));
3964 /* Walk the tree of blocks describing the binding levels within a
3965 function and warn about variables the might be killed by setjmp or
3966 vfork. This is done after calling flow_analysis before register
3967 allocation since that will clobber the pseudo-regs to hard
3971 setjmp_vars_warning (bitmap setjmp_crosses
, tree block
)
3975 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
3977 if (TREE_CODE (decl
) == VAR_DECL
3978 && DECL_RTL_SET_P (decl
)
3979 && REG_P (DECL_RTL (decl
))
3980 && regno_clobbered_at_setjmp (setjmp_crosses
, REGNO (DECL_RTL (decl
))))
3981 warning (OPT_Wclobbered
, "variable %q+D might be clobbered by"
3982 " %<longjmp%> or %<vfork%>", decl
);
3985 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= BLOCK_CHAIN (sub
))
3986 setjmp_vars_warning (setjmp_crosses
, sub
);
3989 /* Do the appropriate part of setjmp_vars_warning
3990 but for arguments instead of local variables. */
3993 setjmp_args_warning (bitmap setjmp_crosses
)
3996 for (decl
= DECL_ARGUMENTS (current_function_decl
);
3997 decl
; decl
= DECL_CHAIN (decl
))
3998 if (DECL_RTL (decl
) != 0
3999 && REG_P (DECL_RTL (decl
))
4000 && regno_clobbered_at_setjmp (setjmp_crosses
, REGNO (DECL_RTL (decl
))))
4001 warning (OPT_Wclobbered
,
4002 "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
4006 /* Generate warning messages for variables live across setjmp. */
4009 generate_setjmp_warnings (void)
4011 bitmap setjmp_crosses
= regstat_get_setjmp_crosses ();
4013 if (n_basic_blocks
== NUM_FIXED_BLOCKS
4014 || bitmap_empty_p (setjmp_crosses
))
4017 setjmp_vars_warning (setjmp_crosses
, DECL_INITIAL (current_function_decl
));
4018 setjmp_args_warning (setjmp_crosses
);
4022 /* Reverse the order of elements in the fragment chain T of blocks,
4023 and return the new head of the chain (old last element).
4024 In addition to that clear BLOCK_SAME_RANGE flags when needed
4025 and adjust BLOCK_SUPERCONTEXT from the super fragment to
4026 its super fragment origin. */
4029 block_fragments_nreverse (tree t
)
4031 tree prev
= 0, block
, next
, prev_super
= 0;
4032 tree super
= BLOCK_SUPERCONTEXT (t
);
4033 if (BLOCK_FRAGMENT_ORIGIN (super
))
4034 super
= BLOCK_FRAGMENT_ORIGIN (super
);
4035 for (block
= t
; block
; block
= next
)
4037 next
= BLOCK_FRAGMENT_CHAIN (block
);
4038 BLOCK_FRAGMENT_CHAIN (block
) = prev
;
4039 if ((prev
&& !BLOCK_SAME_RANGE (prev
))
4040 || (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (block
))
4042 BLOCK_SAME_RANGE (block
) = 0;
4043 prev_super
= BLOCK_SUPERCONTEXT (block
);
4044 BLOCK_SUPERCONTEXT (block
) = super
;
4047 t
= BLOCK_FRAGMENT_ORIGIN (t
);
4048 if (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (t
))
4050 BLOCK_SAME_RANGE (t
) = 0;
4051 BLOCK_SUPERCONTEXT (t
) = super
;
4055 /* Reverse the order of elements in the chain T of blocks,
4056 and return the new head of the chain (old last element).
4057 Also do the same on subblocks and reverse the order of elements
4058 in BLOCK_FRAGMENT_CHAIN as well. */
4061 blocks_nreverse_all (tree t
)
4063 tree prev
= 0, block
, next
;
4064 for (block
= t
; block
; block
= next
)
4066 next
= BLOCK_CHAIN (block
);
4067 BLOCK_CHAIN (block
) = prev
;
4068 if (BLOCK_FRAGMENT_CHAIN (block
)
4069 && BLOCK_FRAGMENT_ORIGIN (block
) == NULL_TREE
)
4071 BLOCK_FRAGMENT_CHAIN (block
)
4072 = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block
));
4073 if (!BLOCK_SAME_RANGE (BLOCK_FRAGMENT_CHAIN (block
)))
4074 BLOCK_SAME_RANGE (block
) = 0;
4076 BLOCK_SUBBLOCKS (block
) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block
));
4083 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
4084 and create duplicate blocks. */
4085 /* ??? Need an option to either create block fragments or to create
4086 abstract origin duplicates of a source block. It really depends
4087 on what optimization has been performed. */
4090 reorder_blocks (void)
4092 tree block
= DECL_INITIAL (current_function_decl
);
4093 VEC(tree
,heap
) *block_stack
;
4095 if (block
== NULL_TREE
)
4098 block_stack
= VEC_alloc (tree
, heap
, 10);
4100 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
4101 clear_block_marks (block
);
4103 /* Prune the old trees away, so that they don't get in the way. */
4104 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
4105 BLOCK_CHAIN (block
) = NULL_TREE
;
4107 /* Recreate the block tree from the note nesting. */
4108 reorder_blocks_1 (get_insns (), block
, &block_stack
);
4109 BLOCK_SUBBLOCKS (block
) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block
));
4111 VEC_free (tree
, heap
, block_stack
);
4114 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
4117 clear_block_marks (tree block
)
4121 TREE_ASM_WRITTEN (block
) = 0;
4122 clear_block_marks (BLOCK_SUBBLOCKS (block
));
4123 block
= BLOCK_CHAIN (block
);
4128 reorder_blocks_1 (rtx insns
, tree current_block
, VEC(tree
,heap
) **p_block_stack
)
4131 tree prev_beg
= NULL_TREE
, prev_end
= NULL_TREE
;
4133 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
4137 if (NOTE_KIND (insn
) == NOTE_INSN_BLOCK_BEG
)
4139 tree block
= NOTE_BLOCK (insn
);
4142 gcc_assert (BLOCK_FRAGMENT_ORIGIN (block
) == NULL_TREE
);
4146 BLOCK_SAME_RANGE (prev_end
) = 0;
4147 prev_end
= NULL_TREE
;
4149 /* If we have seen this block before, that means it now
4150 spans multiple address regions. Create a new fragment. */
4151 if (TREE_ASM_WRITTEN (block
))
4153 tree new_block
= copy_node (block
);
4155 BLOCK_SAME_RANGE (new_block
) = 0;
4156 BLOCK_FRAGMENT_ORIGIN (new_block
) = origin
;
4157 BLOCK_FRAGMENT_CHAIN (new_block
)
4158 = BLOCK_FRAGMENT_CHAIN (origin
);
4159 BLOCK_FRAGMENT_CHAIN (origin
) = new_block
;
4161 NOTE_BLOCK (insn
) = new_block
;
4165 if (prev_beg
== current_block
&& prev_beg
)
4166 BLOCK_SAME_RANGE (block
) = 1;
4170 BLOCK_SUBBLOCKS (block
) = 0;
4171 TREE_ASM_WRITTEN (block
) = 1;
4172 /* When there's only one block for the entire function,
4173 current_block == block and we mustn't do this, it
4174 will cause infinite recursion. */
4175 if (block
!= current_block
)
4178 if (block
!= origin
)
4179 gcc_assert (BLOCK_SUPERCONTEXT (origin
) == current_block
4180 || BLOCK_FRAGMENT_ORIGIN (BLOCK_SUPERCONTEXT
4183 if (VEC_empty (tree
, *p_block_stack
))
4184 super
= current_block
;
4187 super
= VEC_last (tree
, *p_block_stack
);
4188 gcc_assert (super
== current_block
4189 || BLOCK_FRAGMENT_ORIGIN (super
)
4192 BLOCK_SUPERCONTEXT (block
) = super
;
4193 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
4194 BLOCK_SUBBLOCKS (current_block
) = block
;
4195 current_block
= origin
;
4197 VEC_safe_push (tree
, heap
, *p_block_stack
, block
);
4199 else if (NOTE_KIND (insn
) == NOTE_INSN_BLOCK_END
)
4201 NOTE_BLOCK (insn
) = VEC_pop (tree
, *p_block_stack
);
4202 current_block
= BLOCK_SUPERCONTEXT (current_block
);
4203 if (BLOCK_FRAGMENT_ORIGIN (current_block
))
4204 current_block
= BLOCK_FRAGMENT_ORIGIN (current_block
);
4205 prev_beg
= NULL_TREE
;
4206 prev_end
= BLOCK_SAME_RANGE (NOTE_BLOCK (insn
))
4207 ? NOTE_BLOCK (insn
) : NULL_TREE
;
4212 prev_beg
= NULL_TREE
;
4214 BLOCK_SAME_RANGE (prev_end
) = 0;
4215 prev_end
= NULL_TREE
;
4220 /* Reverse the order of elements in the chain T of blocks,
4221 and return the new head of the chain (old last element). */
4224 blocks_nreverse (tree t
)
4226 tree prev
= 0, block
, next
;
4227 for (block
= t
; block
; block
= next
)
4229 next
= BLOCK_CHAIN (block
);
4230 BLOCK_CHAIN (block
) = prev
;
4236 /* Concatenate two chains of blocks (chained through BLOCK_CHAIN)
4237 by modifying the last node in chain 1 to point to chain 2. */
4240 block_chainon (tree op1
, tree op2
)
4249 for (t1
= op1
; BLOCK_CHAIN (t1
); t1
= BLOCK_CHAIN (t1
))
4251 BLOCK_CHAIN (t1
) = op2
;
4253 #ifdef ENABLE_TREE_CHECKING
4256 for (t2
= op2
; t2
; t2
= BLOCK_CHAIN (t2
))
4257 gcc_assert (t2
!= t1
);
4264 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
4265 non-NULL, list them all into VECTOR, in a depth-first preorder
4266 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
4270 all_blocks (tree block
, tree
*vector
)
4276 TREE_ASM_WRITTEN (block
) = 0;
4278 /* Record this block. */
4280 vector
[n_blocks
] = block
;
4284 /* Record the subblocks, and their subblocks... */
4285 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
4286 vector
? vector
+ n_blocks
: 0);
4287 block
= BLOCK_CHAIN (block
);
4293 /* Return a vector containing all the blocks rooted at BLOCK. The
4294 number of elements in the vector is stored in N_BLOCKS_P. The
4295 vector is dynamically allocated; it is the caller's responsibility
4296 to call `free' on the pointer returned. */
4299 get_block_vector (tree block
, int *n_blocks_p
)
4303 *n_blocks_p
= all_blocks (block
, NULL
);
4304 block_vector
= XNEWVEC (tree
, *n_blocks_p
);
4305 all_blocks (block
, block_vector
);
4307 return block_vector
;
4310 static GTY(()) int next_block_index
= 2;
4312 /* Set BLOCK_NUMBER for all the blocks in FN. */
4315 number_blocks (tree fn
)
4321 /* For SDB and XCOFF debugging output, we start numbering the blocks
4322 from 1 within each function, rather than keeping a running
4324 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
4325 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
4326 next_block_index
= 1;
4329 block_vector
= get_block_vector (DECL_INITIAL (fn
), &n_blocks
);
4331 /* The top-level BLOCK isn't numbered at all. */
4332 for (i
= 1; i
< n_blocks
; ++i
)
4333 /* We number the blocks from two. */
4334 BLOCK_NUMBER (block_vector
[i
]) = next_block_index
++;
4336 free (block_vector
);
4341 /* If VAR is present in a subblock of BLOCK, return the subblock. */
4344 debug_find_var_in_block_tree (tree var
, tree block
)
4348 for (t
= BLOCK_VARS (block
); t
; t
= TREE_CHAIN (t
))
4352 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= TREE_CHAIN (t
))
4354 tree ret
= debug_find_var_in_block_tree (var
, t
);
4362 /* Keep track of whether we're in a dummy function context. If we are,
4363 we don't want to invoke the set_current_function hook, because we'll
4364 get into trouble if the hook calls target_reinit () recursively or
4365 when the initial initialization is not yet complete. */
4367 static bool in_dummy_function
;
4369 /* Invoke the target hook when setting cfun. Update the optimization options
4370 if the function uses different options than the default. */
4373 invoke_set_current_function_hook (tree fndecl
)
4375 if (!in_dummy_function
)
4377 tree opts
= ((fndecl
)
4378 ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
)
4379 : optimization_default_node
);
4382 opts
= optimization_default_node
;
4384 /* Change optimization options if needed. */
4385 if (optimization_current_node
!= opts
)
4387 optimization_current_node
= opts
;
4388 cl_optimization_restore (&global_options
, TREE_OPTIMIZATION (opts
));
4391 targetm
.set_current_function (fndecl
);
4395 /* cfun should never be set directly; use this function. */
4398 set_cfun (struct function
*new_cfun
)
4400 if (cfun
!= new_cfun
)
4403 invoke_set_current_function_hook (new_cfun
? new_cfun
->decl
: NULL_TREE
);
4407 /* Initialized with NOGC, making this poisonous to the garbage collector. */
4409 static VEC(function_p
,heap
) *cfun_stack
;
4411 /* Push the current cfun onto the stack, and set cfun to new_cfun. */
4414 push_cfun (struct function
*new_cfun
)
4416 VEC_safe_push (function_p
, heap
, cfun_stack
, cfun
);
4417 set_cfun (new_cfun
);
4420 /* Pop cfun from the stack. */
4425 struct function
*new_cfun
= VEC_pop (function_p
, cfun_stack
);
4426 set_cfun (new_cfun
);
4429 /* Return value of funcdef and increase it. */
4431 get_next_funcdef_no (void)
4433 return funcdef_no
++;
4436 /* Return value of funcdef. */
4438 get_last_funcdef_no (void)
4443 /* Allocate a function structure for FNDECL and set its contents
4444 to the defaults. Set cfun to the newly-allocated object.
4445 Some of the helper functions invoked during initialization assume
4446 that cfun has already been set. Therefore, assign the new object
4447 directly into cfun and invoke the back end hook explicitly at the
4448 very end, rather than initializing a temporary and calling set_cfun
4451 ABSTRACT_P is true if this is a function that will never be seen by
4452 the middle-end. Such functions are front-end concepts (like C++
4453 function templates) that do not correspond directly to functions
4454 placed in object files. */
4457 allocate_struct_function (tree fndecl
, bool abstract_p
)
4460 tree fntype
= fndecl
? TREE_TYPE (fndecl
) : NULL_TREE
;
4462 cfun
= ggc_alloc_cleared_function ();
4464 init_eh_for_function ();
4466 if (init_machine_status
)
4467 cfun
->machine
= (*init_machine_status
) ();
4469 #ifdef OVERRIDE_ABI_FORMAT
4470 OVERRIDE_ABI_FORMAT (fndecl
);
4473 invoke_set_current_function_hook (fndecl
);
4475 if (fndecl
!= NULL_TREE
)
4477 DECL_STRUCT_FUNCTION (fndecl
) = cfun
;
4478 cfun
->decl
= fndecl
;
4479 current_function_funcdef_no
= get_next_funcdef_no ();
4481 result
= DECL_RESULT (fndecl
);
4482 if (!abstract_p
&& aggregate_value_p (result
, fndecl
))
4484 #ifdef PCC_STATIC_STRUCT_RETURN
4485 cfun
->returns_pcc_struct
= 1;
4487 cfun
->returns_struct
= 1;
4490 cfun
->stdarg
= stdarg_p (fntype
);
4492 /* Assume all registers in stdarg functions need to be saved. */
4493 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
4494 cfun
->va_list_fpr_size
= VA_LIST_MAX_FPR_SIZE
;
4496 /* ??? This could be set on a per-function basis by the front-end
4497 but is this worth the hassle? */
4498 cfun
->can_throw_non_call_exceptions
= flag_non_call_exceptions
;
4502 /* This is like allocate_struct_function, but pushes a new cfun for FNDECL
4503 instead of just setting it. */
4506 push_struct_function (tree fndecl
)
4508 VEC_safe_push (function_p
, heap
, cfun_stack
, cfun
);
4509 allocate_struct_function (fndecl
, false);
4512 /* Reset crtl and other non-struct-function variables to defaults as
4513 appropriate for emitting rtl at the start of a function. */
4516 prepare_function_start (void)
4518 gcc_assert (!crtl
->emit
.x_last_insn
);
4521 init_varasm_status ();
4523 default_rtl_profile ();
4525 if (flag_stack_usage_info
)
4527 cfun
->su
= ggc_alloc_cleared_stack_usage ();
4528 cfun
->su
->static_stack_size
= -1;
4531 cse_not_expected
= ! optimize
;
4533 /* Caller save not needed yet. */
4534 caller_save_needed
= 0;
4536 /* We haven't done register allocation yet. */
4539 /* Indicate that we have not instantiated virtual registers yet. */
4540 virtuals_instantiated
= 0;
4542 /* Indicate that we want CONCATs now. */
4543 generating_concat_p
= 1;
4545 /* Indicate we have no need of a frame pointer yet. */
4546 frame_pointer_needed
= 0;
4549 /* Initialize the rtl expansion mechanism so that we can do simple things
4550 like generate sequences. This is used to provide a context during global
4551 initialization of some passes. You must call expand_dummy_function_end
4552 to exit this context. */
4555 init_dummy_function_start (void)
4557 gcc_assert (!in_dummy_function
);
4558 in_dummy_function
= true;
4559 push_struct_function (NULL_TREE
);
4560 prepare_function_start ();
4563 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4564 and initialize static variables for generating RTL for the statements
4568 init_function_start (tree subr
)
4570 if (subr
&& DECL_STRUCT_FUNCTION (subr
))
4571 set_cfun (DECL_STRUCT_FUNCTION (subr
));
4573 allocate_struct_function (subr
, false);
4574 prepare_function_start ();
4575 decide_function_section (subr
);
4577 /* Warn if this value is an aggregate type,
4578 regardless of which calling convention we are using for it. */
4579 if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
4580 warning (OPT_Waggregate_return
, "function returns an aggregate");
4585 expand_main_function (void)
4587 #if (defined(INVOKE__main) \
4588 || (!defined(HAS_INIT_SECTION) \
4589 && !defined(INIT_SECTION_ASM_OP) \
4590 && !defined(INIT_ARRAY_SECTION_ASM_OP)))
4591 emit_library_call (init_one_libfunc (NAME__MAIN
), LCT_NORMAL
, VOIDmode
, 0);
4595 /* Expand code to initialize the stack_protect_guard. This is invoked at
4596 the beginning of a function to be protected. */
4598 #ifndef HAVE_stack_protect_set
4599 # define HAVE_stack_protect_set 0
4600 # define gen_stack_protect_set(x,y) (gcc_unreachable (), NULL_RTX)
4604 stack_protect_prologue (void)
4606 tree guard_decl
= targetm
.stack_protect_guard ();
4609 x
= expand_normal (crtl
->stack_protect_guard
);
4610 y
= expand_normal (guard_decl
);
4612 /* Allow the target to copy from Y to X without leaking Y into a
4614 if (HAVE_stack_protect_set
)
4616 rtx insn
= gen_stack_protect_set (x
, y
);
4624 /* Otherwise do a straight move. */
4625 emit_move_insn (x
, y
);
4628 /* Expand code to verify the stack_protect_guard. This is invoked at
4629 the end of a function to be protected. */
4631 #ifndef HAVE_stack_protect_test
4632 # define HAVE_stack_protect_test 0
4633 # define gen_stack_protect_test(x, y, z) (gcc_unreachable (), NULL_RTX)
4637 stack_protect_epilogue (void)
4639 tree guard_decl
= targetm
.stack_protect_guard ();
4640 rtx label
= gen_label_rtx ();
4643 x
= expand_normal (crtl
->stack_protect_guard
);
4644 y
= expand_normal (guard_decl
);
4646 /* Allow the target to compare Y with X without leaking either into
4648 switch (HAVE_stack_protect_test
!= 0)
4651 tmp
= gen_stack_protect_test (x
, y
, label
);
4660 emit_cmp_and_jump_insns (x
, y
, EQ
, NULL_RTX
, ptr_mode
, 1, label
);
4664 /* The noreturn predictor has been moved to the tree level. The rtl-level
4665 predictors estimate this branch about 20%, which isn't enough to get
4666 things moved out of line. Since this is the only extant case of adding
4667 a noreturn function at the rtl level, it doesn't seem worth doing ought
4668 except adding the prediction by hand. */
4669 tmp
= get_last_insn ();
4671 predict_insn_def (tmp
, PRED_NORETURN
, TAKEN
);
4673 expand_expr_stmt (targetm
.stack_protect_fail ());
4677 /* Start the RTL for a new function, and set variables used for
4679 SUBR is the FUNCTION_DECL node.
4680 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4681 the function's parameters, which must be run at any return statement. */
4684 expand_function_start (tree subr
)
4686 /* Make sure volatile mem refs aren't considered
4687 valid operands of arithmetic insns. */
4688 init_recog_no_volatile ();
4692 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
4695 = (stack_limit_rtx
!= NULL_RTX
&& ! DECL_NO_LIMIT_STACK (subr
));
4697 /* Make the label for return statements to jump to. Do not special
4698 case machines with special return instructions -- they will be
4699 handled later during jump, ifcvt, or epilogue creation. */
4700 return_label
= gen_label_rtx ();
4702 /* Initialize rtx used to return the value. */
4703 /* Do this before assign_parms so that we copy the struct value address
4704 before any library calls that assign parms might generate. */
4706 /* Decide whether to return the value in memory or in a register. */
4707 if (aggregate_value_p (DECL_RESULT (subr
), subr
))
4709 /* Returning something that won't go in a register. */
4710 rtx value_address
= 0;
4712 #ifdef PCC_STATIC_STRUCT_RETURN
4713 if (cfun
->returns_pcc_struct
)
4715 int size
= int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr
)));
4716 value_address
= assemble_static_space (size
);
4721 rtx sv
= targetm
.calls
.struct_value_rtx (TREE_TYPE (subr
), 2);
4722 /* Expect to be passed the address of a place to store the value.
4723 If it is passed as an argument, assign_parms will take care of
4727 value_address
= gen_reg_rtx (Pmode
);
4728 emit_move_insn (value_address
, sv
);
4733 rtx x
= value_address
;
4734 if (!DECL_BY_REFERENCE (DECL_RESULT (subr
)))
4736 x
= gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr
)), x
);
4737 set_mem_attributes (x
, DECL_RESULT (subr
), 1);
4739 SET_DECL_RTL (DECL_RESULT (subr
), x
);
4742 else if (DECL_MODE (DECL_RESULT (subr
)) == VOIDmode
)
4743 /* If return mode is void, this decl rtl should not be used. */
4744 SET_DECL_RTL (DECL_RESULT (subr
), NULL_RTX
);
4747 /* Compute the return values into a pseudo reg, which we will copy
4748 into the true return register after the cleanups are done. */
4749 tree return_type
= TREE_TYPE (DECL_RESULT (subr
));
4750 if (TYPE_MODE (return_type
) != BLKmode
4751 && targetm
.calls
.return_in_msb (return_type
))
4752 /* expand_function_end will insert the appropriate padding in
4753 this case. Use the return value's natural (unpadded) mode
4754 within the function proper. */
4755 SET_DECL_RTL (DECL_RESULT (subr
),
4756 gen_reg_rtx (TYPE_MODE (return_type
)));
4759 /* In order to figure out what mode to use for the pseudo, we
4760 figure out what the mode of the eventual return register will
4761 actually be, and use that. */
4762 rtx hard_reg
= hard_function_value (return_type
, subr
, 0, 1);
4764 /* Structures that are returned in registers are not
4765 aggregate_value_p, so we may see a PARALLEL or a REG. */
4766 if (REG_P (hard_reg
))
4767 SET_DECL_RTL (DECL_RESULT (subr
),
4768 gen_reg_rtx (GET_MODE (hard_reg
)));
4771 gcc_assert (GET_CODE (hard_reg
) == PARALLEL
);
4772 SET_DECL_RTL (DECL_RESULT (subr
), gen_group_rtx (hard_reg
));
4776 /* Set DECL_REGISTER flag so that expand_function_end will copy the
4777 result to the real return register(s). */
4778 DECL_REGISTER (DECL_RESULT (subr
)) = 1;
4781 /* Initialize rtx for parameters and local variables.
4782 In some cases this requires emitting insns. */
4783 assign_parms (subr
);
4785 /* If function gets a static chain arg, store it. */
4786 if (cfun
->static_chain_decl
)
4788 tree parm
= cfun
->static_chain_decl
;
4789 rtx local
, chain
, insn
;
4791 local
= gen_reg_rtx (Pmode
);
4792 chain
= targetm
.calls
.static_chain (current_function_decl
, true);
4794 set_decl_incoming_rtl (parm
, chain
, false);
4795 SET_DECL_RTL (parm
, local
);
4796 mark_reg_pointer (local
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
4798 insn
= emit_move_insn (local
, chain
);
4800 /* Mark the register as eliminable, similar to parameters. */
4802 && reg_mentioned_p (arg_pointer_rtx
, XEXP (chain
, 0)))
4803 set_dst_reg_note (insn
, REG_EQUIV
, chain
, local
);
4806 /* If the function receives a non-local goto, then store the
4807 bits we need to restore the frame pointer. */
4808 if (cfun
->nonlocal_goto_save_area
)
4813 tree var
= TREE_OPERAND (cfun
->nonlocal_goto_save_area
, 0);
4814 gcc_assert (DECL_RTL_SET_P (var
));
4816 t_save
= build4 (ARRAY_REF
,
4817 TREE_TYPE (TREE_TYPE (cfun
->nonlocal_goto_save_area
)),
4818 cfun
->nonlocal_goto_save_area
,
4819 integer_zero_node
, NULL_TREE
, NULL_TREE
);
4820 r_save
= expand_expr (t_save
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
4821 gcc_assert (GET_MODE (r_save
) == Pmode
);
4823 emit_move_insn (r_save
, targetm
.builtin_setjmp_frame_value ());
4824 update_nonlocal_goto_save_area ();
4827 /* The following was moved from init_function_start.
4828 The move is supposed to make sdb output more accurate. */
4829 /* Indicate the beginning of the function body,
4830 as opposed to parm setup. */
4831 emit_note (NOTE_INSN_FUNCTION_BEG
);
4833 gcc_assert (NOTE_P (get_last_insn ()));
4835 parm_birth_insn
= get_last_insn ();
4840 PROFILE_HOOK (current_function_funcdef_no
);
4844 /* If we are doing generic stack checking, the probe should go here. */
4845 if (flag_stack_check
== GENERIC_STACK_CHECK
)
4846 stack_check_probe_note
= emit_note (NOTE_INSN_DELETED
);
4848 /* Make sure there is a line number after the function entry setup code. */
4849 force_next_line_note ();
4852 /* Undo the effects of init_dummy_function_start. */
4854 expand_dummy_function_end (void)
4856 gcc_assert (in_dummy_function
);
4858 /* End any sequences that failed to be closed due to syntax errors. */
4859 while (in_sequence_p ())
4862 /* Outside function body, can't compute type's actual size
4863 until next function's body starts. */
4865 free_after_parsing (cfun
);
4866 free_after_compilation (cfun
);
4868 in_dummy_function
= false;
4871 /* Call DOIT for each hard register used as a return value from
4872 the current function. */
4875 diddle_return_value (void (*doit
) (rtx
, void *), void *arg
)
4877 rtx outgoing
= crtl
->return_rtx
;
4882 if (REG_P (outgoing
))
4883 (*doit
) (outgoing
, arg
);
4884 else if (GET_CODE (outgoing
) == PARALLEL
)
4888 for (i
= 0; i
< XVECLEN (outgoing
, 0); i
++)
4890 rtx x
= XEXP (XVECEXP (outgoing
, 0, i
), 0);
4892 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
4899 do_clobber_return_reg (rtx reg
, void *arg ATTRIBUTE_UNUSED
)
4905 clobber_return_register (void)
4907 diddle_return_value (do_clobber_return_reg
, NULL
);
4909 /* In case we do use pseudo to return value, clobber it too. */
4910 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
4912 tree decl_result
= DECL_RESULT (current_function_decl
);
4913 rtx decl_rtl
= DECL_RTL (decl_result
);
4914 if (REG_P (decl_rtl
) && REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
)
4916 do_clobber_return_reg (decl_rtl
, NULL
);
4922 do_use_return_reg (rtx reg
, void *arg ATTRIBUTE_UNUSED
)
4928 use_return_register (void)
4930 diddle_return_value (do_use_return_reg
, NULL
);
4933 /* Possibly warn about unused parameters. */
4935 do_warn_unused_parameter (tree fn
)
4939 for (decl
= DECL_ARGUMENTS (fn
);
4940 decl
; decl
= DECL_CHAIN (decl
))
4941 if (!TREE_USED (decl
) && TREE_CODE (decl
) == PARM_DECL
4942 && DECL_NAME (decl
) && !DECL_ARTIFICIAL (decl
)
4943 && !TREE_NO_WARNING (decl
))
4944 warning (OPT_Wunused_parameter
, "unused parameter %q+D", decl
);
4947 static GTY(()) rtx initial_trampoline
;
4949 /* Generate RTL for the end of the current function. */
4952 expand_function_end (void)
4956 /* If arg_pointer_save_area was referenced only from a nested
4957 function, we will not have initialized it yet. Do that now. */
4958 if (arg_pointer_save_area
&& ! crtl
->arg_pointer_save_area_init
)
4959 get_arg_pointer_save_area ();
4961 /* If we are doing generic stack checking and this function makes calls,
4962 do a stack probe at the start of the function to ensure we have enough
4963 space for another stack frame. */
4964 if (flag_stack_check
== GENERIC_STACK_CHECK
)
4968 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4971 rtx max_frame_size
= GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
);
4973 if (STACK_CHECK_MOVING_SP
)
4974 anti_adjust_stack_and_probe (max_frame_size
, true);
4976 probe_stack_range (STACK_OLD_CHECK_PROTECT
, max_frame_size
);
4979 set_insn_locators (seq
, prologue_locator
);
4980 emit_insn_before (seq
, stack_check_probe_note
);
4985 /* End any sequences that failed to be closed due to syntax errors. */
4986 while (in_sequence_p ())
4989 clear_pending_stack_adjust ();
4990 do_pending_stack_adjust ();
4992 /* Output a linenumber for the end of the function.
4993 SDB depends on this. */
4994 force_next_line_note ();
4995 set_curr_insn_source_location (input_location
);
4997 /* Before the return label (if any), clobber the return
4998 registers so that they are not propagated live to the rest of
4999 the function. This can only happen with functions that drop
5000 through; if there had been a return statement, there would
5001 have either been a return rtx, or a jump to the return label.
5003 We delay actual code generation after the current_function_value_rtx
5005 clobber_after
= get_last_insn ();
5007 /* Output the label for the actual return from the function. */
5008 emit_label (return_label
);
5010 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
5012 /* Let except.c know where it should emit the call to unregister
5013 the function context for sjlj exceptions. */
5014 if (flag_exceptions
)
5015 sjlj_emit_function_exit_after (get_last_insn ());
5019 /* We want to ensure that instructions that may trap are not
5020 moved into the epilogue by scheduling, because we don't
5021 always emit unwind information for the epilogue. */
5022 if (cfun
->can_throw_non_call_exceptions
)
5023 emit_insn (gen_blockage ());
5026 /* If this is an implementation of throw, do what's necessary to
5027 communicate between __builtin_eh_return and the epilogue. */
5028 expand_eh_return ();
5030 /* If scalar return value was computed in a pseudo-reg, or was a named
5031 return value that got dumped to the stack, copy that to the hard
5033 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
5035 tree decl_result
= DECL_RESULT (current_function_decl
);
5036 rtx decl_rtl
= DECL_RTL (decl_result
);
5038 if (REG_P (decl_rtl
)
5039 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
5040 : DECL_REGISTER (decl_result
))
5042 rtx real_decl_rtl
= crtl
->return_rtx
;
5044 /* This should be set in assign_parms. */
5045 gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl
));
5047 /* If this is a BLKmode structure being returned in registers,
5048 then use the mode computed in expand_return. Note that if
5049 decl_rtl is memory, then its mode may have been changed,
5050 but that crtl->return_rtx has not. */
5051 if (GET_MODE (real_decl_rtl
) == BLKmode
)
5052 PUT_MODE (real_decl_rtl
, GET_MODE (decl_rtl
));
5054 /* If a non-BLKmode return value should be padded at the least
5055 significant end of the register, shift it left by the appropriate
5056 amount. BLKmode results are handled using the group load/store
5058 if (TYPE_MODE (TREE_TYPE (decl_result
)) != BLKmode
5059 && targetm
.calls
.return_in_msb (TREE_TYPE (decl_result
)))
5061 emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl
),
5062 REGNO (real_decl_rtl
)),
5064 shift_return_value (GET_MODE (decl_rtl
), true, real_decl_rtl
);
5066 /* If a named return value dumped decl_return to memory, then
5067 we may need to re-do the PROMOTE_MODE signed/unsigned
5069 else if (GET_MODE (real_decl_rtl
) != GET_MODE (decl_rtl
))
5071 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (decl_result
));
5072 promote_function_mode (TREE_TYPE (decl_result
),
5073 GET_MODE (decl_rtl
), &unsignedp
,
5074 TREE_TYPE (current_function_decl
), 1);
5076 convert_move (real_decl_rtl
, decl_rtl
, unsignedp
);
5078 else if (GET_CODE (real_decl_rtl
) == PARALLEL
)
5080 /* If expand_function_start has created a PARALLEL for decl_rtl,
5081 move the result to the real return registers. Otherwise, do
5082 a group load from decl_rtl for a named return. */
5083 if (GET_CODE (decl_rtl
) == PARALLEL
)
5084 emit_group_move (real_decl_rtl
, decl_rtl
);
5086 emit_group_load (real_decl_rtl
, decl_rtl
,
5087 TREE_TYPE (decl_result
),
5088 int_size_in_bytes (TREE_TYPE (decl_result
)));
5090 /* In the case of complex integer modes smaller than a word, we'll
5091 need to generate some non-trivial bitfield insertions. Do that
5092 on a pseudo and not the hard register. */
5093 else if (GET_CODE (decl_rtl
) == CONCAT
5094 && GET_MODE_CLASS (GET_MODE (decl_rtl
)) == MODE_COMPLEX_INT
5095 && GET_MODE_BITSIZE (GET_MODE (decl_rtl
)) <= BITS_PER_WORD
)
5097 int old_generating_concat_p
;
5100 old_generating_concat_p
= generating_concat_p
;
5101 generating_concat_p
= 0;
5102 tmp
= gen_reg_rtx (GET_MODE (decl_rtl
));
5103 generating_concat_p
= old_generating_concat_p
;
5105 emit_move_insn (tmp
, decl_rtl
);
5106 emit_move_insn (real_decl_rtl
, tmp
);
5109 emit_move_insn (real_decl_rtl
, decl_rtl
);
5113 /* If returning a structure, arrange to return the address of the value
5114 in a place where debuggers expect to find it.
5116 If returning a structure PCC style,
5117 the caller also depends on this value.
5118 And cfun->returns_pcc_struct is not necessarily set. */
5119 if (cfun
->returns_struct
5120 || cfun
->returns_pcc_struct
)
5122 rtx value_address
= DECL_RTL (DECL_RESULT (current_function_decl
));
5123 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
5126 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl
)))
5127 type
= TREE_TYPE (type
);
5129 value_address
= XEXP (value_address
, 0);
5131 outgoing
= targetm
.calls
.function_value (build_pointer_type (type
),
5132 current_function_decl
, true);
5134 /* Mark this as a function return value so integrate will delete the
5135 assignment and USE below when inlining this function. */
5136 REG_FUNCTION_VALUE_P (outgoing
) = 1;
5138 /* The address may be ptr_mode and OUTGOING may be Pmode. */
5139 value_address
= convert_memory_address (GET_MODE (outgoing
),
5142 emit_move_insn (outgoing
, value_address
);
5144 /* Show return register used to hold result (in this case the address
5146 crtl
->return_rtx
= outgoing
;
5149 /* Emit the actual code to clobber return register. */
5154 clobber_return_register ();
5158 emit_insn_after (seq
, clobber_after
);
5161 /* Output the label for the naked return from the function. */
5162 if (naked_return_label
)
5163 emit_label (naked_return_label
);
5165 /* @@@ This is a kludge. We want to ensure that instructions that
5166 may trap are not moved into the epilogue by scheduling, because
5167 we don't always emit unwind information for the epilogue. */
5168 if (cfun
->can_throw_non_call_exceptions
5169 && targetm_common
.except_unwind_info (&global_options
) != UI_SJLJ
)
5170 emit_insn (gen_blockage ());
5172 /* If stack protection is enabled for this function, check the guard. */
5173 if (crtl
->stack_protect_guard
)
5174 stack_protect_epilogue ();
5176 /* If we had calls to alloca, and this machine needs
5177 an accurate stack pointer to exit the function,
5178 insert some code to save and restore the stack pointer. */
5179 if (! EXIT_IGNORE_STACK
5180 && cfun
->calls_alloca
)
5185 emit_stack_save (SAVE_FUNCTION
, &tem
);
5188 emit_insn_before (seq
, parm_birth_insn
);
5190 emit_stack_restore (SAVE_FUNCTION
, tem
);
5193 /* ??? This should no longer be necessary since stupid is no longer with
5194 us, but there are some parts of the compiler (eg reload_combine, and
5195 sh mach_dep_reorg) that still try and compute their own lifetime info
5196 instead of using the general framework. */
5197 use_return_register ();
5201 get_arg_pointer_save_area (void)
5203 rtx ret
= arg_pointer_save_area
;
5207 ret
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5208 arg_pointer_save_area
= ret
;
5211 if (! crtl
->arg_pointer_save_area_init
)
5215 /* Save the arg pointer at the beginning of the function. The
5216 generated stack slot may not be a valid memory address, so we
5217 have to check it and fix it if necessary. */
5219 emit_move_insn (validize_mem (ret
),
5220 crtl
->args
.internal_arg_pointer
);
5224 push_topmost_sequence ();
5225 emit_insn_after (seq
, entry_of_function ());
5226 pop_topmost_sequence ();
5228 crtl
->arg_pointer_save_area_init
= true;
5234 /* Add a list of INSNS to the hash HASHP, possibly allocating HASHP
5235 for the first time. */
5238 record_insns (rtx insns
, rtx end
, htab_t
*hashp
)
5241 htab_t hash
= *hashp
;
5245 = htab_create_ggc (17, htab_hash_pointer
, htab_eq_pointer
, NULL
);
5247 for (tmp
= insns
; tmp
!= end
; tmp
= NEXT_INSN (tmp
))
5249 void **slot
= htab_find_slot (hash
, tmp
, INSERT
);
5250 gcc_assert (*slot
== NULL
);
5255 /* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a
5256 basic block, splitting or peepholes. If INSN is a prologue or epilogue
5257 insn, then record COPY as well. */
5260 maybe_copy_prologue_epilogue_insn (rtx insn
, rtx copy
)
5265 hash
= epilogue_insn_hash
;
5266 if (!hash
|| !htab_find (hash
, insn
))
5268 hash
= prologue_insn_hash
;
5269 if (!hash
|| !htab_find (hash
, insn
))
5273 slot
= htab_find_slot (hash
, copy
, INSERT
);
5274 gcc_assert (*slot
== NULL
);
5278 /* Set the locator of the insn chain starting at INSN to LOC. */
5280 set_insn_locators (rtx insn
, int loc
)
5282 while (insn
!= NULL_RTX
)
5285 INSN_LOCATOR (insn
) = loc
;
5286 insn
= NEXT_INSN (insn
);
5290 /* Determine if any INSNs in HASH are, or are part of, INSN. Because
5291 we can be running after reorg, SEQUENCE rtl is possible. */
5294 contains (const_rtx insn
, htab_t hash
)
5299 if (NONJUMP_INSN_P (insn
) && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
5302 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
5303 if (htab_find (hash
, XVECEXP (PATTERN (insn
), 0, i
)))
5308 return htab_find (hash
, insn
) != NULL
;
5312 prologue_epilogue_contains (const_rtx insn
)
5314 if (contains (insn
, prologue_insn_hash
))
5316 if (contains (insn
, epilogue_insn_hash
))
5321 #ifdef HAVE_simple_return
5323 /* Return true if INSN requires the stack frame to be set up.
5324 PROLOGUE_USED contains the hard registers used in the function
5325 prologue. SET_UP_BY_PROLOGUE is the set of registers we expect the
5326 prologue to set up for the function. */
5328 requires_stack_frame_p (rtx insn
, HARD_REG_SET prologue_used
,
5329 HARD_REG_SET set_up_by_prologue
)
5332 HARD_REG_SET hardregs
;
5336 return !SIBLING_CALL_P (insn
);
5338 /* We need a frame to get the unique CFA expected by the unwinder. */
5339 if (cfun
->can_throw_non_call_exceptions
&& can_throw_internal (insn
))
5342 CLEAR_HARD_REG_SET (hardregs
);
5343 for (df_rec
= DF_INSN_DEFS (insn
); *df_rec
; df_rec
++)
5345 rtx dreg
= DF_REF_REG (*df_rec
);
5350 add_to_hard_reg_set (&hardregs
, GET_MODE (dreg
),
5353 if (hard_reg_set_intersect_p (hardregs
, prologue_used
))
5355 AND_COMPL_HARD_REG_SET (hardregs
, call_used_reg_set
);
5356 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
5357 if (TEST_HARD_REG_BIT (hardregs
, regno
)
5358 && df_regs_ever_live_p (regno
))
5361 for (df_rec
= DF_INSN_USES (insn
); *df_rec
; df_rec
++)
5363 rtx reg
= DF_REF_REG (*df_rec
);
5368 add_to_hard_reg_set (&hardregs
, GET_MODE (reg
),
5371 if (hard_reg_set_intersect_p (hardregs
, set_up_by_prologue
))
5377 /* See whether BB has a single successor that uses [REGNO, END_REGNO),
5378 and if BB is its only predecessor. Return that block if so,
5379 otherwise return null. */
5382 next_block_for_reg (basic_block bb
, int regno
, int end_regno
)
5390 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
5392 live
= df_get_live_in (e
->dest
);
5393 for (i
= regno
; i
< end_regno
; i
++)
5394 if (REGNO_REG_SET_P (live
, i
))
5396 if (live_edge
&& live_edge
!= e
)
5402 /* We can sometimes encounter dead code. Don't try to move it
5403 into the exit block. */
5404 if (!live_edge
|| live_edge
->dest
== EXIT_BLOCK_PTR
)
5407 /* Reject targets of abnormal edges. This is needed for correctness
5408 on ports like Alpha and MIPS, whose pic_offset_table_rtx can die on
5409 exception edges even though it is generally treated as call-saved
5410 for the majority of the compilation. Moving across abnormal edges
5411 isn't going to be interesting for shrink-wrap usage anyway. */
5412 if (live_edge
->flags
& EDGE_ABNORMAL
)
5415 if (EDGE_COUNT (live_edge
->dest
->preds
) > 1)
5418 return live_edge
->dest
;
5421 /* Try to move INSN from BB to a successor. Return true on success.
5422 USES and DEFS are the set of registers that are used and defined
5423 after INSN in BB. */
5426 move_insn_for_shrink_wrap (basic_block bb
, rtx insn
,
5427 const HARD_REG_SET uses
,
5428 const HARD_REG_SET defs
)
5431 bitmap live_out
, live_in
, bb_uses
, bb_defs
;
5432 unsigned int i
, dregno
, end_dregno
, sregno
, end_sregno
;
5433 basic_block next_block
;
5435 /* Look for a simple register copy. */
5436 set
= single_set (insn
);
5439 src
= SET_SRC (set
);
5440 dest
= SET_DEST (set
);
5441 if (!REG_P (dest
) || !REG_P (src
))
5444 /* Make sure that the source register isn't defined later in BB. */
5445 sregno
= REGNO (src
);
5446 end_sregno
= END_REGNO (src
);
5447 if (overlaps_hard_reg_set_p (defs
, GET_MODE (src
), sregno
))
5450 /* Make sure that the destination register isn't referenced later in BB. */
5451 dregno
= REGNO (dest
);
5452 end_dregno
= END_REGNO (dest
);
5453 if (overlaps_hard_reg_set_p (uses
, GET_MODE (dest
), dregno
)
5454 || overlaps_hard_reg_set_p (defs
, GET_MODE (dest
), dregno
))
5457 /* See whether there is a successor block to which we could move INSN. */
5458 next_block
= next_block_for_reg (bb
, dregno
, end_dregno
);
5462 /* At this point we are committed to moving INSN, but let's try to
5463 move it as far as we can. */
5466 live_out
= df_get_live_out (bb
);
5467 live_in
= df_get_live_in (next_block
);
5470 /* Check whether BB uses DEST or clobbers DEST. We need to add
5471 INSN to BB if so. Either way, DEST is no longer live on entry,
5472 except for any part that overlaps SRC (next loop). */
5473 bb_uses
= &DF_LR_BB_INFO (bb
)->use
;
5474 bb_defs
= &DF_LR_BB_INFO (bb
)->def
;
5475 for (i
= dregno
; i
< end_dregno
; i
++)
5477 if (REGNO_REG_SET_P (bb_uses
, i
) || REGNO_REG_SET_P (bb_defs
, i
))
5479 CLEAR_REGNO_REG_SET (live_out
, i
);
5480 CLEAR_REGNO_REG_SET (live_in
, i
);
5483 /* Check whether BB clobbers SRC. We need to add INSN to BB if so.
5484 Either way, SRC is now live on entry. */
5485 for (i
= sregno
; i
< end_sregno
; i
++)
5487 if (REGNO_REG_SET_P (bb_defs
, i
))
5489 SET_REGNO_REG_SET (live_out
, i
);
5490 SET_REGNO_REG_SET (live_in
, i
);
5493 /* If we don't need to add the move to BB, look for a single
5496 next_block
= next_block_for_reg (next_block
, dregno
, end_dregno
);
5500 /* BB now defines DEST. It only uses the parts of DEST that overlap SRC
5502 for (i
= dregno
; i
< end_dregno
; i
++)
5504 CLEAR_REGNO_REG_SET (bb_uses
, i
);
5505 SET_REGNO_REG_SET (bb_defs
, i
);
5508 /* BB now uses SRC. */
5509 for (i
= sregno
; i
< end_sregno
; i
++)
5510 SET_REGNO_REG_SET (bb_uses
, i
);
5512 emit_insn_after (PATTERN (insn
), bb_note (bb
));
5517 /* Look for register copies in the first block of the function, and move
5518 them down into successor blocks if the register is used only on one
5519 path. This exposes more opportunities for shrink-wrapping. These
5520 kinds of sets often occur when incoming argument registers are moved
5521 to call-saved registers because their values are live across one or
5522 more calls during the function. */
5525 prepare_shrink_wrap (basic_block entry_block
)
5528 HARD_REG_SET uses
, defs
;
5531 CLEAR_HARD_REG_SET (uses
);
5532 CLEAR_HARD_REG_SET (defs
);
5533 FOR_BB_INSNS_REVERSE_SAFE (entry_block
, insn
, curr
)
5534 if (NONDEBUG_INSN_P (insn
)
5535 && !move_insn_for_shrink_wrap (entry_block
, insn
, uses
, defs
))
5537 /* Add all defined registers to DEFs. */
5538 for (ref
= DF_INSN_DEFS (insn
); *ref
; ref
++)
5540 x
= DF_REF_REG (*ref
);
5541 if (REG_P (x
) && HARD_REGISTER_P (x
))
5542 SET_HARD_REG_BIT (defs
, REGNO (x
));
5545 /* Add all used registers to USESs. */
5546 for (ref
= DF_INSN_USES (insn
); *ref
; ref
++)
5548 x
= DF_REF_REG (*ref
);
5549 if (REG_P (x
) && HARD_REGISTER_P (x
))
5550 SET_HARD_REG_BIT (uses
, REGNO (x
));
5558 /* Insert use of return register before the end of BB. */
5561 emit_use_return_register_into_block (basic_block bb
)
5565 use_return_register ();
5568 emit_insn_before (seq
, BB_END (bb
));
5572 /* Create a return pattern, either simple_return or return, depending on
5576 gen_return_pattern (bool simple_p
)
5578 #ifdef HAVE_simple_return
5579 return simple_p
? gen_simple_return () : gen_return ();
5581 gcc_assert (!simple_p
);
5582 return gen_return ();
5586 /* Insert an appropriate return pattern at the end of block BB. This
5587 also means updating block_for_insn appropriately. SIMPLE_P is
5588 the same as in gen_return_pattern and passed to it. */
5591 emit_return_into_block (bool simple_p
, basic_block bb
)
5594 jump
= emit_jump_insn_after (gen_return_pattern (simple_p
), BB_END (bb
));
5595 pat
= PATTERN (jump
);
5596 if (GET_CODE (pat
) == PARALLEL
)
5597 pat
= XVECEXP (pat
, 0, 0);
5598 gcc_assert (ANY_RETURN_P (pat
));
5599 JUMP_LABEL (jump
) = pat
;
5603 /* Set JUMP_LABEL for a return insn. */
5606 set_return_jump_label (rtx returnjump
)
5608 rtx pat
= PATTERN (returnjump
);
5609 if (GET_CODE (pat
) == PARALLEL
)
5610 pat
= XVECEXP (pat
, 0, 0);
5611 if (ANY_RETURN_P (pat
))
5612 JUMP_LABEL (returnjump
) = pat
;
5614 JUMP_LABEL (returnjump
) = ret_rtx
;
5617 #ifdef HAVE_simple_return
5618 /* Create a copy of BB instructions and insert at BEFORE. Redirect
5619 preds of BB to COPY_BB if they don't appear in NEED_PROLOGUE. */
5621 dup_block_and_redirect (basic_block bb
, basic_block copy_bb
, rtx before
,
5622 bitmap_head
*need_prologue
)
5626 rtx insn
= BB_END (bb
);
5628 /* We know BB has a single successor, so there is no need to copy a
5629 simple jump at the end of BB. */
5630 if (simplejump_p (insn
))
5631 insn
= PREV_INSN (insn
);
5634 duplicate_insn_chain (BB_HEAD (bb
), insn
);
5638 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5639 if (active_insn_p (insn
))
5641 fprintf (dump_file
, "Duplicating bb %d to bb %d, %u active insns.\n",
5642 bb
->index
, copy_bb
->index
, count
);
5644 insn
= get_insns ();
5646 emit_insn_before (insn
, before
);
5648 /* Redirect all the paths that need no prologue into copy_bb. */
5649 for (ei
= ei_start (bb
->preds
); (e
= ei_safe_edge (ei
)); )
5650 if (!bitmap_bit_p (need_prologue
, e
->src
->index
))
5652 redirect_edge_and_branch_force (e
, copy_bb
);
5660 #if defined (HAVE_return) || defined (HAVE_simple_return)
5661 /* Return true if there are any active insns between HEAD and TAIL. */
5663 active_insn_between (rtx head
, rtx tail
)
5667 if (active_insn_p (tail
))
5671 tail
= PREV_INSN (tail
);
5676 /* LAST_BB is a block that exits, and empty of active instructions.
5677 Examine its predecessors for jumps that can be converted to
5678 (conditional) returns. */
5679 static VEC (edge
, heap
) *
5680 convert_jumps_to_returns (basic_block last_bb
, bool simple_p
,
5681 VEC (edge
, heap
) *unconverted ATTRIBUTE_UNUSED
)
5688 VEC(basic_block
,heap
) *src_bbs
;
5690 src_bbs
= VEC_alloc (basic_block
, heap
, EDGE_COUNT (last_bb
->preds
));
5691 FOR_EACH_EDGE (e
, ei
, last_bb
->preds
)
5692 if (e
->src
!= ENTRY_BLOCK_PTR
)
5693 VEC_quick_push (basic_block
, src_bbs
, e
->src
);
5695 label
= BB_HEAD (last_bb
);
5697 FOR_EACH_VEC_ELT (basic_block
, src_bbs
, i
, bb
)
5699 rtx jump
= BB_END (bb
);
5701 if (!JUMP_P (jump
) || JUMP_LABEL (jump
) != label
)
5704 e
= find_edge (bb
, last_bb
);
5706 /* If we have an unconditional jump, we can replace that
5707 with a simple return instruction. */
5708 if (simplejump_p (jump
))
5710 /* The use of the return register might be present in the exit
5711 fallthru block. Either:
5712 - removing the use is safe, and we should remove the use in
5713 the exit fallthru block, or
5714 - removing the use is not safe, and we should add it here.
5715 For now, we conservatively choose the latter. Either of the
5716 2 helps in crossjumping. */
5717 emit_use_return_register_into_block (bb
);
5719 emit_return_into_block (simple_p
, bb
);
5723 /* If we have a conditional jump branching to the last
5724 block, we can try to replace that with a conditional
5725 return instruction. */
5726 else if (condjump_p (jump
))
5731 dest
= simple_return_rtx
;
5734 if (!redirect_jump (jump
, dest
, 0))
5736 #ifdef HAVE_simple_return
5741 "Failed to redirect bb %d branch.\n", bb
->index
);
5742 VEC_safe_push (edge
, heap
, unconverted
, e
);
5748 /* See comment in simplejump_p case above. */
5749 emit_use_return_register_into_block (bb
);
5751 /* If this block has only one successor, it both jumps
5752 and falls through to the fallthru block, so we can't
5754 if (single_succ_p (bb
))
5759 #ifdef HAVE_simple_return
5764 "Failed to redirect bb %d branch.\n", bb
->index
);
5765 VEC_safe_push (edge
, heap
, unconverted
, e
);
5771 /* Fix up the CFG for the successful change we just made. */
5772 redirect_edge_succ (e
, EXIT_BLOCK_PTR
);
5773 e
->flags
&= ~EDGE_CROSSING
;
5775 VEC_free (basic_block
, heap
, src_bbs
);
5779 /* Emit a return insn for the exit fallthru block. */
5781 emit_return_for_exit (edge exit_fallthru_edge
, bool simple_p
)
5783 basic_block last_bb
= exit_fallthru_edge
->src
;
5785 if (JUMP_P (BB_END (last_bb
)))
5787 last_bb
= split_edge (exit_fallthru_edge
);
5788 exit_fallthru_edge
= single_succ_edge (last_bb
);
5790 emit_barrier_after (BB_END (last_bb
));
5791 emit_return_into_block (simple_p
, last_bb
);
5792 exit_fallthru_edge
->flags
&= ~EDGE_FALLTHRU
;
5798 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5799 this into place with notes indicating where the prologue ends and where
5800 the epilogue begins. Update the basic block information when possible.
5802 Notes on epilogue placement:
5803 There are several kinds of edges to the exit block:
5804 * a single fallthru edge from LAST_BB
5805 * possibly, edges from blocks containing sibcalls
5806 * possibly, fake edges from infinite loops
5808 The epilogue is always emitted on the fallthru edge from the last basic
5809 block in the function, LAST_BB, into the exit block.
5811 If LAST_BB is empty except for a label, it is the target of every
5812 other basic block in the function that ends in a return. If a
5813 target has a return or simple_return pattern (possibly with
5814 conditional variants), these basic blocks can be changed so that a
5815 return insn is emitted into them, and their target is adjusted to
5816 the real exit block.
5818 Notes on shrink wrapping: We implement a fairly conservative
5819 version of shrink-wrapping rather than the textbook one. We only
5820 generate a single prologue and a single epilogue. This is
5821 sufficient to catch a number of interesting cases involving early
5824 First, we identify the blocks that require the prologue to occur before
5825 them. These are the ones that modify a call-saved register, or reference
5826 any of the stack or frame pointer registers. To simplify things, we then
5827 mark everything reachable from these blocks as also requiring a prologue.
5828 This takes care of loops automatically, and avoids the need to examine
5829 whether MEMs reference the frame, since it is sufficient to check for
5830 occurrences of the stack or frame pointer.
5832 We then compute the set of blocks for which the need for a prologue
5833 is anticipatable (borrowing terminology from the shrink-wrapping
5834 description in Muchnick's book). These are the blocks which either
5835 require a prologue themselves, or those that have only successors
5836 where the prologue is anticipatable. The prologue needs to be
5837 inserted on all edges from BB1->BB2 where BB2 is in ANTIC and BB1
5838 is not. For the moment, we ensure that only one such edge exists.
5840 The epilogue is placed as described above, but we make a
5841 distinction between inserting return and simple_return patterns
5842 when modifying other blocks that end in a return. Blocks that end
5843 in a sibcall omit the sibcall_epilogue if the block is not in
5847 thread_prologue_and_epilogue_insns (void)
5850 #ifdef HAVE_simple_return
5851 VEC (edge
, heap
) *unconverted_simple_returns
= NULL
;
5852 bool nonempty_prologue
;
5853 bitmap_head bb_flags
;
5854 unsigned max_grow_size
;
5857 rtx seq ATTRIBUTE_UNUSED
, epilogue_end ATTRIBUTE_UNUSED
;
5858 rtx prologue_seq ATTRIBUTE_UNUSED
, split_prologue_seq ATTRIBUTE_UNUSED
;
5859 edge e
, entry_edge
, orig_entry_edge
, exit_fallthru_edge
;
5864 rtl_profile_for_bb (ENTRY_BLOCK_PTR
);
5868 epilogue_end
= NULL_RTX
;
5869 returnjump
= NULL_RTX
;
5871 /* Can't deal with multiple successors of the entry block at the
5872 moment. Function should always have at least one entry
5874 gcc_assert (single_succ_p (ENTRY_BLOCK_PTR
));
5875 entry_edge
= single_succ_edge (ENTRY_BLOCK_PTR
);
5876 orig_entry_edge
= entry_edge
;
5878 split_prologue_seq
= NULL_RTX
;
5879 if (flag_split_stack
5880 && (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun
->decl
))
5883 #ifndef HAVE_split_stack_prologue
5886 gcc_assert (HAVE_split_stack_prologue
);
5889 emit_insn (gen_split_stack_prologue ());
5890 split_prologue_seq
= get_insns ();
5893 record_insns (split_prologue_seq
, NULL
, &prologue_insn_hash
);
5894 set_insn_locators (split_prologue_seq
, prologue_locator
);
5898 prologue_seq
= NULL_RTX
;
5899 #ifdef HAVE_prologue
5903 seq
= gen_prologue ();
5906 /* Insert an explicit USE for the frame pointer
5907 if the profiling is on and the frame pointer is required. */
5908 if (crtl
->profile
&& frame_pointer_needed
)
5909 emit_use (hard_frame_pointer_rtx
);
5911 /* Retain a map of the prologue insns. */
5912 record_insns (seq
, NULL
, &prologue_insn_hash
);
5913 emit_note (NOTE_INSN_PROLOGUE_END
);
5915 /* Ensure that instructions are not moved into the prologue when
5916 profiling is on. The call to the profiling routine can be
5917 emitted within the live range of a call-clobbered register. */
5918 if (!targetm
.profile_before_prologue () && crtl
->profile
)
5919 emit_insn (gen_blockage ());
5921 prologue_seq
= get_insns ();
5923 set_insn_locators (prologue_seq
, prologue_locator
);
5927 #ifdef HAVE_simple_return
5928 bitmap_initialize (&bb_flags
, &bitmap_default_obstack
);
5930 /* Try to perform a kind of shrink-wrapping, making sure the
5931 prologue/epilogue is emitted only around those parts of the
5932 function that require it. */
5934 nonempty_prologue
= false;
5935 for (seq
= prologue_seq
; seq
; seq
= NEXT_INSN (seq
))
5936 if (!NOTE_P (seq
) || NOTE_KIND (seq
) != NOTE_INSN_PROLOGUE_END
)
5938 nonempty_prologue
= true;
5942 if (flag_shrink_wrap
&& HAVE_simple_return
5943 && (targetm
.profile_before_prologue () || !crtl
->profile
)
5944 && nonempty_prologue
&& !crtl
->calls_eh_return
)
5946 HARD_REG_SET prologue_clobbered
, prologue_used
, live_on_edge
;
5947 struct hard_reg_set_container set_up_by_prologue
;
5949 VEC(basic_block
, heap
) *vec
;
5951 bitmap_head bb_antic_flags
;
5952 bitmap_head bb_on_list
;
5953 bitmap_head bb_tail
;
5956 fprintf (dump_file
, "Attempting shrink-wrapping optimization.\n");
5958 /* Compute the registers set and used in the prologue. */
5959 CLEAR_HARD_REG_SET (prologue_clobbered
);
5960 CLEAR_HARD_REG_SET (prologue_used
);
5961 for (p_insn
= prologue_seq
; p_insn
; p_insn
= NEXT_INSN (p_insn
))
5963 HARD_REG_SET this_used
;
5964 if (!NONDEBUG_INSN_P (p_insn
))
5967 CLEAR_HARD_REG_SET (this_used
);
5968 note_uses (&PATTERN (p_insn
), record_hard_reg_uses
,
5970 AND_COMPL_HARD_REG_SET (this_used
, prologue_clobbered
);
5971 IOR_HARD_REG_SET (prologue_used
, this_used
);
5972 note_stores (PATTERN (p_insn
), record_hard_reg_sets
,
5973 &prologue_clobbered
);
5976 prepare_shrink_wrap (entry_edge
->dest
);
5978 bitmap_initialize (&bb_antic_flags
, &bitmap_default_obstack
);
5979 bitmap_initialize (&bb_on_list
, &bitmap_default_obstack
);
5980 bitmap_initialize (&bb_tail
, &bitmap_default_obstack
);
5982 /* Find the set of basic blocks that require a stack frame,
5983 and blocks that are too big to be duplicated. */
5985 vec
= VEC_alloc (basic_block
, heap
, n_basic_blocks
);
5987 CLEAR_HARD_REG_SET (set_up_by_prologue
.set
);
5988 add_to_hard_reg_set (&set_up_by_prologue
.set
, Pmode
,
5989 STACK_POINTER_REGNUM
);
5990 add_to_hard_reg_set (&set_up_by_prologue
.set
, Pmode
, ARG_POINTER_REGNUM
);
5991 if (frame_pointer_needed
)
5992 add_to_hard_reg_set (&set_up_by_prologue
.set
, Pmode
,
5993 HARD_FRAME_POINTER_REGNUM
);
5994 if (pic_offset_table_rtx
)
5995 add_to_hard_reg_set (&set_up_by_prologue
.set
, Pmode
,
5996 PIC_OFFSET_TABLE_REGNUM
);
5997 if (stack_realign_drap
&& crtl
->drap_reg
)
5998 add_to_hard_reg_set (&set_up_by_prologue
.set
,
5999 GET_MODE (crtl
->drap_reg
),
6000 REGNO (crtl
->drap_reg
));
6001 if (targetm
.set_up_by_prologue
)
6002 targetm
.set_up_by_prologue (&set_up_by_prologue
);
6004 /* We don't use a different max size depending on
6005 optimize_bb_for_speed_p because increasing shrink-wrapping
6006 opportunities by duplicating tail blocks can actually result
6007 in an overall decrease in code size. */
6008 max_grow_size
= get_uncond_jump_length ();
6009 max_grow_size
*= PARAM_VALUE (PARAM_MAX_GROW_COPY_BB_INSNS
);
6016 FOR_BB_INSNS (bb
, insn
)
6017 if (NONDEBUG_INSN_P (insn
))
6019 if (requires_stack_frame_p (insn
, prologue_used
,
6020 set_up_by_prologue
.set
))
6022 if (bb
== entry_edge
->dest
)
6023 goto fail_shrinkwrap
;
6024 bitmap_set_bit (&bb_flags
, bb
->index
);
6025 VEC_quick_push (basic_block
, vec
, bb
);
6028 else if (size
<= max_grow_size
)
6030 size
+= get_attr_min_length (insn
);
6031 if (size
> max_grow_size
)
6032 bitmap_set_bit (&bb_on_list
, bb
->index
);
6037 /* Blocks that really need a prologue, or are too big for tails. */
6038 bitmap_ior_into (&bb_on_list
, &bb_flags
);
6040 /* For every basic block that needs a prologue, mark all blocks
6041 reachable from it, so as to ensure they are also seen as
6042 requiring a prologue. */
6043 while (!VEC_empty (basic_block
, vec
))
6045 basic_block tmp_bb
= VEC_pop (basic_block
, vec
);
6047 FOR_EACH_EDGE (e
, ei
, tmp_bb
->succs
)
6048 if (e
->dest
!= EXIT_BLOCK_PTR
6049 && bitmap_set_bit (&bb_flags
, e
->dest
->index
))
6050 VEC_quick_push (basic_block
, vec
, e
->dest
);
6053 /* Find the set of basic blocks that need no prologue, have a
6054 single successor, can be duplicated, meet a max size
6055 requirement, and go to the exit via like blocks. */
6056 VEC_quick_push (basic_block
, vec
, EXIT_BLOCK_PTR
);
6057 while (!VEC_empty (basic_block
, vec
))
6059 basic_block tmp_bb
= VEC_pop (basic_block
, vec
);
6061 FOR_EACH_EDGE (e
, ei
, tmp_bb
->preds
)
6062 if (single_succ_p (e
->src
)
6063 && !bitmap_bit_p (&bb_on_list
, e
->src
->index
)
6064 && can_duplicate_block_p (e
->src
))
6069 /* If there is predecessor of e->src which doesn't
6070 need prologue and the edge is complex,
6071 we might not be able to redirect the branch
6072 to a copy of e->src. */
6073 FOR_EACH_EDGE (pe
, pei
, e
->src
->preds
)
6074 if ((pe
->flags
& EDGE_COMPLEX
) != 0
6075 && !bitmap_bit_p (&bb_flags
, pe
->src
->index
))
6077 if (pe
== NULL
&& bitmap_set_bit (&bb_tail
, e
->src
->index
))
6078 VEC_quick_push (basic_block
, vec
, e
->src
);
6082 /* Now walk backwards from every block that is marked as needing
6083 a prologue to compute the bb_antic_flags bitmap. Exclude
6084 tail blocks; They can be duplicated to be used on paths not
6085 needing a prologue. */
6086 bitmap_clear (&bb_on_list
);
6087 bitmap_and_compl (&bb_antic_flags
, &bb_flags
, &bb_tail
);
6090 if (!bitmap_bit_p (&bb_antic_flags
, bb
->index
))
6092 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6093 if (!bitmap_bit_p (&bb_antic_flags
, e
->src
->index
)
6094 && bitmap_set_bit (&bb_on_list
, e
->src
->index
))
6095 VEC_quick_push (basic_block
, vec
, e
->src
);
6097 while (!VEC_empty (basic_block
, vec
))
6099 basic_block tmp_bb
= VEC_pop (basic_block
, vec
);
6100 bool all_set
= true;
6102 bitmap_clear_bit (&bb_on_list
, tmp_bb
->index
);
6103 FOR_EACH_EDGE (e
, ei
, tmp_bb
->succs
)
6104 if (!bitmap_bit_p (&bb_antic_flags
, e
->dest
->index
))
6112 bitmap_set_bit (&bb_antic_flags
, tmp_bb
->index
);
6113 FOR_EACH_EDGE (e
, ei
, tmp_bb
->preds
)
6114 if (!bitmap_bit_p (&bb_antic_flags
, e
->src
->index
)
6115 && bitmap_set_bit (&bb_on_list
, e
->src
->index
))
6116 VEC_quick_push (basic_block
, vec
, e
->src
);
6119 /* Find exactly one edge that leads to a block in ANTIC from
6120 a block that isn't. */
6121 if (!bitmap_bit_p (&bb_antic_flags
, entry_edge
->dest
->index
))
6124 if (!bitmap_bit_p (&bb_antic_flags
, bb
->index
))
6126 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6127 if (!bitmap_bit_p (&bb_antic_flags
, e
->src
->index
))
6129 if (entry_edge
!= orig_entry_edge
)
6131 entry_edge
= orig_entry_edge
;
6133 fprintf (dump_file
, "More than one candidate edge.\n");
6134 goto fail_shrinkwrap
;
6137 fprintf (dump_file
, "Found candidate edge for "
6138 "shrink-wrapping, %d->%d.\n", e
->src
->index
,
6144 if (entry_edge
!= orig_entry_edge
)
6146 /* Test whether the prologue is known to clobber any register
6147 (other than FP or SP) which are live on the edge. */
6148 CLEAR_HARD_REG_BIT (prologue_clobbered
, STACK_POINTER_REGNUM
);
6149 if (frame_pointer_needed
)
6150 CLEAR_HARD_REG_BIT (prologue_clobbered
, HARD_FRAME_POINTER_REGNUM
);
6151 CLEAR_HARD_REG_SET (live_on_edge
);
6152 reg_set_to_hard_reg_set (&live_on_edge
,
6153 df_get_live_in (entry_edge
->dest
));
6154 if (hard_reg_set_intersect_p (live_on_edge
, prologue_clobbered
))
6156 entry_edge
= orig_entry_edge
;
6159 "Shrink-wrapping aborted due to clobber.\n");
6162 if (entry_edge
!= orig_entry_edge
)
6164 crtl
->shrink_wrapped
= true;
6166 fprintf (dump_file
, "Performing shrink-wrapping.\n");
6168 /* Find tail blocks reachable from both blocks needing a
6169 prologue and blocks not needing a prologue. */
6170 if (!bitmap_empty_p (&bb_tail
))
6173 bool some_pro
, some_no_pro
;
6174 if (!bitmap_bit_p (&bb_tail
, bb
->index
))
6176 some_pro
= some_no_pro
= false;
6177 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6179 if (bitmap_bit_p (&bb_flags
, e
->src
->index
))
6184 if (some_pro
&& some_no_pro
)
6185 VEC_quick_push (basic_block
, vec
, bb
);
6187 bitmap_clear_bit (&bb_tail
, bb
->index
);
6189 /* Find the head of each tail. */
6190 while (!VEC_empty (basic_block
, vec
))
6192 basic_block tbb
= VEC_pop (basic_block
, vec
);
6194 if (!bitmap_bit_p (&bb_tail
, tbb
->index
))
6197 while (single_succ_p (tbb
))
6199 tbb
= single_succ (tbb
);
6200 bitmap_clear_bit (&bb_tail
, tbb
->index
);
6203 /* Now duplicate the tails. */
6204 if (!bitmap_empty_p (&bb_tail
))
6205 FOR_EACH_BB_REVERSE (bb
)
6207 basic_block copy_bb
, tbb
;
6211 if (!bitmap_clear_bit (&bb_tail
, bb
->index
))
6214 /* Create a copy of BB, instructions and all, for
6215 use on paths that don't need a prologue.
6216 Ideal placement of the copy is on a fall-thru edge
6217 or after a block that would jump to the copy. */
6218 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
6219 if (!bitmap_bit_p (&bb_flags
, e
->src
->index
)
6220 && single_succ_p (e
->src
))
6224 copy_bb
= create_basic_block (NEXT_INSN (BB_END (e
->src
)),
6226 BB_COPY_PARTITION (copy_bb
, e
->src
);
6230 /* Otherwise put the copy at the end of the function. */
6231 copy_bb
= create_basic_block (NULL_RTX
, NULL_RTX
,
6232 EXIT_BLOCK_PTR
->prev_bb
);
6233 BB_COPY_PARTITION (copy_bb
, bb
);
6236 insert_point
= emit_note_after (NOTE_INSN_DELETED
,
6238 emit_barrier_after (BB_END (copy_bb
));
6243 dup_block_and_redirect (tbb
, copy_bb
, insert_point
,
6245 tbb
= single_succ (tbb
);
6246 if (tbb
== EXIT_BLOCK_PTR
)
6248 e
= split_block (copy_bb
, PREV_INSN (insert_point
));
6252 /* Quiet verify_flow_info by (ab)using EDGE_FAKE.
6253 We have yet to add a simple_return to the tails,
6254 as we'd like to first convert_jumps_to_returns in
6255 case the block is no longer used after that. */
6257 if (CALL_P (PREV_INSN (insert_point
))
6258 && SIBLING_CALL_P (PREV_INSN (insert_point
)))
6259 eflags
= EDGE_SIBCALL
| EDGE_ABNORMAL
;
6260 make_single_succ_edge (copy_bb
, EXIT_BLOCK_PTR
, eflags
);
6262 /* verify_flow_info doesn't like a note after a
6264 delete_insn (insert_point
);
6265 if (bitmap_empty_p (&bb_tail
))
6271 bitmap_clear (&bb_tail
);
6272 bitmap_clear (&bb_antic_flags
);
6273 bitmap_clear (&bb_on_list
);
6274 VEC_free (basic_block
, heap
, vec
);
6278 if (split_prologue_seq
!= NULL_RTX
)
6280 insert_insn_on_edge (split_prologue_seq
, orig_entry_edge
);
6283 if (prologue_seq
!= NULL_RTX
)
6285 insert_insn_on_edge (prologue_seq
, entry_edge
);
6289 /* If the exit block has no non-fake predecessors, we don't need
6291 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
6292 if ((e
->flags
& EDGE_FAKE
) == 0)
6297 rtl_profile_for_bb (EXIT_BLOCK_PTR
);
6299 exit_fallthru_edge
= find_fallthru_edge (EXIT_BLOCK_PTR
->preds
);
6301 /* If we're allowed to generate a simple return instruction, then by
6302 definition we don't need a full epilogue. If the last basic
6303 block before the exit block does not contain active instructions,
6304 examine its predecessors and try to emit (conditional) return
6306 #ifdef HAVE_simple_return
6307 if (entry_edge
!= orig_entry_edge
)
6313 /* convert_jumps_to_returns may add to EXIT_BLOCK_PTR->preds
6314 (but won't remove). Stop at end of current preds. */
6315 last
= EDGE_COUNT (EXIT_BLOCK_PTR
->preds
);
6316 for (i
= 0; i
< last
; i
++)
6318 e
= EDGE_I (EXIT_BLOCK_PTR
->preds
, i
);
6319 if (LABEL_P (BB_HEAD (e
->src
))
6320 && !bitmap_bit_p (&bb_flags
, e
->src
->index
)
6321 && !active_insn_between (BB_HEAD (e
->src
), BB_END (e
->src
)))
6322 unconverted_simple_returns
6323 = convert_jumps_to_returns (e
->src
, true,
6324 unconverted_simple_returns
);
6328 if (exit_fallthru_edge
!= NULL
6329 && EDGE_COUNT (exit_fallthru_edge
->src
->preds
) != 0
6330 && !bitmap_bit_p (&bb_flags
, exit_fallthru_edge
->src
->index
))
6332 basic_block last_bb
;
6334 last_bb
= emit_return_for_exit (exit_fallthru_edge
, true);
6335 returnjump
= BB_END (last_bb
);
6336 exit_fallthru_edge
= NULL
;
6343 if (exit_fallthru_edge
== NULL
)
6348 basic_block last_bb
= exit_fallthru_edge
->src
;
6350 if (LABEL_P (BB_HEAD (last_bb
))
6351 && !active_insn_between (BB_HEAD (last_bb
), BB_END (last_bb
)))
6352 convert_jumps_to_returns (last_bb
, false, NULL
);
6354 if (EDGE_COUNT (last_bb
->preds
) != 0
6355 && single_succ_p (last_bb
))
6357 last_bb
= emit_return_for_exit (exit_fallthru_edge
, false);
6358 epilogue_end
= returnjump
= BB_END (last_bb
);
6359 #ifdef HAVE_simple_return
6360 /* Emitting the return may add a basic block.
6361 Fix bb_flags for the added block. */
6362 if (last_bb
!= exit_fallthru_edge
->src
)
6363 bitmap_set_bit (&bb_flags
, last_bb
->index
);
6371 /* A small fib -- epilogue is not yet completed, but we wish to re-use
6372 this marker for the splits of EH_RETURN patterns, and nothing else
6373 uses the flag in the meantime. */
6374 epilogue_completed
= 1;
6376 #ifdef HAVE_eh_return
6377 /* Find non-fallthru edges that end with EH_RETURN instructions. On
6378 some targets, these get split to a special version of the epilogue
6379 code. In order to be able to properly annotate these with unwind
6380 info, try to split them now. If we get a valid split, drop an
6381 EPILOGUE_BEG note and mark the insns as epilogue insns. */
6382 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
6384 rtx prev
, last
, trial
;
6386 if (e
->flags
& EDGE_FALLTHRU
)
6388 last
= BB_END (e
->src
);
6389 if (!eh_returnjump_p (last
))
6392 prev
= PREV_INSN (last
);
6393 trial
= try_split (PATTERN (last
), last
, 1);
6397 record_insns (NEXT_INSN (prev
), NEXT_INSN (trial
), &epilogue_insn_hash
);
6398 emit_note_after (NOTE_INSN_EPILOGUE_BEG
, prev
);
6402 /* If nothing falls through into the exit block, we don't need an
6405 if (exit_fallthru_edge
== NULL
)
6408 #ifdef HAVE_epilogue
6412 epilogue_end
= emit_note (NOTE_INSN_EPILOGUE_BEG
);
6413 seq
= gen_epilogue ();
6415 emit_jump_insn (seq
);
6417 /* Retain a map of the epilogue insns. */
6418 record_insns (seq
, NULL
, &epilogue_insn_hash
);
6419 set_insn_locators (seq
, epilogue_locator
);
6422 returnjump
= get_last_insn ();
6425 insert_insn_on_edge (seq
, exit_fallthru_edge
);
6428 if (JUMP_P (returnjump
))
6429 set_return_jump_label (returnjump
);
6436 if (! next_active_insn (BB_END (exit_fallthru_edge
->src
)))
6438 /* We have a fall-through edge to the exit block, the source is not
6439 at the end of the function, and there will be an assembler epilogue
6440 at the end of the function.
6441 We can't use force_nonfallthru here, because that would try to
6442 use return. Inserting a jump 'by hand' is extremely messy, so
6443 we take advantage of cfg_layout_finalize using
6444 fixup_fallthru_exit_predecessor. */
6445 cfg_layout_initialize (0);
6446 FOR_EACH_BB (cur_bb
)
6447 if (cur_bb
->index
>= NUM_FIXED_BLOCKS
6448 && cur_bb
->next_bb
->index
>= NUM_FIXED_BLOCKS
)
6449 cur_bb
->aux
= cur_bb
->next_bb
;
6450 cfg_layout_finalize ();
6455 default_rtl_profile ();
6461 commit_edge_insertions ();
6463 /* Look for basic blocks within the prologue insns. */
6464 blocks
= sbitmap_alloc (last_basic_block
);
6465 sbitmap_zero (blocks
);
6466 SET_BIT (blocks
, entry_edge
->dest
->index
);
6467 SET_BIT (blocks
, orig_entry_edge
->dest
->index
);
6468 find_many_sub_basic_blocks (blocks
);
6469 sbitmap_free (blocks
);
6471 /* The epilogue insns we inserted may cause the exit edge to no longer
6473 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
6475 if (((e
->flags
& EDGE_FALLTHRU
) != 0)
6476 && returnjump_p (BB_END (e
->src
)))
6477 e
->flags
&= ~EDGE_FALLTHRU
;
6481 #ifdef HAVE_simple_return
6482 /* If there were branches to an empty LAST_BB which we tried to
6483 convert to conditional simple_returns, but couldn't for some
6484 reason, create a block to hold a simple_return insn and redirect
6485 those remaining edges. */
6486 if (!VEC_empty (edge
, unconverted_simple_returns
))
6488 basic_block simple_return_block_hot
= NULL
;
6489 basic_block simple_return_block_cold
= NULL
;
6490 edge pending_edge_hot
= NULL
;
6491 edge pending_edge_cold
= NULL
;
6492 basic_block exit_pred
= EXIT_BLOCK_PTR
->prev_bb
;
6495 gcc_assert (entry_edge
!= orig_entry_edge
);
6497 /* See if we can reuse the last insn that was emitted for the
6499 if (returnjump
!= NULL_RTX
6500 && JUMP_LABEL (returnjump
) == simple_return_rtx
)
6502 e
= split_block (BLOCK_FOR_INSN (returnjump
), PREV_INSN (returnjump
));
6503 if (BB_PARTITION (e
->src
) == BB_HOT_PARTITION
)
6504 simple_return_block_hot
= e
->dest
;
6506 simple_return_block_cold
= e
->dest
;
6509 /* Also check returns we might need to add to tail blocks. */
6510 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
6511 if (EDGE_COUNT (e
->src
->preds
) != 0
6512 && (e
->flags
& EDGE_FAKE
) != 0
6513 && !bitmap_bit_p (&bb_flags
, e
->src
->index
))
6515 if (BB_PARTITION (e
->src
) == BB_HOT_PARTITION
)
6516 pending_edge_hot
= e
;
6518 pending_edge_cold
= e
;
6521 FOR_EACH_VEC_ELT (edge
, unconverted_simple_returns
, i
, e
)
6523 basic_block
*pdest_bb
;
6526 if (BB_PARTITION (e
->src
) == BB_HOT_PARTITION
)
6528 pdest_bb
= &simple_return_block_hot
;
6529 pending
= pending_edge_hot
;
6533 pdest_bb
= &simple_return_block_cold
;
6534 pending
= pending_edge_cold
;
6537 if (*pdest_bb
== NULL
&& pending
!= NULL
)
6539 emit_return_into_block (true, pending
->src
);
6540 pending
->flags
&= ~(EDGE_FALLTHRU
| EDGE_FAKE
);
6541 *pdest_bb
= pending
->src
;
6543 else if (*pdest_bb
== NULL
)
6548 bb
= create_basic_block (NULL
, NULL
, exit_pred
);
6549 BB_COPY_PARTITION (bb
, e
->src
);
6550 start
= emit_jump_insn_after (gen_simple_return (),
6552 JUMP_LABEL (start
) = simple_return_rtx
;
6553 emit_barrier_after (start
);
6556 make_edge (bb
, EXIT_BLOCK_PTR
, 0);
6558 redirect_edge_and_branch_force (e
, *pdest_bb
);
6560 VEC_free (edge
, heap
, unconverted_simple_returns
);
6563 if (entry_edge
!= orig_entry_edge
)
6565 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
6566 if (EDGE_COUNT (e
->src
->preds
) != 0
6567 && (e
->flags
& EDGE_FAKE
) != 0
6568 && !bitmap_bit_p (&bb_flags
, e
->src
->index
))
6570 emit_return_into_block (true, e
->src
);
6571 e
->flags
&= ~(EDGE_FALLTHRU
| EDGE_FAKE
);
6576 #ifdef HAVE_sibcall_epilogue
6577 /* Emit sibling epilogues before any sibling call sites. */
6578 for (ei
= ei_start (EXIT_BLOCK_PTR
->preds
); (e
= ei_safe_edge (ei
)); )
6580 basic_block bb
= e
->src
;
6581 rtx insn
= BB_END (bb
);
6585 || ! SIBLING_CALL_P (insn
)
6586 #ifdef HAVE_simple_return
6587 || (entry_edge
!= orig_entry_edge
6588 && !bitmap_bit_p (&bb_flags
, bb
->index
))
6596 ep_seq
= gen_sibcall_epilogue ();
6600 emit_note (NOTE_INSN_EPILOGUE_BEG
);
6605 /* Retain a map of the epilogue insns. Used in life analysis to
6606 avoid getting rid of sibcall epilogue insns. Do this before we
6607 actually emit the sequence. */
6608 record_insns (seq
, NULL
, &epilogue_insn_hash
);
6609 set_insn_locators (seq
, epilogue_locator
);
6611 emit_insn_before (seq
, insn
);
6617 #ifdef HAVE_epilogue
6622 /* Similarly, move any line notes that appear after the epilogue.
6623 There is no need, however, to be quite so anal about the existence
6624 of such a note. Also possibly move
6625 NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
6627 for (insn
= epilogue_end
; insn
; insn
= next
)
6629 next
= NEXT_INSN (insn
);
6631 && (NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
))
6632 reorder_insns (insn
, insn
, PREV_INSN (epilogue_end
));
6637 #ifdef HAVE_simple_return
6638 bitmap_clear (&bb_flags
);
6641 /* Threading the prologue and epilogue changes the artificial refs
6642 in the entry and exit blocks. */
6643 epilogue_completed
= 1;
6644 df_update_entry_exit_and_calls ();
6647 /* Reposition the prologue-end and epilogue-begin notes after
6648 instruction scheduling. */
6651 reposition_prologue_and_epilogue_notes (void)
6653 #if defined (HAVE_prologue) || defined (HAVE_epilogue) \
6654 || defined (HAVE_sibcall_epilogue)
6655 /* Since the hash table is created on demand, the fact that it is
6656 non-null is a signal that it is non-empty. */
6657 if (prologue_insn_hash
!= NULL
)
6659 size_t len
= htab_elements (prologue_insn_hash
);
6660 rtx insn
, last
= NULL
, note
= NULL
;
6662 /* Scan from the beginning until we reach the last prologue insn. */
6663 /* ??? While we do have the CFG intact, there are two problems:
6664 (1) The prologue can contain loops (typically probing the stack),
6665 which means that the end of the prologue isn't in the first bb.
6666 (2) Sometimes the PROLOGUE_END note gets pushed into the next bb. */
6667 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6671 if (NOTE_KIND (insn
) == NOTE_INSN_PROLOGUE_END
)
6674 else if (contains (insn
, prologue_insn_hash
))
6686 /* Scan forward looking for the PROLOGUE_END note. It should
6687 be right at the beginning of the block, possibly with other
6688 insn notes that got moved there. */
6689 for (note
= NEXT_INSN (last
); ; note
= NEXT_INSN (note
))
6692 && NOTE_KIND (note
) == NOTE_INSN_PROLOGUE_END
)
6697 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
6699 last
= NEXT_INSN (last
);
6700 reorder_insns (note
, note
, last
);
6704 if (epilogue_insn_hash
!= NULL
)
6709 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR
->preds
)
6711 rtx insn
, first
= NULL
, note
= NULL
;
6712 basic_block bb
= e
->src
;
6714 /* Scan from the beginning until we reach the first epilogue insn. */
6715 FOR_BB_INSNS (bb
, insn
)
6719 if (NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
6726 else if (first
== NULL
&& contains (insn
, epilogue_insn_hash
))
6736 /* If the function has a single basic block, and no real
6737 epilogue insns (e.g. sibcall with no cleanup), the
6738 epilogue note can get scheduled before the prologue
6739 note. If we have frame related prologue insns, having
6740 them scanned during the epilogue will result in a crash.
6741 In this case re-order the epilogue note to just before
6742 the last insn in the block. */
6744 first
= BB_END (bb
);
6746 if (PREV_INSN (first
) != note
)
6747 reorder_insns (note
, note
, PREV_INSN (first
));
6751 #endif /* HAVE_prologue or HAVE_epilogue */
6754 /* Returns the name of the current function. */
6756 current_function_name (void)
6760 return lang_hooks
.decl_printable_name (cfun
->decl
, 2);
6765 rest_of_handle_check_leaf_regs (void)
6767 #ifdef LEAF_REGISTERS
6768 current_function_uses_only_leaf_regs
6769 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
6774 /* Insert a TYPE into the used types hash table of CFUN. */
6777 used_types_insert_helper (tree type
, struct function
*func
)
6779 if (type
!= NULL
&& func
!= NULL
)
6783 if (func
->used_types_hash
== NULL
)
6784 func
->used_types_hash
= htab_create_ggc (37, htab_hash_pointer
,
6785 htab_eq_pointer
, NULL
);
6786 slot
= htab_find_slot (func
->used_types_hash
, type
, INSERT
);
6792 /* Given a type, insert it into the used hash table in cfun. */
6794 used_types_insert (tree t
)
6796 while (POINTER_TYPE_P (t
) || TREE_CODE (t
) == ARRAY_TYPE
)
6801 if (TREE_CODE (t
) == ERROR_MARK
)
6803 if (TYPE_NAME (t
) == NULL_TREE
6804 || TYPE_NAME (t
) == TYPE_NAME (TYPE_MAIN_VARIANT (t
)))
6805 t
= TYPE_MAIN_VARIANT (t
);
6806 if (debug_info_level
> DINFO_LEVEL_NONE
)
6809 used_types_insert_helper (t
, cfun
);
6811 /* So this might be a type referenced by a global variable.
6812 Record that type so that we can later decide to emit its debug
6814 VEC_safe_push (tree
, gc
, types_used_by_cur_var_decl
, t
);
6818 /* Helper to Hash a struct types_used_by_vars_entry. */
6821 hash_types_used_by_vars_entry (const struct types_used_by_vars_entry
*entry
)
6823 gcc_assert (entry
&& entry
->var_decl
&& entry
->type
);
6825 return iterative_hash_object (entry
->type
,
6826 iterative_hash_object (entry
->var_decl
, 0));
6829 /* Hash function of the types_used_by_vars_entry hash table. */
6832 types_used_by_vars_do_hash (const void *x
)
6834 const struct types_used_by_vars_entry
*entry
=
6835 (const struct types_used_by_vars_entry
*) x
;
6837 return hash_types_used_by_vars_entry (entry
);
6840 /*Equality function of the types_used_by_vars_entry hash table. */
6843 types_used_by_vars_eq (const void *x1
, const void *x2
)
6845 const struct types_used_by_vars_entry
*e1
=
6846 (const struct types_used_by_vars_entry
*) x1
;
6847 const struct types_used_by_vars_entry
*e2
=
6848 (const struct types_used_by_vars_entry
*)x2
;
6850 return (e1
->var_decl
== e2
->var_decl
&& e1
->type
== e2
->type
);
6853 /* Inserts an entry into the types_used_by_vars_hash hash table. */
6856 types_used_by_var_decl_insert (tree type
, tree var_decl
)
6858 if (type
!= NULL
&& var_decl
!= NULL
)
6861 struct types_used_by_vars_entry e
;
6862 e
.var_decl
= var_decl
;
6864 if (types_used_by_vars_hash
== NULL
)
6865 types_used_by_vars_hash
=
6866 htab_create_ggc (37, types_used_by_vars_do_hash
,
6867 types_used_by_vars_eq
, NULL
);
6868 slot
= htab_find_slot_with_hash (types_used_by_vars_hash
, &e
,
6869 hash_types_used_by_vars_entry (&e
), INSERT
);
6872 struct types_used_by_vars_entry
*entry
;
6873 entry
= ggc_alloc_types_used_by_vars_entry ();
6875 entry
->var_decl
= var_decl
;
6881 struct rtl_opt_pass pass_leaf_regs
=
6885 "*leaf_regs", /* name */
6887 rest_of_handle_check_leaf_regs
, /* execute */
6890 0, /* static_pass_number */
6891 TV_NONE
, /* tv_id */
6892 0, /* properties_required */
6893 0, /* properties_provided */
6894 0, /* properties_destroyed */
6895 0, /* todo_flags_start */
6896 0 /* todo_flags_finish */
6901 rest_of_handle_thread_prologue_and_epilogue (void)
6904 cleanup_cfg (CLEANUP_EXPENSIVE
);
6906 /* On some machines, the prologue and epilogue code, or parts thereof,
6907 can be represented as RTL. Doing so lets us schedule insns between
6908 it and the rest of the code and also allows delayed branch
6909 scheduling to operate in the epilogue. */
6910 thread_prologue_and_epilogue_insns ();
6912 /* The stack usage info is finalized during prologue expansion. */
6913 if (flag_stack_usage_info
)
6914 output_stack_usage ();
6919 struct rtl_opt_pass pass_thread_prologue_and_epilogue
=
6923 "pro_and_epilogue", /* name */
6925 rest_of_handle_thread_prologue_and_epilogue
, /* execute */
6928 0, /* static_pass_number */
6929 TV_THREAD_PROLOGUE_AND_EPILOGUE
, /* tv_id */
6930 0, /* properties_required */
6931 0, /* properties_provided */
6932 0, /* properties_destroyed */
6933 TODO_verify_flow
, /* todo_flags_start */
6935 TODO_df_finish
| TODO_verify_rtl_sharing
|
6936 TODO_ggc_collect
/* todo_flags_finish */
6941 /* This mini-pass fixes fall-out from SSA in asm statements that have
6942 in-out constraints. Say you start with
6945 asm ("": "+mr" (inout));
6948 which is transformed very early to use explicit output and match operands:
6951 asm ("": "=mr" (inout) : "0" (inout));
6954 Or, after SSA and copyprop,
6956 asm ("": "=mr" (inout_2) : "0" (inout_1));
6959 Clearly inout_2 and inout_1 can't be coalesced easily anymore, as
6960 they represent two separate values, so they will get different pseudo
6961 registers during expansion. Then, since the two operands need to match
6962 per the constraints, but use different pseudo registers, reload can
6963 only register a reload for these operands. But reloads can only be
6964 satisfied by hardregs, not by memory, so we need a register for this
6965 reload, just because we are presented with non-matching operands.
6966 So, even though we allow memory for this operand, no memory can be
6967 used for it, just because the two operands don't match. This can
6968 cause reload failures on register-starved targets.
6970 So it's a symptom of reload not being able to use memory for reloads
6971 or, alternatively it's also a symptom of both operands not coming into
6972 reload as matching (in which case the pseudo could go to memory just
6973 fine, as the alternative allows it, and no reload would be necessary).
6974 We fix the latter problem here, by transforming
6976 asm ("": "=mr" (inout_2) : "0" (inout_1));
6981 asm ("": "=mr" (inout_2) : "0" (inout_2)); */
6984 match_asm_constraints_1 (rtx insn
, rtx
*p_sets
, int noutputs
)
6987 bool changed
= false;
6988 rtx op
= SET_SRC (p_sets
[0]);
6989 int ninputs
= ASM_OPERANDS_INPUT_LENGTH (op
);
6990 rtvec inputs
= ASM_OPERANDS_INPUT_VEC (op
);
6991 bool *output_matched
= XALLOCAVEC (bool, noutputs
);
6993 memset (output_matched
, 0, noutputs
* sizeof (bool));
6994 for (i
= 0; i
< ninputs
; i
++)
6996 rtx input
, output
, insns
;
6997 const char *constraint
= ASM_OPERANDS_INPUT_CONSTRAINT (op
, i
);
7001 if (*constraint
== '%')
7004 match
= strtoul (constraint
, &end
, 10);
7005 if (end
== constraint
)
7008 gcc_assert (match
< noutputs
);
7009 output
= SET_DEST (p_sets
[match
]);
7010 input
= RTVEC_ELT (inputs
, i
);
7011 /* Only do the transformation for pseudos. */
7012 if (! REG_P (output
)
7013 || rtx_equal_p (output
, input
)
7014 || (GET_MODE (input
) != VOIDmode
7015 && GET_MODE (input
) != GET_MODE (output
)))
7018 /* We can't do anything if the output is also used as input,
7019 as we're going to overwrite it. */
7020 for (j
= 0; j
< ninputs
; j
++)
7021 if (reg_overlap_mentioned_p (output
, RTVEC_ELT (inputs
, j
)))
7026 /* Avoid changing the same input several times. For
7027 asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in));
7028 only change in once (to out1), rather than changing it
7029 first to out1 and afterwards to out2. */
7032 for (j
= 0; j
< noutputs
; j
++)
7033 if (output_matched
[j
] && input
== SET_DEST (p_sets
[j
]))
7038 output_matched
[match
] = true;
7041 emit_move_insn (output
, input
);
7042 insns
= get_insns ();
7044 emit_insn_before (insns
, insn
);
7046 /* Now replace all mentions of the input with output. We can't
7047 just replace the occurrence in inputs[i], as the register might
7048 also be used in some other input (or even in an address of an
7049 output), which would mean possibly increasing the number of
7050 inputs by one (namely 'output' in addition), which might pose
7051 a too complicated problem for reload to solve. E.g. this situation:
7053 asm ("" : "=r" (output), "=m" (input) : "0" (input))
7055 Here 'input' is used in two occurrences as input (once for the
7056 input operand, once for the address in the second output operand).
7057 If we would replace only the occurrence of the input operand (to
7058 make the matching) we would be left with this:
7061 asm ("" : "=r" (output), "=m" (input) : "0" (output))
7063 Now we suddenly have two different input values (containing the same
7064 value, but different pseudos) where we formerly had only one.
7065 With more complicated asms this might lead to reload failures
7066 which wouldn't have happen without this pass. So, iterate over
7067 all operands and replace all occurrences of the register used. */
7068 for (j
= 0; j
< noutputs
; j
++)
7069 if (!rtx_equal_p (SET_DEST (p_sets
[j
]), input
)
7070 && reg_overlap_mentioned_p (input
, SET_DEST (p_sets
[j
])))
7071 SET_DEST (p_sets
[j
]) = replace_rtx (SET_DEST (p_sets
[j
]),
7073 for (j
= 0; j
< ninputs
; j
++)
7074 if (reg_overlap_mentioned_p (input
, RTVEC_ELT (inputs
, j
)))
7075 RTVEC_ELT (inputs
, j
) = replace_rtx (RTVEC_ELT (inputs
, j
),
7082 df_insn_rescan (insn
);
7086 rest_of_match_asm_constraints (void)
7089 rtx insn
, pat
, *p_sets
;
7092 if (!crtl
->has_asm_statement
)
7095 df_set_flags (DF_DEFER_INSN_RESCAN
);
7098 FOR_BB_INSNS (bb
, insn
)
7103 pat
= PATTERN (insn
);
7104 if (GET_CODE (pat
) == PARALLEL
)
7105 p_sets
= &XVECEXP (pat
, 0, 0), noutputs
= XVECLEN (pat
, 0);
7106 else if (GET_CODE (pat
) == SET
)
7107 p_sets
= &PATTERN (insn
), noutputs
= 1;
7111 if (GET_CODE (*p_sets
) == SET
7112 && GET_CODE (SET_SRC (*p_sets
)) == ASM_OPERANDS
)
7113 match_asm_constraints_1 (insn
, p_sets
, noutputs
);
7117 return TODO_df_finish
;
7120 struct rtl_opt_pass pass_match_asm_constraints
=
7124 "asmcons", /* name */
7126 rest_of_match_asm_constraints
, /* execute */
7129 0, /* static_pass_number */
7130 TV_NONE
, /* tv_id */
7131 0, /* properties_required */
7132 0, /* properties_provided */
7133 0, /* properties_destroyed */
7134 0, /* todo_flags_start */
7135 0 /* todo_flags_finish */
7140 #include "gt-function.h"