1 /* Expands front end tree to back end RTL for GCC.
2 Copyright (C) 1987-2015 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"
45 #include "stringpool.h"
51 #include "rtl-error.h"
53 #include "fold-const.h"
54 #include "stor-layout.h"
61 #include "optabs-tree.h"
63 #include "langhooks.h"
64 #include "common/common-target.h"
66 #include "tree-pass.h"
70 #include "cfgcleanup.h"
71 #include "cfgexpand.h"
72 #include "shrink-wrap.h"
75 #include "tree-chkp.h"
79 /* So we can assign to cfun in this file. */
82 #ifndef STACK_ALIGNMENT_NEEDED
83 #define STACK_ALIGNMENT_NEEDED 1
86 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
88 /* Round a value to the lowest integer less than it that is a multiple of
89 the required alignment. Avoid using division in case the value is
90 negative. Assume the alignment is a power of two. */
91 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
93 /* Similar, but round to the next highest integer that meets the
95 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
97 /* Nonzero once virtual register instantiation has been done.
98 assign_stack_local uses frame_pointer_rtx when this is nonzero.
99 calls.c:emit_library_call_value_1 uses it to set up
100 post-instantiation libcalls. */
101 int virtuals_instantiated
;
103 /* Assign unique numbers to labels generated for profiling, debugging, etc. */
104 static GTY(()) int funcdef_no
;
106 /* These variables hold pointers to functions to create and destroy
107 target specific, per-function data structures. */
108 struct machine_function
* (*init_machine_status
) (void);
110 /* The currently compiled function. */
111 struct function
*cfun
= 0;
113 /* These hashes record the prologue and epilogue insns. */
115 struct insn_cache_hasher
: ggc_cache_ptr_hash
<rtx_def
>
117 static hashval_t
hash (rtx x
) { return htab_hash_pointer (x
); }
118 static bool equal (rtx a
, rtx b
) { return a
== b
; }
122 hash_table
<insn_cache_hasher
> *prologue_insn_hash
;
124 hash_table
<insn_cache_hasher
> *epilogue_insn_hash
;
127 hash_table
<used_type_hasher
> *types_used_by_vars_hash
= NULL
;
128 vec
<tree
, va_gc
> *types_used_by_cur_var_decl
;
130 /* Forward declarations. */
132 static struct temp_slot
*find_temp_slot_from_address (rtx
);
133 static void pad_to_arg_alignment (struct args_size
*, int, struct args_size
*);
134 static void pad_below (struct args_size
*, machine_mode
, tree
);
135 static void reorder_blocks_1 (rtx_insn
*, tree
, vec
<tree
> *);
136 static int all_blocks (tree
, tree
*);
137 static tree
*get_block_vector (tree
, int *);
138 extern tree
debug_find_var_in_block_tree (tree
, tree
);
139 /* We always define `record_insns' even if it's not used so that we
140 can always export `prologue_epilogue_contains'. */
141 static void record_insns (rtx_insn
*, rtx
, hash_table
<insn_cache_hasher
> **)
143 static bool contains (const_rtx
, hash_table
<insn_cache_hasher
> *);
144 static void prepare_function_start (void);
145 static void do_clobber_return_reg (rtx
, void *);
146 static void do_use_return_reg (rtx
, void *);
149 /* Stack of nested functions. */
150 /* Keep track of the cfun stack. */
152 static vec
<function
*> function_context_stack
;
154 /* Save the current context for compilation of a nested function.
155 This is called from language-specific code. */
158 push_function_context (void)
161 allocate_struct_function (NULL
, false);
163 function_context_stack
.safe_push (cfun
);
167 /* Restore the last saved context, at the end of a nested function.
168 This function is called from language-specific code. */
171 pop_function_context (void)
173 struct function
*p
= function_context_stack
.pop ();
175 current_function_decl
= p
->decl
;
177 /* Reset variables that have known state during rtx generation. */
178 virtuals_instantiated
= 0;
179 generating_concat_p
= 1;
182 /* Clear out all parts of the state in F that can safely be discarded
183 after the function has been parsed, but not compiled, to let
184 garbage collection reclaim the memory. */
187 free_after_parsing (struct function
*f
)
192 /* Clear out all parts of the state in F that can safely be discarded
193 after the function has been compiled, to let garbage collection
194 reclaim the memory. */
197 free_after_compilation (struct function
*f
)
199 prologue_insn_hash
= NULL
;
200 epilogue_insn_hash
= NULL
;
202 free (crtl
->emit
.regno_pointer_align
);
204 memset (crtl
, 0, sizeof (struct rtl_data
));
208 f
->curr_properties
&= ~PROP_cfg
;
210 regno_reg_rtx
= NULL
;
213 /* Return size needed for stack frame based on slots so far allocated.
214 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY;
215 the caller may have to do that. */
218 get_frame_size (void)
220 if (FRAME_GROWS_DOWNWARD
)
221 return -frame_offset
;
226 /* Issue an error message and return TRUE if frame OFFSET overflows in
227 the signed target pointer arithmetics for function FUNC. Otherwise
231 frame_offset_overflow (HOST_WIDE_INT offset
, tree func
)
233 unsigned HOST_WIDE_INT size
= FRAME_GROWS_DOWNWARD
? -offset
: offset
;
235 if (size
> ((unsigned HOST_WIDE_INT
) 1 << (GET_MODE_BITSIZE (Pmode
) - 1))
236 /* Leave room for the fixed part of the frame. */
237 - 64 * UNITS_PER_WORD
)
239 error_at (DECL_SOURCE_LOCATION (func
),
240 "total size of local objects too large");
247 /* Return stack slot alignment in bits for TYPE and MODE. */
250 get_stack_local_alignment (tree type
, machine_mode mode
)
252 unsigned int alignment
;
255 alignment
= BIGGEST_ALIGNMENT
;
257 alignment
= GET_MODE_ALIGNMENT (mode
);
259 /* Allow the frond-end to (possibly) increase the alignment of this
262 type
= lang_hooks
.types
.type_for_mode (mode
, 0);
264 return STACK_SLOT_ALIGNMENT (type
, mode
, alignment
);
267 /* Determine whether it is possible to fit a stack slot of size SIZE and
268 alignment ALIGNMENT into an area in the stack frame that starts at
269 frame offset START and has a length of LENGTH. If so, store the frame
270 offset to be used for the stack slot in *POFFSET and return true;
271 return false otherwise. This function will extend the frame size when
272 given a start/length pair that lies at the end of the frame. */
275 try_fit_stack_local (HOST_WIDE_INT start
, HOST_WIDE_INT length
,
276 HOST_WIDE_INT size
, unsigned int alignment
,
277 HOST_WIDE_INT
*poffset
)
279 HOST_WIDE_INT this_frame_offset
;
280 int frame_off
, frame_alignment
, frame_phase
;
282 /* Calculate how many bytes the start of local variables is off from
284 frame_alignment
= PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
;
285 frame_off
= STARTING_FRAME_OFFSET
% frame_alignment
;
286 frame_phase
= frame_off
? frame_alignment
- frame_off
: 0;
288 /* Round the frame offset to the specified alignment. */
290 /* We must be careful here, since FRAME_OFFSET might be negative and
291 division with a negative dividend isn't as well defined as we might
292 like. So we instead assume that ALIGNMENT is a power of two and
293 use logical operations which are unambiguous. */
294 if (FRAME_GROWS_DOWNWARD
)
296 = (FLOOR_ROUND (start
+ length
- size
- frame_phase
,
297 (unsigned HOST_WIDE_INT
) alignment
)
301 = (CEIL_ROUND (start
- frame_phase
,
302 (unsigned HOST_WIDE_INT
) alignment
)
305 /* See if it fits. If this space is at the edge of the frame,
306 consider extending the frame to make it fit. Our caller relies on
307 this when allocating a new slot. */
308 if (frame_offset
== start
&& this_frame_offset
< frame_offset
)
309 frame_offset
= this_frame_offset
;
310 else if (this_frame_offset
< start
)
312 else if (start
+ length
== frame_offset
313 && this_frame_offset
+ size
> start
+ length
)
314 frame_offset
= this_frame_offset
+ size
;
315 else if (this_frame_offset
+ size
> start
+ length
)
318 *poffset
= this_frame_offset
;
322 /* Create a new frame_space structure describing free space in the stack
323 frame beginning at START and ending at END, and chain it into the
324 function's frame_space_list. */
327 add_frame_space (HOST_WIDE_INT start
, HOST_WIDE_INT end
)
329 struct frame_space
*space
= ggc_alloc
<frame_space
> ();
330 space
->next
= crtl
->frame_space_list
;
331 crtl
->frame_space_list
= space
;
332 space
->start
= start
;
333 space
->length
= end
- start
;
336 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
337 with machine mode MODE.
339 ALIGN controls the amount of alignment for the address of the slot:
340 0 means according to MODE,
341 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
342 -2 means use BITS_PER_UNIT,
343 positive specifies alignment boundary in bits.
345 KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce
346 alignment and ASLK_RECORD_PAD bit set if we should remember
347 extra space we allocated for alignment purposes. When we are
348 called from assign_stack_temp_for_type, it is not set so we don't
349 track the same stack slot in two independent lists.
351 We do not round to stack_boundary here. */
354 assign_stack_local_1 (machine_mode mode
, HOST_WIDE_INT size
,
358 int bigend_correction
= 0;
359 HOST_WIDE_INT slot_offset
= 0, old_frame_offset
;
360 unsigned int alignment
, alignment_in_bits
;
364 alignment
= get_stack_local_alignment (NULL
, mode
);
365 alignment
/= BITS_PER_UNIT
;
367 else if (align
== -1)
369 alignment
= BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
;
370 size
= CEIL_ROUND (size
, alignment
);
372 else if (align
== -2)
373 alignment
= 1; /* BITS_PER_UNIT / BITS_PER_UNIT */
375 alignment
= align
/ BITS_PER_UNIT
;
377 alignment_in_bits
= alignment
* BITS_PER_UNIT
;
379 /* Ignore alignment if it exceeds MAX_SUPPORTED_STACK_ALIGNMENT. */
380 if (alignment_in_bits
> MAX_SUPPORTED_STACK_ALIGNMENT
)
382 alignment_in_bits
= MAX_SUPPORTED_STACK_ALIGNMENT
;
383 alignment
= alignment_in_bits
/ BITS_PER_UNIT
;
386 if (SUPPORTS_STACK_ALIGNMENT
)
388 if (crtl
->stack_alignment_estimated
< alignment_in_bits
)
390 if (!crtl
->stack_realign_processed
)
391 crtl
->stack_alignment_estimated
= alignment_in_bits
;
394 /* If stack is realigned and stack alignment value
395 hasn't been finalized, it is OK not to increase
396 stack_alignment_estimated. The bigger alignment
397 requirement is recorded in stack_alignment_needed
399 gcc_assert (!crtl
->stack_realign_finalized
);
400 if (!crtl
->stack_realign_needed
)
402 /* It is OK to reduce the alignment as long as the
403 requested size is 0 or the estimated stack
404 alignment >= mode alignment. */
405 gcc_assert ((kind
& ASLK_REDUCE_ALIGN
)
407 || (crtl
->stack_alignment_estimated
408 >= GET_MODE_ALIGNMENT (mode
)));
409 alignment_in_bits
= crtl
->stack_alignment_estimated
;
410 alignment
= alignment_in_bits
/ BITS_PER_UNIT
;
416 if (crtl
->stack_alignment_needed
< alignment_in_bits
)
417 crtl
->stack_alignment_needed
= alignment_in_bits
;
418 if (crtl
->max_used_stack_slot_alignment
< alignment_in_bits
)
419 crtl
->max_used_stack_slot_alignment
= alignment_in_bits
;
421 if (mode
!= BLKmode
|| size
!= 0)
423 if (kind
& ASLK_RECORD_PAD
)
425 struct frame_space
**psp
;
427 for (psp
= &crtl
->frame_space_list
; *psp
; psp
= &(*psp
)->next
)
429 struct frame_space
*space
= *psp
;
430 if (!try_fit_stack_local (space
->start
, space
->length
, size
,
431 alignment
, &slot_offset
))
434 if (slot_offset
> space
->start
)
435 add_frame_space (space
->start
, slot_offset
);
436 if (slot_offset
+ size
< space
->start
+ space
->length
)
437 add_frame_space (slot_offset
+ size
,
438 space
->start
+ space
->length
);
443 else if (!STACK_ALIGNMENT_NEEDED
)
445 slot_offset
= frame_offset
;
449 old_frame_offset
= frame_offset
;
451 if (FRAME_GROWS_DOWNWARD
)
453 frame_offset
-= size
;
454 try_fit_stack_local (frame_offset
, size
, size
, alignment
, &slot_offset
);
456 if (kind
& ASLK_RECORD_PAD
)
458 if (slot_offset
> frame_offset
)
459 add_frame_space (frame_offset
, slot_offset
);
460 if (slot_offset
+ size
< old_frame_offset
)
461 add_frame_space (slot_offset
+ size
, old_frame_offset
);
466 frame_offset
+= size
;
467 try_fit_stack_local (old_frame_offset
, size
, size
, alignment
, &slot_offset
);
469 if (kind
& ASLK_RECORD_PAD
)
471 if (slot_offset
> old_frame_offset
)
472 add_frame_space (old_frame_offset
, slot_offset
);
473 if (slot_offset
+ size
< frame_offset
)
474 add_frame_space (slot_offset
+ size
, frame_offset
);
479 /* On a big-endian machine, if we are allocating more space than we will use,
480 use the least significant bytes of those that are allocated. */
481 if (BYTES_BIG_ENDIAN
&& mode
!= BLKmode
&& GET_MODE_SIZE (mode
) < size
)
482 bigend_correction
= size
- GET_MODE_SIZE (mode
);
484 /* If we have already instantiated virtual registers, return the actual
485 address relative to the frame pointer. */
486 if (virtuals_instantiated
)
487 addr
= plus_constant (Pmode
, frame_pointer_rtx
,
489 (slot_offset
+ bigend_correction
490 + STARTING_FRAME_OFFSET
, Pmode
));
492 addr
= plus_constant (Pmode
, virtual_stack_vars_rtx
,
494 (slot_offset
+ bigend_correction
,
497 x
= gen_rtx_MEM (mode
, addr
);
498 set_mem_align (x
, alignment_in_bits
);
499 MEM_NOTRAP_P (x
) = 1;
502 = gen_rtx_EXPR_LIST (VOIDmode
, x
, stack_slot_list
);
504 if (frame_offset_overflow (frame_offset
, current_function_decl
))
510 /* Wrap up assign_stack_local_1 with last parameter as false. */
513 assign_stack_local (machine_mode mode
, HOST_WIDE_INT size
, int align
)
515 return assign_stack_local_1 (mode
, size
, align
, ASLK_RECORD_PAD
);
518 /* In order to evaluate some expressions, such as function calls returning
519 structures in memory, we need to temporarily allocate stack locations.
520 We record each allocated temporary in the following structure.
522 Associated with each temporary slot is a nesting level. When we pop up
523 one level, all temporaries associated with the previous level are freed.
524 Normally, all temporaries are freed after the execution of the statement
525 in which they were created. However, if we are inside a ({...}) grouping,
526 the result may be in a temporary and hence must be preserved. If the
527 result could be in a temporary, we preserve it if we can determine which
528 one it is in. If we cannot determine which temporary may contain the
529 result, all temporaries are preserved. A temporary is preserved by
530 pretending it was allocated at the previous nesting level. */
532 struct GTY(()) temp_slot
{
533 /* Points to next temporary slot. */
534 struct temp_slot
*next
;
535 /* Points to previous temporary slot. */
536 struct temp_slot
*prev
;
537 /* The rtx to used to reference the slot. */
539 /* The size, in units, of the slot. */
541 /* The type of the object in the slot, or zero if it doesn't correspond
542 to a type. We use this to determine whether a slot can be reused.
543 It can be reused if objects of the type of the new slot will always
544 conflict with objects of the type of the old slot. */
546 /* The alignment (in bits) of the slot. */
548 /* Nonzero if this temporary is currently in use. */
550 /* Nesting level at which this slot is being used. */
552 /* The offset of the slot from the frame_pointer, including extra space
553 for alignment. This info is for combine_temp_slots. */
554 HOST_WIDE_INT base_offset
;
555 /* The size of the slot, including extra space for alignment. This
556 info is for combine_temp_slots. */
557 HOST_WIDE_INT full_size
;
560 /* Entry for the below hash table. */
561 struct GTY((for_user
)) temp_slot_address_entry
{
564 struct temp_slot
*temp_slot
;
567 struct temp_address_hasher
: ggc_ptr_hash
<temp_slot_address_entry
>
569 static hashval_t
hash (temp_slot_address_entry
*);
570 static bool equal (temp_slot_address_entry
*, temp_slot_address_entry
*);
573 /* A table of addresses that represent a stack slot. The table is a mapping
574 from address RTXen to a temp slot. */
575 static GTY(()) hash_table
<temp_address_hasher
> *temp_slot_address_table
;
576 static size_t n_temp_slots_in_use
;
578 /* Removes temporary slot TEMP from LIST. */
581 cut_slot_from_list (struct temp_slot
*temp
, struct temp_slot
**list
)
584 temp
->next
->prev
= temp
->prev
;
586 temp
->prev
->next
= temp
->next
;
590 temp
->prev
= temp
->next
= NULL
;
593 /* Inserts temporary slot TEMP to LIST. */
596 insert_slot_to_list (struct temp_slot
*temp
, struct temp_slot
**list
)
600 (*list
)->prev
= temp
;
605 /* Returns the list of used temp slots at LEVEL. */
607 static struct temp_slot
**
608 temp_slots_at_level (int level
)
610 if (level
>= (int) vec_safe_length (used_temp_slots
))
611 vec_safe_grow_cleared (used_temp_slots
, level
+ 1);
613 return &(*used_temp_slots
)[level
];
616 /* Returns the maximal temporary slot level. */
619 max_slot_level (void)
621 if (!used_temp_slots
)
624 return used_temp_slots
->length () - 1;
627 /* Moves temporary slot TEMP to LEVEL. */
630 move_slot_to_level (struct temp_slot
*temp
, int level
)
632 cut_slot_from_list (temp
, temp_slots_at_level (temp
->level
));
633 insert_slot_to_list (temp
, temp_slots_at_level (level
));
637 /* Make temporary slot TEMP available. */
640 make_slot_available (struct temp_slot
*temp
)
642 cut_slot_from_list (temp
, temp_slots_at_level (temp
->level
));
643 insert_slot_to_list (temp
, &avail_temp_slots
);
646 n_temp_slots_in_use
--;
649 /* Compute the hash value for an address -> temp slot mapping.
650 The value is cached on the mapping entry. */
652 temp_slot_address_compute_hash (struct temp_slot_address_entry
*t
)
654 int do_not_record
= 0;
655 return hash_rtx (t
->address
, GET_MODE (t
->address
),
656 &do_not_record
, NULL
, false);
659 /* Return the hash value for an address -> temp slot mapping. */
661 temp_address_hasher::hash (temp_slot_address_entry
*t
)
666 /* Compare two address -> temp slot mapping entries. */
668 temp_address_hasher::equal (temp_slot_address_entry
*t1
,
669 temp_slot_address_entry
*t2
)
671 return exp_equiv_p (t1
->address
, t2
->address
, 0, true);
674 /* Add ADDRESS as an alias of TEMP_SLOT to the addess -> temp slot mapping. */
676 insert_temp_slot_address (rtx address
, struct temp_slot
*temp_slot
)
678 struct temp_slot_address_entry
*t
= ggc_alloc
<temp_slot_address_entry
> ();
679 t
->address
= address
;
680 t
->temp_slot
= temp_slot
;
681 t
->hash
= temp_slot_address_compute_hash (t
);
682 *temp_slot_address_table
->find_slot_with_hash (t
, t
->hash
, INSERT
) = t
;
685 /* Remove an address -> temp slot mapping entry if the temp slot is
686 not in use anymore. Callback for remove_unused_temp_slot_addresses. */
688 remove_unused_temp_slot_addresses_1 (temp_slot_address_entry
**slot
, void *)
690 const struct temp_slot_address_entry
*t
= *slot
;
691 if (! t
->temp_slot
->in_use
)
692 temp_slot_address_table
->clear_slot (slot
);
696 /* Remove all mappings of addresses to unused temp slots. */
698 remove_unused_temp_slot_addresses (void)
700 /* Use quicker clearing if there aren't any active temp slots. */
701 if (n_temp_slots_in_use
)
702 temp_slot_address_table
->traverse
703 <void *, remove_unused_temp_slot_addresses_1
> (NULL
);
705 temp_slot_address_table
->empty ();
708 /* Find the temp slot corresponding to the object at address X. */
710 static struct temp_slot
*
711 find_temp_slot_from_address (rtx x
)
714 struct temp_slot_address_entry tmp
, *t
;
716 /* First try the easy way:
717 See if X exists in the address -> temp slot mapping. */
719 tmp
.temp_slot
= NULL
;
720 tmp
.hash
= temp_slot_address_compute_hash (&tmp
);
721 t
= temp_slot_address_table
->find_with_hash (&tmp
, tmp
.hash
);
725 /* If we have a sum involving a register, see if it points to a temp
727 if (GET_CODE (x
) == PLUS
&& REG_P (XEXP (x
, 0))
728 && (p
= find_temp_slot_from_address (XEXP (x
, 0))) != 0)
730 else if (GET_CODE (x
) == PLUS
&& REG_P (XEXP (x
, 1))
731 && (p
= find_temp_slot_from_address (XEXP (x
, 1))) != 0)
734 /* Last resort: Address is a virtual stack var address. */
735 if (GET_CODE (x
) == PLUS
736 && XEXP (x
, 0) == virtual_stack_vars_rtx
737 && CONST_INT_P (XEXP (x
, 1)))
740 for (i
= max_slot_level (); i
>= 0; i
--)
741 for (p
= *temp_slots_at_level (i
); p
; p
= p
->next
)
743 if (INTVAL (XEXP (x
, 1)) >= p
->base_offset
744 && INTVAL (XEXP (x
, 1)) < p
->base_offset
+ p
->full_size
)
752 /* Allocate a temporary stack slot and record it for possible later
755 MODE is the machine mode to be given to the returned rtx.
757 SIZE is the size in units of the space required. We do no rounding here
758 since assign_stack_local will do any required rounding.
760 TYPE is the type that will be used for the stack slot. */
763 assign_stack_temp_for_type (machine_mode mode
, HOST_WIDE_INT size
,
767 struct temp_slot
*p
, *best_p
= 0, *selected
= NULL
, **pp
;
770 /* If SIZE is -1 it means that somebody tried to allocate a temporary
771 of a variable size. */
772 gcc_assert (size
!= -1);
774 align
= get_stack_local_alignment (type
, mode
);
776 /* Try to find an available, already-allocated temporary of the proper
777 mode which meets the size and alignment requirements. Choose the
778 smallest one with the closest alignment.
780 If assign_stack_temp is called outside of the tree->rtl expansion,
781 we cannot reuse the stack slots (that may still refer to
782 VIRTUAL_STACK_VARS_REGNUM). */
783 if (!virtuals_instantiated
)
785 for (p
= avail_temp_slots
; p
; p
= p
->next
)
787 if (p
->align
>= align
&& p
->size
>= size
788 && GET_MODE (p
->slot
) == mode
789 && objects_must_conflict_p (p
->type
, type
)
790 && (best_p
== 0 || best_p
->size
> p
->size
791 || (best_p
->size
== p
->size
&& best_p
->align
> p
->align
)))
793 if (p
->align
== align
&& p
->size
== size
)
796 cut_slot_from_list (selected
, &avail_temp_slots
);
805 /* Make our best, if any, the one to use. */
809 cut_slot_from_list (selected
, &avail_temp_slots
);
811 /* If there are enough aligned bytes left over, make them into a new
812 temp_slot so that the extra bytes don't get wasted. Do this only
813 for BLKmode slots, so that we can be sure of the alignment. */
814 if (GET_MODE (best_p
->slot
) == BLKmode
)
816 int alignment
= best_p
->align
/ BITS_PER_UNIT
;
817 HOST_WIDE_INT rounded_size
= CEIL_ROUND (size
, alignment
);
819 if (best_p
->size
- rounded_size
>= alignment
)
821 p
= ggc_alloc
<temp_slot
> ();
823 p
->size
= best_p
->size
- rounded_size
;
824 p
->base_offset
= best_p
->base_offset
+ rounded_size
;
825 p
->full_size
= best_p
->full_size
- rounded_size
;
826 p
->slot
= adjust_address_nv (best_p
->slot
, BLKmode
, rounded_size
);
827 p
->align
= best_p
->align
;
828 p
->type
= best_p
->type
;
829 insert_slot_to_list (p
, &avail_temp_slots
);
831 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, p
->slot
,
834 best_p
->size
= rounded_size
;
835 best_p
->full_size
= rounded_size
;
840 /* If we still didn't find one, make a new temporary. */
843 HOST_WIDE_INT frame_offset_old
= frame_offset
;
845 p
= ggc_alloc
<temp_slot
> ();
847 /* We are passing an explicit alignment request to assign_stack_local.
848 One side effect of that is assign_stack_local will not round SIZE
849 to ensure the frame offset remains suitably aligned.
851 So for requests which depended on the rounding of SIZE, we go ahead
852 and round it now. We also make sure ALIGNMENT is at least
853 BIGGEST_ALIGNMENT. */
854 gcc_assert (mode
!= BLKmode
|| align
== BIGGEST_ALIGNMENT
);
855 p
->slot
= assign_stack_local_1 (mode
,
865 /* The following slot size computation is necessary because we don't
866 know the actual size of the temporary slot until assign_stack_local
867 has performed all the frame alignment and size rounding for the
868 requested temporary. Note that extra space added for alignment
869 can be either above or below this stack slot depending on which
870 way the frame grows. We include the extra space if and only if it
871 is above this slot. */
872 if (FRAME_GROWS_DOWNWARD
)
873 p
->size
= frame_offset_old
- frame_offset
;
877 /* Now define the fields used by combine_temp_slots. */
878 if (FRAME_GROWS_DOWNWARD
)
880 p
->base_offset
= frame_offset
;
881 p
->full_size
= frame_offset_old
- frame_offset
;
885 p
->base_offset
= frame_offset_old
;
886 p
->full_size
= frame_offset
- frame_offset_old
;
895 p
->level
= temp_slot_level
;
896 n_temp_slots_in_use
++;
898 pp
= temp_slots_at_level (p
->level
);
899 insert_slot_to_list (p
, pp
);
900 insert_temp_slot_address (XEXP (p
->slot
, 0), p
);
902 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */
903 slot
= gen_rtx_MEM (mode
, XEXP (p
->slot
, 0));
904 stack_slot_list
= gen_rtx_EXPR_LIST (VOIDmode
, slot
, stack_slot_list
);
906 /* If we know the alias set for the memory that will be used, use
907 it. If there's no TYPE, then we don't know anything about the
908 alias set for the memory. */
909 set_mem_alias_set (slot
, type
? get_alias_set (type
) : 0);
910 set_mem_align (slot
, align
);
912 /* If a type is specified, set the relevant flags. */
914 MEM_VOLATILE_P (slot
) = TYPE_VOLATILE (type
);
915 MEM_NOTRAP_P (slot
) = 1;
920 /* Allocate a temporary stack slot and record it for possible later
921 reuse. First two arguments are same as in preceding function. */
924 assign_stack_temp (machine_mode mode
, HOST_WIDE_INT size
)
926 return assign_stack_temp_for_type (mode
, size
, NULL_TREE
);
929 /* Assign a temporary.
930 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl
931 and so that should be used in error messages. In either case, we
932 allocate of the given type.
933 MEMORY_REQUIRED is 1 if the result must be addressable stack memory;
934 it is 0 if a register is OK.
935 DONT_PROMOTE is 1 if we should not promote values in register
939 assign_temp (tree type_or_decl
, int memory_required
,
940 int dont_promote ATTRIBUTE_UNUSED
)
948 if (DECL_P (type_or_decl
))
949 decl
= type_or_decl
, type
= TREE_TYPE (decl
);
951 decl
= NULL
, type
= type_or_decl
;
953 mode
= TYPE_MODE (type
);
955 unsignedp
= TYPE_UNSIGNED (type
);
958 if (mode
== BLKmode
|| memory_required
)
960 HOST_WIDE_INT size
= int_size_in_bytes (type
);
963 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid
964 problems with allocating the stack space. */
968 /* Unfortunately, we don't yet know how to allocate variable-sized
969 temporaries. However, sometimes we can find a fixed upper limit on
970 the size, so try that instead. */
972 size
= max_int_size_in_bytes (type
);
974 /* The size of the temporary may be too large to fit into an integer. */
975 /* ??? Not sure this should happen except for user silliness, so limit
976 this to things that aren't compiler-generated temporaries. The
977 rest of the time we'll die in assign_stack_temp_for_type. */
978 if (decl
&& size
== -1
979 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
)
981 error ("size of variable %q+D is too large", decl
);
985 tmp
= assign_stack_temp_for_type (mode
, size
, type
);
991 mode
= promote_mode (type
, mode
, &unsignedp
);
994 return gen_reg_rtx (mode
);
997 /* Combine temporary stack slots which are adjacent on the stack.
999 This allows for better use of already allocated stack space. This is only
1000 done for BLKmode slots because we can be sure that we won't have alignment
1001 problems in this case. */
1004 combine_temp_slots (void)
1006 struct temp_slot
*p
, *q
, *next
, *next_q
;
1009 /* We can't combine slots, because the information about which slot
1010 is in which alias set will be lost. */
1011 if (flag_strict_aliasing
)
1014 /* If there are a lot of temp slots, don't do anything unless
1015 high levels of optimization. */
1016 if (! flag_expensive_optimizations
)
1017 for (p
= avail_temp_slots
, num_slots
= 0; p
; p
= p
->next
, num_slots
++)
1018 if (num_slots
> 100 || (num_slots
> 10 && optimize
== 0))
1021 for (p
= avail_temp_slots
; p
; p
= next
)
1027 if (GET_MODE (p
->slot
) != BLKmode
)
1030 for (q
= p
->next
; q
; q
= next_q
)
1036 if (GET_MODE (q
->slot
) != BLKmode
)
1039 if (p
->base_offset
+ p
->full_size
== q
->base_offset
)
1041 /* Q comes after P; combine Q into P. */
1043 p
->full_size
+= q
->full_size
;
1046 else if (q
->base_offset
+ q
->full_size
== p
->base_offset
)
1048 /* P comes after Q; combine P into Q. */
1050 q
->full_size
+= p
->full_size
;
1055 cut_slot_from_list (q
, &avail_temp_slots
);
1058 /* Either delete P or advance past it. */
1060 cut_slot_from_list (p
, &avail_temp_slots
);
1064 /* Indicate that NEW_RTX is an alternate way of referring to the temp
1065 slot that previously was known by OLD_RTX. */
1068 update_temp_slot_address (rtx old_rtx
, rtx new_rtx
)
1070 struct temp_slot
*p
;
1072 if (rtx_equal_p (old_rtx
, new_rtx
))
1075 p
= find_temp_slot_from_address (old_rtx
);
1077 /* If we didn't find one, see if both OLD_RTX is a PLUS. If so, and
1078 NEW_RTX is a register, see if one operand of the PLUS is a
1079 temporary location. If so, NEW_RTX points into it. Otherwise,
1080 if both OLD_RTX and NEW_RTX are a PLUS and if there is a register
1081 in common between them. If so, try a recursive call on those
1085 if (GET_CODE (old_rtx
) != PLUS
)
1088 if (REG_P (new_rtx
))
1090 update_temp_slot_address (XEXP (old_rtx
, 0), new_rtx
);
1091 update_temp_slot_address (XEXP (old_rtx
, 1), new_rtx
);
1094 else if (GET_CODE (new_rtx
) != PLUS
)
1097 if (rtx_equal_p (XEXP (old_rtx
, 0), XEXP (new_rtx
, 0)))
1098 update_temp_slot_address (XEXP (old_rtx
, 1), XEXP (new_rtx
, 1));
1099 else if (rtx_equal_p (XEXP (old_rtx
, 1), XEXP (new_rtx
, 0)))
1100 update_temp_slot_address (XEXP (old_rtx
, 0), XEXP (new_rtx
, 1));
1101 else if (rtx_equal_p (XEXP (old_rtx
, 0), XEXP (new_rtx
, 1)))
1102 update_temp_slot_address (XEXP (old_rtx
, 1), XEXP (new_rtx
, 0));
1103 else if (rtx_equal_p (XEXP (old_rtx
, 1), XEXP (new_rtx
, 1)))
1104 update_temp_slot_address (XEXP (old_rtx
, 0), XEXP (new_rtx
, 0));
1109 /* Otherwise add an alias for the temp's address. */
1110 insert_temp_slot_address (new_rtx
, p
);
1113 /* If X could be a reference to a temporary slot, mark that slot as
1114 belonging to the to one level higher than the current level. If X
1115 matched one of our slots, just mark that one. Otherwise, we can't
1116 easily predict which it is, so upgrade all of them.
1118 This is called when an ({...}) construct occurs and a statement
1119 returns a value in memory. */
1122 preserve_temp_slots (rtx x
)
1124 struct temp_slot
*p
= 0, *next
;
1129 /* If X is a register that is being used as a pointer, see if we have
1130 a temporary slot we know it points to. */
1131 if (REG_P (x
) && REG_POINTER (x
))
1132 p
= find_temp_slot_from_address (x
);
1134 /* If X is not in memory or is at a constant address, it cannot be in
1135 a temporary slot. */
1136 if (p
== 0 && (!MEM_P (x
) || CONSTANT_P (XEXP (x
, 0))))
1139 /* First see if we can find a match. */
1141 p
= find_temp_slot_from_address (XEXP (x
, 0));
1145 if (p
->level
== temp_slot_level
)
1146 move_slot_to_level (p
, temp_slot_level
- 1);
1150 /* Otherwise, preserve all non-kept slots at this level. */
1151 for (p
= *temp_slots_at_level (temp_slot_level
); p
; p
= next
)
1154 move_slot_to_level (p
, temp_slot_level
- 1);
1158 /* Free all temporaries used so far. This is normally called at the
1159 end of generating code for a statement. */
1162 free_temp_slots (void)
1164 struct temp_slot
*p
, *next
;
1165 bool some_available
= false;
1167 for (p
= *temp_slots_at_level (temp_slot_level
); p
; p
= next
)
1170 make_slot_available (p
);
1171 some_available
= true;
1176 remove_unused_temp_slot_addresses ();
1177 combine_temp_slots ();
1181 /* Push deeper into the nesting level for stack temporaries. */
1184 push_temp_slots (void)
1189 /* Pop a temporary nesting level. All slots in use in the current level
1193 pop_temp_slots (void)
1199 /* Initialize temporary slots. */
1202 init_temp_slots (void)
1204 /* We have not allocated any temporaries yet. */
1205 avail_temp_slots
= 0;
1206 vec_alloc (used_temp_slots
, 0);
1207 temp_slot_level
= 0;
1208 n_temp_slots_in_use
= 0;
1210 /* Set up the table to map addresses to temp slots. */
1211 if (! temp_slot_address_table
)
1212 temp_slot_address_table
= hash_table
<temp_address_hasher
>::create_ggc (32);
1214 temp_slot_address_table
->empty ();
1217 /* Functions and data structures to keep track of the values hard regs
1218 had at the start of the function. */
1220 /* Private type used by get_hard_reg_initial_reg, get_hard_reg_initial_val,
1221 and has_hard_reg_initial_val.. */
1222 struct GTY(()) initial_value_pair
{
1226 /* ??? This could be a VEC but there is currently no way to define an
1227 opaque VEC type. This could be worked around by defining struct
1228 initial_value_pair in function.h. */
1229 struct GTY(()) initial_value_struct
{
1232 initial_value_pair
* GTY ((length ("%h.num_entries"))) entries
;
1235 /* If a pseudo represents an initial hard reg (or expression), return
1236 it, else return NULL_RTX. */
1239 get_hard_reg_initial_reg (rtx reg
)
1241 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1247 for (i
= 0; i
< ivs
->num_entries
; i
++)
1248 if (rtx_equal_p (ivs
->entries
[i
].pseudo
, reg
))
1249 return ivs
->entries
[i
].hard_reg
;
1254 /* Make sure that there's a pseudo register of mode MODE that stores the
1255 initial value of hard register REGNO. Return an rtx for such a pseudo. */
1258 get_hard_reg_initial_val (machine_mode mode
, unsigned int regno
)
1260 struct initial_value_struct
*ivs
;
1263 rv
= has_hard_reg_initial_val (mode
, regno
);
1267 ivs
= crtl
->hard_reg_initial_vals
;
1270 ivs
= ggc_alloc
<initial_value_struct
> ();
1271 ivs
->num_entries
= 0;
1272 ivs
->max_entries
= 5;
1273 ivs
->entries
= ggc_vec_alloc
<initial_value_pair
> (5);
1274 crtl
->hard_reg_initial_vals
= ivs
;
1277 if (ivs
->num_entries
>= ivs
->max_entries
)
1279 ivs
->max_entries
+= 5;
1280 ivs
->entries
= GGC_RESIZEVEC (initial_value_pair
, ivs
->entries
,
1284 ivs
->entries
[ivs
->num_entries
].hard_reg
= gen_rtx_REG (mode
, regno
);
1285 ivs
->entries
[ivs
->num_entries
].pseudo
= gen_reg_rtx (mode
);
1287 return ivs
->entries
[ivs
->num_entries
++].pseudo
;
1290 /* See if get_hard_reg_initial_val has been used to create a pseudo
1291 for the initial value of hard register REGNO in mode MODE. Return
1292 the associated pseudo if so, otherwise return NULL. */
1295 has_hard_reg_initial_val (machine_mode mode
, unsigned int regno
)
1297 struct initial_value_struct
*ivs
;
1300 ivs
= crtl
->hard_reg_initial_vals
;
1302 for (i
= 0; i
< ivs
->num_entries
; i
++)
1303 if (GET_MODE (ivs
->entries
[i
].hard_reg
) == mode
1304 && REGNO (ivs
->entries
[i
].hard_reg
) == regno
)
1305 return ivs
->entries
[i
].pseudo
;
1311 emit_initial_value_sets (void)
1313 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1321 for (i
= 0; i
< ivs
->num_entries
; i
++)
1322 emit_move_insn (ivs
->entries
[i
].pseudo
, ivs
->entries
[i
].hard_reg
);
1326 emit_insn_at_entry (seq
);
1330 /* Return the hardreg-pseudoreg initial values pair entry I and
1331 TRUE if I is a valid entry, or FALSE if I is not a valid entry. */
1333 initial_value_entry (int i
, rtx
*hreg
, rtx
*preg
)
1335 struct initial_value_struct
*ivs
= crtl
->hard_reg_initial_vals
;
1336 if (!ivs
|| i
>= ivs
->num_entries
)
1339 *hreg
= ivs
->entries
[i
].hard_reg
;
1340 *preg
= ivs
->entries
[i
].pseudo
;
1344 /* These routines are responsible for converting virtual register references
1345 to the actual hard register references once RTL generation is complete.
1347 The following four variables are used for communication between the
1348 routines. They contain the offsets of the virtual registers from their
1349 respective hard registers. */
1351 static int in_arg_offset
;
1352 static int var_offset
;
1353 static int dynamic_offset
;
1354 static int out_arg_offset
;
1355 static int cfa_offset
;
1357 /* In most machines, the stack pointer register is equivalent to the bottom
1360 #ifndef STACK_POINTER_OFFSET
1361 #define STACK_POINTER_OFFSET 0
1364 #if defined (REG_PARM_STACK_SPACE) && !defined (INCOMING_REG_PARM_STACK_SPACE)
1365 #define INCOMING_REG_PARM_STACK_SPACE REG_PARM_STACK_SPACE
1368 /* If not defined, pick an appropriate default for the offset of dynamically
1369 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
1370 INCOMING_REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */
1372 #ifndef STACK_DYNAMIC_OFFSET
1374 /* The bottom of the stack points to the actual arguments. If
1375 REG_PARM_STACK_SPACE is defined, this includes the space for the register
1376 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined,
1377 stack space for register parameters is not pushed by the caller, but
1378 rather part of the fixed stack areas and hence not included in
1379 `crtl->outgoing_args_size'. Nevertheless, we must allow
1380 for it when allocating stack dynamic objects. */
1382 #ifdef INCOMING_REG_PARM_STACK_SPACE
1383 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1384 ((ACCUMULATE_OUTGOING_ARGS \
1385 ? (crtl->outgoing_args_size \
1386 + (OUTGOING_REG_PARM_STACK_SPACE ((!(FNDECL) ? NULL_TREE : TREE_TYPE (FNDECL))) ? 0 \
1387 : INCOMING_REG_PARM_STACK_SPACE (FNDECL))) \
1388 : 0) + (STACK_POINTER_OFFSET))
1390 #define STACK_DYNAMIC_OFFSET(FNDECL) \
1391 ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0) \
1392 + (STACK_POINTER_OFFSET))
1397 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX
1398 is a virtual register, return the equivalent hard register and set the
1399 offset indirectly through the pointer. Otherwise, return 0. */
1402 instantiate_new_reg (rtx x
, HOST_WIDE_INT
*poffset
)
1405 HOST_WIDE_INT offset
;
1407 if (x
== virtual_incoming_args_rtx
)
1409 if (stack_realign_drap
)
1411 /* Replace virtual_incoming_args_rtx with internal arg
1412 pointer if DRAP is used to realign stack. */
1413 new_rtx
= crtl
->args
.internal_arg_pointer
;
1417 new_rtx
= arg_pointer_rtx
, offset
= in_arg_offset
;
1419 else if (x
== virtual_stack_vars_rtx
)
1420 new_rtx
= frame_pointer_rtx
, offset
= var_offset
;
1421 else if (x
== virtual_stack_dynamic_rtx
)
1422 new_rtx
= stack_pointer_rtx
, offset
= dynamic_offset
;
1423 else if (x
== virtual_outgoing_args_rtx
)
1424 new_rtx
= stack_pointer_rtx
, offset
= out_arg_offset
;
1425 else if (x
== virtual_cfa_rtx
)
1427 #ifdef FRAME_POINTER_CFA_OFFSET
1428 new_rtx
= frame_pointer_rtx
;
1430 new_rtx
= arg_pointer_rtx
;
1432 offset
= cfa_offset
;
1434 else if (x
== virtual_preferred_stack_boundary_rtx
)
1436 new_rtx
= GEN_INT (crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
);
1446 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1447 registers present inside of *LOC. The expression is simplified,
1448 as much as possible, but is not to be considered "valid" in any sense
1449 implied by the target. Return true if any change is made. */
1452 instantiate_virtual_regs_in_rtx (rtx
*loc
)
1456 bool changed
= false;
1457 subrtx_ptr_iterator::array_type array
;
1458 FOR_EACH_SUBRTX_PTR (iter
, array
, loc
, NONCONST
)
1464 HOST_WIDE_INT offset
;
1465 switch (GET_CODE (x
))
1468 new_rtx
= instantiate_new_reg (x
, &offset
);
1471 *loc
= plus_constant (GET_MODE (x
), new_rtx
, offset
);
1474 iter
.skip_subrtxes ();
1478 new_rtx
= instantiate_new_reg (XEXP (x
, 0), &offset
);
1481 XEXP (x
, 0) = new_rtx
;
1482 *loc
= plus_constant (GET_MODE (x
), x
, offset
, true);
1484 iter
.skip_subrtxes ();
1488 /* FIXME -- from old code */
1489 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know
1490 we can commute the PLUS and SUBREG because pointers into the
1491 frame are well-behaved. */
1502 /* A subroutine of instantiate_virtual_regs_in_insn. Return true if X
1503 matches the predicate for insn CODE operand OPERAND. */
1506 safe_insn_predicate (int code
, int operand
, rtx x
)
1508 return code
< 0 || insn_operand_matches ((enum insn_code
) code
, operand
, x
);
1511 /* A subroutine of instantiate_virtual_regs. Instantiate any virtual
1512 registers present inside of insn. The result will be a valid insn. */
1515 instantiate_virtual_regs_in_insn (rtx_insn
*insn
)
1517 HOST_WIDE_INT offset
;
1519 bool any_change
= false;
1520 rtx set
, new_rtx
, x
;
1523 /* There are some special cases to be handled first. */
1524 set
= single_set (insn
);
1527 /* We're allowed to assign to a virtual register. This is interpreted
1528 to mean that the underlying register gets assigned the inverse
1529 transformation. This is used, for example, in the handling of
1531 new_rtx
= instantiate_new_reg (SET_DEST (set
), &offset
);
1536 instantiate_virtual_regs_in_rtx (&SET_SRC (set
));
1537 x
= simplify_gen_binary (PLUS
, GET_MODE (new_rtx
), SET_SRC (set
),
1538 gen_int_mode (-offset
, GET_MODE (new_rtx
)));
1539 x
= force_operand (x
, new_rtx
);
1541 emit_move_insn (new_rtx
, x
);
1546 emit_insn_before (seq
, insn
);
1551 /* Handle a straight copy from a virtual register by generating a
1552 new add insn. The difference between this and falling through
1553 to the generic case is avoiding a new pseudo and eliminating a
1554 move insn in the initial rtl stream. */
1555 new_rtx
= instantiate_new_reg (SET_SRC (set
), &offset
);
1556 if (new_rtx
&& offset
!= 0
1557 && REG_P (SET_DEST (set
))
1558 && REGNO (SET_DEST (set
)) > LAST_VIRTUAL_REGISTER
)
1562 x
= expand_simple_binop (GET_MODE (SET_DEST (set
)), PLUS
, new_rtx
,
1563 gen_int_mode (offset
,
1564 GET_MODE (SET_DEST (set
))),
1565 SET_DEST (set
), 1, OPTAB_LIB_WIDEN
);
1566 if (x
!= SET_DEST (set
))
1567 emit_move_insn (SET_DEST (set
), x
);
1572 emit_insn_before (seq
, insn
);
1577 extract_insn (insn
);
1578 insn_code
= INSN_CODE (insn
);
1580 /* Handle a plus involving a virtual register by determining if the
1581 operands remain valid if they're modified in place. */
1582 if (GET_CODE (SET_SRC (set
)) == PLUS
1583 && recog_data
.n_operands
>= 3
1584 && recog_data
.operand_loc
[1] == &XEXP (SET_SRC (set
), 0)
1585 && recog_data
.operand_loc
[2] == &XEXP (SET_SRC (set
), 1)
1586 && CONST_INT_P (recog_data
.operand
[2])
1587 && (new_rtx
= instantiate_new_reg (recog_data
.operand
[1], &offset
)))
1589 offset
+= INTVAL (recog_data
.operand
[2]);
1591 /* If the sum is zero, then replace with a plain move. */
1593 && REG_P (SET_DEST (set
))
1594 && REGNO (SET_DEST (set
)) > LAST_VIRTUAL_REGISTER
)
1597 emit_move_insn (SET_DEST (set
), new_rtx
);
1601 emit_insn_before (seq
, insn
);
1606 x
= gen_int_mode (offset
, recog_data
.operand_mode
[2]);
1608 /* Using validate_change and apply_change_group here leaves
1609 recog_data in an invalid state. Since we know exactly what
1610 we want to check, do those two by hand. */
1611 if (safe_insn_predicate (insn_code
, 1, new_rtx
)
1612 && safe_insn_predicate (insn_code
, 2, x
))
1614 *recog_data
.operand_loc
[1] = recog_data
.operand
[1] = new_rtx
;
1615 *recog_data
.operand_loc
[2] = recog_data
.operand
[2] = x
;
1618 /* Fall through into the regular operand fixup loop in
1619 order to take care of operands other than 1 and 2. */
1625 extract_insn (insn
);
1626 insn_code
= INSN_CODE (insn
);
1629 /* In the general case, we expect virtual registers to appear only in
1630 operands, and then only as either bare registers or inside memories. */
1631 for (i
= 0; i
< recog_data
.n_operands
; ++i
)
1633 x
= recog_data
.operand
[i
];
1634 switch (GET_CODE (x
))
1638 rtx addr
= XEXP (x
, 0);
1640 if (!instantiate_virtual_regs_in_rtx (&addr
))
1644 x
= replace_equiv_address (x
, addr
, true);
1645 /* It may happen that the address with the virtual reg
1646 was valid (e.g. based on the virtual stack reg, which might
1647 be acceptable to the predicates with all offsets), whereas
1648 the address now isn't anymore, for instance when the address
1649 is still offsetted, but the base reg isn't virtual-stack-reg
1650 anymore. Below we would do a force_reg on the whole operand,
1651 but this insn might actually only accept memory. Hence,
1652 before doing that last resort, try to reload the address into
1653 a register, so this operand stays a MEM. */
1654 if (!safe_insn_predicate (insn_code
, i
, x
))
1656 addr
= force_reg (GET_MODE (addr
), addr
);
1657 x
= replace_equiv_address (x
, addr
, true);
1662 emit_insn_before (seq
, insn
);
1667 new_rtx
= instantiate_new_reg (x
, &offset
);
1668 if (new_rtx
== NULL
)
1676 /* Careful, special mode predicates may have stuff in
1677 insn_data[insn_code].operand[i].mode that isn't useful
1678 to us for computing a new value. */
1679 /* ??? Recognize address_operand and/or "p" constraints
1680 to see if (plus new offset) is a valid before we put
1681 this through expand_simple_binop. */
1682 x
= expand_simple_binop (GET_MODE (x
), PLUS
, new_rtx
,
1683 gen_int_mode (offset
, GET_MODE (x
)),
1684 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1687 emit_insn_before (seq
, insn
);
1692 new_rtx
= instantiate_new_reg (SUBREG_REG (x
), &offset
);
1693 if (new_rtx
== NULL
)
1698 new_rtx
= expand_simple_binop
1699 (GET_MODE (new_rtx
), PLUS
, new_rtx
,
1700 gen_int_mode (offset
, GET_MODE (new_rtx
)),
1701 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1704 emit_insn_before (seq
, insn
);
1706 x
= simplify_gen_subreg (recog_data
.operand_mode
[i
], new_rtx
,
1707 GET_MODE (new_rtx
), SUBREG_BYTE (x
));
1715 /* At this point, X contains the new value for the operand.
1716 Validate the new value vs the insn predicate. Note that
1717 asm insns will have insn_code -1 here. */
1718 if (!safe_insn_predicate (insn_code
, i
, x
))
1723 gcc_assert (REGNO (x
) <= LAST_VIRTUAL_REGISTER
);
1724 x
= copy_to_reg (x
);
1727 x
= force_reg (insn_data
[insn_code
].operand
[i
].mode
, x
);
1731 emit_insn_before (seq
, insn
);
1734 *recog_data
.operand_loc
[i
] = recog_data
.operand
[i
] = x
;
1740 /* Propagate operand changes into the duplicates. */
1741 for (i
= 0; i
< recog_data
.n_dups
; ++i
)
1742 *recog_data
.dup_loc
[i
]
1743 = copy_rtx (recog_data
.operand
[(unsigned)recog_data
.dup_num
[i
]]);
1745 /* Force re-recognition of the instruction for validation. */
1746 INSN_CODE (insn
) = -1;
1749 if (asm_noperands (PATTERN (insn
)) >= 0)
1751 if (!check_asm_operands (PATTERN (insn
)))
1753 error_for_asm (insn
, "impossible constraint in %<asm%>");
1754 /* For asm goto, instead of fixing up all the edges
1755 just clear the template and clear input operands
1756 (asm goto doesn't have any output operands). */
1759 rtx asm_op
= extract_asm_operands (PATTERN (insn
));
1760 ASM_OPERANDS_TEMPLATE (asm_op
) = ggc_strdup ("");
1761 ASM_OPERANDS_INPUT_VEC (asm_op
) = rtvec_alloc (0);
1762 ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op
) = rtvec_alloc (0);
1770 if (recog_memoized (insn
) < 0)
1771 fatal_insn_not_found (insn
);
1775 /* Subroutine of instantiate_decls. Given RTL representing a decl,
1776 do any instantiation required. */
1779 instantiate_decl_rtl (rtx x
)
1786 /* If this is a CONCAT, recurse for the pieces. */
1787 if (GET_CODE (x
) == CONCAT
)
1789 instantiate_decl_rtl (XEXP (x
, 0));
1790 instantiate_decl_rtl (XEXP (x
, 1));
1794 /* If this is not a MEM, no need to do anything. Similarly if the
1795 address is a constant or a register that is not a virtual register. */
1800 if (CONSTANT_P (addr
)
1802 && (REGNO (addr
) < FIRST_VIRTUAL_REGISTER
1803 || REGNO (addr
) > LAST_VIRTUAL_REGISTER
)))
1806 instantiate_virtual_regs_in_rtx (&XEXP (x
, 0));
1809 /* Helper for instantiate_decls called via walk_tree: Process all decls
1810 in the given DECL_VALUE_EXPR. */
1813 instantiate_expr (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
1821 if (DECL_RTL_SET_P (t
))
1822 instantiate_decl_rtl (DECL_RTL (t
));
1823 if (TREE_CODE (t
) == PARM_DECL
&& DECL_NAMELESS (t
)
1824 && DECL_INCOMING_RTL (t
))
1825 instantiate_decl_rtl (DECL_INCOMING_RTL (t
));
1826 if ((TREE_CODE (t
) == VAR_DECL
1827 || TREE_CODE (t
) == RESULT_DECL
)
1828 && DECL_HAS_VALUE_EXPR_P (t
))
1830 tree v
= DECL_VALUE_EXPR (t
);
1831 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1838 /* Subroutine of instantiate_decls: Process all decls in the given
1839 BLOCK node and all its subblocks. */
1842 instantiate_decls_1 (tree let
)
1846 for (t
= BLOCK_VARS (let
); t
; t
= DECL_CHAIN (t
))
1848 if (DECL_RTL_SET_P (t
))
1849 instantiate_decl_rtl (DECL_RTL (t
));
1850 if (TREE_CODE (t
) == VAR_DECL
&& DECL_HAS_VALUE_EXPR_P (t
))
1852 tree v
= DECL_VALUE_EXPR (t
);
1853 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1857 /* Process all subblocks. */
1858 for (t
= BLOCK_SUBBLOCKS (let
); t
; t
= BLOCK_CHAIN (t
))
1859 instantiate_decls_1 (t
);
1862 /* Scan all decls in FNDECL (both variables and parameters) and instantiate
1863 all virtual registers in their DECL_RTL's. */
1866 instantiate_decls (tree fndecl
)
1871 /* Process all parameters of the function. */
1872 for (decl
= DECL_ARGUMENTS (fndecl
); decl
; decl
= DECL_CHAIN (decl
))
1874 instantiate_decl_rtl (DECL_RTL (decl
));
1875 instantiate_decl_rtl (DECL_INCOMING_RTL (decl
));
1876 if (DECL_HAS_VALUE_EXPR_P (decl
))
1878 tree v
= DECL_VALUE_EXPR (decl
);
1879 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1883 if ((decl
= DECL_RESULT (fndecl
))
1884 && TREE_CODE (decl
) == RESULT_DECL
)
1886 if (DECL_RTL_SET_P (decl
))
1887 instantiate_decl_rtl (DECL_RTL (decl
));
1888 if (DECL_HAS_VALUE_EXPR_P (decl
))
1890 tree v
= DECL_VALUE_EXPR (decl
);
1891 walk_tree (&v
, instantiate_expr
, NULL
, NULL
);
1895 /* Process the saved static chain if it exists. */
1896 decl
= DECL_STRUCT_FUNCTION (fndecl
)->static_chain_decl
;
1897 if (decl
&& DECL_HAS_VALUE_EXPR_P (decl
))
1898 instantiate_decl_rtl (DECL_RTL (DECL_VALUE_EXPR (decl
)));
1900 /* Now process all variables defined in the function or its subblocks. */
1901 instantiate_decls_1 (DECL_INITIAL (fndecl
));
1903 FOR_EACH_LOCAL_DECL (cfun
, ix
, decl
)
1904 if (DECL_RTL_SET_P (decl
))
1905 instantiate_decl_rtl (DECL_RTL (decl
));
1906 vec_free (cfun
->local_decls
);
1909 /* Pass through the INSNS of function FNDECL and convert virtual register
1910 references to hard register references. */
1913 instantiate_virtual_regs (void)
1917 /* Compute the offsets to use for this function. */
1918 in_arg_offset
= FIRST_PARM_OFFSET (current_function_decl
);
1919 var_offset
= STARTING_FRAME_OFFSET
;
1920 dynamic_offset
= STACK_DYNAMIC_OFFSET (current_function_decl
);
1921 out_arg_offset
= STACK_POINTER_OFFSET
;
1922 #ifdef FRAME_POINTER_CFA_OFFSET
1923 cfa_offset
= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
1925 cfa_offset
= ARG_POINTER_CFA_OFFSET (current_function_decl
);
1928 /* Initialize recognition, indicating that volatile is OK. */
1931 /* Scan through all the insns, instantiating every virtual register still
1933 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
1936 /* These patterns in the instruction stream can never be recognized.
1937 Fortunately, they shouldn't contain virtual registers either. */
1938 if (GET_CODE (PATTERN (insn
)) == USE
1939 || GET_CODE (PATTERN (insn
)) == CLOBBER
1940 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
)
1942 else if (DEBUG_INSN_P (insn
))
1943 instantiate_virtual_regs_in_rtx (&INSN_VAR_LOCATION (insn
));
1945 instantiate_virtual_regs_in_insn (insn
);
1947 if (insn
->deleted ())
1950 instantiate_virtual_regs_in_rtx (®_NOTES (insn
));
1952 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */
1954 instantiate_virtual_regs_in_rtx (&CALL_INSN_FUNCTION_USAGE (insn
));
1957 /* Instantiate the virtual registers in the DECLs for debugging purposes. */
1958 instantiate_decls (current_function_decl
);
1960 targetm
.instantiate_decls ();
1962 /* Indicate that, from now on, assign_stack_local should use
1963 frame_pointer_rtx. */
1964 virtuals_instantiated
= 1;
1971 const pass_data pass_data_instantiate_virtual_regs
=
1973 RTL_PASS
, /* type */
1975 OPTGROUP_NONE
, /* optinfo_flags */
1976 TV_NONE
, /* tv_id */
1977 0, /* properties_required */
1978 0, /* properties_provided */
1979 0, /* properties_destroyed */
1980 0, /* todo_flags_start */
1981 0, /* todo_flags_finish */
1984 class pass_instantiate_virtual_regs
: public rtl_opt_pass
1987 pass_instantiate_virtual_regs (gcc::context
*ctxt
)
1988 : rtl_opt_pass (pass_data_instantiate_virtual_regs
, ctxt
)
1991 /* opt_pass methods: */
1992 virtual unsigned int execute (function
*)
1994 return instantiate_virtual_regs ();
1997 }; // class pass_instantiate_virtual_regs
2002 make_pass_instantiate_virtual_regs (gcc::context
*ctxt
)
2004 return new pass_instantiate_virtual_regs (ctxt
);
2008 /* Return 1 if EXP is an aggregate type (or a value with aggregate type).
2009 This means a type for which function calls must pass an address to the
2010 function or get an address back from the function.
2011 EXP may be a type node or an expression (whose type is tested). */
2014 aggregate_value_p (const_tree exp
, const_tree fntype
)
2016 const_tree type
= (TYPE_P (exp
)) ? exp
: TREE_TYPE (exp
);
2017 int i
, regno
, nregs
;
2021 switch (TREE_CODE (fntype
))
2025 tree fndecl
= get_callee_fndecl (fntype
);
2027 fntype
= TREE_TYPE (fndecl
);
2028 else if (CALL_EXPR_FN (fntype
))
2029 fntype
= TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (fntype
)));
2031 /* For internal functions, assume nothing needs to be
2032 returned in memory. */
2037 fntype
= TREE_TYPE (fntype
);
2042 case IDENTIFIER_NODE
:
2046 /* We don't expect other tree types here. */
2050 if (VOID_TYPE_P (type
))
2053 /* If a record should be passed the same as its first (and only) member
2054 don't pass it as an aggregate. */
2055 if (TREE_CODE (type
) == RECORD_TYPE
&& TYPE_TRANSPARENT_AGGR (type
))
2056 return aggregate_value_p (first_field (type
), fntype
);
2058 /* If the front end has decided that this needs to be passed by
2059 reference, do so. */
2060 if ((TREE_CODE (exp
) == PARM_DECL
|| TREE_CODE (exp
) == RESULT_DECL
)
2061 && DECL_BY_REFERENCE (exp
))
2064 /* Function types that are TREE_ADDRESSABLE force return in memory. */
2065 if (fntype
&& TREE_ADDRESSABLE (fntype
))
2068 /* Types that are TREE_ADDRESSABLE must be constructed in memory,
2069 and thus can't be returned in registers. */
2070 if (TREE_ADDRESSABLE (type
))
2073 if (flag_pcc_struct_return
&& AGGREGATE_TYPE_P (type
))
2076 if (targetm
.calls
.return_in_memory (type
, fntype
))
2079 /* Make sure we have suitable call-clobbered regs to return
2080 the value in; if not, we must return it in memory. */
2081 reg
= hard_function_value (type
, 0, fntype
, 0);
2083 /* If we have something other than a REG (e.g. a PARALLEL), then assume
2088 regno
= REGNO (reg
);
2089 nregs
= hard_regno_nregs
[regno
][TYPE_MODE (type
)];
2090 for (i
= 0; i
< nregs
; i
++)
2091 if (! call_used_regs
[regno
+ i
])
2097 /* Return true if we should assign DECL a pseudo register; false if it
2098 should live on the local stack. */
2101 use_register_for_decl (const_tree decl
)
2103 if (TREE_CODE (decl
) == SSA_NAME
)
2105 /* We often try to use the SSA_NAME, instead of its underlying
2106 decl, to get type information and guide decisions, to avoid
2107 differences of behavior between anonymous and named
2108 variables, but in this one case we have to go for the actual
2109 variable if there is one. The main reason is that, at least
2110 at -O0, we want to place user variables on the stack, but we
2111 don't mind using pseudos for anonymous or ignored temps.
2112 Should we take the SSA_NAME, we'd conclude all SSA_NAMEs
2113 should go in pseudos, whereas their corresponding variables
2114 might have to go on the stack. So, disregarding the decl
2115 here would negatively impact debug info at -O0, enable
2116 coalescing between SSA_NAMEs that ought to get different
2117 stack/pseudo assignments, and get the incoming argument
2118 processing thoroughly confused by PARM_DECLs expected to live
2119 in stack slots but assigned to pseudos. */
2120 if (!SSA_NAME_VAR (decl
))
2121 return TYPE_MODE (TREE_TYPE (decl
)) != BLKmode
2122 && !(flag_float_store
&& FLOAT_TYPE_P (TREE_TYPE (decl
)));
2124 decl
= SSA_NAME_VAR (decl
);
2127 /* Honor volatile. */
2128 if (TREE_SIDE_EFFECTS (decl
))
2131 /* Honor addressability. */
2132 if (TREE_ADDRESSABLE (decl
))
2135 /* RESULT_DECLs are a bit special in that they're assigned without
2136 regard to use_register_for_decl, but we generally only store in
2137 them. If we coalesce their SSA NAMEs, we'd better return a
2138 result that matches the assignment in expand_function_start. */
2139 if (TREE_CODE (decl
) == RESULT_DECL
)
2141 /* If it's not an aggregate, we're going to use a REG or a
2142 PARALLEL containing a REG. */
2143 if (!aggregate_value_p (decl
, current_function_decl
))
2146 /* If expand_function_start determines the return value, we'll
2147 use MEM if it's not by reference. */
2148 if (cfun
->returns_pcc_struct
2149 || (targetm
.calls
.struct_value_rtx
2150 (TREE_TYPE (current_function_decl
), 1)))
2151 return DECL_BY_REFERENCE (decl
);
2153 /* Otherwise, we're taking an extra all.function_result_decl
2154 argument. It's set up in assign_parms_augmented_arg_list,
2155 under the (negated) conditions above, and then it's used to
2156 set up the RESULT_DECL rtl in assign_params, after looping
2157 over all parameters. Now, if the RESULT_DECL is not by
2158 reference, we'll use a MEM either way. */
2159 if (!DECL_BY_REFERENCE (decl
))
2162 /* Otherwise, if RESULT_DECL is DECL_BY_REFERENCE, it will take
2163 the function_result_decl's assignment. Since it's a pointer,
2164 we can short-circuit a number of the tests below, and we must
2165 duplicat e them because we don't have the
2166 function_result_decl to test. */
2167 if (!targetm
.calls
.allocate_stack_slots_for_args ())
2169 /* We don't set DECL_IGNORED_P for the function_result_decl. */
2172 /* We don't set DECL_REGISTER for the function_result_decl. */
2176 /* Decl is implicitly addressible by bound stores and loads
2177 if it is an aggregate holding bounds. */
2178 if (chkp_function_instrumented_p (current_function_decl
)
2180 && !BOUNDED_P (decl
)
2181 && chkp_type_has_pointer (TREE_TYPE (decl
)))
2184 /* Only register-like things go in registers. */
2185 if (DECL_MODE (decl
) == BLKmode
)
2188 /* If -ffloat-store specified, don't put explicit float variables
2190 /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa
2191 propagates values across these stores, and it probably shouldn't. */
2192 if (flag_float_store
&& FLOAT_TYPE_P (TREE_TYPE (decl
)))
2195 if (!targetm
.calls
.allocate_stack_slots_for_args ())
2198 /* If we're not interested in tracking debugging information for
2199 this decl, then we can certainly put it in a register. */
2200 if (DECL_IGNORED_P (decl
))
2206 if (!DECL_REGISTER (decl
))
2209 switch (TREE_CODE (TREE_TYPE (decl
)))
2213 case QUAL_UNION_TYPE
:
2214 /* When not optimizing, disregard register keyword for variables with
2215 types containing methods, otherwise the methods won't be callable
2216 from the debugger. */
2217 if (TYPE_METHODS (TYPE_MAIN_VARIANT (TREE_TYPE (decl
))))
2227 /* Structures to communicate between the subroutines of assign_parms.
2228 The first holds data persistent across all parameters, the second
2229 is cleared out for each parameter. */
2231 struct assign_parm_data_all
2233 /* When INIT_CUMULATIVE_ARGS gets revamped, allocating CUMULATIVE_ARGS
2234 should become a job of the target or otherwise encapsulated. */
2235 CUMULATIVE_ARGS args_so_far_v
;
2236 cumulative_args_t args_so_far
;
2237 struct args_size stack_args_size
;
2238 tree function_result_decl
;
2240 rtx_insn
*first_conversion_insn
;
2241 rtx_insn
*last_conversion_insn
;
2242 HOST_WIDE_INT pretend_args_size
;
2243 HOST_WIDE_INT extra_pretend_bytes
;
2244 int reg_parm_stack_space
;
2247 struct assign_parm_data_one
2253 machine_mode nominal_mode
;
2254 machine_mode passed_mode
;
2255 machine_mode promoted_mode
;
2256 struct locate_and_pad_arg_data locate
;
2258 BOOL_BITFIELD named_arg
: 1;
2259 BOOL_BITFIELD passed_pointer
: 1;
2260 BOOL_BITFIELD on_stack
: 1;
2261 BOOL_BITFIELD loaded_in_reg
: 1;
2264 struct bounds_parm_data
2266 assign_parm_data_one parm_data
;
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 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
;
2388 /* If function is instrumented then bounds of the
2389 passed structure address is the second argument. */
2390 if (chkp_function_instrumented_p (fndecl
))
2392 decl
= build_decl (DECL_SOURCE_LOCATION (fndecl
),
2393 PARM_DECL
, get_identifier (".result_bnd"),
2394 pointer_bounds_type_node
);
2395 DECL_ARG_TYPE (decl
) = pointer_bounds_type_node
;
2396 DECL_ARTIFICIAL (decl
) = 1;
2397 DECL_NAMELESS (decl
) = 1;
2398 TREE_CONSTANT (decl
) = 1;
2400 DECL_CHAIN (decl
) = DECL_CHAIN (all
->orig_fnargs
);
2401 DECL_CHAIN (all
->orig_fnargs
) = decl
;
2402 fnargs
.safe_insert (1, decl
);
2406 /* If the target wants to split complex arguments into scalars, do so. */
2407 if (targetm
.calls
.split_complex_arg
)
2408 split_complex_args (&fnargs
);
2413 /* A subroutine of assign_parms. Examine PARM and pull out type and mode
2414 data for the parameter. Incorporate ABI specifics such as pass-by-
2415 reference and type promotion. */
2418 assign_parm_find_data_types (struct assign_parm_data_all
*all
, tree parm
,
2419 struct assign_parm_data_one
*data
)
2421 tree nominal_type
, passed_type
;
2422 machine_mode nominal_mode
, passed_mode
, promoted_mode
;
2425 memset (data
, 0, sizeof (*data
));
2427 /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */
2429 data
->named_arg
= 1; /* No variadic parms. */
2430 else if (DECL_CHAIN (parm
))
2431 data
->named_arg
= 1; /* Not the last non-variadic parm. */
2432 else if (targetm
.calls
.strict_argument_naming (all
->args_so_far
))
2433 data
->named_arg
= 1; /* Only variadic ones are unnamed. */
2435 data
->named_arg
= 0; /* Treat as variadic. */
2437 nominal_type
= TREE_TYPE (parm
);
2438 passed_type
= DECL_ARG_TYPE (parm
);
2440 /* Look out for errors propagating this far. Also, if the parameter's
2441 type is void then its value doesn't matter. */
2442 if (TREE_TYPE (parm
) == error_mark_node
2443 /* This can happen after weird syntax errors
2444 or if an enum type is defined among the parms. */
2445 || TREE_CODE (parm
) != PARM_DECL
2446 || passed_type
== NULL
2447 || VOID_TYPE_P (nominal_type
))
2449 nominal_type
= passed_type
= void_type_node
;
2450 nominal_mode
= passed_mode
= promoted_mode
= VOIDmode
;
2454 /* Find mode of arg as it is passed, and mode of arg as it should be
2455 during execution of this function. */
2456 passed_mode
= TYPE_MODE (passed_type
);
2457 nominal_mode
= TYPE_MODE (nominal_type
);
2459 /* If the parm is to be passed as a transparent union or record, use the
2460 type of the first field for the tests below. We have already verified
2461 that the modes are the same. */
2462 if ((TREE_CODE (passed_type
) == UNION_TYPE
2463 || TREE_CODE (passed_type
) == RECORD_TYPE
)
2464 && TYPE_TRANSPARENT_AGGR (passed_type
))
2465 passed_type
= TREE_TYPE (first_field (passed_type
));
2467 /* See if this arg was passed by invisible reference. */
2468 if (pass_by_reference (&all
->args_so_far_v
, passed_mode
,
2469 passed_type
, data
->named_arg
))
2471 passed_type
= nominal_type
= build_pointer_type (passed_type
);
2472 data
->passed_pointer
= true;
2473 passed_mode
= nominal_mode
= TYPE_MODE (nominal_type
);
2476 /* Find mode as it is passed by the ABI. */
2477 unsignedp
= TYPE_UNSIGNED (passed_type
);
2478 promoted_mode
= promote_function_mode (passed_type
, passed_mode
, &unsignedp
,
2479 TREE_TYPE (current_function_decl
), 0);
2482 data
->nominal_type
= nominal_type
;
2483 data
->passed_type
= passed_type
;
2484 data
->nominal_mode
= nominal_mode
;
2485 data
->passed_mode
= passed_mode
;
2486 data
->promoted_mode
= promoted_mode
;
2489 /* A subroutine of assign_parms. Invoke setup_incoming_varargs. */
2492 assign_parms_setup_varargs (struct assign_parm_data_all
*all
,
2493 struct assign_parm_data_one
*data
, bool no_rtl
)
2495 int varargs_pretend_bytes
= 0;
2497 targetm
.calls
.setup_incoming_varargs (all
->args_so_far
,
2498 data
->promoted_mode
,
2500 &varargs_pretend_bytes
, no_rtl
);
2502 /* If the back-end has requested extra stack space, record how much is
2503 needed. Do not change pretend_args_size otherwise since it may be
2504 nonzero from an earlier partial argument. */
2505 if (varargs_pretend_bytes
> 0)
2506 all
->pretend_args_size
= varargs_pretend_bytes
;
2509 /* A subroutine of assign_parms. Set DATA->ENTRY_PARM corresponding to
2510 the incoming location of the current parameter. */
2513 assign_parm_find_entry_rtl (struct assign_parm_data_all
*all
,
2514 struct assign_parm_data_one
*data
)
2516 HOST_WIDE_INT pretend_bytes
= 0;
2520 if (data
->promoted_mode
== VOIDmode
)
2522 data
->entry_parm
= data
->stack_parm
= const0_rtx
;
2526 entry_parm
= targetm
.calls
.function_incoming_arg (all
->args_so_far
,
2527 data
->promoted_mode
,
2531 if (entry_parm
== 0)
2532 data
->promoted_mode
= data
->passed_mode
;
2534 /* Determine parm's home in the stack, in case it arrives in the stack
2535 or we should pretend it did. Compute the stack position and rtx where
2536 the argument arrives and its size.
2538 There is one complexity here: If this was a parameter that would
2539 have been passed in registers, but wasn't only because it is
2540 __builtin_va_alist, we want locate_and_pad_parm to treat it as if
2541 it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
2542 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0
2543 as it was the previous time. */
2544 in_regs
= (entry_parm
!= 0) || POINTER_BOUNDS_TYPE_P (data
->passed_type
);
2545 #ifdef STACK_PARMS_IN_REG_PARM_AREA
2548 if (!in_regs
&& !data
->named_arg
)
2550 if (targetm
.calls
.pretend_outgoing_varargs_named (all
->args_so_far
))
2553 tem
= targetm
.calls
.function_incoming_arg (all
->args_so_far
,
2554 data
->promoted_mode
,
2555 data
->passed_type
, true);
2556 in_regs
= tem
!= NULL
;
2560 /* If this parameter was passed both in registers and in the stack, use
2561 the copy on the stack. */
2562 if (targetm
.calls
.must_pass_in_stack (data
->promoted_mode
,
2570 partial
= targetm
.calls
.arg_partial_bytes (all
->args_so_far
,
2571 data
->promoted_mode
,
2574 data
->partial
= partial
;
2576 /* The caller might already have allocated stack space for the
2577 register parameters. */
2578 if (partial
!= 0 && all
->reg_parm_stack_space
== 0)
2580 /* Part of this argument is passed in registers and part
2581 is passed on the stack. Ask the prologue code to extend
2582 the stack part so that we can recreate the full value.
2584 PRETEND_BYTES is the size of the registers we need to store.
2585 CURRENT_FUNCTION_PRETEND_ARGS_SIZE is the amount of extra
2586 stack space that the prologue should allocate.
2588 Internally, gcc assumes that the argument pointer is aligned
2589 to STACK_BOUNDARY bits. This is used both for alignment
2590 optimizations (see init_emit) and to locate arguments that are
2591 aligned to more than PARM_BOUNDARY bits. We must preserve this
2592 invariant by rounding CURRENT_FUNCTION_PRETEND_ARGS_SIZE up to
2593 a stack boundary. */
2595 /* We assume at most one partial arg, and it must be the first
2596 argument on the stack. */
2597 gcc_assert (!all
->extra_pretend_bytes
&& !all
->pretend_args_size
);
2599 pretend_bytes
= partial
;
2600 all
->pretend_args_size
= CEIL_ROUND (pretend_bytes
, STACK_BYTES
);
2602 /* We want to align relative to the actual stack pointer, so
2603 don't include this in the stack size until later. */
2604 all
->extra_pretend_bytes
= all
->pretend_args_size
;
2608 locate_and_pad_parm (data
->promoted_mode
, data
->passed_type
, in_regs
,
2609 all
->reg_parm_stack_space
,
2610 entry_parm
? data
->partial
: 0, current_function_decl
,
2611 &all
->stack_args_size
, &data
->locate
);
2613 /* Update parm_stack_boundary if this parameter is passed in the
2615 if (!in_regs
&& crtl
->parm_stack_boundary
< data
->locate
.boundary
)
2616 crtl
->parm_stack_boundary
= data
->locate
.boundary
;
2618 /* Adjust offsets to include the pretend args. */
2619 pretend_bytes
= all
->extra_pretend_bytes
- pretend_bytes
;
2620 data
->locate
.slot_offset
.constant
+= pretend_bytes
;
2621 data
->locate
.offset
.constant
+= pretend_bytes
;
2623 data
->entry_parm
= entry_parm
;
2626 /* A subroutine of assign_parms. If there is actually space on the stack
2627 for this parm, count it in stack_args_size and return true. */
2630 assign_parm_is_stack_parm (struct assign_parm_data_all
*all
,
2631 struct assign_parm_data_one
*data
)
2633 /* Bounds are never passed on the stack to keep compatibility
2634 with not instrumented code. */
2635 if (POINTER_BOUNDS_TYPE_P (data
->passed_type
))
2637 /* Trivially true if we've no incoming register. */
2638 else if (data
->entry_parm
== NULL
)
2640 /* Also true if we're partially in registers and partially not,
2641 since we've arranged to drop the entire argument on the stack. */
2642 else if (data
->partial
!= 0)
2644 /* Also true if the target says that it's passed in both registers
2645 and on the stack. */
2646 else if (GET_CODE (data
->entry_parm
) == PARALLEL
2647 && XEXP (XVECEXP (data
->entry_parm
, 0, 0), 0) == NULL_RTX
)
2649 /* Also true if the target says that there's stack allocated for
2650 all register parameters. */
2651 else if (all
->reg_parm_stack_space
> 0)
2653 /* Otherwise, no, this parameter has no ABI defined stack slot. */
2657 all
->stack_args_size
.constant
+= data
->locate
.size
.constant
;
2658 if (data
->locate
.size
.var
)
2659 ADD_PARM_SIZE (all
->stack_args_size
, data
->locate
.size
.var
);
2664 /* A subroutine of assign_parms. Given that this parameter is allocated
2665 stack space by the ABI, find it. */
2668 assign_parm_find_stack_rtl (tree parm
, struct assign_parm_data_one
*data
)
2670 rtx offset_rtx
, stack_parm
;
2671 unsigned int align
, boundary
;
2673 /* If we're passing this arg using a reg, make its stack home the
2674 aligned stack slot. */
2675 if (data
->entry_parm
)
2676 offset_rtx
= ARGS_SIZE_RTX (data
->locate
.slot_offset
);
2678 offset_rtx
= ARGS_SIZE_RTX (data
->locate
.offset
);
2680 stack_parm
= crtl
->args
.internal_arg_pointer
;
2681 if (offset_rtx
!= const0_rtx
)
2682 stack_parm
= gen_rtx_PLUS (Pmode
, stack_parm
, offset_rtx
);
2683 stack_parm
= gen_rtx_MEM (data
->promoted_mode
, stack_parm
);
2685 if (!data
->passed_pointer
)
2687 set_mem_attributes (stack_parm
, parm
, 1);
2688 /* set_mem_attributes could set MEM_SIZE to the passed mode's size,
2689 while promoted mode's size is needed. */
2690 if (data
->promoted_mode
!= BLKmode
2691 && data
->promoted_mode
!= DECL_MODE (parm
))
2693 set_mem_size (stack_parm
, GET_MODE_SIZE (data
->promoted_mode
));
2694 if (MEM_EXPR (stack_parm
) && MEM_OFFSET_KNOWN_P (stack_parm
))
2696 int offset
= subreg_lowpart_offset (DECL_MODE (parm
),
2697 data
->promoted_mode
);
2699 set_mem_offset (stack_parm
, MEM_OFFSET (stack_parm
) - offset
);
2704 boundary
= data
->locate
.boundary
;
2705 align
= BITS_PER_UNIT
;
2707 /* If we're padding upward, we know that the alignment of the slot
2708 is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're
2709 intentionally forcing upward padding. Otherwise we have to come
2710 up with a guess at the alignment based on OFFSET_RTX. */
2711 if (data
->locate
.where_pad
!= downward
|| data
->entry_parm
)
2713 else if (CONST_INT_P (offset_rtx
))
2715 align
= INTVAL (offset_rtx
) * BITS_PER_UNIT
| boundary
;
2716 align
= align
& -align
;
2718 set_mem_align (stack_parm
, align
);
2720 if (data
->entry_parm
)
2721 set_reg_attrs_for_parm (data
->entry_parm
, stack_parm
);
2723 data
->stack_parm
= stack_parm
;
2726 /* A subroutine of assign_parms. Adjust DATA->ENTRY_RTL such that it's
2727 always valid and contiguous. */
2730 assign_parm_adjust_entry_rtl (struct assign_parm_data_one
*data
)
2732 rtx entry_parm
= data
->entry_parm
;
2733 rtx stack_parm
= data
->stack_parm
;
2735 /* If this parm was passed part in regs and part in memory, pretend it
2736 arrived entirely in memory by pushing the register-part onto the stack.
2737 In the special case of a DImode or DFmode that is split, we could put
2738 it together in a pseudoreg directly, but for now that's not worth
2740 if (data
->partial
!= 0)
2742 /* Handle calls that pass values in multiple non-contiguous
2743 locations. The Irix 6 ABI has examples of this. */
2744 if (GET_CODE (entry_parm
) == PARALLEL
)
2745 emit_group_store (validize_mem (copy_rtx (stack_parm
)), entry_parm
,
2747 int_size_in_bytes (data
->passed_type
));
2750 gcc_assert (data
->partial
% UNITS_PER_WORD
== 0);
2751 move_block_from_reg (REGNO (entry_parm
),
2752 validize_mem (copy_rtx (stack_parm
)),
2753 data
->partial
/ UNITS_PER_WORD
);
2756 entry_parm
= stack_parm
;
2759 /* If we didn't decide this parm came in a register, by default it came
2761 else if (entry_parm
== NULL
)
2762 entry_parm
= stack_parm
;
2764 /* When an argument is passed in multiple locations, we can't make use
2765 of this information, but we can save some copying if the whole argument
2766 is passed in a single register. */
2767 else if (GET_CODE (entry_parm
) == PARALLEL
2768 && data
->nominal_mode
!= BLKmode
2769 && data
->passed_mode
!= BLKmode
)
2771 size_t i
, len
= XVECLEN (entry_parm
, 0);
2773 for (i
= 0; i
< len
; i
++)
2774 if (XEXP (XVECEXP (entry_parm
, 0, i
), 0) != NULL_RTX
2775 && REG_P (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
2776 && (GET_MODE (XEXP (XVECEXP (entry_parm
, 0, i
), 0))
2777 == data
->passed_mode
)
2778 && INTVAL (XEXP (XVECEXP (entry_parm
, 0, i
), 1)) == 0)
2780 entry_parm
= XEXP (XVECEXP (entry_parm
, 0, i
), 0);
2785 data
->entry_parm
= entry_parm
;
2788 /* A subroutine of assign_parms. Reconstitute any values which were
2789 passed in multiple registers and would fit in a single register. */
2792 assign_parm_remove_parallels (struct assign_parm_data_one
*data
)
2794 rtx entry_parm
= data
->entry_parm
;
2796 /* Convert the PARALLEL to a REG of the same mode as the parallel.
2797 This can be done with register operations rather than on the
2798 stack, even if we will store the reconstituted parameter on the
2800 if (GET_CODE (entry_parm
) == PARALLEL
&& GET_MODE (entry_parm
) != BLKmode
)
2802 rtx parmreg
= gen_reg_rtx (GET_MODE (entry_parm
));
2803 emit_group_store (parmreg
, entry_parm
, data
->passed_type
,
2804 GET_MODE_SIZE (GET_MODE (entry_parm
)));
2805 entry_parm
= parmreg
;
2808 data
->entry_parm
= entry_parm
;
2811 /* A subroutine of assign_parms. Adjust DATA->STACK_RTL such that it's
2812 always valid and properly aligned. */
2815 assign_parm_adjust_stack_rtl (struct assign_parm_data_one
*data
)
2817 rtx stack_parm
= data
->stack_parm
;
2819 /* If we can't trust the parm stack slot to be aligned enough for its
2820 ultimate type, don't use that slot after entry. We'll make another
2821 stack slot, if we need one. */
2823 && ((STRICT_ALIGNMENT
2824 && GET_MODE_ALIGNMENT (data
->nominal_mode
) > MEM_ALIGN (stack_parm
))
2825 || (data
->nominal_type
2826 && TYPE_ALIGN (data
->nominal_type
) > MEM_ALIGN (stack_parm
)
2827 && MEM_ALIGN (stack_parm
) < PREFERRED_STACK_BOUNDARY
)))
2830 /* If parm was passed in memory, and we need to convert it on entry,
2831 don't store it back in that same slot. */
2832 else if (data
->entry_parm
== stack_parm
2833 && data
->nominal_mode
!= BLKmode
2834 && data
->nominal_mode
!= data
->passed_mode
)
2837 /* If stack protection is in effect for this function, don't leave any
2838 pointers in their passed stack slots. */
2839 else if (crtl
->stack_protect_guard
2840 && (flag_stack_protect
== 2
2841 || data
->passed_pointer
2842 || POINTER_TYPE_P (data
->nominal_type
)))
2845 data
->stack_parm
= stack_parm
;
2848 /* A subroutine of assign_parms. Return true if the current parameter
2849 should be stored as a BLKmode in the current frame. */
2852 assign_parm_setup_block_p (struct assign_parm_data_one
*data
)
2854 if (data
->nominal_mode
== BLKmode
)
2856 if (GET_MODE (data
->entry_parm
) == BLKmode
)
2859 #ifdef BLOCK_REG_PADDING
2860 /* Only assign_parm_setup_block knows how to deal with register arguments
2861 that are padded at the least significant end. */
2862 if (REG_P (data
->entry_parm
)
2863 && GET_MODE_SIZE (data
->promoted_mode
) < UNITS_PER_WORD
2864 && (BLOCK_REG_PADDING (data
->passed_mode
, data
->passed_type
, 1)
2865 == (BYTES_BIG_ENDIAN
? upward
: downward
)))
2872 /* A subroutine of assign_parms. Arrange for the parameter to be
2873 present and valid in DATA->STACK_RTL. */
2876 assign_parm_setup_block (struct assign_parm_data_all
*all
,
2877 tree parm
, struct assign_parm_data_one
*data
)
2879 rtx entry_parm
= data
->entry_parm
;
2880 rtx stack_parm
= data
->stack_parm
;
2881 rtx target_reg
= NULL_RTX
;
2882 bool in_conversion_seq
= false;
2884 HOST_WIDE_INT size_stored
;
2886 if (GET_CODE (entry_parm
) == PARALLEL
)
2887 entry_parm
= emit_group_move_into_temps (entry_parm
);
2889 /* If we want the parameter in a pseudo, don't use a stack slot. */
2890 if (is_gimple_reg (parm
) && use_register_for_decl (parm
))
2892 tree def
= ssa_default_def (cfun
, parm
);
2894 machine_mode mode
= promote_ssa_mode (def
, NULL
);
2895 rtx reg
= gen_reg_rtx (mode
);
2896 if (GET_CODE (reg
) != CONCAT
)
2901 /* Avoid allocating a stack slot, if there isn't one
2902 preallocated by the ABI. It might seem like we should
2903 always prefer a pseudo, but converting between
2904 floating-point and integer modes goes through the stack
2905 on various machines, so it's better to use the reserved
2906 stack slot than to risk wasting it and allocating more
2907 for the conversion. */
2908 if (stack_parm
== NULL_RTX
)
2910 int save
= generating_concat_p
;
2911 generating_concat_p
= 0;
2912 stack_parm
= gen_reg_rtx (mode
);
2913 generating_concat_p
= save
;
2916 data
->stack_parm
= NULL
;
2919 size
= int_size_in_bytes (data
->passed_type
);
2920 size_stored
= CEIL_ROUND (size
, UNITS_PER_WORD
);
2921 if (stack_parm
== 0)
2923 DECL_ALIGN (parm
) = MAX (DECL_ALIGN (parm
), BITS_PER_WORD
);
2924 stack_parm
= assign_stack_local (BLKmode
, size_stored
,
2926 if (GET_MODE_SIZE (GET_MODE (entry_parm
)) == size
)
2927 PUT_MODE (stack_parm
, GET_MODE (entry_parm
));
2928 set_mem_attributes (stack_parm
, parm
, 1);
2931 /* If a BLKmode arrives in registers, copy it to a stack slot. Handle
2932 calls that pass values in multiple non-contiguous locations. */
2933 if (REG_P (entry_parm
) || GET_CODE (entry_parm
) == PARALLEL
)
2937 /* Note that we will be storing an integral number of words.
2938 So we have to be careful to ensure that we allocate an
2939 integral number of words. We do this above when we call
2940 assign_stack_local if space was not allocated in the argument
2941 list. If it was, this will not work if PARM_BOUNDARY is not
2942 a multiple of BITS_PER_WORD. It isn't clear how to fix this
2943 if it becomes a problem. Exception is when BLKmode arrives
2944 with arguments not conforming to word_mode. */
2946 if (data
->stack_parm
== 0)
2948 else if (GET_CODE (entry_parm
) == PARALLEL
)
2951 gcc_assert (!size
|| !(PARM_BOUNDARY
% BITS_PER_WORD
));
2953 mem
= validize_mem (copy_rtx (stack_parm
));
2955 /* Handle values in multiple non-contiguous locations. */
2956 if (GET_CODE (entry_parm
) == PARALLEL
&& !MEM_P (mem
))
2957 emit_group_store (mem
, entry_parm
, data
->passed_type
, size
);
2958 else if (GET_CODE (entry_parm
) == PARALLEL
)
2960 push_to_sequence2 (all
->first_conversion_insn
,
2961 all
->last_conversion_insn
);
2962 emit_group_store (mem
, entry_parm
, data
->passed_type
, size
);
2963 all
->first_conversion_insn
= get_insns ();
2964 all
->last_conversion_insn
= get_last_insn ();
2966 in_conversion_seq
= true;
2972 /* If SIZE is that of a mode no bigger than a word, just use
2973 that mode's store operation. */
2974 else if (size
<= UNITS_PER_WORD
)
2977 = mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2980 #ifdef BLOCK_REG_PADDING
2981 && (size
== UNITS_PER_WORD
2982 || (BLOCK_REG_PADDING (mode
, data
->passed_type
, 1)
2983 != (BYTES_BIG_ENDIAN
? upward
: downward
)))
2989 /* We are really truncating a word_mode value containing
2990 SIZE bytes into a value of mode MODE. If such an
2991 operation requires no actual instructions, we can refer
2992 to the value directly in mode MODE, otherwise we must
2993 start with the register in word_mode and explicitly
2995 if (TRULY_NOOP_TRUNCATION (size
* BITS_PER_UNIT
, BITS_PER_WORD
))
2996 reg
= gen_rtx_REG (mode
, REGNO (entry_parm
));
2999 reg
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
3000 reg
= convert_to_mode (mode
, copy_to_reg (reg
), 1);
3002 emit_move_insn (change_address (mem
, mode
, 0), reg
);
3005 /* Blocks smaller than a word on a BYTES_BIG_ENDIAN
3006 machine must be aligned to the left before storing
3007 to memory. Note that the previous test doesn't
3008 handle all cases (e.g. SIZE == 3). */
3009 else if (size
!= UNITS_PER_WORD
3010 #ifdef BLOCK_REG_PADDING
3011 && (BLOCK_REG_PADDING (mode
, data
->passed_type
, 1)
3019 int by
= (UNITS_PER_WORD
- size
) * BITS_PER_UNIT
;
3020 rtx reg
= gen_rtx_REG (word_mode
, REGNO (entry_parm
));
3022 x
= expand_shift (LSHIFT_EXPR
, word_mode
, reg
, by
, NULL_RTX
, 1);
3023 tem
= change_address (mem
, word_mode
, 0);
3024 emit_move_insn (tem
, x
);
3026 else if (!MEM_P (mem
))
3027 emit_move_insn (mem
, entry_parm
);
3029 move_block_from_reg (REGNO (entry_parm
), mem
,
3030 size_stored
/ UNITS_PER_WORD
);
3032 else if (!MEM_P (mem
))
3033 emit_move_insn (mem
, entry_parm
);
3035 move_block_from_reg (REGNO (entry_parm
), mem
,
3036 size_stored
/ UNITS_PER_WORD
);
3038 else if (data
->stack_parm
== 0)
3040 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3041 emit_block_move (stack_parm
, data
->entry_parm
, GEN_INT (size
),
3043 all
->first_conversion_insn
= get_insns ();
3044 all
->last_conversion_insn
= get_last_insn ();
3046 in_conversion_seq
= true;
3051 if (!in_conversion_seq
)
3052 emit_move_insn (target_reg
, stack_parm
);
3055 push_to_sequence2 (all
->first_conversion_insn
,
3056 all
->last_conversion_insn
);
3057 emit_move_insn (target_reg
, stack_parm
);
3058 all
->first_conversion_insn
= get_insns ();
3059 all
->last_conversion_insn
= get_last_insn ();
3062 stack_parm
= target_reg
;
3065 data
->stack_parm
= stack_parm
;
3066 set_parm_rtl (parm
, stack_parm
);
3069 /* A subroutine of assign_parms. Allocate a pseudo to hold the current
3070 parameter. Get it there. Perform all ABI specified conversions. */
3073 assign_parm_setup_reg (struct assign_parm_data_all
*all
, tree parm
,
3074 struct assign_parm_data_one
*data
)
3076 rtx parmreg
, validated_mem
;
3077 rtx equiv_stack_parm
;
3078 machine_mode promoted_nominal_mode
;
3079 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (parm
));
3080 bool did_conversion
= false;
3081 bool need_conversion
, moved
;
3084 /* Store the parm in a pseudoregister during the function, but we may
3085 need to do it in a wider mode. Using 2 here makes the result
3086 consistent with promote_decl_mode and thus expand_expr_real_1. */
3087 promoted_nominal_mode
3088 = promote_function_mode (data
->nominal_type
, data
->nominal_mode
, &unsignedp
,
3089 TREE_TYPE (current_function_decl
), 2);
3091 parmreg
= gen_reg_rtx (promoted_nominal_mode
);
3092 if (!DECL_ARTIFICIAL (parm
))
3093 mark_user_reg (parmreg
);
3095 /* If this was an item that we received a pointer to,
3096 set rtl appropriately. */
3097 if (data
->passed_pointer
)
3099 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data
->passed_type
)), parmreg
);
3100 set_mem_attributes (rtl
, parm
, 1);
3105 assign_parm_remove_parallels (data
);
3107 /* Copy the value into the register, thus bridging between
3108 assign_parm_find_data_types and expand_expr_real_1. */
3110 equiv_stack_parm
= data
->stack_parm
;
3111 validated_mem
= validize_mem (copy_rtx (data
->entry_parm
));
3113 need_conversion
= (data
->nominal_mode
!= data
->passed_mode
3114 || promoted_nominal_mode
!= data
->promoted_mode
);
3118 && GET_MODE_CLASS (data
->nominal_mode
) == MODE_INT
3119 && data
->nominal_mode
== data
->passed_mode
3120 && data
->nominal_mode
== GET_MODE (data
->entry_parm
))
3122 /* ENTRY_PARM has been converted to PROMOTED_MODE, its
3123 mode, by the caller. We now have to convert it to
3124 NOMINAL_MODE, if different. However, PARMREG may be in
3125 a different mode than NOMINAL_MODE if it is being stored
3128 If ENTRY_PARM is a hard register, it might be in a register
3129 not valid for operating in its mode (e.g., an odd-numbered
3130 register for a DFmode). In that case, moves are the only
3131 thing valid, so we can't do a convert from there. This
3132 occurs when the calling sequence allow such misaligned
3135 In addition, the conversion may involve a call, which could
3136 clobber parameters which haven't been copied to pseudo
3139 First, we try to emit an insn which performs the necessary
3140 conversion. We verify that this insn does not clobber any
3143 enum insn_code icode
;
3146 icode
= can_extend_p (promoted_nominal_mode
, data
->passed_mode
,
3150 op1
= validated_mem
;
3151 if (icode
!= CODE_FOR_nothing
3152 && insn_operand_matches (icode
, 0, op0
)
3153 && insn_operand_matches (icode
, 1, op1
))
3155 enum rtx_code code
= unsignedp
? ZERO_EXTEND
: SIGN_EXTEND
;
3156 rtx_insn
*insn
, *insns
;
3158 HARD_REG_SET hardregs
;
3161 /* If op1 is a hard register that is likely spilled, first
3162 force it into a pseudo, otherwise combiner might extend
3163 its lifetime too much. */
3164 if (GET_CODE (t
) == SUBREG
)
3167 && HARD_REGISTER_P (t
)
3168 && ! TEST_HARD_REG_BIT (fixed_reg_set
, REGNO (t
))
3169 && targetm
.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (t
))))
3171 t
= gen_reg_rtx (GET_MODE (op1
));
3172 emit_move_insn (t
, op1
);
3176 rtx_insn
*pat
= gen_extend_insn (op0
, t
, promoted_nominal_mode
,
3177 data
->passed_mode
, unsignedp
);
3179 insns
= get_insns ();
3182 CLEAR_HARD_REG_SET (hardregs
);
3183 for (insn
= insns
; insn
&& moved
; insn
= NEXT_INSN (insn
))
3186 note_stores (PATTERN (insn
), record_hard_reg_sets
,
3188 if (!hard_reg_set_empty_p (hardregs
))
3197 if (equiv_stack_parm
!= NULL_RTX
)
3198 equiv_stack_parm
= gen_rtx_fmt_e (code
, GET_MODE (parmreg
),
3205 /* Nothing to do. */
3207 else if (need_conversion
)
3209 /* We did not have an insn to convert directly, or the sequence
3210 generated appeared unsafe. We must first copy the parm to a
3211 pseudo reg, and save the conversion until after all
3212 parameters have been moved. */
3215 rtx tempreg
= gen_reg_rtx (GET_MODE (data
->entry_parm
));
3217 emit_move_insn (tempreg
, validated_mem
);
3219 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3220 tempreg
= convert_to_mode (data
->nominal_mode
, tempreg
, unsignedp
);
3222 if (GET_CODE (tempreg
) == SUBREG
3223 && GET_MODE (tempreg
) == data
->nominal_mode
3224 && REG_P (SUBREG_REG (tempreg
))
3225 && data
->nominal_mode
== data
->passed_mode
3226 && GET_MODE (SUBREG_REG (tempreg
)) == GET_MODE (data
->entry_parm
)
3227 && GET_MODE_SIZE (GET_MODE (tempreg
))
3228 < GET_MODE_SIZE (GET_MODE (data
->entry_parm
)))
3230 /* The argument is already sign/zero extended, so note it
3232 SUBREG_PROMOTED_VAR_P (tempreg
) = 1;
3233 SUBREG_PROMOTED_SET (tempreg
, unsignedp
);
3236 /* TREE_USED gets set erroneously during expand_assignment. */
3237 save_tree_used
= TREE_USED (parm
);
3238 SET_DECL_RTL (parm
, rtl
);
3239 expand_assignment (parm
, make_tree (data
->nominal_type
, tempreg
), false);
3240 SET_DECL_RTL (parm
, NULL_RTX
);
3241 TREE_USED (parm
) = save_tree_used
;
3242 all
->first_conversion_insn
= get_insns ();
3243 all
->last_conversion_insn
= get_last_insn ();
3246 did_conversion
= true;
3249 emit_move_insn (parmreg
, validated_mem
);
3251 /* If we were passed a pointer but the actual value can safely live
3252 in a register, retrieve it and use it directly. */
3253 if (data
->passed_pointer
&& TYPE_MODE (TREE_TYPE (parm
)) != BLKmode
)
3255 /* We can't use nominal_mode, because it will have been set to
3256 Pmode above. We must use the actual mode of the parm. */
3257 if (use_register_for_decl (parm
))
3259 parmreg
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm
)));
3260 mark_user_reg (parmreg
);
3264 int align
= STACK_SLOT_ALIGNMENT (TREE_TYPE (parm
),
3265 TYPE_MODE (TREE_TYPE (parm
)),
3266 TYPE_ALIGN (TREE_TYPE (parm
)));
3268 = assign_stack_local (TYPE_MODE (TREE_TYPE (parm
)),
3269 GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parm
))),
3271 set_mem_attributes (parmreg
, parm
, 1);
3274 if (GET_MODE (parmreg
) != GET_MODE (rtl
))
3276 rtx tempreg
= gen_reg_rtx (GET_MODE (rtl
));
3277 int unsigned_p
= TYPE_UNSIGNED (TREE_TYPE (parm
));
3279 push_to_sequence2 (all
->first_conversion_insn
,
3280 all
->last_conversion_insn
);
3281 emit_move_insn (tempreg
, rtl
);
3282 tempreg
= convert_to_mode (GET_MODE (parmreg
), tempreg
, unsigned_p
);
3283 emit_move_insn (parmreg
, tempreg
);
3284 all
->first_conversion_insn
= get_insns ();
3285 all
->last_conversion_insn
= get_last_insn ();
3288 did_conversion
= true;
3291 emit_move_insn (parmreg
, rtl
);
3295 /* STACK_PARM is the pointer, not the parm, and PARMREG is
3297 data
->stack_parm
= NULL
;
3300 set_parm_rtl (parm
, rtl
);
3302 /* Mark the register as eliminable if we did no conversion and it was
3303 copied from memory at a fixed offset, and the arg pointer was not
3304 copied to a pseudo-reg. If the arg pointer is a pseudo reg or the
3305 offset formed an invalid address, such memory-equivalences as we
3306 make here would screw up life analysis for it. */
3307 if (data
->nominal_mode
== data
->passed_mode
3309 && data
->stack_parm
!= 0
3310 && MEM_P (data
->stack_parm
)
3311 && data
->locate
.offset
.var
== 0
3312 && reg_mentioned_p (virtual_incoming_args_rtx
,
3313 XEXP (data
->stack_parm
, 0)))
3315 rtx_insn
*linsn
= get_last_insn ();
3319 /* Mark complex types separately. */
3320 if (GET_CODE (parmreg
) == CONCAT
)
3322 machine_mode submode
3323 = GET_MODE_INNER (GET_MODE (parmreg
));
3324 int regnor
= REGNO (XEXP (parmreg
, 0));
3325 int regnoi
= REGNO (XEXP (parmreg
, 1));
3326 rtx stackr
= adjust_address_nv (data
->stack_parm
, submode
, 0);
3327 rtx stacki
= adjust_address_nv (data
->stack_parm
, submode
,
3328 GET_MODE_SIZE (submode
));
3330 /* Scan backwards for the set of the real and
3332 for (sinsn
= linsn
; sinsn
!= 0;
3333 sinsn
= prev_nonnote_insn (sinsn
))
3335 set
= single_set (sinsn
);
3339 if (SET_DEST (set
) == regno_reg_rtx
[regnoi
])
3340 set_unique_reg_note (sinsn
, REG_EQUIV
, stacki
);
3341 else if (SET_DEST (set
) == regno_reg_rtx
[regnor
])
3342 set_unique_reg_note (sinsn
, REG_EQUIV
, stackr
);
3346 set_dst_reg_note (linsn
, REG_EQUIV
, equiv_stack_parm
, parmreg
);
3349 /* For pointer data type, suggest pointer register. */
3350 if (POINTER_TYPE_P (TREE_TYPE (parm
)))
3351 mark_reg_pointer (parmreg
,
3352 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
3355 /* A subroutine of assign_parms. Allocate stack space to hold the current
3356 parameter. Get it there. Perform all ABI specified conversions. */
3359 assign_parm_setup_stack (struct assign_parm_data_all
*all
, tree parm
,
3360 struct assign_parm_data_one
*data
)
3362 /* Value must be stored in the stack slot STACK_PARM during function
3364 bool to_conversion
= false;
3366 assign_parm_remove_parallels (data
);
3368 if (data
->promoted_mode
!= data
->nominal_mode
)
3370 /* Conversion is required. */
3371 rtx tempreg
= gen_reg_rtx (GET_MODE (data
->entry_parm
));
3373 emit_move_insn (tempreg
, validize_mem (copy_rtx (data
->entry_parm
)));
3375 push_to_sequence2 (all
->first_conversion_insn
, all
->last_conversion_insn
);
3376 to_conversion
= true;
3378 data
->entry_parm
= convert_to_mode (data
->nominal_mode
, tempreg
,
3379 TYPE_UNSIGNED (TREE_TYPE (parm
)));
3381 if (data
->stack_parm
)
3383 int offset
= subreg_lowpart_offset (data
->nominal_mode
,
3384 GET_MODE (data
->stack_parm
));
3385 /* ??? This may need a big-endian conversion on sparc64. */
3387 = adjust_address (data
->stack_parm
, data
->nominal_mode
, 0);
3388 if (offset
&& MEM_OFFSET_KNOWN_P (data
->stack_parm
))
3389 set_mem_offset (data
->stack_parm
,
3390 MEM_OFFSET (data
->stack_parm
) + offset
);
3394 if (data
->entry_parm
!= data
->stack_parm
)
3398 if (data
->stack_parm
== 0)
3400 int align
= STACK_SLOT_ALIGNMENT (data
->passed_type
,
3401 GET_MODE (data
->entry_parm
),
3402 TYPE_ALIGN (data
->passed_type
));
3404 = assign_stack_local (GET_MODE (data
->entry_parm
),
3405 GET_MODE_SIZE (GET_MODE (data
->entry_parm
)),
3407 set_mem_attributes (data
->stack_parm
, parm
, 1);
3410 dest
= validize_mem (copy_rtx (data
->stack_parm
));
3411 src
= validize_mem (copy_rtx (data
->entry_parm
));
3415 /* Use a block move to handle potentially misaligned entry_parm. */
3417 push_to_sequence2 (all
->first_conversion_insn
,
3418 all
->last_conversion_insn
);
3419 to_conversion
= true;
3421 emit_block_move (dest
, src
,
3422 GEN_INT (int_size_in_bytes (data
->passed_type
)),
3426 emit_move_insn (dest
, src
);
3431 all
->first_conversion_insn
= get_insns ();
3432 all
->last_conversion_insn
= get_last_insn ();
3436 set_parm_rtl (parm
, data
->stack_parm
);
3439 /* A subroutine of assign_parms. If the ABI splits complex arguments, then
3440 undo the frobbing that we did in assign_parms_augmented_arg_list. */
3443 assign_parms_unsplit_complex (struct assign_parm_data_all
*all
,
3447 tree orig_fnargs
= all
->orig_fnargs
;
3450 for (parm
= orig_fnargs
; parm
; parm
= TREE_CHAIN (parm
), ++i
)
3452 if (TREE_CODE (TREE_TYPE (parm
)) == COMPLEX_TYPE
3453 && targetm
.calls
.split_complex_arg (TREE_TYPE (parm
)))
3455 rtx tmp
, real
, imag
;
3456 machine_mode inner
= GET_MODE_INNER (DECL_MODE (parm
));
3458 real
= DECL_RTL (fnargs
[i
]);
3459 imag
= DECL_RTL (fnargs
[i
+ 1]);
3460 if (inner
!= GET_MODE (real
))
3462 real
= gen_lowpart_SUBREG (inner
, real
);
3463 imag
= gen_lowpart_SUBREG (inner
, imag
);
3466 if (TREE_ADDRESSABLE (parm
))
3469 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (parm
));
3470 int align
= STACK_SLOT_ALIGNMENT (TREE_TYPE (parm
),
3472 TYPE_ALIGN (TREE_TYPE (parm
)));
3474 /* split_complex_arg put the real and imag parts in
3475 pseudos. Move them to memory. */
3476 tmp
= assign_stack_local (DECL_MODE (parm
), size
, align
);
3477 set_mem_attributes (tmp
, parm
, 1);
3478 rmem
= adjust_address_nv (tmp
, inner
, 0);
3479 imem
= adjust_address_nv (tmp
, inner
, GET_MODE_SIZE (inner
));
3480 push_to_sequence2 (all
->first_conversion_insn
,
3481 all
->last_conversion_insn
);
3482 emit_move_insn (rmem
, real
);
3483 emit_move_insn (imem
, imag
);
3484 all
->first_conversion_insn
= get_insns ();
3485 all
->last_conversion_insn
= get_last_insn ();
3489 tmp
= gen_rtx_CONCAT (DECL_MODE (parm
), real
, imag
);
3490 set_parm_rtl (parm
, tmp
);
3492 real
= DECL_INCOMING_RTL (fnargs
[i
]);
3493 imag
= DECL_INCOMING_RTL (fnargs
[i
+ 1]);
3494 if (inner
!= GET_MODE (real
))
3496 real
= gen_lowpart_SUBREG (inner
, real
);
3497 imag
= gen_lowpart_SUBREG (inner
, imag
);
3499 tmp
= gen_rtx_CONCAT (DECL_MODE (parm
), real
, imag
);
3500 set_decl_incoming_rtl (parm
, tmp
, false);
3506 /* Load bounds of PARM from bounds table. */
3508 assign_parm_load_bounds (struct assign_parm_data_one
*data
,
3514 unsigned i
, offs
= 0;
3516 rtx slot
= NULL
, ptr
= NULL
;
3521 bitmap_obstack_initialize (NULL
);
3522 slots
= BITMAP_ALLOC (NULL
);
3523 chkp_find_bound_slots (TREE_TYPE (parm
), slots
);
3524 EXECUTE_IF_SET_IN_BITMAP (slots
, 0, i
, bi
)
3534 BITMAP_FREE (slots
);
3535 bitmap_obstack_release (NULL
);
3538 /* We may have bounds not associated with any pointer. */
3540 offs
= bnd_no
* POINTER_SIZE
/ BITS_PER_UNIT
;
3542 /* Find associated pointer. */
3545 /* If bounds are not associated with any bounds,
3546 then it is passed in a register or special slot. */
3547 gcc_assert (data
->entry_parm
);
3550 else if (MEM_P (entry
))
3551 slot
= adjust_address (entry
, Pmode
, offs
);
3552 else if (REG_P (entry
))
3553 ptr
= gen_rtx_REG (Pmode
, REGNO (entry
) + bnd_no
);
3554 else if (GET_CODE (entry
) == PARALLEL
)
3555 ptr
= chkp_get_value_with_offs (entry
, GEN_INT (offs
));
3558 data
->entry_parm
= targetm
.calls
.load_bounds_for_arg (slot
, ptr
,
3562 /* Assign RTL expressions to the function's bounds parameters BNDARGS. */
3565 assign_bounds (vec
<bounds_parm_data
> &bndargs
,
3566 struct assign_parm_data_all
&all
,
3567 bool assign_regs
, bool assign_special
,
3571 bounds_parm_data
*pbdata
;
3573 if (!bndargs
.exists ())
3576 /* We make few passes to store input bounds. Firstly handle bounds
3577 passed in registers. After that we load bounds passed in special
3578 slots. Finally we load bounds from Bounds Table. */
3579 for (pass
= 0; pass
< 3; pass
++)
3580 FOR_EACH_VEC_ELT (bndargs
, i
, pbdata
)
3582 /* Pass 0 => regs only. */
3585 ||(!pbdata
->parm_data
.entry_parm
3586 || GET_CODE (pbdata
->parm_data
.entry_parm
) != REG
)))
3588 /* Pass 1 => slots only. */
3591 || (!pbdata
->parm_data
.entry_parm
3592 || GET_CODE (pbdata
->parm_data
.entry_parm
) == REG
)))
3594 /* Pass 2 => BT only. */
3597 || pbdata
->parm_data
.entry_parm
))
3600 if (!pbdata
->parm_data
.entry_parm
3601 || GET_CODE (pbdata
->parm_data
.entry_parm
) != REG
)
3602 assign_parm_load_bounds (&pbdata
->parm_data
, pbdata
->ptr_parm
,
3603 pbdata
->ptr_entry
, pbdata
->bound_no
);
3605 set_decl_incoming_rtl (pbdata
->bounds_parm
,
3606 pbdata
->parm_data
.entry_parm
, false);
3608 if (assign_parm_setup_block_p (&pbdata
->parm_data
))
3609 assign_parm_setup_block (&all
, pbdata
->bounds_parm
,
3610 &pbdata
->parm_data
);
3611 else if (pbdata
->parm_data
.passed_pointer
3612 || use_register_for_decl (pbdata
->bounds_parm
))
3613 assign_parm_setup_reg (&all
, pbdata
->bounds_parm
,
3614 &pbdata
->parm_data
);
3616 assign_parm_setup_stack (&all
, pbdata
->bounds_parm
,
3617 &pbdata
->parm_data
);
3621 /* Assign RTL expressions to the function's parameters. This may involve
3622 copying them into registers and using those registers as the DECL_RTL. */
3625 assign_parms (tree fndecl
)
3627 struct assign_parm_data_all all
;
3630 unsigned i
, bound_no
= 0;
3631 tree last_arg
= NULL
;
3632 rtx last_arg_entry
= NULL
;
3633 vec
<bounds_parm_data
> bndargs
= vNULL
;
3634 bounds_parm_data bdata
;
3636 crtl
->args
.internal_arg_pointer
3637 = targetm
.calls
.internal_arg_pointer ();
3639 assign_parms_initialize_all (&all
);
3640 fnargs
= assign_parms_augmented_arg_list (&all
);
3642 FOR_EACH_VEC_ELT (fnargs
, i
, parm
)
3644 struct assign_parm_data_one data
;
3646 /* Extract the type of PARM; adjust it according to ABI. */
3647 assign_parm_find_data_types (&all
, parm
, &data
);
3649 /* Early out for errors and void parameters. */
3650 if (data
.passed_mode
== VOIDmode
)
3652 SET_DECL_RTL (parm
, const0_rtx
);
3653 DECL_INCOMING_RTL (parm
) = DECL_RTL (parm
);
3657 /* Estimate stack alignment from parameter alignment. */
3658 if (SUPPORTS_STACK_ALIGNMENT
)
3661 = targetm
.calls
.function_arg_boundary (data
.promoted_mode
,
3663 align
= MINIMUM_ALIGNMENT (data
.passed_type
, data
.promoted_mode
,
3665 if (TYPE_ALIGN (data
.nominal_type
) > align
)
3666 align
= MINIMUM_ALIGNMENT (data
.nominal_type
,
3667 TYPE_MODE (data
.nominal_type
),
3668 TYPE_ALIGN (data
.nominal_type
));
3669 if (crtl
->stack_alignment_estimated
< align
)
3671 gcc_assert (!crtl
->stack_realign_processed
);
3672 crtl
->stack_alignment_estimated
= align
;
3676 /* Find out where the parameter arrives in this function. */
3677 assign_parm_find_entry_rtl (&all
, &data
);
3679 /* Find out where stack space for this parameter might be. */
3680 if (assign_parm_is_stack_parm (&all
, &data
))
3682 assign_parm_find_stack_rtl (parm
, &data
);
3683 assign_parm_adjust_entry_rtl (&data
);
3685 if (!POINTER_BOUNDS_TYPE_P (data
.passed_type
))
3687 /* Remember where last non bounds arg was passed in case
3688 we have to load associated bounds for it from Bounds
3691 last_arg_entry
= data
.entry_parm
;
3694 /* Record permanently how this parm was passed. */
3695 if (data
.passed_pointer
)
3698 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (data
.passed_type
)),
3700 set_decl_incoming_rtl (parm
, incoming_rtl
, true);
3703 set_decl_incoming_rtl (parm
, data
.entry_parm
, false);
3705 assign_parm_adjust_stack_rtl (&data
);
3707 /* Bounds should be loaded in the particular order to
3708 have registers allocated correctly. Collect info about
3709 input bounds and load them later. */
3710 if (POINTER_BOUNDS_TYPE_P (data
.passed_type
))
3712 /* Expect bounds in instrumented functions only. */
3713 gcc_assert (chkp_function_instrumented_p (fndecl
));
3715 bdata
.parm_data
= data
;
3716 bdata
.bounds_parm
= parm
;
3717 bdata
.ptr_parm
= last_arg
;
3718 bdata
.ptr_entry
= last_arg_entry
;
3719 bdata
.bound_no
= bound_no
;
3720 bndargs
.safe_push (bdata
);
3724 if (assign_parm_setup_block_p (&data
))
3725 assign_parm_setup_block (&all
, parm
, &data
);
3726 else if (data
.passed_pointer
|| use_register_for_decl (parm
))
3727 assign_parm_setup_reg (&all
, parm
, &data
);
3729 assign_parm_setup_stack (&all
, parm
, &data
);
3732 if (cfun
->stdarg
&& !DECL_CHAIN (parm
))
3734 int pretend_bytes
= 0;
3736 assign_parms_setup_varargs (&all
, &data
, false);
3738 if (chkp_function_instrumented_p (fndecl
))
3740 /* We expect this is the last parm. Otherwise it is wrong
3741 to assign bounds right now. */
3742 gcc_assert (i
== (fnargs
.length () - 1));
3743 assign_bounds (bndargs
, all
, true, false, false);
3744 targetm
.calls
.setup_incoming_vararg_bounds (all
.args_so_far
,
3749 assign_bounds (bndargs
, all
, false, true, true);
3754 /* Update info on where next arg arrives in registers. */
3755 targetm
.calls
.function_arg_advance (all
.args_so_far
, data
.promoted_mode
,
3756 data
.passed_type
, data
.named_arg
);
3758 if (POINTER_BOUNDS_TYPE_P (data
.passed_type
))
3762 assign_bounds (bndargs
, all
, true, true, true);
3765 if (targetm
.calls
.split_complex_arg
)
3766 assign_parms_unsplit_complex (&all
, fnargs
);
3770 /* Output all parameter conversion instructions (possibly including calls)
3771 now that all parameters have been copied out of hard registers. */
3772 emit_insn (all
.first_conversion_insn
);
3774 /* Estimate reload stack alignment from scalar return mode. */
3775 if (SUPPORTS_STACK_ALIGNMENT
)
3777 if (DECL_RESULT (fndecl
))
3779 tree type
= TREE_TYPE (DECL_RESULT (fndecl
));
3780 machine_mode mode
= TYPE_MODE (type
);
3784 && !AGGREGATE_TYPE_P (type
))
3786 unsigned int align
= GET_MODE_ALIGNMENT (mode
);
3787 if (crtl
->stack_alignment_estimated
< align
)
3789 gcc_assert (!crtl
->stack_realign_processed
);
3790 crtl
->stack_alignment_estimated
= align
;
3796 /* If we are receiving a struct value address as the first argument, set up
3797 the RTL for the function result. As this might require code to convert
3798 the transmitted address to Pmode, we do this here to ensure that possible
3799 preliminary conversions of the address have been emitted already. */
3800 if (all
.function_result_decl
)
3802 tree result
= DECL_RESULT (current_function_decl
);
3803 rtx addr
= DECL_RTL (all
.function_result_decl
);
3806 if (DECL_BY_REFERENCE (result
))
3808 SET_DECL_VALUE_EXPR (result
, all
.function_result_decl
);
3813 SET_DECL_VALUE_EXPR (result
,
3814 build1 (INDIRECT_REF
, TREE_TYPE (result
),
3815 all
.function_result_decl
));
3816 addr
= convert_memory_address (Pmode
, addr
);
3817 x
= gen_rtx_MEM (DECL_MODE (result
), addr
);
3818 set_mem_attributes (x
, result
, 1);
3821 DECL_HAS_VALUE_EXPR_P (result
) = 1;
3823 set_parm_rtl (result
, x
);
3826 /* We have aligned all the args, so add space for the pretend args. */
3827 crtl
->args
.pretend_args_size
= all
.pretend_args_size
;
3828 all
.stack_args_size
.constant
+= all
.extra_pretend_bytes
;
3829 crtl
->args
.size
= all
.stack_args_size
.constant
;
3831 /* Adjust function incoming argument size for alignment and
3834 crtl
->args
.size
= MAX (crtl
->args
.size
, all
.reg_parm_stack_space
);
3835 crtl
->args
.size
= CEIL_ROUND (crtl
->args
.size
,
3836 PARM_BOUNDARY
/ BITS_PER_UNIT
);
3838 if (ARGS_GROW_DOWNWARD
)
3840 crtl
->args
.arg_offset_rtx
3841 = (all
.stack_args_size
.var
== 0 ? GEN_INT (-all
.stack_args_size
.constant
)
3842 : expand_expr (size_diffop (all
.stack_args_size
.var
,
3843 size_int (-all
.stack_args_size
.constant
)),
3844 NULL_RTX
, VOIDmode
, EXPAND_NORMAL
));
3847 crtl
->args
.arg_offset_rtx
= ARGS_SIZE_RTX (all
.stack_args_size
);
3849 /* See how many bytes, if any, of its args a function should try to pop
3852 crtl
->args
.pops_args
= targetm
.calls
.return_pops_args (fndecl
,
3856 /* For stdarg.h function, save info about
3857 regs and stack space used by the named args. */
3859 crtl
->args
.info
= all
.args_so_far_v
;
3861 /* Set the rtx used for the function return value. Put this in its
3862 own variable so any optimizers that need this information don't have
3863 to include tree.h. Do this here so it gets done when an inlined
3864 function gets output. */
3867 = (DECL_RTL_SET_P (DECL_RESULT (fndecl
))
3868 ? DECL_RTL (DECL_RESULT (fndecl
)) : NULL_RTX
);
3870 /* If scalar return value was computed in a pseudo-reg, or was a named
3871 return value that got dumped to the stack, copy that to the hard
3873 if (DECL_RTL_SET_P (DECL_RESULT (fndecl
)))
3875 tree decl_result
= DECL_RESULT (fndecl
);
3876 rtx decl_rtl
= DECL_RTL (decl_result
);
3878 if (REG_P (decl_rtl
)
3879 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
3880 : DECL_REGISTER (decl_result
))
3884 real_decl_rtl
= targetm
.calls
.function_value (TREE_TYPE (decl_result
),
3886 if (chkp_function_instrumented_p (fndecl
))
3888 = targetm
.calls
.chkp_function_value_bounds (TREE_TYPE (decl_result
),
3890 REG_FUNCTION_VALUE_P (real_decl_rtl
) = 1;
3891 /* The delay slot scheduler assumes that crtl->return_rtx
3892 holds the hard register containing the return value, not a
3893 temporary pseudo. */
3894 crtl
->return_rtx
= real_decl_rtl
;
3899 /* A subroutine of gimplify_parameters, invoked via walk_tree.
3900 For all seen types, gimplify their sizes. */
3903 gimplify_parm_type (tree
*tp
, int *walk_subtrees
, void *data
)
3910 if (POINTER_TYPE_P (t
))
3912 else if (TYPE_SIZE (t
) && !TREE_CONSTANT (TYPE_SIZE (t
))
3913 && !TYPE_SIZES_GIMPLIFIED (t
))
3915 gimplify_type_sizes (t
, (gimple_seq
*) data
);
3923 /* Gimplify the parameter list for current_function_decl. This involves
3924 evaluating SAVE_EXPRs of variable sized parameters and generating code
3925 to implement callee-copies reference parameters. Returns a sequence of
3926 statements to add to the beginning of the function. */
3929 gimplify_parameters (void)
3931 struct assign_parm_data_all all
;
3933 gimple_seq stmts
= NULL
;
3937 assign_parms_initialize_all (&all
);
3938 fnargs
= assign_parms_augmented_arg_list (&all
);
3940 FOR_EACH_VEC_ELT (fnargs
, i
, parm
)
3942 struct assign_parm_data_one data
;
3944 /* Extract the type of PARM; adjust it according to ABI. */
3945 assign_parm_find_data_types (&all
, parm
, &data
);
3947 /* Early out for errors and void parameters. */
3948 if (data
.passed_mode
== VOIDmode
|| DECL_SIZE (parm
) == NULL
)
3951 /* Update info on where next arg arrives in registers. */
3952 targetm
.calls
.function_arg_advance (all
.args_so_far
, data
.promoted_mode
,
3953 data
.passed_type
, data
.named_arg
);
3955 /* ??? Once upon a time variable_size stuffed parameter list
3956 SAVE_EXPRs (amongst others) onto a pending sizes list. This
3957 turned out to be less than manageable in the gimple world.
3958 Now we have to hunt them down ourselves. */
3959 walk_tree_without_duplicates (&data
.passed_type
,
3960 gimplify_parm_type
, &stmts
);
3962 if (TREE_CODE (DECL_SIZE_UNIT (parm
)) != INTEGER_CST
)
3964 gimplify_one_sizepos (&DECL_SIZE (parm
), &stmts
);
3965 gimplify_one_sizepos (&DECL_SIZE_UNIT (parm
), &stmts
);
3968 if (data
.passed_pointer
)
3970 tree type
= TREE_TYPE (data
.passed_type
);
3971 if (reference_callee_copied (&all
.args_so_far_v
, TYPE_MODE (type
),
3972 type
, data
.named_arg
))
3976 /* For constant-sized objects, this is trivial; for
3977 variable-sized objects, we have to play games. */
3978 if (TREE_CODE (DECL_SIZE_UNIT (parm
)) == INTEGER_CST
3979 && !(flag_stack_check
== GENERIC_STACK_CHECK
3980 && compare_tree_int (DECL_SIZE_UNIT (parm
),
3981 STACK_CHECK_MAX_VAR_SIZE
) > 0))
3983 local
= create_tmp_var (type
, get_name (parm
));
3984 DECL_IGNORED_P (local
) = 0;
3985 /* If PARM was addressable, move that flag over
3986 to the local copy, as its address will be taken,
3987 not the PARMs. Keep the parms address taken
3988 as we'll query that flag during gimplification. */
3989 if (TREE_ADDRESSABLE (parm
))
3990 TREE_ADDRESSABLE (local
) = 1;
3991 else if (TREE_CODE (type
) == COMPLEX_TYPE
3992 || TREE_CODE (type
) == VECTOR_TYPE
)
3993 DECL_GIMPLE_REG_P (local
) = 1;
3997 tree ptr_type
, addr
;
3999 ptr_type
= build_pointer_type (type
);
4000 addr
= create_tmp_reg (ptr_type
, get_name (parm
));
4001 DECL_IGNORED_P (addr
) = 0;
4002 local
= build_fold_indirect_ref (addr
);
4004 t
= builtin_decl_explicit (BUILT_IN_ALLOCA_WITH_ALIGN
);
4005 t
= build_call_expr (t
, 2, DECL_SIZE_UNIT (parm
),
4006 size_int (DECL_ALIGN (parm
)));
4008 /* The call has been built for a variable-sized object. */
4009 CALL_ALLOCA_FOR_VAR_P (t
) = 1;
4010 t
= fold_convert (ptr_type
, t
);
4011 t
= build2 (MODIFY_EXPR
, TREE_TYPE (addr
), addr
, t
);
4012 gimplify_and_add (t
, &stmts
);
4015 gimplify_assign (local
, parm
, &stmts
);
4017 SET_DECL_VALUE_EXPR (parm
, local
);
4018 DECL_HAS_VALUE_EXPR_P (parm
) = 1;
4028 /* Compute the size and offset from the start of the stacked arguments for a
4029 parm passed in mode PASSED_MODE and with type TYPE.
4031 INITIAL_OFFSET_PTR points to the current offset into the stacked
4034 The starting offset and size for this parm are returned in
4035 LOCATE->OFFSET and LOCATE->SIZE, respectively. When IN_REGS is
4036 nonzero, the offset is that of stack slot, which is returned in
4037 LOCATE->SLOT_OFFSET. LOCATE->ALIGNMENT_PAD is the amount of
4038 padding required from the initial offset ptr to the stack slot.
4040 IN_REGS is nonzero if the argument will be passed in registers. It will
4041 never be set if REG_PARM_STACK_SPACE is not defined.
4043 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved
4044 for arguments which are passed in registers.
4046 FNDECL is the function in which the argument was defined.
4048 There are two types of rounding that are done. The first, controlled by
4049 TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the
4050 argument list to be aligned to the specific boundary (in bits). This
4051 rounding affects the initial and starting offsets, but not the argument
4054 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
4055 optionally rounds the size of the parm to PARM_BOUNDARY. The
4056 initial offset is not affected by this rounding, while the size always
4057 is and the starting offset may be. */
4059 /* LOCATE->OFFSET will be negative for ARGS_GROW_DOWNWARD case;
4060 INITIAL_OFFSET_PTR is positive because locate_and_pad_parm's
4061 callers pass in the total size of args so far as
4062 INITIAL_OFFSET_PTR. LOCATE->SIZE is always positive. */
4065 locate_and_pad_parm (machine_mode passed_mode
, tree type
, int in_regs
,
4066 int reg_parm_stack_space
, int partial
,
4067 tree fndecl ATTRIBUTE_UNUSED
,
4068 struct args_size
*initial_offset_ptr
,
4069 struct locate_and_pad_arg_data
*locate
)
4072 enum direction where_pad
;
4073 unsigned int boundary
, round_boundary
;
4074 int part_size_in_regs
;
4076 /* If we have found a stack parm before we reach the end of the
4077 area reserved for registers, skip that area. */
4080 if (reg_parm_stack_space
> 0)
4082 if (initial_offset_ptr
->var
)
4084 initial_offset_ptr
->var
4085 = size_binop (MAX_EXPR
, ARGS_SIZE_TREE (*initial_offset_ptr
),
4086 ssize_int (reg_parm_stack_space
));
4087 initial_offset_ptr
->constant
= 0;
4089 else if (initial_offset_ptr
->constant
< reg_parm_stack_space
)
4090 initial_offset_ptr
->constant
= reg_parm_stack_space
;
4094 part_size_in_regs
= (reg_parm_stack_space
== 0 ? partial
: 0);
4097 = type
? size_in_bytes (type
) : size_int (GET_MODE_SIZE (passed_mode
));
4098 where_pad
= FUNCTION_ARG_PADDING (passed_mode
, type
);
4099 boundary
= targetm
.calls
.function_arg_boundary (passed_mode
, type
);
4100 round_boundary
= targetm
.calls
.function_arg_round_boundary (passed_mode
,
4102 locate
->where_pad
= where_pad
;
4104 /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */
4105 if (boundary
> MAX_SUPPORTED_STACK_ALIGNMENT
)
4106 boundary
= MAX_SUPPORTED_STACK_ALIGNMENT
;
4108 locate
->boundary
= boundary
;
4110 if (SUPPORTS_STACK_ALIGNMENT
)
4112 /* stack_alignment_estimated can't change after stack has been
4114 if (crtl
->stack_alignment_estimated
< boundary
)
4116 if (!crtl
->stack_realign_processed
)
4117 crtl
->stack_alignment_estimated
= boundary
;
4120 /* If stack is realigned and stack alignment value
4121 hasn't been finalized, it is OK not to increase
4122 stack_alignment_estimated. The bigger alignment
4123 requirement is recorded in stack_alignment_needed
4125 gcc_assert (!crtl
->stack_realign_finalized
4126 && crtl
->stack_realign_needed
);
4131 /* Remember if the outgoing parameter requires extra alignment on the
4132 calling function side. */
4133 if (crtl
->stack_alignment_needed
< boundary
)
4134 crtl
->stack_alignment_needed
= boundary
;
4135 if (crtl
->preferred_stack_boundary
< boundary
)
4136 crtl
->preferred_stack_boundary
= boundary
;
4138 if (ARGS_GROW_DOWNWARD
)
4140 locate
->slot_offset
.constant
= -initial_offset_ptr
->constant
;
4141 if (initial_offset_ptr
->var
)
4142 locate
->slot_offset
.var
= size_binop (MINUS_EXPR
, ssize_int (0),
4143 initial_offset_ptr
->var
);
4147 if (where_pad
!= none
4148 && (!tree_fits_uhwi_p (sizetree
)
4149 || (tree_to_uhwi (sizetree
) * BITS_PER_UNIT
) % round_boundary
))
4150 s2
= round_up (s2
, round_boundary
/ BITS_PER_UNIT
);
4151 SUB_PARM_SIZE (locate
->slot_offset
, s2
);
4154 locate
->slot_offset
.constant
+= part_size_in_regs
;
4156 if (!in_regs
|| reg_parm_stack_space
> 0)
4157 pad_to_arg_alignment (&locate
->slot_offset
, boundary
,
4158 &locate
->alignment_pad
);
4160 locate
->size
.constant
= (-initial_offset_ptr
->constant
4161 - locate
->slot_offset
.constant
);
4162 if (initial_offset_ptr
->var
)
4163 locate
->size
.var
= size_binop (MINUS_EXPR
,
4164 size_binop (MINUS_EXPR
,
4166 initial_offset_ptr
->var
),
4167 locate
->slot_offset
.var
);
4169 /* Pad_below needs the pre-rounded size to know how much to pad
4171 locate
->offset
= locate
->slot_offset
;
4172 if (where_pad
== downward
)
4173 pad_below (&locate
->offset
, passed_mode
, sizetree
);
4178 if (!in_regs
|| reg_parm_stack_space
> 0)
4179 pad_to_arg_alignment (initial_offset_ptr
, boundary
,
4180 &locate
->alignment_pad
);
4181 locate
->slot_offset
= *initial_offset_ptr
;
4183 #ifdef PUSH_ROUNDING
4184 if (passed_mode
!= BLKmode
)
4185 sizetree
= size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree
)));
4188 /* Pad_below needs the pre-rounded size to know how much to pad below
4189 so this must be done before rounding up. */
4190 locate
->offset
= locate
->slot_offset
;
4191 if (where_pad
== downward
)
4192 pad_below (&locate
->offset
, passed_mode
, sizetree
);
4194 if (where_pad
!= none
4195 && (!tree_fits_uhwi_p (sizetree
)
4196 || (tree_to_uhwi (sizetree
) * BITS_PER_UNIT
) % round_boundary
))
4197 sizetree
= round_up (sizetree
, round_boundary
/ BITS_PER_UNIT
);
4199 ADD_PARM_SIZE (locate
->size
, sizetree
);
4201 locate
->size
.constant
-= part_size_in_regs
;
4204 #ifdef FUNCTION_ARG_OFFSET
4205 locate
->offset
.constant
+= FUNCTION_ARG_OFFSET (passed_mode
, type
);
4209 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY.
4210 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */
4213 pad_to_arg_alignment (struct args_size
*offset_ptr
, int boundary
,
4214 struct args_size
*alignment_pad
)
4216 tree save_var
= NULL_TREE
;
4217 HOST_WIDE_INT save_constant
= 0;
4218 int boundary_in_bytes
= boundary
/ BITS_PER_UNIT
;
4219 HOST_WIDE_INT sp_offset
= STACK_POINTER_OFFSET
;
4221 #ifdef SPARC_STACK_BOUNDARY_HACK
4222 /* ??? The SPARC port may claim a STACK_BOUNDARY higher than
4223 the real alignment of %sp. However, when it does this, the
4224 alignment of %sp+STACK_POINTER_OFFSET is STACK_BOUNDARY. */
4225 if (SPARC_STACK_BOUNDARY_HACK
)
4229 if (boundary
> PARM_BOUNDARY
)
4231 save_var
= offset_ptr
->var
;
4232 save_constant
= offset_ptr
->constant
;
4235 alignment_pad
->var
= NULL_TREE
;
4236 alignment_pad
->constant
= 0;
4238 if (boundary
> BITS_PER_UNIT
)
4240 if (offset_ptr
->var
)
4242 tree sp_offset_tree
= ssize_int (sp_offset
);
4243 tree offset
= size_binop (PLUS_EXPR
,
4244 ARGS_SIZE_TREE (*offset_ptr
),
4247 if (ARGS_GROW_DOWNWARD
)
4248 rounded
= round_down (offset
, boundary
/ BITS_PER_UNIT
);
4250 rounded
= round_up (offset
, boundary
/ BITS_PER_UNIT
);
4252 offset_ptr
->var
= size_binop (MINUS_EXPR
, rounded
, sp_offset_tree
);
4253 /* ARGS_SIZE_TREE includes constant term. */
4254 offset_ptr
->constant
= 0;
4255 if (boundary
> PARM_BOUNDARY
)
4256 alignment_pad
->var
= size_binop (MINUS_EXPR
, offset_ptr
->var
,
4261 offset_ptr
->constant
= -sp_offset
+
4263 ? FLOOR_ROUND (offset_ptr
->constant
+ sp_offset
, boundary_in_bytes
)
4264 : CEIL_ROUND (offset_ptr
->constant
+ sp_offset
, boundary_in_bytes
));
4266 if (boundary
> PARM_BOUNDARY
)
4267 alignment_pad
->constant
= offset_ptr
->constant
- save_constant
;
4273 pad_below (struct args_size
*offset_ptr
, machine_mode passed_mode
, tree sizetree
)
4275 if (passed_mode
!= BLKmode
)
4277 if (GET_MODE_BITSIZE (passed_mode
) % PARM_BOUNDARY
)
4278 offset_ptr
->constant
4279 += (((GET_MODE_BITSIZE (passed_mode
) + PARM_BOUNDARY
- 1)
4280 / PARM_BOUNDARY
* PARM_BOUNDARY
/ BITS_PER_UNIT
)
4281 - GET_MODE_SIZE (passed_mode
));
4285 if (TREE_CODE (sizetree
) != INTEGER_CST
4286 || (TREE_INT_CST_LOW (sizetree
) * BITS_PER_UNIT
) % PARM_BOUNDARY
)
4288 /* Round the size up to multiple of PARM_BOUNDARY bits. */
4289 tree s2
= round_up (sizetree
, PARM_BOUNDARY
/ BITS_PER_UNIT
);
4291 ADD_PARM_SIZE (*offset_ptr
, s2
);
4292 SUB_PARM_SIZE (*offset_ptr
, sizetree
);
4298 /* True if register REGNO was alive at a place where `setjmp' was
4299 called and was set more than once or is an argument. Such regs may
4300 be clobbered by `longjmp'. */
4303 regno_clobbered_at_setjmp (bitmap setjmp_crosses
, int regno
)
4305 /* There appear to be cases where some local vars never reach the
4306 backend but have bogus regnos. */
4307 if (regno
>= max_reg_num ())
4310 return ((REG_N_SETS (regno
) > 1
4311 || REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun
)),
4313 && REGNO_REG_SET_P (setjmp_crosses
, regno
));
4316 /* Walk the tree of blocks describing the binding levels within a
4317 function and warn about variables the might be killed by setjmp or
4318 vfork. This is done after calling flow_analysis before register
4319 allocation since that will clobber the pseudo-regs to hard
4323 setjmp_vars_warning (bitmap setjmp_crosses
, tree block
)
4327 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
4329 if (TREE_CODE (decl
) == VAR_DECL
4330 && DECL_RTL_SET_P (decl
)
4331 && REG_P (DECL_RTL (decl
))
4332 && regno_clobbered_at_setjmp (setjmp_crosses
, REGNO (DECL_RTL (decl
))))
4333 warning (OPT_Wclobbered
, "variable %q+D might be clobbered by"
4334 " %<longjmp%> or %<vfork%>", decl
);
4337 for (sub
= BLOCK_SUBBLOCKS (block
); sub
; sub
= BLOCK_CHAIN (sub
))
4338 setjmp_vars_warning (setjmp_crosses
, sub
);
4341 /* Do the appropriate part of setjmp_vars_warning
4342 but for arguments instead of local variables. */
4345 setjmp_args_warning (bitmap setjmp_crosses
)
4348 for (decl
= DECL_ARGUMENTS (current_function_decl
);
4349 decl
; decl
= DECL_CHAIN (decl
))
4350 if (DECL_RTL (decl
) != 0
4351 && REG_P (DECL_RTL (decl
))
4352 && regno_clobbered_at_setjmp (setjmp_crosses
, REGNO (DECL_RTL (decl
))))
4353 warning (OPT_Wclobbered
,
4354 "argument %q+D might be clobbered by %<longjmp%> or %<vfork%>",
4358 /* Generate warning messages for variables live across setjmp. */
4361 generate_setjmp_warnings (void)
4363 bitmap setjmp_crosses
= regstat_get_setjmp_crosses ();
4365 if (n_basic_blocks_for_fn (cfun
) == NUM_FIXED_BLOCKS
4366 || bitmap_empty_p (setjmp_crosses
))
4369 setjmp_vars_warning (setjmp_crosses
, DECL_INITIAL (current_function_decl
));
4370 setjmp_args_warning (setjmp_crosses
);
4374 /* Reverse the order of elements in the fragment chain T of blocks,
4375 and return the new head of the chain (old last element).
4376 In addition to that clear BLOCK_SAME_RANGE flags when needed
4377 and adjust BLOCK_SUPERCONTEXT from the super fragment to
4378 its super fragment origin. */
4381 block_fragments_nreverse (tree t
)
4383 tree prev
= 0, block
, next
, prev_super
= 0;
4384 tree super
= BLOCK_SUPERCONTEXT (t
);
4385 if (BLOCK_FRAGMENT_ORIGIN (super
))
4386 super
= BLOCK_FRAGMENT_ORIGIN (super
);
4387 for (block
= t
; block
; block
= next
)
4389 next
= BLOCK_FRAGMENT_CHAIN (block
);
4390 BLOCK_FRAGMENT_CHAIN (block
) = prev
;
4391 if ((prev
&& !BLOCK_SAME_RANGE (prev
))
4392 || (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (block
))
4394 BLOCK_SAME_RANGE (block
) = 0;
4395 prev_super
= BLOCK_SUPERCONTEXT (block
);
4396 BLOCK_SUPERCONTEXT (block
) = super
;
4399 t
= BLOCK_FRAGMENT_ORIGIN (t
);
4400 if (BLOCK_FRAGMENT_CHAIN (BLOCK_SUPERCONTEXT (t
))
4402 BLOCK_SAME_RANGE (t
) = 0;
4403 BLOCK_SUPERCONTEXT (t
) = super
;
4407 /* Reverse the order of elements in the chain T of blocks,
4408 and return the new head of the chain (old last element).
4409 Also do the same on subblocks and reverse the order of elements
4410 in BLOCK_FRAGMENT_CHAIN as well. */
4413 blocks_nreverse_all (tree t
)
4415 tree prev
= 0, block
, next
;
4416 for (block
= t
; block
; block
= next
)
4418 next
= BLOCK_CHAIN (block
);
4419 BLOCK_CHAIN (block
) = prev
;
4420 if (BLOCK_FRAGMENT_CHAIN (block
)
4421 && BLOCK_FRAGMENT_ORIGIN (block
) == NULL_TREE
)
4423 BLOCK_FRAGMENT_CHAIN (block
)
4424 = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block
));
4425 if (!BLOCK_SAME_RANGE (BLOCK_FRAGMENT_CHAIN (block
)))
4426 BLOCK_SAME_RANGE (block
) = 0;
4428 BLOCK_SUBBLOCKS (block
) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block
));
4435 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
4436 and create duplicate blocks. */
4437 /* ??? Need an option to either create block fragments or to create
4438 abstract origin duplicates of a source block. It really depends
4439 on what optimization has been performed. */
4442 reorder_blocks (void)
4444 tree block
= DECL_INITIAL (current_function_decl
);
4446 if (block
== NULL_TREE
)
4449 auto_vec
<tree
, 10> block_stack
;
4451 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */
4452 clear_block_marks (block
);
4454 /* Prune the old trees away, so that they don't get in the way. */
4455 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
4456 BLOCK_CHAIN (block
) = NULL_TREE
;
4458 /* Recreate the block tree from the note nesting. */
4459 reorder_blocks_1 (get_insns (), block
, &block_stack
);
4460 BLOCK_SUBBLOCKS (block
) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block
));
4463 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */
4466 clear_block_marks (tree block
)
4470 TREE_ASM_WRITTEN (block
) = 0;
4471 clear_block_marks (BLOCK_SUBBLOCKS (block
));
4472 block
= BLOCK_CHAIN (block
);
4477 reorder_blocks_1 (rtx_insn
*insns
, tree current_block
,
4478 vec
<tree
> *p_block_stack
)
4481 tree prev_beg
= NULL_TREE
, prev_end
= NULL_TREE
;
4483 for (insn
= insns
; insn
; insn
= NEXT_INSN (insn
))
4487 if (NOTE_KIND (insn
) == NOTE_INSN_BLOCK_BEG
)
4489 tree block
= NOTE_BLOCK (insn
);
4492 gcc_assert (BLOCK_FRAGMENT_ORIGIN (block
) == NULL_TREE
);
4496 BLOCK_SAME_RANGE (prev_end
) = 0;
4497 prev_end
= NULL_TREE
;
4499 /* If we have seen this block before, that means it now
4500 spans multiple address regions. Create a new fragment. */
4501 if (TREE_ASM_WRITTEN (block
))
4503 tree new_block
= copy_node (block
);
4505 BLOCK_SAME_RANGE (new_block
) = 0;
4506 BLOCK_FRAGMENT_ORIGIN (new_block
) = origin
;
4507 BLOCK_FRAGMENT_CHAIN (new_block
)
4508 = BLOCK_FRAGMENT_CHAIN (origin
);
4509 BLOCK_FRAGMENT_CHAIN (origin
) = new_block
;
4511 NOTE_BLOCK (insn
) = new_block
;
4515 if (prev_beg
== current_block
&& prev_beg
)
4516 BLOCK_SAME_RANGE (block
) = 1;
4520 BLOCK_SUBBLOCKS (block
) = 0;
4521 TREE_ASM_WRITTEN (block
) = 1;
4522 /* When there's only one block for the entire function,
4523 current_block == block and we mustn't do this, it
4524 will cause infinite recursion. */
4525 if (block
!= current_block
)
4528 if (block
!= origin
)
4529 gcc_assert (BLOCK_SUPERCONTEXT (origin
) == current_block
4530 || BLOCK_FRAGMENT_ORIGIN (BLOCK_SUPERCONTEXT
4533 if (p_block_stack
->is_empty ())
4534 super
= current_block
;
4537 super
= p_block_stack
->last ();
4538 gcc_assert (super
== current_block
4539 || BLOCK_FRAGMENT_ORIGIN (super
)
4542 BLOCK_SUPERCONTEXT (block
) = super
;
4543 BLOCK_CHAIN (block
) = BLOCK_SUBBLOCKS (current_block
);
4544 BLOCK_SUBBLOCKS (current_block
) = block
;
4545 current_block
= origin
;
4547 p_block_stack
->safe_push (block
);
4549 else if (NOTE_KIND (insn
) == NOTE_INSN_BLOCK_END
)
4551 NOTE_BLOCK (insn
) = p_block_stack
->pop ();
4552 current_block
= BLOCK_SUPERCONTEXT (current_block
);
4553 if (BLOCK_FRAGMENT_ORIGIN (current_block
))
4554 current_block
= BLOCK_FRAGMENT_ORIGIN (current_block
);
4555 prev_beg
= NULL_TREE
;
4556 prev_end
= BLOCK_SAME_RANGE (NOTE_BLOCK (insn
))
4557 ? NOTE_BLOCK (insn
) : NULL_TREE
;
4562 prev_beg
= NULL_TREE
;
4564 BLOCK_SAME_RANGE (prev_end
) = 0;
4565 prev_end
= NULL_TREE
;
4570 /* Reverse the order of elements in the chain T of blocks,
4571 and return the new head of the chain (old last element). */
4574 blocks_nreverse (tree t
)
4576 tree prev
= 0, block
, next
;
4577 for (block
= t
; block
; block
= next
)
4579 next
= BLOCK_CHAIN (block
);
4580 BLOCK_CHAIN (block
) = prev
;
4586 /* Concatenate two chains of blocks (chained through BLOCK_CHAIN)
4587 by modifying the last node in chain 1 to point to chain 2. */
4590 block_chainon (tree op1
, tree op2
)
4599 for (t1
= op1
; BLOCK_CHAIN (t1
); t1
= BLOCK_CHAIN (t1
))
4601 BLOCK_CHAIN (t1
) = op2
;
4603 #ifdef ENABLE_TREE_CHECKING
4606 for (t2
= op2
; t2
; t2
= BLOCK_CHAIN (t2
))
4607 gcc_assert (t2
!= t1
);
4614 /* Count the subblocks of the list starting with BLOCK. If VECTOR is
4615 non-NULL, list them all into VECTOR, in a depth-first preorder
4616 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all
4620 all_blocks (tree block
, tree
*vector
)
4626 TREE_ASM_WRITTEN (block
) = 0;
4628 /* Record this block. */
4630 vector
[n_blocks
] = block
;
4634 /* Record the subblocks, and their subblocks... */
4635 n_blocks
+= all_blocks (BLOCK_SUBBLOCKS (block
),
4636 vector
? vector
+ n_blocks
: 0);
4637 block
= BLOCK_CHAIN (block
);
4643 /* Return a vector containing all the blocks rooted at BLOCK. The
4644 number of elements in the vector is stored in N_BLOCKS_P. The
4645 vector is dynamically allocated; it is the caller's responsibility
4646 to call `free' on the pointer returned. */
4649 get_block_vector (tree block
, int *n_blocks_p
)
4653 *n_blocks_p
= all_blocks (block
, NULL
);
4654 block_vector
= XNEWVEC (tree
, *n_blocks_p
);
4655 all_blocks (block
, block_vector
);
4657 return block_vector
;
4660 static GTY(()) int next_block_index
= 2;
4662 /* Set BLOCK_NUMBER for all the blocks in FN. */
4665 number_blocks (tree fn
)
4671 /* For SDB and XCOFF debugging output, we start numbering the blocks
4672 from 1 within each function, rather than keeping a running
4674 #if SDB_DEBUGGING_INFO || defined (XCOFF_DEBUGGING_INFO)
4675 if (write_symbols
== SDB_DEBUG
|| write_symbols
== XCOFF_DEBUG
)
4676 next_block_index
= 1;
4679 block_vector
= get_block_vector (DECL_INITIAL (fn
), &n_blocks
);
4681 /* The top-level BLOCK isn't numbered at all. */
4682 for (i
= 1; i
< n_blocks
; ++i
)
4683 /* We number the blocks from two. */
4684 BLOCK_NUMBER (block_vector
[i
]) = next_block_index
++;
4686 free (block_vector
);
4691 /* If VAR is present in a subblock of BLOCK, return the subblock. */
4694 debug_find_var_in_block_tree (tree var
, tree block
)
4698 for (t
= BLOCK_VARS (block
); t
; t
= TREE_CHAIN (t
))
4702 for (t
= BLOCK_SUBBLOCKS (block
); t
; t
= TREE_CHAIN (t
))
4704 tree ret
= debug_find_var_in_block_tree (var
, t
);
4712 /* Keep track of whether we're in a dummy function context. If we are,
4713 we don't want to invoke the set_current_function hook, because we'll
4714 get into trouble if the hook calls target_reinit () recursively or
4715 when the initial initialization is not yet complete. */
4717 static bool in_dummy_function
;
4719 /* Invoke the target hook when setting cfun. Update the optimization options
4720 if the function uses different options than the default. */
4723 invoke_set_current_function_hook (tree fndecl
)
4725 if (!in_dummy_function
)
4727 tree opts
= ((fndecl
)
4728 ? DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl
)
4729 : optimization_default_node
);
4732 opts
= optimization_default_node
;
4734 /* Change optimization options if needed. */
4735 if (optimization_current_node
!= opts
)
4737 optimization_current_node
= opts
;
4738 cl_optimization_restore (&global_options
, TREE_OPTIMIZATION (opts
));
4741 targetm
.set_current_function (fndecl
);
4742 this_fn_optabs
= this_target_optabs
;
4744 if (opts
!= optimization_default_node
)
4746 init_tree_optimization_optabs (opts
);
4747 if (TREE_OPTIMIZATION_OPTABS (opts
))
4748 this_fn_optabs
= (struct target_optabs
*)
4749 TREE_OPTIMIZATION_OPTABS (opts
);
4754 /* cfun should never be set directly; use this function. */
4757 set_cfun (struct function
*new_cfun
)
4759 if (cfun
!= new_cfun
)
4762 invoke_set_current_function_hook (new_cfun
? new_cfun
->decl
: NULL_TREE
);
4766 /* Initialized with NOGC, making this poisonous to the garbage collector. */
4768 static vec
<function
*> cfun_stack
;
4770 /* Push the current cfun onto the stack, and set cfun to new_cfun. Also set
4771 current_function_decl accordingly. */
4774 push_cfun (struct function
*new_cfun
)
4776 gcc_assert ((!cfun
&& !current_function_decl
)
4777 || (cfun
&& current_function_decl
== cfun
->decl
));
4778 cfun_stack
.safe_push (cfun
);
4779 current_function_decl
= new_cfun
? new_cfun
->decl
: NULL_TREE
;
4780 set_cfun (new_cfun
);
4783 /* Pop cfun from the stack. Also set current_function_decl accordingly. */
4788 struct function
*new_cfun
= cfun_stack
.pop ();
4789 /* When in_dummy_function, we do have a cfun but current_function_decl is
4790 NULL. We also allow pushing NULL cfun and subsequently changing
4791 current_function_decl to something else and have both restored by
4793 gcc_checking_assert (in_dummy_function
4795 || current_function_decl
== cfun
->decl
);
4796 set_cfun (new_cfun
);
4797 current_function_decl
= new_cfun
? new_cfun
->decl
: NULL_TREE
;
4800 /* Return value of funcdef and increase it. */
4802 get_next_funcdef_no (void)
4804 return funcdef_no
++;
4807 /* Return value of funcdef. */
4809 get_last_funcdef_no (void)
4814 /* Allocate a function structure for FNDECL and set its contents
4815 to the defaults. Set cfun to the newly-allocated object.
4816 Some of the helper functions invoked during initialization assume
4817 that cfun has already been set. Therefore, assign the new object
4818 directly into cfun and invoke the back end hook explicitly at the
4819 very end, rather than initializing a temporary and calling set_cfun
4822 ABSTRACT_P is true if this is a function that will never be seen by
4823 the middle-end. Such functions are front-end concepts (like C++
4824 function templates) that do not correspond directly to functions
4825 placed in object files. */
4828 allocate_struct_function (tree fndecl
, bool abstract_p
)
4830 tree fntype
= fndecl
? TREE_TYPE (fndecl
) : NULL_TREE
;
4832 cfun
= ggc_cleared_alloc
<function
> ();
4834 init_eh_for_function ();
4836 if (init_machine_status
)
4837 cfun
->machine
= (*init_machine_status
) ();
4839 #ifdef OVERRIDE_ABI_FORMAT
4840 OVERRIDE_ABI_FORMAT (fndecl
);
4843 if (fndecl
!= NULL_TREE
)
4845 DECL_STRUCT_FUNCTION (fndecl
) = cfun
;
4846 cfun
->decl
= fndecl
;
4847 current_function_funcdef_no
= get_next_funcdef_no ();
4850 invoke_set_current_function_hook (fndecl
);
4852 if (fndecl
!= NULL_TREE
)
4854 tree result
= DECL_RESULT (fndecl
);
4858 /* Now that we have activated any function-specific attributes
4859 that might affect layout, particularly vector modes, relayout
4860 each of the parameters and the result. */
4861 relayout_decl (result
);
4862 for (tree parm
= DECL_ARGUMENTS (fndecl
); parm
;
4863 parm
= DECL_CHAIN (parm
))
4864 relayout_decl (parm
);
4866 /* Similarly relayout the function decl. */
4867 targetm
.target_option
.relayout_function (fndecl
);
4870 if (!abstract_p
&& aggregate_value_p (result
, fndecl
))
4872 #ifdef PCC_STATIC_STRUCT_RETURN
4873 cfun
->returns_pcc_struct
= 1;
4875 cfun
->returns_struct
= 1;
4878 cfun
->stdarg
= stdarg_p (fntype
);
4880 /* Assume all registers in stdarg functions need to be saved. */
4881 cfun
->va_list_gpr_size
= VA_LIST_MAX_GPR_SIZE
;
4882 cfun
->va_list_fpr_size
= VA_LIST_MAX_FPR_SIZE
;
4884 /* ??? This could be set on a per-function basis by the front-end
4885 but is this worth the hassle? */
4886 cfun
->can_throw_non_call_exceptions
= flag_non_call_exceptions
;
4887 cfun
->can_delete_dead_exceptions
= flag_delete_dead_exceptions
;
4889 if (!profile_flag
&& !flag_instrument_function_entry_exit
)
4890 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (fndecl
) = 1;
4894 /* This is like allocate_struct_function, but pushes a new cfun for FNDECL
4895 instead of just setting it. */
4898 push_struct_function (tree fndecl
)
4900 /* When in_dummy_function we might be in the middle of a pop_cfun and
4901 current_function_decl and cfun may not match. */
4902 gcc_assert (in_dummy_function
4903 || (!cfun
&& !current_function_decl
)
4904 || (cfun
&& current_function_decl
== cfun
->decl
));
4905 cfun_stack
.safe_push (cfun
);
4906 current_function_decl
= fndecl
;
4907 allocate_struct_function (fndecl
, false);
4910 /* Reset crtl and other non-struct-function variables to defaults as
4911 appropriate for emitting rtl at the start of a function. */
4914 prepare_function_start (void)
4916 gcc_assert (!get_last_insn ());
4919 init_varasm_status ();
4921 default_rtl_profile ();
4923 if (flag_stack_usage_info
)
4925 cfun
->su
= ggc_cleared_alloc
<stack_usage
> ();
4926 cfun
->su
->static_stack_size
= -1;
4929 cse_not_expected
= ! optimize
;
4931 /* Caller save not needed yet. */
4932 caller_save_needed
= 0;
4934 /* We haven't done register allocation yet. */
4937 /* Indicate that we have not instantiated virtual registers yet. */
4938 virtuals_instantiated
= 0;
4940 /* Indicate that we want CONCATs now. */
4941 generating_concat_p
= 1;
4943 /* Indicate we have no need of a frame pointer yet. */
4944 frame_pointer_needed
= 0;
4948 push_dummy_function (bool with_decl
)
4950 tree fn_decl
, fn_type
, fn_result_decl
;
4952 gcc_assert (!in_dummy_function
);
4953 in_dummy_function
= true;
4957 fn_type
= build_function_type_list (void_type_node
, NULL_TREE
);
4958 fn_decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
4960 fn_result_decl
= build_decl (UNKNOWN_LOCATION
, RESULT_DECL
,
4961 NULL_TREE
, void_type_node
);
4962 DECL_RESULT (fn_decl
) = fn_result_decl
;
4965 fn_decl
= NULL_TREE
;
4967 push_struct_function (fn_decl
);
4970 /* Initialize the rtl expansion mechanism so that we can do simple things
4971 like generate sequences. This is used to provide a context during global
4972 initialization of some passes. You must call expand_dummy_function_end
4973 to exit this context. */
4976 init_dummy_function_start (void)
4978 push_dummy_function (false);
4979 prepare_function_start ();
4982 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
4983 and initialize static variables for generating RTL for the statements
4987 init_function_start (tree subr
)
4989 /* Initialize backend, if needed. */
4992 prepare_function_start ();
4993 decide_function_section (subr
);
4995 /* Warn if this value is an aggregate type,
4996 regardless of which calling convention we are using for it. */
4997 if (AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr
))))
4998 warning (OPT_Waggregate_return
, "function returns an aggregate");
5001 /* Expand code to verify the stack_protect_guard. This is invoked at
5002 the end of a function to be protected. */
5005 stack_protect_epilogue (void)
5007 tree guard_decl
= targetm
.stack_protect_guard ();
5008 rtx_code_label
*label
= gen_label_rtx ();
5012 x
= expand_normal (crtl
->stack_protect_guard
);
5013 y
= expand_normal (guard_decl
);
5015 /* Allow the target to compare Y with X without leaking either into
5017 if (targetm
.have_stack_protect_test ()
5018 && ((seq
= targetm
.gen_stack_protect_test (x
, y
, label
)) != NULL_RTX
))
5021 emit_cmp_and_jump_insns (x
, y
, EQ
, NULL_RTX
, ptr_mode
, 1, label
);
5023 /* The noreturn predictor has been moved to the tree level. The rtl-level
5024 predictors estimate this branch about 20%, which isn't enough to get
5025 things moved out of line. Since this is the only extant case of adding
5026 a noreturn function at the rtl level, it doesn't seem worth doing ought
5027 except adding the prediction by hand. */
5028 rtx_insn
*tmp
= get_last_insn ();
5030 predict_insn_def (tmp
, PRED_NORETURN
, TAKEN
);
5032 expand_call (targetm
.stack_protect_fail (), NULL_RTX
, /*ignore=*/true);
5037 /* Start the RTL for a new function, and set variables used for
5039 SUBR is the FUNCTION_DECL node.
5040 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
5041 the function's parameters, which must be run at any return statement. */
5044 expand_function_start (tree subr
)
5046 /* Make sure volatile mem refs aren't considered
5047 valid operands of arithmetic insns. */
5048 init_recog_no_volatile ();
5052 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr
));
5055 = (stack_limit_rtx
!= NULL_RTX
&& ! DECL_NO_LIMIT_STACK (subr
));
5057 /* Make the label for return statements to jump to. Do not special
5058 case machines with special return instructions -- they will be
5059 handled later during jump, ifcvt, or epilogue creation. */
5060 return_label
= gen_label_rtx ();
5062 /* Initialize rtx used to return the value. */
5063 /* Do this before assign_parms so that we copy the struct value address
5064 before any library calls that assign parms might generate. */
5066 /* Decide whether to return the value in memory or in a register. */
5067 tree res
= DECL_RESULT (subr
);
5068 if (aggregate_value_p (res
, subr
))
5070 /* Returning something that won't go in a register. */
5071 rtx value_address
= 0;
5073 #ifdef PCC_STATIC_STRUCT_RETURN
5074 if (cfun
->returns_pcc_struct
)
5076 int size
= int_size_in_bytes (TREE_TYPE (res
));
5077 value_address
= assemble_static_space (size
);
5082 rtx sv
= targetm
.calls
.struct_value_rtx (TREE_TYPE (subr
), 2);
5083 /* Expect to be passed the address of a place to store the value.
5084 If it is passed as an argument, assign_parms will take care of
5088 value_address
= gen_reg_rtx (Pmode
);
5089 emit_move_insn (value_address
, sv
);
5094 rtx x
= value_address
;
5095 if (!DECL_BY_REFERENCE (res
))
5097 x
= gen_rtx_MEM (DECL_MODE (res
), x
);
5098 set_mem_attributes (x
, res
, 1);
5100 set_parm_rtl (res
, x
);
5103 else if (DECL_MODE (res
) == VOIDmode
)
5104 /* If return mode is void, this decl rtl should not be used. */
5105 set_parm_rtl (res
, NULL_RTX
);
5108 /* Compute the return values into a pseudo reg, which we will copy
5109 into the true return register after the cleanups are done. */
5110 tree return_type
= TREE_TYPE (res
);
5111 /* If we may coalesce this result, make sure it has the expected
5113 if (flag_tree_coalesce_vars
&& is_gimple_reg (res
))
5115 tree def
= ssa_default_def (cfun
, res
);
5117 machine_mode mode
= promote_ssa_mode (def
, NULL
);
5118 set_parm_rtl (res
, gen_reg_rtx (mode
));
5120 else if (TYPE_MODE (return_type
) != BLKmode
5121 && targetm
.calls
.return_in_msb (return_type
))
5122 /* expand_function_end will insert the appropriate padding in
5123 this case. Use the return value's natural (unpadded) mode
5124 within the function proper. */
5125 set_parm_rtl (res
, gen_reg_rtx (TYPE_MODE (return_type
)));
5128 /* In order to figure out what mode to use for the pseudo, we
5129 figure out what the mode of the eventual return register will
5130 actually be, and use that. */
5131 rtx hard_reg
= hard_function_value (return_type
, subr
, 0, 1);
5133 /* Structures that are returned in registers are not
5134 aggregate_value_p, so we may see a PARALLEL or a REG. */
5135 if (REG_P (hard_reg
))
5136 set_parm_rtl (res
, gen_reg_rtx (GET_MODE (hard_reg
)));
5139 gcc_assert (GET_CODE (hard_reg
) == PARALLEL
);
5140 set_parm_rtl (res
, gen_group_rtx (hard_reg
));
5144 /* Set DECL_REGISTER flag so that expand_function_end will copy the
5145 result to the real return register(s). */
5146 DECL_REGISTER (res
) = 1;
5148 if (chkp_function_instrumented_p (current_function_decl
))
5150 tree return_type
= TREE_TYPE (res
);
5151 rtx bounds
= targetm
.calls
.chkp_function_value_bounds (return_type
,
5153 SET_DECL_BOUNDS_RTL (res
, bounds
);
5157 /* Initialize rtx for parameters and local variables.
5158 In some cases this requires emitting insns. */
5159 assign_parms (subr
);
5161 /* If function gets a static chain arg, store it. */
5162 if (cfun
->static_chain_decl
)
5164 tree parm
= cfun
->static_chain_decl
;
5169 local
= gen_reg_rtx (promote_decl_mode (parm
, &unsignedp
));
5170 chain
= targetm
.calls
.static_chain (current_function_decl
, true);
5172 set_decl_incoming_rtl (parm
, chain
, false);
5173 set_parm_rtl (parm
, local
);
5174 mark_reg_pointer (local
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm
))));
5176 if (GET_MODE (local
) != GET_MODE (chain
))
5178 convert_move (local
, chain
, unsignedp
);
5179 insn
= get_last_insn ();
5182 insn
= emit_move_insn (local
, chain
);
5184 /* Mark the register as eliminable, similar to parameters. */
5186 && reg_mentioned_p (arg_pointer_rtx
, XEXP (chain
, 0)))
5187 set_dst_reg_note (insn
, REG_EQUIV
, chain
, local
);
5189 /* If we aren't optimizing, save the static chain onto the stack. */
5192 tree saved_static_chain_decl
5193 = build_decl (DECL_SOURCE_LOCATION (parm
), VAR_DECL
,
5194 DECL_NAME (parm
), TREE_TYPE (parm
));
5195 rtx saved_static_chain_rtx
5196 = assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5197 SET_DECL_RTL (saved_static_chain_decl
, saved_static_chain_rtx
);
5198 emit_move_insn (saved_static_chain_rtx
, chain
);
5199 SET_DECL_VALUE_EXPR (parm
, saved_static_chain_decl
);
5200 DECL_HAS_VALUE_EXPR_P (parm
) = 1;
5204 /* If the function receives a non-local goto, then store the
5205 bits we need to restore the frame pointer. */
5206 if (cfun
->nonlocal_goto_save_area
)
5211 tree var
= TREE_OPERAND (cfun
->nonlocal_goto_save_area
, 0);
5212 gcc_assert (DECL_RTL_SET_P (var
));
5214 t_save
= build4 (ARRAY_REF
,
5215 TREE_TYPE (TREE_TYPE (cfun
->nonlocal_goto_save_area
)),
5216 cfun
->nonlocal_goto_save_area
,
5217 integer_zero_node
, NULL_TREE
, NULL_TREE
);
5218 r_save
= expand_expr (t_save
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5219 gcc_assert (GET_MODE (r_save
) == Pmode
);
5221 emit_move_insn (r_save
, targetm
.builtin_setjmp_frame_value ());
5222 update_nonlocal_goto_save_area ();
5225 /* The following was moved from init_function_start.
5226 The move is supposed to make sdb output more accurate. */
5227 /* Indicate the beginning of the function body,
5228 as opposed to parm setup. */
5229 emit_note (NOTE_INSN_FUNCTION_BEG
);
5231 gcc_assert (NOTE_P (get_last_insn ()));
5233 parm_birth_insn
= get_last_insn ();
5238 PROFILE_HOOK (current_function_funcdef_no
);
5242 /* If we are doing generic stack checking, the probe should go here. */
5243 if (flag_stack_check
== GENERIC_STACK_CHECK
)
5244 stack_check_probe_note
= emit_note (NOTE_INSN_DELETED
);
5248 pop_dummy_function (void)
5251 in_dummy_function
= false;
5254 /* Undo the effects of init_dummy_function_start. */
5256 expand_dummy_function_end (void)
5258 gcc_assert (in_dummy_function
);
5260 /* End any sequences that failed to be closed due to syntax errors. */
5261 while (in_sequence_p ())
5264 /* Outside function body, can't compute type's actual size
5265 until next function's body starts. */
5267 free_after_parsing (cfun
);
5268 free_after_compilation (cfun
);
5269 pop_dummy_function ();
5272 /* Helper for diddle_return_value. */
5275 diddle_return_value_1 (void (*doit
) (rtx
, void *), void *arg
, rtx outgoing
)
5280 if (REG_P (outgoing
))
5281 (*doit
) (outgoing
, arg
);
5282 else if (GET_CODE (outgoing
) == PARALLEL
)
5286 for (i
= 0; i
< XVECLEN (outgoing
, 0); i
++)
5288 rtx x
= XEXP (XVECEXP (outgoing
, 0, i
), 0);
5290 if (REG_P (x
) && REGNO (x
) < FIRST_PSEUDO_REGISTER
)
5296 /* Call DOIT for each hard register used as a return value from
5297 the current function. */
5300 diddle_return_value (void (*doit
) (rtx
, void *), void *arg
)
5302 diddle_return_value_1 (doit
, arg
, crtl
->return_bnd
);
5303 diddle_return_value_1 (doit
, arg
, crtl
->return_rtx
);
5307 do_clobber_return_reg (rtx reg
, void *arg ATTRIBUTE_UNUSED
)
5313 clobber_return_register (void)
5315 diddle_return_value (do_clobber_return_reg
, NULL
);
5317 /* In case we do use pseudo to return value, clobber it too. */
5318 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
5320 tree decl_result
= DECL_RESULT (current_function_decl
);
5321 rtx decl_rtl
= DECL_RTL (decl_result
);
5322 if (REG_P (decl_rtl
) && REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
)
5324 do_clobber_return_reg (decl_rtl
, NULL
);
5330 do_use_return_reg (rtx reg
, void *arg ATTRIBUTE_UNUSED
)
5336 use_return_register (void)
5338 diddle_return_value (do_use_return_reg
, NULL
);
5341 /* Set the location of the insn chain starting at INSN to LOC. */
5344 set_insn_locations (rtx_insn
*insn
, int loc
)
5346 while (insn
!= NULL
)
5349 INSN_LOCATION (insn
) = loc
;
5350 insn
= NEXT_INSN (insn
);
5354 /* Generate RTL for the end of the current function. */
5357 expand_function_end (void)
5359 /* If arg_pointer_save_area was referenced only from a nested
5360 function, we will not have initialized it yet. Do that now. */
5361 if (arg_pointer_save_area
&& ! crtl
->arg_pointer_save_area_init
)
5362 get_arg_pointer_save_area ();
5364 /* If we are doing generic stack checking and this function makes calls,
5365 do a stack probe at the start of the function to ensure we have enough
5366 space for another stack frame. */
5367 if (flag_stack_check
== GENERIC_STACK_CHECK
)
5369 rtx_insn
*insn
, *seq
;
5371 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
5374 rtx max_frame_size
= GEN_INT (STACK_CHECK_MAX_FRAME_SIZE
);
5376 if (STACK_CHECK_MOVING_SP
)
5377 anti_adjust_stack_and_probe (max_frame_size
, true);
5379 probe_stack_range (STACK_OLD_CHECK_PROTECT
, max_frame_size
);
5382 set_insn_locations (seq
, prologue_location
);
5383 emit_insn_before (seq
, stack_check_probe_note
);
5388 /* End any sequences that failed to be closed due to syntax errors. */
5389 while (in_sequence_p ())
5392 clear_pending_stack_adjust ();
5393 do_pending_stack_adjust ();
5395 /* Output a linenumber for the end of the function.
5396 SDB depends on this. */
5397 set_curr_insn_location (input_location
);
5399 /* Before the return label (if any), clobber the return
5400 registers so that they are not propagated live to the rest of
5401 the function. This can only happen with functions that drop
5402 through; if there had been a return statement, there would
5403 have either been a return rtx, or a jump to the return label.
5405 We delay actual code generation after the current_function_value_rtx
5407 rtx_insn
*clobber_after
= get_last_insn ();
5409 /* Output the label for the actual return from the function. */
5410 emit_label (return_label
);
5412 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
5414 /* Let except.c know where it should emit the call to unregister
5415 the function context for sjlj exceptions. */
5416 if (flag_exceptions
)
5417 sjlj_emit_function_exit_after (get_last_insn ());
5421 /* We want to ensure that instructions that may trap are not
5422 moved into the epilogue by scheduling, because we don't
5423 always emit unwind information for the epilogue. */
5424 if (cfun
->can_throw_non_call_exceptions
)
5425 emit_insn (gen_blockage ());
5428 /* If this is an implementation of throw, do what's necessary to
5429 communicate between __builtin_eh_return and the epilogue. */
5430 expand_eh_return ();
5432 /* If scalar return value was computed in a pseudo-reg, or was a named
5433 return value that got dumped to the stack, copy that to the hard
5435 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl
)))
5437 tree decl_result
= DECL_RESULT (current_function_decl
);
5438 rtx decl_rtl
= DECL_RTL (decl_result
);
5440 if (REG_P (decl_rtl
)
5441 ? REGNO (decl_rtl
) >= FIRST_PSEUDO_REGISTER
5442 : DECL_REGISTER (decl_result
))
5444 rtx real_decl_rtl
= crtl
->return_rtx
;
5446 /* This should be set in assign_parms. */
5447 gcc_assert (REG_FUNCTION_VALUE_P (real_decl_rtl
));
5449 /* If this is a BLKmode structure being returned in registers,
5450 then use the mode computed in expand_return. Note that if
5451 decl_rtl is memory, then its mode may have been changed,
5452 but that crtl->return_rtx has not. */
5453 if (GET_MODE (real_decl_rtl
) == BLKmode
)
5454 PUT_MODE (real_decl_rtl
, GET_MODE (decl_rtl
));
5456 /* If a non-BLKmode return value should be padded at the least
5457 significant end of the register, shift it left by the appropriate
5458 amount. BLKmode results are handled using the group load/store
5460 if (TYPE_MODE (TREE_TYPE (decl_result
)) != BLKmode
5461 && REG_P (real_decl_rtl
)
5462 && targetm
.calls
.return_in_msb (TREE_TYPE (decl_result
)))
5464 emit_move_insn (gen_rtx_REG (GET_MODE (decl_rtl
),
5465 REGNO (real_decl_rtl
)),
5467 shift_return_value (GET_MODE (decl_rtl
), true, real_decl_rtl
);
5469 else if (GET_CODE (real_decl_rtl
) == PARALLEL
)
5471 /* If expand_function_start has created a PARALLEL for decl_rtl,
5472 move the result to the real return registers. Otherwise, do
5473 a group load from decl_rtl for a named return. */
5474 if (GET_CODE (decl_rtl
) == PARALLEL
)
5475 emit_group_move (real_decl_rtl
, decl_rtl
);
5477 emit_group_load (real_decl_rtl
, decl_rtl
,
5478 TREE_TYPE (decl_result
),
5479 int_size_in_bytes (TREE_TYPE (decl_result
)));
5481 /* In the case of complex integer modes smaller than a word, we'll
5482 need to generate some non-trivial bitfield insertions. Do that
5483 on a pseudo and not the hard register. */
5484 else if (GET_CODE (decl_rtl
) == CONCAT
5485 && GET_MODE_CLASS (GET_MODE (decl_rtl
)) == MODE_COMPLEX_INT
5486 && GET_MODE_BITSIZE (GET_MODE (decl_rtl
)) <= BITS_PER_WORD
)
5488 int old_generating_concat_p
;
5491 old_generating_concat_p
= generating_concat_p
;
5492 generating_concat_p
= 0;
5493 tmp
= gen_reg_rtx (GET_MODE (decl_rtl
));
5494 generating_concat_p
= old_generating_concat_p
;
5496 emit_move_insn (tmp
, decl_rtl
);
5497 emit_move_insn (real_decl_rtl
, tmp
);
5499 /* If a named return value dumped decl_return to memory, then
5500 we may need to re-do the PROMOTE_MODE signed/unsigned
5502 else if (GET_MODE (real_decl_rtl
) != GET_MODE (decl_rtl
))
5504 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (decl_result
));
5505 promote_function_mode (TREE_TYPE (decl_result
),
5506 GET_MODE (decl_rtl
), &unsignedp
,
5507 TREE_TYPE (current_function_decl
), 1);
5509 convert_move (real_decl_rtl
, decl_rtl
, unsignedp
);
5512 emit_move_insn (real_decl_rtl
, decl_rtl
);
5516 /* If returning a structure, arrange to return the address of the value
5517 in a place where debuggers expect to find it.
5519 If returning a structure PCC style,
5520 the caller also depends on this value.
5521 And cfun->returns_pcc_struct is not necessarily set. */
5522 if ((cfun
->returns_struct
|| cfun
->returns_pcc_struct
)
5523 && !targetm
.calls
.omit_struct_return_reg
)
5525 rtx value_address
= DECL_RTL (DECL_RESULT (current_function_decl
));
5526 tree type
= TREE_TYPE (DECL_RESULT (current_function_decl
));
5529 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl
)))
5530 type
= TREE_TYPE (type
);
5532 value_address
= XEXP (value_address
, 0);
5534 outgoing
= targetm
.calls
.function_value (build_pointer_type (type
),
5535 current_function_decl
, true);
5537 /* Mark this as a function return value so integrate will delete the
5538 assignment and USE below when inlining this function. */
5539 REG_FUNCTION_VALUE_P (outgoing
) = 1;
5541 /* The address may be ptr_mode and OUTGOING may be Pmode. */
5542 value_address
= convert_memory_address (GET_MODE (outgoing
),
5545 emit_move_insn (outgoing
, value_address
);
5547 /* Show return register used to hold result (in this case the address
5549 crtl
->return_rtx
= outgoing
;
5552 /* Emit the actual code to clobber return register. Don't emit
5553 it if clobber_after is a barrier, then the previous basic block
5554 certainly doesn't fall thru into the exit block. */
5555 if (!BARRIER_P (clobber_after
))
5558 clobber_return_register ();
5559 rtx_insn
*seq
= get_insns ();
5562 emit_insn_after (seq
, clobber_after
);
5565 /* Output the label for the naked return from the function. */
5566 if (naked_return_label
)
5567 emit_label (naked_return_label
);
5569 /* @@@ This is a kludge. We want to ensure that instructions that
5570 may trap are not moved into the epilogue by scheduling, because
5571 we don't always emit unwind information for the epilogue. */
5572 if (cfun
->can_throw_non_call_exceptions
5573 && targetm_common
.except_unwind_info (&global_options
) != UI_SJLJ
)
5574 emit_insn (gen_blockage ());
5576 /* If stack protection is enabled for this function, check the guard. */
5577 if (crtl
->stack_protect_guard
)
5578 stack_protect_epilogue ();
5580 /* If we had calls to alloca, and this machine needs
5581 an accurate stack pointer to exit the function,
5582 insert some code to save and restore the stack pointer. */
5583 if (! EXIT_IGNORE_STACK
5584 && cfun
->calls_alloca
)
5589 emit_stack_save (SAVE_FUNCTION
, &tem
);
5590 rtx_insn
*seq
= get_insns ();
5592 emit_insn_before (seq
, parm_birth_insn
);
5594 emit_stack_restore (SAVE_FUNCTION
, tem
);
5597 /* ??? This should no longer be necessary since stupid is no longer with
5598 us, but there are some parts of the compiler (eg reload_combine, and
5599 sh mach_dep_reorg) that still try and compute their own lifetime info
5600 instead of using the general framework. */
5601 use_return_register ();
5605 get_arg_pointer_save_area (void)
5607 rtx ret
= arg_pointer_save_area
;
5611 ret
= assign_stack_local (Pmode
, GET_MODE_SIZE (Pmode
), 0);
5612 arg_pointer_save_area
= ret
;
5615 if (! crtl
->arg_pointer_save_area_init
)
5617 /* Save the arg pointer at the beginning of the function. The
5618 generated stack slot may not be a valid memory address, so we
5619 have to check it and fix it if necessary. */
5621 emit_move_insn (validize_mem (copy_rtx (ret
)),
5622 crtl
->args
.internal_arg_pointer
);
5623 rtx_insn
*seq
= get_insns ();
5626 push_topmost_sequence ();
5627 emit_insn_after (seq
, entry_of_function ());
5628 pop_topmost_sequence ();
5630 crtl
->arg_pointer_save_area_init
= true;
5636 /* Add a list of INSNS to the hash HASHP, possibly allocating HASHP
5637 for the first time. */
5640 record_insns (rtx_insn
*insns
, rtx end
, hash_table
<insn_cache_hasher
> **hashp
)
5643 hash_table
<insn_cache_hasher
> *hash
= *hashp
;
5646 *hashp
= hash
= hash_table
<insn_cache_hasher
>::create_ggc (17);
5648 for (tmp
= insns
; tmp
!= end
; tmp
= NEXT_INSN (tmp
))
5650 rtx
*slot
= hash
->find_slot (tmp
, INSERT
);
5651 gcc_assert (*slot
== NULL
);
5656 /* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a
5657 basic block, splitting or peepholes. If INSN is a prologue or epilogue
5658 insn, then record COPY as well. */
5661 maybe_copy_prologue_epilogue_insn (rtx insn
, rtx copy
)
5663 hash_table
<insn_cache_hasher
> *hash
;
5666 hash
= epilogue_insn_hash
;
5667 if (!hash
|| !hash
->find (insn
))
5669 hash
= prologue_insn_hash
;
5670 if (!hash
|| !hash
->find (insn
))
5674 slot
= hash
->find_slot (copy
, INSERT
);
5675 gcc_assert (*slot
== NULL
);
5679 /* Determine if any INSNs in HASH are, or are part of, INSN. Because
5680 we can be running after reorg, SEQUENCE rtl is possible. */
5683 contains (const_rtx insn
, hash_table
<insn_cache_hasher
> *hash
)
5688 if (NONJUMP_INSN_P (insn
) && GET_CODE (PATTERN (insn
)) == SEQUENCE
)
5690 rtx_sequence
*seq
= as_a
<rtx_sequence
*> (PATTERN (insn
));
5692 for (i
= seq
->len () - 1; i
>= 0; i
--)
5693 if (hash
->find (seq
->element (i
)))
5698 return hash
->find (const_cast<rtx
> (insn
)) != NULL
;
5702 prologue_epilogue_contains (const_rtx insn
)
5704 if (contains (insn
, prologue_insn_hash
))
5706 if (contains (insn
, epilogue_insn_hash
))
5711 /* Insert use of return register before the end of BB. */
5714 emit_use_return_register_into_block (basic_block bb
)
5717 use_return_register ();
5718 rtx_insn
*seq
= get_insns ();
5720 rtx_insn
*insn
= BB_END (bb
);
5721 if (HAVE_cc0
&& reg_mentioned_p (cc0_rtx
, PATTERN (insn
)))
5722 insn
= prev_cc0_setter (insn
);
5724 emit_insn_before (seq
, insn
);
5728 /* Create a return pattern, either simple_return or return, depending on
5732 gen_return_pattern (bool simple_p
)
5735 ? targetm
.gen_simple_return ()
5736 : targetm
.gen_return ());
5739 /* Insert an appropriate return pattern at the end of block BB. This
5740 also means updating block_for_insn appropriately. SIMPLE_P is
5741 the same as in gen_return_pattern and passed to it. */
5744 emit_return_into_block (bool simple_p
, basic_block bb
)
5746 rtx_jump_insn
*jump
= emit_jump_insn_after (gen_return_pattern (simple_p
),
5748 rtx pat
= PATTERN (jump
);
5749 if (GET_CODE (pat
) == PARALLEL
)
5750 pat
= XVECEXP (pat
, 0, 0);
5751 gcc_assert (ANY_RETURN_P (pat
));
5752 JUMP_LABEL (jump
) = pat
;
5755 /* Set JUMP_LABEL for a return insn. */
5758 set_return_jump_label (rtx_insn
*returnjump
)
5760 rtx pat
= PATTERN (returnjump
);
5761 if (GET_CODE (pat
) == PARALLEL
)
5762 pat
= XVECEXP (pat
, 0, 0);
5763 if (ANY_RETURN_P (pat
))
5764 JUMP_LABEL (returnjump
) = pat
;
5766 JUMP_LABEL (returnjump
) = ret_rtx
;
5769 /* Return true if there are any active insns between HEAD and TAIL. */
5771 active_insn_between (rtx_insn
*head
, rtx_insn
*tail
)
5775 if (active_insn_p (tail
))
5779 tail
= PREV_INSN (tail
);
5784 /* LAST_BB is a block that exits, and empty of active instructions.
5785 Examine its predecessors for jumps that can be converted to
5786 (conditional) returns. */
5788 convert_jumps_to_returns (basic_block last_bb
, bool simple_p
,
5789 vec
<edge
> unconverted ATTRIBUTE_UNUSED
)
5795 auto_vec
<basic_block
> src_bbs (EDGE_COUNT (last_bb
->preds
));
5797 FOR_EACH_EDGE (e
, ei
, last_bb
->preds
)
5798 if (e
->src
!= ENTRY_BLOCK_PTR_FOR_FN (cfun
))
5799 src_bbs
.quick_push (e
->src
);
5801 rtx_insn
*label
= BB_HEAD (last_bb
);
5803 FOR_EACH_VEC_ELT (src_bbs
, i
, bb
)
5805 rtx_insn
*jump
= BB_END (bb
);
5807 if (!JUMP_P (jump
) || JUMP_LABEL (jump
) != label
)
5810 e
= find_edge (bb
, last_bb
);
5812 /* If we have an unconditional jump, we can replace that
5813 with a simple return instruction. */
5814 if (simplejump_p (jump
))
5816 /* The use of the return register might be present in the exit
5817 fallthru block. Either:
5818 - removing the use is safe, and we should remove the use in
5819 the exit fallthru block, or
5820 - removing the use is not safe, and we should add it here.
5821 For now, we conservatively choose the latter. Either of the
5822 2 helps in crossjumping. */
5823 emit_use_return_register_into_block (bb
);
5825 emit_return_into_block (simple_p
, bb
);
5829 /* If we have a conditional jump branching to the last
5830 block, we can try to replace that with a conditional
5831 return instruction. */
5832 else if (condjump_p (jump
))
5837 dest
= simple_return_rtx
;
5840 if (!redirect_jump (as_a
<rtx_jump_insn
*> (jump
), dest
, 0))
5842 if (targetm
.have_simple_return () && simple_p
)
5846 "Failed to redirect bb %d branch.\n", bb
->index
);
5847 unconverted
.safe_push (e
);
5852 /* See comment in simplejump_p case above. */
5853 emit_use_return_register_into_block (bb
);
5855 /* If this block has only one successor, it both jumps
5856 and falls through to the fallthru block, so we can't
5858 if (single_succ_p (bb
))
5863 if (targetm
.have_simple_return () && simple_p
)
5867 "Failed to redirect bb %d branch.\n", bb
->index
);
5868 unconverted
.safe_push (e
);
5873 /* Fix up the CFG for the successful change we just made. */
5874 redirect_edge_succ (e
, EXIT_BLOCK_PTR_FOR_FN (cfun
));
5875 e
->flags
&= ~EDGE_CROSSING
;
5881 /* Emit a return insn for the exit fallthru block. */
5883 emit_return_for_exit (edge exit_fallthru_edge
, bool simple_p
)
5885 basic_block last_bb
= exit_fallthru_edge
->src
;
5887 if (JUMP_P (BB_END (last_bb
)))
5889 last_bb
= split_edge (exit_fallthru_edge
);
5890 exit_fallthru_edge
= single_succ_edge (last_bb
);
5892 emit_barrier_after (BB_END (last_bb
));
5893 emit_return_into_block (simple_p
, last_bb
);
5894 exit_fallthru_edge
->flags
&= ~EDGE_FALLTHRU
;
5899 /* Generate the prologue and epilogue RTL if the machine supports it. Thread
5900 this into place with notes indicating where the prologue ends and where
5901 the epilogue begins. Update the basic block information when possible.
5903 Notes on epilogue placement:
5904 There are several kinds of edges to the exit block:
5905 * a single fallthru edge from LAST_BB
5906 * possibly, edges from blocks containing sibcalls
5907 * possibly, fake edges from infinite loops
5909 The epilogue is always emitted on the fallthru edge from the last basic
5910 block in the function, LAST_BB, into the exit block.
5912 If LAST_BB is empty except for a label, it is the target of every
5913 other basic block in the function that ends in a return. If a
5914 target has a return or simple_return pattern (possibly with
5915 conditional variants), these basic blocks can be changed so that a
5916 return insn is emitted into them, and their target is adjusted to
5917 the real exit block.
5919 Notes on shrink wrapping: We implement a fairly conservative
5920 version of shrink-wrapping rather than the textbook one. We only
5921 generate a single prologue and a single epilogue. This is
5922 sufficient to catch a number of interesting cases involving early
5925 First, we identify the blocks that require the prologue to occur before
5926 them. These are the ones that modify a call-saved register, or reference
5927 any of the stack or frame pointer registers. To simplify things, we then
5928 mark everything reachable from these blocks as also requiring a prologue.
5929 This takes care of loops automatically, and avoids the need to examine
5930 whether MEMs reference the frame, since it is sufficient to check for
5931 occurrences of the stack or frame pointer.
5933 We then compute the set of blocks for which the need for a prologue
5934 is anticipatable (borrowing terminology from the shrink-wrapping
5935 description in Muchnick's book). These are the blocks which either
5936 require a prologue themselves, or those that have only successors
5937 where the prologue is anticipatable. The prologue needs to be
5938 inserted on all edges from BB1->BB2 where BB2 is in ANTIC and BB1
5939 is not. For the moment, we ensure that only one such edge exists.
5941 The epilogue is placed as described above, but we make a
5942 distinction between inserting return and simple_return patterns
5943 when modifying other blocks that end in a return. Blocks that end
5944 in a sibcall omit the sibcall_epilogue if the block is not in
5948 thread_prologue_and_epilogue_insns (void)
5951 vec
<edge
> unconverted_simple_returns
= vNULL
;
5952 bitmap_head bb_flags
;
5953 rtx_insn
*returnjump
;
5954 rtx_insn
*epilogue_end ATTRIBUTE_UNUSED
;
5955 rtx_insn
*prologue_seq ATTRIBUTE_UNUSED
, *split_prologue_seq ATTRIBUTE_UNUSED
;
5956 edge e
, entry_edge
, orig_entry_edge
, exit_fallthru_edge
;
5961 rtl_profile_for_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
5964 epilogue_end
= NULL
;
5967 /* Can't deal with multiple successors of the entry block at the
5968 moment. Function should always have at least one entry
5970 gcc_assert (single_succ_p (ENTRY_BLOCK_PTR_FOR_FN (cfun
)));
5971 entry_edge
= single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun
));
5972 orig_entry_edge
= entry_edge
;
5974 split_prologue_seq
= NULL
;
5975 if (flag_split_stack
5976 && (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun
->decl
))
5980 emit_insn (targetm
.gen_split_stack_prologue ());
5981 split_prologue_seq
= get_insns ();
5984 record_insns (split_prologue_seq
, NULL
, &prologue_insn_hash
);
5985 set_insn_locations (split_prologue_seq
, prologue_location
);
5988 prologue_seq
= NULL
;
5989 if (targetm
.have_prologue ())
5992 rtx_insn
*seq
= targetm
.gen_prologue ();
5995 /* Insert an explicit USE for the frame pointer
5996 if the profiling is on and the frame pointer is required. */
5997 if (crtl
->profile
&& frame_pointer_needed
)
5998 emit_use (hard_frame_pointer_rtx
);
6000 /* Retain a map of the prologue insns. */
6001 record_insns (seq
, NULL
, &prologue_insn_hash
);
6002 emit_note (NOTE_INSN_PROLOGUE_END
);
6004 /* Ensure that instructions are not moved into the prologue when
6005 profiling is on. The call to the profiling routine can be
6006 emitted within the live range of a call-clobbered register. */
6007 if (!targetm
.profile_before_prologue () && crtl
->profile
)
6008 emit_insn (gen_blockage ());
6010 prologue_seq
= get_insns ();
6012 set_insn_locations (prologue_seq
, prologue_location
);
6015 bitmap_initialize (&bb_flags
, &bitmap_default_obstack
);
6017 /* Try to perform a kind of shrink-wrapping, making sure the
6018 prologue/epilogue is emitted only around those parts of the
6019 function that require it. */
6021 try_shrink_wrapping (&entry_edge
, &bb_flags
, prologue_seq
);
6023 if (split_prologue_seq
!= NULL_RTX
)
6025 insert_insn_on_edge (split_prologue_seq
, orig_entry_edge
);
6028 if (prologue_seq
!= NULL_RTX
)
6030 insert_insn_on_edge (prologue_seq
, entry_edge
);
6034 /* If the exit block has no non-fake predecessors, we don't need
6036 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
6037 if ((e
->flags
& EDGE_FAKE
) == 0)
6042 rtl_profile_for_bb (EXIT_BLOCK_PTR_FOR_FN (cfun
));
6044 exit_fallthru_edge
= find_fallthru_edge (EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
);
6046 if (targetm
.have_simple_return () && entry_edge
!= orig_entry_edge
)
6048 = get_unconverted_simple_return (exit_fallthru_edge
, bb_flags
,
6049 &unconverted_simple_returns
,
6051 if (targetm
.have_return ())
6053 if (exit_fallthru_edge
== NULL
)
6058 basic_block last_bb
= exit_fallthru_edge
->src
;
6060 if (LABEL_P (BB_HEAD (last_bb
))
6061 && !active_insn_between (BB_HEAD (last_bb
), BB_END (last_bb
)))
6062 convert_jumps_to_returns (last_bb
, false, vNULL
);
6064 if (EDGE_COUNT (last_bb
->preds
) != 0
6065 && single_succ_p (last_bb
))
6067 last_bb
= emit_return_for_exit (exit_fallthru_edge
, false);
6068 epilogue_end
= returnjump
= BB_END (last_bb
);
6070 /* Emitting the return may add a basic block.
6071 Fix bb_flags for the added block. */
6072 if (targetm
.have_simple_return ()
6073 && last_bb
!= exit_fallthru_edge
->src
)
6074 bitmap_set_bit (&bb_flags
, last_bb
->index
);
6081 /* A small fib -- epilogue is not yet completed, but we wish to re-use
6082 this marker for the splits of EH_RETURN patterns, and nothing else
6083 uses the flag in the meantime. */
6084 epilogue_completed
= 1;
6086 /* Find non-fallthru edges that end with EH_RETURN instructions. On
6087 some targets, these get split to a special version of the epilogue
6088 code. In order to be able to properly annotate these with unwind
6089 info, try to split them now. If we get a valid split, drop an
6090 EPILOGUE_BEG note and mark the insns as epilogue insns. */
6091 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
6093 rtx_insn
*prev
, *last
, *trial
;
6095 if (e
->flags
& EDGE_FALLTHRU
)
6097 last
= BB_END (e
->src
);
6098 if (!eh_returnjump_p (last
))
6101 prev
= PREV_INSN (last
);
6102 trial
= try_split (PATTERN (last
), last
, 1);
6106 record_insns (NEXT_INSN (prev
), NEXT_INSN (trial
), &epilogue_insn_hash
);
6107 emit_note_after (NOTE_INSN_EPILOGUE_BEG
, prev
);
6110 /* If nothing falls through into the exit block, we don't need an
6113 if (exit_fallthru_edge
== NULL
)
6116 if (targetm
.have_epilogue ())
6119 epilogue_end
= emit_note (NOTE_INSN_EPILOGUE_BEG
);
6120 rtx_insn
*seq
= targetm
.gen_epilogue ();
6122 emit_jump_insn (seq
);
6124 /* Retain a map of the epilogue insns. */
6125 record_insns (seq
, NULL
, &epilogue_insn_hash
);
6126 set_insn_locations (seq
, epilogue_location
);
6129 returnjump
= get_last_insn ();
6132 insert_insn_on_edge (seq
, exit_fallthru_edge
);
6135 if (JUMP_P (returnjump
))
6136 set_return_jump_label (returnjump
);
6142 if (! next_active_insn (BB_END (exit_fallthru_edge
->src
)))
6144 /* We have a fall-through edge to the exit block, the source is not
6145 at the end of the function, and there will be an assembler epilogue
6146 at the end of the function.
6147 We can't use force_nonfallthru here, because that would try to
6148 use return. Inserting a jump 'by hand' is extremely messy, so
6149 we take advantage of cfg_layout_finalize using
6150 fixup_fallthru_exit_predecessor. */
6151 cfg_layout_initialize (0);
6152 FOR_EACH_BB_FN (cur_bb
, cfun
)
6153 if (cur_bb
->index
>= NUM_FIXED_BLOCKS
6154 && cur_bb
->next_bb
->index
>= NUM_FIXED_BLOCKS
)
6155 cur_bb
->aux
= cur_bb
->next_bb
;
6156 cfg_layout_finalize ();
6161 default_rtl_profile ();
6167 commit_edge_insertions ();
6169 /* Look for basic blocks within the prologue insns. */
6170 blocks
= sbitmap_alloc (last_basic_block_for_fn (cfun
));
6171 bitmap_clear (blocks
);
6172 bitmap_set_bit (blocks
, entry_edge
->dest
->index
);
6173 bitmap_set_bit (blocks
, orig_entry_edge
->dest
->index
);
6174 find_many_sub_basic_blocks (blocks
);
6175 sbitmap_free (blocks
);
6177 /* The epilogue insns we inserted may cause the exit edge to no longer
6179 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
6181 if (((e
->flags
& EDGE_FALLTHRU
) != 0)
6182 && returnjump_p (BB_END (e
->src
)))
6183 e
->flags
&= ~EDGE_FALLTHRU
;
6187 if (targetm
.have_simple_return ())
6188 convert_to_simple_return (entry_edge
, orig_entry_edge
, bb_flags
,
6189 returnjump
, unconverted_simple_returns
);
6191 /* Emit sibling epilogues before any sibling call sites. */
6192 for (ei
= ei_start (EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
); (e
=
6196 basic_block bb
= e
->src
;
6197 rtx_insn
*insn
= BB_END (bb
);
6200 || ! SIBLING_CALL_P (insn
)
6201 || (targetm
.have_simple_return ()
6202 && entry_edge
!= orig_entry_edge
6203 && !bitmap_bit_p (&bb_flags
, bb
->index
)))
6209 if (rtx_insn
*ep_seq
= targetm
.gen_sibcall_epilogue ())
6212 emit_note (NOTE_INSN_EPILOGUE_BEG
);
6214 rtx_insn
*seq
= get_insns ();
6217 /* Retain a map of the epilogue insns. Used in life analysis to
6218 avoid getting rid of sibcall epilogue insns. Do this before we
6219 actually emit the sequence. */
6220 record_insns (seq
, NULL
, &epilogue_insn_hash
);
6221 set_insn_locations (seq
, epilogue_location
);
6223 emit_insn_before (seq
, insn
);
6230 rtx_insn
*insn
, *next
;
6232 /* Similarly, move any line notes that appear after the epilogue.
6233 There is no need, however, to be quite so anal about the existence
6234 of such a note. Also possibly move
6235 NOTE_INSN_FUNCTION_BEG notes, as those can be relevant for debug
6237 for (insn
= epilogue_end
; insn
; insn
= next
)
6239 next
= NEXT_INSN (insn
);
6241 && (NOTE_KIND (insn
) == NOTE_INSN_FUNCTION_BEG
))
6242 reorder_insns (insn
, insn
, PREV_INSN (epilogue_end
));
6246 bitmap_clear (&bb_flags
);
6248 /* Threading the prologue and epilogue changes the artificial refs
6249 in the entry and exit blocks. */
6250 epilogue_completed
= 1;
6251 df_update_entry_exit_and_calls ();
6254 /* Reposition the prologue-end and epilogue-begin notes after
6255 instruction scheduling. */
6258 reposition_prologue_and_epilogue_notes (void)
6260 if (!targetm
.have_prologue ()
6261 && !targetm
.have_epilogue ()
6262 && !targetm
.have_sibcall_epilogue ())
6265 /* Since the hash table is created on demand, the fact that it is
6266 non-null is a signal that it is non-empty. */
6267 if (prologue_insn_hash
!= NULL
)
6269 size_t len
= prologue_insn_hash
->elements ();
6270 rtx_insn
*insn
, *last
= NULL
, *note
= NULL
;
6272 /* Scan from the beginning until we reach the last prologue insn. */
6273 /* ??? While we do have the CFG intact, there are two problems:
6274 (1) The prologue can contain loops (typically probing the stack),
6275 which means that the end of the prologue isn't in the first bb.
6276 (2) Sometimes the PROLOGUE_END note gets pushed into the next bb. */
6277 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
6281 if (NOTE_KIND (insn
) == NOTE_INSN_PROLOGUE_END
)
6284 else if (contains (insn
, prologue_insn_hash
))
6296 /* Scan forward looking for the PROLOGUE_END note. It should
6297 be right at the beginning of the block, possibly with other
6298 insn notes that got moved there. */
6299 for (note
= NEXT_INSN (last
); ; note
= NEXT_INSN (note
))
6302 && NOTE_KIND (note
) == NOTE_INSN_PROLOGUE_END
)
6307 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */
6309 last
= NEXT_INSN (last
);
6310 reorder_insns (note
, note
, last
);
6314 if (epilogue_insn_hash
!= NULL
)
6319 FOR_EACH_EDGE (e
, ei
, EXIT_BLOCK_PTR_FOR_FN (cfun
)->preds
)
6321 rtx_insn
*insn
, *first
= NULL
, *note
= NULL
;
6322 basic_block bb
= e
->src
;
6324 /* Scan from the beginning until we reach the first epilogue insn. */
6325 FOR_BB_INSNS (bb
, insn
)
6329 if (NOTE_KIND (insn
) == NOTE_INSN_EPILOGUE_BEG
)
6336 else if (first
== NULL
&& contains (insn
, epilogue_insn_hash
))
6346 /* If the function has a single basic block, and no real
6347 epilogue insns (e.g. sibcall with no cleanup), the
6348 epilogue note can get scheduled before the prologue
6349 note. If we have frame related prologue insns, having
6350 them scanned during the epilogue will result in a crash.
6351 In this case re-order the epilogue note to just before
6352 the last insn in the block. */
6354 first
= BB_END (bb
);
6356 if (PREV_INSN (first
) != note
)
6357 reorder_insns (note
, note
, PREV_INSN (first
));
6363 /* Returns the name of function declared by FNDECL. */
6365 fndecl_name (tree fndecl
)
6369 return lang_hooks
.decl_printable_name (fndecl
, 2);
6372 /* Returns the name of function FN. */
6374 function_name (struct function
*fn
)
6376 tree fndecl
= (fn
== NULL
) ? NULL
: fn
->decl
;
6377 return fndecl_name (fndecl
);
6380 /* Returns the name of the current function. */
6382 current_function_name (void)
6384 return function_name (cfun
);
6389 rest_of_handle_check_leaf_regs (void)
6391 #ifdef LEAF_REGISTERS
6392 crtl
->uses_only_leaf_regs
6393 = optimize
> 0 && only_leaf_regs_used () && leaf_function_p ();
6398 /* Insert a TYPE into the used types hash table of CFUN. */
6401 used_types_insert_helper (tree type
, struct function
*func
)
6403 if (type
!= NULL
&& func
!= NULL
)
6405 if (func
->used_types_hash
== NULL
)
6406 func
->used_types_hash
= hash_set
<tree
>::create_ggc (37);
6408 func
->used_types_hash
->add (type
);
6412 /* Given a type, insert it into the used hash table in cfun. */
6414 used_types_insert (tree t
)
6416 while (POINTER_TYPE_P (t
) || TREE_CODE (t
) == ARRAY_TYPE
)
6421 if (TREE_CODE (t
) == ERROR_MARK
)
6423 if (TYPE_NAME (t
) == NULL_TREE
6424 || TYPE_NAME (t
) == TYPE_NAME (TYPE_MAIN_VARIANT (t
)))
6425 t
= TYPE_MAIN_VARIANT (t
);
6426 if (debug_info_level
> DINFO_LEVEL_NONE
)
6429 used_types_insert_helper (t
, cfun
);
6432 /* So this might be a type referenced by a global variable.
6433 Record that type so that we can later decide to emit its
6434 debug information. */
6435 vec_safe_push (types_used_by_cur_var_decl
, t
);
6440 /* Helper to Hash a struct types_used_by_vars_entry. */
6443 hash_types_used_by_vars_entry (const struct types_used_by_vars_entry
*entry
)
6445 gcc_assert (entry
&& entry
->var_decl
&& entry
->type
);
6447 return iterative_hash_object (entry
->type
,
6448 iterative_hash_object (entry
->var_decl
, 0));
6451 /* Hash function of the types_used_by_vars_entry hash table. */
6454 used_type_hasher::hash (types_used_by_vars_entry
*entry
)
6456 return hash_types_used_by_vars_entry (entry
);
6459 /*Equality function of the types_used_by_vars_entry hash table. */
6462 used_type_hasher::equal (types_used_by_vars_entry
*e1
,
6463 types_used_by_vars_entry
*e2
)
6465 return (e1
->var_decl
== e2
->var_decl
&& e1
->type
== e2
->type
);
6468 /* Inserts an entry into the types_used_by_vars_hash hash table. */
6471 types_used_by_var_decl_insert (tree type
, tree var_decl
)
6473 if (type
!= NULL
&& var_decl
!= NULL
)
6475 types_used_by_vars_entry
**slot
;
6476 struct types_used_by_vars_entry e
;
6477 e
.var_decl
= var_decl
;
6479 if (types_used_by_vars_hash
== NULL
)
6480 types_used_by_vars_hash
6481 = hash_table
<used_type_hasher
>::create_ggc (37);
6483 slot
= types_used_by_vars_hash
->find_slot (&e
, INSERT
);
6486 struct types_used_by_vars_entry
*entry
;
6487 entry
= ggc_alloc
<types_used_by_vars_entry
> ();
6489 entry
->var_decl
= var_decl
;
6497 const pass_data pass_data_leaf_regs
=
6499 RTL_PASS
, /* type */
6500 "*leaf_regs", /* name */
6501 OPTGROUP_NONE
, /* optinfo_flags */
6502 TV_NONE
, /* tv_id */
6503 0, /* properties_required */
6504 0, /* properties_provided */
6505 0, /* properties_destroyed */
6506 0, /* todo_flags_start */
6507 0, /* todo_flags_finish */
6510 class pass_leaf_regs
: public rtl_opt_pass
6513 pass_leaf_regs (gcc::context
*ctxt
)
6514 : rtl_opt_pass (pass_data_leaf_regs
, ctxt
)
6517 /* opt_pass methods: */
6518 virtual unsigned int execute (function
*)
6520 return rest_of_handle_check_leaf_regs ();
6523 }; // class pass_leaf_regs
6528 make_pass_leaf_regs (gcc::context
*ctxt
)
6530 return new pass_leaf_regs (ctxt
);
6534 rest_of_handle_thread_prologue_and_epilogue (void)
6537 cleanup_cfg (CLEANUP_EXPENSIVE
);
6539 /* On some machines, the prologue and epilogue code, or parts thereof,
6540 can be represented as RTL. Doing so lets us schedule insns between
6541 it and the rest of the code and also allows delayed branch
6542 scheduling to operate in the epilogue. */
6543 thread_prologue_and_epilogue_insns ();
6545 /* Some non-cold blocks may now be only reachable from cold blocks.
6547 fixup_partitions ();
6549 /* Shrink-wrapping can result in unreachable edges in the epilogue,
6553 /* The stack usage info is finalized during prologue expansion. */
6554 if (flag_stack_usage_info
)
6555 output_stack_usage ();
6562 const pass_data pass_data_thread_prologue_and_epilogue
=
6564 RTL_PASS
, /* type */
6565 "pro_and_epilogue", /* name */
6566 OPTGROUP_NONE
, /* optinfo_flags */
6567 TV_THREAD_PROLOGUE_AND_EPILOGUE
, /* tv_id */
6568 0, /* properties_required */
6569 0, /* properties_provided */
6570 0, /* properties_destroyed */
6571 0, /* todo_flags_start */
6572 ( TODO_df_verify
| TODO_df_finish
), /* todo_flags_finish */
6575 class pass_thread_prologue_and_epilogue
: public rtl_opt_pass
6578 pass_thread_prologue_and_epilogue (gcc::context
*ctxt
)
6579 : rtl_opt_pass (pass_data_thread_prologue_and_epilogue
, ctxt
)
6582 /* opt_pass methods: */
6583 virtual unsigned int execute (function
*)
6585 return rest_of_handle_thread_prologue_and_epilogue ();
6588 }; // class pass_thread_prologue_and_epilogue
6593 make_pass_thread_prologue_and_epilogue (gcc::context
*ctxt
)
6595 return new pass_thread_prologue_and_epilogue (ctxt
);
6599 /* This mini-pass fixes fall-out from SSA in asm statements that have
6600 in-out constraints. Say you start with
6603 asm ("": "+mr" (inout));
6606 which is transformed very early to use explicit output and match operands:
6609 asm ("": "=mr" (inout) : "0" (inout));
6612 Or, after SSA and copyprop,
6614 asm ("": "=mr" (inout_2) : "0" (inout_1));
6617 Clearly inout_2 and inout_1 can't be coalesced easily anymore, as
6618 they represent two separate values, so they will get different pseudo
6619 registers during expansion. Then, since the two operands need to match
6620 per the constraints, but use different pseudo registers, reload can
6621 only register a reload for these operands. But reloads can only be
6622 satisfied by hardregs, not by memory, so we need a register for this
6623 reload, just because we are presented with non-matching operands.
6624 So, even though we allow memory for this operand, no memory can be
6625 used for it, just because the two operands don't match. This can
6626 cause reload failures on register-starved targets.
6628 So it's a symptom of reload not being able to use memory for reloads
6629 or, alternatively it's also a symptom of both operands not coming into
6630 reload as matching (in which case the pseudo could go to memory just
6631 fine, as the alternative allows it, and no reload would be necessary).
6632 We fix the latter problem here, by transforming
6634 asm ("": "=mr" (inout_2) : "0" (inout_1));
6639 asm ("": "=mr" (inout_2) : "0" (inout_2)); */
6642 match_asm_constraints_1 (rtx_insn
*insn
, rtx
*p_sets
, int noutputs
)
6645 bool changed
= false;
6646 rtx op
= SET_SRC (p_sets
[0]);
6647 int ninputs
= ASM_OPERANDS_INPUT_LENGTH (op
);
6648 rtvec inputs
= ASM_OPERANDS_INPUT_VEC (op
);
6649 bool *output_matched
= XALLOCAVEC (bool, noutputs
);
6651 memset (output_matched
, 0, noutputs
* sizeof (bool));
6652 for (i
= 0; i
< ninputs
; i
++)
6656 const char *constraint
= ASM_OPERANDS_INPUT_CONSTRAINT (op
, i
);
6660 if (*constraint
== '%')
6663 match
= strtoul (constraint
, &end
, 10);
6664 if (end
== constraint
)
6667 gcc_assert (match
< noutputs
);
6668 output
= SET_DEST (p_sets
[match
]);
6669 input
= RTVEC_ELT (inputs
, i
);
6670 /* Only do the transformation for pseudos. */
6671 if (! REG_P (output
)
6672 || rtx_equal_p (output
, input
)
6673 || (GET_MODE (input
) != VOIDmode
6674 && GET_MODE (input
) != GET_MODE (output
)))
6677 /* We can't do anything if the output is also used as input,
6678 as we're going to overwrite it. */
6679 for (j
= 0; j
< ninputs
; j
++)
6680 if (reg_overlap_mentioned_p (output
, RTVEC_ELT (inputs
, j
)))
6685 /* Avoid changing the same input several times. For
6686 asm ("" : "=mr" (out1), "=mr" (out2) : "0" (in), "1" (in));
6687 only change in once (to out1), rather than changing it
6688 first to out1 and afterwards to out2. */
6691 for (j
= 0; j
< noutputs
; j
++)
6692 if (output_matched
[j
] && input
== SET_DEST (p_sets
[j
]))
6697 output_matched
[match
] = true;
6700 emit_move_insn (output
, input
);
6701 insns
= get_insns ();
6703 emit_insn_before (insns
, insn
);
6705 /* Now replace all mentions of the input with output. We can't
6706 just replace the occurrence in inputs[i], as the register might
6707 also be used in some other input (or even in an address of an
6708 output), which would mean possibly increasing the number of
6709 inputs by one (namely 'output' in addition), which might pose
6710 a too complicated problem for reload to solve. E.g. this situation:
6712 asm ("" : "=r" (output), "=m" (input) : "0" (input))
6714 Here 'input' is used in two occurrences as input (once for the
6715 input operand, once for the address in the second output operand).
6716 If we would replace only the occurrence of the input operand (to
6717 make the matching) we would be left with this:
6720 asm ("" : "=r" (output), "=m" (input) : "0" (output))
6722 Now we suddenly have two different input values (containing the same
6723 value, but different pseudos) where we formerly had only one.
6724 With more complicated asms this might lead to reload failures
6725 which wouldn't have happen without this pass. So, iterate over
6726 all operands and replace all occurrences of the register used. */
6727 for (j
= 0; j
< noutputs
; j
++)
6728 if (!rtx_equal_p (SET_DEST (p_sets
[j
]), input
)
6729 && reg_overlap_mentioned_p (input
, SET_DEST (p_sets
[j
])))
6730 SET_DEST (p_sets
[j
]) = replace_rtx (SET_DEST (p_sets
[j
]),
6732 for (j
= 0; j
< ninputs
; j
++)
6733 if (reg_overlap_mentioned_p (input
, RTVEC_ELT (inputs
, j
)))
6734 RTVEC_ELT (inputs
, j
) = replace_rtx (RTVEC_ELT (inputs
, j
),
6741 df_insn_rescan (insn
);
6744 /* Add the decl D to the local_decls list of FUN. */
6747 add_local_decl (struct function
*fun
, tree d
)
6749 gcc_assert (TREE_CODE (d
) == VAR_DECL
);
6750 vec_safe_push (fun
->local_decls
, d
);
6755 const pass_data pass_data_match_asm_constraints
=
6757 RTL_PASS
, /* type */
6758 "asmcons", /* name */
6759 OPTGROUP_NONE
, /* optinfo_flags */
6760 TV_NONE
, /* tv_id */
6761 0, /* properties_required */
6762 0, /* properties_provided */
6763 0, /* properties_destroyed */
6764 0, /* todo_flags_start */
6765 0, /* todo_flags_finish */
6768 class pass_match_asm_constraints
: public rtl_opt_pass
6771 pass_match_asm_constraints (gcc::context
*ctxt
)
6772 : rtl_opt_pass (pass_data_match_asm_constraints
, ctxt
)
6775 /* opt_pass methods: */
6776 virtual unsigned int execute (function
*);
6778 }; // class pass_match_asm_constraints
6781 pass_match_asm_constraints::execute (function
*fun
)
6788 if (!crtl
->has_asm_statement
)
6791 df_set_flags (DF_DEFER_INSN_RESCAN
);
6792 FOR_EACH_BB_FN (bb
, fun
)
6794 FOR_BB_INSNS (bb
, insn
)
6799 pat
= PATTERN (insn
);
6800 if (GET_CODE (pat
) == PARALLEL
)
6801 p_sets
= &XVECEXP (pat
, 0, 0), noutputs
= XVECLEN (pat
, 0);
6802 else if (GET_CODE (pat
) == SET
)
6803 p_sets
= &PATTERN (insn
), noutputs
= 1;
6807 if (GET_CODE (*p_sets
) == SET
6808 && GET_CODE (SET_SRC (*p_sets
)) == ASM_OPERANDS
)
6809 match_asm_constraints_1 (insn
, p_sets
, noutputs
);
6813 return TODO_df_finish
;
6819 make_pass_match_asm_constraints (gcc::context
*ctxt
)
6821 return new pass_match_asm_constraints (ctxt
);
6825 #include "gt-function.h"