1 /* Subroutines for manipulating rtx's in semantically interesting ways.
2 Copyright (C) 1987-2020 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/>. */
23 #include "coretypes.h"
31 #include "profile-count.h"
35 #include "diagnostic-core.h"
36 #include "stor-layout.h"
41 #include "stringpool.h"
42 #include "common/common-target.h"
45 static rtx
break_out_memory_refs (rtx
);
46 static void anti_adjust_stack_and_probe_stack_clash (rtx
);
49 /* Truncate and perhaps sign-extend C as appropriate for MODE. */
52 trunc_int_for_mode (HOST_WIDE_INT c
, machine_mode mode
)
54 /* Not scalar_int_mode because we also allow pointer bound modes. */
55 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
56 int width
= GET_MODE_PRECISION (smode
);
58 /* You want to truncate to a _what_? */
59 gcc_assert (SCALAR_INT_MODE_P (mode
));
61 /* Canonicalize BImode to 0 and STORE_FLAG_VALUE. */
63 return c
& 1 ? STORE_FLAG_VALUE
: 0;
65 /* Sign-extend for the requested mode. */
67 if (width
< HOST_BITS_PER_WIDE_INT
)
69 HOST_WIDE_INT sign
= 1;
79 /* Likewise for polynomial values, using the sign-extended representation
80 for each individual coefficient. */
83 trunc_int_for_mode (poly_int64 x
, machine_mode mode
)
85 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
86 x
.coeffs
[i
] = trunc_int_for_mode (x
.coeffs
[i
], mode
);
90 /* Return an rtx for the sum of X and the integer C, given that X has
91 mode MODE. INPLACE is true if X can be modified inplace or false
92 if it must be treated as immutable. */
95 plus_constant (machine_mode mode
, rtx x
, poly_int64 c
, bool inplace
)
100 int all_constant
= 0;
102 gcc_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
114 CASE_CONST_SCALAR_INT
:
115 return immed_wide_int_const (wi::add (rtx_mode_t (x
, mode
), c
), mode
);
117 /* If this is a reference to the constant pool, try replacing it with
118 a reference to a new constant. If the resulting address isn't
119 valid, don't return it because we have no way to validize it. */
120 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
121 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
123 rtx cst
= get_pool_constant (XEXP (x
, 0));
125 if (GET_CODE (cst
) == CONST_VECTOR
126 && GET_MODE_INNER (GET_MODE (cst
)) == mode
)
128 cst
= gen_lowpart (mode
, cst
);
131 else if (GET_MODE (cst
) == VOIDmode
132 && get_pool_mode (XEXP (x
, 0)) != mode
)
134 if (GET_MODE (cst
) == VOIDmode
|| GET_MODE (cst
) == mode
)
136 tem
= plus_constant (mode
, cst
, c
);
137 tem
= force_const_mem (GET_MODE (x
), tem
);
138 /* Targets may disallow some constants in the constant pool, thus
139 force_const_mem may return NULL_RTX. */
140 if (tem
&& memory_address_p (GET_MODE (tem
), XEXP (tem
, 0)))
147 /* If adding to something entirely constant, set a flag
148 so that we can add a CONST around the result. */
149 if (inplace
&& shared_const_p (x
))
161 /* The interesting case is adding the integer to a sum. Look
162 for constant term in the sum and combine with C. For an
163 integer constant term or a constant term that is not an
164 explicit integer, we combine or group them together anyway.
166 We may not immediately return from the recursive call here, lest
167 all_constant gets lost. */
169 if (CONSTANT_P (XEXP (x
, 1)))
171 rtx term
= plus_constant (mode
, XEXP (x
, 1), c
, inplace
);
172 if (term
== const0_rtx
)
177 x
= gen_rtx_PLUS (mode
, XEXP (x
, 0), term
);
180 else if (rtx
*const_loc
= find_constant_term_loc (&y
))
184 /* We need to be careful since X may be shared and we can't
185 modify it in place. */
187 const_loc
= find_constant_term_loc (&x
);
189 *const_loc
= plus_constant (mode
, *const_loc
, c
, true);
195 if (CONST_POLY_INT_P (x
))
196 return immed_wide_int_const (const_poly_int_value (x
) + c
, mode
);
201 x
= gen_rtx_PLUS (mode
, x
, gen_int_mode (c
, mode
));
203 if (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
)
205 else if (all_constant
)
206 return gen_rtx_CONST (mode
, x
);
211 /* If X is a sum, return a new sum like X but lacking any constant terms.
212 Add all the removed constant terms into *CONSTPTR.
213 X itself is not altered. The result != X if and only if
214 it is not isomorphic to X. */
217 eliminate_constant_term (rtx x
, rtx
*constptr
)
222 if (GET_CODE (x
) != PLUS
)
225 /* First handle constants appearing at this level explicitly. */
226 if (CONST_INT_P (XEXP (x
, 1))
227 && (tem
= simplify_binary_operation (PLUS
, GET_MODE (x
), *constptr
,
229 && CONST_INT_P (tem
))
232 return eliminate_constant_term (XEXP (x
, 0), constptr
);
236 x0
= eliminate_constant_term (XEXP (x
, 0), &tem
);
237 x1
= eliminate_constant_term (XEXP (x
, 1), &tem
);
238 if ((x1
!= XEXP (x
, 1) || x0
!= XEXP (x
, 0))
239 && (tem
= simplify_binary_operation (PLUS
, GET_MODE (x
),
240 *constptr
, tem
)) != 0
241 && CONST_INT_P (tem
))
244 return gen_rtx_PLUS (GET_MODE (x
), x0
, x1
);
251 /* Return a copy of X in which all memory references
252 and all constants that involve symbol refs
253 have been replaced with new temporary registers.
254 Also emit code to load the memory locations and constants
255 into those registers.
257 If X contains no such constants or memory references,
258 X itself (not a copy) is returned.
260 If a constant is found in the address that is not a legitimate constant
261 in an insn, it is left alone in the hope that it might be valid in the
264 X may contain no arithmetic except addition, subtraction and multiplication.
265 Values returned by expand_expr with 1 for sum_ok fit this constraint. */
268 break_out_memory_refs (rtx x
)
271 || (CONSTANT_P (x
) && CONSTANT_ADDRESS_P (x
)
272 && GET_MODE (x
) != VOIDmode
))
273 x
= force_reg (GET_MODE (x
), x
);
274 else if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
275 || GET_CODE (x
) == MULT
)
277 rtx op0
= break_out_memory_refs (XEXP (x
, 0));
278 rtx op1
= break_out_memory_refs (XEXP (x
, 1));
280 if (op0
!= XEXP (x
, 0) || op1
!= XEXP (x
, 1))
281 x
= simplify_gen_binary (GET_CODE (x
), GET_MODE (x
), op0
, op1
);
287 /* Given X, a memory address in address space AS' pointer mode, convert it to
288 an address in the address space's address mode, or vice versa (TO_MODE says
289 which way). We take advantage of the fact that pointers are not allowed to
290 overflow by commuting arithmetic operations over conversions so that address
291 arithmetic insns can be used. IN_CONST is true if this conversion is inside
292 a CONST. NO_EMIT is true if no insns should be emitted, and instead
293 it should return NULL if it can't be simplified without emitting insns. */
296 convert_memory_address_addr_space_1 (scalar_int_mode to_mode ATTRIBUTE_UNUSED
,
297 rtx x
, addr_space_t as ATTRIBUTE_UNUSED
,
298 bool in_const ATTRIBUTE_UNUSED
,
299 bool no_emit ATTRIBUTE_UNUSED
)
301 #ifndef POINTERS_EXTEND_UNSIGNED
302 gcc_assert (GET_MODE (x
) == to_mode
|| GET_MODE (x
) == VOIDmode
);
304 #else /* defined(POINTERS_EXTEND_UNSIGNED) */
305 scalar_int_mode pointer_mode
, address_mode
, from_mode
;
309 /* If X already has the right mode, just return it. */
310 if (GET_MODE (x
) == to_mode
)
313 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
314 address_mode
= targetm
.addr_space
.address_mode (as
);
315 from_mode
= to_mode
== pointer_mode
? address_mode
: pointer_mode
;
317 /* Here we handle some special cases. If none of them apply, fall through
318 to the default case. */
319 switch (GET_CODE (x
))
321 CASE_CONST_SCALAR_INT
:
322 if (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (from_mode
))
324 else if (POINTERS_EXTEND_UNSIGNED
< 0)
326 else if (POINTERS_EXTEND_UNSIGNED
> 0)
330 temp
= simplify_unary_operation (code
, to_mode
, x
, from_mode
);
336 if ((SUBREG_PROMOTED_VAR_P (x
) || REG_POINTER (SUBREG_REG (x
)))
337 && GET_MODE (SUBREG_REG (x
)) == to_mode
)
338 return SUBREG_REG (x
);
342 temp
= gen_rtx_LABEL_REF (to_mode
, label_ref_label (x
));
343 LABEL_REF_NONLOCAL_P (temp
) = LABEL_REF_NONLOCAL_P (x
);
347 temp
= shallow_copy_rtx (x
);
348 PUT_MODE (temp
, to_mode
);
352 temp
= convert_memory_address_addr_space_1 (to_mode
, XEXP (x
, 0), as
,
354 return temp
? gen_rtx_CONST (to_mode
, temp
) : temp
;
358 /* For addition we can safely permute the conversion and addition
359 operation if one operand is a constant and converting the constant
360 does not change it or if one operand is a constant and we are
361 using a ptr_extend instruction (POINTERS_EXTEND_UNSIGNED < 0).
362 We can always safely permute them if we are making the address
363 narrower. Inside a CONST RTL, this is safe for both pointers
364 zero or sign extended as pointers cannot wrap. */
365 if (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (from_mode
)
366 || (GET_CODE (x
) == PLUS
367 && CONST_INT_P (XEXP (x
, 1))
368 && ((in_const
&& POINTERS_EXTEND_UNSIGNED
!= 0)
369 || XEXP (x
, 1) == convert_memory_address_addr_space_1
370 (to_mode
, XEXP (x
, 1), as
, in_const
,
372 || POINTERS_EXTEND_UNSIGNED
< 0)))
374 temp
= convert_memory_address_addr_space_1 (to_mode
, XEXP (x
, 0),
375 as
, in_const
, no_emit
);
376 return (temp
? gen_rtx_fmt_ee (GET_CODE (x
), to_mode
,
389 return convert_modes (to_mode
, from_mode
,
390 x
, POINTERS_EXTEND_UNSIGNED
);
391 #endif /* defined(POINTERS_EXTEND_UNSIGNED) */
394 /* Given X, a memory address in address space AS' pointer mode, convert it to
395 an address in the address space's address mode, or vice versa (TO_MODE says
396 which way). We take advantage of the fact that pointers are not allowed to
397 overflow by commuting arithmetic operations over conversions so that address
398 arithmetic insns can be used. */
401 convert_memory_address_addr_space (scalar_int_mode to_mode
, rtx x
,
404 return convert_memory_address_addr_space_1 (to_mode
, x
, as
, false, false);
408 /* Return something equivalent to X but valid as a memory address for something
409 of mode MODE in the named address space AS. When X is not itself valid,
410 this works by copying X or subexpressions of it into registers. */
413 memory_address_addr_space (machine_mode mode
, rtx x
, addr_space_t as
)
416 scalar_int_mode address_mode
= targetm
.addr_space
.address_mode (as
);
418 x
= convert_memory_address_addr_space (address_mode
, x
, as
);
420 /* By passing constant addresses through registers
421 we get a chance to cse them. */
422 if (! cse_not_expected
&& CONSTANT_P (x
) && CONSTANT_ADDRESS_P (x
))
423 x
= force_reg (address_mode
, x
);
425 /* We get better cse by rejecting indirect addressing at this stage.
426 Let the combiner create indirect addresses where appropriate.
427 For now, generate the code so that the subexpressions useful to share
428 are visible. But not if cse won't be done! */
431 if (! cse_not_expected
&& !REG_P (x
))
432 x
= break_out_memory_refs (x
);
434 /* At this point, any valid address is accepted. */
435 if (memory_address_addr_space_p (mode
, x
, as
))
438 /* If it was valid before but breaking out memory refs invalidated it,
439 use it the old way. */
440 if (memory_address_addr_space_p (mode
, oldx
, as
))
446 /* Perform machine-dependent transformations on X
447 in certain cases. This is not necessary since the code
448 below can handle all possible cases, but machine-dependent
449 transformations can make better code. */
452 x
= targetm
.addr_space
.legitimize_address (x
, oldx
, mode
, as
);
453 if (orig_x
!= x
&& memory_address_addr_space_p (mode
, x
, as
))
457 /* PLUS and MULT can appear in special ways
458 as the result of attempts to make an address usable for indexing.
459 Usually they are dealt with by calling force_operand, below.
460 But a sum containing constant terms is special
461 if removing them makes the sum a valid address:
462 then we generate that address in a register
463 and index off of it. We do this because it often makes
464 shorter code, and because the addresses thus generated
465 in registers often become common subexpressions. */
466 if (GET_CODE (x
) == PLUS
)
468 rtx constant_term
= const0_rtx
;
469 rtx y
= eliminate_constant_term (x
, &constant_term
);
470 if (constant_term
== const0_rtx
471 || ! memory_address_addr_space_p (mode
, y
, as
))
472 x
= force_operand (x
, NULL_RTX
);
475 y
= gen_rtx_PLUS (GET_MODE (x
), copy_to_reg (y
), constant_term
);
476 if (! memory_address_addr_space_p (mode
, y
, as
))
477 x
= force_operand (x
, NULL_RTX
);
483 else if (GET_CODE (x
) == MULT
|| GET_CODE (x
) == MINUS
)
484 x
= force_operand (x
, NULL_RTX
);
486 /* If we have a register that's an invalid address,
487 it must be a hard reg of the wrong class. Copy it to a pseudo. */
491 /* Last resort: copy the value to a register, since
492 the register is a valid address. */
494 x
= force_reg (address_mode
, x
);
499 gcc_assert (memory_address_addr_space_p (mode
, x
, as
));
500 /* If we didn't change the address, we are done. Otherwise, mark
501 a reg as a pointer if we have REG or REG + CONST_INT. */
505 mark_reg_pointer (x
, BITS_PER_UNIT
);
506 else if (GET_CODE (x
) == PLUS
507 && REG_P (XEXP (x
, 0))
508 && CONST_INT_P (XEXP (x
, 1)))
509 mark_reg_pointer (XEXP (x
, 0), BITS_PER_UNIT
);
511 /* OLDX may have been the address on a temporary. Update the address
512 to indicate that X is now used. */
513 update_temp_slot_address (oldx
, x
);
518 /* Convert a mem ref into one with a valid memory address.
519 Pass through anything else unchanged. */
522 validize_mem (rtx ref
)
526 ref
= use_anchored_address (ref
);
527 if (memory_address_addr_space_p (GET_MODE (ref
), XEXP (ref
, 0),
528 MEM_ADDR_SPACE (ref
)))
531 /* Don't alter REF itself, since that is probably a stack slot. */
532 return replace_equiv_address (ref
, XEXP (ref
, 0));
535 /* If X is a memory reference to a member of an object block, try rewriting
536 it to use an anchor instead. Return the new memory reference on success
537 and the old one on failure. */
540 use_anchored_address (rtx x
)
543 HOST_WIDE_INT offset
;
546 if (!flag_section_anchors
)
552 /* Split the address into a base and offset. */
555 if (GET_CODE (base
) == CONST
556 && GET_CODE (XEXP (base
, 0)) == PLUS
557 && CONST_INT_P (XEXP (XEXP (base
, 0), 1)))
559 offset
+= INTVAL (XEXP (XEXP (base
, 0), 1));
560 base
= XEXP (XEXP (base
, 0), 0);
563 /* Check whether BASE is suitable for anchors. */
564 if (GET_CODE (base
) != SYMBOL_REF
565 || !SYMBOL_REF_HAS_BLOCK_INFO_P (base
)
566 || SYMBOL_REF_ANCHOR_P (base
)
567 || SYMBOL_REF_BLOCK (base
) == NULL
568 || !targetm
.use_anchors_for_symbol_p (base
))
571 /* Decide where BASE is going to be. */
572 place_block_symbol (base
);
574 /* Get the anchor we need to use. */
575 offset
+= SYMBOL_REF_BLOCK_OFFSET (base
);
576 base
= get_section_anchor (SYMBOL_REF_BLOCK (base
), offset
,
577 SYMBOL_REF_TLS_MODEL (base
));
579 /* Work out the offset from the anchor. */
580 offset
-= SYMBOL_REF_BLOCK_OFFSET (base
);
582 /* If we're going to run a CSE pass, force the anchor into a register.
583 We will then be able to reuse registers for several accesses, if the
584 target costs say that that's worthwhile. */
585 mode
= GET_MODE (base
);
586 if (!cse_not_expected
)
587 base
= force_reg (mode
, base
);
589 return replace_equiv_address (x
, plus_constant (mode
, base
, offset
));
592 /* Copy the value or contents of X to a new temp reg and return that reg. */
597 rtx temp
= gen_reg_rtx (GET_MODE (x
));
599 /* If not an operand, must be an address with PLUS and MULT so
600 do the computation. */
601 if (! general_operand (x
, VOIDmode
))
602 x
= force_operand (x
, temp
);
605 emit_move_insn (temp
, x
);
610 /* Like copy_to_reg but always give the new register mode Pmode
611 in case X is a constant. */
614 copy_addr_to_reg (rtx x
)
616 return copy_to_mode_reg (Pmode
, x
);
619 /* Like copy_to_reg but always give the new register mode MODE
620 in case X is a constant. */
623 copy_to_mode_reg (machine_mode mode
, rtx x
)
625 rtx temp
= gen_reg_rtx (mode
);
627 /* If not an operand, must be an address with PLUS and MULT so
628 do the computation. */
629 if (! general_operand (x
, VOIDmode
))
630 x
= force_operand (x
, temp
);
632 gcc_assert (GET_MODE (x
) == mode
|| GET_MODE (x
) == VOIDmode
);
634 emit_move_insn (temp
, x
);
638 /* Load X into a register if it is not already one.
639 Use mode MODE for the register.
640 X should be valid for mode MODE, but it may be a constant which
641 is valid for all integer modes; that's why caller must specify MODE.
643 The caller must not alter the value in the register we return,
644 since we mark it as a "constant" register. */
647 force_reg (machine_mode mode
, rtx x
)
655 if (general_operand (x
, mode
))
657 temp
= gen_reg_rtx (mode
);
658 insn
= emit_move_insn (temp
, x
);
662 temp
= force_operand (x
, NULL_RTX
);
664 insn
= get_last_insn ();
667 rtx temp2
= gen_reg_rtx (mode
);
668 insn
= emit_move_insn (temp2
, temp
);
673 /* Let optimizers know that TEMP's value never changes
674 and that X can be substituted for it. Don't get confused
675 if INSN set something else (such as a SUBREG of TEMP). */
677 && (set
= single_set (insn
)) != 0
678 && SET_DEST (set
) == temp
679 && ! rtx_equal_p (x
, SET_SRC (set
)))
680 set_unique_reg_note (insn
, REG_EQUAL
, x
);
682 /* Let optimizers know that TEMP is a pointer, and if so, the
683 known alignment of that pointer. */
686 if (GET_CODE (x
) == SYMBOL_REF
)
688 align
= BITS_PER_UNIT
;
689 if (SYMBOL_REF_DECL (x
) && DECL_P (SYMBOL_REF_DECL (x
)))
690 align
= DECL_ALIGN (SYMBOL_REF_DECL (x
));
692 else if (GET_CODE (x
) == LABEL_REF
)
693 align
= BITS_PER_UNIT
;
694 else if (GET_CODE (x
) == CONST
695 && GET_CODE (XEXP (x
, 0)) == PLUS
696 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
697 && CONST_INT_P (XEXP (XEXP (x
, 0), 1)))
699 rtx s
= XEXP (XEXP (x
, 0), 0);
700 rtx c
= XEXP (XEXP (x
, 0), 1);
704 if (SYMBOL_REF_DECL (s
) && DECL_P (SYMBOL_REF_DECL (s
)))
705 sa
= DECL_ALIGN (SYMBOL_REF_DECL (s
));
711 ca
= ctz_hwi (INTVAL (c
)) * BITS_PER_UNIT
;
712 align
= MIN (sa
, ca
);
716 if (align
|| (MEM_P (x
) && MEM_POINTER (x
)))
717 mark_reg_pointer (temp
, align
);
723 /* If X is a memory ref, copy its contents to a new temp reg and return
724 that reg. Otherwise, return X. */
727 force_not_mem (rtx x
)
731 if (!MEM_P (x
) || GET_MODE (x
) == BLKmode
)
734 temp
= gen_reg_rtx (GET_MODE (x
));
737 REG_POINTER (temp
) = 1;
739 emit_move_insn (temp
, x
);
743 /* Copy X to TARGET (if it's nonzero and a reg)
744 or to a new temp reg and return that reg.
745 MODE is the mode to use for X in case it is a constant. */
748 copy_to_suggested_reg (rtx x
, rtx target
, machine_mode mode
)
752 if (target
&& REG_P (target
))
755 temp
= gen_reg_rtx (mode
);
757 emit_move_insn (temp
, x
);
761 /* Return the mode to use to pass or return a scalar of TYPE and MODE.
762 PUNSIGNEDP points to the signedness of the type and may be adjusted
763 to show what signedness to use on extension operations.
765 FOR_RETURN is nonzero if the caller is promoting the return value
766 of FNDECL, else it is for promoting args. */
769 promote_function_mode (const_tree type
, machine_mode mode
, int *punsignedp
,
770 const_tree funtype
, int for_return
)
772 /* Called without a type node for a libcall. */
773 if (type
== NULL_TREE
)
775 if (INTEGRAL_MODE_P (mode
))
776 return targetm
.calls
.promote_function_mode (NULL_TREE
, mode
,
783 switch (TREE_CODE (type
))
785 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
786 case REAL_TYPE
: case OFFSET_TYPE
: case FIXED_POINT_TYPE
:
787 case POINTER_TYPE
: case REFERENCE_TYPE
:
788 return targetm
.calls
.promote_function_mode (type
, mode
, punsignedp
, funtype
,
795 /* Return the mode to use to store a scalar of TYPE and MODE.
796 PUNSIGNEDP points to the signedness of the type and may be adjusted
797 to show what signedness to use on extension operations. */
800 promote_mode (const_tree type ATTRIBUTE_UNUSED
, machine_mode mode
,
801 int *punsignedp ATTRIBUTE_UNUSED
)
809 /* For libcalls this is invoked without TYPE from the backends
810 TARGET_PROMOTE_FUNCTION_MODE hooks. Don't do anything in that
812 if (type
== NULL_TREE
)
815 /* FIXME: this is the same logic that was there until GCC 4.4, but we
816 probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
817 is not defined. The affected targets are M32C, S390, SPARC. */
819 code
= TREE_CODE (type
);
820 unsignedp
= *punsignedp
;
824 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
825 case REAL_TYPE
: case OFFSET_TYPE
: case FIXED_POINT_TYPE
:
826 /* Values of these types always have scalar mode. */
827 smode
= as_a
<scalar_mode
> (mode
);
828 PROMOTE_MODE (smode
, unsignedp
, type
);
829 *punsignedp
= unsignedp
;
832 #ifdef POINTERS_EXTEND_UNSIGNED
835 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
836 return targetm
.addr_space
.address_mode
837 (TYPE_ADDR_SPACE (TREE_TYPE (type
)));
849 /* Use one of promote_mode or promote_function_mode to find the promoted
850 mode of DECL. If PUNSIGNEDP is not NULL, store there the unsignedness
851 of DECL after promotion. */
854 promote_decl_mode (const_tree decl
, int *punsignedp
)
856 tree type
= TREE_TYPE (decl
);
857 int unsignedp
= TYPE_UNSIGNED (type
);
858 machine_mode mode
= DECL_MODE (decl
);
861 if (TREE_CODE (decl
) == RESULT_DECL
&& !DECL_BY_REFERENCE (decl
))
862 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
863 TREE_TYPE (current_function_decl
), 1);
864 else if (TREE_CODE (decl
) == RESULT_DECL
|| TREE_CODE (decl
) == PARM_DECL
)
865 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
866 TREE_TYPE (current_function_decl
), 2);
868 pmode
= promote_mode (type
, mode
, &unsignedp
);
871 *punsignedp
= unsignedp
;
875 /* Return the promoted mode for name. If it is a named SSA_NAME, it
876 is the same as promote_decl_mode. Otherwise, it is the promoted
877 mode of a temp decl of same type as the SSA_NAME, if we had created
881 promote_ssa_mode (const_tree name
, int *punsignedp
)
883 gcc_assert (TREE_CODE (name
) == SSA_NAME
);
885 /* Partitions holding parms and results must be promoted as expected
887 if (SSA_NAME_VAR (name
)
888 && (TREE_CODE (SSA_NAME_VAR (name
)) == PARM_DECL
889 || TREE_CODE (SSA_NAME_VAR (name
)) == RESULT_DECL
))
891 machine_mode mode
= promote_decl_mode (SSA_NAME_VAR (name
), punsignedp
);
896 tree type
= TREE_TYPE (name
);
897 int unsignedp
= TYPE_UNSIGNED (type
);
898 machine_mode pmode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
);
900 *punsignedp
= unsignedp
;
907 /* Controls the behavior of {anti_,}adjust_stack. */
908 static bool suppress_reg_args_size
;
910 /* A helper for adjust_stack and anti_adjust_stack. */
913 adjust_stack_1 (rtx adjust
, bool anti_p
)
918 /* Hereafter anti_p means subtract_p. */
919 if (!STACK_GROWS_DOWNWARD
)
922 temp
= expand_binop (Pmode
,
923 anti_p
? sub_optab
: add_optab
,
924 stack_pointer_rtx
, adjust
, stack_pointer_rtx
, 0,
927 if (temp
!= stack_pointer_rtx
)
928 insn
= emit_move_insn (stack_pointer_rtx
, temp
);
931 insn
= get_last_insn ();
932 temp
= single_set (insn
);
933 gcc_assert (temp
!= NULL
&& SET_DEST (temp
) == stack_pointer_rtx
);
936 if (!suppress_reg_args_size
)
937 add_args_size_note (insn
, stack_pointer_delta
);
940 /* Adjust the stack pointer by ADJUST (an rtx for a number of bytes).
941 This pops when ADJUST is positive. ADJUST need not be constant. */
944 adjust_stack (rtx adjust
)
946 if (adjust
== const0_rtx
)
949 /* We expect all variable sized adjustments to be multiple of
950 PREFERRED_STACK_BOUNDARY. */
951 poly_int64 const_adjust
;
952 if (poly_int_rtx_p (adjust
, &const_adjust
))
953 stack_pointer_delta
-= const_adjust
;
955 adjust_stack_1 (adjust
, false);
958 /* Adjust the stack pointer by minus ADJUST (an rtx for a number of bytes).
959 This pushes when ADJUST is positive. ADJUST need not be constant. */
962 anti_adjust_stack (rtx adjust
)
964 if (adjust
== const0_rtx
)
967 /* We expect all variable sized adjustments to be multiple of
968 PREFERRED_STACK_BOUNDARY. */
969 poly_int64 const_adjust
;
970 if (poly_int_rtx_p (adjust
, &const_adjust
))
971 stack_pointer_delta
+= const_adjust
;
973 adjust_stack_1 (adjust
, true);
976 /* Round the size of a block to be pushed up to the boundary required
977 by this machine. SIZE is the desired size, which need not be constant. */
980 round_push (rtx size
)
982 rtx align_rtx
, alignm1_rtx
;
984 if (!SUPPORTS_STACK_ALIGNMENT
985 || crtl
->preferred_stack_boundary
== MAX_SUPPORTED_STACK_ALIGNMENT
)
987 int align
= crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
;
992 if (CONST_INT_P (size
))
994 HOST_WIDE_INT new_size
= (INTVAL (size
) + align
- 1) / align
* align
;
996 if (INTVAL (size
) != new_size
)
997 size
= GEN_INT (new_size
);
1001 align_rtx
= GEN_INT (align
);
1002 alignm1_rtx
= GEN_INT (align
- 1);
1006 /* If crtl->preferred_stack_boundary might still grow, use
1007 virtual_preferred_stack_boundary_rtx instead. This will be
1008 substituted by the right value in vregs pass and optimized
1010 align_rtx
= virtual_preferred_stack_boundary_rtx
;
1011 alignm1_rtx
= force_operand (plus_constant (Pmode
, align_rtx
, -1),
1015 /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
1016 but we know it can't. So add ourselves and then do
1018 size
= expand_binop (Pmode
, add_optab
, size
, alignm1_rtx
,
1019 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1020 size
= expand_divmod (0, TRUNC_DIV_EXPR
, Pmode
, size
, align_rtx
,
1022 size
= expand_mult (Pmode
, size
, align_rtx
, NULL_RTX
, 1);
1027 /* Save the stack pointer for the purpose in SAVE_LEVEL. PSAVE is a pointer
1028 to a previously-created save area. If no save area has been allocated,
1029 this function will allocate one. If a save area is specified, it
1030 must be of the proper mode. */
1033 emit_stack_save (enum save_level save_level
, rtx
*psave
)
1036 /* The default is that we use a move insn and save in a Pmode object. */
1037 rtx_insn
*(*fcn
) (rtx
, rtx
) = gen_move_insn
;
1038 machine_mode mode
= STACK_SAVEAREA_MODE (save_level
);
1040 /* See if this machine has anything special to do for this kind of save. */
1044 if (targetm
.have_save_stack_block ())
1045 fcn
= targetm
.gen_save_stack_block
;
1048 if (targetm
.have_save_stack_function ())
1049 fcn
= targetm
.gen_save_stack_function
;
1052 if (targetm
.have_save_stack_nonlocal ())
1053 fcn
= targetm
.gen_save_stack_nonlocal
;
1059 /* If there is no save area and we have to allocate one, do so. Otherwise
1060 verify the save area is the proper mode. */
1064 if (mode
!= VOIDmode
)
1066 if (save_level
== SAVE_NONLOCAL
)
1067 *psave
= sa
= assign_stack_local (mode
, GET_MODE_SIZE (mode
), 0);
1069 *psave
= sa
= gen_reg_rtx (mode
);
1073 do_pending_stack_adjust ();
1075 sa
= validize_mem (sa
);
1076 emit_insn (fcn (sa
, stack_pointer_rtx
));
1079 /* Restore the stack pointer for the purpose in SAVE_LEVEL. SA is the save
1080 area made by emit_stack_save. If it is zero, we have nothing to do. */
1083 emit_stack_restore (enum save_level save_level
, rtx sa
)
1085 /* The default is that we use a move insn. */
1086 rtx_insn
*(*fcn
) (rtx
, rtx
) = gen_move_insn
;
1088 /* If stack_realign_drap, the x86 backend emits a prologue that aligns both
1089 STACK_POINTER and HARD_FRAME_POINTER.
1090 If stack_realign_fp, the x86 backend emits a prologue that aligns only
1091 STACK_POINTER. This renders the HARD_FRAME_POINTER unusable for accessing
1092 aligned variables, which is reflected in ix86_can_eliminate.
1093 We normally still have the realigned STACK_POINTER that we can use.
1094 But if there is a stack restore still present at reload, it can trigger
1095 mark_not_eliminable for the STACK_POINTER, leaving no way to eliminate
1096 FRAME_POINTER into a hard reg.
1097 To prevent this situation, we force need_drap if we emit a stack
1099 if (SUPPORTS_STACK_ALIGNMENT
)
1100 crtl
->need_drap
= true;
1102 /* See if this machine has anything special to do for this kind of save. */
1106 if (targetm
.have_restore_stack_block ())
1107 fcn
= targetm
.gen_restore_stack_block
;
1110 if (targetm
.have_restore_stack_function ())
1111 fcn
= targetm
.gen_restore_stack_function
;
1114 if (targetm
.have_restore_stack_nonlocal ())
1115 fcn
= targetm
.gen_restore_stack_nonlocal
;
1123 sa
= validize_mem (sa
);
1124 /* These clobbers prevent the scheduler from moving
1125 references to variable arrays below the code
1126 that deletes (pops) the arrays. */
1127 emit_clobber (gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
)));
1128 emit_clobber (gen_rtx_MEM (BLKmode
, stack_pointer_rtx
));
1131 discard_pending_stack_adjust ();
1133 emit_insn (fcn (stack_pointer_rtx
, sa
));
1136 /* Invoke emit_stack_save on the nonlocal_goto_save_area for the current
1137 function. This should be called whenever we allocate or deallocate
1138 dynamic stack space. */
1141 update_nonlocal_goto_save_area (void)
1146 /* The nonlocal_goto_save_area object is an array of N pointers. The
1147 first one is used for the frame pointer save; the rest are sized by
1148 STACK_SAVEAREA_MODE. Create a reference to array index 1, the first
1149 of the stack save area slots. */
1150 t_save
= build4 (ARRAY_REF
,
1151 TREE_TYPE (TREE_TYPE (cfun
->nonlocal_goto_save_area
)),
1152 cfun
->nonlocal_goto_save_area
,
1153 integer_one_node
, NULL_TREE
, NULL_TREE
);
1154 r_save
= expand_expr (t_save
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
1156 emit_stack_save (SAVE_NONLOCAL
, &r_save
);
1159 /* Record a new stack level for the current function. This should be called
1160 whenever we allocate or deallocate dynamic stack space. */
1163 record_new_stack_level (void)
1165 /* Record the new stack level for nonlocal gotos. */
1166 if (cfun
->nonlocal_goto_save_area
)
1167 update_nonlocal_goto_save_area ();
1169 /* Record the new stack level for SJLJ exceptions. */
1170 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
1171 update_sjlj_context ();
1174 /* Return an rtx doing runtime alignment to REQUIRED_ALIGN on TARGET. */
1177 align_dynamic_address (rtx target
, unsigned required_align
)
1179 /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
1180 but we know it can't. So add ourselves and then do
1182 target
= expand_binop (Pmode
, add_optab
, target
,
1183 gen_int_mode (required_align
/ BITS_PER_UNIT
- 1,
1185 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1186 target
= expand_divmod (0, TRUNC_DIV_EXPR
, Pmode
, target
,
1187 gen_int_mode (required_align
/ BITS_PER_UNIT
,
1190 target
= expand_mult (Pmode
, target
,
1191 gen_int_mode (required_align
/ BITS_PER_UNIT
,
1198 /* Return an rtx through *PSIZE, representing the size of an area of memory to
1199 be dynamically pushed on the stack.
1201 *PSIZE is an rtx representing the size of the area.
1203 SIZE_ALIGN is the alignment (in bits) that we know SIZE has. This
1204 parameter may be zero. If so, a proper value will be extracted
1205 from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed.
1207 REQUIRED_ALIGN is the alignment (in bits) required for the region
1210 If PSTACK_USAGE_SIZE is not NULL it points to a value that is increased for
1211 the additional size returned. */
1213 get_dynamic_stack_size (rtx
*psize
, unsigned size_align
,
1214 unsigned required_align
,
1215 HOST_WIDE_INT
*pstack_usage_size
)
1219 /* Ensure the size is in the proper mode. */
1220 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
1221 size
= convert_to_mode (Pmode
, size
, 1);
1223 if (CONST_INT_P (size
))
1225 unsigned HOST_WIDE_INT lsb
;
1227 lsb
= INTVAL (size
);
1230 /* Watch out for overflow truncating to "unsigned". */
1231 if (lsb
> UINT_MAX
/ BITS_PER_UNIT
)
1232 size_align
= 1u << (HOST_BITS_PER_INT
- 1);
1234 size_align
= (unsigned)lsb
* BITS_PER_UNIT
;
1236 else if (size_align
< BITS_PER_UNIT
)
1237 size_align
= BITS_PER_UNIT
;
1239 /* We can't attempt to minimize alignment necessary, because we don't
1240 know the final value of preferred_stack_boundary yet while executing
1242 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
1243 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
1245 /* We will need to ensure that the address we return is aligned to
1246 REQUIRED_ALIGN. At this point in the compilation, we don't always
1247 know the final value of the STACK_DYNAMIC_OFFSET used in function.c
1248 (it might depend on the size of the outgoing parameter lists, for
1249 example), so we must preventively align the value. We leave space
1250 in SIZE for the hole that might result from the alignment operation. */
1252 unsigned known_align
= REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM
);
1253 if (known_align
== 0)
1254 known_align
= BITS_PER_UNIT
;
1255 if (required_align
> known_align
)
1257 unsigned extra
= (required_align
- known_align
) / BITS_PER_UNIT
;
1258 size
= plus_constant (Pmode
, size
, extra
);
1259 size
= force_operand (size
, NULL_RTX
);
1260 if (size_align
> known_align
)
1261 size_align
= known_align
;
1263 if (flag_stack_usage_info
&& pstack_usage_size
)
1264 *pstack_usage_size
+= extra
;
1267 /* Round the size to a multiple of the required stack alignment.
1268 Since the stack is presumed to be rounded before this allocation,
1269 this will maintain the required alignment.
1271 If the stack grows downward, we could save an insn by subtracting
1272 SIZE from the stack pointer and then aligning the stack pointer.
1273 The problem with this is that the stack pointer may be unaligned
1274 between the execution of the subtraction and alignment insns and
1275 some machines do not allow this. Even on those that do, some
1276 signal handlers malfunction if a signal should occur between those
1277 insns. Since this is an extremely rare event, we have no reliable
1278 way of knowing which systems have this problem. So we avoid even
1279 momentarily mis-aligning the stack. */
1280 if (size_align
% MAX_SUPPORTED_STACK_ALIGNMENT
!= 0)
1282 size
= round_push (size
);
1284 if (flag_stack_usage_info
&& pstack_usage_size
)
1286 int align
= crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
;
1287 *pstack_usage_size
=
1288 (*pstack_usage_size
+ align
- 1) / align
* align
;
1295 /* Return the number of bytes to "protect" on the stack for -fstack-check.
1297 "protect" in the context of -fstack-check means how many bytes we
1298 should always ensure are available on the stack. More importantly
1299 this is how many bytes are skipped when probing the stack.
1301 On some targets we want to reuse the -fstack-check prologue support
1302 to give a degree of protection against stack clashing style attacks.
1304 In that scenario we do not want to skip bytes before probing as that
1305 would render the stack clash protections useless.
1307 So we never use STACK_CHECK_PROTECT directly. Instead we indirect though
1308 this helper which allows us to provide different values for
1309 -fstack-check and -fstack-clash-protection. */
1311 get_stack_check_protect (void)
1313 if (flag_stack_clash_protection
)
1315 return STACK_CHECK_PROTECT
;
1318 /* Return an rtx representing the address of an area of memory dynamically
1319 pushed on the stack.
1321 Any required stack pointer alignment is preserved.
1323 SIZE is an rtx representing the size of the area.
1325 SIZE_ALIGN is the alignment (in bits) that we know SIZE has. This
1326 parameter may be zero. If so, a proper value will be extracted
1327 from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed.
1329 REQUIRED_ALIGN is the alignment (in bits) required for the region
1332 MAX_SIZE is an upper bound for SIZE, if SIZE is not constant, or -1 if
1333 no such upper bound is known.
1335 If CANNOT_ACCUMULATE is set to TRUE, the caller guarantees that the
1336 stack space allocated by the generated code cannot be added with itself
1337 in the course of the execution of the function. It is always safe to
1338 pass FALSE here and the following criterion is sufficient in order to
1339 pass TRUE: every path in the CFG that starts at the allocation point and
1340 loops to it executes the associated deallocation code. */
1343 allocate_dynamic_stack_space (rtx size
, unsigned size_align
,
1344 unsigned required_align
,
1345 HOST_WIDE_INT max_size
,
1346 bool cannot_accumulate
)
1348 HOST_WIDE_INT stack_usage_size
= -1;
1349 rtx_code_label
*final_label
;
1350 rtx final_target
, target
;
1352 /* If we're asking for zero bytes, it doesn't matter what we point
1353 to since we can't dereference it. But return a reasonable
1355 if (size
== const0_rtx
)
1356 return virtual_stack_dynamic_rtx
;
1358 /* Otherwise, show we're calling alloca or equivalent. */
1359 cfun
->calls_alloca
= 1;
1361 /* If stack usage info is requested, look into the size we are passed.
1362 We need to do so this early to avoid the obfuscation that may be
1363 introduced later by the various alignment operations. */
1364 if (flag_stack_usage_info
)
1366 if (CONST_INT_P (size
))
1367 stack_usage_size
= INTVAL (size
);
1368 else if (REG_P (size
))
1370 /* Look into the last emitted insn and see if we can deduce
1371 something for the register. */
1374 insn
= get_last_insn ();
1375 if ((set
= single_set (insn
)) && rtx_equal_p (SET_DEST (set
), size
))
1377 if (CONST_INT_P (SET_SRC (set
)))
1378 stack_usage_size
= INTVAL (SET_SRC (set
));
1379 else if ((note
= find_reg_equal_equiv_note (insn
))
1380 && CONST_INT_P (XEXP (note
, 0)))
1381 stack_usage_size
= INTVAL (XEXP (note
, 0));
1385 /* If the size is not constant, try the maximum size. */
1386 if (stack_usage_size
< 0)
1387 stack_usage_size
= max_size
;
1389 /* If the size is still not constant, we can't say anything. */
1390 if (stack_usage_size
< 0)
1392 current_function_has_unbounded_dynamic_stack_size
= 1;
1393 stack_usage_size
= 0;
1397 get_dynamic_stack_size (&size
, size_align
, required_align
, &stack_usage_size
);
1399 target
= gen_reg_rtx (Pmode
);
1401 /* The size is supposed to be fully adjusted at this point so record it
1402 if stack usage info is requested. */
1403 if (flag_stack_usage_info
)
1405 current_function_dynamic_stack_size
+= stack_usage_size
;
1407 /* ??? This is gross but the only safe stance in the absence
1408 of stack usage oriented flow analysis. */
1409 if (!cannot_accumulate
)
1410 current_function_has_unbounded_dynamic_stack_size
= 1;
1413 do_pending_stack_adjust ();
1416 final_target
= NULL_RTX
;
1418 /* If we are splitting the stack, we need to ask the backend whether
1419 there is enough room on the current stack. If there isn't, or if
1420 the backend doesn't know how to tell is, then we need to call a
1421 function to allocate memory in some other way. This memory will
1422 be released when we release the current stack segment. The
1423 effect is that stack allocation becomes less efficient, but at
1424 least it doesn't cause a stack overflow. */
1425 if (flag_split_stack
)
1427 rtx_code_label
*available_label
;
1428 rtx ask
, space
, func
;
1430 available_label
= NULL
;
1432 if (targetm
.have_split_stack_space_check ())
1434 available_label
= gen_label_rtx ();
1436 /* This instruction will branch to AVAILABLE_LABEL if there
1437 are SIZE bytes available on the stack. */
1438 emit_insn (targetm
.gen_split_stack_space_check
1439 (size
, available_label
));
1442 /* The __morestack_allocate_stack_space function will allocate
1443 memory using malloc. If the alignment of the memory returned
1444 by malloc does not meet REQUIRED_ALIGN, we increase SIZE to
1445 make sure we allocate enough space. */
1446 if (MALLOC_ABI_ALIGNMENT
>= required_align
)
1449 ask
= expand_binop (Pmode
, add_optab
, size
,
1450 gen_int_mode (required_align
/ BITS_PER_UNIT
- 1,
1452 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1454 func
= init_one_libfunc ("__morestack_allocate_stack_space");
1456 space
= emit_library_call_value (func
, target
, LCT_NORMAL
, Pmode
,
1459 if (available_label
== NULL_RTX
)
1462 final_target
= gen_reg_rtx (Pmode
);
1464 emit_move_insn (final_target
, space
);
1466 final_label
= gen_label_rtx ();
1467 emit_jump (final_label
);
1469 emit_label (available_label
);
1472 /* We ought to be called always on the toplevel and stack ought to be aligned
1474 gcc_assert (multiple_p (stack_pointer_delta
,
1475 PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
));
1477 /* If needed, check that we have the required amount of stack. Take into
1478 account what has already been checked. */
1479 if (STACK_CHECK_MOVING_SP
)
1481 else if (flag_stack_check
== GENERIC_STACK_CHECK
)
1482 probe_stack_range (STACK_OLD_CHECK_PROTECT
+ STACK_CHECK_MAX_FRAME_SIZE
,
1484 else if (flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
)
1485 probe_stack_range (get_stack_check_protect (), size
);
1487 /* Don't let anti_adjust_stack emit notes. */
1488 suppress_reg_args_size
= true;
1490 /* Perform the required allocation from the stack. Some systems do
1491 this differently than simply incrementing/decrementing from the
1492 stack pointer, such as acquiring the space by calling malloc(). */
1493 if (targetm
.have_allocate_stack ())
1495 class expand_operand ops
[2];
1496 /* We don't have to check against the predicate for operand 0 since
1497 TARGET is known to be a pseudo of the proper mode, which must
1498 be valid for the operand. */
1499 create_fixed_operand (&ops
[0], target
);
1500 create_convert_operand_to (&ops
[1], size
, STACK_SIZE_MODE
, true);
1501 expand_insn (targetm
.code_for_allocate_stack
, 2, ops
);
1505 poly_int64 saved_stack_pointer_delta
;
1507 if (!STACK_GROWS_DOWNWARD
)
1508 emit_move_insn (target
, virtual_stack_dynamic_rtx
);
1510 /* Check stack bounds if necessary. */
1511 if (crtl
->limit_stack
)
1514 rtx_code_label
*space_available
= gen_label_rtx ();
1515 if (STACK_GROWS_DOWNWARD
)
1516 available
= expand_binop (Pmode
, sub_optab
,
1517 stack_pointer_rtx
, stack_limit_rtx
,
1518 NULL_RTX
, 1, OPTAB_WIDEN
);
1520 available
= expand_binop (Pmode
, sub_optab
,
1521 stack_limit_rtx
, stack_pointer_rtx
,
1522 NULL_RTX
, 1, OPTAB_WIDEN
);
1524 emit_cmp_and_jump_insns (available
, size
, GEU
, NULL_RTX
, Pmode
, 1,
1526 if (targetm
.have_trap ())
1527 emit_insn (targetm
.gen_trap ());
1529 error ("stack limits not supported on this target");
1531 emit_label (space_available
);
1534 saved_stack_pointer_delta
= stack_pointer_delta
;
1536 if (flag_stack_check
&& STACK_CHECK_MOVING_SP
)
1537 anti_adjust_stack_and_probe (size
, false);
1538 else if (flag_stack_clash_protection
)
1539 anti_adjust_stack_and_probe_stack_clash (size
);
1541 anti_adjust_stack (size
);
1543 /* Even if size is constant, don't modify stack_pointer_delta.
1544 The constant size alloca should preserve
1545 crtl->preferred_stack_boundary alignment. */
1546 stack_pointer_delta
= saved_stack_pointer_delta
;
1548 if (STACK_GROWS_DOWNWARD
)
1549 emit_move_insn (target
, virtual_stack_dynamic_rtx
);
1552 suppress_reg_args_size
= false;
1554 /* Finish up the split stack handling. */
1555 if (final_label
!= NULL_RTX
)
1557 gcc_assert (flag_split_stack
);
1558 emit_move_insn (final_target
, target
);
1559 emit_label (final_label
);
1560 target
= final_target
;
1563 target
= align_dynamic_address (target
, required_align
);
1565 /* Now that we've committed to a return value, mark its alignment. */
1566 mark_reg_pointer (target
, required_align
);
1568 /* Record the new stack level. */
1569 record_new_stack_level ();
1574 /* Return an rtx representing the address of an area of memory already
1575 statically pushed onto the stack in the virtual stack vars area. (It is
1576 assumed that the area is allocated in the function prologue.)
1578 Any required stack pointer alignment is preserved.
1580 OFFSET is the offset of the area into the virtual stack vars area.
1582 REQUIRED_ALIGN is the alignment (in bits) required for the region
1586 get_dynamic_stack_base (poly_int64 offset
, unsigned required_align
)
1590 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
1591 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
1593 target
= gen_reg_rtx (Pmode
);
1594 emit_move_insn (target
, virtual_stack_vars_rtx
);
1595 target
= expand_binop (Pmode
, add_optab
, target
,
1596 gen_int_mode (offset
, Pmode
),
1597 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1598 target
= align_dynamic_address (target
, required_align
);
1600 /* Now that we've committed to a return value, mark its alignment. */
1601 mark_reg_pointer (target
, required_align
);
1606 /* A front end may want to override GCC's stack checking by providing a
1607 run-time routine to call to check the stack, so provide a mechanism for
1608 calling that routine. */
1610 static GTY(()) rtx stack_check_libfunc
;
1613 set_stack_check_libfunc (const char *libfunc_name
)
1615 gcc_assert (stack_check_libfunc
== NULL_RTX
);
1616 stack_check_libfunc
= gen_rtx_SYMBOL_REF (Pmode
, libfunc_name
);
1617 tree decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
1618 get_identifier (libfunc_name
), void_type_node
);
1619 DECL_EXTERNAL (decl
) = 1;
1620 SET_SYMBOL_REF_DECL (stack_check_libfunc
, decl
);
1623 /* Emit one stack probe at ADDRESS, an address within the stack. */
1626 emit_stack_probe (rtx address
)
1628 if (targetm
.have_probe_stack_address ())
1630 class expand_operand ops
[1];
1631 insn_code icode
= targetm
.code_for_probe_stack_address
;
1632 create_address_operand (ops
, address
);
1633 maybe_legitimize_operands (icode
, 0, 1, ops
);
1634 expand_insn (icode
, 1, ops
);
1638 rtx memref
= gen_rtx_MEM (word_mode
, address
);
1640 MEM_VOLATILE_P (memref
) = 1;
1641 memref
= validize_mem (memref
);
1643 /* See if we have an insn to probe the stack. */
1644 if (targetm
.have_probe_stack ())
1645 emit_insn (targetm
.gen_probe_stack (memref
));
1647 emit_move_insn (memref
, const0_rtx
);
1651 /* Probe a range of stack addresses from FIRST to FIRST+SIZE, inclusive.
1652 FIRST is a constant and size is a Pmode RTX. These are offsets from
1653 the current stack pointer. STACK_GROWS_DOWNWARD says whether to add
1654 or subtract them from the stack pointer. */
1656 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
1658 #if STACK_GROWS_DOWNWARD
1659 #define STACK_GROW_OP MINUS
1660 #define STACK_GROW_OPTAB sub_optab
1661 #define STACK_GROW_OFF(off) -(off)
1663 #define STACK_GROW_OP PLUS
1664 #define STACK_GROW_OPTAB add_optab
1665 #define STACK_GROW_OFF(off) (off)
1669 probe_stack_range (HOST_WIDE_INT first
, rtx size
)
1671 /* First ensure SIZE is Pmode. */
1672 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
1673 size
= convert_to_mode (Pmode
, size
, 1);
1675 /* Next see if we have a function to check the stack. */
1676 if (stack_check_libfunc
)
1678 rtx addr
= memory_address (Pmode
,
1679 gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1681 plus_constant (Pmode
,
1683 emit_library_call (stack_check_libfunc
, LCT_THROW
, VOIDmode
,
1687 /* Next see if we have an insn to check the stack. */
1688 else if (targetm
.have_check_stack ())
1690 class expand_operand ops
[1];
1691 rtx addr
= memory_address (Pmode
,
1692 gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1694 plus_constant (Pmode
,
1697 create_input_operand (&ops
[0], addr
, Pmode
);
1698 success
= maybe_expand_insn (targetm
.code_for_check_stack
, 1, ops
);
1699 gcc_assert (success
);
1702 /* Otherwise we have to generate explicit probes. If we have a constant
1703 small number of them to generate, that's the easy case. */
1704 else if (CONST_INT_P (size
) && INTVAL (size
) < 7 * PROBE_INTERVAL
)
1706 HOST_WIDE_INT isize
= INTVAL (size
), i
;
1709 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
1710 it exceeds SIZE. If only one probe is needed, this will not
1711 generate any code. Then probe at FIRST + SIZE. */
1712 for (i
= PROBE_INTERVAL
; i
< isize
; i
+= PROBE_INTERVAL
)
1714 addr
= memory_address (Pmode
,
1715 plus_constant (Pmode
, stack_pointer_rtx
,
1716 STACK_GROW_OFF (first
+ i
)));
1717 emit_stack_probe (addr
);
1720 addr
= memory_address (Pmode
,
1721 plus_constant (Pmode
, stack_pointer_rtx
,
1722 STACK_GROW_OFF (first
+ isize
)));
1723 emit_stack_probe (addr
);
1726 /* In the variable case, do the same as above, but in a loop. Note that we
1727 must be extra careful with variables wrapping around because we might be
1728 at the very top (or the very bottom) of the address space and we have to
1729 be able to handle this case properly; in particular, we use an equality
1730 test for the loop condition. */
1733 rtx rounded_size
, rounded_size_op
, test_addr
, last_addr
, temp
;
1734 rtx_code_label
*loop_lab
= gen_label_rtx ();
1735 rtx_code_label
*end_lab
= gen_label_rtx ();
1737 /* Step 1: round SIZE to the previous multiple of the interval. */
1739 /* ROUNDED_SIZE = SIZE & -PROBE_INTERVAL */
1741 = simplify_gen_binary (AND
, Pmode
, size
,
1742 gen_int_mode (-PROBE_INTERVAL
, Pmode
));
1743 rounded_size_op
= force_operand (rounded_size
, NULL_RTX
);
1746 /* Step 2: compute initial and final value of the loop counter. */
1748 /* TEST_ADDR = SP + FIRST. */
1749 test_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1751 gen_int_mode (first
, Pmode
)),
1754 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
1755 last_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1757 rounded_size_op
), NULL_RTX
);
1762 while (TEST_ADDR != LAST_ADDR)
1764 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
1768 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
1769 until it is equal to ROUNDED_SIZE. */
1771 emit_label (loop_lab
);
1773 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
1774 emit_cmp_and_jump_insns (test_addr
, last_addr
, EQ
, NULL_RTX
, Pmode
, 1,
1777 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
1778 temp
= expand_binop (Pmode
, STACK_GROW_OPTAB
, test_addr
,
1779 gen_int_mode (PROBE_INTERVAL
, Pmode
), test_addr
,
1782 gcc_assert (temp
== test_addr
);
1784 /* Probe at TEST_ADDR. */
1785 emit_stack_probe (test_addr
);
1787 emit_jump (loop_lab
);
1789 emit_label (end_lab
);
1792 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
1793 that SIZE is equal to ROUNDED_SIZE. */
1795 /* TEMP = SIZE - ROUNDED_SIZE. */
1796 temp
= simplify_gen_binary (MINUS
, Pmode
, size
, rounded_size
);
1797 if (temp
!= const0_rtx
)
1801 if (CONST_INT_P (temp
))
1803 /* Use [base + disp} addressing mode if supported. */
1804 HOST_WIDE_INT offset
= INTVAL (temp
);
1805 addr
= memory_address (Pmode
,
1806 plus_constant (Pmode
, last_addr
,
1807 STACK_GROW_OFF (offset
)));
1811 /* Manual CSE if the difference is not known at compile-time. */
1812 temp
= gen_rtx_MINUS (Pmode
, size
, rounded_size_op
);
1813 addr
= memory_address (Pmode
,
1814 gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1818 emit_stack_probe (addr
);
1822 /* Make sure nothing is scheduled before we are done. */
1823 emit_insn (gen_blockage ());
1826 /* Compute parameters for stack clash probing a dynamic stack
1827 allocation of SIZE bytes.
1829 We compute ROUNDED_SIZE, LAST_ADDR, RESIDUAL and PROBE_INTERVAL.
1831 Additionally we conditionally dump the type of probing that will
1832 be needed given the values computed. */
1835 compute_stack_clash_protection_loop_data (rtx
*rounded_size
, rtx
*last_addr
,
1837 HOST_WIDE_INT
*probe_interval
,
1840 /* Round SIZE down to STACK_CLASH_PROTECTION_PROBE_INTERVAL */
1842 = 1 << param_stack_clash_protection_probe_interval
;
1843 *rounded_size
= simplify_gen_binary (AND
, Pmode
, size
,
1844 GEN_INT (-*probe_interval
));
1846 /* Compute the value of the stack pointer for the last iteration.
1847 It's just SP + ROUNDED_SIZE. */
1848 rtx rounded_size_op
= force_operand (*rounded_size
, NULL_RTX
);
1849 *last_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1854 /* Compute any residuals not allocated by the loop above. Residuals
1855 are just the ROUNDED_SIZE - SIZE. */
1856 *residual
= simplify_gen_binary (MINUS
, Pmode
, size
, *rounded_size
);
1858 /* Dump key information to make writing tests easy. */
1861 if (*rounded_size
== CONST0_RTX (Pmode
))
1863 "Stack clash skipped dynamic allocation and probing loop.\n");
1864 else if (CONST_INT_P (*rounded_size
)
1865 && INTVAL (*rounded_size
) <= 4 * *probe_interval
)
1867 "Stack clash dynamic allocation and probing inline.\n");
1868 else if (CONST_INT_P (*rounded_size
))
1870 "Stack clash dynamic allocation and probing in "
1874 "Stack clash dynamic allocation and probing in loop.\n");
1876 if (*residual
!= CONST0_RTX (Pmode
))
1878 "Stack clash dynamic allocation and probing residuals.\n");
1881 "Stack clash skipped dynamic allocation and "
1882 "probing residuals.\n");
1886 /* Emit the start of an allocate/probe loop for stack
1889 LOOP_LAB and END_LAB are returned for use when we emit the
1892 LAST addr is the value for SP which stops the loop. */
1894 emit_stack_clash_protection_probe_loop_start (rtx
*loop_lab
,
1899 /* Essentially we want to emit any setup code, the top of loop
1900 label and the comparison at the top of the loop. */
1901 *loop_lab
= gen_label_rtx ();
1902 *end_lab
= gen_label_rtx ();
1904 emit_label (*loop_lab
);
1906 emit_cmp_and_jump_insns (stack_pointer_rtx
, last_addr
, EQ
, NULL_RTX
,
1907 Pmode
, 1, *end_lab
);
1910 /* Emit the end of a stack clash probing loop.
1912 This consists of just the jump back to LOOP_LAB and
1913 emitting END_LOOP after the loop. */
1916 emit_stack_clash_protection_probe_loop_end (rtx loop_lab
, rtx end_loop
,
1917 rtx last_addr
, bool rotated
)
1920 emit_cmp_and_jump_insns (stack_pointer_rtx
, last_addr
, NE
, NULL_RTX
,
1921 Pmode
, 1, loop_lab
);
1923 emit_jump (loop_lab
);
1925 emit_label (end_loop
);
1929 /* Adjust the stack pointer by minus SIZE (an rtx for a number of bytes)
1930 while probing it. This pushes when SIZE is positive. SIZE need not
1933 This is subtly different than anti_adjust_stack_and_probe to try and
1934 prevent stack-clash attacks
1936 1. It must assume no knowledge of the probing state, any allocation
1939 Consider the case of a 1 byte alloca in a loop. If the sum of the
1940 allocations is large, then this could be used to jump the guard if
1941 probes were not emitted.
1943 2. It never skips probes, whereas anti_adjust_stack_and_probe will
1944 skip probes on the first couple PROBE_INTERVALs on the assumption
1945 they're done elsewhere.
1947 3. It only allocates and probes SIZE bytes, it does not need to
1948 allocate/probe beyond that because this probing style does not
1949 guarantee signal handling capability if the guard is hit. */
1952 anti_adjust_stack_and_probe_stack_clash (rtx size
)
1954 /* First ensure SIZE is Pmode. */
1955 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
1956 size
= convert_to_mode (Pmode
, size
, 1);
1958 /* We can get here with a constant size on some targets. */
1959 rtx rounded_size
, last_addr
, residual
;
1960 HOST_WIDE_INT probe_interval
, probe_range
;
1961 bool target_probe_range_p
= false;
1962 compute_stack_clash_protection_loop_data (&rounded_size
, &last_addr
,
1963 &residual
, &probe_interval
, size
);
1965 /* Get the back-end specific probe ranges. */
1966 probe_range
= targetm
.stack_clash_protection_alloca_probe_range ();
1967 target_probe_range_p
= probe_range
!= 0;
1968 gcc_assert (probe_range
>= 0);
1970 /* If no back-end specific range defined, default to the top of the newly
1972 if (probe_range
== 0)
1973 probe_range
= probe_interval
- GET_MODE_SIZE (word_mode
);
1975 if (rounded_size
!= CONST0_RTX (Pmode
))
1977 if (CONST_INT_P (rounded_size
)
1978 && INTVAL (rounded_size
) <= 4 * probe_interval
)
1980 for (HOST_WIDE_INT i
= 0;
1981 i
< INTVAL (rounded_size
);
1982 i
+= probe_interval
)
1984 anti_adjust_stack (GEN_INT (probe_interval
));
1985 /* The prologue does not probe residuals. Thus the offset
1986 here to probe just beyond what the prologue had already
1988 emit_stack_probe (plus_constant (Pmode
, stack_pointer_rtx
,
1991 emit_insn (gen_blockage ());
1996 rtx loop_lab
, end_loop
;
1997 bool rotate_loop
= CONST_INT_P (rounded_size
);
1998 emit_stack_clash_protection_probe_loop_start (&loop_lab
, &end_loop
,
1999 last_addr
, rotate_loop
);
2001 anti_adjust_stack (GEN_INT (probe_interval
));
2003 /* The prologue does not probe residuals. Thus the offset here
2004 to probe just beyond what the prologue had already
2006 emit_stack_probe (plus_constant (Pmode
, stack_pointer_rtx
,
2009 emit_stack_clash_protection_probe_loop_end (loop_lab
, end_loop
,
2010 last_addr
, rotate_loop
);
2011 emit_insn (gen_blockage ());
2015 if (residual
!= CONST0_RTX (Pmode
))
2017 rtx label
= NULL_RTX
;
2018 /* RESIDUAL could be zero at runtime and in that case *sp could
2019 hold live data. Furthermore, we do not want to probe into the
2022 If TARGET_PROBE_RANGE_P then the target has promised it's safe to
2023 probe at offset 0. In which case we no longer have to check for
2024 RESIDUAL == 0. However we still need to probe at the right offset
2025 when RESIDUAL > PROBE_RANGE, in which case we probe at PROBE_RANGE.
2027 If !TARGET_PROBE_RANGE_P then go ahead and just guard the probe at *sp
2028 on RESIDUAL != 0 at runtime if RESIDUAL is not a compile time constant.
2030 anti_adjust_stack (residual
);
2032 if (!CONST_INT_P (residual
))
2034 label
= gen_label_rtx ();
2035 rtx_code op
= target_probe_range_p
? LT
: EQ
;
2036 rtx probe_cmp_value
= target_probe_range_p
2037 ? gen_rtx_CONST_INT (GET_MODE (residual
), probe_range
)
2038 : CONST0_RTX (GET_MODE (residual
));
2040 if (target_probe_range_p
)
2041 emit_stack_probe (stack_pointer_rtx
);
2043 emit_cmp_and_jump_insns (residual
, probe_cmp_value
,
2044 op
, NULL_RTX
, Pmode
, 1, label
);
2049 /* If RESIDUAL isn't a constant and TARGET_PROBE_RANGE_P then we probe up
2050 by the ABI defined safe value. */
2051 if (!CONST_INT_P (residual
) && target_probe_range_p
)
2052 x
= GEN_INT (probe_range
);
2053 /* If RESIDUAL is a constant but smaller than the ABI defined safe value,
2054 we still want to probe up, but the safest amount if a word. */
2055 else if (target_probe_range_p
)
2057 if (INTVAL (residual
) <= probe_range
)
2058 x
= GEN_INT (GET_MODE_SIZE (word_mode
));
2060 x
= GEN_INT (probe_range
);
2063 /* If nothing else, probe at the top of the new allocation. */
2064 x
= plus_constant (Pmode
, residual
, -GET_MODE_SIZE (word_mode
));
2066 emit_stack_probe (gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, x
));
2068 emit_insn (gen_blockage ());
2069 if (!CONST_INT_P (residual
))
2075 /* Adjust the stack pointer by minus SIZE (an rtx for a number of bytes)
2076 while probing it. This pushes when SIZE is positive. SIZE need not
2077 be constant. If ADJUST_BACK is true, adjust back the stack pointer
2078 by plus SIZE at the end. */
2081 anti_adjust_stack_and_probe (rtx size
, bool adjust_back
)
2083 /* We skip the probe for the first interval + a small dope of 4 words and
2084 probe that many bytes past the specified size to maintain a protection
2085 area at the botton of the stack. */
2086 const int dope
= 4 * UNITS_PER_WORD
;
2088 /* First ensure SIZE is Pmode. */
2089 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
2090 size
= convert_to_mode (Pmode
, size
, 1);
2092 /* If we have a constant small number of probes to generate, that's the
2094 if (CONST_INT_P (size
) && INTVAL (size
) < 7 * PROBE_INTERVAL
)
2096 HOST_WIDE_INT isize
= INTVAL (size
), i
;
2097 bool first_probe
= true;
2099 /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for
2100 values of N from 1 until it exceeds SIZE. If only one probe is
2101 needed, this will not generate any code. Then adjust and probe
2102 to PROBE_INTERVAL + SIZE. */
2103 for (i
= PROBE_INTERVAL
; i
< isize
; i
+= PROBE_INTERVAL
)
2107 anti_adjust_stack (GEN_INT (2 * PROBE_INTERVAL
+ dope
));
2108 first_probe
= false;
2111 anti_adjust_stack (GEN_INT (PROBE_INTERVAL
));
2112 emit_stack_probe (stack_pointer_rtx
);
2116 anti_adjust_stack (plus_constant (Pmode
, size
, PROBE_INTERVAL
+ dope
));
2118 anti_adjust_stack (plus_constant (Pmode
, size
, PROBE_INTERVAL
- i
));
2119 emit_stack_probe (stack_pointer_rtx
);
2122 /* In the variable case, do the same as above, but in a loop. Note that we
2123 must be extra careful with variables wrapping around because we might be
2124 at the very top (or the very bottom) of the address space and we have to
2125 be able to handle this case properly; in particular, we use an equality
2126 test for the loop condition. */
2129 rtx rounded_size
, rounded_size_op
, last_addr
, temp
;
2130 rtx_code_label
*loop_lab
= gen_label_rtx ();
2131 rtx_code_label
*end_lab
= gen_label_rtx ();
2134 /* Step 1: round SIZE to the previous multiple of the interval. */
2136 /* ROUNDED_SIZE = SIZE & -PROBE_INTERVAL */
2138 = simplify_gen_binary (AND
, Pmode
, size
,
2139 gen_int_mode (-PROBE_INTERVAL
, Pmode
));
2140 rounded_size_op
= force_operand (rounded_size
, NULL_RTX
);
2143 /* Step 2: compute initial and final value of the loop counter. */
2145 /* SP = SP_0 + PROBE_INTERVAL. */
2146 anti_adjust_stack (GEN_INT (PROBE_INTERVAL
+ dope
));
2148 /* LAST_ADDR = SP_0 + PROBE_INTERVAL + ROUNDED_SIZE. */
2149 last_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
2151 rounded_size_op
), NULL_RTX
);
2156 while (SP != LAST_ADDR)
2158 SP = SP + PROBE_INTERVAL
2162 adjusts SP and probes at PROBE_INTERVAL + N * PROBE_INTERVAL for
2163 values of N from 1 until it is equal to ROUNDED_SIZE. */
2165 emit_label (loop_lab
);
2167 /* Jump to END_LAB if SP == LAST_ADDR. */
2168 emit_cmp_and_jump_insns (stack_pointer_rtx
, last_addr
, EQ
, NULL_RTX
,
2171 /* SP = SP + PROBE_INTERVAL and probe at SP. */
2172 anti_adjust_stack (GEN_INT (PROBE_INTERVAL
));
2173 emit_stack_probe (stack_pointer_rtx
);
2175 emit_jump (loop_lab
);
2177 emit_label (end_lab
);
2180 /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot
2181 assert at compile-time that SIZE is equal to ROUNDED_SIZE. */
2183 /* TEMP = SIZE - ROUNDED_SIZE. */
2184 temp
= simplify_gen_binary (MINUS
, Pmode
, size
, rounded_size
);
2185 if (temp
!= const0_rtx
)
2187 /* Manual CSE if the difference is not known at compile-time. */
2188 if (GET_CODE (temp
) != CONST_INT
)
2189 temp
= gen_rtx_MINUS (Pmode
, size
, rounded_size_op
);
2190 anti_adjust_stack (temp
);
2191 emit_stack_probe (stack_pointer_rtx
);
2195 /* Adjust back and account for the additional first interval. */
2197 adjust_stack (plus_constant (Pmode
, size
, PROBE_INTERVAL
+ dope
));
2199 adjust_stack (GEN_INT (PROBE_INTERVAL
+ dope
));
2202 /* Return an rtx representing the register or memory location
2203 in which a scalar value of data type VALTYPE
2204 was returned by a function call to function FUNC.
2205 FUNC is a FUNCTION_DECL, FNTYPE a FUNCTION_TYPE node if the precise
2206 function is known, otherwise 0.
2207 OUTGOING is 1 if on a machine with register windows this function
2208 should return the register in which the function will put its result
2212 hard_function_value (const_tree valtype
, const_tree func
, const_tree fntype
,
2213 int outgoing ATTRIBUTE_UNUSED
)
2217 val
= targetm
.calls
.function_value (valtype
, func
? func
: fntype
, outgoing
);
2220 && GET_MODE (val
) == BLKmode
)
2222 unsigned HOST_WIDE_INT bytes
= arg_int_size_in_bytes (valtype
);
2223 opt_scalar_int_mode tmpmode
;
2225 /* int_size_in_bytes can return -1. We don't need a check here
2226 since the value of bytes will then be large enough that no
2227 mode will match anyway. */
2229 FOR_EACH_MODE_IN_CLASS (tmpmode
, MODE_INT
)
2231 /* Have we found a large enough mode? */
2232 if (GET_MODE_SIZE (tmpmode
.require ()) >= bytes
)
2236 PUT_MODE (val
, tmpmode
.require ());
2241 /* Return an rtx representing the register or memory location
2242 in which a scalar value of mode MODE was returned by a library call. */
2245 hard_libcall_value (machine_mode mode
, rtx fun
)
2247 return targetm
.calls
.libcall_value (mode
, fun
);
2250 /* Look up the tree code for a given rtx code
2251 to provide the arithmetic operation for real_arithmetic.
2252 The function returns an int because the caller may not know
2253 what `enum tree_code' means. */
2256 rtx_to_tree_code (enum rtx_code code
)
2258 enum tree_code tcode
;
2281 tcode
= LAST_AND_UNUSED_TREE_CODE
;
2284 return ((int) tcode
);
2287 #include "gt-explow.h"