1 /* Subroutines for manipulating rtx's in semantically interesting ways.
2 Copyright (C) 1987-2019 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"
46 static rtx
break_out_memory_refs (rtx
);
47 static void anti_adjust_stack_and_probe_stack_clash (rtx
);
50 /* Truncate and perhaps sign-extend C as appropriate for MODE. */
53 trunc_int_for_mode (HOST_WIDE_INT c
, machine_mode mode
)
55 /* Not scalar_int_mode because we also allow pointer bound modes. */
56 scalar_mode smode
= as_a
<scalar_mode
> (mode
);
57 int width
= GET_MODE_PRECISION (smode
);
59 /* You want to truncate to a _what_? */
60 gcc_assert (SCALAR_INT_MODE_P (mode
));
62 /* Canonicalize BImode to 0 and STORE_FLAG_VALUE. */
64 return c
& 1 ? STORE_FLAG_VALUE
: 0;
66 /* Sign-extend for the requested mode. */
68 if (width
< HOST_BITS_PER_WIDE_INT
)
70 HOST_WIDE_INT sign
= 1;
80 /* Likewise for polynomial values, using the sign-extended representation
81 for each individual coefficient. */
84 trunc_int_for_mode (poly_int64 x
, machine_mode mode
)
86 for (unsigned int i
= 0; i
< NUM_POLY_INT_COEFFS
; ++i
)
87 x
.coeffs
[i
] = trunc_int_for_mode (x
.coeffs
[i
], mode
);
91 /* Return an rtx for the sum of X and the integer C, given that X has
92 mode MODE. INPLACE is true if X can be modified inplace or false
93 if it must be treated as immutable. */
96 plus_constant (machine_mode mode
, rtx x
, poly_int64 c
, bool inplace
)
101 int all_constant
= 0;
103 gcc_assert (GET_MODE (x
) == VOIDmode
|| GET_MODE (x
) == mode
);
115 CASE_CONST_SCALAR_INT
:
116 return immed_wide_int_const (wi::add (rtx_mode_t (x
, mode
), c
), mode
);
118 /* If this is a reference to the constant pool, try replacing it with
119 a reference to a new constant. If the resulting address isn't
120 valid, don't return it because we have no way to validize it. */
121 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
122 && CONSTANT_POOL_ADDRESS_P (XEXP (x
, 0)))
124 rtx cst
= get_pool_constant (XEXP (x
, 0));
126 if (GET_CODE (cst
) == CONST_VECTOR
127 && GET_MODE_INNER (GET_MODE (cst
)) == mode
)
129 cst
= gen_lowpart (mode
, cst
);
132 if (GET_MODE (cst
) == VOIDmode
|| GET_MODE (cst
) == mode
)
134 tem
= plus_constant (mode
, cst
, c
);
135 tem
= force_const_mem (GET_MODE (x
), tem
);
136 /* Targets may disallow some constants in the constant pool, thus
137 force_const_mem may return NULL_RTX. */
138 if (tem
&& memory_address_p (GET_MODE (tem
), XEXP (tem
, 0)))
145 /* If adding to something entirely constant, set a flag
146 so that we can add a CONST around the result. */
147 if (inplace
&& shared_const_p (x
))
159 /* The interesting case is adding the integer to a sum. Look
160 for constant term in the sum and combine with C. For an
161 integer constant term or a constant term that is not an
162 explicit integer, we combine or group them together anyway.
164 We may not immediately return from the recursive call here, lest
165 all_constant gets lost. */
167 if (CONSTANT_P (XEXP (x
, 1)))
169 rtx term
= plus_constant (mode
, XEXP (x
, 1), c
, inplace
);
170 if (term
== const0_rtx
)
175 x
= gen_rtx_PLUS (mode
, XEXP (x
, 0), term
);
178 else if (rtx
*const_loc
= find_constant_term_loc (&y
))
182 /* We need to be careful since X may be shared and we can't
183 modify it in place. */
185 const_loc
= find_constant_term_loc (&x
);
187 *const_loc
= plus_constant (mode
, *const_loc
, c
, true);
193 if (CONST_POLY_INT_P (x
))
194 return immed_wide_int_const (const_poly_int_value (x
) + c
, mode
);
199 x
= gen_rtx_PLUS (mode
, x
, gen_int_mode (c
, mode
));
201 if (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
)
203 else if (all_constant
)
204 return gen_rtx_CONST (mode
, x
);
209 /* If X is a sum, return a new sum like X but lacking any constant terms.
210 Add all the removed constant terms into *CONSTPTR.
211 X itself is not altered. The result != X if and only if
212 it is not isomorphic to X. */
215 eliminate_constant_term (rtx x
, rtx
*constptr
)
220 if (GET_CODE (x
) != PLUS
)
223 /* First handle constants appearing at this level explicitly. */
224 if (CONST_INT_P (XEXP (x
, 1))
225 && (tem
= simplify_binary_operation (PLUS
, GET_MODE (x
), *constptr
,
227 && CONST_INT_P (tem
))
230 return eliminate_constant_term (XEXP (x
, 0), constptr
);
234 x0
= eliminate_constant_term (XEXP (x
, 0), &tem
);
235 x1
= eliminate_constant_term (XEXP (x
, 1), &tem
);
236 if ((x1
!= XEXP (x
, 1) || x0
!= XEXP (x
, 0))
237 && (tem
= simplify_binary_operation (PLUS
, GET_MODE (x
),
238 *constptr
, tem
)) != 0
239 && CONST_INT_P (tem
))
242 return gen_rtx_PLUS (GET_MODE (x
), x0
, x1
);
249 /* Return a copy of X in which all memory references
250 and all constants that involve symbol refs
251 have been replaced with new temporary registers.
252 Also emit code to load the memory locations and constants
253 into those registers.
255 If X contains no such constants or memory references,
256 X itself (not a copy) is returned.
258 If a constant is found in the address that is not a legitimate constant
259 in an insn, it is left alone in the hope that it might be valid in the
262 X may contain no arithmetic except addition, subtraction and multiplication.
263 Values returned by expand_expr with 1 for sum_ok fit this constraint. */
266 break_out_memory_refs (rtx x
)
269 || (CONSTANT_P (x
) && CONSTANT_ADDRESS_P (x
)
270 && GET_MODE (x
) != VOIDmode
))
271 x
= force_reg (GET_MODE (x
), x
);
272 else if (GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
273 || GET_CODE (x
) == MULT
)
275 rtx op0
= break_out_memory_refs (XEXP (x
, 0));
276 rtx op1
= break_out_memory_refs (XEXP (x
, 1));
278 if (op0
!= XEXP (x
, 0) || op1
!= XEXP (x
, 1))
279 x
= simplify_gen_binary (GET_CODE (x
), GET_MODE (x
), op0
, op1
);
285 /* Given X, a memory address in address space AS' pointer mode, convert it to
286 an address in the address space's address mode, or vice versa (TO_MODE says
287 which way). We take advantage of the fact that pointers are not allowed to
288 overflow by commuting arithmetic operations over conversions so that address
289 arithmetic insns can be used. IN_CONST is true if this conversion is inside
290 a CONST. NO_EMIT is true if no insns should be emitted, and instead
291 it should return NULL if it can't be simplified without emitting insns. */
294 convert_memory_address_addr_space_1 (scalar_int_mode to_mode ATTRIBUTE_UNUSED
,
295 rtx x
, addr_space_t as ATTRIBUTE_UNUSED
,
296 bool in_const ATTRIBUTE_UNUSED
,
297 bool no_emit ATTRIBUTE_UNUSED
)
299 #ifndef POINTERS_EXTEND_UNSIGNED
300 gcc_assert (GET_MODE (x
) == to_mode
|| GET_MODE (x
) == VOIDmode
);
302 #else /* defined(POINTERS_EXTEND_UNSIGNED) */
303 scalar_int_mode pointer_mode
, address_mode
, from_mode
;
307 /* If X already has the right mode, just return it. */
308 if (GET_MODE (x
) == to_mode
)
311 pointer_mode
= targetm
.addr_space
.pointer_mode (as
);
312 address_mode
= targetm
.addr_space
.address_mode (as
);
313 from_mode
= to_mode
== pointer_mode
? address_mode
: pointer_mode
;
315 /* Here we handle some special cases. If none of them apply, fall through
316 to the default case. */
317 switch (GET_CODE (x
))
319 CASE_CONST_SCALAR_INT
:
320 if (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (from_mode
))
322 else if (POINTERS_EXTEND_UNSIGNED
< 0)
324 else if (POINTERS_EXTEND_UNSIGNED
> 0)
328 temp
= simplify_unary_operation (code
, to_mode
, x
, from_mode
);
334 if ((SUBREG_PROMOTED_VAR_P (x
) || REG_POINTER (SUBREG_REG (x
)))
335 && GET_MODE (SUBREG_REG (x
)) == to_mode
)
336 return SUBREG_REG (x
);
340 temp
= gen_rtx_LABEL_REF (to_mode
, label_ref_label (x
));
341 LABEL_REF_NONLOCAL_P (temp
) = LABEL_REF_NONLOCAL_P (x
);
345 temp
= shallow_copy_rtx (x
);
346 PUT_MODE (temp
, to_mode
);
350 temp
= convert_memory_address_addr_space_1 (to_mode
, XEXP (x
, 0), as
,
352 return temp
? gen_rtx_CONST (to_mode
, temp
) : temp
;
356 /* For addition we can safely permute the conversion and addition
357 operation if one operand is a constant and converting the constant
358 does not change it or if one operand is a constant and we are
359 using a ptr_extend instruction (POINTERS_EXTEND_UNSIGNED < 0).
360 We can always safely permute them if we are making the address
361 narrower. Inside a CONST RTL, this is safe for both pointers
362 zero or sign extended as pointers cannot wrap. */
363 if (GET_MODE_SIZE (to_mode
) < GET_MODE_SIZE (from_mode
)
364 || (GET_CODE (x
) == PLUS
365 && CONST_INT_P (XEXP (x
, 1))
366 && ((in_const
&& POINTERS_EXTEND_UNSIGNED
!= 0)
367 || XEXP (x
, 1) == convert_memory_address_addr_space_1
368 (to_mode
, XEXP (x
, 1), as
, in_const
,
370 || POINTERS_EXTEND_UNSIGNED
< 0)))
372 temp
= convert_memory_address_addr_space_1 (to_mode
, XEXP (x
, 0),
373 as
, in_const
, no_emit
);
374 return (temp
? gen_rtx_fmt_ee (GET_CODE (x
), to_mode
,
387 return convert_modes (to_mode
, from_mode
,
388 x
, POINTERS_EXTEND_UNSIGNED
);
389 #endif /* defined(POINTERS_EXTEND_UNSIGNED) */
392 /* Given X, a memory address in address space AS' pointer mode, convert it to
393 an address in the address space's address mode, or vice versa (TO_MODE says
394 which way). We take advantage of the fact that pointers are not allowed to
395 overflow by commuting arithmetic operations over conversions so that address
396 arithmetic insns can be used. */
399 convert_memory_address_addr_space (scalar_int_mode to_mode
, rtx x
,
402 return convert_memory_address_addr_space_1 (to_mode
, x
, as
, false, false);
406 /* Return something equivalent to X but valid as a memory address for something
407 of mode MODE in the named address space AS. When X is not itself valid,
408 this works by copying X or subexpressions of it into registers. */
411 memory_address_addr_space (machine_mode mode
, rtx x
, addr_space_t as
)
414 scalar_int_mode address_mode
= targetm
.addr_space
.address_mode (as
);
416 x
= convert_memory_address_addr_space (address_mode
, x
, as
);
418 /* By passing constant addresses through registers
419 we get a chance to cse them. */
420 if (! cse_not_expected
&& CONSTANT_P (x
) && CONSTANT_ADDRESS_P (x
))
421 x
= force_reg (address_mode
, x
);
423 /* We get better cse by rejecting indirect addressing at this stage.
424 Let the combiner create indirect addresses where appropriate.
425 For now, generate the code so that the subexpressions useful to share
426 are visible. But not if cse won't be done! */
429 if (! cse_not_expected
&& !REG_P (x
))
430 x
= break_out_memory_refs (x
);
432 /* At this point, any valid address is accepted. */
433 if (memory_address_addr_space_p (mode
, x
, as
))
436 /* If it was valid before but breaking out memory refs invalidated it,
437 use it the old way. */
438 if (memory_address_addr_space_p (mode
, oldx
, as
))
444 /* Perform machine-dependent transformations on X
445 in certain cases. This is not necessary since the code
446 below can handle all possible cases, but machine-dependent
447 transformations can make better code. */
450 x
= targetm
.addr_space
.legitimize_address (x
, oldx
, mode
, as
);
451 if (orig_x
!= x
&& memory_address_addr_space_p (mode
, x
, as
))
455 /* PLUS and MULT can appear in special ways
456 as the result of attempts to make an address usable for indexing.
457 Usually they are dealt with by calling force_operand, below.
458 But a sum containing constant terms is special
459 if removing them makes the sum a valid address:
460 then we generate that address in a register
461 and index off of it. We do this because it often makes
462 shorter code, and because the addresses thus generated
463 in registers often become common subexpressions. */
464 if (GET_CODE (x
) == PLUS
)
466 rtx constant_term
= const0_rtx
;
467 rtx y
= eliminate_constant_term (x
, &constant_term
);
468 if (constant_term
== const0_rtx
469 || ! memory_address_addr_space_p (mode
, y
, as
))
470 x
= force_operand (x
, NULL_RTX
);
473 y
= gen_rtx_PLUS (GET_MODE (x
), copy_to_reg (y
), constant_term
);
474 if (! memory_address_addr_space_p (mode
, y
, as
))
475 x
= force_operand (x
, NULL_RTX
);
481 else if (GET_CODE (x
) == MULT
|| GET_CODE (x
) == MINUS
)
482 x
= force_operand (x
, NULL_RTX
);
484 /* If we have a register that's an invalid address,
485 it must be a hard reg of the wrong class. Copy it to a pseudo. */
489 /* Last resort: copy the value to a register, since
490 the register is a valid address. */
492 x
= force_reg (address_mode
, x
);
497 gcc_assert (memory_address_addr_space_p (mode
, x
, as
));
498 /* If we didn't change the address, we are done. Otherwise, mark
499 a reg as a pointer if we have REG or REG + CONST_INT. */
503 mark_reg_pointer (x
, BITS_PER_UNIT
);
504 else if (GET_CODE (x
) == PLUS
505 && REG_P (XEXP (x
, 0))
506 && CONST_INT_P (XEXP (x
, 1)))
507 mark_reg_pointer (XEXP (x
, 0), BITS_PER_UNIT
);
509 /* OLDX may have been the address on a temporary. Update the address
510 to indicate that X is now used. */
511 update_temp_slot_address (oldx
, x
);
516 /* Convert a mem ref into one with a valid memory address.
517 Pass through anything else unchanged. */
520 validize_mem (rtx ref
)
524 ref
= use_anchored_address (ref
);
525 if (memory_address_addr_space_p (GET_MODE (ref
), XEXP (ref
, 0),
526 MEM_ADDR_SPACE (ref
)))
529 /* Don't alter REF itself, since that is probably a stack slot. */
530 return replace_equiv_address (ref
, XEXP (ref
, 0));
533 /* If X is a memory reference to a member of an object block, try rewriting
534 it to use an anchor instead. Return the new memory reference on success
535 and the old one on failure. */
538 use_anchored_address (rtx x
)
541 HOST_WIDE_INT offset
;
544 if (!flag_section_anchors
)
550 /* Split the address into a base and offset. */
553 if (GET_CODE (base
) == CONST
554 && GET_CODE (XEXP (base
, 0)) == PLUS
555 && CONST_INT_P (XEXP (XEXP (base
, 0), 1)))
557 offset
+= INTVAL (XEXP (XEXP (base
, 0), 1));
558 base
= XEXP (XEXP (base
, 0), 0);
561 /* Check whether BASE is suitable for anchors. */
562 if (GET_CODE (base
) != SYMBOL_REF
563 || !SYMBOL_REF_HAS_BLOCK_INFO_P (base
)
564 || SYMBOL_REF_ANCHOR_P (base
)
565 || SYMBOL_REF_BLOCK (base
) == NULL
566 || !targetm
.use_anchors_for_symbol_p (base
))
569 /* Decide where BASE is going to be. */
570 place_block_symbol (base
);
572 /* Get the anchor we need to use. */
573 offset
+= SYMBOL_REF_BLOCK_OFFSET (base
);
574 base
= get_section_anchor (SYMBOL_REF_BLOCK (base
), offset
,
575 SYMBOL_REF_TLS_MODEL (base
));
577 /* Work out the offset from the anchor. */
578 offset
-= SYMBOL_REF_BLOCK_OFFSET (base
);
580 /* If we're going to run a CSE pass, force the anchor into a register.
581 We will then be able to reuse registers for several accesses, if the
582 target costs say that that's worthwhile. */
583 mode
= GET_MODE (base
);
584 if (!cse_not_expected
)
585 base
= force_reg (mode
, base
);
587 return replace_equiv_address (x
, plus_constant (mode
, base
, offset
));
590 /* Copy the value or contents of X to a new temp reg and return that reg. */
595 rtx temp
= gen_reg_rtx (GET_MODE (x
));
597 /* If not an operand, must be an address with PLUS and MULT so
598 do the computation. */
599 if (! general_operand (x
, VOIDmode
))
600 x
= force_operand (x
, temp
);
603 emit_move_insn (temp
, x
);
608 /* Like copy_to_reg but always give the new register mode Pmode
609 in case X is a constant. */
612 copy_addr_to_reg (rtx x
)
614 return copy_to_mode_reg (Pmode
, x
);
617 /* Like copy_to_reg but always give the new register mode MODE
618 in case X is a constant. */
621 copy_to_mode_reg (machine_mode mode
, rtx x
)
623 rtx temp
= gen_reg_rtx (mode
);
625 /* If not an operand, must be an address with PLUS and MULT so
626 do the computation. */
627 if (! general_operand (x
, VOIDmode
))
628 x
= force_operand (x
, temp
);
630 gcc_assert (GET_MODE (x
) == mode
|| GET_MODE (x
) == VOIDmode
);
632 emit_move_insn (temp
, x
);
636 /* Load X into a register if it is not already one.
637 Use mode MODE for the register.
638 X should be valid for mode MODE, but it may be a constant which
639 is valid for all integer modes; that's why caller must specify MODE.
641 The caller must not alter the value in the register we return,
642 since we mark it as a "constant" register. */
645 force_reg (machine_mode mode
, rtx x
)
653 if (general_operand (x
, mode
))
655 temp
= gen_reg_rtx (mode
);
656 insn
= emit_move_insn (temp
, x
);
660 temp
= force_operand (x
, NULL_RTX
);
662 insn
= get_last_insn ();
665 rtx temp2
= gen_reg_rtx (mode
);
666 insn
= emit_move_insn (temp2
, temp
);
671 /* Let optimizers know that TEMP's value never changes
672 and that X can be substituted for it. Don't get confused
673 if INSN set something else (such as a SUBREG of TEMP). */
675 && (set
= single_set (insn
)) != 0
676 && SET_DEST (set
) == temp
677 && ! rtx_equal_p (x
, SET_SRC (set
)))
678 set_unique_reg_note (insn
, REG_EQUAL
, x
);
680 /* Let optimizers know that TEMP is a pointer, and if so, the
681 known alignment of that pointer. */
684 if (GET_CODE (x
) == SYMBOL_REF
)
686 align
= BITS_PER_UNIT
;
687 if (SYMBOL_REF_DECL (x
) && DECL_P (SYMBOL_REF_DECL (x
)))
688 align
= DECL_ALIGN (SYMBOL_REF_DECL (x
));
690 else if (GET_CODE (x
) == LABEL_REF
)
691 align
= BITS_PER_UNIT
;
692 else if (GET_CODE (x
) == CONST
693 && GET_CODE (XEXP (x
, 0)) == PLUS
694 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
695 && CONST_INT_P (XEXP (XEXP (x
, 0), 1)))
697 rtx s
= XEXP (XEXP (x
, 0), 0);
698 rtx c
= XEXP (XEXP (x
, 0), 1);
702 if (SYMBOL_REF_DECL (s
) && DECL_P (SYMBOL_REF_DECL (s
)))
703 sa
= DECL_ALIGN (SYMBOL_REF_DECL (s
));
709 ca
= ctz_hwi (INTVAL (c
)) * BITS_PER_UNIT
;
710 align
= MIN (sa
, ca
);
714 if (align
|| (MEM_P (x
) && MEM_POINTER (x
)))
715 mark_reg_pointer (temp
, align
);
721 /* If X is a memory ref, copy its contents to a new temp reg and return
722 that reg. Otherwise, return X. */
725 force_not_mem (rtx x
)
729 if (!MEM_P (x
) || GET_MODE (x
) == BLKmode
)
732 temp
= gen_reg_rtx (GET_MODE (x
));
735 REG_POINTER (temp
) = 1;
737 emit_move_insn (temp
, x
);
741 /* Copy X to TARGET (if it's nonzero and a reg)
742 or to a new temp reg and return that reg.
743 MODE is the mode to use for X in case it is a constant. */
746 copy_to_suggested_reg (rtx x
, rtx target
, machine_mode mode
)
750 if (target
&& REG_P (target
))
753 temp
= gen_reg_rtx (mode
);
755 emit_move_insn (temp
, x
);
759 /* Return the mode to use to pass or return a scalar of TYPE and MODE.
760 PUNSIGNEDP points to the signedness of the type and may be adjusted
761 to show what signedness to use on extension operations.
763 FOR_RETURN is nonzero if the caller is promoting the return value
764 of FNDECL, else it is for promoting args. */
767 promote_function_mode (const_tree type
, machine_mode mode
, int *punsignedp
,
768 const_tree funtype
, int for_return
)
770 /* Called without a type node for a libcall. */
771 if (type
== NULL_TREE
)
773 if (INTEGRAL_MODE_P (mode
))
774 return targetm
.calls
.promote_function_mode (NULL_TREE
, mode
,
781 switch (TREE_CODE (type
))
783 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
784 case REAL_TYPE
: case OFFSET_TYPE
: case FIXED_POINT_TYPE
:
785 case POINTER_TYPE
: case REFERENCE_TYPE
:
786 return targetm
.calls
.promote_function_mode (type
, mode
, punsignedp
, funtype
,
793 /* Return the mode to use to store a scalar of TYPE and MODE.
794 PUNSIGNEDP points to the signedness of the type and may be adjusted
795 to show what signedness to use on extension operations. */
798 promote_mode (const_tree type ATTRIBUTE_UNUSED
, machine_mode mode
,
799 int *punsignedp ATTRIBUTE_UNUSED
)
807 /* For libcalls this is invoked without TYPE from the backends
808 TARGET_PROMOTE_FUNCTION_MODE hooks. Don't do anything in that
810 if (type
== NULL_TREE
)
813 /* FIXME: this is the same logic that was there until GCC 4.4, but we
814 probably want to test POINTERS_EXTEND_UNSIGNED even if PROMOTE_MODE
815 is not defined. The affected targets are M32C, S390, SPARC. */
817 code
= TREE_CODE (type
);
818 unsignedp
= *punsignedp
;
822 case INTEGER_TYPE
: case ENUMERAL_TYPE
: case BOOLEAN_TYPE
:
823 case REAL_TYPE
: case OFFSET_TYPE
: case FIXED_POINT_TYPE
:
824 /* Values of these types always have scalar mode. */
825 smode
= as_a
<scalar_mode
> (mode
);
826 PROMOTE_MODE (smode
, unsignedp
, type
);
827 *punsignedp
= unsignedp
;
830 #ifdef POINTERS_EXTEND_UNSIGNED
833 *punsignedp
= POINTERS_EXTEND_UNSIGNED
;
834 return targetm
.addr_space
.address_mode
835 (TYPE_ADDR_SPACE (TREE_TYPE (type
)));
847 /* Use one of promote_mode or promote_function_mode to find the promoted
848 mode of DECL. If PUNSIGNEDP is not NULL, store there the unsignedness
849 of DECL after promotion. */
852 promote_decl_mode (const_tree decl
, int *punsignedp
)
854 tree type
= TREE_TYPE (decl
);
855 int unsignedp
= TYPE_UNSIGNED (type
);
856 machine_mode mode
= DECL_MODE (decl
);
859 if (TREE_CODE (decl
) == RESULT_DECL
&& !DECL_BY_REFERENCE (decl
))
860 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
861 TREE_TYPE (current_function_decl
), 1);
862 else if (TREE_CODE (decl
) == RESULT_DECL
|| TREE_CODE (decl
) == PARM_DECL
)
863 pmode
= promote_function_mode (type
, mode
, &unsignedp
,
864 TREE_TYPE (current_function_decl
), 2);
866 pmode
= promote_mode (type
, mode
, &unsignedp
);
869 *punsignedp
= unsignedp
;
873 /* Return the promoted mode for name. If it is a named SSA_NAME, it
874 is the same as promote_decl_mode. Otherwise, it is the promoted
875 mode of a temp decl of same type as the SSA_NAME, if we had created
879 promote_ssa_mode (const_tree name
, int *punsignedp
)
881 gcc_assert (TREE_CODE (name
) == SSA_NAME
);
883 /* Partitions holding parms and results must be promoted as expected
885 if (SSA_NAME_VAR (name
)
886 && (TREE_CODE (SSA_NAME_VAR (name
)) == PARM_DECL
887 || TREE_CODE (SSA_NAME_VAR (name
)) == RESULT_DECL
))
889 machine_mode mode
= promote_decl_mode (SSA_NAME_VAR (name
), punsignedp
);
894 tree type
= TREE_TYPE (name
);
895 int unsignedp
= TYPE_UNSIGNED (type
);
896 machine_mode pmode
= promote_mode (type
, TYPE_MODE (type
), &unsignedp
);
898 *punsignedp
= unsignedp
;
905 /* Controls the behavior of {anti_,}adjust_stack. */
906 static bool suppress_reg_args_size
;
908 /* A helper for adjust_stack and anti_adjust_stack. */
911 adjust_stack_1 (rtx adjust
, bool anti_p
)
916 /* Hereafter anti_p means subtract_p. */
917 if (!STACK_GROWS_DOWNWARD
)
920 temp
= expand_binop (Pmode
,
921 anti_p
? sub_optab
: add_optab
,
922 stack_pointer_rtx
, adjust
, stack_pointer_rtx
, 0,
925 if (temp
!= stack_pointer_rtx
)
926 insn
= emit_move_insn (stack_pointer_rtx
, temp
);
929 insn
= get_last_insn ();
930 temp
= single_set (insn
);
931 gcc_assert (temp
!= NULL
&& SET_DEST (temp
) == stack_pointer_rtx
);
934 if (!suppress_reg_args_size
)
935 add_args_size_note (insn
, stack_pointer_delta
);
938 /* Adjust the stack pointer by ADJUST (an rtx for a number of bytes).
939 This pops when ADJUST is positive. ADJUST need not be constant. */
942 adjust_stack (rtx adjust
)
944 if (adjust
== const0_rtx
)
947 /* We expect all variable sized adjustments to be multiple of
948 PREFERRED_STACK_BOUNDARY. */
949 poly_int64 const_adjust
;
950 if (poly_int_rtx_p (adjust
, &const_adjust
))
951 stack_pointer_delta
-= const_adjust
;
953 adjust_stack_1 (adjust
, false);
956 /* Adjust the stack pointer by minus ADJUST (an rtx for a number of bytes).
957 This pushes when ADJUST is positive. ADJUST need not be constant. */
960 anti_adjust_stack (rtx adjust
)
962 if (adjust
== const0_rtx
)
965 /* We expect all variable sized adjustments to be multiple of
966 PREFERRED_STACK_BOUNDARY. */
967 poly_int64 const_adjust
;
968 if (poly_int_rtx_p (adjust
, &const_adjust
))
969 stack_pointer_delta
+= const_adjust
;
971 adjust_stack_1 (adjust
, true);
974 /* Round the size of a block to be pushed up to the boundary required
975 by this machine. SIZE is the desired size, which need not be constant. */
978 round_push (rtx size
)
980 rtx align_rtx
, alignm1_rtx
;
982 if (!SUPPORTS_STACK_ALIGNMENT
983 || crtl
->preferred_stack_boundary
== MAX_SUPPORTED_STACK_ALIGNMENT
)
985 int align
= crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
;
990 if (CONST_INT_P (size
))
992 HOST_WIDE_INT new_size
= (INTVAL (size
) + align
- 1) / align
* align
;
994 if (INTVAL (size
) != new_size
)
995 size
= GEN_INT (new_size
);
999 align_rtx
= GEN_INT (align
);
1000 alignm1_rtx
= GEN_INT (align
- 1);
1004 /* If crtl->preferred_stack_boundary might still grow, use
1005 virtual_preferred_stack_boundary_rtx instead. This will be
1006 substituted by the right value in vregs pass and optimized
1008 align_rtx
= virtual_preferred_stack_boundary_rtx
;
1009 alignm1_rtx
= force_operand (plus_constant (Pmode
, align_rtx
, -1),
1013 /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
1014 but we know it can't. So add ourselves and then do
1016 size
= expand_binop (Pmode
, add_optab
, size
, alignm1_rtx
,
1017 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1018 size
= expand_divmod (0, TRUNC_DIV_EXPR
, Pmode
, size
, align_rtx
,
1020 size
= expand_mult (Pmode
, size
, align_rtx
, NULL_RTX
, 1);
1025 /* Save the stack pointer for the purpose in SAVE_LEVEL. PSAVE is a pointer
1026 to a previously-created save area. If no save area has been allocated,
1027 this function will allocate one. If a save area is specified, it
1028 must be of the proper mode. */
1031 emit_stack_save (enum save_level save_level
, rtx
*psave
)
1034 /* The default is that we use a move insn and save in a Pmode object. */
1035 rtx_insn
*(*fcn
) (rtx
, rtx
) = gen_move_insn
;
1036 machine_mode mode
= STACK_SAVEAREA_MODE (save_level
);
1038 /* See if this machine has anything special to do for this kind of save. */
1042 if (targetm
.have_save_stack_block ())
1043 fcn
= targetm
.gen_save_stack_block
;
1046 if (targetm
.have_save_stack_function ())
1047 fcn
= targetm
.gen_save_stack_function
;
1050 if (targetm
.have_save_stack_nonlocal ())
1051 fcn
= targetm
.gen_save_stack_nonlocal
;
1057 /* If there is no save area and we have to allocate one, do so. Otherwise
1058 verify the save area is the proper mode. */
1062 if (mode
!= VOIDmode
)
1064 if (save_level
== SAVE_NONLOCAL
)
1065 *psave
= sa
= assign_stack_local (mode
, GET_MODE_SIZE (mode
), 0);
1067 *psave
= sa
= gen_reg_rtx (mode
);
1071 do_pending_stack_adjust ();
1073 sa
= validize_mem (sa
);
1074 emit_insn (fcn (sa
, stack_pointer_rtx
));
1077 /* Restore the stack pointer for the purpose in SAVE_LEVEL. SA is the save
1078 area made by emit_stack_save. If it is zero, we have nothing to do. */
1081 emit_stack_restore (enum save_level save_level
, rtx sa
)
1083 /* The default is that we use a move insn. */
1084 rtx_insn
*(*fcn
) (rtx
, rtx
) = gen_move_insn
;
1086 /* If stack_realign_drap, the x86 backend emits a prologue that aligns both
1087 STACK_POINTER and HARD_FRAME_POINTER.
1088 If stack_realign_fp, the x86 backend emits a prologue that aligns only
1089 STACK_POINTER. This renders the HARD_FRAME_POINTER unusable for accessing
1090 aligned variables, which is reflected in ix86_can_eliminate.
1091 We normally still have the realigned STACK_POINTER that we can use.
1092 But if there is a stack restore still present at reload, it can trigger
1093 mark_not_eliminable for the STACK_POINTER, leaving no way to eliminate
1094 FRAME_POINTER into a hard reg.
1095 To prevent this situation, we force need_drap if we emit a stack
1097 if (SUPPORTS_STACK_ALIGNMENT
)
1098 crtl
->need_drap
= true;
1100 /* See if this machine has anything special to do for this kind of save. */
1104 if (targetm
.have_restore_stack_block ())
1105 fcn
= targetm
.gen_restore_stack_block
;
1108 if (targetm
.have_restore_stack_function ())
1109 fcn
= targetm
.gen_restore_stack_function
;
1112 if (targetm
.have_restore_stack_nonlocal ())
1113 fcn
= targetm
.gen_restore_stack_nonlocal
;
1121 sa
= validize_mem (sa
);
1122 /* These clobbers prevent the scheduler from moving
1123 references to variable arrays below the code
1124 that deletes (pops) the arrays. */
1125 emit_clobber (gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
)));
1126 emit_clobber (gen_rtx_MEM (BLKmode
, stack_pointer_rtx
));
1129 discard_pending_stack_adjust ();
1131 emit_insn (fcn (stack_pointer_rtx
, sa
));
1134 /* Invoke emit_stack_save on the nonlocal_goto_save_area for the current
1135 function. This should be called whenever we allocate or deallocate
1136 dynamic stack space. */
1139 update_nonlocal_goto_save_area (void)
1144 /* The nonlocal_goto_save_area object is an array of N pointers. The
1145 first one is used for the frame pointer save; the rest are sized by
1146 STACK_SAVEAREA_MODE. Create a reference to array index 1, the first
1147 of the stack save area slots. */
1148 t_save
= build4 (ARRAY_REF
,
1149 TREE_TYPE (TREE_TYPE (cfun
->nonlocal_goto_save_area
)),
1150 cfun
->nonlocal_goto_save_area
,
1151 integer_one_node
, NULL_TREE
, NULL_TREE
);
1152 r_save
= expand_expr (t_save
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
1154 emit_stack_save (SAVE_NONLOCAL
, &r_save
);
1157 /* Record a new stack level for the current function. This should be called
1158 whenever we allocate or deallocate dynamic stack space. */
1161 record_new_stack_level (void)
1163 /* Record the new stack level for nonlocal gotos. */
1164 if (cfun
->nonlocal_goto_save_area
)
1165 update_nonlocal_goto_save_area ();
1167 /* Record the new stack level for SJLJ exceptions. */
1168 if (targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
)
1169 update_sjlj_context ();
1172 /* Return an rtx doing runtime alignment to REQUIRED_ALIGN on TARGET. */
1175 align_dynamic_address (rtx target
, unsigned required_align
)
1177 /* CEIL_DIV_EXPR needs to worry about the addition overflowing,
1178 but we know it can't. So add ourselves and then do
1180 target
= expand_binop (Pmode
, add_optab
, target
,
1181 gen_int_mode (required_align
/ BITS_PER_UNIT
- 1,
1183 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1184 target
= expand_divmod (0, TRUNC_DIV_EXPR
, Pmode
, target
,
1185 gen_int_mode (required_align
/ BITS_PER_UNIT
,
1188 target
= expand_mult (Pmode
, target
,
1189 gen_int_mode (required_align
/ BITS_PER_UNIT
,
1196 /* Return an rtx through *PSIZE, representing the size of an area of memory to
1197 be dynamically pushed on the stack.
1199 *PSIZE is an rtx representing the size of the area.
1201 SIZE_ALIGN is the alignment (in bits) that we know SIZE has. This
1202 parameter may be zero. If so, a proper value will be extracted
1203 from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed.
1205 REQUIRED_ALIGN is the alignment (in bits) required for the region
1208 If PSTACK_USAGE_SIZE is not NULL it points to a value that is increased for
1209 the additional size returned. */
1211 get_dynamic_stack_size (rtx
*psize
, unsigned size_align
,
1212 unsigned required_align
,
1213 HOST_WIDE_INT
*pstack_usage_size
)
1217 /* Ensure the size is in the proper mode. */
1218 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
1219 size
= convert_to_mode (Pmode
, size
, 1);
1221 if (CONST_INT_P (size
))
1223 unsigned HOST_WIDE_INT lsb
;
1225 lsb
= INTVAL (size
);
1228 /* Watch out for overflow truncating to "unsigned". */
1229 if (lsb
> UINT_MAX
/ BITS_PER_UNIT
)
1230 size_align
= 1u << (HOST_BITS_PER_INT
- 1);
1232 size_align
= (unsigned)lsb
* BITS_PER_UNIT
;
1234 else if (size_align
< BITS_PER_UNIT
)
1235 size_align
= BITS_PER_UNIT
;
1237 /* We can't attempt to minimize alignment necessary, because we don't
1238 know the final value of preferred_stack_boundary yet while executing
1240 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
1241 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
1243 /* We will need to ensure that the address we return is aligned to
1244 REQUIRED_ALIGN. At this point in the compilation, we don't always
1245 know the final value of the STACK_DYNAMIC_OFFSET used in function.c
1246 (it might depend on the size of the outgoing parameter lists, for
1247 example), so we must preventively align the value. We leave space
1248 in SIZE for the hole that might result from the alignment operation. */
1250 unsigned known_align
= REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM
);
1251 if (known_align
== 0)
1252 known_align
= BITS_PER_UNIT
;
1253 if (required_align
> known_align
)
1255 unsigned extra
= (required_align
- known_align
) / BITS_PER_UNIT
;
1256 size
= plus_constant (Pmode
, size
, extra
);
1257 size
= force_operand (size
, NULL_RTX
);
1258 if (size_align
> known_align
)
1259 size_align
= known_align
;
1261 if (flag_stack_usage_info
&& pstack_usage_size
)
1262 *pstack_usage_size
+= extra
;
1265 /* Round the size to a multiple of the required stack alignment.
1266 Since the stack is presumed to be rounded before this allocation,
1267 this will maintain the required alignment.
1269 If the stack grows downward, we could save an insn by subtracting
1270 SIZE from the stack pointer and then aligning the stack pointer.
1271 The problem with this is that the stack pointer may be unaligned
1272 between the execution of the subtraction and alignment insns and
1273 some machines do not allow this. Even on those that do, some
1274 signal handlers malfunction if a signal should occur between those
1275 insns. Since this is an extremely rare event, we have no reliable
1276 way of knowing which systems have this problem. So we avoid even
1277 momentarily mis-aligning the stack. */
1278 if (size_align
% MAX_SUPPORTED_STACK_ALIGNMENT
!= 0)
1280 size
= round_push (size
);
1282 if (flag_stack_usage_info
&& pstack_usage_size
)
1284 int align
= crtl
->preferred_stack_boundary
/ BITS_PER_UNIT
;
1285 *pstack_usage_size
=
1286 (*pstack_usage_size
+ align
- 1) / align
* align
;
1293 /* Return the number of bytes to "protect" on the stack for -fstack-check.
1295 "protect" in the context of -fstack-check means how many bytes we
1296 should always ensure are available on the stack. More importantly
1297 this is how many bytes are skipped when probing the stack.
1299 On some targets we want to reuse the -fstack-check prologue support
1300 to give a degree of protection against stack clashing style attacks.
1302 In that scenario we do not want to skip bytes before probing as that
1303 would render the stack clash protections useless.
1305 So we never use STACK_CHECK_PROTECT directly. Instead we indirect though
1306 this helper which allows us to provide different values for
1307 -fstack-check and -fstack-clash-protection. */
1309 get_stack_check_protect (void)
1311 if (flag_stack_clash_protection
)
1313 return STACK_CHECK_PROTECT
;
1316 /* Return an rtx representing the address of an area of memory dynamically
1317 pushed on the stack.
1319 Any required stack pointer alignment is preserved.
1321 SIZE is an rtx representing the size of the area.
1323 SIZE_ALIGN is the alignment (in bits) that we know SIZE has. This
1324 parameter may be zero. If so, a proper value will be extracted
1325 from SIZE if it is constant, otherwise BITS_PER_UNIT will be assumed.
1327 REQUIRED_ALIGN is the alignment (in bits) required for the region
1330 MAX_SIZE is an upper bound for SIZE, if SIZE is not constant, or -1 if
1331 no such upper bound is known.
1333 If CANNOT_ACCUMULATE is set to TRUE, the caller guarantees that the
1334 stack space allocated by the generated code cannot be added with itself
1335 in the course of the execution of the function. It is always safe to
1336 pass FALSE here and the following criterion is sufficient in order to
1337 pass TRUE: every path in the CFG that starts at the allocation point and
1338 loops to it executes the associated deallocation code. */
1341 allocate_dynamic_stack_space (rtx size
, unsigned size_align
,
1342 unsigned required_align
,
1343 HOST_WIDE_INT max_size
,
1344 bool cannot_accumulate
)
1346 HOST_WIDE_INT stack_usage_size
= -1;
1347 rtx_code_label
*final_label
;
1348 rtx final_target
, target
;
1350 /* If we're asking for zero bytes, it doesn't matter what we point
1351 to since we can't dereference it. But return a reasonable
1353 if (size
== const0_rtx
)
1354 return virtual_stack_dynamic_rtx
;
1356 /* Otherwise, show we're calling alloca or equivalent. */
1357 cfun
->calls_alloca
= 1;
1359 /* If stack usage info is requested, look into the size we are passed.
1360 We need to do so this early to avoid the obfuscation that may be
1361 introduced later by the various alignment operations. */
1362 if (flag_stack_usage_info
)
1364 if (CONST_INT_P (size
))
1365 stack_usage_size
= INTVAL (size
);
1366 else if (REG_P (size
))
1368 /* Look into the last emitted insn and see if we can deduce
1369 something for the register. */
1372 insn
= get_last_insn ();
1373 if ((set
= single_set (insn
)) && rtx_equal_p (SET_DEST (set
), size
))
1375 if (CONST_INT_P (SET_SRC (set
)))
1376 stack_usage_size
= INTVAL (SET_SRC (set
));
1377 else if ((note
= find_reg_equal_equiv_note (insn
))
1378 && CONST_INT_P (XEXP (note
, 0)))
1379 stack_usage_size
= INTVAL (XEXP (note
, 0));
1383 /* If the size is not constant, try the maximum size. */
1384 if (stack_usage_size
< 0)
1385 stack_usage_size
= max_size
;
1387 /* If the size is still not constant, we can't say anything. */
1388 if (stack_usage_size
< 0)
1390 current_function_has_unbounded_dynamic_stack_size
= 1;
1391 stack_usage_size
= 0;
1395 get_dynamic_stack_size (&size
, size_align
, required_align
, &stack_usage_size
);
1397 target
= gen_reg_rtx (Pmode
);
1399 /* The size is supposed to be fully adjusted at this point so record it
1400 if stack usage info is requested. */
1401 if (flag_stack_usage_info
)
1403 current_function_dynamic_stack_size
+= stack_usage_size
;
1405 /* ??? This is gross but the only safe stance in the absence
1406 of stack usage oriented flow analysis. */
1407 if (!cannot_accumulate
)
1408 current_function_has_unbounded_dynamic_stack_size
= 1;
1411 do_pending_stack_adjust ();
1414 final_target
= NULL_RTX
;
1416 /* If we are splitting the stack, we need to ask the backend whether
1417 there is enough room on the current stack. If there isn't, or if
1418 the backend doesn't know how to tell is, then we need to call a
1419 function to allocate memory in some other way. This memory will
1420 be released when we release the current stack segment. The
1421 effect is that stack allocation becomes less efficient, but at
1422 least it doesn't cause a stack overflow. */
1423 if (flag_split_stack
)
1425 rtx_code_label
*available_label
;
1426 rtx ask
, space
, func
;
1428 available_label
= NULL
;
1430 if (targetm
.have_split_stack_space_check ())
1432 available_label
= gen_label_rtx ();
1434 /* This instruction will branch to AVAILABLE_LABEL if there
1435 are SIZE bytes available on the stack. */
1436 emit_insn (targetm
.gen_split_stack_space_check
1437 (size
, available_label
));
1440 /* The __morestack_allocate_stack_space function will allocate
1441 memory using malloc. If the alignment of the memory returned
1442 by malloc does not meet REQUIRED_ALIGN, we increase SIZE to
1443 make sure we allocate enough space. */
1444 if (MALLOC_ABI_ALIGNMENT
>= required_align
)
1447 ask
= expand_binop (Pmode
, add_optab
, size
,
1448 gen_int_mode (required_align
/ BITS_PER_UNIT
- 1,
1450 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1452 func
= init_one_libfunc ("__morestack_allocate_stack_space");
1454 space
= emit_library_call_value (func
, target
, LCT_NORMAL
, Pmode
,
1457 if (available_label
== NULL_RTX
)
1460 final_target
= gen_reg_rtx (Pmode
);
1462 emit_move_insn (final_target
, space
);
1464 final_label
= gen_label_rtx ();
1465 emit_jump (final_label
);
1467 emit_label (available_label
);
1470 /* We ought to be called always on the toplevel and stack ought to be aligned
1472 gcc_assert (multiple_p (stack_pointer_delta
,
1473 PREFERRED_STACK_BOUNDARY
/ BITS_PER_UNIT
));
1475 /* If needed, check that we have the required amount of stack. Take into
1476 account what has already been checked. */
1477 if (STACK_CHECK_MOVING_SP
)
1479 else if (flag_stack_check
== GENERIC_STACK_CHECK
)
1480 probe_stack_range (STACK_OLD_CHECK_PROTECT
+ STACK_CHECK_MAX_FRAME_SIZE
,
1482 else if (flag_stack_check
== STATIC_BUILTIN_STACK_CHECK
)
1483 probe_stack_range (get_stack_check_protect (), size
);
1485 /* Don't let anti_adjust_stack emit notes. */
1486 suppress_reg_args_size
= true;
1488 /* Perform the required allocation from the stack. Some systems do
1489 this differently than simply incrementing/decrementing from the
1490 stack pointer, such as acquiring the space by calling malloc(). */
1491 if (targetm
.have_allocate_stack ())
1493 class expand_operand ops
[2];
1494 /* We don't have to check against the predicate for operand 0 since
1495 TARGET is known to be a pseudo of the proper mode, which must
1496 be valid for the operand. */
1497 create_fixed_operand (&ops
[0], target
);
1498 create_convert_operand_to (&ops
[1], size
, STACK_SIZE_MODE
, true);
1499 expand_insn (targetm
.code_for_allocate_stack
, 2, ops
);
1503 poly_int64 saved_stack_pointer_delta
;
1505 if (!STACK_GROWS_DOWNWARD
)
1506 emit_move_insn (target
, virtual_stack_dynamic_rtx
);
1508 /* Check stack bounds if necessary. */
1509 if (crtl
->limit_stack
)
1512 rtx_code_label
*space_available
= gen_label_rtx ();
1513 if (STACK_GROWS_DOWNWARD
)
1514 available
= expand_binop (Pmode
, sub_optab
,
1515 stack_pointer_rtx
, stack_limit_rtx
,
1516 NULL_RTX
, 1, OPTAB_WIDEN
);
1518 available
= expand_binop (Pmode
, sub_optab
,
1519 stack_limit_rtx
, stack_pointer_rtx
,
1520 NULL_RTX
, 1, OPTAB_WIDEN
);
1522 emit_cmp_and_jump_insns (available
, size
, GEU
, NULL_RTX
, Pmode
, 1,
1524 if (targetm
.have_trap ())
1525 emit_insn (targetm
.gen_trap ());
1527 error ("stack limits not supported on this target");
1529 emit_label (space_available
);
1532 saved_stack_pointer_delta
= stack_pointer_delta
;
1534 if (flag_stack_check
&& STACK_CHECK_MOVING_SP
)
1535 anti_adjust_stack_and_probe (size
, false);
1536 else if (flag_stack_clash_protection
)
1537 anti_adjust_stack_and_probe_stack_clash (size
);
1539 anti_adjust_stack (size
);
1541 /* Even if size is constant, don't modify stack_pointer_delta.
1542 The constant size alloca should preserve
1543 crtl->preferred_stack_boundary alignment. */
1544 stack_pointer_delta
= saved_stack_pointer_delta
;
1546 if (STACK_GROWS_DOWNWARD
)
1547 emit_move_insn (target
, virtual_stack_dynamic_rtx
);
1550 suppress_reg_args_size
= false;
1552 /* Finish up the split stack handling. */
1553 if (final_label
!= NULL_RTX
)
1555 gcc_assert (flag_split_stack
);
1556 emit_move_insn (final_target
, target
);
1557 emit_label (final_label
);
1558 target
= final_target
;
1561 target
= align_dynamic_address (target
, required_align
);
1563 /* Now that we've committed to a return value, mark its alignment. */
1564 mark_reg_pointer (target
, required_align
);
1566 /* Record the new stack level. */
1567 record_new_stack_level ();
1572 /* Return an rtx representing the address of an area of memory already
1573 statically pushed onto the stack in the virtual stack vars area. (It is
1574 assumed that the area is allocated in the function prologue.)
1576 Any required stack pointer alignment is preserved.
1578 OFFSET is the offset of the area into the virtual stack vars area.
1580 REQUIRED_ALIGN is the alignment (in bits) required for the region
1584 get_dynamic_stack_base (poly_int64 offset
, unsigned required_align
)
1588 if (crtl
->preferred_stack_boundary
< PREFERRED_STACK_BOUNDARY
)
1589 crtl
->preferred_stack_boundary
= PREFERRED_STACK_BOUNDARY
;
1591 target
= gen_reg_rtx (Pmode
);
1592 emit_move_insn (target
, virtual_stack_vars_rtx
);
1593 target
= expand_binop (Pmode
, add_optab
, target
,
1594 gen_int_mode (offset
, Pmode
),
1595 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
1596 target
= align_dynamic_address (target
, required_align
);
1598 /* Now that we've committed to a return value, mark its alignment. */
1599 mark_reg_pointer (target
, required_align
);
1604 /* A front end may want to override GCC's stack checking by providing a
1605 run-time routine to call to check the stack, so provide a mechanism for
1606 calling that routine. */
1608 static GTY(()) rtx stack_check_libfunc
;
1611 set_stack_check_libfunc (const char *libfunc_name
)
1613 gcc_assert (stack_check_libfunc
== NULL_RTX
);
1614 stack_check_libfunc
= gen_rtx_SYMBOL_REF (Pmode
, libfunc_name
);
1615 tree decl
= build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
,
1616 get_identifier (libfunc_name
), void_type_node
);
1617 DECL_EXTERNAL (decl
) = 1;
1618 SET_SYMBOL_REF_DECL (stack_check_libfunc
, decl
);
1621 /* Emit one stack probe at ADDRESS, an address within the stack. */
1624 emit_stack_probe (rtx address
)
1626 if (targetm
.have_probe_stack_address ())
1628 class expand_operand ops
[1];
1629 insn_code icode
= targetm
.code_for_probe_stack_address
;
1630 create_address_operand (ops
, address
);
1631 maybe_legitimize_operands (icode
, 0, 1, ops
);
1632 expand_insn (icode
, 1, ops
);
1636 rtx memref
= gen_rtx_MEM (word_mode
, address
);
1638 MEM_VOLATILE_P (memref
) = 1;
1639 memref
= validize_mem (memref
);
1641 /* See if we have an insn to probe the stack. */
1642 if (targetm
.have_probe_stack ())
1643 emit_insn (targetm
.gen_probe_stack (memref
));
1645 emit_move_insn (memref
, const0_rtx
);
1649 /* Probe a range of stack addresses from FIRST to FIRST+SIZE, inclusive.
1650 FIRST is a constant and size is a Pmode RTX. These are offsets from
1651 the current stack pointer. STACK_GROWS_DOWNWARD says whether to add
1652 or subtract them from the stack pointer. */
1654 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
1656 #if STACK_GROWS_DOWNWARD
1657 #define STACK_GROW_OP MINUS
1658 #define STACK_GROW_OPTAB sub_optab
1659 #define STACK_GROW_OFF(off) -(off)
1661 #define STACK_GROW_OP PLUS
1662 #define STACK_GROW_OPTAB add_optab
1663 #define STACK_GROW_OFF(off) (off)
1667 probe_stack_range (HOST_WIDE_INT first
, rtx size
)
1669 /* First ensure SIZE is Pmode. */
1670 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
1671 size
= convert_to_mode (Pmode
, size
, 1);
1673 /* Next see if we have a function to check the stack. */
1674 if (stack_check_libfunc
)
1676 rtx addr
= memory_address (Pmode
,
1677 gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1679 plus_constant (Pmode
,
1681 emit_library_call (stack_check_libfunc
, LCT_THROW
, VOIDmode
,
1685 /* Next see if we have an insn to check the stack. */
1686 else if (targetm
.have_check_stack ())
1688 class expand_operand ops
[1];
1689 rtx addr
= memory_address (Pmode
,
1690 gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1692 plus_constant (Pmode
,
1695 create_input_operand (&ops
[0], addr
, Pmode
);
1696 success
= maybe_expand_insn (targetm
.code_for_check_stack
, 1, ops
);
1697 gcc_assert (success
);
1700 /* Otherwise we have to generate explicit probes. If we have a constant
1701 small number of them to generate, that's the easy case. */
1702 else if (CONST_INT_P (size
) && INTVAL (size
) < 7 * PROBE_INTERVAL
)
1704 HOST_WIDE_INT isize
= INTVAL (size
), i
;
1707 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
1708 it exceeds SIZE. If only one probe is needed, this will not
1709 generate any code. Then probe at FIRST + SIZE. */
1710 for (i
= PROBE_INTERVAL
; i
< isize
; i
+= PROBE_INTERVAL
)
1712 addr
= memory_address (Pmode
,
1713 plus_constant (Pmode
, stack_pointer_rtx
,
1714 STACK_GROW_OFF (first
+ i
)));
1715 emit_stack_probe (addr
);
1718 addr
= memory_address (Pmode
,
1719 plus_constant (Pmode
, stack_pointer_rtx
,
1720 STACK_GROW_OFF (first
+ isize
)));
1721 emit_stack_probe (addr
);
1724 /* In the variable case, do the same as above, but in a loop. Note that we
1725 must be extra careful with variables wrapping around because we might be
1726 at the very top (or the very bottom) of the address space and we have to
1727 be able to handle this case properly; in particular, we use an equality
1728 test for the loop condition. */
1731 rtx rounded_size
, rounded_size_op
, test_addr
, last_addr
, temp
;
1732 rtx_code_label
*loop_lab
= gen_label_rtx ();
1733 rtx_code_label
*end_lab
= gen_label_rtx ();
1735 /* Step 1: round SIZE to the previous multiple of the interval. */
1737 /* ROUNDED_SIZE = SIZE & -PROBE_INTERVAL */
1739 = simplify_gen_binary (AND
, Pmode
, size
,
1740 gen_int_mode (-PROBE_INTERVAL
, Pmode
));
1741 rounded_size_op
= force_operand (rounded_size
, NULL_RTX
);
1744 /* Step 2: compute initial and final value of the loop counter. */
1746 /* TEST_ADDR = SP + FIRST. */
1747 test_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1749 gen_int_mode (first
, Pmode
)),
1752 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
1753 last_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1755 rounded_size_op
), NULL_RTX
);
1760 while (TEST_ADDR != LAST_ADDR)
1762 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
1766 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
1767 until it is equal to ROUNDED_SIZE. */
1769 emit_label (loop_lab
);
1771 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
1772 emit_cmp_and_jump_insns (test_addr
, last_addr
, EQ
, NULL_RTX
, Pmode
, 1,
1775 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
1776 temp
= expand_binop (Pmode
, STACK_GROW_OPTAB
, test_addr
,
1777 gen_int_mode (PROBE_INTERVAL
, Pmode
), test_addr
,
1780 gcc_assert (temp
== test_addr
);
1782 /* Probe at TEST_ADDR. */
1783 emit_stack_probe (test_addr
);
1785 emit_jump (loop_lab
);
1787 emit_label (end_lab
);
1790 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
1791 that SIZE is equal to ROUNDED_SIZE. */
1793 /* TEMP = SIZE - ROUNDED_SIZE. */
1794 temp
= simplify_gen_binary (MINUS
, Pmode
, size
, rounded_size
);
1795 if (temp
!= const0_rtx
)
1799 if (CONST_INT_P (temp
))
1801 /* Use [base + disp} addressing mode if supported. */
1802 HOST_WIDE_INT offset
= INTVAL (temp
);
1803 addr
= memory_address (Pmode
,
1804 plus_constant (Pmode
, last_addr
,
1805 STACK_GROW_OFF (offset
)));
1809 /* Manual CSE if the difference is not known at compile-time. */
1810 temp
= gen_rtx_MINUS (Pmode
, size
, rounded_size_op
);
1811 addr
= memory_address (Pmode
,
1812 gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1816 emit_stack_probe (addr
);
1820 /* Make sure nothing is scheduled before we are done. */
1821 emit_insn (gen_blockage ());
1824 /* Compute parameters for stack clash probing a dynamic stack
1825 allocation of SIZE bytes.
1827 We compute ROUNDED_SIZE, LAST_ADDR, RESIDUAL and PROBE_INTERVAL.
1829 Additionally we conditionally dump the type of probing that will
1830 be needed given the values computed. */
1833 compute_stack_clash_protection_loop_data (rtx
*rounded_size
, rtx
*last_addr
,
1835 HOST_WIDE_INT
*probe_interval
,
1838 /* Round SIZE down to STACK_CLASH_PROTECTION_PROBE_INTERVAL */
1840 = 1 << param_stack_clash_protection_probe_interval
;
1841 *rounded_size
= simplify_gen_binary (AND
, Pmode
, size
,
1842 GEN_INT (-*probe_interval
));
1844 /* Compute the value of the stack pointer for the last iteration.
1845 It's just SP + ROUNDED_SIZE. */
1846 rtx rounded_size_op
= force_operand (*rounded_size
, NULL_RTX
);
1847 *last_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
1852 /* Compute any residuals not allocated by the loop above. Residuals
1853 are just the ROUNDED_SIZE - SIZE. */
1854 *residual
= simplify_gen_binary (MINUS
, Pmode
, size
, *rounded_size
);
1856 /* Dump key information to make writing tests easy. */
1859 if (*rounded_size
== CONST0_RTX (Pmode
))
1861 "Stack clash skipped dynamic allocation and probing loop.\n");
1862 else if (CONST_INT_P (*rounded_size
)
1863 && INTVAL (*rounded_size
) <= 4 * *probe_interval
)
1865 "Stack clash dynamic allocation and probing inline.\n");
1866 else if (CONST_INT_P (*rounded_size
))
1868 "Stack clash dynamic allocation and probing in "
1872 "Stack clash dynamic allocation and probing in loop.\n");
1874 if (*residual
!= CONST0_RTX (Pmode
))
1876 "Stack clash dynamic allocation and probing residuals.\n");
1879 "Stack clash skipped dynamic allocation and "
1880 "probing residuals.\n");
1884 /* Emit the start of an allocate/probe loop for stack
1887 LOOP_LAB and END_LAB are returned for use when we emit the
1890 LAST addr is the value for SP which stops the loop. */
1892 emit_stack_clash_protection_probe_loop_start (rtx
*loop_lab
,
1897 /* Essentially we want to emit any setup code, the top of loop
1898 label and the comparison at the top of the loop. */
1899 *loop_lab
= gen_label_rtx ();
1900 *end_lab
= gen_label_rtx ();
1902 emit_label (*loop_lab
);
1904 emit_cmp_and_jump_insns (stack_pointer_rtx
, last_addr
, EQ
, NULL_RTX
,
1905 Pmode
, 1, *end_lab
);
1908 /* Emit the end of a stack clash probing loop.
1910 This consists of just the jump back to LOOP_LAB and
1911 emitting END_LOOP after the loop. */
1914 emit_stack_clash_protection_probe_loop_end (rtx loop_lab
, rtx end_loop
,
1915 rtx last_addr
, bool rotated
)
1918 emit_cmp_and_jump_insns (stack_pointer_rtx
, last_addr
, NE
, NULL_RTX
,
1919 Pmode
, 1, loop_lab
);
1921 emit_jump (loop_lab
);
1923 emit_label (end_loop
);
1927 /* Adjust the stack pointer by minus SIZE (an rtx for a number of bytes)
1928 while probing it. This pushes when SIZE is positive. SIZE need not
1931 This is subtly different than anti_adjust_stack_and_probe to try and
1932 prevent stack-clash attacks
1934 1. It must assume no knowledge of the probing state, any allocation
1937 Consider the case of a 1 byte alloca in a loop. If the sum of the
1938 allocations is large, then this could be used to jump the guard if
1939 probes were not emitted.
1941 2. It never skips probes, whereas anti_adjust_stack_and_probe will
1942 skip probes on the first couple PROBE_INTERVALs on the assumption
1943 they're done elsewhere.
1945 3. It only allocates and probes SIZE bytes, it does not need to
1946 allocate/probe beyond that because this probing style does not
1947 guarantee signal handling capability if the guard is hit. */
1950 anti_adjust_stack_and_probe_stack_clash (rtx size
)
1952 /* First ensure SIZE is Pmode. */
1953 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
1954 size
= convert_to_mode (Pmode
, size
, 1);
1956 /* We can get here with a constant size on some targets. */
1957 rtx rounded_size
, last_addr
, residual
;
1958 HOST_WIDE_INT probe_interval
, probe_range
;
1959 bool target_probe_range_p
= false;
1960 compute_stack_clash_protection_loop_data (&rounded_size
, &last_addr
,
1961 &residual
, &probe_interval
, size
);
1963 /* Get the back-end specific probe ranges. */
1964 probe_range
= targetm
.stack_clash_protection_alloca_probe_range ();
1965 target_probe_range_p
= probe_range
!= 0;
1966 gcc_assert (probe_range
>= 0);
1968 /* If no back-end specific range defined, default to the top of the newly
1970 if (probe_range
== 0)
1971 probe_range
= probe_interval
- GET_MODE_SIZE (word_mode
);
1973 if (rounded_size
!= CONST0_RTX (Pmode
))
1975 if (CONST_INT_P (rounded_size
)
1976 && INTVAL (rounded_size
) <= 4 * probe_interval
)
1978 for (HOST_WIDE_INT i
= 0;
1979 i
< INTVAL (rounded_size
);
1980 i
+= probe_interval
)
1982 anti_adjust_stack (GEN_INT (probe_interval
));
1983 /* The prologue does not probe residuals. Thus the offset
1984 here to probe just beyond what the prologue had already
1986 emit_stack_probe (plus_constant (Pmode
, stack_pointer_rtx
,
1989 emit_insn (gen_blockage ());
1994 rtx loop_lab
, end_loop
;
1995 bool rotate_loop
= CONST_INT_P (rounded_size
);
1996 emit_stack_clash_protection_probe_loop_start (&loop_lab
, &end_loop
,
1997 last_addr
, rotate_loop
);
1999 anti_adjust_stack (GEN_INT (probe_interval
));
2001 /* The prologue does not probe residuals. Thus the offset here
2002 to probe just beyond what the prologue had already
2004 emit_stack_probe (plus_constant (Pmode
, stack_pointer_rtx
,
2007 emit_stack_clash_protection_probe_loop_end (loop_lab
, end_loop
,
2008 last_addr
, rotate_loop
);
2009 emit_insn (gen_blockage ());
2013 if (residual
!= CONST0_RTX (Pmode
))
2015 rtx label
= NULL_RTX
;
2016 /* RESIDUAL could be zero at runtime and in that case *sp could
2017 hold live data. Furthermore, we do not want to probe into the
2020 If TARGET_PROBE_RANGE_P then the target has promised it's safe to
2021 probe at offset 0. In which case we no longer have to check for
2022 RESIDUAL == 0. However we still need to probe at the right offset
2023 when RESIDUAL > PROBE_RANGE, in which case we probe at PROBE_RANGE.
2025 If !TARGET_PROBE_RANGE_P then go ahead and just guard the probe at *sp
2026 on RESIDUAL != 0 at runtime if RESIDUAL is not a compile time constant.
2028 anti_adjust_stack (residual
);
2030 if (!CONST_INT_P (residual
))
2032 label
= gen_label_rtx ();
2033 rtx_code op
= target_probe_range_p
? LT
: EQ
;
2034 rtx probe_cmp_value
= target_probe_range_p
2035 ? gen_rtx_CONST_INT (GET_MODE (residual
), probe_range
)
2036 : CONST0_RTX (GET_MODE (residual
));
2038 if (target_probe_range_p
)
2039 emit_stack_probe (stack_pointer_rtx
);
2041 emit_cmp_and_jump_insns (residual
, probe_cmp_value
,
2042 op
, NULL_RTX
, Pmode
, 1, label
);
2047 /* If RESIDUAL isn't a constant and TARGET_PROBE_RANGE_P then we probe up
2048 by the ABI defined safe value. */
2049 if (!CONST_INT_P (residual
) && target_probe_range_p
)
2050 x
= GEN_INT (probe_range
);
2051 /* If RESIDUAL is a constant but smaller than the ABI defined safe value,
2052 we still want to probe up, but the safest amount if a word. */
2053 else if (target_probe_range_p
)
2055 if (INTVAL (residual
) <= probe_range
)
2056 x
= GEN_INT (GET_MODE_SIZE (word_mode
));
2058 x
= GEN_INT (probe_range
);
2061 /* If nothing else, probe at the top of the new allocation. */
2062 x
= plus_constant (Pmode
, residual
, -GET_MODE_SIZE (word_mode
));
2064 emit_stack_probe (gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, x
));
2066 emit_insn (gen_blockage ());
2067 if (!CONST_INT_P (residual
))
2073 /* Adjust the stack pointer by minus SIZE (an rtx for a number of bytes)
2074 while probing it. This pushes when SIZE is positive. SIZE need not
2075 be constant. If ADJUST_BACK is true, adjust back the stack pointer
2076 by plus SIZE at the end. */
2079 anti_adjust_stack_and_probe (rtx size
, bool adjust_back
)
2081 /* We skip the probe for the first interval + a small dope of 4 words and
2082 probe that many bytes past the specified size to maintain a protection
2083 area at the botton of the stack. */
2084 const int dope
= 4 * UNITS_PER_WORD
;
2086 /* First ensure SIZE is Pmode. */
2087 if (GET_MODE (size
) != VOIDmode
&& GET_MODE (size
) != Pmode
)
2088 size
= convert_to_mode (Pmode
, size
, 1);
2090 /* If we have a constant small number of probes to generate, that's the
2092 if (CONST_INT_P (size
) && INTVAL (size
) < 7 * PROBE_INTERVAL
)
2094 HOST_WIDE_INT isize
= INTVAL (size
), i
;
2095 bool first_probe
= true;
2097 /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for
2098 values of N from 1 until it exceeds SIZE. If only one probe is
2099 needed, this will not generate any code. Then adjust and probe
2100 to PROBE_INTERVAL + SIZE. */
2101 for (i
= PROBE_INTERVAL
; i
< isize
; i
+= PROBE_INTERVAL
)
2105 anti_adjust_stack (GEN_INT (2 * PROBE_INTERVAL
+ dope
));
2106 first_probe
= false;
2109 anti_adjust_stack (GEN_INT (PROBE_INTERVAL
));
2110 emit_stack_probe (stack_pointer_rtx
);
2114 anti_adjust_stack (plus_constant (Pmode
, size
, PROBE_INTERVAL
+ dope
));
2116 anti_adjust_stack (plus_constant (Pmode
, size
, PROBE_INTERVAL
- i
));
2117 emit_stack_probe (stack_pointer_rtx
);
2120 /* In the variable case, do the same as above, but in a loop. Note that we
2121 must be extra careful with variables wrapping around because we might be
2122 at the very top (or the very bottom) of the address space and we have to
2123 be able to handle this case properly; in particular, we use an equality
2124 test for the loop condition. */
2127 rtx rounded_size
, rounded_size_op
, last_addr
, temp
;
2128 rtx_code_label
*loop_lab
= gen_label_rtx ();
2129 rtx_code_label
*end_lab
= gen_label_rtx ();
2132 /* Step 1: round SIZE to the previous multiple of the interval. */
2134 /* ROUNDED_SIZE = SIZE & -PROBE_INTERVAL */
2136 = simplify_gen_binary (AND
, Pmode
, size
,
2137 gen_int_mode (-PROBE_INTERVAL
, Pmode
));
2138 rounded_size_op
= force_operand (rounded_size
, NULL_RTX
);
2141 /* Step 2: compute initial and final value of the loop counter. */
2143 /* SP = SP_0 + PROBE_INTERVAL. */
2144 anti_adjust_stack (GEN_INT (PROBE_INTERVAL
+ dope
));
2146 /* LAST_ADDR = SP_0 + PROBE_INTERVAL + ROUNDED_SIZE. */
2147 last_addr
= force_operand (gen_rtx_fmt_ee (STACK_GROW_OP
, Pmode
,
2149 rounded_size_op
), NULL_RTX
);
2154 while (SP != LAST_ADDR)
2156 SP = SP + PROBE_INTERVAL
2160 adjusts SP and probes at PROBE_INTERVAL + N * PROBE_INTERVAL for
2161 values of N from 1 until it is equal to ROUNDED_SIZE. */
2163 emit_label (loop_lab
);
2165 /* Jump to END_LAB if SP == LAST_ADDR. */
2166 emit_cmp_and_jump_insns (stack_pointer_rtx
, last_addr
, EQ
, NULL_RTX
,
2169 /* SP = SP + PROBE_INTERVAL and probe at SP. */
2170 anti_adjust_stack (GEN_INT (PROBE_INTERVAL
));
2171 emit_stack_probe (stack_pointer_rtx
);
2173 emit_jump (loop_lab
);
2175 emit_label (end_lab
);
2178 /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot
2179 assert at compile-time that SIZE is equal to ROUNDED_SIZE. */
2181 /* TEMP = SIZE - ROUNDED_SIZE. */
2182 temp
= simplify_gen_binary (MINUS
, Pmode
, size
, rounded_size
);
2183 if (temp
!= const0_rtx
)
2185 /* Manual CSE if the difference is not known at compile-time. */
2186 if (GET_CODE (temp
) != CONST_INT
)
2187 temp
= gen_rtx_MINUS (Pmode
, size
, rounded_size_op
);
2188 anti_adjust_stack (temp
);
2189 emit_stack_probe (stack_pointer_rtx
);
2193 /* Adjust back and account for the additional first interval. */
2195 adjust_stack (plus_constant (Pmode
, size
, PROBE_INTERVAL
+ dope
));
2197 adjust_stack (GEN_INT (PROBE_INTERVAL
+ dope
));
2200 /* Return an rtx representing the register or memory location
2201 in which a scalar value of data type VALTYPE
2202 was returned by a function call to function FUNC.
2203 FUNC is a FUNCTION_DECL, FNTYPE a FUNCTION_TYPE node if the precise
2204 function is known, otherwise 0.
2205 OUTGOING is 1 if on a machine with register windows this function
2206 should return the register in which the function will put its result
2210 hard_function_value (const_tree valtype
, const_tree func
, const_tree fntype
,
2211 int outgoing ATTRIBUTE_UNUSED
)
2215 val
= targetm
.calls
.function_value (valtype
, func
? func
: fntype
, outgoing
);
2218 && GET_MODE (val
) == BLKmode
)
2220 unsigned HOST_WIDE_INT bytes
= arg_int_size_in_bytes (valtype
);
2221 opt_scalar_int_mode tmpmode
;
2223 /* int_size_in_bytes can return -1. We don't need a check here
2224 since the value of bytes will then be large enough that no
2225 mode will match anyway. */
2227 FOR_EACH_MODE_IN_CLASS (tmpmode
, MODE_INT
)
2229 /* Have we found a large enough mode? */
2230 if (GET_MODE_SIZE (tmpmode
.require ()) >= bytes
)
2234 PUT_MODE (val
, tmpmode
.require ());
2239 /* Return an rtx representing the register or memory location
2240 in which a scalar value of mode MODE was returned by a library call. */
2243 hard_libcall_value (machine_mode mode
, rtx fun
)
2245 return targetm
.calls
.libcall_value (mode
, fun
);
2248 /* Look up the tree code for a given rtx code
2249 to provide the arithmetic operation for real_arithmetic.
2250 The function returns an int because the caller may not know
2251 what `enum tree_code' means. */
2254 rtx_to_tree_code (enum rtx_code code
)
2256 enum tree_code tcode
;
2279 tcode
= LAST_AND_UNUSED_TREE_CODE
;
2282 return ((int) tcode
);
2285 #include "gt-explow.h"