1 /* Expands front end tree to back end RTL for GCC.
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file handles the generation of rtl code from tree structure
21 at the level of the function as a whole.
22 It creates the rtl expressions for parameters and auto variables
23 and has full responsibility for allocating stack slots.
25 `expand_function_start' is called at the beginning of a function,
26 before the function body is parsed, and `expand_function_end' is
27 called after parsing the body.
29 Call `assign_stack_local' to allocate a stack slot for a local variable.
30 This is usually done during the RTL generation for the function body,
31 but it can also be done in the reload pass when a pseudo-register does
32 not get a hard register. */
36 #include "coretypes.h"
41 #include "gimple-expr.h"
46 #include "stringpool.h"
52 #include "rtl-error.h"
54 #include "fold-const.h"
55 #include "stor-layout.h"
62 #include "optabs-tree.h"
64 #include "langhooks.h"
65 #include "common/common-target.h"
67 #include "tree-pass.h"
71 #include "cfgcleanup.h"
72 #include "cfgexpand.h"
73 #include "shrink-wrap.h"
78 #include "stringpool.h"
83 /* So we can assign to cfun in this file. */
86 #ifndef STACK_ALIGNMENT_NEEDED
87 #define STACK_ALIGNMENT_NEEDED 1
90 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
92 /* Round a value to the lowest integer less than it that is a multiple of
93 the required alignment. Avoid using division in case the value is
94 negative. Assume the alignment is a power of two. */
95 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
97 /* Similar, but round to the next highest integer that meets the
99 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
101 /* Nonzero once virtual register instantiation has been done.
102 assign_stack_local uses frame_pointer_rtx when this is nonzero.
103 calls.c:emit_library_call_value_1 uses it to set up
104 post-instantiation libcalls. */
105 int virtuals_instantiated
;
107 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
108 static GTY(()) int funcdef_no
;
110 /* These variables hold pointers to functions to create and destroy
111 target specific, per-function data structures. */
112 struct machine_function
* (*init_machine_status
) (void);
114 /* The currently compiled function. */
115 struct function
*cfun
= 0;
117 /* These hashes record the prologue and epilogue insns. */
119 struct insn_cache_hasher
: ggc_cache_ptr_hash
<rtx_def
>
121 static hashval_t
hash (rtx x
) { return htab_hash_pointer (x
); }
122 static bool equal (rtx a
, rtx b
) { return a
== b
; }
126 hash_table
<insn_cache_hasher
> *prologue_insn_hash
;
128 hash_table
<insn_cache_hasher
> *epilogue_insn_hash
;
131 hash_table
<used_type_hasher
> *types_used_by_vars_hash
= NULL
;
132 vec
<tree
, va_gc
> *types_used_by_cur_var_decl
;
134 /* Forward declarations. */
136 static struct temp_slot
*find_temp_slot_from_address (rtx
);
137 static void pad_to_arg_alignment (struct args_size
*, int, struct args_size
*);
138 static void pad_below (struct args_size
*, machine_mode
, tree
);
139 static void reorder_blocks_1 (rtx_insn
*, tree
, vec
<tree
> *);
140 static int all_blocks (tree
, tree
*);
141 static tree
*get_block_vector (tree
, int *);
142 extern tree
debug_find_var_in_block_tree (tree
, tree
);
143 /* We always define `record_insns' even if it's not used so that we
144 can always export `prologue_epilogue_contains'. */
145 static void record_insns (rtx_insn
*, rtx
, hash_table
<insn_cache_hasher
> **)
147 static bool contains (const rtx_insn
*, hash_table
<insn_cache_hasher
> *);
148 static void prepare_function_start (void);
149 static void do_clobber_return_reg (rtx
, void *);
150 static void do_use_return_reg (rtx
, void *);
153 /* Stack of nested functions. */
154 /* Keep track of the cfun stack. */
156 static vec
<function
*> function_context_stack
;
158 /* Save the current context for compilation of a nested function.
159 This is called from language-specific code. */
162 push_function_context (void)
165 allocate_struct_function (NULL
, false);
167 function_context_stack
.safe_push (cfun
);
171 /* Restore the last saved context, at the end of a nested function.
172 This function is called from language-specific code. */
175 pop_function_context (void)
177 struct function
*p
= function_context_stack
.pop ();
179 current_function_decl
= p
->decl
;
181 /* Reset variables that have known state during rtx generation. */
182 virtuals_instantiated
= 0;
183 generating_concat_p
= 1;
186 /* Clear out all parts of the state in F that can safely be discarded
187 after the function has been parsed, but not compiled, to let
188 garbage collection reclaim the memory. */
191 free_after_parsing (struct function
*f
)
196 /* Clear out all parts of the state in F that can safely be discarded
197 after the function has been compiled, to let garbage collection
198 reclaim the memory. */
201 free_after_compilation (struct function
*f
)
203 prologue_insn_hash
= NULL
;
204 epilogue_insn_hash
= NULL
;
206 free (crtl
->emit
.regno_pointer_align
);
208 memset (crtl
, 0, sizeof (struct rtl_data
));
212 f
->curr_properties
&= ~PROP_cfg
;
214 regno_reg_rtx
= NULL
;
217 /* Return size needed for stack frame based on slots so far allocated.
218 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
219 the caller may have to do that. */
222 get_frame_size (void)
224 if (FRAME_GROWS_DOWNWARD
)
225 return -frame_offset
;
230 /* Issue an error message and return TRUE if frame OFFSET overflows in
231 the signed target pointer arithmetics for function FUNC. Otherwise
235 frame_offset_overflow (poly_int64 offset
, tree func
)
237 poly_uint64 size
= FRAME_GROWS_DOWNWARD
? -offset
: offset
;
238 unsigned HOST_WIDE_INT limit
239 = ((HOST_WIDE_INT_1U
<< (GET_MODE_BITSIZE (Pmode
) - 1))
240 /* Leave room for the fixed part of the frame. */
241 - 64 * UNITS_PER_WORD
);
243 if (!coeffs_in_range_p (size
, 0U, limit
))
245 error_at (DECL_SOURCE_LOCATION (func
),
246 "total size of local objects too large");
253 /* Return the minimum spill slot alignment for a register of mode MODE. */
256 spill_slot_alignment (machine_mode mode ATTRIBUTE_UNUSED
)
258 return STACK_SLOT_ALIGNMENT (NULL_TREE
, mode
, GET_MODE_ALIGNMENT (mode
));
261 /* Return stack slot alignment in bits for TYPE and MODE. */
264 get_stack_local_alignment (tree type
, machine_mode mode
)
266 unsigned int alignment
;
269 alignment
= BIGGEST_ALIGNMENT
;
271 alignment
= GET_MODE_ALIGNMENT (mode
);
273 /* Allow the frond-end to (possibly) increase the alignment of this
276 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
278 return STACK_SLOT_ALIGNMENT (type
, mode
, alignment
);
281 /* Determine whether it is possible to fit a stack slot of size SIZE and
282 alignment ALIGNMENT into an area in the stack frame that starts at
283 frame offset START and has a length of LENGTH. If so, store the frame
284 offset to be used for the stack slot in *POFFSET and return true;
285 return false otherwise. This function will extend the frame size when
286 given a start/length pair that lies at the end of the frame. */
289 try_fit_stack_local (poly_int64 start
, poly_int64 length
,
290 poly_int64 size
, unsigned int alignment
,
291 poly_int64_pod
*poffset
)
293 poly_int64 this_frame_offset
;
294 int frame_off
, frame_alignment
, frame_phase
;
296 /* Calculate how many bytes the start of local variables is off from
298 frame_alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
299 frame_off
= targetm
.starting_frame_offset () % frame_alignment
;
300 frame_phase
= frame_off
? frame_alignment
- frame_off
: 0;
302 /* Round the frame offset to the specified alignment. */
304 if (FRAME_GROWS_DOWNWARD
)
306 = (aligned_lower_bound (start
+ length
- size
- frame_phase
, alignment
)
310 = aligned_upper_bound (start
- frame_phase
, alignment
) + frame_phase
;
312 /* See if it fits. If this space is at the edge of the frame,
313 consider extending the frame to make it fit. Our caller relies on
314 this when allocating a new slot. */
315 if (maybe_lt (this_frame_offset
, start
))
317 if (known_eq (frame_offset
, start
))
318 frame_offset
= this_frame_offset
;
322 else if (maybe_gt (this_frame_offset
+ size
, start
+ length
))
324 if (known_eq (frame_offset
, start
+ length
))
325 frame_offset
= this_frame_offset
+ size
;
330 *poffset
= this_frame_offset
;
334 /* Create a new frame_space structure describing free space in the stack
335 frame beginning at START and ending at END, and chain it into the
336 function's frame_space_list. */
339 add_frame_space (poly_int64 start
, poly_int64 end
)
341 struct frame_space
*space
= ggc_alloc
<frame_space
> ();
342 space
->next
= crtl
->frame_space_list
;
343 crtl
->frame_space_list
= space
;
344 space
->start
= start
;
345 space
->length
= end
- start
;
348 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
349 with machine mode MODE.
351 ALIGN controls the amount of alignment for the address of the slot:
352 0 means according to MODE,
353 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
354 -2 means use BITS_PER_UNIT,
355 positive specifies alignment boundary in bits.
357 KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce
358 alignment and ASLK_RECORD_PAD bit set if we should remember
359 extra space we allocated for alignment purposes. When we are
360 called from assign_stack_temp_for_type, it is not set so we don't
361 track the same stack slot in two independent lists.
363 We do not round to stack_boundary here. */
366 assign_stack_local_1 (machine_mode mode
, poly_int64 size
,
370 poly_int64 bigend_correction
= 0;
371 poly_int64 slot_offset
= 0, old_frame_offset
;
372 unsigned int alignment
, alignment_in_bits
;
376 alignment
= get_stack_local_alignment (NULL
, mode
);
377 alignment
/= BITS_PER_UNIT
;
379 else if (align
== -1)
381 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
382 size
= aligned_upper_bound (size
, alignment
);
384 else if (align
== -2)
385 alignment
= 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
387 alignment
= align
/ BITS_PER_UNIT
;
389 alignment_in_bits
= alignment
* BITS_PER_UNIT
;
391 /* Ignore alignment if it exceeds MAX_SUPPORTED_STACK_ALIGNMENT. */
392 if (alignment_in_bits
> MAX_SUPPORTED_STACK_ALIGNMENT
)
394 alignment_in_bits
= MAX_SUPPORTED_STACK_ALIGNMENT
;
395 alignment
= alignment_in_bits
/ BITS_PER_UNIT
;
398 if (SUPPORTS_STACK_ALIGNMENT
)
400 if (crtl
->stack_alignment_estimated
< alignment_in_bits
)
402 if (!crtl
->stack_realign_processed
)
403 crtl
->stack_alignment_estimated
= alignment_in_bits
;
406 /* If stack is realigned and stack alignment value
407 hasn't been finalized, it is OK not to increase
408 stack_alignment_estimated. The bigger alignment
409 requirement is recorded in stack_alignment_needed
411 gcc_assert (!crtl
->stack_realign_finalized
);
412 if (!crtl
->stack_realign_needed
)
414 /* It is OK to reduce the alignment as long as the
415 requested size is 0 or the estimated stack
416 alignment >= mode alignment. */
417 gcc_assert ((kind
& ASLK_REDUCE_ALIGN
)
418 || known_eq (size
, 0)
419 || (crtl
->stack_alignment_estimated
420 >= GET_MODE_ALIGNMENT (mode
)));
421 alignment_in_bits
= crtl
->stack_alignment_estimated
;
422 alignment
= alignment_in_bits
/ BITS_PER_UNIT
;
428 if (crtl
->stack_alignment_needed
< alignment_in_bits
)
429 crtl
->stack_alignment_needed
= alignment_in_bits
;
430 if (crtl
->max_used_stack_slot_alignment
< alignment_in_bits
)
431 crtl
->max_used_stack_slot_alignment
= alignment_in_bits
;
433 if (mode
!= BLKmode
|| maybe_ne (size
, 0))
435 if (kind
& ASLK_RECORD_PAD
)
437 struct frame_space
**psp
;
439 for (psp
= &crtl
->frame_space_list
; *psp
; psp
= &(*psp
)->next
)
441 struct frame_space
*space
= *psp
;
442 if (!try_fit_stack_local (space
->start
, space
->length
, size
,
443 alignment
, &slot_offset
))
446 if (known_gt (slot_offset
, space
->start
))
447 add_frame_space (space
->start
, slot_offset
);
448 if (known_lt (slot_offset
+ size
, space
->start
+ space
->length
))
449 add_frame_space (slot_offset
+ size
,
450 space
->start
+ space
->length
);
455 else if (!STACK_ALIGNMENT_NEEDED
)
457 slot_offset
= frame_offset
;
461 old_frame_offset
= frame_offset
;
463 if (FRAME_GROWS_DOWNWARD
)
465 frame_offset
-= size
;
466 try_fit_stack_local (frame_offset
, size
, size
, alignment
, &slot_offset
);
468 if (kind
& ASLK_RECORD_PAD
)
470 if (known_gt (slot_offset
, frame_offset
))
471 add_frame_space (frame_offset
, slot_offset
);
472 if (known_lt (slot_offset
+ size
, old_frame_offset
))
473 add_frame_space (slot_offset
+ size
, old_frame_offset
);
478 frame_offset
+= size
;
479 try_fit_stack_local (old_frame_offset
, size
, size
, alignment
, &slot_offset
);
481 if (kind
& ASLK_RECORD_PAD
)
483 if (known_gt (slot_offset
, old_frame_offset
))
484 add_frame_space (old_frame_offset
, slot_offset
);
485 if (known_lt (slot_offset
+ size
, frame_offset
))
486 add_frame_space (slot_offset
+ size
, frame_offset
);
491 /* On a big-endian machine, if we are allocating more space than we will use,
492 use the least significant bytes of those that are allocated. */
495 /* The slot size can sometimes be smaller than the mode size;
496 e.g. the rs6000 port allocates slots with a vector mode
497 that have the size of only one element. However, the slot
498 size must always be ordered wrt to the mode size, in the
499 same way as for a subreg. */
500 gcc_checking_assert (ordered_p (GET_MODE_SIZE (mode
), size
));
501 if (BYTES_BIG_ENDIAN
&& maybe_lt (GET_MODE_SIZE (mode
), size
))
502 bigend_correction
= size
- GET_MODE_SIZE (mode
);
505 /* If we have already instantiated virtual registers, return the actual
506 address relative to the frame pointer. */
507 if (virtuals_instantiated
)
508 addr
= plus_constant (Pmode
, frame_pointer_rtx
,
510 (slot_offset
+ bigend_correction
511 + targetm
.starting_frame_offset (), Pmode
));
513 addr
= plus_constant (Pmode
, virtual_stack_vars_rtx
,
515 (slot_offset
+ bigend_correction
,
518 x
= gen_rtx_MEM (mode
, addr
);
519 set_mem_align (x
, alignment_in_bits
);
520 MEM_NOTRAP_P (x
) = 1;
522 vec_safe_push (stack_slot_list
, x
);
524 if (frame_offset_overflow (frame_offset
, current_function_decl
))
530 /* Wrap up assign_stack_local_1 with last parameter as false. */
533 assign_stack_local (machine_mode mode
, poly_int64 size
, int align
)
535 return assign_stack_local_1 (mode
, size
, align
, ASLK_RECORD_PAD
);
538 /* In order to evaluate some expressions, such as function calls returning
539 structures in memory, we need to temporarily allocate stack locations.
540 We record each allocated temporary in the following structure.
542 Associated with each temporary slot is a nesting level. When we pop up
543 one level, all temporaries associated with the previous level are freed.
544 Normally, all temporaries are freed after the execution of the statement
545 in which they were created. However, if we are inside a ({...}) grouping,
546 the result may be in a temporary and hence must be preserved. If the
547 result could be in a temporary, we preserve it if we can determine which
548 one it is in. If we cannot determine which temporary may contain the
549 result, all temporaries are preserved. A temporary is preserved by
550 pretending it was allocated at the previous nesting level. */
552 struct GTY(()) temp_slot
{
553 /* Points to next temporary slot. */
554 struct temp_slot
*next
;
555 /* Points to previous temporary slot. */
556 struct temp_slot
*prev
;
557 /* The rtx to used to reference the slot. */
559 /* The size, in units, of the slot. */
561 /* The type of the object in the slot, or zero if it doesn't correspond
562 to a type. We use this to determine whether a slot can be reused.
563 It can be reused if objects of the type of the new slot will always
564 conflict with objects of the type of the old slot. */
566 /* The alignment (in bits) of the slot. */
568 /* Nonzero if this temporary is currently in use. */
570 /* Nesting level at which this slot is being used. */
572 /* The offset of the slot from the frame_pointer, including extra space
573 for alignment. This info is for combine_temp_slots. */
574 poly_int64 base_offset
;
575 /* The size of the slot, including extra space for alignment. This
576 info is for combine_temp_slots. */
577 poly_int64 full_size
;
580 /* Entry for the below hash table. */
581 struct GTY((for_user
)) temp_slot_address_entry
{
584 struct temp_slot
*temp_slot
;
587 struct temp_address_hasher
: ggc_ptr_hash
<temp_slot_address_entry
>
589 static hashval_t
hash (temp_slot_address_entry
*);
590 static bool equal (temp_slot_address_entry
*, temp_slot_address_entry
*);
593 /* A table of addresses that represent a stack slot. The table is a mapping
594 from address RTXen to a temp slot. */
595 static GTY(()) hash_table
<temp_address_hasher
> *temp_slot_address_table
;
596 static size_t n_temp_slots_in_use
;
598 /* Removes temporary slot TEMP from LIST. */
601 cut_slot_from_list (struct temp_slot
*temp
, struct temp_slot
**list
)
604 temp
->next
->prev
= temp
->prev
;
606 temp
->prev
->next
= temp
->next
;
610 temp
->prev
= temp
->next
= NULL
;
613 /* Inserts temporary slot TEMP to LIST. */
616 insert_slot_to_list (struct temp_slot
*temp
, struct temp_slot
**list
)
620 (*list
)->prev
= temp
;
625 /* Returns the list of used temp slots at LEVEL. */
627 static struct temp_slot
**
628 temp_slots_at_level (int level
)
630 if (level
>= (int) vec_safe_length (used_temp_slots
))
631 vec_safe_grow_cleared (used_temp_slots
, level
+ 1);
633 return &(*used_temp_slots
)[level
];
636 /* Returns the maximal temporary slot level. */
639 max_slot_level (void)
641 if (!used_temp_slots
)
644 return used_temp_slots
->length () - 1;
647 /* Moves temporary slot TEMP to LEVEL. */
650 move_slot_to_level (struct temp_slot
*temp
, int level
)
652 cut_slot_from_list (temp
, temp_slots_at_level (temp
->level
));
653 insert_slot_to_list (temp
, temp_slots_at_level (level
));
657 /* Make temporary slot TEMP available. */
660 make_slot_available (struct temp_slot
*temp
)
662 cut_slot_from_list (temp
, temp_slots_at_level (temp
->level
));
663 insert_slot_to_list (temp
, &avail_temp_slots
);
666 n_temp_slots_in_use
--;
669 /* Compute the hash value for an address -> temp slot mapping.
670 The value is cached on the mapping entry. */
672 temp_slot_address_compute_hash (struct temp_slot_address_entry
*t
)
674 int do_not_record
= 0;
675 return hash_rtx (t
->address
, GET_MODE (t
->address
),
676 &do_not_record
, NULL
, false);
679 /* Return the hash value for an address -> temp slot mapping. */
681 temp_address_hasher::hash (temp_slot_address_entry
*t
)
686 /* Compare two address -> temp slot mapping entries. */
688 temp_address_hasher::equal (temp_slot_address_entry
*t1
,
689 temp_slot_address_entry
*t2
)
691 return exp_equiv_p (t1
->address
, t2
->address
, 0, true);
694 /* Add ADDRESS as an alias of TEMP_SLOT to the addess -> temp slot mapping. */
696 insert_temp_slot_address (rtx address
, struct temp_slot
*temp_slot
)
698 struct temp_slot_address_entry
*t
= ggc_alloc
<temp_slot_address_entry
> ();
699 t
->address
= address
;
700 t
->temp_slot
= temp_slot
;
701 t
->hash
= temp_slot_address_compute_hash (t
);
702 *temp_slot_address_table
->find_slot_with_hash (t
, t
->hash
, INSERT
) = t
;
705 /* Remove an address -> temp slot mapping entry if the temp slot is
706 not in use anymore. Callback for remove_unused_temp_slot_addresses. */
708 remove_unused_temp_slot_addresses_1 (temp_slot_address_entry
**slot
, void *)
710 const struct temp_slot_address_entry
*t
= *slot
;
711 if (! t
->temp_slot
->in_use
)
712 temp_slot_address_table
->clear_slot (slot
);
716 /* Remove all mappings of addresses to unused temp slots. */
718 remove_unused_temp_slot_addresses (void)
720 /* Use quicker clearing if there aren't any active temp slots. */
721 if (n_temp_slots_in_use
)
722 temp_slot_address_table
->traverse
723 <void *, remove_unused_temp_slot_addresses_1
> (NULL
);
725 temp_slot_address_table
->empty ();
728 /* Find the temp slot corresponding to the object at address X. */
730 static struct temp_slot
*
731 find_temp_slot_from_address (rtx x
)
734 struct temp_slot_address_entry tmp
, *t
;
736 /* First try the easy way:
737 See if X exists in the address -> temp slot mapping. */
739 tmp
.temp_slot
= NULL
;
740 tmp
.hash
= temp_slot_address_compute_hash (&tmp
);
741 t
= temp_slot_address_table
->find_with_hash (&tmp
, tmp
.hash
);
745 /* If we have a sum involving a register, see if it points to a temp
747 if (GET_CODE (x
) == PLUS
&& REG_P (XEXP (x
, 0))
748 && (p
= find_temp_slot_from_address (XEXP (x
, 0))) != 0)
750 else if (GET_CODE (x
) == PLUS
&& REG_P (XEXP (x
, 1))
751 && (p
= find_temp_slot_from_address (XEXP (x
, 1))) != 0)
754 /* Last resort: Address is a virtual stack var address. */
756 if (strip_offset (x
, &offset
) == virtual_stack_vars_rtx
)
759 for (i
= max_slot_level (); i
>= 0; i
--)
760 for (p
= *temp_slots_at_level (i
); p
; p
= p
->next
)
761 if (known_in_range_p (offset
, p
->base_offset
, p
->full_size
))
768 /* Allocate a temporary stack slot and record it for possible later
771 MODE is the machine mode to be given to the returned rtx.
773 SIZE is the size in units of the space required. We do no rounding here
774 since assign_stack_local will do any required rounding.
776 TYPE is the type that will be used for the stack slot. */
779 assign_stack_temp_for_type (machine_mode mode
, poly_int64 size
, tree type
)
782 struct temp_slot
*p
, *best_p
= 0, *selected
= NULL
, **pp
;
785 gcc_assert (known_size_p (size
));
787 align
= get_stack_local_alignment (type
, mode
);
789 /* Try to find an available, already-allocated temporary of the proper
790 mode which meets the size and alignment requirements. Choose the
791 smallest one with the closest alignment.
793 If assign_stack_temp is called outside of the tree->rtl expansion,
794 we cannot reuse the stack slots (that may still refer to
795 VIRTUAL_STACK_VARS_REGNUM). */
796 if (!virtuals_instantiated
)
798 for (p
= avail_temp_slots
; p
; p
= p
->next
)
800 if (p
->align
>= align
801 && known_ge (p
->size
, size
)
802 && GET_MODE (p
->slot
) == mode
803 && objects_must_conflict_p (p
->type
, type
)
805 || (known_eq (best_p
->size
, p
->size
)
806 ? best_p
->align
> p
->align
807 : known_ge (best_p
->size
, p
->size
))))
809 if (p
->align
== align
&& known_eq (p
->size
, size
))
812 cut_slot_from_list (selected
, &avail_temp_slots
);
821 /* Make our best, if any, the one to use. */
825 cut_slot_from_list (selected
, &avail_temp_slots
);
827 /* If there are enough aligned bytes left over, make them into a new
828 temp_slot so that the extra bytes don't get wasted. Do this only
829 for BLKmode slots, so that we can be sure of the alignment. */
830 if (GET_MODE (best_p
->slot
) == BLKmode
)
832 int alignment
= best_p
->align
/ BITS_PER_UNIT
;
833 poly_int64 rounded_size
= aligned_upper_bound (size
, alignment
);
835 if (known_ge (best_p
->size
- rounded_size
, alignment
))
837 p
= ggc_alloc
<temp_slot
> ();
839 p
->size
= best_p
->size
- rounded_size
;
840 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
841 p
->full_size
= best_p
->full_size
- rounded_size
;
842 p
->slot
= adjust_address_nv (best_p
->slot
, BLKmode
, rounded_size
);
843 p
->align
= best_p
->align
;
844 p
->type
= best_p
->type
;
845 insert_slot_to_list (p
, &avail_temp_slots
);
847 vec_safe_push (stack_slot_list
, p
->slot
);
849 best_p
->size
= rounded_size
;
850 best_p
->full_size
= rounded_size
;
855 /* If we still didn't find one, make a new temporary. */
858 poly_int64 frame_offset_old
= frame_offset
;
860 p
= ggc_alloc
<temp_slot
> ();
862 /* We are passing an explicit alignment request to assign_stack_local.
863 One side effect of that is assign_stack_local will not round SIZE
864 to ensure the frame offset remains suitably aligned.
866 So for requests which depended on the rounding of SIZE, we go ahead
867 and round it now. We also make sure ALIGNMENT is at least
868 BIGGEST_ALIGNMENT. */
869 gcc_assert (mode
!= BLKmode
|| align
== BIGGEST_ALIGNMENT
);
870 p
->slot
= assign_stack_local_1 (mode
,
872 ? aligned_upper_bound (size
,
880 /* The following slot size computation is necessary because we don't
881 know the actual size of the temporary slot until assign_stack_local
882 has performed all the frame alignment and size rounding for the
883 requested temporary. Note that extra space added for alignment
884 can be either above or below this stack slot depending on which
885 way the frame grows. We include the extra space if and only if it
886 is above this slot. */
887 if (FRAME_GROWS_DOWNWARD
)
888 p
->size
= frame_offset_old
- frame_offset
;
892 /* Now define the fields used by combine_temp_slots. */
893 if (FRAME_GROWS_DOWNWARD
)
895 p
->base_offset
= frame_offset
;
896 p
->full_size
= frame_offset_old
- frame_offset
;
900 p
->base_offset
= frame_offset_old
;
901 p
->full_size
= frame_offset
- frame_offset_old
;
910 p
->level
= temp_slot_level
;
911 n_temp_slots_in_use
++;
913 pp
= temp_slots_at_level (p
->level
);
914 insert_slot_to_list (p
, pp
);
915 insert_temp_slot_address (XEXP (p
->slot
, 0), p
);
917 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
918 slot
= gen_rtx_MEM (mode
, XEXP (p
->slot
, 0));
919 vec_safe_push (stack_slot_list
, slot
);
921 /* If we know the alias set for the memory that will be used, use
922 it. If there's no TYPE, then we don't know anything about the
923 alias set for the memory. */
924 set_mem_alias_set (slot
, type
? get_alias_set (type
) : 0);
925 set_mem_align (slot
, align
);
927 /* If a type is specified, set the relevant flags. */
929 MEM_VOLATILE_P (slot
) = TYPE_VOLATILE (type
);
930 MEM_NOTRAP_P (slot
) = 1;
935 /* Allocate a temporary stack slot and record it for possible later
936 reuse. First two arguments are same as in preceding function. */
939 assign_stack_temp (machine_mode mode
, poly_int64 size
)
941 return assign_stack_temp_for_type (mode
, size
, NULL_TREE
);
944 /* Assign a temporary.
945 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
946 and so that should be used in error messages. In either case, we
947 allocate of the given type.
948 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
949 it is 0 if a register is OK.
950 DONT_PROMOTE is 1 if we should not promote values in register
954 assign_temp (tree type_or_decl
, int memory_required
,
955 int dont_promote ATTRIBUTE_UNUSED
)
963 if (DECL_P (type_or_decl
))
964 decl
= type_or_decl
, type
= TREE_TYPE (decl
);
966 decl
= NULL
, type
= type_or_decl
;
968 mode
= TYPE_MODE (type
);
970 unsignedp
= TYPE_UNSIGNED (type
);
973 /* Allocating temporaries of TREE_ADDRESSABLE type must be done in the front
974 end. See also create_tmp_var for the gimplification-time check. */
975 gcc_assert (!TREE_ADDRESSABLE (type
) && COMPLETE_TYPE_P (type
));
977 if (mode
== BLKmode
|| memory_required
)
982 /* Unfortunately, we don't yet know how to allocate variable-sized
983 temporaries. However, sometimes we can find a fixed upper limit on
984 the size, so try that instead. */
985 if (!poly_int_tree_p (TYPE_SIZE_UNIT (type
), &size
))
986 size
= max_int_size_in_bytes (type
);
988 /* Zero sized arrays are a GNU C extension. Set size to 1 to avoid
989 problems with allocating the stack space. */
990 if (known_eq (size
, 0))
993 /* The size of the temporary may be too large to fit into an integer. */
994 /* ??? Not sure this should happen except for user silliness, so limit
995 this to things that aren't compiler-generated temporaries. The
996 rest of the time we'll die in assign_stack_temp_for_type. */
998 && !known_size_p (size
)
999 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
)
1001 error ("size of variable %q+D is too large", decl
);
1005 tmp
= assign_stack_temp_for_type (mode
, size
, type
);
1011 mode
= promote_mode (type
, mode
, &unsignedp
);
1014 return gen_reg_rtx (mode
);
1017 /* Combine temporary stack slots which are adjacent on the stack.
1019 This allows for better use of already allocated stack space. This is only
1020 done for BLKmode slots because we can be sure that we won't have alignment
1021 problems in this case. */
1024 combine_temp_slots (void)
1026 struct temp_slot
*p
, *q
, *next
, *next_q
;
1029 /* We can't combine slots, because the information about which slot
1030 is in which alias set will be lost. */
1031 if (flag_strict_aliasing
)
1034 /* If there are a lot of temp slots, don't do anything unless
1035 high levels of optimization. */
1036 if (! flag_expensive_optimizations
)
1037 for (p
= avail_temp_slots
, num_slots
= 0; p
; p
= p
->next
, num_slots
++)
1038 if (num_slots
> 100 || (num_slots
> 10 && optimize
== 0))
1041 for (p
= avail_temp_slots
; p
; p
= next
)
1047 if (GET_MODE (p
->slot
) != BLKmode
)
1050 for (q
= p
->next
; q
; q
= next_q
)
1056 if (GET_MODE (q
->slot
) != BLKmode
)
1059 if (known_eq (p
->base_offset
+ p
->full_size
, q
->base_offset
))
1061 /* Q comes after P; combine Q into P. */
1063 p
->full_size
+= q
->full_size
;
1066 else if (known_eq (q
->base_offset
+ q
->full_size
, p
->base_offset
))
1068 /* P comes after Q; combine P into Q. */
1070 q
->full_size
+= p
->full_size
;
1075 cut_slot_from_list (q
, &avail_temp_slots
);
1078 /* Either delete P or advance past it. */
1080 cut_slot_from_list (p
, &avail_temp_slots
);
1084 /* Indicate that NEW_RTX is an alternate way of referring to the temp
1085 slot that previously was known by OLD_RTX. */
1088 update_temp_slot_address (rtx old_rtx
, rtx new_rtx
)
1090 struct temp_slot
*p
;
1092 if (rtx_equal_p (old_rtx
, new_rtx
))
1095 p
= find_temp_slot_from_address (old_rtx
);
1097 /* If we didn't find one, see if both OLD_RTX is a PLUS. If so, and
1098 NEW_RTX is a register, see if one operand of the PLUS is a
1099 temporary location. If so, NEW_RTX points into it. Otherwise,
1100 if both OLD_RTX and NEW_RTX are a PLUS and if there is a register
1101 in common between them. If so, try a recursive call on those
1105 if (GET_CODE (old_rtx
) != PLUS
)
1108 if (REG_P (new_rtx
))
1110 update_temp_slot_address (XEXP (old_rtx
, 0), new_rtx
);
1111 update_temp_slot_address (XEXP (old_rtx
, 1), new_rtx
);
1114 else if (GET_CODE (new_rtx
) != PLUS
)
1117 if (rtx_equal_p (XEXP (old_rtx
, 0), XEXP (new_rtx
, 0)))
1118 update_temp_slot_address (XEXP (old_rtx
, 1), XEXP (new_rtx
, 1));
1119 else if (rtx_equal_p (XEXP (old_rtx
, 1), XEXP (new_rtx
, 0)))
1120 update_temp_slot_address (XEXP (old_rtx
, 0), XEXP (new_rtx
, 1));
1121 else if (rtx_equal_p (XEXP (old_rtx
, 0), XEXP (new_rtx
, 1)))
1122 update_temp_slot_address (XEXP (old_rtx
, 1), XEXP (new_rtx
, 0));
1123 else if (rtx_equal_p (XEXP (old_rtx
, 1), XEXP (new_rtx
, 1)))
1124 update_temp_slot_address (XEXP (old_rtx
, 0), XEXP (new_rtx
, 0));
1129 /* Otherwise add an alias for the temp's address. */
1130 insert_temp_slot_address (new_rtx
, p
);
1133 /* If X could be a reference to a temporary slot, mark that slot as
1134 belonging to the to one level higher than the current level. If X
1135 matched one of our slots, just mark that one. Otherwise, we can't
1136 easily predict which it is, so upgrade all of them.
1138 This is called when an ({...}) construct occurs and a statement
1139 returns a value in memory. */
1142 preserve_temp_slots (rtx x
)
1144 struct temp_slot
*p
= 0, *next
;
1149 /* If X is a register that is being used as a pointer, see if we have
1150 a temporary slot we know it points to. */
1151 if (REG_P (x
) && REG_POINTER (x
))
1152 p
= find_temp_slot_from_address (x
);
1154 /* If X is not in memory or is at a constant address, it cannot be in
1155 a temporary slot. */
1156 if (p
== 0 && (!MEM_P (x
) || CONSTANT_P (XEXP (x
, 0))))
1159 /* First see if we can find a match. */
1161 p
= find_temp_slot_from_address (XEXP (x
, 0));
1165 if (p
->level
== temp_slot_level
)
1166 move_slot_to_level (p
, temp_slot_level
- 1);
1170 /* Otherwise, preserve all non-kept slots at this level. */
1171 for (p
= *temp_slots_at_level (temp_slot_level
); p
; p
= next
)
1174 move_slot_to_level (p
, temp_slot_level
- 1);
1178 /* Free all temporaries used so far. This is normally called at the
1179 end of generating code for a statement. */
1182 free_temp_slots (void)
1184 struct temp_slot
*p
, *next
;
1185 bool some_available
= false;
1187 for (p
= *temp_slots_at_level (temp_slot_level
); p
; p
= next
)
1190 make_slot_available (p
);
1191 some_available
= true;
1196 remove_unused_temp_slot_addresses ();
1197 combine_temp_slots ();
1201 /* Push deeper into the nesting level for stack temporaries. */
1204 push_temp_slots (void)
1209 /* Pop a temporary nesting level. All slots in use in the current level
1213 pop_temp_slots (void)
1219 /* Initialize temporary slots. */
1222 init_temp_slots (void)
1224 /* We have not allocated any temporaries yet. */
1225 avail_temp_slots
= 0;
1226 vec_alloc (used_temp_slots
, 0);
1227 temp_slot_level
= 0;
1228 n_temp_slots_in_use
= 0;
1230 /* Set up the table to map addresses to temp slots. */
1231 if (! temp_slot_address_table
)
1232 temp_slot_address_table
= hash_table
<temp_address_hasher
>::create_ggc (32);
1234 temp_slot_address_table
->empty ();
1237 /* Functions and data structures to keep track of the values hard regs
1238 had at the start of the function. */
1240 /* Private type used by get_hard_reg_initial_reg, get_hard_reg_initial_val,
1241 and has_hard_reg_initial_val.. */
1242 struct GTY(()) initial_value_pair
{
1246 /* ??? This could be a VEC but there is currently no way to define an
1247 opaque VEC type. This could be worked around by defining struct
1248 initial_value_pair in function.h. */
1249 struct GTY(()) initial_value_struct
{
1252 initial_value_pair
* GTY ((length ("%h.num_entries"))) entries
;
1255 /* If a pseudo represents an initial hard reg (or expression), return
1256 it, else return NULL_RTX. */
1259 get_hard_reg_initial_reg (rtx reg
)
1261 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1267 for (i
= 0; i
< ivs
->num_entries
; i
++)
1268 if (rtx_equal_p (ivs
->entries
[i
].pseudo
, reg
))
1269 return ivs
->entries
[i
].hard_reg
;
1274 /* Make sure that there's a pseudo register of mode MODE that stores the
1275 initial value of hard register REGNO. Return an rtx for such a pseudo. */
1278 get_hard_reg_initial_val (machine_mode mode
, unsigned int regno
)
1280 struct initial_value_struct
*ivs
;
1283 rv
= has_hard_reg_initial_val (mode
, regno
);
1287 ivs
= crtl
->hard_reg_initial_vals
;
1290 ivs
= ggc_alloc
<initial_value_struct
> ();
1291 ivs
->num_entries
= 0;
1292 ivs
->max_entries
= 5;
1293 ivs
->entries
= ggc_vec_alloc
<initial_value_pair
> (5);
1294 crtl
->hard_reg_initial_vals
= ivs
;
1297 if (ivs
->num_entries
>= ivs
->max_entries
)
1299 ivs
->max_entries
+= 5;
1300 ivs
->entries
= GGC_RESIZEVEC (initial_value_pair
, ivs
->entries
,
1304 ivs
->entries
[ivs
->num_entries
].hard_reg
= gen_rtx_REG (mode
, regno
);
1305 ivs
->entries
[ivs
->num_entries
].pseudo
= gen_reg_rtx (mode
);
1307 return ivs
->entries
[ivs
->num_entries
++].pseudo
;
1310 /* See if get_hard_reg_initial_val has been used to create a pseudo
1311 for the initial value of hard register REGNO in mode MODE. Return
1312 the associated pseudo if so, otherwise return NULL. */
1315 has_hard_reg_initial_val (machine_mode mode
, unsigned int regno
)
1317 struct initial_value_struct
*ivs
;
1320 ivs
= crtl
->hard_reg_initial_vals
;
1322 for (i
= 0; i
< ivs
->num_entries
; i
++)
1323 if (GET_MODE (ivs
->entries
[i
].hard_reg
) == mode
1324 && REGNO (ivs
->entries
[i
].hard_reg
) == regno
)
1325 return ivs
->entries
[i
].pseudo
;
1331 emit_initial_value_sets (void)
1333 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1341 for (i
= 0; i
< ivs
->num_entries
; i
++)
1342 emit_move_insn (ivs
->entries
[i
].pseudo
, ivs
->entries
[i
].hard_reg
);
1346 emit_insn_at_entry (seq
);
1350 /* Return the hardreg-pseudoreg initial values pair entry I and
1351 TRUE if I is a valid entry, or FALSE if I is not a valid entry. */
1353 initial_value_entry (int i
, rtx
*hreg
, rtx
*preg
)
1355 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1356 if (!ivs
|| i
>= ivs
->num_entries
)
1359 *hreg
= ivs
->entries
[i
].hard_reg
;
1360 *preg
= ivs
->entries
[i
].pseudo
;
1364 /* These routines are responsible for converting virtual register references
1365 to the actual hard register references once RTL generation is complete.
1367 The following four variables are used for communication between the
1368 routines. They contain the offsets of the virtual registers from their
1369 respective hard registers. */
1371 static poly_int64 in_arg_offset
;
1372 static poly_int64 var_offset
;
1373 static poly_int64 dynamic_offset
;
1374 static poly_int64 out_arg_offset
;
1375 static poly_int64 cfa_offset
;
1377 /* In most machines, the stack pointer register is equivalent to the bottom
1380 #ifndef STACK_POINTER_OFFSET
1381 #define STACK_POINTER_OFFSET 0
1384 #if defined (REG_PARM_STACK_SPACE) && !defined (INCOMING_REG_PARM_STACK_SPACE)
1385 #define INCOMING_REG_PARM_STACK_SPACE REG_PARM_STACK_SPACE
1388 /* If not defined, pick an appropriate default for the offset of dynamically
1389 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
1390 INCOMING_REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
1392 #ifndef STACK_DYNAMIC_OFFSET
1394 /* The bottom of the stack points to the actual arguments. If
1395 REG_PARM_STACK_SPACE is defined, this includes the space for the register
1396 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
1397 stack space for register parameters is not pushed by the caller, but
1398 rather part of the fixed stack areas and hence not included in
1399 `crtl->outgoing_args_size'. Nevertheless, we must allow
1400 for it when allocating stack dynamic objects. */
1402 #ifdef INCOMING_REG_PARM_STACK_SPACE
1403 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1404 ((ACCUMULATE_OUTGOING_ARGS \
1405 ? (crtl->outgoing_args_size \
1406 + (OUTGOING_REG_PARM_STACK_SPACE ((!(FNDECL) ? NULL_TREE : TREE_TYPE (FNDECL))) ? 0 \
1407 : INCOMING_REG_PARM_STACK_SPACE (FNDECL))) \
1408 : 0) + (STACK_POINTER_OFFSET))
1410 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1411 ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : poly_int64 (0)) \
1412 + (STACK_POINTER_OFFSET))
1417 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
1418 is a virtual register, return the equivalent hard register and set the
1419 offset indirectly through the pointer. Otherwise, return 0. */
1422 instantiate_new_reg (rtx x
, poly_int64_pod
*poffset
)
1427 if (x
== virtual_incoming_args_rtx
)
1429 if (stack_realign_drap
)
1431 /* Replace virtual_incoming_args_rtx with internal arg
1432 pointer if DRAP is used to realign stack. */
1433 new_rtx
= crtl
->args
.internal_arg_pointer
;
1437 new_rtx
= arg_pointer_rtx
, offset
= in_arg_offset
;
1439 else if (x
== virtual_stack_vars_rtx
)
1440 new_rtx
= frame_pointer_rtx
, offset
= var_offset
;
1441 else if (x
== virtual_stack_dynamic_rtx
)
1442 new_rtx
= stack_pointer_rtx
, offset
= dynamic_offset
;
1443 else if (x
== virtual_outgoing_args_rtx
)
1444 new_rtx
= stack_pointer_rtx
, offset
= out_arg_offset
;
1445 else if (x
== virtual_cfa_rtx
)
1447 #ifdef FRAME_POINTER_CFA_OFFSET
1448 new_rtx
= frame_pointer_rtx
;
1450 new_rtx
= arg_pointer_rtx
;
1452 offset
= cfa_offset
;
1454 else if (x
== virtual_preferred_stack_boundary_rtx
)
1456 new_rtx
= GEN_INT (crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
);
1466 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1467 registers present inside of *LOC. The expression is simplified,
1468 as much as possible, but is not to be considered "valid" in any sense
1469 implied by the target. Return true if any change is made. */
1472 instantiate_virtual_regs_in_rtx (rtx
*loc
)
1476 bool changed
= false;
1477 subrtx_ptr_iterator::array_type array
;
1478 FOR_EACH_SUBRTX_PTR (iter
, array
, loc
, NONCONST
)
1485 switch (GET_CODE (x
))
1488 new_rtx
= instantiate_new_reg (x
, &offset
);
1491 *loc
= plus_constant (GET_MODE (x
), new_rtx
, offset
);
1494 iter
.skip_subrtxes ();
1498 new_rtx
= instantiate_new_reg (XEXP (x
, 0), &offset
);
1501 XEXP (x
, 0) = new_rtx
;
1502 *loc
= plus_constant (GET_MODE (x
), x
, offset
, true);
1504 iter
.skip_subrtxes ();
1508 /* FIXME -- from old code */
1509 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
1510 we can commute the PLUS and SUBREG because pointers into the
1511 frame are well-behaved. */
1522 /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
1523 matches the predicate for insn CODE operand OPERAND. */
1526 safe_insn_predicate (int code
, int operand
, rtx x
)
1528 return code
< 0 || insn_operand_matches ((enum insn_code
) code
, operand
, x
);
1531 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1532 registers present inside of insn. The result will be a valid insn. */
1535 instantiate_virtual_regs_in_insn (rtx_insn
*insn
)
1539 bool any_change
= false;
1540 rtx set
, new_rtx
, x
;
1543 /* There are some special cases to be handled first. */
1544 set
= single_set (insn
);
1547 /* We're allowed to assign to a virtual register. This is interpreted
1548 to mean that the underlying register gets assigned the inverse
1549 transformation. This is used, for example, in the handling of
1551 new_rtx
= instantiate_new_reg (SET_DEST (set
), &offset
);
1556 instantiate_virtual_regs_in_rtx (&SET_SRC (set
));
1557 x
= simplify_gen_binary (PLUS
, GET_MODE (new_rtx
), SET_SRC (set
),
1558 gen_int_mode (-offset
, GET_MODE (new_rtx
)));
1559 x
= force_operand (x
, new_rtx
);
1561 emit_move_insn (new_rtx
, x
);
1566 emit_insn_before (seq
, insn
);
1571 /* Handle a straight copy from a virtual register by generating a
1572 new add insn. The difference between this and falling through
1573 to the generic case is avoiding a new pseudo and eliminating a
1574 move insn in the initial rtl stream. */
1575 new_rtx
= instantiate_new_reg (SET_SRC (set
), &offset
);
1577 && maybe_ne (offset
, 0)
1578 && REG_P (SET_DEST (set
))
1579 && REGNO (SET_DEST (set
)) > LAST_VIRTUAL_REGISTER
)
1583 x
= expand_simple_binop (GET_MODE (SET_DEST (set
)), PLUS
, new_rtx
,
1584 gen_int_mode (offset
,
1585 GET_MODE (SET_DEST (set
))),
1586 SET_DEST (set
), 1, OPTAB_LIB_WIDEN
);
1587 if (x
!= SET_DEST (set
))
1588 emit_move_insn (SET_DEST (set
), x
);
1593 emit_insn_before (seq
, insn
);
1598 extract_insn (insn
);
1599 insn_code
= INSN_CODE (insn
);
1601 /* Handle a plus involving a virtual register by determining if the
1602 operands remain valid if they're modified in place. */
1604 if (GET_CODE (SET_SRC (set
)) == PLUS
1605 && recog_data
.n_operands
>= 3
1606 && recog_data
.operand_loc
[1] == &XEXP (SET_SRC (set
), 0)
1607 && recog_data
.operand_loc
[2] == &XEXP (SET_SRC (set
), 1)
1608 && poly_int_rtx_p (recog_data
.operand
[2], &delta
)
1609 && (new_rtx
= instantiate_new_reg (recog_data
.operand
[1], &offset
)))
1613 /* If the sum is zero, then replace with a plain move. */
1614 if (known_eq (offset
, 0)
1615 && REG_P (SET_DEST (set
))
1616 && REGNO (SET_DEST (set
)) > LAST_VIRTUAL_REGISTER
)
1619 emit_move_insn (SET_DEST (set
), new_rtx
);
1623 emit_insn_before (seq
, insn
);
1628 x
= gen_int_mode (offset
, recog_data
.operand_mode
[2]);
1630 /* Using validate_change and apply_change_group here leaves
1631 recog_data in an invalid state. Since we know exactly what
1632 we want to check, do those two by hand. */
1633 if (safe_insn_predicate (insn_code
, 1, new_rtx
)
1634 && safe_insn_predicate (insn_code
, 2, x
))
1636 *recog_data
.operand_loc
[1] = recog_data
.operand
[1] = new_rtx
;
1637 *recog_data
.operand_loc
[2] = recog_data
.operand
[2] = x
;
1640 /* Fall through into the regular operand fixup loop in
1641 order to take care of operands other than 1 and 2. */
1647 extract_insn (insn
);
1648 insn_code
= INSN_CODE (insn
);
1651 /* In the general case, we expect virtual registers to appear only in
1652 operands, and then only as either bare registers or inside memories. */
1653 for (i
= 0; i
< recog_data
.n_operands
; ++i
)
1655 x
= recog_data
.operand
[i
];
1656 switch (GET_CODE (x
))
1660 rtx addr
= XEXP (x
, 0);
1662 if (!instantiate_virtual_regs_in_rtx (&addr
))
1666 x
= replace_equiv_address (x
, addr
, true);
1667 /* It may happen that the address with the virtual reg
1668 was valid (e.g. based on the virtual stack reg, which might
1669 be acceptable to the predicates with all offsets), whereas
1670 the address now isn't anymore, for instance when the address
1671 is still offsetted, but the base reg isn't virtual-stack-reg
1672 anymore. Below we would do a force_reg on the whole operand,
1673 but this insn might actually only accept memory. Hence,
1674 before doing that last resort, try to reload the address into
1675 a register, so this operand stays a MEM. */
1676 if (!safe_insn_predicate (insn_code
, i
, x
))
1678 addr
= force_reg (GET_MODE (addr
), addr
);
1679 x
= replace_equiv_address (x
, addr
, true);
1684 emit_insn_before (seq
, insn
);
1689 new_rtx
= instantiate_new_reg (x
, &offset
);
1690 if (new_rtx
== NULL
)
1692 if (known_eq (offset
, 0))
1698 /* Careful, special mode predicates may have stuff in
1699 insn_data[insn_code].operand[i].mode that isn't useful
1700 to us for computing a new value. */
1701 /* ??? Recognize address_operand and/or "p" constraints
1702 to see if (plus new offset) is a valid before we put
1703 this through expand_simple_binop. */
1704 x
= expand_simple_binop (GET_MODE (x
), PLUS
, new_rtx
,
1705 gen_int_mode (offset
, GET_MODE (x
)),
1706 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1709 emit_insn_before (seq
, insn
);
1714 new_rtx
= instantiate_new_reg (SUBREG_REG (x
), &offset
);
1715 if (new_rtx
== NULL
)
1717 if (maybe_ne (offset
, 0))
1720 new_rtx
= expand_simple_binop
1721 (GET_MODE (new_rtx
), PLUS
, new_rtx
,
1722 gen_int_mode (offset
, GET_MODE (new_rtx
)),
1723 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1726 emit_insn_before (seq
, insn
);
1728 x
= simplify_gen_subreg (recog_data
.operand_mode
[i
], new_rtx
,
1729 GET_MODE (new_rtx
), SUBREG_BYTE (x
));
1737 /* At this point, X contains the new value for the operand.
1738 Validate the new value vs the insn predicate. Note that
1739 asm insns will have insn_code -1 here. */
1740 if (!safe_insn_predicate (insn_code
, i
, x
))
1745 gcc_assert (REGNO (x
) <= LAST_VIRTUAL_REGISTER
);
1746 x
= copy_to_reg (x
);
1749 x
= force_reg (insn_data
[insn_code
].operand
[i
].mode
, x
);
1753 emit_insn_before (seq
, insn
);
1756 *recog_data
.operand_loc
[i
] = recog_data
.operand
[i
] = x
;
1762 /* Propagate operand changes into the duplicates. */
1763 for (i
= 0; i
< recog_data
.n_dups
; ++i
)
1764 *recog_data
.dup_loc
[i
]
1765 = copy_rtx (recog_data
.operand
[(unsigned)recog_data
.dup_num
[i
]]);
1767 /* Force re-recognition of the instruction for validation. */
1768 INSN_CODE (insn
) = -1;
1771 if (asm_noperands (PATTERN (insn
)) >= 0)
1773 if (!check_asm_operands (PATTERN (insn
)))
1775 error_for_asm (insn
, "impossible constraint in %<asm%>");
1776 /* For asm goto, instead of fixing up all the edges
1777 just clear the template and clear input operands
1778 (asm goto doesn't have any output operands). */
1781 rtx asm_op
= extract_asm_operands (PATTERN (insn
));
1782 ASM_OPERANDS_TEMPLATE (asm_op
) = ggc_strdup ("");
1783 ASM_OPERANDS_INPUT_VEC (asm_op
) = rtvec_alloc (0);
1784 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op
) = rtvec_alloc (0);
1792 if (recog_memoized (insn
) < 0)
1793 fatal_insn_not_found (insn
);
1797 /* Subroutine of instantiate_decls. Given RTL representing a decl,
1798 do any instantiation required. */
1801 instantiate_decl_rtl (rtx x
)
1808 /* If this is a CONCAT, recurse for the pieces. */
1809 if (GET_CODE (x
) == CONCAT
)
1811 instantiate_decl_rtl (XEXP (x
, 0));
1812 instantiate_decl_rtl (XEXP (x
, 1));
1816 /* If this is not a MEM, no need to do anything. Similarly if the
1817 address is a constant or a register that is not a virtual register. */
1822 if (CONSTANT_P (addr
)
1824 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
1825 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
1828 instantiate_virtual_regs_in_rtx (&XEXP (x
, 0));
1831 /* Helper for instantiate_decls called via walk_tree: Process all decls
1832 in the given DECL_VALUE_EXPR. */
1835 instantiate_expr (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
1843 if (DECL_RTL_SET_P (t
))
1844 instantiate_decl_rtl (DECL_RTL (t
));
1845 if (TREE_CODE (t
) == PARM_DECL
&& DECL_NAMELESS (t
)
1846 && DECL_INCOMING_RTL (t
))
1847 instantiate_decl_rtl (DECL_INCOMING_RTL (t
));
1848 if ((VAR_P (t
) || TREE_CODE (t
) == RESULT_DECL
)
1849 && DECL_HAS_VALUE_EXPR_P (t
))
1851 tree v
= DECL_VALUE_EXPR (t
);
1852 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1859 /* Subroutine of instantiate_decls: Process all decls in the given
1860 BLOCK node and all its subblocks. */
1863 instantiate_decls_1 (tree let
)
1867 for (t
= BLOCK_VARS (let
); t
; t
= DECL_CHAIN (t
))
1869 if (DECL_RTL_SET_P (t
))
1870 instantiate_decl_rtl (DECL_RTL (t
));
1871 if (VAR_P (t
) && DECL_HAS_VALUE_EXPR_P (t
))
1873 tree v
= DECL_VALUE_EXPR (t
);
1874 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1878 /* Process all subblocks. */
1879 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= BLOCK_CHAIN (t
))
1880 instantiate_decls_1 (t
);
1883 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
1884 all virtual registers in their DECL_RTL's. */
1887 instantiate_decls (tree fndecl
)
1892 /* Process all parameters of the function. */
1893 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= DECL_CHAIN (decl
))
1895 instantiate_decl_rtl (DECL_RTL (decl
));
1896 instantiate_decl_rtl (DECL_INCOMING_RTL (decl
));
1897 if (DECL_HAS_VALUE_EXPR_P (decl
))
1899 tree v
= DECL_VALUE_EXPR (decl
);
1900 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1904 if ((decl
= DECL_RESULT (fndecl
))
1905 && TREE_CODE (decl
) == RESULT_DECL
)
1907 if (DECL_RTL_SET_P (decl
))
1908 instantiate_decl_rtl (DECL_RTL (decl
));
1909 if (DECL_HAS_VALUE_EXPR_P (decl
))
1911 tree v
= DECL_VALUE_EXPR (decl
);
1912 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1916 /* Process the saved static chain if it exists. */
1917 decl
= DECL_STRUCT_FUNCTION (fndecl
)->static_chain_decl
;
1918 if (decl
&& DECL_HAS_VALUE_EXPR_P (decl
))
1919 instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl
)));
1921 /* Now process all variables defined in the function or its subblocks. */
1922 if (DECL_INITIAL (fndecl
))
1923 instantiate_decls_1 (DECL_INITIAL (fndecl
));
1925 FOR_EACH_LOCAL_DECL (cfun
, ix
, decl
)
1926 if (DECL_RTL_SET_P (decl
))
1927 instantiate_decl_rtl (DECL_RTL (decl
));
1928 vec_free (cfun
->local_decls
);
1931 /* Pass through the INSNS of function FNDECL and convert virtual register
1932 references to hard register references. */
1935 instantiate_virtual_regs (void)
1939 /* Compute the offsets to use for this function. */
1940 in_arg_offset
= FIRST_PARM_OFFSET (current_function_decl
);
1941 var_offset
= targetm
.starting_frame_offset ();
1942 dynamic_offset
= STACK_DYNAMIC_OFFSET (current_function_decl
);
1943 out_arg_offset
= STACK_POINTER_OFFSET
;
1944 #ifdef FRAME_POINTER_CFA_OFFSET
1945 cfa_offset
= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
1947 cfa_offset
= ARG_POINTER_CFA_OFFSET (current_function_decl
);
1950 /* Initialize recognition, indicating that volatile is OK. */
1953 /* Scan through all the insns, instantiating every virtual register still
1955 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
1958 /* These patterns in the instruction stream can never be recognized.
1959 Fortunately, they shouldn't contain virtual registers either. */
1960 if (GET_CODE (PATTERN (insn
)) == USE
1961 || GET_CODE (PATTERN (insn
)) == CLOBBER
1962 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
1963 || DEBUG_MARKER_INSN_P (insn
))
1965 else if (DEBUG_BIND_INSN_P (insn
))
1966 instantiate_virtual_regs_in_rtx (INSN_VAR_LOCATION_PTR (insn
));
1968 instantiate_virtual_regs_in_insn (insn
);
1970 if (insn
->deleted ())
1973 instantiate_virtual_regs_in_rtx (®_NOTES (insn
));
1975 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
1977 instantiate_virtual_regs_in_rtx (&CALL_INSN_FUNCTION_USAGE (insn
));
1980 /* Instantiate the virtual registers in the DECLs for debugging purposes. */
1981 instantiate_decls (current_function_decl
);
1983 targetm
.instantiate_decls ();
1985 /* Indicate that, from now on, assign_stack_local should use
1986 frame_pointer_rtx. */
1987 virtuals_instantiated
= 1;
1994 const pass_data pass_data_instantiate_virtual_regs
=
1996 RTL_PASS
, /* type */
1998 OPTGROUP_NONE
, /* optinfo_flags */
1999 TV_NONE
, /* tv_id */
2000 0, /* properties_required */
2001 0, /* properties_provided */
2002 0, /* properties_destroyed */
2003 0, /* todo_flags_start */
2004 0, /* todo_flags_finish */
2007 class pass_instantiate_virtual_regs
: public rtl_opt_pass
2010 pass_instantiate_virtual_regs (gcc::context
*ctxt
)
2011 : rtl_opt_pass (pass_data_instantiate_virtual_regs
, ctxt
)
2014 /* opt_pass methods: */
2015 virtual unsigned int execute (function
*)
2017 return instantiate_virtual_regs ();
2020 }; // class pass_instantiate_virtual_regs
2025 make_pass_instantiate_virtual_regs (gcc::context
*ctxt
)
2027 return new pass_instantiate_virtual_regs (ctxt
);
2031 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
2032 This means a type for which function calls must pass an address to the
2033 function or get an address back from the function.
2034 EXP may be a type node or an expression (whose type is tested). */
2037 aggregate_value_p (const_tree exp
, const_tree fntype
)
2039 const_tree type
= (TYPE_P (exp
)) ? exp
: TREE_TYPE (exp
);
2040 int i
, regno
, nregs
;
2044 switch (TREE_CODE (fntype
))
2048 tree fndecl
= get_callee_fndecl (fntype
);
2050 fntype
= TREE_TYPE (fndecl
);
2051 else if (CALL_EXPR_FN (fntype
))
2052 fntype
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (fntype
)));
2054 /* For internal functions, assume nothing needs to be
2055 returned in memory. */
2060 fntype
= TREE_TYPE (fntype
);
2065 case IDENTIFIER_NODE
:
2069 /* We don't expect other tree types here. */
2073 if (VOID_TYPE_P (type
))
2076 /* If a record should be passed the same as its first (and only) member
2077 don't pass it as an aggregate. */
2078 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_TRANSPARENT_AGGR (type
))
2079 return aggregate_value_p (first_field (type
), fntype
);
2081 /* If the front end has decided that this needs to be passed by
2082 reference, do so. */
2083 if ((TREE_CODE (exp
) == PARM_DECL
|| TREE_CODE (exp
) == RESULT_DECL
)
2084 && DECL_BY_REFERENCE (exp
))
2087 /* Function types that are TREE_ADDRESSABLE force return in memory. */
2088 if (fntype
&& TREE_ADDRESSABLE (fntype
))
2091 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
2092 and thus can't be returned in registers. */
2093 if (TREE_ADDRESSABLE (type
))
2096 if (TYPE_EMPTY_P (type
))
2099 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
2102 if (targetm
.calls
.return_in_memory (type
, fntype
))
2105 /* Make sure we have suitable call-clobbered regs to return
2106 the value in; if not, we must return it in memory. */
2107 reg
= hard_function_value (type
, 0, fntype
, 0);
2109 /* If we have something other than a REG (e.g. a PARALLEL), then assume
2114 regno
= REGNO (reg
);
2115 nregs
= hard_regno_nregs (regno
, TYPE_MODE (type
));
2116 for (i
= 0; i
< nregs
; i
++)
2117 if (! call_used_regs
[regno
+ i
])
2123 /* Return true if we should assign DECL a pseudo register; false if it
2124 should live on the local stack. */
2127 use_register_for_decl (const_tree decl
)
2129 if (TREE_CODE (decl
) == SSA_NAME
)
2131 /* We often try to use the SSA_NAME, instead of its underlying
2132 decl, to get type information and guide decisions, to avoid
2133 differences of behavior between anonymous and named
2134 variables, but in this one case we have to go for the actual
2135 variable if there is one. The main reason is that, at least
2136 at -O0, we want to place user variables on the stack, but we
2137 don't mind using pseudos for anonymous or ignored temps.
2138 Should we take the SSA_NAME, we'd conclude all SSA_NAMEs
2139 should go in pseudos, whereas their corresponding variables
2140 might have to go on the stack. So, disregarding the decl
2141 here would negatively impact debug info at -O0, enable
2142 coalescing between SSA_NAMEs that ought to get different
2143 stack/pseudo assignments, and get the incoming argument
2144 processing thoroughly confused by PARM_DECLs expected to live
2145 in stack slots but assigned to pseudos. */
2146 if (!SSA_NAME_VAR (decl
))
2147 return TYPE_MODE (TREE_TYPE (decl
)) != BLKmode
2148 && !(flag_float_store
&& FLOAT_TYPE_P (TREE_TYPE (decl
)));
2150 decl
= SSA_NAME_VAR (decl
);
2153 /* Honor volatile. */
2154 if (TREE_SIDE_EFFECTS (decl
))
2157 /* Honor addressability. */
2158 if (TREE_ADDRESSABLE (decl
))
2161 /* RESULT_DECLs are a bit special in that they're assigned without
2162 regard to use_register_for_decl, but we generally only store in
2163 them. If we coalesce their SSA NAMEs, we'd better return a
2164 result that matches the assignment in expand_function_start. */
2165 if (TREE_CODE (decl
) == RESULT_DECL
)
2167 /* If it's not an aggregate, we're going to use a REG or a
2168 PARALLEL containing a REG. */
2169 if (!aggregate_value_p (decl
, current_function_decl
))
2172 /* If expand_function_start determines the return value, we'll
2173 use MEM if it's not by reference. */
2174 if (cfun
->returns_pcc_struct
2175 || (targetm
.calls
.struct_value_rtx
2176 (TREE_TYPE (current_function_decl
), 1)))
2177 return DECL_BY_REFERENCE (decl
);
2179 /* Otherwise, we're taking an extra all.function_result_decl
2180 argument. It's set up in assign_parms_augmented_arg_list,
2181 under the (negated) conditions above, and then it's used to
2182 set up the RESULT_DECL rtl in assign_params, after looping
2183 over all parameters. Now, if the RESULT_DECL is not by
2184 reference, we'll use a MEM either way. */
2185 if (!DECL_BY_REFERENCE (decl
))
2188 /* Otherwise, if RESULT_DECL is DECL_BY_REFERENCE, it will take
2189 the function_result_decl's assignment. Since it's a pointer,
2190 we can short-circuit a number of the tests below, and we must
2191 duplicat e them because we don't have the
2192 function_result_decl to test. */
2193 if (!targetm
.calls
.allocate_stack_slots_for_args ())
2195 /* We don't set DECL_IGNORED_P for the function_result_decl. */
2198 /* We don't set DECL_REGISTER for the function_result_decl. */
2202 /* Only register-like things go in registers. */
2203 if (DECL_MODE (decl
) == BLKmode
)
2206 /* If -ffloat-store specified, don't put explicit float variables
2208 /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
2209 propagates values across these stores, and it probably shouldn't. */
2210 if (flag_float_store
&& FLOAT_TYPE_P (TREE_TYPE (decl
)))
2213 if (!targetm
.calls
.allocate_stack_slots_for_args ())
2216 /* If we're not interested in tracking debugging information for
2217 this decl, then we can certainly put it in a register. */
2218 if (DECL_IGNORED_P (decl
))
2224 if (!DECL_REGISTER (decl
))
2227 /* When not optimizing, disregard register keyword for types that
2228 could have methods, otherwise the methods won't be callable from
2230 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
)))
2236 /* Structures to communicate between the subroutines of assign_parms.
2237 The first holds data persistent across all parameters, the second
2238 is cleared out for each parameter. */
2240 struct assign_parm_data_all
2242 /* When INIT_CUMULATIVE_ARGS gets revamped, allocating CUMULATIVE_ARGS
2243 should become a job of the target or otherwise encapsulated. */
2244 CUMULATIVE_ARGS args_so_far_v
;
2245 cumulative_args_t args_so_far
;
2246 struct args_size stack_args_size
;
2247 tree function_result_decl
;
2249 rtx_insn
*first_conversion_insn
;
2250 rtx_insn
*last_conversion_insn
;
2251 HOST_WIDE_INT pretend_args_size
;
2252 HOST_WIDE_INT extra_pretend_bytes
;
2253 int reg_parm_stack_space
;
2256 struct assign_parm_data_one
2262 machine_mode nominal_mode
;
2263 machine_mode passed_mode
;
2264 machine_mode promoted_mode
;
2265 struct locate_and_pad_arg_data locate
;
2267 BOOL_BITFIELD named_arg
: 1;
2268 BOOL_BITFIELD passed_pointer
: 1;
2269 BOOL_BITFIELD on_stack
: 1;
2270 BOOL_BITFIELD loaded_in_reg
: 1;
2273 /* A subroutine of assign_parms. Initialize ALL. */
2276 assign_parms_initialize_all (struct assign_parm_data_all
*all
)
2278 tree fntype ATTRIBUTE_UNUSED
;
2280 memset (all
, 0, sizeof (*all
));
2282 fntype
= TREE_TYPE (current_function_decl
);
2284 #ifdef INIT_CUMULATIVE_INCOMING_ARGS
2285 INIT_CUMULATIVE_INCOMING_ARGS (all
->args_so_far_v
, fntype
, NULL_RTX
);
2287 INIT_CUMULATIVE_ARGS (all
->args_so_far_v
, fntype
, NULL_RTX
,
2288 current_function_decl
, -1);
2290 all
->args_so_far
= pack_cumulative_args (&all
->args_so_far_v
);
2292 #ifdef INCOMING_REG_PARM_STACK_SPACE
2293 all
->reg_parm_stack_space
2294 = INCOMING_REG_PARM_STACK_SPACE (current_function_decl
);
2298 /* If ARGS contains entries with complex types, split the entry into two
2299 entries of the component type. Return a new list of substitutions are
2300 needed, else the old list. */
2303 split_complex_args (vec
<tree
> *args
)
2308 FOR_EACH_VEC_ELT (*args
, i
, p
)
2310 tree type
= TREE_TYPE (p
);
2311 if (TREE_CODE (type
) == COMPLEX_TYPE
2312 && targetm
.calls
.split_complex_arg (type
))
2315 tree subtype
= TREE_TYPE (type
);
2316 bool addressable
= TREE_ADDRESSABLE (p
);
2318 /* Rewrite the PARM_DECL's type with its component. */
2320 TREE_TYPE (p
) = subtype
;
2321 DECL_ARG_TYPE (p
) = TREE_TYPE (DECL_ARG_TYPE (p
));
2322 SET_DECL_MODE (p
, VOIDmode
);
2323 DECL_SIZE (p
) = NULL
;
2324 DECL_SIZE_UNIT (p
) = NULL
;
2325 /* If this arg must go in memory, put it in a pseudo here.
2326 We can't allow it to go in memory as per normal parms,
2327 because the usual place might not have the imag part
2328 adjacent to the real part. */
2329 DECL_ARTIFICIAL (p
) = addressable
;
2330 DECL_IGNORED_P (p
) = addressable
;
2331 TREE_ADDRESSABLE (p
) = 0;
2335 /* Build a second synthetic decl. */
2336 decl
= build_decl (EXPR_LOCATION (p
),
2337 PARM_DECL
, NULL_TREE
, subtype
);
2338 DECL_ARG_TYPE (decl
) = DECL_ARG_TYPE (p
);
2339 DECL_ARTIFICIAL (decl
) = addressable
;
2340 DECL_IGNORED_P (decl
) = addressable
;
2341 layout_decl (decl
, 0);
2342 args
->safe_insert (++i
, decl
);
2347 /* A subroutine of assign_parms. Adjust the parameter list to incorporate
2348 the hidden struct return argument, and (abi willing) complex args.
2349 Return the new parameter list. */
2352 assign_parms_augmented_arg_list (struct assign_parm_data_all
*all
)
2354 tree fndecl
= current_function_decl
;
2355 tree fntype
= TREE_TYPE (fndecl
);
2356 vec
<tree
> fnargs
= vNULL
;
2359 for (arg
= DECL_ARGUMENTS (fndecl
); arg
; arg
= DECL_CHAIN (arg
))
2360 fnargs
.safe_push (arg
);
2362 all
->orig_fnargs
= DECL_ARGUMENTS (fndecl
);
2364 /* If struct value address is treated as the first argument, make it so. */
2365 if (aggregate_value_p (DECL_RESULT (fndecl
), fndecl
)
2366 && ! cfun
->returns_pcc_struct
2367 && targetm
.calls
.struct_value_rtx (TREE_TYPE (fndecl
), 1) == 0)
2369 tree type
= build_pointer_type (TREE_TYPE (fntype
));
2372 decl
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
2373 PARM_DECL
, get_identifier (".result_ptr"), type
);
2374 DECL_ARG_TYPE (decl
) = type
;
2375 DECL_ARTIFICIAL (decl
) = 1;
2376 DECL_NAMELESS (decl
) = 1;
2377 TREE_CONSTANT (decl
) = 1;
2378 /* We don't set DECL_IGNORED_P or DECL_REGISTER here. If this
2379 changes, the end of the RESULT_DECL handling block in
2380 use_register_for_decl must be adjusted to match. */
2382 DECL_CHAIN (decl
) = all
->orig_fnargs
;
2383 all
->orig_fnargs
= decl
;
2384 fnargs
.safe_insert (0, decl
);
2386 all
->function_result_decl
= decl
;
2389 /* If the target wants to split complex arguments into scalars, do so. */
2390 if (targetm
.calls
.split_complex_arg
)
2391 split_complex_args (&fnargs
);
2396 /* A subroutine of assign_parms. Examine PARM and pull out type and mode
2397 data for the parameter. Incorporate ABI specifics such as pass-by-
2398 reference and type promotion. */
2401 assign_parm_find_data_types (struct assign_parm_data_all
*all
, tree parm
,
2402 struct assign_parm_data_one
*data
)
2404 tree nominal_type
, passed_type
;
2405 machine_mode nominal_mode
, passed_mode
, promoted_mode
;
2408 memset (data
, 0, sizeof (*data
));
2410 /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */
2412 data
->named_arg
= 1; /* No variadic parms. */
2413 else if (DECL_CHAIN (parm
))
2414 data
->named_arg
= 1; /* Not the last non-variadic parm. */
2415 else if (targetm
.calls
.strict_argument_naming (all
->args_so_far
))
2416 data
->named_arg
= 1; /* Only variadic ones are unnamed. */
2418 data
->named_arg
= 0; /* Treat as variadic. */
2420 nominal_type
= TREE_TYPE (parm
);
2421 passed_type
= DECL_ARG_TYPE (parm
);
2423 /* Look out for errors propagating this far. Also, if the parameter's
2424 type is void then its value doesn't matter. */
2425 if (TREE_TYPE (parm
) == error_mark_node
2426 /* This can happen after weird syntax errors
2427 or if an enum type is defined among the parms. */
2428 || TREE_CODE (parm
) != PARM_DECL
2429 || passed_type
== NULL
2430 || VOID_TYPE_P (nominal_type
))
2432 nominal_type
= passed_type
= void_type_node
;
2433 nominal_mode
= passed_mode
= promoted_mode
= VOIDmode
;
2437 /* Find mode of arg as it is passed, and mode of arg as it should be
2438 during execution of this function. */
2439 passed_mode
= TYPE_MODE (passed_type
);
2440 nominal_mode
= TYPE_MODE (nominal_type
);
2442 /* If the parm is to be passed as a transparent union or record, use the
2443 type of the first field for the tests below. We have already verified
2444 that the modes are the same. */
2445 if ((TREE_CODE (passed_type
) == UNION_TYPE
2446 || TREE_CODE (passed_type
) == RECORD_TYPE
)
2447 && TYPE_TRANSPARENT_AGGR (passed_type
))
2448 passed_type
= TREE_TYPE (first_field (passed_type
));
2450 /* See if this arg was passed by invisible reference. */
2451 if (pass_by_reference (&all
->args_so_far_v
, passed_mode
,
2452 passed_type
, data
->named_arg
))
2454 passed_type
= nominal_type
= build_pointer_type (passed_type
);
2455 data
->passed_pointer
= true;
2456 passed_mode
= nominal_mode
= TYPE_MODE (nominal_type
);
2459 /* Find mode as it is passed by the ABI. */
2460 unsignedp
= TYPE_UNSIGNED (passed_type
);
2461 promoted_mode
= promote_function_mode (passed_type
, passed_mode
, &unsignedp
,
2462 TREE_TYPE (current_function_decl
), 0);
2465 data
->nominal_type
= nominal_type
;
2466 data
->passed_type
= passed_type
;
2467 data
->nominal_mode
= nominal_mode
;
2468 data
->passed_mode
= passed_mode
;
2469 data
->promoted_mode
= promoted_mode
;
2472 /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
2475 assign_parms_setup_varargs (struct assign_parm_data_all
*all
,
2476 struct assign_parm_data_one
*data
, bool no_rtl
)
2478 int varargs_pretend_bytes
= 0;
2480 targetm
.calls
.setup_incoming_varargs (all
->args_so_far
,
2481 data
->promoted_mode
,
2483 &varargs_pretend_bytes
, no_rtl
);
2485 /* If the back-end has requested extra stack space, record how much is
2486 needed. Do not change pretend_args_size otherwise since it may be
2487 nonzero from an earlier partial argument. */
2488 if (varargs_pretend_bytes
> 0)
2489 all
->pretend_args_size
= varargs_pretend_bytes
;
2492 /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
2493 the incoming location of the current parameter. */
2496 assign_parm_find_entry_rtl (struct assign_parm_data_all
*all
,
2497 struct assign_parm_data_one
*data
)
2499 HOST_WIDE_INT pretend_bytes
= 0;
2503 if (data
->promoted_mode
== VOIDmode
)
2505 data
->entry_parm
= data
->stack_parm
= const0_rtx
;
2509 targetm
.calls
.warn_parameter_passing_abi (all
->args_so_far
,
2512 entry_parm
= targetm
.calls
.function_incoming_arg (all
->args_so_far
,
2513 data
->promoted_mode
,
2517 if (entry_parm
== 0)
2518 data
->promoted_mode
= data
->passed_mode
;
2520 /* Determine parm's home in the stack, in case it arrives in the stack
2521 or we should pretend it did. Compute the stack position and rtx where
2522 the argument arrives and its size.
2524 There is one complexity here: If this was a parameter that would
2525 have been passed in registers, but wasn't only because it is
2526 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
2527 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
2528 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
2529 as it was the previous time. */
2530 in_regs
= (entry_parm
!= 0);
2531 #ifdef STACK_PARMS_IN_REG_PARM_AREA
2534 if (!in_regs
&& !data
->named_arg
)
2536 if (targetm
.calls
.pretend_outgoing_varargs_named (all
->args_so_far
))
2539 tem
= targetm
.calls
.function_incoming_arg (all
->args_so_far
,
2540 data
->promoted_mode
,
2541 data
->passed_type
, true);
2542 in_regs
= tem
!= NULL
;
2546 /* If this parameter was passed both in registers and in the stack, use
2547 the copy on the stack. */
2548 if (targetm
.calls
.must_pass_in_stack (data
->promoted_mode
,
2556 partial
= targetm
.calls
.arg_partial_bytes (all
->args_so_far
,
2557 data
->promoted_mode
,
2560 data
->partial
= partial
;
2562 /* The caller might already have allocated stack space for the
2563 register parameters. */
2564 if (partial
!= 0 && all
->reg_parm_stack_space
== 0)
2566 /* Part of this argument is passed in registers and part
2567 is passed on the stack. Ask the prologue code to extend
2568 the stack part so that we can recreate the full value.
2570 PRETEND_BYTES is the size of the registers we need to store.
2571 CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
2572 stack space that the prologue should allocate.
2574 Internally, gcc assumes that the argument pointer is aligned
2575 to STACK_BOUNDARY bits. This is used both for alignment
2576 optimizations (see init_emit) and to locate arguments that are
2577 aligned to more than PARM_BOUNDARY bits. We must preserve this
2578 invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
2579 a stack boundary. */
2581 /* We assume at most one partial arg, and it must be the first
2582 argument on the stack. */
2583 gcc_assert (!all
->extra_pretend_bytes
&& !all
->pretend_args_size
);
2585 pretend_bytes
= partial
;
2586 all
->pretend_args_size
= CEIL_ROUND (pretend_bytes
, STACK_BYTES
);
2588 /* We want to align relative to the actual stack pointer, so
2589 don't include this in the stack size until later. */
2590 all
->extra_pretend_bytes
= all
->pretend_args_size
;
2594 locate_and_pad_parm (data
->promoted_mode
, data
->passed_type
, in_regs
,
2595 all
->reg_parm_stack_space
,
2596 entry_parm
? data
->partial
: 0, current_function_decl
,
2597 &all
->stack_args_size
, &data
->locate
);
2599 /* Update parm_stack_boundary if this parameter is passed in the
2601 if (!in_regs
&& crtl
->parm_stack_boundary
< data
->locate
.boundary
)
2602 crtl
->parm_stack_boundary
= data
->locate
.boundary
;
2604 /* Adjust offsets to include the pretend args. */
2605 pretend_bytes
= all
->extra_pretend_bytes
- pretend_bytes
;
2606 data
->locate
.slot_offset
.constant
+= pretend_bytes
;
2607 data
->locate
.offset
.constant
+= pretend_bytes
;
2609 data
->entry_parm
= entry_parm
;
2612 /* A subroutine of assign_parms. If there is actually space on the stack
2613 for this parm, count it in stack_args_size and return true. */
2616 assign_parm_is_stack_parm (struct assign_parm_data_all
*all
,
2617 struct assign_parm_data_one
*data
)
2619 /* Trivially true if we've no incoming register. */
2620 if (data
->entry_parm
== NULL
)
2622 /* Also true if we're partially in registers and partially not,
2623 since we've arranged to drop the entire argument on the stack. */
2624 else if (data
->partial
!= 0)
2626 /* Also true if the target says that it's passed in both registers
2627 and on the stack. */
2628 else if (GET_CODE (data
->entry_parm
) == PARALLEL
2629 && XEXP (XVECEXP (data
->entry_parm
, 0, 0), 0) == NULL_RTX
)
2631 /* Also true if the target says that there's stack allocated for
2632 all register parameters. */
2633 else if (all
->reg_parm_stack_space
> 0)
2635 /* Otherwise, no, this parameter has no ABI defined stack slot. */
2639 all
->stack_args_size
.constant
+= data
->locate
.size
.constant
;
2640 if (data
->locate
.size
.var
)
2641 ADD_PARM_SIZE (all
->stack_args_size
, data
->locate
.size
.var
);
2646 /* A subroutine of assign_parms. Given that this parameter is allocated
2647 stack space by the ABI, find it. */
2650 assign_parm_find_stack_rtl (tree parm
, struct assign_parm_data_one
*data
)
2652 rtx offset_rtx
, stack_parm
;
2653 unsigned int align
, boundary
;
2655 /* If we're passing this arg using a reg, make its stack home the
2656 aligned stack slot. */
2657 if (data
->entry_parm
)
2658 offset_rtx
= ARGS_SIZE_RTX (data
->locate
.slot_offset
);
2660 offset_rtx
= ARGS_SIZE_RTX (data
->locate
.offset
);
2662 stack_parm
= crtl
->args
.internal_arg_pointer
;
2663 if (offset_rtx
!= const0_rtx
)
2664 stack_parm
= gen_rtx_PLUS (Pmode
, stack_parm
, offset_rtx
);
2665 stack_parm
= gen_rtx_MEM (data
->promoted_mode
, stack_parm
);
2667 if (!data
->passed_pointer
)
2669 set_mem_attributes (stack_parm
, parm
, 1);
2670 /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
2671 while promoted mode's size is needed. */
2672 if (data
->promoted_mode
!= BLKmode
2673 && data
->promoted_mode
!= DECL_MODE (parm
))
2675 set_mem_size (stack_parm
, GET_MODE_SIZE (data
->promoted_mode
));
2676 if (MEM_EXPR (stack_parm
) && MEM_OFFSET_KNOWN_P (stack_parm
))
2678 poly_int64 offset
= subreg_lowpart_offset (DECL_MODE (parm
),
2679 data
->promoted_mode
);
2680 if (maybe_ne (offset
, 0))
2681 set_mem_offset (stack_parm
, MEM_OFFSET (stack_parm
) - offset
);
2686 boundary
= data
->locate
.boundary
;
2687 align
= BITS_PER_UNIT
;
2689 /* If we're padding upward, we know that the alignment of the slot
2690 is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
2691 intentionally forcing upward padding. Otherwise we have to come
2692 up with a guess at the alignment based on OFFSET_RTX. */
2694 if (data
->locate
.where_pad
!= PAD_DOWNWARD
|| data
->entry_parm
)
2696 else if (poly_int_rtx_p (offset_rtx
, &offset
))
2698 align
= least_bit_hwi (boundary
);
2699 unsigned int offset_align
= known_alignment (offset
) * BITS_PER_UNIT
;
2700 if (offset_align
!= 0)
2701 align
= MIN (align
, offset_align
);
2703 set_mem_align (stack_parm
, align
);
2705 if (data
->entry_parm
)
2706 set_reg_attrs_for_parm (data
->entry_parm
, stack_parm
);
2708 data
->stack_parm
= stack_parm
;
2711 /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
2712 always valid and contiguous. */
2715 assign_parm_adjust_entry_rtl (struct assign_parm_data_one
*data
)
2717 rtx entry_parm
= data
->entry_parm
;
2718 rtx stack_parm
= data
->stack_parm
;
2720 /* If this parm was passed part in regs and part in memory, pretend it
2721 arrived entirely in memory by pushing the register-part onto the stack.
2722 In the special case of a DImode or DFmode that is split, we could put
2723 it together in a pseudoreg directly, but for now that's not worth
2725 if (data
->partial
!= 0)
2727 /* Handle calls that pass values in multiple non-contiguous
2728 locations. The Irix 6 ABI has examples of this. */
2729 if (GET_CODE (entry_parm
) == PARALLEL
)
2730 emit_group_store (validize_mem (copy_rtx (stack_parm
)), entry_parm
,
2732 int_size_in_bytes (data
->passed_type
));
2735 gcc_assert (data
->partial
% UNITS_PER_WORD
== 0);
2736 move_block_from_reg (REGNO (entry_parm
),
2737 validize_mem (copy_rtx (stack_parm
)),
2738 data
->partial
/ UNITS_PER_WORD
);
2741 entry_parm
= stack_parm
;
2744 /* If we didn't decide this parm came in a register, by default it came
2746 else if (entry_parm
== NULL
)
2747 entry_parm
= stack_parm
;
2749 /* When an argument is passed in multiple locations, we can't make use
2750 of this information, but we can save some copying if the whole argument
2751 is passed in a single register. */
2752 else if (GET_CODE (entry_parm
) == PARALLEL
2753 && data
->nominal_mode
!= BLKmode
2754 && data
->passed_mode
!= BLKmode
)
2756 size_t i
, len
= XVECLEN (entry_parm
, 0);
2758 for (i
= 0; i
< len
; i
++)
2759 if (XEXP (XVECEXP (entry_parm
, 0, i
), 0) != NULL_RTX
2760 && REG_P (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
2761 && (GET_MODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
2762 == data
->passed_mode
)
2763 && INTVAL (XEXP (XVECEXP (entry_parm
, 0, i
), 1)) == 0)
2765 entry_parm
= XEXP (XVECEXP (entry_parm
, 0, i
), 0);
2770 data
->entry_parm
= entry_parm
;
2773 /* A subroutine of assign_parms. Reconstitute any values which were
2774 passed in multiple registers and would fit in a single register. */
2777 assign_parm_remove_parallels (struct assign_parm_data_one
*data
)
2779 rtx entry_parm
= data
->entry_parm
;
2781 /* Convert the PARALLEL to a REG of the same mode as the parallel.
2782 This can be done with register operations rather than on the
2783 stack, even if we will store the reconstituted parameter on the
2785 if (GET_CODE (entry_parm
) == PARALLEL
&& GET_MODE (entry_parm
) != BLKmode
)
2787 rtx parmreg
= gen_reg_rtx (GET_MODE (entry_parm
));
2788 emit_group_store (parmreg
, entry_parm
, data
->passed_type
,
2789 GET_MODE_SIZE (GET_MODE (entry_parm
)));
2790 entry_parm
= parmreg
;
2793 data
->entry_parm
= entry_parm
;
2796 /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
2797 always valid and properly aligned. */
2800 assign_parm_adjust_stack_rtl (struct assign_parm_data_one
*data
)
2802 rtx stack_parm
= data
->stack_parm
;
2804 /* If we can't trust the parm stack slot to be aligned enough for its
2805 ultimate type, don't use that slot after entry. We'll make another
2806 stack slot, if we need one. */
2808 && ((STRICT_ALIGNMENT
2809 && GET_MODE_ALIGNMENT (data
->nominal_mode
) > MEM_ALIGN (stack_parm
))
2810 || (data
->nominal_type
2811 && TYPE_ALIGN (data
->nominal_type
) > MEM_ALIGN (stack_parm
)
2812 && MEM_ALIGN (stack_parm
) < PREFERRED_STACK_BOUNDARY
)))
2815 /* If parm was passed in memory, and we need to convert it on entry,
2816 don't store it back in that same slot. */
2817 else if (data
->entry_parm
== stack_parm
2818 && data
->nominal_mode
!= BLKmode
2819 && data
->nominal_mode
!= data
->passed_mode
)
2822 /* If stack protection is in effect for this function, don't leave any
2823 pointers in their passed stack slots. */
2824 else if (crtl
->stack_protect_guard
2825 && (flag_stack_protect
== 2
2826 || data
->passed_pointer
2827 || POINTER_TYPE_P (data
->nominal_type
)))
2830 data
->stack_parm
= stack_parm
;
2833 /* A subroutine of assign_parms. Return true if the current parameter
2834 should be stored as a BLKmode in the current frame. */
2837 assign_parm_setup_block_p (struct assign_parm_data_one
*data
)
2839 if (data
->nominal_mode
== BLKmode
)
2841 if (GET_MODE (data
->entry_parm
) == BLKmode
)
2844 #ifdef BLOCK_REG_PADDING
2845 /* Only assign_parm_setup_block knows how to deal with register arguments
2846 that are padded at the least significant end. */
2847 if (REG_P (data
->entry_parm
)
2848 && known_lt (GET_MODE_SIZE (data
->promoted_mode
), UNITS_PER_WORD
)
2849 && (BLOCK_REG_PADDING (data
->passed_mode
, data
->passed_type
, 1)
2850 == (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
)))
2857 /* A subroutine of assign_parms. Arrange for the parameter to be
2858 present and valid in DATA->STACK_RTL. */
2861 assign_parm_setup_block (struct assign_parm_data_all
*all
,
2862 tree parm
, struct assign_parm_data_one
*data
)
2864 rtx entry_parm
= data
->entry_parm
;
2865 rtx stack_parm
= data
->stack_parm
;
2866 rtx target_reg
= NULL_RTX
;
2867 bool in_conversion_seq
= false;
2869 HOST_WIDE_INT size_stored
;
2871 if (GET_CODE (entry_parm
) == PARALLEL
)
2872 entry_parm
= emit_group_move_into_temps (entry_parm
);
2874 /* If we want the parameter in a pseudo, don't use a stack slot. */
2875 if (is_gimple_reg (parm
) && use_register_for_decl (parm
))
2877 tree def
= ssa_default_def (cfun
, parm
);
2879 machine_mode mode
= promote_ssa_mode (def
, NULL
);
2880 rtx reg
= gen_reg_rtx (mode
);
2881 if (GET_CODE (reg
) != CONCAT
)
2886 /* Avoid allocating a stack slot, if there isn't one
2887 preallocated by the ABI. It might seem like we should
2888 always prefer a pseudo, but converting between
2889 floating-point and integer modes goes through the stack
2890 on various machines, so it's better to use the reserved
2891 stack slot than to risk wasting it and allocating more
2892 for the conversion. */
2893 if (stack_parm
== NULL_RTX
)
2895 int save
= generating_concat_p
;
2896 generating_concat_p
= 0;
2897 stack_parm
= gen_reg_rtx (mode
);
2898 generating_concat_p
= save
;
2901 data
->stack_parm
= NULL
;
2904 size
= int_size_in_bytes (data
->passed_type
);
2905 size_stored
= CEIL_ROUND (size
, UNITS_PER_WORD
);
2906 if (stack_parm
== 0)
2908 SET_DECL_ALIGN (parm
, MAX (DECL_ALIGN (parm
), BITS_PER_WORD
));
2909 stack_parm
= assign_stack_local (BLKmode
, size_stored
,
2911 if (known_eq (GET_MODE_SIZE (GET_MODE (entry_parm
)), size
))
2912 PUT_MODE (stack_parm
, GET_MODE (entry_parm
));
2913 set_mem_attributes (stack_parm
, parm
, 1);
2916 /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
2917 calls that pass values in multiple non-contiguous locations. */
2918 if (REG_P (entry_parm
) || GET_CODE (entry_parm
) == PARALLEL
)
2922 /* Note that we will be storing an integral number of words.
2923 So we have to be careful to ensure that we allocate an
2924 integral number of words. We do this above when we call
2925 assign_stack_local if space was not allocated in the argument
2926 list. If it was, this will not work if PARM_BOUNDARY is not
2927 a multiple of BITS_PER_WORD. It isn't clear how to fix this
2928 if it becomes a problem. Exception is when BLKmode arrives
2929 with arguments not conforming to word_mode. */
2931 if (data
->stack_parm
== 0)
2933 else if (GET_CODE (entry_parm
) == PARALLEL
)
2936 gcc_assert (!size
|| !(PARM_BOUNDARY
% BITS_PER_WORD
));
2938 mem
= validize_mem (copy_rtx (stack_parm
));
2940 /* Handle values in multiple non-contiguous locations. */
2941 if (GET_CODE (entry_parm
) == PARALLEL
&& !MEM_P (mem
))
2942 emit_group_store (mem
, entry_parm
, data
->passed_type
, size
);
2943 else if (GET_CODE (entry_parm
) == PARALLEL
)
2945 push_to_sequence2 (all
->first_conversion_insn
,
2946 all
->last_conversion_insn
);
2947 emit_group_store (mem
, entry_parm
, data
->passed_type
, size
);
2948 all
->first_conversion_insn
= get_insns ();
2949 all
->last_conversion_insn
= get_last_insn ();
2951 in_conversion_seq
= true;
2957 /* If SIZE is that of a mode no bigger than a word, just use
2958 that mode's store operation. */
2959 else if (size
<= UNITS_PER_WORD
)
2961 unsigned int bits
= size
* BITS_PER_UNIT
;
2962 machine_mode mode
= int_mode_for_size (bits
, 0).else_blk ();
2965 #ifdef BLOCK_REG_PADDING
2966 && (size
== UNITS_PER_WORD
2967 || (BLOCK_REG_PADDING (mode
, data
->passed_type
, 1)
2968 != (BYTES_BIG_ENDIAN
? PAD_UPWARD
: PAD_DOWNWARD
)))
2974 /* We are really truncating a word_mode value containing
2975 SIZE bytes into a value of mode MODE. If such an
2976 operation requires no actual instructions, we can refer
2977 to the value directly in mode MODE, otherwise we must
2978 start with the register in word_mode and explicitly
2980 if (targetm
.truly_noop_truncation (size
* BITS_PER_UNIT
,
2982 reg
= gen_rtx_REG (mode
, REGNO (entry_parm
));
2985 reg
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
2986 reg
= convert_to_mode (mode
, copy_to_reg (reg
), 1);
2988 emit_move_insn (change_address (mem
, mode
, 0), reg
);
2991 #ifdef BLOCK_REG_PADDING
2992 /* Storing the register in memory as a full word, as
2993 move_block_from_reg below would do, and then using the
2994 MEM in a smaller mode, has the effect of shifting right
2995 if BYTES_BIG_ENDIAN. If we're bypassing memory, the
2996 shifting must be explicit. */
2997 else if (!MEM_P (mem
))
3001 /* If the assert below fails, we should have taken the
3002 mode != BLKmode path above, unless we have downward
3003 padding of smaller-than-word arguments on a machine
3004 with little-endian bytes, which would likely require
3005 additional changes to work correctly. */
3006 gcc_checking_assert (BYTES_BIG_ENDIAN
3007 && (BLOCK_REG_PADDING (mode
,
3008 data
->passed_type
, 1)
3011 int by
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
3013 x
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
3014 x
= expand_shift (RSHIFT_EXPR
, word_mode
, x
, by
,
3016 x
= force_reg (word_mode
, x
);
3017 x
= gen_lowpart_SUBREG (GET_MODE (mem
), x
);
3019 emit_move_insn (mem
, x
);
3023 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
3024 machine must be aligned to the left before storing
3025 to memory. Note that the previous test doesn't
3026 handle all cases (e.g. SIZE == 3). */
3027 else if (size
!= UNITS_PER_WORD
3028 #ifdef BLOCK_REG_PADDING
3029 && (BLOCK_REG_PADDING (mode
, data
->passed_type
, 1)
3037 int by
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
3038 rtx reg
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
3040 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, by
, NULL_RTX
, 1);
3041 tem
= change_address (mem
, word_mode
, 0);
3042 emit_move_insn (tem
, x
);
3045 move_block_from_reg (REGNO (entry_parm
), mem
,
3046 size_stored
/ UNITS_PER_WORD
);
3048 else if (!MEM_P (mem
))
3050 gcc_checking_assert (size
> UNITS_PER_WORD
);
3051 #ifdef BLOCK_REG_PADDING
3052 gcc_checking_assert (BLOCK_REG_PADDING (GET_MODE (mem
),
3053 data
->passed_type
, 0)
3056 emit_move_insn (mem
, entry_parm
);
3059 move_block_from_reg (REGNO (entry_parm
), mem
,
3060 size_stored
/ UNITS_PER_WORD
);
3062 else if (data
->stack_parm
== 0)
3064 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3065 emit_block_move (stack_parm
, data
->entry_parm
, GEN_INT (size
),
3067 all
->first_conversion_insn
= get_insns ();
3068 all
->last_conversion_insn
= get_last_insn ();
3070 in_conversion_seq
= true;
3075 if (!in_conversion_seq
)
3076 emit_move_insn (target_reg
, stack_parm
);
3079 push_to_sequence2 (all
->first_conversion_insn
,
3080 all
->last_conversion_insn
);
3081 emit_move_insn (target_reg
, stack_parm
);
3082 all
->first_conversion_insn
= get_insns ();
3083 all
->last_conversion_insn
= get_last_insn ();
3086 stack_parm
= target_reg
;
3089 data
->stack_parm
= stack_parm
;
3090 set_parm_rtl (parm
, stack_parm
);
3093 /* A subroutine of assign_parms. Allocate a pseudo to hold the current
3094 parameter. Get it there. Perform all ABI specified conversions. */
3097 assign_parm_setup_reg (struct assign_parm_data_all
*all
, tree parm
,
3098 struct assign_parm_data_one
*data
)
3100 rtx parmreg
, validated_mem
;
3101 rtx equiv_stack_parm
;
3102 machine_mode promoted_nominal_mode
;
3103 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (parm
));
3104 bool did_conversion
= false;
3105 bool need_conversion
, moved
;
3108 /* Store the parm in a pseudoregister during the function, but we may
3109 need to do it in a wider mode. Using 2 here makes the result
3110 consistent with promote_decl_mode and thus expand_expr_real_1. */
3111 promoted_nominal_mode
3112 = promote_function_mode (data
->nominal_type
, data
->nominal_mode
, &unsignedp
,
3113 TREE_TYPE (current_function_decl
), 2);
3115 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
3116 if (!DECL_ARTIFICIAL (parm
))
3117 mark_user_reg (parmreg
);
3119 /* If this was an item that we received a pointer to,
3120 set rtl appropriately. */
3121 if (data
->passed_pointer
)
3123 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data
->passed_type
)), parmreg
);
3124 set_mem_attributes (rtl
, parm
, 1);
3129 assign_parm_remove_parallels (data
);
3131 /* Copy the value into the register, thus bridging between
3132 assign_parm_find_data_types and expand_expr_real_1. */
3134 equiv_stack_parm
= data
->stack_parm
;
3135 validated_mem
= validize_mem (copy_rtx (data
->entry_parm
));
3137 need_conversion
= (data
->nominal_mode
!= data
->passed_mode
3138 || promoted_nominal_mode
!= data
->promoted_mode
);
3142 && GET_MODE_CLASS (data
->nominal_mode
) == MODE_INT
3143 && data
->nominal_mode
== data
->passed_mode
3144 && data
->nominal_mode
== GET_MODE (data
->entry_parm
))
3146 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3147 mode, by the caller. We now have to convert it to
3148 NOMINAL_MODE, if different. However, PARMREG may be in
3149 a different mode than NOMINAL_MODE if it is being stored
3152 If ENTRY_PARM is a hard register, it might be in a register
3153 not valid for operating in its mode (e.g., an odd-numbered
3154 register for a DFmode). In that case, moves are the only
3155 thing valid, so we can't do a convert from there. This
3156 occurs when the calling sequence allow such misaligned
3159 In addition, the conversion may involve a call, which could
3160 clobber parameters which haven't been copied to pseudo
3163 First, we try to emit an insn which performs the necessary
3164 conversion. We verify that this insn does not clobber any
3167 enum insn_code icode
;
3170 icode
= can_extend_p (promoted_nominal_mode
, data
->passed_mode
,
3174 op1
= validated_mem
;
3175 if (icode
!= CODE_FOR_nothing
3176 && insn_operand_matches (icode
, 0, op0
)
3177 && insn_operand_matches (icode
, 1, op1
))
3179 enum rtx_code code
= unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
;
3180 rtx_insn
*insn
, *insns
;
3182 HARD_REG_SET hardregs
;
3185 /* If op1 is a hard register that is likely spilled, first
3186 force it into a pseudo, otherwise combiner might extend
3187 its lifetime too much. */
3188 if (GET_CODE (t
) == SUBREG
)
3191 && HARD_REGISTER_P (t
)
3192 && ! TEST_HARD_REG_BIT (fixed_reg_set
, REGNO (t
))
3193 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (t
))))
3195 t
= gen_reg_rtx (GET_MODE (op1
));
3196 emit_move_insn (t
, op1
);
3200 rtx_insn
*pat
= gen_extend_insn (op0
, t
, promoted_nominal_mode
,
3201 data
->passed_mode
, unsignedp
);
3203 insns
= get_insns ();
3206 CLEAR_HARD_REG_SET (hardregs
);
3207 for (insn
= insns
; insn
&& moved
; insn
= NEXT_INSN (insn
))
3210 note_stores (PATTERN (insn
), record_hard_reg_sets
,
3212 if (!hard_reg_set_empty_p (hardregs
))
3221 if (equiv_stack_parm
!= NULL_RTX
)
3222 equiv_stack_parm
= gen_rtx_fmt_e (code
, GET_MODE (parmreg
),
3229 /* Nothing to do. */
3231 else if (need_conversion
)
3233 /* We did not have an insn to convert directly, or the sequence
3234 generated appeared unsafe. We must first copy the parm to a
3235 pseudo reg, and save the conversion until after all
3236 parameters have been moved. */
3239 rtx tempreg
= gen_reg_rtx (GET_MODE (data
->entry_parm
));
3241 emit_move_insn (tempreg
, validated_mem
);
3243 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3244 tempreg
= convert_to_mode (data
->nominal_mode
, tempreg
, unsignedp
);
3246 if (partial_subreg_p (tempreg
)
3247 && GET_MODE (tempreg
) == data
->nominal_mode
3248 && REG_P (SUBREG_REG (tempreg
))
3249 && data
->nominal_mode
== data
->passed_mode
3250 && GET_MODE (SUBREG_REG (tempreg
)) == GET_MODE (data
->entry_parm
))
3252 /* The argument is already sign/zero extended, so note it
3254 SUBREG_PROMOTED_VAR_P (tempreg
) = 1;
3255 SUBREG_PROMOTED_SET (tempreg
, unsignedp
);
3258 /* TREE_USED gets set erroneously during expand_assignment. */
3259 save_tree_used
= TREE_USED (parm
);
3260 SET_DECL_RTL (parm
, rtl
);
3261 expand_assignment (parm
, make_tree (data
->nominal_type
, tempreg
), false);
3262 SET_DECL_RTL (parm
, NULL_RTX
);
3263 TREE_USED (parm
) = save_tree_used
;
3264 all
->first_conversion_insn
= get_insns ();
3265 all
->last_conversion_insn
= get_last_insn ();
3268 did_conversion
= true;
3271 emit_move_insn (parmreg
, validated_mem
);
3273 /* If we were passed a pointer but the actual value can safely live
3274 in a register, retrieve it and use it directly. */
3275 if (data
->passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
)
3277 /* We can't use nominal_mode, because it will have been set to
3278 Pmode above. We must use the actual mode of the parm. */
3279 if (use_register_for_decl (parm
))
3281 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
3282 mark_user_reg (parmreg
);
3286 int align
= STACK_SLOT_ALIGNMENT (TREE_TYPE (parm
),
3287 TYPE_MODE (TREE_TYPE (parm
)),
3288 TYPE_ALIGN (TREE_TYPE (parm
)));
3290 = assign_stack_local (TYPE_MODE (TREE_TYPE (parm
)),
3291 GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parm
))),
3293 set_mem_attributes (parmreg
, parm
, 1);
3296 /* We need to preserve an address based on VIRTUAL_STACK_VARS_REGNUM for
3297 the debug info in case it is not legitimate. */
3298 if (GET_MODE (parmreg
) != GET_MODE (rtl
))
3300 rtx tempreg
= gen_reg_rtx (GET_MODE (rtl
));
3301 int unsigned_p
= TYPE_UNSIGNED (TREE_TYPE (parm
));
3303 push_to_sequence2 (all
->first_conversion_insn
,
3304 all
->last_conversion_insn
);
3305 emit_move_insn (tempreg
, rtl
);
3306 tempreg
= convert_to_mode (GET_MODE (parmreg
), tempreg
, unsigned_p
);
3307 emit_move_insn (MEM_P (parmreg
) ? copy_rtx (parmreg
) : parmreg
,
3309 all
->first_conversion_insn
= get_insns ();
3310 all
->last_conversion_insn
= get_last_insn ();
3313 did_conversion
= true;
3316 emit_move_insn (MEM_P (parmreg
) ? copy_rtx (parmreg
) : parmreg
, rtl
);
3320 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3322 data
->stack_parm
= NULL
;
3325 set_parm_rtl (parm
, rtl
);
3327 /* Mark the register as eliminable if we did no conversion and it was
3328 copied from memory at a fixed offset, and the arg pointer was not
3329 copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
3330 offset formed an invalid address, such memory-equivalences as we
3331 make here would screw up life analysis for it. */
3332 if (data
->nominal_mode
== data
->passed_mode
3334 && data
->stack_parm
!= 0
3335 && MEM_P (data
->stack_parm
)
3336 && data
->locate
.offset
.var
== 0
3337 && reg_mentioned_p (virtual_incoming_args_rtx
,
3338 XEXP (data
->stack_parm
, 0)))
3340 rtx_insn
*linsn
= get_last_insn ();
3344 /* Mark complex types separately. */
3345 if (GET_CODE (parmreg
) == CONCAT
)
3347 scalar_mode submode
= GET_MODE_INNER (GET_MODE (parmreg
));
3348 int regnor
= REGNO (XEXP (parmreg
, 0));
3349 int regnoi
= REGNO (XEXP (parmreg
, 1));
3350 rtx stackr
= adjust_address_nv (data
->stack_parm
, submode
, 0);
3351 rtx stacki
= adjust_address_nv (data
->stack_parm
, submode
,
3352 GET_MODE_SIZE (submode
));
3354 /* Scan backwards for the set of the real and
3356 for (sinsn
= linsn
; sinsn
!= 0;
3357 sinsn
= prev_nonnote_insn (sinsn
))
3359 set
= single_set (sinsn
);
3363 if (SET_DEST (set
) == regno_reg_rtx
[regnoi
])
3364 set_unique_reg_note (sinsn
, REG_EQUIV
, stacki
);
3365 else if (SET_DEST (set
) == regno_reg_rtx
[regnor
])
3366 set_unique_reg_note (sinsn
, REG_EQUIV
, stackr
);
3370 set_dst_reg_note (linsn
, REG_EQUIV
, equiv_stack_parm
, parmreg
);
3373 /* For pointer data type, suggest pointer register. */
3374 if (POINTER_TYPE_P (TREE_TYPE (parm
)))
3375 mark_reg_pointer (parmreg
,
3376 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
3379 /* A subroutine of assign_parms. Allocate stack space to hold the current
3380 parameter. Get it there. Perform all ABI specified conversions. */
3383 assign_parm_setup_stack (struct assign_parm_data_all
*all
, tree parm
,
3384 struct assign_parm_data_one
*data
)
3386 /* Value must be stored in the stack slot STACK_PARM during function
3388 bool to_conversion
= false;
3390 assign_parm_remove_parallels (data
);
3392 if (data
->promoted_mode
!= data
->nominal_mode
)
3394 /* Conversion is required. */
3395 rtx tempreg
= gen_reg_rtx (GET_MODE (data
->entry_parm
));
3397 emit_move_insn (tempreg
, validize_mem (copy_rtx (data
->entry_parm
)));
3399 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3400 to_conversion
= true;
3402 data
->entry_parm
= convert_to_mode (data
->nominal_mode
, tempreg
,
3403 TYPE_UNSIGNED (TREE_TYPE (parm
)));
3405 if (data
->stack_parm
)
3408 = subreg_lowpart_offset (data
->nominal_mode
,
3409 GET_MODE (data
->stack_parm
));
3410 /* ??? This may need a big-endian conversion on sparc64. */
3412 = adjust_address (data
->stack_parm
, data
->nominal_mode
, 0);
3413 if (maybe_ne (offset
, 0) && MEM_OFFSET_KNOWN_P (data
->stack_parm
))
3414 set_mem_offset (data
->stack_parm
,
3415 MEM_OFFSET (data
->stack_parm
) + offset
);
3419 if (data
->entry_parm
!= data
->stack_parm
)
3423 if (data
->stack_parm
== 0)
3425 int align
= STACK_SLOT_ALIGNMENT (data
->passed_type
,
3426 GET_MODE (data
->entry_parm
),
3427 TYPE_ALIGN (data
->passed_type
));
3429 = assign_stack_local (GET_MODE (data
->entry_parm
),
3430 GET_MODE_SIZE (GET_MODE (data
->entry_parm
)),
3432 set_mem_attributes (data
->stack_parm
, parm
, 1);
3435 dest
= validize_mem (copy_rtx (data
->stack_parm
));
3436 src
= validize_mem (copy_rtx (data
->entry_parm
));
3440 /* Use a block move to handle potentially misaligned entry_parm. */
3442 push_to_sequence2 (all
->first_conversion_insn
,
3443 all
->last_conversion_insn
);
3444 to_conversion
= true;
3446 emit_block_move (dest
, src
,
3447 GEN_INT (int_size_in_bytes (data
->passed_type
)),
3453 src
= force_reg (GET_MODE (src
), src
);
3454 emit_move_insn (dest
, src
);
3460 all
->first_conversion_insn
= get_insns ();
3461 all
->last_conversion_insn
= get_last_insn ();
3465 set_parm_rtl (parm
, data
->stack_parm
);
3468 /* A subroutine of assign_parms. If the ABI splits complex arguments, then
3469 undo the frobbing that we did in assign_parms_augmented_arg_list. */
3472 assign_parms_unsplit_complex (struct assign_parm_data_all
*all
,
3476 tree orig_fnargs
= all
->orig_fnargs
;
3479 for (parm
= orig_fnargs
; parm
; parm
= TREE_CHAIN (parm
), ++i
)
3481 if (TREE_CODE (TREE_TYPE (parm
)) == COMPLEX_TYPE
3482 && targetm
.calls
.split_complex_arg (TREE_TYPE (parm
)))
3484 rtx tmp
, real
, imag
;
3485 scalar_mode inner
= GET_MODE_INNER (DECL_MODE (parm
));
3487 real
= DECL_RTL (fnargs
[i
]);
3488 imag
= DECL_RTL (fnargs
[i
+ 1]);
3489 if (inner
!= GET_MODE (real
))
3491 real
= gen_lowpart_SUBREG (inner
, real
);
3492 imag
= gen_lowpart_SUBREG (inner
, imag
);
3495 if (TREE_ADDRESSABLE (parm
))
3498 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (parm
));
3499 int align
= STACK_SLOT_ALIGNMENT (TREE_TYPE (parm
),
3501 TYPE_ALIGN (TREE_TYPE (parm
)));
3503 /* split_complex_arg put the real and imag parts in
3504 pseudos. Move them to memory. */
3505 tmp
= assign_stack_local (DECL_MODE (parm
), size
, align
);
3506 set_mem_attributes (tmp
, parm
, 1);
3507 rmem
= adjust_address_nv (tmp
, inner
, 0);
3508 imem
= adjust_address_nv (tmp
, inner
, GET_MODE_SIZE (inner
));
3509 push_to_sequence2 (all
->first_conversion_insn
,
3510 all
->last_conversion_insn
);
3511 emit_move_insn (rmem
, real
);
3512 emit_move_insn (imem
, imag
);
3513 all
->first_conversion_insn
= get_insns ();
3514 all
->last_conversion_insn
= get_last_insn ();
3518 tmp
= gen_rtx_CONCAT (DECL_MODE (parm
), real
, imag
);
3519 set_parm_rtl (parm
, tmp
);
3521 real
= DECL_INCOMING_RTL (fnargs
[i
]);
3522 imag
= DECL_INCOMING_RTL (fnargs
[i
+ 1]);
3523 if (inner
!= GET_MODE (real
))
3525 real
= gen_lowpart_SUBREG (inner
, real
);
3526 imag
= gen_lowpart_SUBREG (inner
, imag
);
3528 tmp
= gen_rtx_CONCAT (DECL_MODE (parm
), real
, imag
);
3529 set_decl_incoming_rtl (parm
, tmp
, false);
3535 /* Assign RTL expressions to the function's parameters. This may involve
3536 copying them into registers and using those registers as the DECL_RTL. */
3539 assign_parms (tree fndecl
)
3541 struct assign_parm_data_all all
;
3546 crtl
->args
.internal_arg_pointer
3547 = targetm
.calls
.internal_arg_pointer ();
3549 assign_parms_initialize_all (&all
);
3550 fnargs
= assign_parms_augmented_arg_list (&all
);
3552 FOR_EACH_VEC_ELT (fnargs
, i
, parm
)
3554 struct assign_parm_data_one data
;
3556 /* Extract the type of PARM; adjust it according to ABI. */
3557 assign_parm_find_data_types (&all
, parm
, &data
);
3559 /* Early out for errors and void parameters. */
3560 if (data
.passed_mode
== VOIDmode
)
3562 SET_DECL_RTL (parm
, const0_rtx
);
3563 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
3567 /* Estimate stack alignment from parameter alignment. */
3568 if (SUPPORTS_STACK_ALIGNMENT
)
3571 = targetm
.calls
.function_arg_boundary (data
.promoted_mode
,
3573 align
= MINIMUM_ALIGNMENT (data
.passed_type
, data
.promoted_mode
,
3575 if (TYPE_ALIGN (data
.nominal_type
) > align
)
3576 align
= MINIMUM_ALIGNMENT (data
.nominal_type
,
3577 TYPE_MODE (data
.nominal_type
),
3578 TYPE_ALIGN (data
.nominal_type
));
3579 if (crtl
->stack_alignment_estimated
< align
)
3581 gcc_assert (!crtl
->stack_realign_processed
);
3582 crtl
->stack_alignment_estimated
= align
;
3586 /* Find out where the parameter arrives in this function. */
3587 assign_parm_find_entry_rtl (&all
, &data
);
3589 /* Find out where stack space for this parameter might be. */
3590 if (assign_parm_is_stack_parm (&all
, &data
))
3592 assign_parm_find_stack_rtl (parm
, &data
);
3593 assign_parm_adjust_entry_rtl (&data
);
3595 /* Record permanently how this parm was passed. */
3596 if (data
.passed_pointer
)
3599 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data
.passed_type
)),
3601 set_decl_incoming_rtl (parm
, incoming_rtl
, true);
3604 set_decl_incoming_rtl (parm
, data
.entry_parm
, false);
3606 assign_parm_adjust_stack_rtl (&data
);
3608 if (assign_parm_setup_block_p (&data
))
3609 assign_parm_setup_block (&all
, parm
, &data
);
3610 else if (data
.passed_pointer
|| use_register_for_decl (parm
))
3611 assign_parm_setup_reg (&all
, parm
, &data
);
3613 assign_parm_setup_stack (&all
, parm
, &data
);
3615 if (cfun
->stdarg
&& !DECL_CHAIN (parm
))
3616 assign_parms_setup_varargs (&all
, &data
, false);
3618 /* Update info on where next arg arrives in registers. */
3619 targetm
.calls
.function_arg_advance (all
.args_so_far
, data
.promoted_mode
,
3620 data
.passed_type
, data
.named_arg
);
3623 if (targetm
.calls
.split_complex_arg
)
3624 assign_parms_unsplit_complex (&all
, fnargs
);
3628 /* Output all parameter conversion instructions (possibly including calls)
3629 now that all parameters have been copied out of hard registers. */
3630 emit_insn (all
.first_conversion_insn
);
3632 /* Estimate reload stack alignment from scalar return mode. */
3633 if (SUPPORTS_STACK_ALIGNMENT
)
3635 if (DECL_RESULT (fndecl
))
3637 tree type
= TREE_TYPE (DECL_RESULT (fndecl
));
3638 machine_mode mode
= TYPE_MODE (type
);
3642 && !AGGREGATE_TYPE_P (type
))
3644 unsigned int align
= GET_MODE_ALIGNMENT (mode
);
3645 if (crtl
->stack_alignment_estimated
< align
)
3647 gcc_assert (!crtl
->stack_realign_processed
);
3648 crtl
->stack_alignment_estimated
= align
;
3654 /* If we are receiving a struct value address as the first argument, set up
3655 the RTL for the function result. As this might require code to convert
3656 the transmitted address to Pmode, we do this here to ensure that possible
3657 preliminary conversions of the address have been emitted already. */
3658 if (all
.function_result_decl
)
3660 tree result
= DECL_RESULT (current_function_decl
);
3661 rtx addr
= DECL_RTL (all
.function_result_decl
);
3664 if (DECL_BY_REFERENCE (result
))
3666 SET_DECL_VALUE_EXPR (result
, all
.function_result_decl
);
3671 SET_DECL_VALUE_EXPR (result
,
3672 build1 (INDIRECT_REF
, TREE_TYPE (result
),
3673 all
.function_result_decl
));
3674 addr
= convert_memory_address (Pmode
, addr
);
3675 x
= gen_rtx_MEM (DECL_MODE (result
), addr
);
3676 set_mem_attributes (x
, result
, 1);
3679 DECL_HAS_VALUE_EXPR_P (result
) = 1;
3681 set_parm_rtl (result
, x
);
3684 /* We have aligned all the args, so add space for the pretend args. */
3685 crtl
->args
.pretend_args_size
= all
.pretend_args_size
;
3686 all
.stack_args_size
.constant
+= all
.extra_pretend_bytes
;
3687 crtl
->args
.size
= all
.stack_args_size
.constant
;
3689 /* Adjust function incoming argument size for alignment and
3692 crtl
->args
.size
= upper_bound (crtl
->args
.size
, all
.reg_parm_stack_space
);
3693 crtl
->args
.size
= aligned_upper_bound (crtl
->args
.size
,
3694 PARM_BOUNDARY
/ BITS_PER_UNIT
);
3696 if (ARGS_GROW_DOWNWARD
)
3698 crtl
->args
.arg_offset_rtx
3699 = (all
.stack_args_size
.var
== 0
3700 ? gen_int_mode (-all
.stack_args_size
.constant
, Pmode
)
3701 : expand_expr (size_diffop (all
.stack_args_size
.var
,
3702 size_int (-all
.stack_args_size
.constant
)),
3703 NULL_RTX
, VOIDmode
, EXPAND_NORMAL
));
3706 crtl
->args
.arg_offset_rtx
= ARGS_SIZE_RTX (all
.stack_args_size
);
3708 /* See how many bytes, if any, of its args a function should try to pop
3711 crtl
->args
.pops_args
= targetm
.calls
.return_pops_args (fndecl
,
3715 /* For stdarg.h function, save info about
3716 regs and stack space used by the named args. */
3718 crtl
->args
.info
= all
.args_so_far_v
;
3720 /* Set the rtx used for the function return value. Put this in its
3721 own variable so any optimizers that need this information don't have
3722 to include tree.h. Do this here so it gets done when an inlined
3723 function gets output. */
3726 = (DECL_RTL_SET_P (DECL_RESULT (fndecl
))
3727 ? DECL_RTL (DECL_RESULT (fndecl
)) : NULL_RTX
);
3729 /* If scalar return value was computed in a pseudo-reg, or was a named
3730 return value that got dumped to the stack, copy that to the hard
3732 if (DECL_RTL_SET_P (DECL_RESULT (fndecl
)))
3734 tree decl_result
= DECL_RESULT (fndecl
);
3735 rtx decl_rtl
= DECL_RTL (decl_result
);
3737 if (REG_P (decl_rtl
)
3738 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
3739 : DECL_REGISTER (decl_result
))
3743 real_decl_rtl
= targetm
.calls
.function_value (TREE_TYPE (decl_result
),
3745 REG_FUNCTION_VALUE_P (real_decl_rtl
) = 1;
3746 /* The delay slot scheduler assumes that crtl->return_rtx
3747 holds the hard register containing the return value, not a
3748 temporary pseudo. */
3749 crtl
->return_rtx
= real_decl_rtl
;
3754 /* A subroutine of gimplify_parameters, invoked via walk_tree.
3755 For all seen types, gimplify their sizes. */
3758 gimplify_parm_type (tree
*tp
, int *walk_subtrees
, void *data
)
3765 if (POINTER_TYPE_P (t
))
3767 else if (TYPE_SIZE (t
) && !TREE_CONSTANT (TYPE_SIZE (t
))
3768 && !TYPE_SIZES_GIMPLIFIED (t
))
3770 gimplify_type_sizes (t
, (gimple_seq
*) data
);
3778 /* Gimplify the parameter list for current_function_decl. This involves
3779 evaluating SAVE_EXPRs of variable sized parameters and generating code
3780 to implement callee-copies reference parameters. Returns a sequence of
3781 statements to add to the beginning of the function. */
3784 gimplify_parameters (gimple_seq
*cleanup
)
3786 struct assign_parm_data_all all
;
3788 gimple_seq stmts
= NULL
;
3792 assign_parms_initialize_all (&all
);
3793 fnargs
= assign_parms_augmented_arg_list (&all
);
3795 FOR_EACH_VEC_ELT (fnargs
, i
, parm
)
3797 struct assign_parm_data_one data
;
3799 /* Extract the type of PARM; adjust it according to ABI. */
3800 assign_parm_find_data_types (&all
, parm
, &data
);
3802 /* Early out for errors and void parameters. */
3803 if (data
.passed_mode
== VOIDmode
|| DECL_SIZE (parm
) == NULL
)
3806 /* Update info on where next arg arrives in registers. */
3807 targetm
.calls
.function_arg_advance (all
.args_so_far
, data
.promoted_mode
,
3808 data
.passed_type
, data
.named_arg
);
3810 /* ??? Once upon a time variable_size stuffed parameter list
3811 SAVE_EXPRs (amongst others) onto a pending sizes list. This
3812 turned out to be less than manageable in the gimple world.
3813 Now we have to hunt them down ourselves. */
3814 walk_tree_without_duplicates (&data
.passed_type
,
3815 gimplify_parm_type
, &stmts
);
3817 if (TREE_CODE (DECL_SIZE_UNIT (parm
)) != INTEGER_CST
)
3819 gimplify_one_sizepos (&DECL_SIZE (parm
), &stmts
);
3820 gimplify_one_sizepos (&DECL_SIZE_UNIT (parm
), &stmts
);
3823 if (data
.passed_pointer
)
3825 tree type
= TREE_TYPE (data
.passed_type
);
3826 if (reference_callee_copied (&all
.args_so_far_v
, TYPE_MODE (type
),
3827 type
, data
.named_arg
))
3831 /* For constant-sized objects, this is trivial; for
3832 variable-sized objects, we have to play games. */
3833 if (TREE_CODE (DECL_SIZE_UNIT (parm
)) == INTEGER_CST
3834 && !(flag_stack_check
== GENERIC_STACK_CHECK
3835 && compare_tree_int (DECL_SIZE_UNIT (parm
),
3836 STACK_CHECK_MAX_VAR_SIZE
) > 0))
3838 local
= create_tmp_var (type
, get_name (parm
));
3839 DECL_IGNORED_P (local
) = 0;
3840 /* If PARM was addressable, move that flag over
3841 to the local copy, as its address will be taken,
3842 not the PARMs. Keep the parms address taken
3843 as we'll query that flag during gimplification. */
3844 if (TREE_ADDRESSABLE (parm
))
3845 TREE_ADDRESSABLE (local
) = 1;
3846 else if (TREE_CODE (type
) == COMPLEX_TYPE
3847 || TREE_CODE (type
) == VECTOR_TYPE
)
3848 DECL_GIMPLE_REG_P (local
) = 1;
3850 if (!is_gimple_reg (local
)
3851 && flag_stack_reuse
!= SR_NONE
)
3853 tree clobber
= build_constructor (type
, NULL
);
3854 gimple
*clobber_stmt
;
3855 TREE_THIS_VOLATILE (clobber
) = 1;
3856 clobber_stmt
= gimple_build_assign (local
, clobber
);
3857 gimple_seq_add_stmt (cleanup
, clobber_stmt
);
3862 tree ptr_type
, addr
;
3864 ptr_type
= build_pointer_type (type
);
3865 addr
= create_tmp_reg (ptr_type
, get_name (parm
));
3866 DECL_IGNORED_P (addr
) = 0;
3867 local
= build_fold_indirect_ref (addr
);
3869 t
= build_alloca_call_expr (DECL_SIZE_UNIT (parm
),
3871 max_int_size_in_bytes (type
));
3872 /* The call has been built for a variable-sized object. */
3873 CALL_ALLOCA_FOR_VAR_P (t
) = 1;
3874 t
= fold_convert (ptr_type
, t
);
3875 t
= build2 (MODIFY_EXPR
, TREE_TYPE (addr
), addr
, t
);
3876 gimplify_and_add (t
, &stmts
);
3879 gimplify_assign (local
, parm
, &stmts
);
3881 SET_DECL_VALUE_EXPR (parm
, local
);
3882 DECL_HAS_VALUE_EXPR_P (parm
) = 1;
3892 /* Compute the size and offset from the start of the stacked arguments for a
3893 parm passed in mode PASSED_MODE and with type TYPE.
3895 INITIAL_OFFSET_PTR points to the current offset into the stacked
3898 The starting offset and size for this parm are returned in
3899 LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
3900 nonzero, the offset is that of stack slot, which is returned in
3901 LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
3902 padding required from the initial offset ptr to the stack slot.
3904 IN_REGS is nonzero if the argument will be passed in registers. It will
3905 never be set if REG_PARM_STACK_SPACE is not defined.
3907 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
3908 for arguments which are passed in registers.
3910 FNDECL is the function in which the argument was defined.
3912 There are two types of rounding that are done. The first, controlled by
3913 TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the
3914 argument list to be aligned to the specific boundary (in bits). This
3915 rounding affects the initial and starting offsets, but not the argument
3918 The second, controlled by TARGET_FUNCTION_ARG_PADDING and PARM_BOUNDARY,
3919 optionally rounds the size of the parm to PARM_BOUNDARY. The
3920 initial offset is not affected by this rounding, while the size always
3921 is and the starting offset may be. */
3923 /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
3924 INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
3925 callers pass in the total size of args so far as
3926 INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
3929 locate_and_pad_parm (machine_mode passed_mode
, tree type
, int in_regs
,
3930 int reg_parm_stack_space
, int partial
,
3931 tree fndecl ATTRIBUTE_UNUSED
,
3932 struct args_size
*initial_offset_ptr
,
3933 struct locate_and_pad_arg_data
*locate
)
3936 pad_direction where_pad
;
3937 unsigned int boundary
, round_boundary
;
3938 int part_size_in_regs
;
3940 /* If we have found a stack parm before we reach the end of the
3941 area reserved for registers, skip that area. */
3944 if (reg_parm_stack_space
> 0)
3946 if (initial_offset_ptr
->var
3947 || !ordered_p (initial_offset_ptr
->constant
,
3948 reg_parm_stack_space
))
3950 initial_offset_ptr
->var
3951 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
3952 ssize_int (reg_parm_stack_space
));
3953 initial_offset_ptr
->constant
= 0;
3956 initial_offset_ptr
->constant
3957 = ordered_max (initial_offset_ptr
->constant
,
3958 reg_parm_stack_space
);
3962 part_size_in_regs
= (reg_parm_stack_space
== 0 ? partial
: 0);
3965 ? arg_size_in_bytes (type
)
3966 : size_int (GET_MODE_SIZE (passed_mode
)));
3967 where_pad
= targetm
.calls
.function_arg_padding (passed_mode
, type
);
3968 boundary
= targetm
.calls
.function_arg_boundary (passed_mode
, type
);
3969 round_boundary
= targetm
.calls
.function_arg_round_boundary (passed_mode
,
3971 locate
->where_pad
= where_pad
;
3973 /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */
3974 if (boundary
> MAX_SUPPORTED_STACK_ALIGNMENT
)
3975 boundary
= MAX_SUPPORTED_STACK_ALIGNMENT
;
3977 locate
->boundary
= boundary
;
3979 if (SUPPORTS_STACK_ALIGNMENT
)
3981 /* stack_alignment_estimated can't change after stack has been
3983 if (crtl
->stack_alignment_estimated
< boundary
)
3985 if (!crtl
->stack_realign_processed
)
3986 crtl
->stack_alignment_estimated
= boundary
;
3989 /* If stack is realigned and stack alignment value
3990 hasn't been finalized, it is OK not to increase
3991 stack_alignment_estimated. The bigger alignment
3992 requirement is recorded in stack_alignment_needed
3994 gcc_assert (!crtl
->stack_realign_finalized
3995 && crtl
->stack_realign_needed
);
4000 /* Remember if the outgoing parameter requires extra alignment on the
4001 calling function side. */
4002 if (crtl
->stack_alignment_needed
< boundary
)
4003 crtl
->stack_alignment_needed
= boundary
;
4004 if (crtl
->preferred_stack_boundary
< boundary
)
4005 crtl
->preferred_stack_boundary
= boundary
;
4007 if (ARGS_GROW_DOWNWARD
)
4009 locate
->slot_offset
.constant
= -initial_offset_ptr
->constant
;
4010 if (initial_offset_ptr
->var
)
4011 locate
->slot_offset
.var
= size_binop (MINUS_EXPR
, ssize_int (0),
4012 initial_offset_ptr
->var
);
4016 if (where_pad
!= PAD_NONE
4017 && (!tree_fits_uhwi_p (sizetree
)
4018 || (tree_to_uhwi (sizetree
) * BITS_PER_UNIT
) % round_boundary
))
4019 s2
= round_up (s2
, round_boundary
/ BITS_PER_UNIT
);
4020 SUB_PARM_SIZE (locate
->slot_offset
, s2
);
4023 locate
->slot_offset
.constant
+= part_size_in_regs
;
4025 if (!in_regs
|| reg_parm_stack_space
> 0)
4026 pad_to_arg_alignment (&locate
->slot_offset
, boundary
,
4027 &locate
->alignment_pad
);
4029 locate
->size
.constant
= (-initial_offset_ptr
->constant
4030 - locate
->slot_offset
.constant
);
4031 if (initial_offset_ptr
->var
)
4032 locate
->size
.var
= size_binop (MINUS_EXPR
,
4033 size_binop (MINUS_EXPR
,
4035 initial_offset_ptr
->var
),
4036 locate
->slot_offset
.var
);
4038 /* Pad_below needs the pre-rounded size to know how much to pad
4040 locate
->offset
= locate
->slot_offset
;
4041 if (where_pad
== PAD_DOWNWARD
)
4042 pad_below (&locate
->offset
, passed_mode
, sizetree
);
4047 if (!in_regs
|| reg_parm_stack_space
> 0)
4048 pad_to_arg_alignment (initial_offset_ptr
, boundary
,
4049 &locate
->alignment_pad
);
4050 locate
->slot_offset
= *initial_offset_ptr
;
4052 #ifdef PUSH_ROUNDING
4053 if (passed_mode
!= BLKmode
)
4054 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
4057 /* Pad_below needs the pre-rounded size to know how much to pad below
4058 so this must be done before rounding up. */
4059 locate
->offset
= locate
->slot_offset
;
4060 if (where_pad
== PAD_DOWNWARD
)
4061 pad_below (&locate
->offset
, passed_mode
, sizetree
);
4063 if (where_pad
!= PAD_NONE
4064 && (!tree_fits_uhwi_p (sizetree
)
4065 || (tree_to_uhwi (sizetree
) * BITS_PER_UNIT
) % round_boundary
))
4066 sizetree
= round_up (sizetree
, round_boundary
/ BITS_PER_UNIT
);
4068 ADD_PARM_SIZE (locate
->size
, sizetree
);
4070 locate
->size
.constant
-= part_size_in_regs
;
4073 locate
->offset
.constant
4074 += targetm
.calls
.function_arg_offset (passed_mode
, type
);
4077 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4078 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4081 pad_to_arg_alignment (struct args_size
*offset_ptr
, int boundary
,
4082 struct args_size
*alignment_pad
)
4084 tree save_var
= NULL_TREE
;
4085 poly_int64 save_constant
= 0;
4086 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
4087 poly_int64 sp_offset
= STACK_POINTER_OFFSET
;
4089 #ifdef SPARC_STACK_BOUNDARY_HACK
4090 /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
4091 the real alignment of %sp. However, when it does this, the
4092 alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
4093 if (SPARC_STACK_BOUNDARY_HACK
)
4097 if (boundary
> PARM_BOUNDARY
)
4099 save_var
= offset_ptr
->var
;
4100 save_constant
= offset_ptr
->constant
;
4103 alignment_pad
->var
= NULL_TREE
;
4104 alignment_pad
->constant
= 0;
4106 if (boundary
> BITS_PER_UNIT
)
4110 || !known_misalignment (offset_ptr
->constant
+ sp_offset
,
4111 boundary_in_bytes
, &misalign
))
4113 tree sp_offset_tree
= ssize_int (sp_offset
);
4114 tree offset
= size_binop (PLUS_EXPR
,
4115 ARGS_SIZE_TREE (*offset_ptr
),
4118 if (ARGS_GROW_DOWNWARD
)
4119 rounded
= round_down (offset
, boundary
/ BITS_PER_UNIT
);
4121 rounded
= round_up (offset
, boundary
/ BITS_PER_UNIT
);
4123 offset_ptr
->var
= size_binop (MINUS_EXPR
, rounded
, sp_offset_tree
);
4124 /* ARGS_SIZE_TREE includes constant term. */
4125 offset_ptr
->constant
= 0;
4126 if (boundary
> PARM_BOUNDARY
)
4127 alignment_pad
->var
= size_binop (MINUS_EXPR
, offset_ptr
->var
,
4132 if (ARGS_GROW_DOWNWARD
)
4133 offset_ptr
->constant
-= misalign
;
4135 offset_ptr
->constant
+= -misalign
& (boundary_in_bytes
- 1);
4137 if (boundary
> PARM_BOUNDARY
)
4138 alignment_pad
->constant
= offset_ptr
->constant
- save_constant
;
4144 pad_below (struct args_size
*offset_ptr
, machine_mode passed_mode
, tree sizetree
)
4146 unsigned int align
= PARM_BOUNDARY
/ BITS_PER_UNIT
;
4148 if (passed_mode
!= BLKmode
4149 && known_misalignment (GET_MODE_SIZE (passed_mode
), align
, &misalign
))
4150 offset_ptr
->constant
+= -misalign
& (align
- 1);
4153 if (TREE_CODE (sizetree
) != INTEGER_CST
4154 || (TREE_INT_CST_LOW (sizetree
) & (align
- 1)) != 0)
4156 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4157 tree s2
= round_up (sizetree
, align
);
4159 ADD_PARM_SIZE (*offset_ptr
, s2
);
4160 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
4166 /* True if register REGNO was alive at a place where `setjmp' was
4167 called and was set more than once or is an argument. Such regs may
4168 be clobbered by `longjmp'. */
4171 regno_clobbered_at_setjmp (bitmap setjmp_crosses
, int regno
)
4173 /* There appear to be cases where some local vars never reach the
4174 backend but have bogus regnos. */
4175 if (regno
>= max_reg_num ())
4178 return ((REG_N_SETS (regno
) > 1
4179 || REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun
)),
4181 && REGNO_REG_SET_P (setjmp_crosses
, regno
));
4184 /* Walk the tree of blocks describing the binding levels within a
4185 function and warn about variables the might be killed by setjmp or
4186 vfork. This is done after calling flow_analysis before register
4187 allocation since that will clobber the pseudo-regs to hard
4191 setjmp_vars_warning (bitmap setjmp_crosses
, tree block
)
4195 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
4198 && DECL_RTL_SET_P (decl
)
4199 && REG_P (DECL_RTL (decl
))
4200 && regno_clobbered_at_setjmp (setjmp_crosses
, REGNO (DECL_RTL (decl
))))
4201 warning (OPT_Wclobbered
, "variable %q+D might be clobbered by"
4202 " %<longjmp%> or %<vfork%>", decl
);
4205 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= BLOCK_CHAIN (sub
))
4206 setjmp_vars_warning (setjmp_crosses
, sub
);
4209 /* Do the appropriate part of setjmp_vars_warning
4210 but for arguments instead of local variables. */
4213 setjmp_args_warning (bitmap setjmp_crosses
)
4216 for (decl
= DECL_ARGUMENTS (current_function_decl
);
4217 decl
; decl
= DECL_CHAIN (decl
))
4218 if (DECL_RTL (decl
) != 0
4219 && REG_P (DECL_RTL (decl
))
4220 && regno_clobbered_at_setjmp (setjmp_crosses
, REGNO (DECL_RTL (decl
))))
4221 warning (OPT_Wclobbered
,
4222 "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
4226 /* Generate warning messages for variables live across setjmp. */
4229 generate_setjmp_warnings (void)
4231 bitmap setjmp_crosses
= regstat_get_setjmp_crosses ();
4233 if (n_basic_blocks_for_fn (cfun
) == NUM_FIXED_BLOCKS
4234 || bitmap_empty_p (setjmp_crosses
))
4237 setjmp_vars_warning (setjmp_crosses
, DECL_INITIAL (current_function_decl
));
4238 setjmp_args_warning (setjmp_crosses
);
4242 /* Reverse the order of elements in the fragment chain T of blocks,
4243 and return the new head of the chain (old last element).
4244 In addition to that clear BLOCK_SAME_RANGE flags when needed
4245 and adjust BLOCK_SUPERCONTEXT from the super fragment to
4246 its super fragment origin. */
4249 block_fragments_nreverse (tree t
)
4251 tree prev
= 0, block
, next
, prev_super
= 0;
4252 tree super
= BLOCK_SUPERCONTEXT (t
);
4253 if (BLOCK_FRAGMENT_ORIGIN (super
))
4254 super
= BLOCK_FRAGMENT_ORIGIN (super
);
4255 for (block
= t
; block
; block
= next
)
4257 next
= BLOCK_FRAGMENT_CHAIN (block
);
4258 BLOCK_FRAGMENT_CHAIN (block
) = prev
;
4259 if ((prev
&& !BLOCK_SAME_RANGE (prev
))
4260 || (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (block
))
4262 BLOCK_SAME_RANGE (block
) = 0;
4263 prev_super
= BLOCK_SUPERCONTEXT (block
);
4264 BLOCK_SUPERCONTEXT (block
) = super
;
4267 t
= BLOCK_FRAGMENT_ORIGIN (t
);
4268 if (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (t
))
4270 BLOCK_SAME_RANGE (t
) = 0;
4271 BLOCK_SUPERCONTEXT (t
) = super
;
4275 /* Reverse the order of elements in the chain T of blocks,
4276 and return the new head of the chain (old last element).
4277 Also do the same on subblocks and reverse the order of elements
4278 in BLOCK_FRAGMENT_CHAIN as well. */
4281 blocks_nreverse_all (tree t
)
4283 tree prev
= 0, block
, next
;
4284 for (block
= t
; block
; block
= next
)
4286 next
= BLOCK_CHAIN (block
);
4287 BLOCK_CHAIN (block
) = prev
;
4288 if (BLOCK_FRAGMENT_CHAIN (block
)
4289 && BLOCK_FRAGMENT_ORIGIN (block
) == NULL_TREE
)
4291 BLOCK_FRAGMENT_CHAIN (block
)
4292 = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block
));
4293 if (!BLOCK_SAME_RANGE (BLOCK_FRAGMENT_CHAIN (block
)))
4294 BLOCK_SAME_RANGE (block
) = 0;
4296 BLOCK_SUBBLOCKS (block
) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block
));
4303 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
4304 and create duplicate blocks. */
4305 /* ??? Need an option to either create block fragments or to create
4306 abstract origin duplicates of a source block. It really depends
4307 on what optimization has been performed. */
4310 reorder_blocks (void)
4312 tree block
= DECL_INITIAL (current_function_decl
);
4314 if (block
== NULL_TREE
)
4317 auto_vec
<tree
, 10> block_stack
;
4319 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
4320 clear_block_marks (block
);
4322 /* Prune the old trees away, so that they don't get in the way. */
4323 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
4324 BLOCK_CHAIN (block
) = NULL_TREE
;
4326 /* Recreate the block tree from the note nesting. */
4327 reorder_blocks_1 (get_insns (), block
, &block_stack
);
4328 BLOCK_SUBBLOCKS (block
) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block
));
4331 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
4334 clear_block_marks (tree block
)
4338 TREE_ASM_WRITTEN (block
) = 0;
4339 clear_block_marks (BLOCK_SUBBLOCKS (block
));
4340 block
= BLOCK_CHAIN (block
);
4345 reorder_blocks_1 (rtx_insn
*insns
, tree current_block
,
4346 vec
<tree
> *p_block_stack
)
4349 tree prev_beg
= NULL_TREE
, prev_end
= NULL_TREE
;
4351 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
4355 if (NOTE_KIND (insn
) == NOTE_INSN_BLOCK_BEG
)
4357 tree block
= NOTE_BLOCK (insn
);
4360 gcc_assert (BLOCK_FRAGMENT_ORIGIN (block
) == NULL_TREE
);
4364 BLOCK_SAME_RANGE (prev_end
) = 0;
4365 prev_end
= NULL_TREE
;
4367 /* If we have seen this block before, that means it now
4368 spans multiple address regions. Create a new fragment. */
4369 if (TREE_ASM_WRITTEN (block
))
4371 tree new_block
= copy_node (block
);
4373 BLOCK_SAME_RANGE (new_block
) = 0;
4374 BLOCK_FRAGMENT_ORIGIN (new_block
) = origin
;
4375 BLOCK_FRAGMENT_CHAIN (new_block
)
4376 = BLOCK_FRAGMENT_CHAIN (origin
);
4377 BLOCK_FRAGMENT_CHAIN (origin
) = new_block
;
4379 NOTE_BLOCK (insn
) = new_block
;
4383 if (prev_beg
== current_block
&& prev_beg
)
4384 BLOCK_SAME_RANGE (block
) = 1;
4388 BLOCK_SUBBLOCKS (block
) = 0;
4389 TREE_ASM_WRITTEN (block
) = 1;
4390 /* When there's only one block for the entire function,
4391 current_block == block and we mustn't do this, it
4392 will cause infinite recursion. */
4393 if (block
!= current_block
)
4396 if (block
!= origin
)
4397 gcc_assert (BLOCK_SUPERCONTEXT (origin
) == current_block
4398 || BLOCK_FRAGMENT_ORIGIN (BLOCK_SUPERCONTEXT
4401 if (p_block_stack
->is_empty ())
4402 super
= current_block
;
4405 super
= p_block_stack
->last ();
4406 gcc_assert (super
== current_block
4407 || BLOCK_FRAGMENT_ORIGIN (super
)
4410 BLOCK_SUPERCONTEXT (block
) = super
;
4411 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
4412 BLOCK_SUBBLOCKS (current_block
) = block
;
4413 current_block
= origin
;
4415 p_block_stack
->safe_push (block
);
4417 else if (NOTE_KIND (insn
) == NOTE_INSN_BLOCK_END
)
4419 NOTE_BLOCK (insn
) = p_block_stack
->pop ();
4420 current_block
= BLOCK_SUPERCONTEXT (current_block
);
4421 if (BLOCK_FRAGMENT_ORIGIN (current_block
))
4422 current_block
= BLOCK_FRAGMENT_ORIGIN (current_block
);
4423 prev_beg
= NULL_TREE
;
4424 prev_end
= BLOCK_SAME_RANGE (NOTE_BLOCK (insn
))
4425 ? NOTE_BLOCK (insn
) : NULL_TREE
;
4430 prev_beg
= NULL_TREE
;
4432 BLOCK_SAME_RANGE (prev_end
) = 0;
4433 prev_end
= NULL_TREE
;
4438 /* Reverse the order of elements in the chain T of blocks,
4439 and return the new head of the chain (old last element). */
4442 blocks_nreverse (tree t
)
4444 tree prev
= 0, block
, next
;
4445 for (block
= t
; block
; block
= next
)
4447 next
= BLOCK_CHAIN (block
);
4448 BLOCK_CHAIN (block
) = prev
;
4454 /* Concatenate two chains of blocks (chained through BLOCK_CHAIN)
4455 by modifying the last node in chain 1 to point to chain 2. */
4458 block_chainon (tree op1
, tree op2
)
4467 for (t1
= op1
; BLOCK_CHAIN (t1
); t1
= BLOCK_CHAIN (t1
))
4469 BLOCK_CHAIN (t1
) = op2
;
4471 #ifdef ENABLE_TREE_CHECKING
4474 for (t2
= op2
; t2
; t2
= BLOCK_CHAIN (t2
))
4475 gcc_assert (t2
!= t1
);
4482 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
4483 non-NULL, list them all into VECTOR, in a depth-first preorder
4484 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
4488 all_blocks (tree block
, tree
*vector
)
4494 TREE_ASM_WRITTEN (block
) = 0;
4496 /* Record this block. */
4498 vector
[n_blocks
] = block
;
4502 /* Record the subblocks, and their subblocks... */
4503 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
4504 vector
? vector
+ n_blocks
: 0);
4505 block
= BLOCK_CHAIN (block
);
4511 /* Return a vector containing all the blocks rooted at BLOCK. The
4512 number of elements in the vector is stored in N_BLOCKS_P. The
4513 vector is dynamically allocated; it is the caller's responsibility
4514 to call `free' on the pointer returned. */
4517 get_block_vector (tree block
, int *n_blocks_p
)
4521 *n_blocks_p
= all_blocks (block
, NULL
);
4522 block_vector
= XNEWVEC (tree
, *n_blocks_p
);
4523 all_blocks (block
, block_vector
);
4525 return block_vector
;
4528 static GTY(()) int next_block_index
= 2;
4530 /* Set BLOCK_NUMBER for all the blocks in FN. */
4533 number_blocks (tree fn
)
4539 /* For XCOFF debugging output, we start numbering the blocks
4540 from 1 within each function, rather than keeping a running
4542 #if defined (XCOFF_DEBUGGING_INFO)
4543 if (write_symbols
== XCOFF_DEBUG
)
4544 next_block_index
= 1;
4547 block_vector
= get_block_vector (DECL_INITIAL (fn
), &n_blocks
);
4549 /* The top-level BLOCK isn't numbered at all. */
4550 for (i
= 1; i
< n_blocks
; ++i
)
4551 /* We number the blocks from two. */
4552 BLOCK_NUMBER (block_vector
[i
]) = next_block_index
++;
4554 free (block_vector
);
4559 /* If VAR is present in a subblock of BLOCK, return the subblock. */
4562 debug_find_var_in_block_tree (tree var
, tree block
)
4566 for (t
= BLOCK_VARS (block
); t
; t
= TREE_CHAIN (t
))
4570 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= TREE_CHAIN (t
))
4572 tree ret
= debug_find_var_in_block_tree (var
, t
);
4580 /* Keep track of whether we're in a dummy function context. If we are,
4581 we don't want to invoke the set_current_function hook, because we'll
4582 get into trouble if the hook calls target_reinit () recursively or
4583 when the initial initialization is not yet complete. */
4585 static bool in_dummy_function
;
4587 /* Invoke the target hook when setting cfun. Update the optimization options
4588 if the function uses different options than the default. */
4591 invoke_set_current_function_hook (tree fndecl
)
4593 if (!in_dummy_function
)
4595 tree opts
= ((fndecl
)
4596 ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
)
4597 : optimization_default_node
);
4600 opts
= optimization_default_node
;
4602 /* Change optimization options if needed. */
4603 if (optimization_current_node
!= opts
)
4605 optimization_current_node
= opts
;
4606 cl_optimization_restore (&global_options
, TREE_OPTIMIZATION (opts
));
4609 targetm
.set_current_function (fndecl
);
4610 this_fn_optabs
= this_target_optabs
;
4612 /* Initialize global alignment variables after op. */
4613 parse_alignment_opts ();
4615 if (opts
!= optimization_default_node
)
4617 init_tree_optimization_optabs (opts
);
4618 if (TREE_OPTIMIZATION_OPTABS (opts
))
4619 this_fn_optabs
= (struct target_optabs
*)
4620 TREE_OPTIMIZATION_OPTABS (opts
);
4625 /* cfun should never be set directly; use this function. */
4628 set_cfun (struct function
*new_cfun
, bool force
)
4630 if (cfun
!= new_cfun
|| force
)
4633 invoke_set_current_function_hook (new_cfun
? new_cfun
->decl
: NULL_TREE
);
4634 redirect_edge_var_map_empty ();
4638 /* Initialized with NOGC, making this poisonous to the garbage collector. */
4640 static vec
<function
*> cfun_stack
;
4642 /* Push the current cfun onto the stack, and set cfun to new_cfun. Also set
4643 current_function_decl accordingly. */
4646 push_cfun (struct function
*new_cfun
)
4648 gcc_assert ((!cfun
&& !current_function_decl
)
4649 || (cfun
&& current_function_decl
== cfun
->decl
));
4650 cfun_stack
.safe_push (cfun
);
4651 current_function_decl
= new_cfun
? new_cfun
->decl
: NULL_TREE
;
4652 set_cfun (new_cfun
);
4655 /* Pop cfun from the stack. Also set current_function_decl accordingly. */
4660 struct function
*new_cfun
= cfun_stack
.pop ();
4661 /* When in_dummy_function, we do have a cfun but current_function_decl is
4662 NULL. We also allow pushing NULL cfun and subsequently changing
4663 current_function_decl to something else and have both restored by
4665 gcc_checking_assert (in_dummy_function
4667 || current_function_decl
== cfun
->decl
);
4668 set_cfun (new_cfun
);
4669 current_function_decl
= new_cfun
? new_cfun
->decl
: NULL_TREE
;
4672 /* Return value of funcdef and increase it. */
4674 get_next_funcdef_no (void)
4676 return funcdef_no
++;
4679 /* Return value of funcdef. */
4681 get_last_funcdef_no (void)
4686 /* Allocate a function structure for FNDECL and set its contents
4687 to the defaults. Set cfun to the newly-allocated object.
4688 Some of the helper functions invoked during initialization assume
4689 that cfun has already been set. Therefore, assign the new object
4690 directly into cfun and invoke the back end hook explicitly at the
4691 very end, rather than initializing a temporary and calling set_cfun
4694 ABSTRACT_P is true if this is a function that will never be seen by
4695 the middle-end. Such functions are front-end concepts (like C++
4696 function templates) that do not correspond directly to functions
4697 placed in object files. */
4700 allocate_struct_function (tree fndecl
, bool abstract_p
)
4702 tree fntype
= fndecl
? TREE_TYPE (fndecl
) : NULL_TREE
;
4704 cfun
= ggc_cleared_alloc
<function
> ();
4706 init_eh_for_function ();
4708 if (init_machine_status
)
4709 cfun
->machine
= (*init_machine_status
) ();
4711 #ifdef OVERRIDE_ABI_FORMAT
4712 OVERRIDE_ABI_FORMAT (fndecl
);
4715 if (fndecl
!= NULL_TREE
)
4717 DECL_STRUCT_FUNCTION (fndecl
) = cfun
;
4718 cfun
->decl
= fndecl
;
4719 current_function_funcdef_no
= get_next_funcdef_no ();
4722 invoke_set_current_function_hook (fndecl
);
4724 if (fndecl
!= NULL_TREE
)
4726 tree result
= DECL_RESULT (fndecl
);
4730 /* Now that we have activated any function-specific attributes
4731 that might affect layout, particularly vector modes, relayout
4732 each of the parameters and the result. */
4733 relayout_decl (result
);
4734 for (tree parm
= DECL_ARGUMENTS (fndecl
); parm
;
4735 parm
= DECL_CHAIN (parm
))
4736 relayout_decl (parm
);
4738 /* Similarly relayout the function decl. */
4739 targetm
.target_option
.relayout_function (fndecl
);
4742 if (!abstract_p
&& aggregate_value_p (result
, fndecl
))
4744 #ifdef PCC_STATIC_STRUCT_RETURN
4745 cfun
->returns_pcc_struct
= 1;
4747 cfun
->returns_struct
= 1;
4750 cfun
->stdarg
= stdarg_p (fntype
);
4752 /* Assume all registers in stdarg functions need to be saved. */
4753 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
4754 cfun
->va_list_fpr_size
= VA_LIST_MAX_FPR_SIZE
;
4756 /* ??? This could be set on a per-function basis by the front-end
4757 but is this worth the hassle? */
4758 cfun
->can_throw_non_call_exceptions
= flag_non_call_exceptions
;
4759 cfun
->can_delete_dead_exceptions
= flag_delete_dead_exceptions
;
4761 if (!profile_flag
&& !flag_instrument_function_entry_exit
)
4762 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl
) = 1;
4765 /* Don't enable begin stmt markers if var-tracking at assignments is
4766 disabled. The markers make little sense without the variable
4767 binding annotations among them. */
4768 cfun
->debug_nonbind_markers
= lang_hooks
.emits_begin_stmt
4769 && MAY_HAVE_DEBUG_MARKER_STMTS
;
4772 /* This is like allocate_struct_function, but pushes a new cfun for FNDECL
4773 instead of just setting it. */
4776 push_struct_function (tree fndecl
)
4778 /* When in_dummy_function we might be in the middle of a pop_cfun and
4779 current_function_decl and cfun may not match. */
4780 gcc_assert (in_dummy_function
4781 || (!cfun
&& !current_function_decl
)
4782 || (cfun
&& current_function_decl
== cfun
->decl
));
4783 cfun_stack
.safe_push (cfun
);
4784 current_function_decl
= fndecl
;
4785 allocate_struct_function (fndecl
, false);
4788 /* Reset crtl and other non-struct-function variables to defaults as
4789 appropriate for emitting rtl at the start of a function. */
4792 prepare_function_start (void)
4794 gcc_assert (!get_last_insn ());
4797 init_varasm_status ();
4799 default_rtl_profile ();
4801 if (flag_stack_usage_info
)
4803 cfun
->su
= ggc_cleared_alloc
<stack_usage
> ();
4804 cfun
->su
->static_stack_size
= -1;
4807 cse_not_expected
= ! optimize
;
4809 /* Caller save not needed yet. */
4810 caller_save_needed
= 0;
4812 /* We haven't done register allocation yet. */
4815 /* Indicate that we have not instantiated virtual registers yet. */
4816 virtuals_instantiated
= 0;
4818 /* Indicate that we want CONCATs now. */
4819 generating_concat_p
= 1;
4821 /* Indicate we have no need of a frame pointer yet. */
4822 frame_pointer_needed
= 0;
4826 push_dummy_function (bool with_decl
)
4828 tree fn_decl
, fn_type
, fn_result_decl
;
4830 gcc_assert (!in_dummy_function
);
4831 in_dummy_function
= true;
4835 fn_type
= build_function_type_list (void_type_node
, NULL_TREE
);
4836 fn_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
4838 fn_result_decl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
,
4839 NULL_TREE
, void_type_node
);
4840 DECL_RESULT (fn_decl
) = fn_result_decl
;
4843 fn_decl
= NULL_TREE
;
4845 push_struct_function (fn_decl
);
4848 /* Initialize the rtl expansion mechanism so that we can do simple things
4849 like generate sequences. This is used to provide a context during global
4850 initialization of some passes. You must call expand_dummy_function_end
4851 to exit this context. */
4854 init_dummy_function_start (void)
4856 push_dummy_function (false);
4857 prepare_function_start ();
4860 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4861 and initialize static variables for generating RTL for the statements
4865 init_function_start (tree subr
)
4867 /* Initialize backend, if needed. */
4870 prepare_function_start ();
4871 decide_function_section (subr
);
4873 /* Warn if this value is an aggregate type,
4874 regardless of which calling convention we are using for it. */
4875 if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
4876 warning (OPT_Waggregate_return
, "function returns an aggregate");
4879 /* Expand code to verify the stack_protect_guard. This is invoked at
4880 the end of a function to be protected. */
4883 stack_protect_epilogue (void)
4885 tree guard_decl
= targetm
.stack_protect_guard ();
4886 rtx_code_label
*label
= gen_label_rtx ();
4890 x
= expand_normal (crtl
->stack_protect_guard
);
4892 y
= expand_normal (guard_decl
);
4896 /* Allow the target to compare Y with X without leaking either into
4898 if (targetm
.have_stack_protect_test ()
4899 && ((seq
= targetm
.gen_stack_protect_test (x
, y
, label
)) != NULL_RTX
))
4902 emit_cmp_and_jump_insns (x
, y
, EQ
, NULL_RTX
, ptr_mode
, 1, label
);
4904 /* The noreturn predictor has been moved to the tree level. The rtl-level
4905 predictors estimate this branch about 20%, which isn't enough to get
4906 things moved out of line. Since this is the only extant case of adding
4907 a noreturn function at the rtl level, it doesn't seem worth doing ought
4908 except adding the prediction by hand. */
4909 rtx_insn
*tmp
= get_last_insn ();
4911 predict_insn_def (tmp
, PRED_NORETURN
, TAKEN
);
4913 expand_call (targetm
.stack_protect_fail (), NULL_RTX
, /*ignore=*/true);
4918 /* Start the RTL for a new function, and set variables used for
4920 SUBR is the FUNCTION_DECL node.
4921 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
4922 the function's parameters, which must be run at any return statement. */
4925 expand_function_start (tree subr
)
4927 /* Make sure volatile mem refs aren't considered
4928 valid operands of arithmetic insns. */
4929 init_recog_no_volatile ();
4933 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
4936 = (stack_limit_rtx
!= NULL_RTX
&& ! DECL_NO_LIMIT_STACK (subr
));
4938 /* Make the label for return statements to jump to. Do not special
4939 case machines with special return instructions -- they will be
4940 handled later during jump, ifcvt, or epilogue creation. */
4941 return_label
= gen_label_rtx ();
4943 /* Initialize rtx used to return the value. */
4944 /* Do this before assign_parms so that we copy the struct value address
4945 before any library calls that assign parms might generate. */
4947 /* Decide whether to return the value in memory or in a register. */
4948 tree res
= DECL_RESULT (subr
);
4949 if (aggregate_value_p (res
, subr
))
4951 /* Returning something that won't go in a register. */
4952 rtx value_address
= 0;
4954 #ifdef PCC_STATIC_STRUCT_RETURN
4955 if (cfun
->returns_pcc_struct
)
4957 int size
= int_size_in_bytes (TREE_TYPE (res
));
4958 value_address
= assemble_static_space (size
);
4963 rtx sv
= targetm
.calls
.struct_value_rtx (TREE_TYPE (subr
), 2);
4964 /* Expect to be passed the address of a place to store the value.
4965 If it is passed as an argument, assign_parms will take care of
4969 value_address
= gen_reg_rtx (Pmode
);
4970 emit_move_insn (value_address
, sv
);
4975 rtx x
= value_address
;
4976 if (!DECL_BY_REFERENCE (res
))
4978 x
= gen_rtx_MEM (DECL_MODE (res
), x
);
4979 set_mem_attributes (x
, res
, 1);
4981 set_parm_rtl (res
, x
);
4984 else if (DECL_MODE (res
) == VOIDmode
)
4985 /* If return mode is void, this decl rtl should not be used. */
4986 set_parm_rtl (res
, NULL_RTX
);
4989 /* Compute the return values into a pseudo reg, which we will copy
4990 into the true return register after the cleanups are done. */
4991 tree return_type
= TREE_TYPE (res
);
4993 /* If we may coalesce this result, make sure it has the expected mode
4994 in case it was promoted. But we need not bother about BLKmode. */
4995 machine_mode promoted_mode
4996 = flag_tree_coalesce_vars
&& is_gimple_reg (res
)
4997 ? promote_ssa_mode (ssa_default_def (cfun
, res
), NULL
)
5000 if (promoted_mode
!= BLKmode
)
5001 set_parm_rtl (res
, gen_reg_rtx (promoted_mode
));
5002 else if (TYPE_MODE (return_type
) != BLKmode
5003 && targetm
.calls
.return_in_msb (return_type
))
5004 /* expand_function_end will insert the appropriate padding in
5005 this case. Use the return value's natural (unpadded) mode
5006 within the function proper. */
5007 set_parm_rtl (res
, gen_reg_rtx (TYPE_MODE (return_type
)));
5010 /* In order to figure out what mode to use for the pseudo, we
5011 figure out what the mode of the eventual return register will
5012 actually be, and use that. */
5013 rtx hard_reg
= hard_function_value (return_type
, subr
, 0, 1);
5015 /* Structures that are returned in registers are not
5016 aggregate_value_p, so we may see a PARALLEL or a REG. */
5017 if (REG_P (hard_reg
))
5018 set_parm_rtl (res
, gen_reg_rtx (GET_MODE (hard_reg
)));
5021 gcc_assert (GET_CODE (hard_reg
) == PARALLEL
);
5022 set_parm_rtl (res
, gen_group_rtx (hard_reg
));
5026 /* Set DECL_REGISTER flag so that expand_function_end will copy the
5027 result to the real return register(s). */
5028 DECL_REGISTER (res
) = 1;
5031 /* Initialize rtx for parameters and local variables.
5032 In some cases this requires emitting insns. */
5033 assign_parms (subr
);
5035 /* If function gets a static chain arg, store it. */
5036 if (cfun
->static_chain_decl
)
5038 tree parm
= cfun
->static_chain_decl
;
5043 local
= gen_reg_rtx (promote_decl_mode (parm
, &unsignedp
));
5044 chain
= targetm
.calls
.static_chain (current_function_decl
, true);
5046 set_decl_incoming_rtl (parm
, chain
, false);
5047 set_parm_rtl (parm
, local
);
5048 mark_reg_pointer (local
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
5050 if (GET_MODE (local
) != GET_MODE (chain
))
5052 convert_move (local
, chain
, unsignedp
);
5053 insn
= get_last_insn ();
5056 insn
= emit_move_insn (local
, chain
);
5058 /* Mark the register as eliminable, similar to parameters. */
5060 && reg_mentioned_p (arg_pointer_rtx
, XEXP (chain
, 0)))
5061 set_dst_reg_note (insn
, REG_EQUIV
, chain
, local
);
5063 /* If we aren't optimizing, save the static chain onto the stack. */
5066 tree saved_static_chain_decl
5067 = build_decl (DECL_SOURCE_LOCATION (parm
), VAR_DECL
,
5068 DECL_NAME (parm
), TREE_TYPE (parm
));
5069 rtx saved_static_chain_rtx
5070 = assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5071 SET_DECL_RTL (saved_static_chain_decl
, saved_static_chain_rtx
);
5072 emit_move_insn (saved_static_chain_rtx
, chain
);
5073 SET_DECL_VALUE_EXPR (parm
, saved_static_chain_decl
);
5074 DECL_HAS_VALUE_EXPR_P (parm
) = 1;
5078 /* The following was moved from init_function_start.
5079 The move was supposed to make sdb output more accurate. */
5080 /* Indicate the beginning of the function body,
5081 as opposed to parm setup. */
5082 emit_note (NOTE_INSN_FUNCTION_BEG
);
5084 gcc_assert (NOTE_P (get_last_insn ()));
5086 parm_birth_insn
= get_last_insn ();
5088 /* If the function receives a non-local goto, then store the
5089 bits we need to restore the frame pointer. */
5090 if (cfun
->nonlocal_goto_save_area
)
5095 tree var
= TREE_OPERAND (cfun
->nonlocal_goto_save_area
, 0);
5096 gcc_assert (DECL_RTL_SET_P (var
));
5098 t_save
= build4 (ARRAY_REF
,
5099 TREE_TYPE (TREE_TYPE (cfun
->nonlocal_goto_save_area
)),
5100 cfun
->nonlocal_goto_save_area
,
5101 integer_zero_node
, NULL_TREE
, NULL_TREE
);
5102 r_save
= expand_expr (t_save
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5103 gcc_assert (GET_MODE (r_save
) == Pmode
);
5105 emit_move_insn (r_save
, targetm
.builtin_setjmp_frame_value ());
5106 update_nonlocal_goto_save_area ();
5112 PROFILE_HOOK (current_function_funcdef_no
);
5116 /* If we are doing generic stack checking, the probe should go here. */
5117 if (flag_stack_check
== GENERIC_STACK_CHECK
)
5118 stack_check_probe_note
= emit_note (NOTE_INSN_DELETED
);
5122 pop_dummy_function (void)
5125 in_dummy_function
= false;
5128 /* Undo the effects of init_dummy_function_start. */
5130 expand_dummy_function_end (void)
5132 gcc_assert (in_dummy_function
);
5134 /* End any sequences that failed to be closed due to syntax errors. */
5135 while (in_sequence_p ())
5138 /* Outside function body, can't compute type's actual size
5139 until next function's body starts. */
5141 free_after_parsing (cfun
);
5142 free_after_compilation (cfun
);
5143 pop_dummy_function ();
5146 /* Helper for diddle_return_value. */
5149 diddle_return_value_1 (void (*doit
) (rtx
, void *), void *arg
, rtx outgoing
)
5154 if (REG_P (outgoing
))
5155 (*doit
) (outgoing
, arg
);
5156 else if (GET_CODE (outgoing
) == PARALLEL
)
5160 for (i
= 0; i
< XVECLEN (outgoing
, 0); i
++)
5162 rtx x
= XEXP (XVECEXP (outgoing
, 0, i
), 0);
5164 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
5170 /* Call DOIT for each hard register used as a return value from
5171 the current function. */
5174 diddle_return_value (void (*doit
) (rtx
, void *), void *arg
)
5176 diddle_return_value_1 (doit
, arg
, crtl
->return_bnd
);
5177 diddle_return_value_1 (doit
, arg
, crtl
->return_rtx
);
5181 do_clobber_return_reg (rtx reg
, void *arg ATTRIBUTE_UNUSED
)
5187 clobber_return_register (void)
5189 diddle_return_value (do_clobber_return_reg
, NULL
);
5191 /* In case we do use pseudo to return value, clobber it too. */
5192 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
5194 tree decl_result
= DECL_RESULT (current_function_decl
);
5195 rtx decl_rtl
= DECL_RTL (decl_result
);
5196 if (REG_P (decl_rtl
) && REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
)
5198 do_clobber_return_reg (decl_rtl
, NULL
);
5204 do_use_return_reg (rtx reg
, void *arg ATTRIBUTE_UNUSED
)
5210 use_return_register (void)
5212 diddle_return_value (do_use_return_reg
, NULL
);
5215 /* Set the location of the insn chain starting at INSN to LOC. */
5218 set_insn_locations (rtx_insn
*insn
, int loc
)
5220 while (insn
!= NULL
)
5223 INSN_LOCATION (insn
) = loc
;
5224 insn
= NEXT_INSN (insn
);
5228 /* Generate RTL for the end of the current function. */
5231 expand_function_end (void)
5233 /* If arg_pointer_save_area was referenced only from a nested
5234 function, we will not have initialized it yet. Do that now. */
5235 if (arg_pointer_save_area
&& ! crtl
->arg_pointer_save_area_init
)
5236 get_arg_pointer_save_area ();
5238 /* If we are doing generic stack checking and this function makes calls,
5239 do a stack probe at the start of the function to ensure we have enough
5240 space for another stack frame. */
5241 if (flag_stack_check
== GENERIC_STACK_CHECK
)
5243 rtx_insn
*insn
, *seq
;
5245 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5248 rtx max_frame_size
= GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
);
5250 if (STACK_CHECK_MOVING_SP
)
5251 anti_adjust_stack_and_probe (max_frame_size
, true);
5253 probe_stack_range (STACK_OLD_CHECK_PROTECT
, max_frame_size
);
5256 set_insn_locations (seq
, prologue_location
);
5257 emit_insn_before (seq
, stack_check_probe_note
);
5262 /* End any sequences that failed to be closed due to syntax errors. */
5263 while (in_sequence_p ())
5266 clear_pending_stack_adjust ();
5267 do_pending_stack_adjust ();
5269 /* Output a linenumber for the end of the function.
5270 SDB depended on this. */
5271 set_curr_insn_location (input_location
);
5273 /* Before the return label (if any), clobber the return
5274 registers so that they are not propagated live to the rest of
5275 the function. This can only happen with functions that drop
5276 through; if there had been a return statement, there would
5277 have either been a return rtx, or a jump to the return label.
5279 We delay actual code generation after the current_function_value_rtx
5281 rtx_insn
*clobber_after
= get_last_insn ();
5283 /* Output the label for the actual return from the function. */
5284 emit_label (return_label
);
5286 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
5288 /* Let except.c know where it should emit the call to unregister
5289 the function context for sjlj exceptions. */
5290 if (flag_exceptions
)
5291 sjlj_emit_function_exit_after (get_last_insn ());
5295 /* We want to ensure that instructions that may trap are not
5296 moved into the epilogue by scheduling, because we don't
5297 always emit unwind information for the epilogue. */
5298 if (cfun
->can_throw_non_call_exceptions
)
5299 emit_insn (gen_blockage ());
5302 /* If this is an implementation of throw, do what's necessary to
5303 communicate between __builtin_eh_return and the epilogue. */
5304 expand_eh_return ();
5306 /* If scalar return value was computed in a pseudo-reg, or was a named
5307 return value that got dumped to the stack, copy that to the hard
5309 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
5311 tree decl_result
= DECL_RESULT (current_function_decl
);
5312 rtx decl_rtl
= DECL_RTL (decl_result
);
5314 if (REG_P (decl_rtl
)
5315 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
5316 : DECL_REGISTER (decl_result
))
5318 rtx real_decl_rtl
= crtl
->return_rtx
;
5321 /* This should be set in assign_parms. */
5322 gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl
));
5324 /* If this is a BLKmode structure being returned in registers,
5325 then use the mode computed in expand_return. Note that if
5326 decl_rtl is memory, then its mode may have been changed,
5327 but that crtl->return_rtx has not. */
5328 if (GET_MODE (real_decl_rtl
) == BLKmode
)
5329 PUT_MODE (real_decl_rtl
, GET_MODE (decl_rtl
));
5331 /* If a non-BLKmode return value should be padded at the least
5332 significant end of the register, shift it left by the appropriate
5333 amount. BLKmode results are handled using the group load/store
5335 if (TYPE_MODE (TREE_TYPE (decl_result
)) != BLKmode
5336 && REG_P (real_decl_rtl
)
5337 && targetm
.calls
.return_in_msb (TREE_TYPE (decl_result
)))
5339 emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl
),
5340 REGNO (real_decl_rtl
)),
5342 shift_return_value (GET_MODE (decl_rtl
), true, real_decl_rtl
);
5344 else if (GET_CODE (real_decl_rtl
) == PARALLEL
)
5346 /* If expand_function_start has created a PARALLEL for decl_rtl,
5347 move the result to the real return registers. Otherwise, do
5348 a group load from decl_rtl for a named return. */
5349 if (GET_CODE (decl_rtl
) == PARALLEL
)
5350 emit_group_move (real_decl_rtl
, decl_rtl
);
5352 emit_group_load (real_decl_rtl
, decl_rtl
,
5353 TREE_TYPE (decl_result
),
5354 int_size_in_bytes (TREE_TYPE (decl_result
)));
5356 /* In the case of complex integer modes smaller than a word, we'll
5357 need to generate some non-trivial bitfield insertions. Do that
5358 on a pseudo and not the hard register. */
5359 else if (GET_CODE (decl_rtl
) == CONCAT
5360 && is_complex_int_mode (GET_MODE (decl_rtl
), &cmode
)
5361 && GET_MODE_BITSIZE (cmode
) <= BITS_PER_WORD
)
5363 int old_generating_concat_p
;
5366 old_generating_concat_p
= generating_concat_p
;
5367 generating_concat_p
= 0;
5368 tmp
= gen_reg_rtx (GET_MODE (decl_rtl
));
5369 generating_concat_p
= old_generating_concat_p
;
5371 emit_move_insn (tmp
, decl_rtl
);
5372 emit_move_insn (real_decl_rtl
, tmp
);
5374 /* If a named return value dumped decl_return to memory, then
5375 we may need to re-do the PROMOTE_MODE signed/unsigned
5377 else if (GET_MODE (real_decl_rtl
) != GET_MODE (decl_rtl
))
5379 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (decl_result
));
5380 promote_function_mode (TREE_TYPE (decl_result
),
5381 GET_MODE (decl_rtl
), &unsignedp
,
5382 TREE_TYPE (current_function_decl
), 1);
5384 convert_move (real_decl_rtl
, decl_rtl
, unsignedp
);
5387 emit_move_insn (real_decl_rtl
, decl_rtl
);
5391 /* If returning a structure, arrange to return the address of the value
5392 in a place where debuggers expect to find it.
5394 If returning a structure PCC style,
5395 the caller also depends on this value.
5396 And cfun->returns_pcc_struct is not necessarily set. */
5397 if ((cfun
->returns_struct
|| cfun
->returns_pcc_struct
)
5398 && !targetm
.calls
.omit_struct_return_reg
)
5400 rtx value_address
= DECL_RTL (DECL_RESULT (current_function_decl
));
5401 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
5404 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl
)))
5405 type
= TREE_TYPE (type
);
5407 value_address
= XEXP (value_address
, 0);
5409 outgoing
= targetm
.calls
.function_value (build_pointer_type (type
),
5410 current_function_decl
, true);
5412 /* Mark this as a function return value so integrate will delete the
5413 assignment and USE below when inlining this function. */
5414 REG_FUNCTION_VALUE_P (outgoing
) = 1;
5416 /* The address may be ptr_mode and OUTGOING may be Pmode. */
5417 scalar_int_mode mode
= as_a
<scalar_int_mode
> (GET_MODE (outgoing
));
5418 value_address
= convert_memory_address (mode
, value_address
);
5420 emit_move_insn (outgoing
, value_address
);
5422 /* Show return register used to hold result (in this case the address
5424 crtl
->return_rtx
= outgoing
;
5427 /* Emit the actual code to clobber return register. Don't emit
5428 it if clobber_after is a barrier, then the previous basic block
5429 certainly doesn't fall thru into the exit block. */
5430 if (!BARRIER_P (clobber_after
))
5433 clobber_return_register ();
5434 rtx_insn
*seq
= get_insns ();
5437 emit_insn_after (seq
, clobber_after
);
5440 /* Output the label for the naked return from the function. */
5441 if (naked_return_label
)
5442 emit_label (naked_return_label
);
5444 /* @@@ This is a kludge. We want to ensure that instructions that
5445 may trap are not moved into the epilogue by scheduling, because
5446 we don't always emit unwind information for the epilogue. */
5447 if (cfun
->can_throw_non_call_exceptions
5448 && targetm_common
.except_unwind_info (&global_options
) != UI_SJLJ
)
5449 emit_insn (gen_blockage ());
5451 /* If stack protection is enabled for this function, check the guard. */
5452 if (crtl
->stack_protect_guard
&& targetm
.stack_protect_runtime_enabled_p ())
5453 stack_protect_epilogue ();
5455 /* If we had calls to alloca, and this machine needs
5456 an accurate stack pointer to exit the function,
5457 insert some code to save and restore the stack pointer. */
5458 if (! EXIT_IGNORE_STACK
5459 && cfun
->calls_alloca
)
5464 emit_stack_save (SAVE_FUNCTION
, &tem
);
5465 rtx_insn
*seq
= get_insns ();
5467 emit_insn_before (seq
, parm_birth_insn
);
5469 emit_stack_restore (SAVE_FUNCTION
, tem
);
5472 /* ??? This should no longer be necessary since stupid is no longer with
5473 us, but there are some parts of the compiler (eg reload_combine, and
5474 sh mach_dep_reorg) that still try and compute their own lifetime info
5475 instead of using the general framework. */
5476 use_return_register ();
5480 get_arg_pointer_save_area (void)
5482 rtx ret
= arg_pointer_save_area
;
5486 ret
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5487 arg_pointer_save_area
= ret
;
5490 if (! crtl
->arg_pointer_save_area_init
)
5492 /* Save the arg pointer at the beginning of the function. The
5493 generated stack slot may not be a valid memory address, so we
5494 have to check it and fix it if necessary. */
5496 emit_move_insn (validize_mem (copy_rtx (ret
)),
5497 crtl
->args
.internal_arg_pointer
);
5498 rtx_insn
*seq
= get_insns ();
5501 push_topmost_sequence ();
5502 emit_insn_after (seq
, entry_of_function ());
5503 pop_topmost_sequence ();
5505 crtl
->arg_pointer_save_area_init
= true;
5512 /* If debugging dumps are requested, dump information about how the
5513 target handled -fstack-check=clash for the prologue.
5515 PROBES describes what if any probes were emitted.
5517 RESIDUALS indicates if the prologue had any residual allocation
5518 (i.e. total allocation was not a multiple of PROBE_INTERVAL). */
5521 dump_stack_clash_frame_info (enum stack_clash_probes probes
, bool residuals
)
5528 case NO_PROBE_NO_FRAME
:
5530 "Stack clash no probe no stack adjustment in prologue.\n");
5532 case NO_PROBE_SMALL_FRAME
:
5534 "Stack clash no probe small stack adjustment in prologue.\n");
5537 fprintf (dump_file
, "Stack clash inline probes in prologue.\n");
5540 fprintf (dump_file
, "Stack clash probe loop in prologue.\n");
5545 fprintf (dump_file
, "Stack clash residual allocation in prologue.\n");
5547 fprintf (dump_file
, "Stack clash no residual allocation in prologue.\n");
5549 if (frame_pointer_needed
)
5550 fprintf (dump_file
, "Stack clash frame pointer needed.\n");
5552 fprintf (dump_file
, "Stack clash no frame pointer needed.\n");
5554 if (TREE_THIS_VOLATILE (cfun
->decl
))
5556 "Stack clash noreturn prologue, assuming no implicit"
5557 " probes in caller.\n");
5560 "Stack clash not noreturn prologue.\n");
5563 /* Add a list of INSNS to the hash HASHP, possibly allocating HASHP
5564 for the first time. */
5567 record_insns (rtx_insn
*insns
, rtx end
, hash_table
<insn_cache_hasher
> **hashp
)
5570 hash_table
<insn_cache_hasher
> *hash
= *hashp
;
5573 *hashp
= hash
= hash_table
<insn_cache_hasher
>::create_ggc (17);
5575 for (tmp
= insns
; tmp
!= end
; tmp
= NEXT_INSN (tmp
))
5577 rtx
*slot
= hash
->find_slot (tmp
, INSERT
);
5578 gcc_assert (*slot
== NULL
);
5583 /* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a
5584 basic block, splitting or peepholes. If INSN is a prologue or epilogue
5585 insn, then record COPY as well. */
5588 maybe_copy_prologue_epilogue_insn (rtx insn
, rtx copy
)
5590 hash_table
<insn_cache_hasher
> *hash
;
5593 hash
= epilogue_insn_hash
;
5594 if (!hash
|| !hash
->find (insn
))
5596 hash
= prologue_insn_hash
;
5597 if (!hash
|| !hash
->find (insn
))
5601 slot
= hash
->find_slot (copy
, INSERT
);
5602 gcc_assert (*slot
== NULL
);
5606 /* Determine if any INSNs in HASH are, or are part of, INSN. Because
5607 we can be running after reorg, SEQUENCE rtl is possible. */
5610 contains (const rtx_insn
*insn
, hash_table
<insn_cache_hasher
> *hash
)
5615 if (NONJUMP_INSN_P (insn
) && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
5617 rtx_sequence
*seq
= as_a
<rtx_sequence
*> (PATTERN (insn
));
5619 for (i
= seq
->len () - 1; i
>= 0; i
--)
5620 if (hash
->find (seq
->element (i
)))
5625 return hash
->find (const_cast<rtx_insn
*> (insn
)) != NULL
;
5629 prologue_contains (const rtx_insn
*insn
)
5631 return contains (insn
, prologue_insn_hash
);
5635 epilogue_contains (const rtx_insn
*insn
)
5637 return contains (insn
, epilogue_insn_hash
);
5641 prologue_epilogue_contains (const rtx_insn
*insn
)
5643 if (contains (insn
, prologue_insn_hash
))
5645 if (contains (insn
, epilogue_insn_hash
))
5651 record_prologue_seq (rtx_insn
*seq
)
5653 record_insns (seq
, NULL
, &prologue_insn_hash
);
5657 record_epilogue_seq (rtx_insn
*seq
)
5659 record_insns (seq
, NULL
, &epilogue_insn_hash
);
5662 /* Set JUMP_LABEL for a return insn. */
5665 set_return_jump_label (rtx_insn
*returnjump
)
5667 rtx pat
= PATTERN (returnjump
);
5668 if (GET_CODE (pat
) == PARALLEL
)
5669 pat
= XVECEXP (pat
, 0, 0);
5670 if (ANY_RETURN_P (pat
))
5671 JUMP_LABEL (returnjump
) = pat
;
5673 JUMP_LABEL (returnjump
) = ret_rtx
;
5676 /* Return a sequence to be used as the split prologue for the current
5677 function, or NULL. */
5680 make_split_prologue_seq (void)
5682 if (!flag_split_stack
5683 || lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun
->decl
)))
5687 emit_insn (targetm
.gen_split_stack_prologue ());
5688 rtx_insn
*seq
= get_insns ();
5691 record_insns (seq
, NULL
, &prologue_insn_hash
);
5692 set_insn_locations (seq
, prologue_location
);
5697 /* Return a sequence to be used as the prologue for the current function,
5701 make_prologue_seq (void)
5703 if (!targetm
.have_prologue ())
5707 rtx_insn
*seq
= targetm
.gen_prologue ();
5710 /* Insert an explicit USE for the frame pointer
5711 if the profiling is on and the frame pointer is required. */
5712 if (crtl
->profile
&& frame_pointer_needed
)
5713 emit_use (hard_frame_pointer_rtx
);
5715 /* Retain a map of the prologue insns. */
5716 record_insns (seq
, NULL
, &prologue_insn_hash
);
5717 emit_note (NOTE_INSN_PROLOGUE_END
);
5719 /* Ensure that instructions are not moved into the prologue when
5720 profiling is on. The call to the profiling routine can be
5721 emitted within the live range of a call-clobbered register. */
5722 if (!targetm
.profile_before_prologue () && crtl
->profile
)
5723 emit_insn (gen_blockage ());
5727 set_insn_locations (seq
, prologue_location
);
5732 /* Return a sequence to be used as the epilogue for the current function,
5736 make_epilogue_seq (void)
5738 if (!targetm
.have_epilogue ())
5742 emit_note (NOTE_INSN_EPILOGUE_BEG
);
5743 rtx_insn
*seq
= targetm
.gen_epilogue ();
5745 emit_jump_insn (seq
);
5747 /* Retain a map of the epilogue insns. */
5748 record_insns (seq
, NULL
, &epilogue_insn_hash
);
5749 set_insn_locations (seq
, epilogue_location
);
5752 rtx_insn
*returnjump
= get_last_insn ();
5755 if (JUMP_P (returnjump
))
5756 set_return_jump_label (returnjump
);
5762 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5763 this into place with notes indicating where the prologue ends and where
5764 the epilogue begins. Update the basic block information when possible.
5766 Notes on epilogue placement:
5767 There are several kinds of edges to the exit block:
5768 * a single fallthru edge from LAST_BB
5769 * possibly, edges from blocks containing sibcalls
5770 * possibly, fake edges from infinite loops
5772 The epilogue is always emitted on the fallthru edge from the last basic
5773 block in the function, LAST_BB, into the exit block.
5775 If LAST_BB is empty except for a label, it is the target of every
5776 other basic block in the function that ends in a return. If a
5777 target has a return or simple_return pattern (possibly with
5778 conditional variants), these basic blocks can be changed so that a
5779 return insn is emitted into them, and their target is adjusted to
5780 the real exit block.
5782 Notes on shrink wrapping: We implement a fairly conservative
5783 version of shrink-wrapping rather than the textbook one. We only
5784 generate a single prologue and a single epilogue. This is
5785 sufficient to catch a number of interesting cases involving early
5788 First, we identify the blocks that require the prologue to occur before
5789 them. These are the ones that modify a call-saved register, or reference
5790 any of the stack or frame pointer registers. To simplify things, we then
5791 mark everything reachable from these blocks as also requiring a prologue.
5792 This takes care of loops automatically, and avoids the need to examine
5793 whether MEMs reference the frame, since it is sufficient to check for
5794 occurrences of the stack or frame pointer.
5796 We then compute the set of blocks for which the need for a prologue
5797 is anticipatable (borrowing terminology from the shrink-wrapping
5798 description in Muchnick's book). These are the blocks which either
5799 require a prologue themselves, or those that have only successors
5800 where the prologue is anticipatable. The prologue needs to be
5801 inserted on all edges from BB1->BB2 where BB2 is in ANTIC and BB1
5802 is not. For the moment, we ensure that only one such edge exists.
5804 The epilogue is placed as described above, but we make a
5805 distinction between inserting return and simple_return patterns
5806 when modifying other blocks that end in a return. Blocks that end
5807 in a sibcall omit the sibcall_epilogue if the block is not in
5811 thread_prologue_and_epilogue_insns (void)
5815 /* Can't deal with multiple successors of the entry block at the
5816 moment. Function should always have at least one entry
5818 gcc_assert (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun
)));
5820 edge entry_edge
= single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
5821 edge orig_entry_edge
= entry_edge
;
5823 rtx_insn
*split_prologue_seq
= make_split_prologue_seq ();
5824 rtx_insn
*prologue_seq
= make_prologue_seq ();
5825 rtx_insn
*epilogue_seq
= make_epilogue_seq ();
5827 /* Try to perform a kind of shrink-wrapping, making sure the
5828 prologue/epilogue is emitted only around those parts of the
5829 function that require it. */
5830 try_shrink_wrapping (&entry_edge
, prologue_seq
);
5832 /* If the target can handle splitting the prologue/epilogue into separate
5833 components, try to shrink-wrap these components separately. */
5834 try_shrink_wrapping_separate (entry_edge
->dest
);
5836 /* If that did anything for any component we now need the generate the
5837 "main" prologue again. Because some targets require some of these
5838 to be called in a specific order (i386 requires the split prologue
5839 to be first, for example), we create all three sequences again here.
5840 If this does not work for some target, that target should not enable
5841 separate shrink-wrapping. */
5842 if (crtl
->shrink_wrapped_separate
)
5844 split_prologue_seq
= make_split_prologue_seq ();
5845 prologue_seq
= make_prologue_seq ();
5846 epilogue_seq
= make_epilogue_seq ();
5849 rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun
));
5851 /* A small fib -- epilogue is not yet completed, but we wish to re-use
5852 this marker for the splits of EH_RETURN patterns, and nothing else
5853 uses the flag in the meantime. */
5854 epilogue_completed
= 1;
5856 /* Find non-fallthru edges that end with EH_RETURN instructions. On
5857 some targets, these get split to a special version of the epilogue
5858 code. In order to be able to properly annotate these with unwind
5859 info, try to split them now. If we get a valid split, drop an
5860 EPILOGUE_BEG note and mark the insns as epilogue insns. */
5863 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
5865 rtx_insn
*prev
, *last
, *trial
;
5867 if (e
->flags
& EDGE_FALLTHRU
)
5869 last
= BB_END (e
->src
);
5870 if (!eh_returnjump_p (last
))
5873 prev
= PREV_INSN (last
);
5874 trial
= try_split (PATTERN (last
), last
, 1);
5878 record_insns (NEXT_INSN (prev
), NEXT_INSN (trial
), &epilogue_insn_hash
);
5879 emit_note_after (NOTE_INSN_EPILOGUE_BEG
, prev
);
5882 edge exit_fallthru_edge
= find_fallthru_edge (EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
);
5884 if (exit_fallthru_edge
)
5888 insert_insn_on_edge (epilogue_seq
, exit_fallthru_edge
);
5889 commit_edge_insertions ();
5891 /* The epilogue insns we inserted may cause the exit edge to no longer
5893 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
5895 if (((e
->flags
& EDGE_FALLTHRU
) != 0)
5896 && returnjump_p (BB_END (e
->src
)))
5897 e
->flags
&= ~EDGE_FALLTHRU
;
5900 else if (next_active_insn (BB_END (exit_fallthru_edge
->src
)))
5902 /* We have a fall-through edge to the exit block, the source is not
5903 at the end of the function, and there will be an assembler epilogue
5904 at the end of the function.
5905 We can't use force_nonfallthru here, because that would try to
5906 use return. Inserting a jump 'by hand' is extremely messy, so
5907 we take advantage of cfg_layout_finalize using
5908 fixup_fallthru_exit_predecessor. */
5909 cfg_layout_initialize (0);
5911 FOR_EACH_BB_FN (cur_bb
, cfun
)
5912 if (cur_bb
->index
>= NUM_FIXED_BLOCKS
5913 && cur_bb
->next_bb
->index
>= NUM_FIXED_BLOCKS
)
5914 cur_bb
->aux
= cur_bb
->next_bb
;
5915 cfg_layout_finalize ();
5919 /* Insert the prologue. */
5921 rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
5923 if (split_prologue_seq
|| prologue_seq
)
5925 rtx_insn
*split_prologue_insn
= split_prologue_seq
;
5926 if (split_prologue_seq
)
5928 while (split_prologue_insn
&& !NONDEBUG_INSN_P (split_prologue_insn
))
5929 split_prologue_insn
= NEXT_INSN (split_prologue_insn
);
5930 insert_insn_on_edge (split_prologue_seq
, orig_entry_edge
);
5933 rtx_insn
*prologue_insn
= prologue_seq
;
5936 while (prologue_insn
&& !NONDEBUG_INSN_P (prologue_insn
))
5937 prologue_insn
= NEXT_INSN (prologue_insn
);
5938 insert_insn_on_edge (prologue_seq
, entry_edge
);
5941 commit_edge_insertions ();
5943 /* Look for basic blocks within the prologue insns. */
5944 if (split_prologue_insn
5945 && BLOCK_FOR_INSN (split_prologue_insn
) == NULL
)
5946 split_prologue_insn
= NULL
;
5948 && BLOCK_FOR_INSN (prologue_insn
) == NULL
)
5949 prologue_insn
= NULL
;
5950 if (split_prologue_insn
|| prologue_insn
)
5952 auto_sbitmap
blocks (last_basic_block_for_fn (cfun
));
5953 bitmap_clear (blocks
);
5954 if (split_prologue_insn
)
5955 bitmap_set_bit (blocks
,
5956 BLOCK_FOR_INSN (split_prologue_insn
)->index
);
5958 bitmap_set_bit (blocks
, BLOCK_FOR_INSN (prologue_insn
)->index
);
5959 find_many_sub_basic_blocks (blocks
);
5963 default_rtl_profile ();
5965 /* Emit sibling epilogues before any sibling call sites. */
5966 for (ei
= ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
);
5967 (e
= ei_safe_edge (ei
));
5970 /* Skip those already handled, the ones that run without prologue. */
5971 if (e
->flags
& EDGE_IGNORE
)
5973 e
->flags
&= ~EDGE_IGNORE
;
5977 rtx_insn
*insn
= BB_END (e
->src
);
5979 if (!(CALL_P (insn
) && SIBLING_CALL_P (insn
)))
5982 if (rtx_insn
*ep_seq
= targetm
.gen_sibcall_epilogue ())
5985 emit_note (NOTE_INSN_EPILOGUE_BEG
);
5987 rtx_insn
*seq
= get_insns ();
5990 /* Retain a map of the epilogue insns. Used in life analysis to
5991 avoid getting rid of sibcall epilogue insns. Do this before we
5992 actually emit the sequence. */
5993 record_insns (seq
, NULL
, &epilogue_insn_hash
);
5994 set_insn_locations (seq
, epilogue_location
);
5996 emit_insn_before (seq
, insn
);
6002 rtx_insn
*insn
, *next
;
6004 /* Similarly, move any line notes that appear after the epilogue.
6005 There is no need, however, to be quite so anal about the existence
6006 of such a note. Also possibly move
6007 NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
6009 for (insn
= epilogue_seq
; insn
; insn
= next
)
6011 next
= NEXT_INSN (insn
);
6013 && (NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
))
6014 reorder_insns (insn
, insn
, PREV_INSN (epilogue_seq
));
6018 /* Threading the prologue and epilogue changes the artificial refs
6019 in the entry and exit blocks. */
6020 epilogue_completed
= 1;
6021 df_update_entry_exit_and_calls ();
6024 /* Reposition the prologue-end and epilogue-begin notes after
6025 instruction scheduling. */
6028 reposition_prologue_and_epilogue_notes (void)
6030 if (!targetm
.have_prologue ()
6031 && !targetm
.have_epilogue ()
6032 && !targetm
.have_sibcall_epilogue ())
6035 /* Since the hash table is created on demand, the fact that it is
6036 non-null is a signal that it is non-empty. */
6037 if (prologue_insn_hash
!= NULL
)
6039 size_t len
= prologue_insn_hash
->elements ();
6040 rtx_insn
*insn
, *last
= NULL
, *note
= NULL
;
6042 /* Scan from the beginning until we reach the last prologue insn. */
6043 /* ??? While we do have the CFG intact, there are two problems:
6044 (1) The prologue can contain loops (typically probing the stack),
6045 which means that the end of the prologue isn't in the first bb.
6046 (2) Sometimes the PROLOGUE_END note gets pushed into the next bb. */
6047 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6051 if (NOTE_KIND (insn
) == NOTE_INSN_PROLOGUE_END
)
6054 else if (contains (insn
, prologue_insn_hash
))
6066 /* Scan forward looking for the PROLOGUE_END note. It should
6067 be right at the beginning of the block, possibly with other
6068 insn notes that got moved there. */
6069 for (note
= NEXT_INSN (last
); ; note
= NEXT_INSN (note
))
6072 && NOTE_KIND (note
) == NOTE_INSN_PROLOGUE_END
)
6077 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
6079 last
= NEXT_INSN (last
);
6080 reorder_insns (note
, note
, last
);
6084 if (epilogue_insn_hash
!= NULL
)
6089 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
6091 rtx_insn
*insn
, *first
= NULL
, *note
= NULL
;
6092 basic_block bb
= e
->src
;
6094 /* Scan from the beginning until we reach the first epilogue insn. */
6095 FOR_BB_INSNS (bb
, insn
)
6099 if (NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
6106 else if (first
== NULL
&& contains (insn
, epilogue_insn_hash
))
6116 /* If the function has a single basic block, and no real
6117 epilogue insns (e.g. sibcall with no cleanup), the
6118 epilogue note can get scheduled before the prologue
6119 note. If we have frame related prologue insns, having
6120 them scanned during the epilogue will result in a crash.
6121 In this case re-order the epilogue note to just before
6122 the last insn in the block. */
6124 first
= BB_END (bb
);
6126 if (PREV_INSN (first
) != note
)
6127 reorder_insns (note
, note
, PREV_INSN (first
));
6133 /* Returns the name of function declared by FNDECL. */
6135 fndecl_name (tree fndecl
)
6139 return lang_hooks
.decl_printable_name (fndecl
, 1);
6142 /* Returns the name of function FN. */
6144 function_name (struct function
*fn
)
6146 tree fndecl
= (fn
== NULL
) ? NULL
: fn
->decl
;
6147 return fndecl_name (fndecl
);
6150 /* Returns the name of the current function. */
6152 current_function_name (void)
6154 return function_name (cfun
);
6159 rest_of_handle_check_leaf_regs (void)
6161 #ifdef LEAF_REGISTERS
6162 crtl
->uses_only_leaf_regs
6163 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
6168 /* Insert a TYPE into the used types hash table of CFUN. */
6171 used_types_insert_helper (tree type
, struct function
*func
)
6173 if (type
!= NULL
&& func
!= NULL
)
6175 if (func
->used_types_hash
== NULL
)
6176 func
->used_types_hash
= hash_set
<tree
>::create_ggc (37);
6178 func
->used_types_hash
->add (type
);
6182 /* Given a type, insert it into the used hash table in cfun. */
6184 used_types_insert (tree t
)
6186 while (POINTER_TYPE_P (t
) || TREE_CODE (t
) == ARRAY_TYPE
)
6191 if (TREE_CODE (t
) == ERROR_MARK
)
6193 if (TYPE_NAME (t
) == NULL_TREE
6194 || TYPE_NAME (t
) == TYPE_NAME (TYPE_MAIN_VARIANT (t
)))
6195 t
= TYPE_MAIN_VARIANT (t
);
6196 if (debug_info_level
> DINFO_LEVEL_NONE
)
6199 used_types_insert_helper (t
, cfun
);
6202 /* So this might be a type referenced by a global variable.
6203 Record that type so that we can later decide to emit its
6204 debug information. */
6205 vec_safe_push (types_used_by_cur_var_decl
, t
);
6210 /* Helper to Hash a struct types_used_by_vars_entry. */
6213 hash_types_used_by_vars_entry (const struct types_used_by_vars_entry
*entry
)
6215 gcc_assert (entry
&& entry
->var_decl
&& entry
->type
);
6217 return iterative_hash_object (entry
->type
,
6218 iterative_hash_object (entry
->var_decl
, 0));
6221 /* Hash function of the types_used_by_vars_entry hash table. */
6224 used_type_hasher::hash (types_used_by_vars_entry
*entry
)
6226 return hash_types_used_by_vars_entry (entry
);
6229 /*Equality function of the types_used_by_vars_entry hash table. */
6232 used_type_hasher::equal (types_used_by_vars_entry
*e1
,
6233 types_used_by_vars_entry
*e2
)
6235 return (e1
->var_decl
== e2
->var_decl
&& e1
->type
== e2
->type
);
6238 /* Inserts an entry into the types_used_by_vars_hash hash table. */
6241 types_used_by_var_decl_insert (tree type
, tree var_decl
)
6243 if (type
!= NULL
&& var_decl
!= NULL
)
6245 types_used_by_vars_entry
**slot
;
6246 struct types_used_by_vars_entry e
;
6247 e
.var_decl
= var_decl
;
6249 if (types_used_by_vars_hash
== NULL
)
6250 types_used_by_vars_hash
6251 = hash_table
<used_type_hasher
>::create_ggc (37);
6253 slot
= types_used_by_vars_hash
->find_slot (&e
, INSERT
);
6256 struct types_used_by_vars_entry
*entry
;
6257 entry
= ggc_alloc
<types_used_by_vars_entry
> ();
6259 entry
->var_decl
= var_decl
;
6267 const pass_data pass_data_leaf_regs
=
6269 RTL_PASS
, /* type */
6270 "*leaf_regs", /* name */
6271 OPTGROUP_NONE
, /* optinfo_flags */
6272 TV_NONE
, /* tv_id */
6273 0, /* properties_required */
6274 0, /* properties_provided */
6275 0, /* properties_destroyed */
6276 0, /* todo_flags_start */
6277 0, /* todo_flags_finish */
6280 class pass_leaf_regs
: public rtl_opt_pass
6283 pass_leaf_regs (gcc::context
*ctxt
)
6284 : rtl_opt_pass (pass_data_leaf_regs
, ctxt
)
6287 /* opt_pass methods: */
6288 virtual unsigned int execute (function
*)
6290 return rest_of_handle_check_leaf_regs ();
6293 }; // class pass_leaf_regs
6298 make_pass_leaf_regs (gcc::context
*ctxt
)
6300 return new pass_leaf_regs (ctxt
);
6304 rest_of_handle_thread_prologue_and_epilogue (void)
6306 /* prepare_shrink_wrap is sensitive to the block structure of the control
6307 flow graph, so clean it up first. */
6311 /* On some machines, the prologue and epilogue code, or parts thereof,
6312 can be represented as RTL. Doing so lets us schedule insns between
6313 it and the rest of the code and also allows delayed branch
6314 scheduling to operate in the epilogue. */
6315 thread_prologue_and_epilogue_insns ();
6317 /* Some non-cold blocks may now be only reachable from cold blocks.
6319 fixup_partitions ();
6321 /* Shrink-wrapping can result in unreachable edges in the epilogue,
6323 cleanup_cfg (optimize
? CLEANUP_EXPENSIVE
: 0);
6325 /* The stack usage info is finalized during prologue expansion. */
6326 if (flag_stack_usage_info
)
6327 output_stack_usage ();
6334 const pass_data pass_data_thread_prologue_and_epilogue
=
6336 RTL_PASS
, /* type */
6337 "pro_and_epilogue", /* name */
6338 OPTGROUP_NONE
, /* optinfo_flags */
6339 TV_THREAD_PROLOGUE_AND_EPILOGUE
, /* tv_id */
6340 0, /* properties_required */
6341 0, /* properties_provided */
6342 0, /* properties_destroyed */
6343 0, /* todo_flags_start */
6344 ( TODO_df_verify
| TODO_df_finish
), /* todo_flags_finish */
6347 class pass_thread_prologue_and_epilogue
: public rtl_opt_pass
6350 pass_thread_prologue_and_epilogue (gcc::context
*ctxt
)
6351 : rtl_opt_pass (pass_data_thread_prologue_and_epilogue
, ctxt
)
6354 /* opt_pass methods: */
6355 virtual unsigned int execute (function
*)
6357 return rest_of_handle_thread_prologue_and_epilogue ();
6360 }; // class pass_thread_prologue_and_epilogue
6365 make_pass_thread_prologue_and_epilogue (gcc::context
*ctxt
)
6367 return new pass_thread_prologue_and_epilogue (ctxt
);
6371 /* This mini-pass fixes fall-out from SSA in asm statements that have
6372 in-out constraints. Say you start with
6375 asm ("": "+mr" (inout));
6378 which is transformed very early to use explicit output and match operands:
6381 asm ("": "=mr" (inout) : "0" (inout));
6384 Or, after SSA and copyprop,
6386 asm ("": "=mr" (inout_2) : "0" (inout_1));
6389 Clearly inout_2 and inout_1 can't be coalesced easily anymore, as
6390 they represent two separate values, so they will get different pseudo
6391 registers during expansion. Then, since the two operands need to match
6392 per the constraints, but use different pseudo registers, reload can
6393 only register a reload for these operands. But reloads can only be
6394 satisfied by hardregs, not by memory, so we need a register for this
6395 reload, just because we are presented with non-matching operands.
6396 So, even though we allow memory for this operand, no memory can be
6397 used for it, just because the two operands don't match. This can
6398 cause reload failures on register-starved targets.
6400 So it's a symptom of reload not being able to use memory for reloads
6401 or, alternatively it's also a symptom of both operands not coming into
6402 reload as matching (in which case the pseudo could go to memory just
6403 fine, as the alternative allows it, and no reload would be necessary).
6404 We fix the latter problem here, by transforming
6406 asm ("": "=mr" (inout_2) : "0" (inout_1));
6411 asm ("": "=mr" (inout_2) : "0" (inout_2)); */
6414 match_asm_constraints_1 (rtx_insn
*insn
, rtx
*p_sets
, int noutputs
)
6417 bool changed
= false;
6418 rtx op
= SET_SRC (p_sets
[0]);
6419 int ninputs
= ASM_OPERANDS_INPUT_LENGTH (op
);
6420 rtvec inputs
= ASM_OPERANDS_INPUT_VEC (op
);
6421 bool *output_matched
= XALLOCAVEC (bool, noutputs
);
6423 memset (output_matched
, 0, noutputs
* sizeof (bool));
6424 for (i
= 0; i
< ninputs
; i
++)
6428 const char *constraint
= ASM_OPERANDS_INPUT_CONSTRAINT (op
, i
);
6432 if (*constraint
== '%')
6435 match
= strtoul (constraint
, &end
, 10);
6436 if (end
== constraint
)
6439 gcc_assert (match
< noutputs
);
6440 output
= SET_DEST (p_sets
[match
]);
6441 input
= RTVEC_ELT (inputs
, i
);
6442 /* Only do the transformation for pseudos. */
6443 if (! REG_P (output
)
6444 || rtx_equal_p (output
, input
)
6445 || !(REG_P (input
) || SUBREG_P (input
)
6446 || MEM_P (input
) || CONSTANT_P (input
))
6447 || !general_operand (input
, GET_MODE (output
)))
6450 /* We can't do anything if the output is also used as input,
6451 as we're going to overwrite it. */
6452 for (j
= 0; j
< ninputs
; j
++)
6453 if (reg_overlap_mentioned_p (output
, RTVEC_ELT (inputs
, j
)))
6458 /* Avoid changing the same input several times. For
6459 asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in));
6460 only change in once (to out1), rather than changing it
6461 first to out1 and afterwards to out2. */
6464 for (j
= 0; j
< noutputs
; j
++)
6465 if (output_matched
[j
] && input
== SET_DEST (p_sets
[j
]))
6470 output_matched
[match
] = true;
6473 emit_move_insn (output
, input
);
6474 insns
= get_insns ();
6476 emit_insn_before (insns
, insn
);
6478 /* Now replace all mentions of the input with output. We can't
6479 just replace the occurrence in inputs[i], as the register might
6480 also be used in some other input (or even in an address of an
6481 output), which would mean possibly increasing the number of
6482 inputs by one (namely 'output' in addition), which might pose
6483 a too complicated problem for reload to solve. E.g. this situation:
6485 asm ("" : "=r" (output), "=m" (input) : "0" (input))
6487 Here 'input' is used in two occurrences as input (once for the
6488 input operand, once for the address in the second output operand).
6489 If we would replace only the occurrence of the input operand (to
6490 make the matching) we would be left with this:
6493 asm ("" : "=r" (output), "=m" (input) : "0" (output))
6495 Now we suddenly have two different input values (containing the same
6496 value, but different pseudos) where we formerly had only one.
6497 With more complicated asms this might lead to reload failures
6498 which wouldn't have happen without this pass. So, iterate over
6499 all operands and replace all occurrences of the register used. */
6500 for (j
= 0; j
< noutputs
; j
++)
6501 if (!rtx_equal_p (SET_DEST (p_sets
[j
]), input
)
6502 && reg_overlap_mentioned_p (input
, SET_DEST (p_sets
[j
])))
6503 SET_DEST (p_sets
[j
]) = replace_rtx (SET_DEST (p_sets
[j
]),
6505 for (j
= 0; j
< ninputs
; j
++)
6506 if (reg_overlap_mentioned_p (input
, RTVEC_ELT (inputs
, j
)))
6507 RTVEC_ELT (inputs
, j
) = replace_rtx (RTVEC_ELT (inputs
, j
),
6514 df_insn_rescan (insn
);
6517 /* Add the decl D to the local_decls list of FUN. */
6520 add_local_decl (struct function
*fun
, tree d
)
6522 gcc_assert (VAR_P (d
));
6523 vec_safe_push (fun
->local_decls
, d
);
6528 const pass_data pass_data_match_asm_constraints
=
6530 RTL_PASS
, /* type */
6531 "asmcons", /* name */
6532 OPTGROUP_NONE
, /* optinfo_flags */
6533 TV_NONE
, /* tv_id */
6534 0, /* properties_required */
6535 0, /* properties_provided */
6536 0, /* properties_destroyed */
6537 0, /* todo_flags_start */
6538 0, /* todo_flags_finish */
6541 class pass_match_asm_constraints
: public rtl_opt_pass
6544 pass_match_asm_constraints (gcc::context
*ctxt
)
6545 : rtl_opt_pass (pass_data_match_asm_constraints
, ctxt
)
6548 /* opt_pass methods: */
6549 virtual unsigned int execute (function
*);
6551 }; // class pass_match_asm_constraints
6554 pass_match_asm_constraints::execute (function
*fun
)
6561 if (!crtl
->has_asm_statement
)
6564 df_set_flags (DF_DEFER_INSN_RESCAN
);
6565 FOR_EACH_BB_FN (bb
, fun
)
6567 FOR_BB_INSNS (bb
, insn
)
6572 pat
= PATTERN (insn
);
6573 if (GET_CODE (pat
) == PARALLEL
)
6574 p_sets
= &XVECEXP (pat
, 0, 0), noutputs
= XVECLEN (pat
, 0);
6575 else if (GET_CODE (pat
) == SET
)
6576 p_sets
= &PATTERN (insn
), noutputs
= 1;
6580 if (GET_CODE (*p_sets
) == SET
6581 && GET_CODE (SET_SRC (*p_sets
)) == ASM_OPERANDS
)
6582 match_asm_constraints_1 (insn
, p_sets
, noutputs
);
6586 return TODO_df_finish
;
6592 make_pass_match_asm_constraints (gcc::context
*ctxt
)
6594 return new pass_match_asm_constraints (ctxt
);
6598 #include "gt-function.h"