1 /* Expand builtin functions.
2 Copyright (C) 1988-2022 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* Legacy warning! Please add no further builtin simplifications here
21 (apart from pure constant folding) - builtin simplifications should go
22 to match.pd or gimple-fold.cc instead. */
26 #include "coretypes.h"
35 #include "stringpool.h"
37 #include "tree-ssanames.h"
42 #include "diagnostic-core.h"
44 #include "fold-const.h"
45 #include "fold-const-call.h"
46 #include "gimple-ssa-warn-access.h"
47 #include "stor-layout.h"
50 #include "tree-object-size.h"
51 #include "tree-ssa-strlen.h"
61 #include "typeclass.h"
62 #include "langhooks.h"
63 #include "value-prof.h"
65 #include "stringpool.h"
68 #include "internal-fn.h"
69 #include "case-cfn-macros.h"
70 #include "gimple-iterator.h"
71 #include "gimple-fold.h"
73 #include "file-prefix-map.h" /* remap_macro_filename() */
74 #include "gomp-constants.h"
75 #include "omp-general.h"
77 #include "gimple-ssa.h"
78 #include "tree-ssa-live.h"
79 #include "tree-outof-ssa.h"
80 #include "attr-fnspec.h"
82 #include "gimple-range.h"
83 #include "pointer-query.h"
85 struct target_builtins default_target_builtins
;
87 struct target_builtins
*this_target_builtins
= &default_target_builtins
;
90 /* Define the names of the builtin function types and codes. */
91 const char *const built_in_class_names
[BUILT_IN_LAST
]
92 = {"NOT_BUILT_IN", "BUILT_IN_FRONTEND", "BUILT_IN_MD", "BUILT_IN_NORMAL"};
94 #define DEF_BUILTIN(X, N, C, T, LT, B, F, NA, AT, IM, COND) #X,
95 const char * built_in_names
[(int) END_BUILTINS
] =
97 #include "builtins.def"
100 /* Setup an array of builtin_info_type, make sure each element decl is
101 initialized to NULL_TREE. */
102 builtin_info_type builtin_info
[(int)END_BUILTINS
];
104 /* Non-zero if __builtin_constant_p should be folded right away. */
105 bool force_folding_builtin_constant_p
;
107 static int target_char_cast (tree
, char *);
108 static int apply_args_size (void);
109 static int apply_result_size (void);
110 static rtx
result_vector (int, rtx
);
111 static void expand_builtin_prefetch (tree
);
112 static rtx
expand_builtin_apply_args (void);
113 static rtx
expand_builtin_apply_args_1 (void);
114 static rtx
expand_builtin_apply (rtx
, rtx
, rtx
);
115 static void expand_builtin_return (rtx
);
116 static enum type_class
type_to_class (tree
);
117 static rtx
expand_builtin_classify_type (tree
);
118 static rtx
expand_builtin_mathfn_3 (tree
, rtx
, rtx
);
119 static rtx
expand_builtin_mathfn_ternary (tree
, rtx
, rtx
);
120 static rtx
expand_builtin_interclass_mathfn (tree
, rtx
);
121 static rtx
expand_builtin_sincos (tree
);
122 static rtx
expand_builtin_fegetround (tree
, rtx
, machine_mode
);
123 static rtx
expand_builtin_feclear_feraise_except (tree
, rtx
, machine_mode
,
125 static rtx
expand_builtin_cexpi (tree
, rtx
);
126 static rtx
expand_builtin_issignaling (tree
, rtx
);
127 static rtx
expand_builtin_int_roundingfn (tree
, rtx
);
128 static rtx
expand_builtin_int_roundingfn_2 (tree
, rtx
);
129 static rtx
expand_builtin_next_arg (void);
130 static rtx
expand_builtin_va_start (tree
);
131 static rtx
expand_builtin_va_end (tree
);
132 static rtx
expand_builtin_va_copy (tree
);
133 static rtx
inline_expand_builtin_bytecmp (tree
, rtx
);
134 static rtx
expand_builtin_strcmp (tree
, rtx
);
135 static rtx
expand_builtin_strncmp (tree
, rtx
, machine_mode
);
136 static rtx
expand_builtin_memcpy (tree
, rtx
);
137 static rtx
expand_builtin_memory_copy_args (tree dest
, tree src
, tree len
,
138 rtx target
, tree exp
,
141 static rtx
expand_builtin_memmove (tree
, rtx
);
142 static rtx
expand_builtin_mempcpy (tree
, rtx
);
143 static rtx
expand_builtin_mempcpy_args (tree
, tree
, tree
, rtx
, tree
, memop_ret
);
144 static rtx
expand_builtin_strcpy (tree
, rtx
);
145 static rtx
expand_builtin_strcpy_args (tree
, tree
, tree
, rtx
);
146 static rtx
expand_builtin_stpcpy (tree
, rtx
, machine_mode
);
147 static rtx
expand_builtin_strncpy (tree
, rtx
);
148 static rtx
expand_builtin_memset_args (tree
, tree
, tree
, rtx
, machine_mode
, tree
);
149 static rtx
expand_builtin_bzero (tree
);
150 static rtx
expand_builtin_strlen (tree
, rtx
, machine_mode
);
151 static rtx
expand_builtin_strnlen (tree
, rtx
, machine_mode
);
152 static rtx
expand_builtin_alloca (tree
);
153 static rtx
expand_builtin_unop (machine_mode
, tree
, rtx
, rtx
, optab
);
154 static rtx
expand_builtin_frame_address (tree
, tree
);
155 static tree
stabilize_va_list_loc (location_t
, tree
, int);
156 static rtx
expand_builtin_expect (tree
, rtx
);
157 static rtx
expand_builtin_expect_with_probability (tree
, rtx
);
158 static tree
fold_builtin_constant_p (tree
);
159 static tree
fold_builtin_classify_type (tree
);
160 static tree
fold_builtin_strlen (location_t
, tree
, tree
, tree
);
161 static tree
fold_builtin_inf (location_t
, tree
, int);
162 static tree
rewrite_call_expr (location_t
, tree
, int, tree
, int, ...);
163 static bool validate_arg (const_tree
, enum tree_code code
);
164 static rtx
expand_builtin_fabs (tree
, rtx
, rtx
);
165 static rtx
expand_builtin_signbit (tree
, rtx
);
166 static tree
fold_builtin_memcmp (location_t
, tree
, tree
, tree
);
167 static tree
fold_builtin_isascii (location_t
, tree
);
168 static tree
fold_builtin_toascii (location_t
, tree
);
169 static tree
fold_builtin_isdigit (location_t
, tree
);
170 static tree
fold_builtin_fabs (location_t
, tree
, tree
);
171 static tree
fold_builtin_abs (location_t
, tree
, tree
);
172 static tree
fold_builtin_unordered_cmp (location_t
, tree
, tree
, tree
, enum tree_code
,
174 static tree
fold_builtin_varargs (location_t
, tree
, tree
*, int);
176 static tree
fold_builtin_strpbrk (location_t
, tree
, tree
, tree
, tree
);
177 static tree
fold_builtin_strspn (location_t
, tree
, tree
, tree
);
178 static tree
fold_builtin_strcspn (location_t
, tree
, tree
, tree
);
180 static rtx
expand_builtin_object_size (tree
);
181 static rtx
expand_builtin_memory_chk (tree
, rtx
, machine_mode
,
182 enum built_in_function
);
183 static void maybe_emit_chk_warning (tree
, enum built_in_function
);
184 static void maybe_emit_sprintf_chk_warning (tree
, enum built_in_function
);
185 static tree
fold_builtin_object_size (tree
, tree
, enum built_in_function
);
187 unsigned HOST_WIDE_INT target_newline
;
188 unsigned HOST_WIDE_INT target_percent
;
189 static unsigned HOST_WIDE_INT target_c
;
190 static unsigned HOST_WIDE_INT target_s
;
191 char target_percent_c
[3];
192 char target_percent_s
[3];
193 char target_percent_s_newline
[4];
194 static tree
do_mpfr_remquo (tree
, tree
, tree
);
195 static tree
do_mpfr_lgamma_r (tree
, tree
, tree
);
196 static void expand_builtin_sync_synchronize (void);
198 /* Return true if NAME starts with __builtin_ or __sync_. */
201 is_builtin_name (const char *name
)
203 return (startswith (name
, "__builtin_")
204 || startswith (name
, "__sync_")
205 || startswith (name
, "__atomic_"));
208 /* Return true if NODE should be considered for inline expansion regardless
209 of the optimization level. This means whenever a function is invoked with
210 its "internal" name, which normally contains the prefix "__builtin". */
213 called_as_built_in (tree node
)
215 /* Note that we must use DECL_NAME, not DECL_ASSEMBLER_NAME_SET_P since
216 we want the name used to call the function, not the name it
218 const char *name
= IDENTIFIER_POINTER (DECL_NAME (node
));
219 return is_builtin_name (name
);
222 /* Compute values M and N such that M divides (address of EXP - N) and such
223 that N < M. If these numbers can be determined, store M in alignp and N in
224 *BITPOSP and return true. Otherwise return false and store BITS_PER_UNIT to
225 *alignp and any bit-offset to *bitposp.
227 Note that the address (and thus the alignment) computed here is based
228 on the address to which a symbol resolves, whereas DECL_ALIGN is based
229 on the address at which an object is actually located. These two
230 addresses are not always the same. For example, on ARM targets,
231 the address &foo of a Thumb function foo() has the lowest bit set,
232 whereas foo() itself starts on an even address.
234 If ADDR_P is true we are taking the address of the memory reference EXP
235 and thus cannot rely on the access taking place. */
238 get_object_alignment_2 (tree exp
, unsigned int *alignp
,
239 unsigned HOST_WIDE_INT
*bitposp
, bool addr_p
)
241 poly_int64 bitsize
, bitpos
;
244 int unsignedp
, reversep
, volatilep
;
245 unsigned int align
= BITS_PER_UNIT
;
246 bool known_alignment
= false;
248 /* Get the innermost object and the constant (bitpos) and possibly
249 variable (offset) offset of the access. */
250 exp
= get_inner_reference (exp
, &bitsize
, &bitpos
, &offset
, &mode
,
251 &unsignedp
, &reversep
, &volatilep
);
253 /* Extract alignment information from the innermost object and
254 possibly adjust bitpos and offset. */
255 if (TREE_CODE (exp
) == FUNCTION_DECL
)
257 /* Function addresses can encode extra information besides their
258 alignment. However, if TARGET_PTRMEMFUNC_VBIT_LOCATION
259 allows the low bit to be used as a virtual bit, we know
260 that the address itself must be at least 2-byte aligned. */
261 if (TARGET_PTRMEMFUNC_VBIT_LOCATION
== ptrmemfunc_vbit_in_pfn
)
262 align
= 2 * BITS_PER_UNIT
;
264 else if (TREE_CODE (exp
) == LABEL_DECL
)
266 else if (TREE_CODE (exp
) == CONST_DECL
)
268 /* The alignment of a CONST_DECL is determined by its initializer. */
269 exp
= DECL_INITIAL (exp
);
270 align
= TYPE_ALIGN (TREE_TYPE (exp
));
271 if (CONSTANT_CLASS_P (exp
))
272 align
= targetm
.constant_alignment (exp
, align
);
274 known_alignment
= true;
276 else if (DECL_P (exp
))
278 align
= DECL_ALIGN (exp
);
279 known_alignment
= true;
281 else if (TREE_CODE (exp
) == INDIRECT_REF
282 || TREE_CODE (exp
) == MEM_REF
283 || TREE_CODE (exp
) == TARGET_MEM_REF
)
285 tree addr
= TREE_OPERAND (exp
, 0);
287 unsigned HOST_WIDE_INT ptr_bitpos
;
288 unsigned HOST_WIDE_INT ptr_bitmask
= ~0;
290 /* If the address is explicitely aligned, handle that. */
291 if (TREE_CODE (addr
) == BIT_AND_EXPR
292 && TREE_CODE (TREE_OPERAND (addr
, 1)) == INTEGER_CST
)
294 ptr_bitmask
= TREE_INT_CST_LOW (TREE_OPERAND (addr
, 1));
295 ptr_bitmask
*= BITS_PER_UNIT
;
296 align
= least_bit_hwi (ptr_bitmask
);
297 addr
= TREE_OPERAND (addr
, 0);
301 = get_pointer_alignment_1 (addr
, &ptr_align
, &ptr_bitpos
);
302 align
= MAX (ptr_align
, align
);
304 /* Re-apply explicit alignment to the bitpos. */
305 ptr_bitpos
&= ptr_bitmask
;
307 /* The alignment of the pointer operand in a TARGET_MEM_REF
308 has to take the variable offset parts into account. */
309 if (TREE_CODE (exp
) == TARGET_MEM_REF
)
313 unsigned HOST_WIDE_INT step
= 1;
315 step
= TREE_INT_CST_LOW (TMR_STEP (exp
));
316 align
= MIN (align
, least_bit_hwi (step
) * BITS_PER_UNIT
);
318 if (TMR_INDEX2 (exp
))
319 align
= BITS_PER_UNIT
;
320 known_alignment
= false;
323 /* When EXP is an actual memory reference then we can use
324 TYPE_ALIGN of a pointer indirection to derive alignment.
325 Do so only if get_pointer_alignment_1 did not reveal absolute
326 alignment knowledge and if using that alignment would
327 improve the situation. */
329 if (!addr_p
&& !known_alignment
330 && (talign
= min_align_of_type (TREE_TYPE (exp
)) * BITS_PER_UNIT
)
335 /* Else adjust bitpos accordingly. */
336 bitpos
+= ptr_bitpos
;
337 if (TREE_CODE (exp
) == MEM_REF
338 || TREE_CODE (exp
) == TARGET_MEM_REF
)
339 bitpos
+= mem_ref_offset (exp
).force_shwi () * BITS_PER_UNIT
;
342 else if (TREE_CODE (exp
) == STRING_CST
)
344 /* STRING_CST are the only constant objects we allow to be not
345 wrapped inside a CONST_DECL. */
346 align
= TYPE_ALIGN (TREE_TYPE (exp
));
347 if (CONSTANT_CLASS_P (exp
))
348 align
= targetm
.constant_alignment (exp
, align
);
350 known_alignment
= true;
353 /* If there is a non-constant offset part extract the maximum
354 alignment that can prevail. */
357 unsigned int trailing_zeros
= tree_ctz (offset
);
358 if (trailing_zeros
< HOST_BITS_PER_INT
)
360 unsigned int inner
= (1U << trailing_zeros
) * BITS_PER_UNIT
;
362 align
= MIN (align
, inner
);
366 /* Account for the alignment of runtime coefficients, so that the constant
367 bitpos is guaranteed to be accurate. */
368 unsigned int alt_align
= ::known_alignment (bitpos
- bitpos
.coeffs
[0]);
369 if (alt_align
!= 0 && alt_align
< align
)
372 known_alignment
= false;
376 *bitposp
= bitpos
.coeffs
[0] & (align
- 1);
377 return known_alignment
;
380 /* For a memory reference expression EXP compute values M and N such that M
381 divides (&EXP - N) and such that N < M. If these numbers can be determined,
382 store M in alignp and N in *BITPOSP and return true. Otherwise return false
383 and store BITS_PER_UNIT to *alignp and any bit-offset to *bitposp. */
386 get_object_alignment_1 (tree exp
, unsigned int *alignp
,
387 unsigned HOST_WIDE_INT
*bitposp
)
389 /* Strip a WITH_SIZE_EXPR, get_inner_reference doesn't know how to deal
391 if (TREE_CODE (exp
) == WITH_SIZE_EXPR
)
392 exp
= TREE_OPERAND (exp
, 0);
393 return get_object_alignment_2 (exp
, alignp
, bitposp
, false);
396 /* Return the alignment in bits of EXP, an object. */
399 get_object_alignment (tree exp
)
401 unsigned HOST_WIDE_INT bitpos
= 0;
404 get_object_alignment_1 (exp
, &align
, &bitpos
);
406 /* align and bitpos now specify known low bits of the pointer.
407 ptr & (align - 1) == bitpos. */
410 align
= least_bit_hwi (bitpos
);
414 /* For a pointer valued expression EXP compute values M and N such that M
415 divides (EXP - N) and such that N < M. If these numbers can be determined,
416 store M in alignp and N in *BITPOSP and return true. Return false if
417 the results are just a conservative approximation.
419 If EXP is not a pointer, false is returned too. */
422 get_pointer_alignment_1 (tree exp
, unsigned int *alignp
,
423 unsigned HOST_WIDE_INT
*bitposp
)
427 if (TREE_CODE (exp
) == ADDR_EXPR
)
428 return get_object_alignment_2 (TREE_OPERAND (exp
, 0),
429 alignp
, bitposp
, true);
430 else if (TREE_CODE (exp
) == POINTER_PLUS_EXPR
)
433 unsigned HOST_WIDE_INT bitpos
;
434 bool res
= get_pointer_alignment_1 (TREE_OPERAND (exp
, 0),
436 if (TREE_CODE (TREE_OPERAND (exp
, 1)) == INTEGER_CST
)
437 bitpos
+= TREE_INT_CST_LOW (TREE_OPERAND (exp
, 1)) * BITS_PER_UNIT
;
440 unsigned int trailing_zeros
= tree_ctz (TREE_OPERAND (exp
, 1));
441 if (trailing_zeros
< HOST_BITS_PER_INT
)
443 unsigned int inner
= (1U << trailing_zeros
) * BITS_PER_UNIT
;
445 align
= MIN (align
, inner
);
449 *bitposp
= bitpos
& (align
- 1);
452 else if (TREE_CODE (exp
) == SSA_NAME
453 && POINTER_TYPE_P (TREE_TYPE (exp
)))
455 unsigned int ptr_align
, ptr_misalign
;
456 struct ptr_info_def
*pi
= SSA_NAME_PTR_INFO (exp
);
458 if (pi
&& get_ptr_info_alignment (pi
, &ptr_align
, &ptr_misalign
))
460 *bitposp
= ptr_misalign
* BITS_PER_UNIT
;
461 *alignp
= ptr_align
* BITS_PER_UNIT
;
462 /* Make sure to return a sensible alignment when the multiplication
463 by BITS_PER_UNIT overflowed. */
465 *alignp
= 1u << (HOST_BITS_PER_INT
- 1);
466 /* We cannot really tell whether this result is an approximation. */
472 *alignp
= BITS_PER_UNIT
;
476 else if (TREE_CODE (exp
) == INTEGER_CST
)
478 *alignp
= BIGGEST_ALIGNMENT
;
479 *bitposp
= ((TREE_INT_CST_LOW (exp
) * BITS_PER_UNIT
)
480 & (BIGGEST_ALIGNMENT
- 1));
485 *alignp
= BITS_PER_UNIT
;
489 /* Return the alignment in bits of EXP, a pointer valued expression.
490 The alignment returned is, by default, the alignment of the thing that
491 EXP points to. If it is not a POINTER_TYPE, 0 is returned.
493 Otherwise, look at the expression to see if we can do better, i.e., if the
494 expression is actually pointing at an object whose alignment is tighter. */
497 get_pointer_alignment (tree exp
)
499 unsigned HOST_WIDE_INT bitpos
= 0;
502 get_pointer_alignment_1 (exp
, &align
, &bitpos
);
504 /* align and bitpos now specify known low bits of the pointer.
505 ptr & (align - 1) == bitpos. */
508 align
= least_bit_hwi (bitpos
);
513 /* Return the number of leading non-zero elements in the sequence
514 [ PTR, PTR + MAXELTS ) where each element's size is ELTSIZE bytes.
515 ELTSIZE must be a power of 2 less than 8. Used by c_strlen. */
518 string_length (const void *ptr
, unsigned eltsize
, unsigned maxelts
)
520 gcc_checking_assert (eltsize
== 1 || eltsize
== 2 || eltsize
== 4);
526 /* Optimize the common case of plain char. */
527 for (n
= 0; n
< maxelts
; n
++)
529 const char *elt
= (const char*) ptr
+ n
;
536 for (n
= 0; n
< maxelts
; n
++)
538 const char *elt
= (const char*) ptr
+ n
* eltsize
;
539 if (!memcmp (elt
, "\0\0\0\0", eltsize
))
546 /* Compute the length of a null-terminated character string or wide
547 character string handling character sizes of 1, 2, and 4 bytes.
548 TREE_STRING_LENGTH is not the right way because it evaluates to
549 the size of the character array in bytes (as opposed to characters)
550 and because it can contain a zero byte in the middle.
552 ONLY_VALUE should be nonzero if the result is not going to be emitted
553 into the instruction stream and zero if it is going to be expanded.
554 E.g. with i++ ? "foo" : "bar", if ONLY_VALUE is nonzero, constant 3
555 is returned, otherwise NULL, since
556 len = c_strlen (ARG, 1); if (len) expand_expr (len, ...); would not
557 evaluate the side-effects.
559 If ONLY_VALUE is two then we do not emit warnings about out-of-bound
560 accesses. Note that this implies the result is not going to be emitted
561 into the instruction stream.
563 Additional information about the string accessed may be recorded
564 in DATA. For example, if ARG references an unterminated string,
565 then the declaration will be stored in the DECL field. If the
566 length of the unterminated string can be determined, it'll be
567 stored in the LEN field. Note this length could well be different
568 than what a C strlen call would return.
570 ELTSIZE is 1 for normal single byte character strings, and 2 or
571 4 for wide characer strings. ELTSIZE is by default 1.
573 The value returned is of type `ssizetype'. */
576 c_strlen (tree arg
, int only_value
, c_strlen_data
*data
, unsigned eltsize
)
578 /* If we were not passed a DATA pointer, then get one to a local
579 structure. That avoids having to check DATA for NULL before
580 each time we want to use it. */
581 c_strlen_data local_strlen_data
= { };
583 data
= &local_strlen_data
;
585 gcc_checking_assert (eltsize
== 1 || eltsize
== 2 || eltsize
== 4);
587 tree src
= STRIP_NOPS (arg
);
588 if (TREE_CODE (src
) == COND_EXPR
589 && (only_value
|| !TREE_SIDE_EFFECTS (TREE_OPERAND (src
, 0))))
593 len1
= c_strlen (TREE_OPERAND (src
, 1), only_value
, data
, eltsize
);
594 len2
= c_strlen (TREE_OPERAND (src
, 2), only_value
, data
, eltsize
);
595 if (tree_int_cst_equal (len1
, len2
))
599 if (TREE_CODE (src
) == COMPOUND_EXPR
600 && (only_value
|| !TREE_SIDE_EFFECTS (TREE_OPERAND (src
, 0))))
601 return c_strlen (TREE_OPERAND (src
, 1), only_value
, data
, eltsize
);
603 location_t loc
= EXPR_LOC_OR_LOC (src
, input_location
);
605 /* Offset from the beginning of the string in bytes. */
609 src
= string_constant (src
, &byteoff
, &memsize
, &decl
);
613 /* Determine the size of the string element. */
614 if (eltsize
!= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src
)))))
617 /* Set MAXELTS to ARRAY_SIZE (SRC) - 1, the maximum possible
618 length of SRC. Prefer TYPE_SIZE() to TREE_STRING_LENGTH() if possible
619 in case the latter is less than the size of the array, such as when
620 SRC refers to a short string literal used to initialize a large array.
621 In that case, the elements of the array after the terminating NUL are
623 HOST_WIDE_INT strelts
= TREE_STRING_LENGTH (src
);
624 strelts
= strelts
/ eltsize
;
626 if (!tree_fits_uhwi_p (memsize
))
629 HOST_WIDE_INT maxelts
= tree_to_uhwi (memsize
) / eltsize
;
631 /* PTR can point to the byte representation of any string type, including
632 char* and wchar_t*. */
633 const char *ptr
= TREE_STRING_POINTER (src
);
635 if (byteoff
&& TREE_CODE (byteoff
) != INTEGER_CST
)
637 /* The code below works only for single byte character types. */
641 /* If the string has an internal NUL character followed by any
642 non-NUL characters (e.g., "foo\0bar"), we can't compute
643 the offset to the following NUL if we don't know where to
644 start searching for it. */
645 unsigned len
= string_length (ptr
, eltsize
, strelts
);
647 /* Return when an embedded null character is found or none at all.
648 In the latter case, set the DECL/LEN field in the DATA structure
649 so that callers may examine them. */
650 if (len
+ 1 < strelts
)
652 else if (len
>= maxelts
)
656 data
->minlen
= ssize_int (len
);
660 /* For empty strings the result should be zero. */
662 return ssize_int (0);
664 /* We don't know the starting offset, but we do know that the string
665 has no internal zero bytes. If the offset falls within the bounds
666 of the string subtract the offset from the length of the string,
667 and return that. Otherwise the length is zero. Take care to
668 use SAVE_EXPR in case the OFFSET has side-effects. */
669 tree offsave
= TREE_SIDE_EFFECTS (byteoff
) ? save_expr (byteoff
)
671 offsave
= fold_convert_loc (loc
, sizetype
, offsave
);
672 tree condexp
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, offsave
,
674 tree lenexp
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
, size_int (len
),
676 lenexp
= fold_convert_loc (loc
, ssizetype
, lenexp
);
677 return fold_build3_loc (loc
, COND_EXPR
, ssizetype
, condexp
, lenexp
,
678 build_zero_cst (ssizetype
));
681 /* Offset from the beginning of the string in elements. */
682 HOST_WIDE_INT eltoff
;
684 /* We have a known offset into the string. Start searching there for
685 a null character if we can represent it as a single HOST_WIDE_INT. */
688 else if (! tree_fits_uhwi_p (byteoff
) || tree_to_uhwi (byteoff
) % eltsize
)
691 eltoff
= tree_to_uhwi (byteoff
) / eltsize
;
693 /* If the offset is known to be out of bounds, warn, and call strlen at
695 if (eltoff
< 0 || eltoff
>= maxelts
)
697 /* Suppress multiple warnings for propagated constant strings. */
699 && !warning_suppressed_p (arg
, OPT_Warray_bounds
)
700 && warning_at (loc
, OPT_Warray_bounds
,
701 "offset %qwi outside bounds of constant string",
705 inform (DECL_SOURCE_LOCATION (decl
), "%qE declared here", decl
);
706 suppress_warning (arg
, OPT_Warray_bounds
);
711 /* If eltoff is larger than strelts but less than maxelts the
712 string length is zero, since the excess memory will be zero. */
713 if (eltoff
> strelts
)
714 return ssize_int (0);
716 /* Use strlen to search for the first zero byte. Since any strings
717 constructed with build_string will have nulls appended, we win even
718 if we get handed something like (char[4])"abcd".
720 Since ELTOFF is our starting index into the string, no further
721 calculation is needed. */
722 unsigned len
= string_length (ptr
+ eltoff
* eltsize
, eltsize
,
725 /* Don't know what to return if there was no zero termination.
726 Ideally this would turn into a gcc_checking_assert over time.
727 Set DECL/LEN so callers can examine them. */
728 if (len
>= maxelts
- eltoff
)
732 data
->minlen
= ssize_int (len
);
736 return ssize_int (len
);
739 /* Return a constant integer corresponding to target reading
740 GET_MODE_BITSIZE (MODE) bits from string constant STR. If
741 NULL_TERMINATED_P, reading stops after '\0' character, all further ones
742 are assumed to be zero, otherwise it reads as many characters
746 c_readstr (const char *str
, scalar_int_mode mode
,
747 bool null_terminated_p
/*=true*/)
751 HOST_WIDE_INT tmp
[MAX_BITSIZE_MODE_ANY_INT
/ HOST_BITS_PER_WIDE_INT
];
753 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
);
754 unsigned int len
= (GET_MODE_PRECISION (mode
) + HOST_BITS_PER_WIDE_INT
- 1)
755 / HOST_BITS_PER_WIDE_INT
;
757 gcc_assert (len
<= MAX_BITSIZE_MODE_ANY_INT
/ HOST_BITS_PER_WIDE_INT
);
758 for (i
= 0; i
< len
; i
++)
762 for (i
= 0; i
< GET_MODE_SIZE (mode
); i
++)
765 if (WORDS_BIG_ENDIAN
)
766 j
= GET_MODE_SIZE (mode
) - i
- 1;
767 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
768 && GET_MODE_SIZE (mode
) >= UNITS_PER_WORD
)
769 j
= j
+ UNITS_PER_WORD
- 2 * (j
% UNITS_PER_WORD
) - 1;
772 if (ch
|| !null_terminated_p
)
773 ch
= (unsigned char) str
[i
];
774 tmp
[j
/ HOST_BITS_PER_WIDE_INT
] |= ch
<< (j
% HOST_BITS_PER_WIDE_INT
);
777 wide_int c
= wide_int::from_array (tmp
, len
, GET_MODE_PRECISION (mode
));
778 return immed_wide_int_const (c
, mode
);
781 /* Cast a target constant CST to target CHAR and if that value fits into
782 host char type, return zero and put that value into variable pointed to by
786 target_char_cast (tree cst
, char *p
)
788 unsigned HOST_WIDE_INT val
, hostval
;
790 if (TREE_CODE (cst
) != INTEGER_CST
791 || CHAR_TYPE_SIZE
> HOST_BITS_PER_WIDE_INT
)
794 /* Do not care if it fits or not right here. */
795 val
= TREE_INT_CST_LOW (cst
);
797 if (CHAR_TYPE_SIZE
< HOST_BITS_PER_WIDE_INT
)
798 val
&= (HOST_WIDE_INT_1U
<< CHAR_TYPE_SIZE
) - 1;
801 if (HOST_BITS_PER_CHAR
< HOST_BITS_PER_WIDE_INT
)
802 hostval
&= (HOST_WIDE_INT_1U
<< HOST_BITS_PER_CHAR
) - 1;
811 /* Similar to save_expr, but assumes that arbitrary code is not executed
812 in between the multiple evaluations. In particular, we assume that a
813 non-addressable local variable will not be modified. */
816 builtin_save_expr (tree exp
)
818 if (TREE_CODE (exp
) == SSA_NAME
819 || (TREE_ADDRESSABLE (exp
) == 0
820 && (TREE_CODE (exp
) == PARM_DECL
821 || (VAR_P (exp
) && !TREE_STATIC (exp
)))))
824 return save_expr (exp
);
827 /* Given TEM, a pointer to a stack frame, follow the dynamic chain COUNT
828 times to get the address of either a higher stack frame, or a return
829 address located within it (depending on FNDECL_CODE). */
832 expand_builtin_return_addr (enum built_in_function fndecl_code
, int count
)
835 rtx tem
= INITIAL_FRAME_ADDRESS_RTX
;
838 /* For a zero count with __builtin_return_address, we don't care what
839 frame address we return, because target-specific definitions will
840 override us. Therefore frame pointer elimination is OK, and using
841 the soft frame pointer is OK.
843 For a nonzero count, or a zero count with __builtin_frame_address,
844 we require a stable offset from the current frame pointer to the
845 previous one, so we must use the hard frame pointer, and
846 we must disable frame pointer elimination. */
847 if (count
== 0 && fndecl_code
== BUILT_IN_RETURN_ADDRESS
)
848 tem
= frame_pointer_rtx
;
851 tem
= hard_frame_pointer_rtx
;
853 /* Tell reload not to eliminate the frame pointer. */
854 crtl
->accesses_prior_frames
= 1;
859 SETUP_FRAME_ADDRESSES ();
861 /* On the SPARC, the return address is not in the frame, it is in a
862 register. There is no way to access it off of the current frame
863 pointer, but it can be accessed off the previous frame pointer by
864 reading the value from the register window save area. */
865 if (RETURN_ADDR_IN_PREVIOUS_FRAME
&& fndecl_code
== BUILT_IN_RETURN_ADDRESS
)
868 /* Scan back COUNT frames to the specified frame. */
869 for (i
= 0; i
< count
; i
++)
871 /* Assume the dynamic chain pointer is in the word that the
872 frame address points to, unless otherwise specified. */
873 tem
= DYNAMIC_CHAIN_ADDRESS (tem
);
874 tem
= memory_address (Pmode
, tem
);
875 tem
= gen_frame_mem (Pmode
, tem
);
876 tem
= copy_to_reg (tem
);
879 /* For __builtin_frame_address, return what we've got. But, on
880 the SPARC for example, we may have to add a bias. */
881 if (fndecl_code
== BUILT_IN_FRAME_ADDRESS
)
882 return FRAME_ADDR_RTX (tem
);
884 /* For __builtin_return_address, get the return address from that frame. */
885 #ifdef RETURN_ADDR_RTX
886 tem
= RETURN_ADDR_RTX (count
, tem
);
888 tem
= memory_address (Pmode
,
889 plus_constant (Pmode
, tem
, GET_MODE_SIZE (Pmode
)));
890 tem
= gen_frame_mem (Pmode
, tem
);
895 /* Alias set used for setjmp buffer. */
896 static alias_set_type setjmp_alias_set
= -1;
898 /* Construct the leading half of a __builtin_setjmp call. Control will
899 return to RECEIVER_LABEL. This is also called directly by the SJLJ
900 exception handling code. */
903 expand_builtin_setjmp_setup (rtx buf_addr
, rtx receiver_label
)
905 machine_mode sa_mode
= STACK_SAVEAREA_MODE (SAVE_NONLOCAL
);
909 if (setjmp_alias_set
== -1)
910 setjmp_alias_set
= new_alias_set ();
912 buf_addr
= convert_memory_address (Pmode
, buf_addr
);
914 buf_addr
= force_reg (Pmode
, force_operand (buf_addr
, NULL_RTX
));
916 /* We store the frame pointer and the address of receiver_label in
917 the buffer and use the rest of it for the stack save area, which
918 is machine-dependent. */
920 mem
= gen_rtx_MEM (Pmode
, buf_addr
);
921 set_mem_alias_set (mem
, setjmp_alias_set
);
922 emit_move_insn (mem
, hard_frame_pointer_rtx
);
924 mem
= gen_rtx_MEM (Pmode
, plus_constant (Pmode
, buf_addr
,
925 GET_MODE_SIZE (Pmode
))),
926 set_mem_alias_set (mem
, setjmp_alias_set
);
928 emit_move_insn (validize_mem (mem
),
929 force_reg (Pmode
, gen_rtx_LABEL_REF (Pmode
, receiver_label
)));
931 stack_save
= gen_rtx_MEM (sa_mode
,
932 plus_constant (Pmode
, buf_addr
,
933 2 * GET_MODE_SIZE (Pmode
)));
934 set_mem_alias_set (stack_save
, setjmp_alias_set
);
935 emit_stack_save (SAVE_NONLOCAL
, &stack_save
);
937 /* If there is further processing to do, do it. */
938 if (targetm
.have_builtin_setjmp_setup ())
939 emit_insn (targetm
.gen_builtin_setjmp_setup (buf_addr
));
941 /* We have a nonlocal label. */
942 cfun
->has_nonlocal_label
= 1;
945 /* Construct the trailing part of a __builtin_setjmp call. This is
946 also called directly by the SJLJ exception handling code.
947 If RECEIVER_LABEL is NULL, instead contruct a nonlocal goto handler. */
950 expand_builtin_setjmp_receiver (rtx receiver_label
)
954 /* Mark the FP as used when we get here, so we have to make sure it's
955 marked as used by this function. */
956 emit_use (hard_frame_pointer_rtx
);
958 /* Mark the static chain as clobbered here so life information
959 doesn't get messed up for it. */
960 chain
= rtx_for_static_chain (current_function_decl
, true);
961 if (chain
&& REG_P (chain
))
962 emit_clobber (chain
);
964 if (!HARD_FRAME_POINTER_IS_ARG_POINTER
&& fixed_regs
[ARG_POINTER_REGNUM
])
966 /* If the argument pointer can be eliminated in favor of the
967 frame pointer, we don't need to restore it. We assume here
968 that if such an elimination is present, it can always be used.
969 This is the case on all known machines; if we don't make this
970 assumption, we do unnecessary saving on many machines. */
972 static const struct elims
{const int from
, to
;} elim_regs
[] = ELIMINABLE_REGS
;
974 for (i
= 0; i
< ARRAY_SIZE (elim_regs
); i
++)
975 if (elim_regs
[i
].from
== ARG_POINTER_REGNUM
976 && elim_regs
[i
].to
== HARD_FRAME_POINTER_REGNUM
)
979 if (i
== ARRAY_SIZE (elim_regs
))
981 /* Now restore our arg pointer from the address at which it
982 was saved in our stack frame. */
983 emit_move_insn (crtl
->args
.internal_arg_pointer
,
984 copy_to_reg (get_arg_pointer_save_area ()));
988 if (receiver_label
!= NULL
&& targetm
.have_builtin_setjmp_receiver ())
989 emit_insn (targetm
.gen_builtin_setjmp_receiver (receiver_label
));
990 else if (targetm
.have_nonlocal_goto_receiver ())
991 emit_insn (targetm
.gen_nonlocal_goto_receiver ());
995 /* We must not allow the code we just generated to be reordered by
996 scheduling. Specifically, the update of the frame pointer must
997 happen immediately, not later. */
998 emit_insn (gen_blockage ());
1001 /* __builtin_longjmp is passed a pointer to an array of five words (not
1002 all will be used on all machines). It operates similarly to the C
1003 library function of the same name, but is more efficient. Much of
1004 the code below is copied from the handling of non-local gotos. */
1007 expand_builtin_longjmp (rtx buf_addr
, rtx value
)
1010 rtx_insn
*insn
, *last
;
1011 machine_mode sa_mode
= STACK_SAVEAREA_MODE (SAVE_NONLOCAL
);
1013 /* DRAP is needed for stack realign if longjmp is expanded to current
1015 if (SUPPORTS_STACK_ALIGNMENT
)
1016 crtl
->need_drap
= true;
1018 if (setjmp_alias_set
== -1)
1019 setjmp_alias_set
= new_alias_set ();
1021 buf_addr
= convert_memory_address (Pmode
, buf_addr
);
1023 buf_addr
= force_reg (Pmode
, buf_addr
);
1025 /* We require that the user must pass a second argument of 1, because
1026 that is what builtin_setjmp will return. */
1027 gcc_assert (value
== const1_rtx
);
1029 last
= get_last_insn ();
1030 if (targetm
.have_builtin_longjmp ())
1031 emit_insn (targetm
.gen_builtin_longjmp (buf_addr
));
1034 fp
= gen_rtx_MEM (Pmode
, buf_addr
);
1035 lab
= gen_rtx_MEM (Pmode
, plus_constant (Pmode
, buf_addr
,
1036 GET_MODE_SIZE (Pmode
)));
1038 stack
= gen_rtx_MEM (sa_mode
, plus_constant (Pmode
, buf_addr
,
1039 2 * GET_MODE_SIZE (Pmode
)));
1040 set_mem_alias_set (fp
, setjmp_alias_set
);
1041 set_mem_alias_set (lab
, setjmp_alias_set
);
1042 set_mem_alias_set (stack
, setjmp_alias_set
);
1044 /* Pick up FP, label, and SP from the block and jump. This code is
1045 from expand_goto in stmt.cc; see there for detailed comments. */
1046 if (targetm
.have_nonlocal_goto ())
1047 /* We have to pass a value to the nonlocal_goto pattern that will
1048 get copied into the static_chain pointer, but it does not matter
1049 what that value is, because builtin_setjmp does not use it. */
1050 emit_insn (targetm
.gen_nonlocal_goto (value
, lab
, stack
, fp
));
1053 emit_clobber (gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
)));
1054 emit_clobber (gen_rtx_MEM (BLKmode
, hard_frame_pointer_rtx
));
1056 lab
= copy_to_reg (lab
);
1058 /* Restore the frame pointer and stack pointer. We must use a
1059 temporary since the setjmp buffer may be a local. */
1060 fp
= copy_to_reg (fp
);
1061 emit_stack_restore (SAVE_NONLOCAL
, stack
);
1063 /* Ensure the frame pointer move is not optimized. */
1064 emit_insn (gen_blockage ());
1065 emit_clobber (hard_frame_pointer_rtx
);
1066 emit_clobber (frame_pointer_rtx
);
1067 emit_move_insn (hard_frame_pointer_rtx
, fp
);
1069 emit_use (hard_frame_pointer_rtx
);
1070 emit_use (stack_pointer_rtx
);
1071 emit_indirect_jump (lab
);
1075 /* Search backwards and mark the jump insn as a non-local goto.
1076 Note that this precludes the use of __builtin_longjmp to a
1077 __builtin_setjmp target in the same function. However, we've
1078 already cautioned the user that these functions are for
1079 internal exception handling use only. */
1080 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
1082 gcc_assert (insn
!= last
);
1086 add_reg_note (insn
, REG_NON_LOCAL_GOTO
, const0_rtx
);
1089 else if (CALL_P (insn
))
1095 more_const_call_expr_args_p (const const_call_expr_arg_iterator
*iter
)
1097 return (iter
->i
< iter
->n
);
1100 /* This function validates the types of a function call argument list
1101 against a specified list of tree_codes. If the last specifier is a 0,
1102 that represents an ellipsis, otherwise the last specifier must be a
1106 validate_arglist (const_tree callexpr
, ...)
1108 enum tree_code code
;
1111 const_call_expr_arg_iterator iter
;
1114 va_start (ap
, callexpr
);
1115 init_const_call_expr_arg_iterator (callexpr
, &iter
);
1117 /* Get a bitmap of pointer argument numbers declared attribute nonnull. */
1118 tree fn
= CALL_EXPR_FN (callexpr
);
1119 bitmap argmap
= get_nonnull_args (TREE_TYPE (TREE_TYPE (fn
)));
1121 for (unsigned argno
= 1; ; ++argno
)
1123 code
= (enum tree_code
) va_arg (ap
, int);
1128 /* This signifies an ellipses, any further arguments are all ok. */
1132 /* This signifies an endlink, if no arguments remain, return
1133 true, otherwise return false. */
1134 res
= !more_const_call_expr_args_p (&iter
);
1137 /* The actual argument must be nonnull when either the whole
1138 called function has been declared nonnull, or when the formal
1139 argument corresponding to the actual argument has been. */
1141 && (bitmap_empty_p (argmap
) || bitmap_bit_p (argmap
, argno
)))
1143 arg
= next_const_call_expr_arg (&iter
);
1144 if (!validate_arg (arg
, code
) || integer_zerop (arg
))
1150 /* If no parameters remain or the parameter's code does not
1151 match the specified code, return false. Otherwise continue
1152 checking any remaining arguments. */
1153 arg
= next_const_call_expr_arg (&iter
);
1154 if (!validate_arg (arg
, code
))
1160 /* We need gotos here since we can only have one VA_CLOSE in a
1165 BITMAP_FREE (argmap
);
1170 /* Expand a call to __builtin_nonlocal_goto. We're passed the target label
1171 and the address of the save area. */
1174 expand_builtin_nonlocal_goto (tree exp
)
1176 tree t_label
, t_save_area
;
1177 rtx r_label
, r_save_area
, r_fp
, r_sp
;
1180 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
1183 t_label
= CALL_EXPR_ARG (exp
, 0);
1184 t_save_area
= CALL_EXPR_ARG (exp
, 1);
1186 r_label
= expand_normal (t_label
);
1187 r_label
= convert_memory_address (Pmode
, r_label
);
1188 r_save_area
= expand_normal (t_save_area
);
1189 r_save_area
= convert_memory_address (Pmode
, r_save_area
);
1190 /* Copy the address of the save location to a register just in case it was
1191 based on the frame pointer. */
1192 r_save_area
= copy_to_reg (r_save_area
);
1193 r_fp
= gen_rtx_MEM (Pmode
, r_save_area
);
1194 r_sp
= gen_rtx_MEM (STACK_SAVEAREA_MODE (SAVE_NONLOCAL
),
1195 plus_constant (Pmode
, r_save_area
,
1196 GET_MODE_SIZE (Pmode
)));
1198 crtl
->has_nonlocal_goto
= 1;
1200 /* ??? We no longer need to pass the static chain value, afaik. */
1201 if (targetm
.have_nonlocal_goto ())
1202 emit_insn (targetm
.gen_nonlocal_goto (const0_rtx
, r_label
, r_sp
, r_fp
));
1205 emit_clobber (gen_rtx_MEM (BLKmode
, gen_rtx_SCRATCH (VOIDmode
)));
1206 emit_clobber (gen_rtx_MEM (BLKmode
, hard_frame_pointer_rtx
));
1208 r_label
= copy_to_reg (r_label
);
1210 /* Restore the frame pointer and stack pointer. We must use a
1211 temporary since the setjmp buffer may be a local. */
1212 r_fp
= copy_to_reg (r_fp
);
1213 emit_stack_restore (SAVE_NONLOCAL
, r_sp
);
1215 /* Ensure the frame pointer move is not optimized. */
1216 emit_insn (gen_blockage ());
1217 emit_clobber (hard_frame_pointer_rtx
);
1218 emit_clobber (frame_pointer_rtx
);
1219 emit_move_insn (hard_frame_pointer_rtx
, r_fp
);
1221 /* USE of hard_frame_pointer_rtx added for consistency;
1222 not clear if really needed. */
1223 emit_use (hard_frame_pointer_rtx
);
1224 emit_use (stack_pointer_rtx
);
1226 /* If the architecture is using a GP register, we must
1227 conservatively assume that the target function makes use of it.
1228 The prologue of functions with nonlocal gotos must therefore
1229 initialize the GP register to the appropriate value, and we
1230 must then make sure that this value is live at the point
1231 of the jump. (Note that this doesn't necessarily apply
1232 to targets with a nonlocal_goto pattern; they are free
1233 to implement it in their own way. Note also that this is
1234 a no-op if the GP register is a global invariant.) */
1235 unsigned regnum
= PIC_OFFSET_TABLE_REGNUM
;
1236 if (regnum
!= INVALID_REGNUM
&& fixed_regs
[regnum
])
1237 emit_use (pic_offset_table_rtx
);
1239 emit_indirect_jump (r_label
);
1242 /* Search backwards to the jump insn and mark it as a
1244 for (insn
= get_last_insn (); insn
; insn
= PREV_INSN (insn
))
1248 add_reg_note (insn
, REG_NON_LOCAL_GOTO
, const0_rtx
);
1251 else if (CALL_P (insn
))
1258 /* __builtin_update_setjmp_buf is passed a pointer to an array of five words
1259 (not all will be used on all machines) that was passed to __builtin_setjmp.
1260 It updates the stack pointer in that block to the current value. This is
1261 also called directly by the SJLJ exception handling code. */
1264 expand_builtin_update_setjmp_buf (rtx buf_addr
)
1266 machine_mode sa_mode
= STACK_SAVEAREA_MODE (SAVE_NONLOCAL
);
1267 buf_addr
= convert_memory_address (Pmode
, buf_addr
);
1269 = gen_rtx_MEM (sa_mode
,
1272 plus_constant (Pmode
, buf_addr
,
1273 2 * GET_MODE_SIZE (Pmode
))));
1275 emit_stack_save (SAVE_NONLOCAL
, &stack_save
);
1278 /* Expand a call to __builtin_prefetch. For a target that does not support
1279 data prefetch, evaluate the memory address argument in case it has side
1283 expand_builtin_prefetch (tree exp
)
1285 tree arg0
, arg1
, arg2
;
1289 if (!validate_arglist (exp
, POINTER_TYPE
, 0))
1292 arg0
= CALL_EXPR_ARG (exp
, 0);
1294 /* Arguments 1 and 2 are optional; argument 1 (read/write) defaults to
1295 zero (read) and argument 2 (locality) defaults to 3 (high degree of
1297 nargs
= call_expr_nargs (exp
);
1299 arg1
= CALL_EXPR_ARG (exp
, 1);
1301 arg1
= integer_zero_node
;
1303 arg2
= CALL_EXPR_ARG (exp
, 2);
1305 arg2
= integer_three_node
;
1307 /* Argument 0 is an address. */
1308 op0
= expand_expr (arg0
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
1310 /* Argument 1 (read/write flag) must be a compile-time constant int. */
1311 if (TREE_CODE (arg1
) != INTEGER_CST
)
1313 error ("second argument to %<__builtin_prefetch%> must be a constant");
1314 arg1
= integer_zero_node
;
1316 op1
= expand_normal (arg1
);
1317 /* Argument 1 must be either zero or one. */
1318 if (INTVAL (op1
) != 0 && INTVAL (op1
) != 1)
1320 warning (0, "invalid second argument to %<__builtin_prefetch%>;"
1325 /* Argument 2 (locality) must be a compile-time constant int. */
1326 if (TREE_CODE (arg2
) != INTEGER_CST
)
1328 error ("third argument to %<__builtin_prefetch%> must be a constant");
1329 arg2
= integer_zero_node
;
1331 op2
= expand_normal (arg2
);
1332 /* Argument 2 must be 0, 1, 2, or 3. */
1333 if (INTVAL (op2
) < 0 || INTVAL (op2
) > 3)
1335 warning (0, "invalid third argument to %<__builtin_prefetch%>; using zero");
1339 if (targetm
.have_prefetch ())
1341 class expand_operand ops
[3];
1343 create_address_operand (&ops
[0], op0
);
1344 create_integer_operand (&ops
[1], INTVAL (op1
));
1345 create_integer_operand (&ops
[2], INTVAL (op2
));
1346 if (maybe_expand_insn (targetm
.code_for_prefetch
, 3, ops
))
1350 /* Don't do anything with direct references to volatile memory, but
1351 generate code to handle other side effects. */
1352 if (!MEM_P (op0
) && side_effects_p (op0
))
1356 /* Get a MEM rtx for expression EXP which is the address of an operand
1357 to be used in a string instruction (cmpstrsi, cpymemsi, ..). LEN is
1358 the maximum length of the block of memory that might be accessed or
1362 get_memory_rtx (tree exp
, tree len
)
1364 tree orig_exp
= exp
, base
;
1367 /* When EXP is not resolved SAVE_EXPR, MEM_ATTRS can be still derived
1368 from its expression, for expr->a.b only <variable>.a.b is recorded. */
1369 if (TREE_CODE (exp
) == SAVE_EXPR
&& !SAVE_EXPR_RESOLVED_P (exp
))
1370 exp
= TREE_OPERAND (exp
, 0);
1372 addr
= expand_expr (orig_exp
, NULL_RTX
, ptr_mode
, EXPAND_NORMAL
);
1373 mem
= gen_rtx_MEM (BLKmode
, memory_address (BLKmode
, addr
));
1375 /* Get an expression we can use to find the attributes to assign to MEM.
1376 First remove any nops. */
1377 while (CONVERT_EXPR_P (exp
)
1378 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (exp
, 0))))
1379 exp
= TREE_OPERAND (exp
, 0);
1381 /* Build a MEM_REF representing the whole accessed area as a byte blob,
1382 (as builtin stringops may alias with anything). */
1383 exp
= fold_build2 (MEM_REF
,
1384 build_array_type (char_type_node
,
1385 build_range_type (sizetype
,
1386 size_one_node
, len
)),
1387 exp
, build_int_cst (ptr_type_node
, 0));
1389 /* If the MEM_REF has no acceptable address, try to get the base object
1390 from the original address we got, and build an all-aliasing
1391 unknown-sized access to that one. */
1392 if (is_gimple_mem_ref_addr (TREE_OPERAND (exp
, 0)))
1393 set_mem_attributes (mem
, exp
, 0);
1394 else if (TREE_CODE (TREE_OPERAND (exp
, 0)) == ADDR_EXPR
1395 && (base
= get_base_address (TREE_OPERAND (TREE_OPERAND (exp
, 0),
1398 unsigned int align
= get_pointer_alignment (TREE_OPERAND (exp
, 0));
1399 exp
= build_fold_addr_expr (base
);
1400 exp
= fold_build2 (MEM_REF
,
1401 build_array_type (char_type_node
,
1402 build_range_type (sizetype
,
1405 exp
, build_int_cst (ptr_type_node
, 0));
1406 set_mem_attributes (mem
, exp
, 0);
1407 /* Since we stripped parts make sure the offset is unknown and the
1408 alignment is computed from the original address. */
1409 clear_mem_offset (mem
);
1410 set_mem_align (mem
, align
);
1412 set_mem_alias_set (mem
, 0);
1416 /* Built-in functions to perform an untyped call and return. */
1418 #define apply_args_mode \
1419 (this_target_builtins->x_apply_args_mode)
1420 #define apply_result_mode \
1421 (this_target_builtins->x_apply_result_mode)
1423 /* Return the size required for the block returned by __builtin_apply_args,
1424 and initialize apply_args_mode. */
1427 apply_args_size (void)
1429 static int size
= -1;
1433 /* The values computed by this function never change. */
1436 /* The first value is the incoming arg-pointer. */
1437 size
= GET_MODE_SIZE (Pmode
);
1439 /* The second value is the structure value address unless this is
1440 passed as an "invisible" first argument. */
1441 if (targetm
.calls
.struct_value_rtx (cfun
? TREE_TYPE (cfun
->decl
) : 0, 0))
1442 size
+= GET_MODE_SIZE (Pmode
);
1444 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1445 if (FUNCTION_ARG_REGNO_P (regno
))
1447 fixed_size_mode mode
= targetm
.calls
.get_raw_arg_mode (regno
);
1449 gcc_assert (mode
!= VOIDmode
);
1451 align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
1452 if (size
% align
!= 0)
1453 size
= CEIL (size
, align
) * align
;
1454 size
+= GET_MODE_SIZE (mode
);
1455 apply_args_mode
[regno
] = mode
;
1459 apply_args_mode
[regno
] = as_a
<fixed_size_mode
> (VOIDmode
);
1465 /* Return the size required for the block returned by __builtin_apply,
1466 and initialize apply_result_mode. */
1469 apply_result_size (void)
1471 static int size
= -1;
1474 /* The values computed by this function never change. */
1479 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1480 if (targetm
.calls
.function_value_regno_p (regno
))
1482 fixed_size_mode mode
= targetm
.calls
.get_raw_result_mode (regno
);
1484 gcc_assert (mode
!= VOIDmode
);
1486 align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
1487 if (size
% align
!= 0)
1488 size
= CEIL (size
, align
) * align
;
1489 size
+= GET_MODE_SIZE (mode
);
1490 apply_result_mode
[regno
] = mode
;
1493 apply_result_mode
[regno
] = as_a
<fixed_size_mode
> (VOIDmode
);
1495 /* Allow targets that use untyped_call and untyped_return to override
1496 the size so that machine-specific information can be stored here. */
1497 #ifdef APPLY_RESULT_SIZE
1498 size
= APPLY_RESULT_SIZE
;
1504 /* Create a vector describing the result block RESULT. If SAVEP is true,
1505 the result block is used to save the values; otherwise it is used to
1506 restore the values. */
1509 result_vector (int savep
, rtx result
)
1511 int regno
, size
, align
, nelts
;
1512 fixed_size_mode mode
;
1514 rtx
*savevec
= XALLOCAVEC (rtx
, FIRST_PSEUDO_REGISTER
);
1517 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1518 if ((mode
= apply_result_mode
[regno
]) != VOIDmode
)
1520 align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
1521 if (size
% align
!= 0)
1522 size
= CEIL (size
, align
) * align
;
1523 reg
= gen_rtx_REG (mode
, savep
? regno
: INCOMING_REGNO (regno
));
1524 mem
= adjust_address (result
, mode
, size
);
1525 savevec
[nelts
++] = (savep
1526 ? gen_rtx_SET (mem
, reg
)
1527 : gen_rtx_SET (reg
, mem
));
1528 size
+= GET_MODE_SIZE (mode
);
1530 return gen_rtx_PARALLEL (VOIDmode
, gen_rtvec_v (nelts
, savevec
));
1533 /* Save the state required to perform an untyped call with the same
1534 arguments as were passed to the current function. */
1537 expand_builtin_apply_args_1 (void)
1540 int size
, align
, regno
;
1541 fixed_size_mode mode
;
1542 rtx struct_incoming_value
= targetm
.calls
.struct_value_rtx (cfun
? TREE_TYPE (cfun
->decl
) : 0, 1);
1544 /* Create a block where the arg-pointer, structure value address,
1545 and argument registers can be saved. */
1546 registers
= assign_stack_local (BLKmode
, apply_args_size (), -1);
1548 /* Walk past the arg-pointer and structure value address. */
1549 size
= GET_MODE_SIZE (Pmode
);
1550 if (targetm
.calls
.struct_value_rtx (cfun
? TREE_TYPE (cfun
->decl
) : 0, 0))
1551 size
+= GET_MODE_SIZE (Pmode
);
1553 /* Save each register used in calling a function to the block. */
1554 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1555 if ((mode
= apply_args_mode
[regno
]) != VOIDmode
)
1557 align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
1558 if (size
% align
!= 0)
1559 size
= CEIL (size
, align
) * align
;
1561 tem
= gen_rtx_REG (mode
, INCOMING_REGNO (regno
));
1563 emit_move_insn (adjust_address (registers
, mode
, size
), tem
);
1564 size
+= GET_MODE_SIZE (mode
);
1567 /* Save the arg pointer to the block. */
1568 tem
= copy_to_reg (crtl
->args
.internal_arg_pointer
);
1569 /* We need the pointer as the caller actually passed them to us, not
1570 as we might have pretended they were passed. Make sure it's a valid
1571 operand, as emit_move_insn isn't expected to handle a PLUS. */
1572 if (STACK_GROWS_DOWNWARD
)
1574 = force_operand (plus_constant (Pmode
, tem
,
1575 crtl
->args
.pretend_args_size
),
1577 emit_move_insn (adjust_address (registers
, Pmode
, 0), tem
);
1579 size
= GET_MODE_SIZE (Pmode
);
1581 /* Save the structure value address unless this is passed as an
1582 "invisible" first argument. */
1583 if (struct_incoming_value
)
1584 emit_move_insn (adjust_address (registers
, Pmode
, size
),
1585 copy_to_reg (struct_incoming_value
));
1587 /* Return the address of the block. */
1588 return copy_addr_to_reg (XEXP (registers
, 0));
1591 /* __builtin_apply_args returns block of memory allocated on
1592 the stack into which is stored the arg pointer, structure
1593 value address, static chain, and all the registers that might
1594 possibly be used in performing a function call. The code is
1595 moved to the start of the function so the incoming values are
1599 expand_builtin_apply_args (void)
1601 /* Don't do __builtin_apply_args more than once in a function.
1602 Save the result of the first call and reuse it. */
1603 if (apply_args_value
!= 0)
1604 return apply_args_value
;
1606 /* When this function is called, it means that registers must be
1607 saved on entry to this function. So we migrate the
1608 call to the first insn of this function. */
1612 temp
= expand_builtin_apply_args_1 ();
1613 rtx_insn
*seq
= get_insns ();
1616 apply_args_value
= temp
;
1618 /* Put the insns after the NOTE that starts the function.
1619 If this is inside a start_sequence, make the outer-level insn
1620 chain current, so the code is placed at the start of the
1621 function. If internal_arg_pointer is a non-virtual pseudo,
1622 it needs to be placed after the function that initializes
1624 push_topmost_sequence ();
1625 if (REG_P (crtl
->args
.internal_arg_pointer
)
1626 && REGNO (crtl
->args
.internal_arg_pointer
) > LAST_VIRTUAL_REGISTER
)
1627 emit_insn_before (seq
, parm_birth_insn
);
1629 emit_insn_before (seq
, NEXT_INSN (entry_of_function ()));
1630 pop_topmost_sequence ();
1635 /* Perform an untyped call and save the state required to perform an
1636 untyped return of whatever value was returned by the given function. */
1639 expand_builtin_apply (rtx function
, rtx arguments
, rtx argsize
)
1641 int size
, align
, regno
;
1642 fixed_size_mode mode
;
1643 rtx incoming_args
, result
, reg
, dest
, src
;
1644 rtx_call_insn
*call_insn
;
1645 rtx old_stack_level
= 0;
1646 rtx call_fusage
= 0;
1647 rtx struct_value
= targetm
.calls
.struct_value_rtx (cfun
? TREE_TYPE (cfun
->decl
) : 0, 0);
1649 arguments
= convert_memory_address (Pmode
, arguments
);
1651 /* Create a block where the return registers can be saved. */
1652 result
= assign_stack_local (BLKmode
, apply_result_size (), -1);
1654 /* Fetch the arg pointer from the ARGUMENTS block. */
1655 incoming_args
= gen_reg_rtx (Pmode
);
1656 emit_move_insn (incoming_args
, gen_rtx_MEM (Pmode
, arguments
));
1657 if (!STACK_GROWS_DOWNWARD
)
1658 incoming_args
= expand_simple_binop (Pmode
, MINUS
, incoming_args
, argsize
,
1659 incoming_args
, 0, OPTAB_LIB_WIDEN
);
1661 /* Push a new argument block and copy the arguments. Do not allow
1662 the (potential) memcpy call below to interfere with our stack
1664 do_pending_stack_adjust ();
1667 /* Save the stack with nonlocal if available. */
1668 if (targetm
.have_save_stack_nonlocal ())
1669 emit_stack_save (SAVE_NONLOCAL
, &old_stack_level
);
1671 emit_stack_save (SAVE_BLOCK
, &old_stack_level
);
1673 /* Allocate a block of memory onto the stack and copy the memory
1674 arguments to the outgoing arguments address. We can pass TRUE
1675 as the 4th argument because we just saved the stack pointer
1676 and will restore it right after the call. */
1677 allocate_dynamic_stack_space (argsize
, 0, BIGGEST_ALIGNMENT
, -1, true);
1679 /* Set DRAP flag to true, even though allocate_dynamic_stack_space
1680 may have already set current_function_calls_alloca to true.
1681 current_function_calls_alloca won't be set if argsize is zero,
1682 so we have to guarantee need_drap is true here. */
1683 if (SUPPORTS_STACK_ALIGNMENT
)
1684 crtl
->need_drap
= true;
1686 dest
= virtual_outgoing_args_rtx
;
1687 if (!STACK_GROWS_DOWNWARD
)
1689 if (CONST_INT_P (argsize
))
1690 dest
= plus_constant (Pmode
, dest
, -INTVAL (argsize
));
1692 dest
= gen_rtx_PLUS (Pmode
, dest
, negate_rtx (Pmode
, argsize
));
1694 dest
= gen_rtx_MEM (BLKmode
, dest
);
1695 set_mem_align (dest
, PARM_BOUNDARY
);
1696 src
= gen_rtx_MEM (BLKmode
, incoming_args
);
1697 set_mem_align (src
, PARM_BOUNDARY
);
1698 emit_block_move (dest
, src
, argsize
, BLOCK_OP_NORMAL
);
1700 /* Refer to the argument block. */
1702 arguments
= gen_rtx_MEM (BLKmode
, arguments
);
1703 set_mem_align (arguments
, PARM_BOUNDARY
);
1705 /* Walk past the arg-pointer and structure value address. */
1706 size
= GET_MODE_SIZE (Pmode
);
1708 size
+= GET_MODE_SIZE (Pmode
);
1710 /* Restore each of the registers previously saved. Make USE insns
1711 for each of these registers for use in making the call. */
1712 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1713 if ((mode
= apply_args_mode
[regno
]) != VOIDmode
)
1715 align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
1716 if (size
% align
!= 0)
1717 size
= CEIL (size
, align
) * align
;
1718 reg
= gen_rtx_REG (mode
, regno
);
1719 emit_move_insn (reg
, adjust_address (arguments
, mode
, size
));
1720 use_reg (&call_fusage
, reg
);
1721 size
+= GET_MODE_SIZE (mode
);
1724 /* Restore the structure value address unless this is passed as an
1725 "invisible" first argument. */
1726 size
= GET_MODE_SIZE (Pmode
);
1729 rtx value
= gen_reg_rtx (Pmode
);
1730 emit_move_insn (value
, adjust_address (arguments
, Pmode
, size
));
1731 emit_move_insn (struct_value
, value
);
1732 if (REG_P (struct_value
))
1733 use_reg (&call_fusage
, struct_value
);
1736 /* All arguments and registers used for the call are set up by now! */
1737 function
= prepare_call_address (NULL
, function
, NULL
, &call_fusage
, 0, 0);
1739 /* Ensure address is valid. SYMBOL_REF is already valid, so no need,
1740 and we don't want to load it into a register as an optimization,
1741 because prepare_call_address already did it if it should be done. */
1742 if (GET_CODE (function
) != SYMBOL_REF
)
1743 function
= memory_address (FUNCTION_MODE
, function
);
1745 /* Generate the actual call instruction and save the return value. */
1746 if (targetm
.have_untyped_call ())
1748 rtx mem
= gen_rtx_MEM (FUNCTION_MODE
, function
);
1749 rtx_insn
*seq
= targetm
.gen_untyped_call (mem
, result
,
1750 result_vector (1, result
));
1751 for (rtx_insn
*insn
= seq
; insn
; insn
= NEXT_INSN (insn
))
1753 add_reg_note (insn
, REG_UNTYPED_CALL
, NULL_RTX
);
1756 else if (targetm
.have_call_value ())
1760 /* Locate the unique return register. It is not possible to
1761 express a call that sets more than one return register using
1762 call_value; use untyped_call for that. In fact, untyped_call
1763 only needs to save the return registers in the given block. */
1764 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1765 if ((mode
= apply_result_mode
[regno
]) != VOIDmode
)
1767 gcc_assert (!valreg
); /* have_untyped_call required. */
1769 valreg
= gen_rtx_REG (mode
, regno
);
1772 emit_insn (targetm
.gen_call_value (valreg
,
1773 gen_rtx_MEM (FUNCTION_MODE
, function
),
1774 const0_rtx
, NULL_RTX
, const0_rtx
));
1776 emit_move_insn (adjust_address (result
, GET_MODE (valreg
), 0), valreg
);
1781 /* Find the CALL insn we just emitted, and attach the register usage
1783 call_insn
= last_call_insn ();
1784 add_function_usage_to (call_insn
, call_fusage
);
1786 /* Restore the stack. */
1787 if (targetm
.have_save_stack_nonlocal ())
1788 emit_stack_restore (SAVE_NONLOCAL
, old_stack_level
);
1790 emit_stack_restore (SAVE_BLOCK
, old_stack_level
);
1791 fixup_args_size_notes (call_insn
, get_last_insn (), 0);
1795 /* Return the address of the result block. */
1796 result
= copy_addr_to_reg (XEXP (result
, 0));
1797 return convert_memory_address (ptr_mode
, result
);
1800 /* Perform an untyped return. */
1803 expand_builtin_return (rtx result
)
1805 int size
, align
, regno
;
1806 fixed_size_mode mode
;
1808 rtx_insn
*call_fusage
= 0;
1810 result
= convert_memory_address (Pmode
, result
);
1812 apply_result_size ();
1813 result
= gen_rtx_MEM (BLKmode
, result
);
1815 if (targetm
.have_untyped_return ())
1817 rtx vector
= result_vector (0, result
);
1818 emit_jump_insn (targetm
.gen_untyped_return (result
, vector
));
1823 /* Restore the return value and note that each value is used. */
1825 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
1826 if ((mode
= apply_result_mode
[regno
]) != VOIDmode
)
1828 align
= GET_MODE_ALIGNMENT (mode
) / BITS_PER_UNIT
;
1829 if (size
% align
!= 0)
1830 size
= CEIL (size
, align
) * align
;
1831 reg
= gen_rtx_REG (mode
, INCOMING_REGNO (regno
));
1832 emit_move_insn (reg
, adjust_address (result
, mode
, size
));
1834 push_to_sequence (call_fusage
);
1836 call_fusage
= get_insns ();
1838 size
+= GET_MODE_SIZE (mode
);
1841 /* Put the USE insns before the return. */
1842 emit_insn (call_fusage
);
1844 /* Return whatever values was restored by jumping directly to the end
1846 expand_naked_return ();
1849 /* Used by expand_builtin_classify_type and fold_builtin_classify_type. */
1851 static enum type_class
1852 type_to_class (tree type
)
1854 switch (TREE_CODE (type
))
1856 case VOID_TYPE
: return void_type_class
;
1857 case INTEGER_TYPE
: return integer_type_class
;
1858 case ENUMERAL_TYPE
: return enumeral_type_class
;
1859 case BOOLEAN_TYPE
: return boolean_type_class
;
1860 case POINTER_TYPE
: return pointer_type_class
;
1861 case REFERENCE_TYPE
: return reference_type_class
;
1862 case OFFSET_TYPE
: return offset_type_class
;
1863 case REAL_TYPE
: return real_type_class
;
1864 case COMPLEX_TYPE
: return complex_type_class
;
1865 case FUNCTION_TYPE
: return function_type_class
;
1866 case METHOD_TYPE
: return method_type_class
;
1867 case RECORD_TYPE
: return record_type_class
;
1869 case QUAL_UNION_TYPE
: return union_type_class
;
1870 case ARRAY_TYPE
: return (TYPE_STRING_FLAG (type
)
1871 ? string_type_class
: array_type_class
);
1872 case LANG_TYPE
: return lang_type_class
;
1873 case OPAQUE_TYPE
: return opaque_type_class
;
1874 default: return no_type_class
;
1878 /* Expand a call EXP to __builtin_classify_type. */
1881 expand_builtin_classify_type (tree exp
)
1883 if (call_expr_nargs (exp
))
1884 return GEN_INT (type_to_class (TREE_TYPE (CALL_EXPR_ARG (exp
, 0))));
1885 return GEN_INT (no_type_class
);
1888 /* This helper macro, meant to be used in mathfn_built_in below, determines
1889 which among a set of builtin math functions is appropriate for a given type
1890 mode. The `F' (float) and `L' (long double) are automatically generated
1891 from the 'double' case. If a function supports the _Float<N> and _Float<N>X
1892 types, there are additional types that are considered with 'F32', 'F64',
1893 'F128', etc. suffixes. */
1894 #define CASE_MATHFN(MATHFN) \
1895 CASE_CFN_##MATHFN: \
1896 fcode = BUILT_IN_##MATHFN; fcodef = BUILT_IN_##MATHFN##F ; \
1897 fcodel = BUILT_IN_##MATHFN##L ; break;
1898 /* Similar to the above, but also add support for the _Float<N> and _Float<N>X
1900 #define CASE_MATHFN_FLOATN(MATHFN) \
1901 CASE_CFN_##MATHFN: \
1902 fcode = BUILT_IN_##MATHFN; fcodef = BUILT_IN_##MATHFN##F ; \
1903 fcodel = BUILT_IN_##MATHFN##L ; fcodef16 = BUILT_IN_##MATHFN##F16 ; \
1904 fcodef32 = BUILT_IN_##MATHFN##F32; fcodef64 = BUILT_IN_##MATHFN##F64 ; \
1905 fcodef128 = BUILT_IN_##MATHFN##F128 ; fcodef32x = BUILT_IN_##MATHFN##F32X ; \
1906 fcodef64x = BUILT_IN_##MATHFN##F64X ; fcodef128x = BUILT_IN_##MATHFN##F128X ;\
1908 /* Similar to above, but appends _R after any F/L suffix. */
1909 #define CASE_MATHFN_REENT(MATHFN) \
1910 case CFN_BUILT_IN_##MATHFN##_R: \
1911 case CFN_BUILT_IN_##MATHFN##F_R: \
1912 case CFN_BUILT_IN_##MATHFN##L_R: \
1913 fcode = BUILT_IN_##MATHFN##_R; fcodef = BUILT_IN_##MATHFN##F_R ; \
1914 fcodel = BUILT_IN_##MATHFN##L_R ; break;
1916 /* Return a function equivalent to FN but operating on floating-point
1917 values of type TYPE, or END_BUILTINS if no such function exists.
1918 This is purely an operation on function codes; it does not guarantee
1919 that the target actually has an implementation of the function. */
1921 static built_in_function
1922 mathfn_built_in_2 (tree type
, combined_fn fn
)
1925 built_in_function fcode
, fcodef
, fcodel
;
1926 built_in_function fcodef16
= END_BUILTINS
;
1927 built_in_function fcodef32
= END_BUILTINS
;
1928 built_in_function fcodef64
= END_BUILTINS
;
1929 built_in_function fcodef128
= END_BUILTINS
;
1930 built_in_function fcodef32x
= END_BUILTINS
;
1931 built_in_function fcodef64x
= END_BUILTINS
;
1932 built_in_function fcodef128x
= END_BUILTINS
;
1936 #define SEQ_OF_CASE_MATHFN \
1937 CASE_MATHFN (ACOS) \
1938 CASE_MATHFN (ACOSH) \
1939 CASE_MATHFN (ASIN) \
1940 CASE_MATHFN (ASINH) \
1941 CASE_MATHFN (ATAN) \
1942 CASE_MATHFN (ATAN2) \
1943 CASE_MATHFN (ATANH) \
1944 CASE_MATHFN (CBRT) \
1945 CASE_MATHFN_FLOATN (CEIL) \
1946 CASE_MATHFN (CEXPI) \
1947 CASE_MATHFN_FLOATN (COPYSIGN) \
1949 CASE_MATHFN (COSH) \
1950 CASE_MATHFN (DREM) \
1952 CASE_MATHFN (ERFC) \
1954 CASE_MATHFN (EXP10) \
1955 CASE_MATHFN (EXP2) \
1956 CASE_MATHFN (EXPM1) \
1957 CASE_MATHFN (FABS) \
1958 CASE_MATHFN (FDIM) \
1959 CASE_MATHFN_FLOATN (FLOOR) \
1960 CASE_MATHFN_FLOATN (FMA) \
1961 CASE_MATHFN_FLOATN (FMAX) \
1962 CASE_MATHFN_FLOATN (FMIN) \
1963 CASE_MATHFN (FMOD) \
1964 CASE_MATHFN (FREXP) \
1965 CASE_MATHFN (GAMMA) \
1966 CASE_MATHFN_REENT (GAMMA) /* GAMMA_R */ \
1967 CASE_MATHFN (HUGE_VAL) \
1968 CASE_MATHFN (HYPOT) \
1969 CASE_MATHFN (ILOGB) \
1970 CASE_MATHFN (ICEIL) \
1971 CASE_MATHFN (IFLOOR) \
1973 CASE_MATHFN (IRINT) \
1974 CASE_MATHFN (IROUND) \
1975 CASE_MATHFN (ISINF) \
1979 CASE_MATHFN (LCEIL) \
1980 CASE_MATHFN (LDEXP) \
1981 CASE_MATHFN (LFLOOR) \
1982 CASE_MATHFN (LGAMMA) \
1983 CASE_MATHFN_REENT (LGAMMA) /* LGAMMA_R */ \
1984 CASE_MATHFN (LLCEIL) \
1985 CASE_MATHFN (LLFLOOR) \
1986 CASE_MATHFN (LLRINT) \
1987 CASE_MATHFN (LLROUND) \
1989 CASE_MATHFN (LOG10) \
1990 CASE_MATHFN (LOG1P) \
1991 CASE_MATHFN (LOG2) \
1992 CASE_MATHFN (LOGB) \
1993 CASE_MATHFN (LRINT) \
1994 CASE_MATHFN (LROUND) \
1995 CASE_MATHFN (MODF) \
1997 CASE_MATHFN (NANS) \
1998 CASE_MATHFN_FLOATN (NEARBYINT) \
1999 CASE_MATHFN (NEXTAFTER) \
2000 CASE_MATHFN (NEXTTOWARD) \
2002 CASE_MATHFN (POWI) \
2003 CASE_MATHFN (POW10) \
2004 CASE_MATHFN (REMAINDER) \
2005 CASE_MATHFN (REMQUO) \
2006 CASE_MATHFN_FLOATN (RINT) \
2007 CASE_MATHFN_FLOATN (ROUND) \
2008 CASE_MATHFN_FLOATN (ROUNDEVEN) \
2009 CASE_MATHFN (SCALB) \
2010 CASE_MATHFN (SCALBLN) \
2011 CASE_MATHFN (SCALBN) \
2012 CASE_MATHFN (SIGNBIT) \
2013 CASE_MATHFN (SIGNIFICAND) \
2015 CASE_MATHFN (SINCOS) \
2016 CASE_MATHFN (SINH) \
2017 CASE_MATHFN_FLOATN (SQRT) \
2019 CASE_MATHFN (TANH) \
2020 CASE_MATHFN (TGAMMA) \
2021 CASE_MATHFN_FLOATN (TRUNC) \
2029 return END_BUILTINS
;
2032 mtype
= TYPE_MAIN_VARIANT (type
);
2033 if (mtype
== double_type_node
)
2035 else if (mtype
== float_type_node
)
2037 else if (mtype
== long_double_type_node
)
2039 else if (mtype
== float16_type_node
)
2041 else if (mtype
== float32_type_node
)
2043 else if (mtype
== float64_type_node
)
2045 else if (mtype
== float128_type_node
)
2047 else if (mtype
== float32x_type_node
)
2049 else if (mtype
== float64x_type_node
)
2051 else if (mtype
== float128x_type_node
)
2054 return END_BUILTINS
;
2058 #undef CASE_MATHFN_FLOATN
2059 #undef CASE_MATHFN_REENT
2061 /* Return mathematic function equivalent to FN but operating directly on TYPE,
2062 if available. If IMPLICIT_P is true use the implicit builtin declaration,
2063 otherwise use the explicit declaration. If we can't do the conversion,
2067 mathfn_built_in_1 (tree type
, combined_fn fn
, bool implicit_p
)
2069 built_in_function fcode2
= mathfn_built_in_2 (type
, fn
);
2070 if (fcode2
== END_BUILTINS
)
2073 if (implicit_p
&& !builtin_decl_implicit_p (fcode2
))
2076 return builtin_decl_explicit (fcode2
);
2079 /* Like mathfn_built_in_1, but always use the implicit array. */
2082 mathfn_built_in (tree type
, combined_fn fn
)
2084 return mathfn_built_in_1 (type
, fn
, /*implicit=*/ 1);
2087 /* Like mathfn_built_in_1, but take a built_in_function and
2088 always use the implicit array. */
2091 mathfn_built_in (tree type
, enum built_in_function fn
)
2093 return mathfn_built_in_1 (type
, as_combined_fn (fn
), /*implicit=*/ 1);
2096 /* Return the type associated with a built in function, i.e., the one
2097 to be passed to mathfn_built_in to get the type-specific
2101 mathfn_built_in_type (combined_fn fn
)
2103 #define CASE_MATHFN(MATHFN) \
2104 case CFN_BUILT_IN_##MATHFN: \
2105 return double_type_node; \
2106 case CFN_BUILT_IN_##MATHFN##F: \
2107 return float_type_node; \
2108 case CFN_BUILT_IN_##MATHFN##L: \
2109 return long_double_type_node;
2111 #define CASE_MATHFN_FLOATN(MATHFN) \
2112 CASE_MATHFN(MATHFN) \
2113 case CFN_BUILT_IN_##MATHFN##F16: \
2114 return float16_type_node; \
2115 case CFN_BUILT_IN_##MATHFN##F32: \
2116 return float32_type_node; \
2117 case CFN_BUILT_IN_##MATHFN##F64: \
2118 return float64_type_node; \
2119 case CFN_BUILT_IN_##MATHFN##F128: \
2120 return float128_type_node; \
2121 case CFN_BUILT_IN_##MATHFN##F32X: \
2122 return float32x_type_node; \
2123 case CFN_BUILT_IN_##MATHFN##F64X: \
2124 return float64x_type_node; \
2125 case CFN_BUILT_IN_##MATHFN##F128X: \
2126 return float128x_type_node;
2128 /* Similar to above, but appends _R after any F/L suffix. */
2129 #define CASE_MATHFN_REENT(MATHFN) \
2130 case CFN_BUILT_IN_##MATHFN##_R: \
2131 return double_type_node; \
2132 case CFN_BUILT_IN_##MATHFN##F_R: \
2133 return float_type_node; \
2134 case CFN_BUILT_IN_##MATHFN##L_R: \
2135 return long_double_type_node;
2146 #undef CASE_MATHFN_FLOATN
2147 #undef CASE_MATHFN_REENT
2148 #undef SEQ_OF_CASE_MATHFN
2151 /* Check whether there is an internal function associated with function FN
2152 and return type RETURN_TYPE. Return the function if so, otherwise return
2155 Note that this function only tests whether the function is defined in
2156 internals.def, not whether it is actually available on the target. */
2159 associated_internal_fn (built_in_function fn
, tree return_type
)
2163 #define DEF_INTERNAL_FLT_FN(NAME, FLAGS, OPTAB, TYPE) \
2164 CASE_FLT_FN (BUILT_IN_##NAME): return IFN_##NAME;
2165 #define DEF_INTERNAL_FLT_FLOATN_FN(NAME, FLAGS, OPTAB, TYPE) \
2166 CASE_FLT_FN (BUILT_IN_##NAME): return IFN_##NAME; \
2167 CASE_FLT_FN_FLOATN_NX (BUILT_IN_##NAME): return IFN_##NAME;
2168 #define DEF_INTERNAL_INT_FN(NAME, FLAGS, OPTAB, TYPE) \
2169 CASE_INT_FN (BUILT_IN_##NAME): return IFN_##NAME;
2170 #include "internal-fn.def"
2172 CASE_FLT_FN (BUILT_IN_POW10
):
2175 CASE_FLT_FN (BUILT_IN_DREM
):
2176 return IFN_REMAINDER
;
2178 CASE_FLT_FN (BUILT_IN_SCALBN
):
2179 CASE_FLT_FN (BUILT_IN_SCALBLN
):
2180 if (REAL_MODE_FORMAT (TYPE_MODE (return_type
))->b
== 2)
2189 /* If BUILT_IN_NORMAL function FNDECL has an associated internal function,
2190 return its code, otherwise return IFN_LAST. Note that this function
2191 only tests whether the function is defined in internals.def, not whether
2192 it is actually available on the target. */
2195 associated_internal_fn (tree fndecl
)
2197 gcc_checking_assert (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_NORMAL
);
2198 return associated_internal_fn (DECL_FUNCTION_CODE (fndecl
),
2199 TREE_TYPE (TREE_TYPE (fndecl
)));
2202 /* Check whether there is an internal function associated with function CFN
2203 and return type RETURN_TYPE. Return the function if so, otherwise return
2206 Note that this function only tests whether the function is defined in
2207 internals.def, not whether it is actually available on the target. */
2210 associated_internal_fn (combined_fn cfn
, tree return_type
)
2212 if (internal_fn_p (cfn
))
2213 return as_internal_fn (cfn
);
2214 return associated_internal_fn (as_builtin_fn (cfn
), return_type
);
2217 /* If CALL is a call to a BUILT_IN_NORMAL function that could be replaced
2218 on the current target by a call to an internal function, return the
2219 code of that internal function, otherwise return IFN_LAST. The caller
2220 is responsible for ensuring that any side-effects of the built-in
2221 call are dealt with correctly. E.g. if CALL sets errno, the caller
2222 must decide that the errno result isn't needed or make it available
2223 in some other way. */
2226 replacement_internal_fn (gcall
*call
)
2228 if (gimple_call_builtin_p (call
, BUILT_IN_NORMAL
))
2230 internal_fn ifn
= associated_internal_fn (gimple_call_fndecl (call
));
2231 if (ifn
!= IFN_LAST
)
2233 tree_pair types
= direct_internal_fn_types (ifn
, call
);
2234 optimization_type opt_type
= bb_optimization_type (gimple_bb (call
));
2235 if (direct_internal_fn_supported_p (ifn
, types
, opt_type
))
2242 /* Expand a call to the builtin trinary math functions (fma).
2243 Return NULL_RTX if a normal call should be emitted rather than expanding the
2244 function in-line. EXP is the expression that is a call to the builtin
2245 function; if convenient, the result should be placed in TARGET.
2246 SUBTARGET may be used as the target for computing one of EXP's
2250 expand_builtin_mathfn_ternary (tree exp
, rtx target
, rtx subtarget
)
2252 optab builtin_optab
;
2253 rtx op0
, op1
, op2
, result
;
2255 tree fndecl
= get_callee_fndecl (exp
);
2256 tree arg0
, arg1
, arg2
;
2259 if (!validate_arglist (exp
, REAL_TYPE
, REAL_TYPE
, REAL_TYPE
, VOID_TYPE
))
2262 arg0
= CALL_EXPR_ARG (exp
, 0);
2263 arg1
= CALL_EXPR_ARG (exp
, 1);
2264 arg2
= CALL_EXPR_ARG (exp
, 2);
2266 switch (DECL_FUNCTION_CODE (fndecl
))
2268 CASE_FLT_FN (BUILT_IN_FMA
):
2269 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA
):
2270 builtin_optab
= fma_optab
; break;
2275 /* Make a suitable register to place result in. */
2276 mode
= TYPE_MODE (TREE_TYPE (exp
));
2278 /* Before working hard, check whether the instruction is available. */
2279 if (optab_handler (builtin_optab
, mode
) == CODE_FOR_nothing
)
2282 result
= gen_reg_rtx (mode
);
2284 /* Always stabilize the argument list. */
2285 CALL_EXPR_ARG (exp
, 0) = arg0
= builtin_save_expr (arg0
);
2286 CALL_EXPR_ARG (exp
, 1) = arg1
= builtin_save_expr (arg1
);
2287 CALL_EXPR_ARG (exp
, 2) = arg2
= builtin_save_expr (arg2
);
2289 op0
= expand_expr (arg0
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
2290 op1
= expand_normal (arg1
);
2291 op2
= expand_normal (arg2
);
2295 /* Compute into RESULT.
2296 Set RESULT to wherever the result comes back. */
2297 result
= expand_ternary_op (mode
, builtin_optab
, op0
, op1
, op2
,
2300 /* If we were unable to expand via the builtin, stop the sequence
2301 (without outputting the insns) and call to the library function
2302 with the stabilized argument list. */
2306 return expand_call (exp
, target
, target
== const0_rtx
);
2309 /* Output the entire sequence. */
2310 insns
= get_insns ();
2317 /* Expand a call to the builtin sin and cos math functions.
2318 Return NULL_RTX if a normal call should be emitted rather than expanding the
2319 function in-line. EXP is the expression that is a call to the builtin
2320 function; if convenient, the result should be placed in TARGET.
2321 SUBTARGET may be used as the target for computing one of EXP's
2325 expand_builtin_mathfn_3 (tree exp
, rtx target
, rtx subtarget
)
2327 optab builtin_optab
;
2330 tree fndecl
= get_callee_fndecl (exp
);
2334 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
2337 arg
= CALL_EXPR_ARG (exp
, 0);
2339 switch (DECL_FUNCTION_CODE (fndecl
))
2341 CASE_FLT_FN (BUILT_IN_SIN
):
2342 CASE_FLT_FN (BUILT_IN_COS
):
2343 builtin_optab
= sincos_optab
; break;
2348 /* Make a suitable register to place result in. */
2349 mode
= TYPE_MODE (TREE_TYPE (exp
));
2351 /* Check if sincos insn is available, otherwise fallback
2352 to sin or cos insn. */
2353 if (optab_handler (builtin_optab
, mode
) == CODE_FOR_nothing
)
2354 switch (DECL_FUNCTION_CODE (fndecl
))
2356 CASE_FLT_FN (BUILT_IN_SIN
):
2357 builtin_optab
= sin_optab
; break;
2358 CASE_FLT_FN (BUILT_IN_COS
):
2359 builtin_optab
= cos_optab
; break;
2364 /* Before working hard, check whether the instruction is available. */
2365 if (optab_handler (builtin_optab
, mode
) != CODE_FOR_nothing
)
2367 rtx result
= gen_reg_rtx (mode
);
2369 /* Wrap the computation of the argument in a SAVE_EXPR, as we may
2370 need to expand the argument again. This way, we will not perform
2371 side-effects more the once. */
2372 CALL_EXPR_ARG (exp
, 0) = arg
= builtin_save_expr (arg
);
2374 op0
= expand_expr (arg
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
2378 /* Compute into RESULT.
2379 Set RESULT to wherever the result comes back. */
2380 if (builtin_optab
== sincos_optab
)
2384 switch (DECL_FUNCTION_CODE (fndecl
))
2386 CASE_FLT_FN (BUILT_IN_SIN
):
2387 ok
= expand_twoval_unop (builtin_optab
, op0
, 0, result
, 0);
2389 CASE_FLT_FN (BUILT_IN_COS
):
2390 ok
= expand_twoval_unop (builtin_optab
, op0
, result
, 0, 0);
2398 result
= expand_unop (mode
, builtin_optab
, op0
, result
, 0);
2402 /* Output the entire sequence. */
2403 insns
= get_insns ();
2409 /* If we were unable to expand via the builtin, stop the sequence
2410 (without outputting the insns) and call to the library function
2411 with the stabilized argument list. */
2415 return expand_call (exp
, target
, target
== const0_rtx
);
2418 /* Given an interclass math builtin decl FNDECL and it's argument ARG
2419 return an RTL instruction code that implements the functionality.
2420 If that isn't possible or available return CODE_FOR_nothing. */
2422 static enum insn_code
2423 interclass_mathfn_icode (tree arg
, tree fndecl
)
2425 bool errno_set
= false;
2426 optab builtin_optab
= unknown_optab
;
2429 switch (DECL_FUNCTION_CODE (fndecl
))
2431 CASE_FLT_FN (BUILT_IN_ILOGB
):
2432 errno_set
= true; builtin_optab
= ilogb_optab
; break;
2433 CASE_FLT_FN (BUILT_IN_ISINF
):
2434 builtin_optab
= isinf_optab
; break;
2435 case BUILT_IN_ISNORMAL
:
2436 case BUILT_IN_ISFINITE
:
2437 CASE_FLT_FN (BUILT_IN_FINITE
):
2438 case BUILT_IN_FINITED32
:
2439 case BUILT_IN_FINITED64
:
2440 case BUILT_IN_FINITED128
:
2441 case BUILT_IN_ISINFD32
:
2442 case BUILT_IN_ISINFD64
:
2443 case BUILT_IN_ISINFD128
:
2444 /* These builtins have no optabs (yet). */
2450 /* There's no easy way to detect the case we need to set EDOM. */
2451 if (flag_errno_math
&& errno_set
)
2452 return CODE_FOR_nothing
;
2454 /* Optab mode depends on the mode of the input argument. */
2455 mode
= TYPE_MODE (TREE_TYPE (arg
));
2458 return optab_handler (builtin_optab
, mode
);
2459 return CODE_FOR_nothing
;
2462 /* Expand a call to one of the builtin math functions that operate on
2463 floating point argument and output an integer result (ilogb, isinf,
2465 Return 0 if a normal call should be emitted rather than expanding the
2466 function in-line. EXP is the expression that is a call to the builtin
2467 function; if convenient, the result should be placed in TARGET. */
2470 expand_builtin_interclass_mathfn (tree exp
, rtx target
)
2472 enum insn_code icode
= CODE_FOR_nothing
;
2474 tree fndecl
= get_callee_fndecl (exp
);
2478 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
2481 arg
= CALL_EXPR_ARG (exp
, 0);
2482 icode
= interclass_mathfn_icode (arg
, fndecl
);
2483 mode
= TYPE_MODE (TREE_TYPE (arg
));
2485 if (icode
!= CODE_FOR_nothing
)
2487 class expand_operand ops
[1];
2488 rtx_insn
*last
= get_last_insn ();
2489 tree orig_arg
= arg
;
2491 /* Wrap the computation of the argument in a SAVE_EXPR, as we may
2492 need to expand the argument again. This way, we will not perform
2493 side-effects more the once. */
2494 CALL_EXPR_ARG (exp
, 0) = arg
= builtin_save_expr (arg
);
2496 op0
= expand_expr (arg
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
2498 if (mode
!= GET_MODE (op0
))
2499 op0
= convert_to_mode (mode
, op0
, 0);
2501 create_output_operand (&ops
[0], target
, TYPE_MODE (TREE_TYPE (exp
)));
2502 if (maybe_legitimize_operands (icode
, 0, 1, ops
)
2503 && maybe_emit_unop_insn (icode
, ops
[0].value
, op0
, UNKNOWN
))
2504 return ops
[0].value
;
2506 delete_insns_since (last
);
2507 CALL_EXPR_ARG (exp
, 0) = orig_arg
;
2513 /* Expand a call to the builtin sincos math function.
2514 Return NULL_RTX if a normal call should be emitted rather than expanding the
2515 function in-line. EXP is the expression that is a call to the builtin
2519 expand_builtin_sincos (tree exp
)
2521 rtx op0
, op1
, op2
, target1
, target2
;
2523 tree arg
, sinp
, cosp
;
2525 location_t loc
= EXPR_LOCATION (exp
);
2526 tree alias_type
, alias_off
;
2528 if (!validate_arglist (exp
, REAL_TYPE
,
2529 POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
2532 arg
= CALL_EXPR_ARG (exp
, 0);
2533 sinp
= CALL_EXPR_ARG (exp
, 1);
2534 cosp
= CALL_EXPR_ARG (exp
, 2);
2536 /* Make a suitable register to place result in. */
2537 mode
= TYPE_MODE (TREE_TYPE (arg
));
2539 /* Check if sincos insn is available, otherwise emit the call. */
2540 if (optab_handler (sincos_optab
, mode
) == CODE_FOR_nothing
)
2543 target1
= gen_reg_rtx (mode
);
2544 target2
= gen_reg_rtx (mode
);
2546 op0
= expand_normal (arg
);
2547 alias_type
= build_pointer_type_for_mode (TREE_TYPE (arg
), ptr_mode
, true);
2548 alias_off
= build_int_cst (alias_type
, 0);
2549 op1
= expand_normal (fold_build2_loc (loc
, MEM_REF
, TREE_TYPE (arg
),
2551 op2
= expand_normal (fold_build2_loc (loc
, MEM_REF
, TREE_TYPE (arg
),
2554 /* Compute into target1 and target2.
2555 Set TARGET to wherever the result comes back. */
2556 result
= expand_twoval_unop (sincos_optab
, op0
, target2
, target1
, 0);
2557 gcc_assert (result
);
2559 /* Move target1 and target2 to the memory locations indicated
2561 emit_move_insn (op1
, target1
);
2562 emit_move_insn (op2
, target2
);
2567 /* Expand call EXP to the fegetround builtin (from C99 fenv.h), returning the
2568 result and setting it in TARGET. Otherwise return NULL_RTX on failure. */
2570 expand_builtin_fegetround (tree exp
, rtx target
, machine_mode target_mode
)
2572 if (!validate_arglist (exp
, VOID_TYPE
))
2575 insn_code icode
= direct_optab_handler (fegetround_optab
, SImode
);
2576 if (icode
== CODE_FOR_nothing
)
2580 || GET_MODE (target
) != target_mode
2581 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, target_mode
))
2582 target
= gen_reg_rtx (target_mode
);
2584 rtx pat
= GEN_FCN (icode
) (target
);
2592 /* Expand call EXP to either feclearexcept or feraiseexcept builtins (from C99
2593 fenv.h), returning the result and setting it in TARGET. Otherwise return
2594 NULL_RTX on failure. */
2596 expand_builtin_feclear_feraise_except (tree exp
, rtx target
,
2597 machine_mode target_mode
, optab op_optab
)
2599 if (!validate_arglist (exp
, INTEGER_TYPE
, VOID_TYPE
))
2601 rtx op0
= expand_normal (CALL_EXPR_ARG (exp
, 0));
2603 insn_code icode
= direct_optab_handler (op_optab
, SImode
);
2604 if (icode
== CODE_FOR_nothing
)
2607 if (!(*insn_data
[icode
].operand
[1].predicate
) (op0
, GET_MODE (op0
)))
2611 || GET_MODE (target
) != target_mode
2612 || !(*insn_data
[icode
].operand
[0].predicate
) (target
, target_mode
))
2613 target
= gen_reg_rtx (target_mode
);
2615 rtx pat
= GEN_FCN (icode
) (target
, op0
);
2623 /* Expand a call to the internal cexpi builtin to the sincos math function.
2624 EXP is the expression that is a call to the builtin function; if convenient,
2625 the result should be placed in TARGET. */
2628 expand_builtin_cexpi (tree exp
, rtx target
)
2630 tree fndecl
= get_callee_fndecl (exp
);
2634 location_t loc
= EXPR_LOCATION (exp
);
2636 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
2639 arg
= CALL_EXPR_ARG (exp
, 0);
2640 type
= TREE_TYPE (arg
);
2641 mode
= TYPE_MODE (TREE_TYPE (arg
));
2643 /* Try expanding via a sincos optab, fall back to emitting a libcall
2644 to sincos or cexp. We are sure we have sincos or cexp because cexpi
2645 is only generated from sincos, cexp or if we have either of them. */
2646 if (optab_handler (sincos_optab
, mode
) != CODE_FOR_nothing
)
2648 op1
= gen_reg_rtx (mode
);
2649 op2
= gen_reg_rtx (mode
);
2651 op0
= expand_expr (arg
, NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
2653 /* Compute into op1 and op2. */
2654 expand_twoval_unop (sincos_optab
, op0
, op2
, op1
, 0);
2656 else if (targetm
.libc_has_function (function_sincos
, type
))
2658 tree call
, fn
= NULL_TREE
;
2662 if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPIF
)
2663 fn
= builtin_decl_explicit (BUILT_IN_SINCOSF
);
2664 else if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPI
)
2665 fn
= builtin_decl_explicit (BUILT_IN_SINCOS
);
2666 else if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPIL
)
2667 fn
= builtin_decl_explicit (BUILT_IN_SINCOSL
);
2671 op1
= assign_temp (TREE_TYPE (arg
), 1, 1);
2672 op2
= assign_temp (TREE_TYPE (arg
), 1, 1);
2673 op1a
= copy_addr_to_reg (XEXP (op1
, 0));
2674 op2a
= copy_addr_to_reg (XEXP (op2
, 0));
2675 top1
= make_tree (build_pointer_type (TREE_TYPE (arg
)), op1a
);
2676 top2
= make_tree (build_pointer_type (TREE_TYPE (arg
)), op2a
);
2678 /* Make sure not to fold the sincos call again. */
2679 call
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (fn
)), fn
);
2680 expand_normal (build_call_nary (TREE_TYPE (TREE_TYPE (fn
)),
2681 call
, 3, arg
, top1
, top2
));
2685 tree call
, fn
= NULL_TREE
, narg
;
2686 tree ctype
= build_complex_type (type
);
2688 if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPIF
)
2689 fn
= builtin_decl_explicit (BUILT_IN_CEXPF
);
2690 else if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPI
)
2691 fn
= builtin_decl_explicit (BUILT_IN_CEXP
);
2692 else if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPIL
)
2693 fn
= builtin_decl_explicit (BUILT_IN_CEXPL
);
2697 /* If we don't have a decl for cexp create one. This is the
2698 friendliest fallback if the user calls __builtin_cexpi
2699 without full target C99 function support. */
2700 if (fn
== NULL_TREE
)
2703 const char *name
= NULL
;
2705 if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPIF
)
2707 else if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPI
)
2709 else if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_CEXPIL
)
2712 fntype
= build_function_type_list (ctype
, ctype
, NULL_TREE
);
2713 fn
= build_fn_decl (name
, fntype
);
2716 narg
= fold_build2_loc (loc
, COMPLEX_EXPR
, ctype
,
2717 build_real (type
, dconst0
), arg
);
2719 /* Make sure not to fold the cexp call again. */
2720 call
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (fn
)), fn
);
2721 return expand_expr (build_call_nary (ctype
, call
, 1, narg
),
2722 target
, VOIDmode
, EXPAND_NORMAL
);
2725 /* Now build the proper return type. */
2726 return expand_expr (build2 (COMPLEX_EXPR
, build_complex_type (type
),
2727 make_tree (TREE_TYPE (arg
), op2
),
2728 make_tree (TREE_TYPE (arg
), op1
)),
2729 target
, VOIDmode
, EXPAND_NORMAL
);
2732 /* Conveniently construct a function call expression. FNDECL names the
2733 function to be called, N is the number of arguments, and the "..."
2734 parameters are the argument expressions. Unlike build_call_exr
2735 this doesn't fold the call, hence it will always return a CALL_EXPR. */
2738 build_call_nofold_loc (location_t loc
, tree fndecl
, int n
, ...)
2741 tree fntype
= TREE_TYPE (fndecl
);
2742 tree fn
= build1 (ADDR_EXPR
, build_pointer_type (fntype
), fndecl
);
2745 fn
= build_call_valist (TREE_TYPE (fntype
), fn
, n
, ap
);
2747 SET_EXPR_LOCATION (fn
, loc
);
2751 /* Expand the __builtin_issignaling builtin. This needs to handle
2752 all floating point formats that do support NaNs (for those that
2753 don't it just sets target to 0). */
2756 expand_builtin_issignaling (tree exp
, rtx target
)
2758 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
2761 tree arg
= CALL_EXPR_ARG (exp
, 0);
2762 scalar_float_mode fmode
= SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (arg
));
2763 const struct real_format
*fmt
= REAL_MODE_FORMAT (fmode
);
2765 /* Expand the argument yielding a RTX expression. */
2766 rtx temp
= expand_normal (arg
);
2768 /* If mode doesn't support NaN, always return 0.
2769 Don't use !HONOR_SNANS (fmode) here, so there is some possibility of
2770 __builtin_issignaling working without -fsignaling-nans. Especially
2771 when -fno-signaling-nans is the default.
2772 On the other side, MODE_HAS_NANS (fmode) is unnecessary, with
2773 -ffinite-math-only even __builtin_isnan or __builtin_fpclassify
2774 fold to 0 or non-NaN/Inf classification. */
2775 if (!HONOR_NANS (fmode
))
2777 emit_move_insn (target
, const0_rtx
);
2781 /* Check if the back end provides an insn that handles issignaling for the
2783 enum insn_code icode
= optab_handler (issignaling_optab
, fmode
);
2784 if (icode
!= CODE_FOR_nothing
)
2786 rtx_insn
*last
= get_last_insn ();
2787 rtx this_target
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp
)));
2788 if (maybe_emit_unop_insn (icode
, this_target
, temp
, UNKNOWN
))
2790 delete_insns_since (last
);
2793 if (DECIMAL_FLOAT_MODE_P (fmode
))
2795 scalar_int_mode imode
;
2797 switch (fmt
->ieee_bits
)
2801 imode
= int_mode_for_mode (fmode
).require ();
2802 temp
= gen_lowpart (imode
, temp
);
2805 imode
= int_mode_for_size (64, 1).require ();
2807 /* For decimal128, TImode support isn't always there and even when
2808 it is, working on the DImode high part is usually better. */
2811 if (rtx t
= simplify_gen_subreg (imode
, temp
, fmode
,
2812 subreg_highpart_offset (imode
,
2817 scalar_int_mode imode2
;
2818 if (int_mode_for_mode (fmode
).exists (&imode2
))
2820 rtx temp2
= gen_lowpart (imode2
, temp
);
2821 poly_uint64 off
= subreg_highpart_offset (imode
, imode2
);
2822 if (rtx t
= simplify_gen_subreg (imode
, temp2
,
2829 rtx mem
= assign_stack_temp (fmode
, GET_MODE_SIZE (fmode
));
2830 emit_move_insn (mem
, temp
);
2837 = subreg_highpart_offset (imode
, GET_MODE (temp
));
2838 hi
= adjust_address (temp
, imode
, offset
);
2845 /* In all of decimal{32,64,128}, there is MSB sign bit and sNaN
2846 have 6 bits below it all set. */
2848 = GEN_INT (HOST_WIDE_INT_C (0x3f) << (GET_MODE_BITSIZE (imode
) - 7));
2849 temp
= expand_binop (imode
, and_optab
, temp
, val
,
2850 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2851 temp
= emit_store_flag_force (target
, EQ
, temp
, val
, imode
, 1, 1);
2855 /* Only PDP11 has these defined differently but doesn't support NaNs. */
2856 gcc_assert (FLOAT_WORDS_BIG_ENDIAN
== WORDS_BIG_ENDIAN
);
2857 gcc_assert (fmt
->signbit_ro
> 0 && fmt
->b
== 2);
2858 gcc_assert (MODE_COMPOSITE_P (fmode
)
2859 || (fmt
->pnan
== fmt
->p
2860 && fmt
->signbit_ro
== fmt
->signbit_rw
));
2864 case 106: /* IBM double double */
2865 /* For IBM double double, recurse on the most significant double. */
2866 gcc_assert (MODE_COMPOSITE_P (fmode
));
2867 temp
= convert_modes (DFmode
, fmode
, temp
, 0);
2869 fmt
= REAL_MODE_FORMAT (DFmode
);
2871 case 8: /* bfloat */
2872 case 11: /* IEEE half */
2873 case 24: /* IEEE single */
2874 case 53: /* IEEE double or Intel extended with rounding to double */
2875 if (fmt
->p
== 53 && fmt
->signbit_ro
== 79)
2878 scalar_int_mode imode
= int_mode_for_mode (fmode
).require ();
2879 temp
= gen_lowpart (imode
, temp
);
2880 rtx val
= GEN_INT ((HOST_WIDE_INT_M1U
<< (fmt
->p
- 2))
2881 & ~(HOST_WIDE_INT_M1U
<< fmt
->signbit_ro
));
2882 if (fmt
->qnan_msb_set
)
2884 rtx mask
= GEN_INT (~(HOST_WIDE_INT_M1U
<< fmt
->signbit_ro
));
2885 rtx bit
= GEN_INT (HOST_WIDE_INT_1U
<< (fmt
->p
- 2));
2886 /* For non-MIPS/PA IEEE single/double/half or bfloat, expand to:
2887 ((temp ^ bit) & mask) > val. */
2888 temp
= expand_binop (imode
, xor_optab
, temp
, bit
,
2889 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2890 temp
= expand_binop (imode
, and_optab
, temp
, mask
,
2891 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2892 temp
= emit_store_flag_force (target
, GTU
, temp
, val
, imode
,
2897 /* For MIPS/PA IEEE single/double, expand to:
2898 (temp & val) == val. */
2899 temp
= expand_binop (imode
, and_optab
, temp
, val
,
2900 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2901 temp
= emit_store_flag_force (target
, EQ
, temp
, val
, imode
,
2906 case 113: /* IEEE quad */
2908 rtx hi
= NULL_RTX
, lo
= NULL_RTX
;
2909 scalar_int_mode imode
= int_mode_for_size (64, 1).require ();
2910 /* For IEEE quad, TImode support isn't always there and even when
2911 it is, working on DImode parts is usually better. */
2914 hi
= simplify_gen_subreg (imode
, temp
, fmode
,
2915 subreg_highpart_offset (imode
, fmode
));
2916 lo
= simplify_gen_subreg (imode
, temp
, fmode
,
2917 subreg_lowpart_offset (imode
, fmode
));
2920 scalar_int_mode imode2
;
2921 if (int_mode_for_mode (fmode
).exists (&imode2
))
2923 rtx temp2
= gen_lowpart (imode2
, temp
);
2924 hi
= simplify_gen_subreg (imode
, temp2
, imode2
,
2925 subreg_highpart_offset (imode
,
2927 lo
= simplify_gen_subreg (imode
, temp2
, imode2
,
2928 subreg_lowpart_offset (imode
,
2934 rtx mem
= assign_stack_temp (fmode
, GET_MODE_SIZE (fmode
));
2935 emit_move_insn (mem
, temp
);
2942 = subreg_highpart_offset (imode
, GET_MODE (temp
));
2943 hi
= adjust_address (temp
, imode
, offset
);
2944 offset
= subreg_lowpart_offset (imode
, GET_MODE (temp
));
2945 lo
= adjust_address (temp
, imode
, offset
);
2947 rtx val
= GEN_INT ((HOST_WIDE_INT_M1U
<< (fmt
->p
- 2 - 64))
2948 & ~(HOST_WIDE_INT_M1U
<< (fmt
->signbit_ro
- 64)));
2949 if (fmt
->qnan_msb_set
)
2951 rtx mask
= GEN_INT (~(HOST_WIDE_INT_M1U
<< (fmt
->signbit_ro
2953 rtx bit
= GEN_INT (HOST_WIDE_INT_1U
<< (fmt
->p
- 2 - 64));
2954 /* For non-MIPS/PA IEEE quad, expand to:
2955 (((hi ^ bit) | ((lo | -lo) >> 63)) & mask) > val. */
2956 rtx nlo
= expand_unop (imode
, neg_optab
, lo
, NULL_RTX
, 0);
2957 lo
= expand_binop (imode
, ior_optab
, lo
, nlo
,
2958 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2959 lo
= expand_shift (RSHIFT_EXPR
, imode
, lo
, 63, NULL_RTX
, 1);
2960 temp
= expand_binop (imode
, xor_optab
, hi
, bit
,
2961 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2962 temp
= expand_binop (imode
, ior_optab
, temp
, lo
,
2963 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2964 temp
= expand_binop (imode
, and_optab
, temp
, mask
,
2965 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2966 temp
= emit_store_flag_force (target
, GTU
, temp
, val
, imode
,
2971 /* For MIPS/PA IEEE quad, expand to:
2972 (hi & val) == val. */
2973 temp
= expand_binop (imode
, and_optab
, hi
, val
,
2974 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
2975 temp
= emit_store_flag_force (target
, EQ
, temp
, val
, imode
,
2980 case 64: /* Intel or Motorola extended */
2984 scalar_int_mode imode
= int_mode_for_size (32, 1).require ();
2985 scalar_int_mode iemode
= int_mode_for_size (16, 1).require ();
2988 rtx mem
= assign_stack_temp (fmode
, GET_MODE_SIZE (fmode
));
2989 emit_move_insn (mem
, temp
);
2992 if (fmt
->signbit_ro
== 95)
2994 /* Motorola, always big endian, with 16-bit gap in between
2995 16-bit sign+exponent and 64-bit mantissa. */
2996 ex
= adjust_address (temp
, iemode
, 0);
2997 hi
= adjust_address (temp
, imode
, 4);
2998 lo
= adjust_address (temp
, imode
, 8);
3000 else if (!WORDS_BIG_ENDIAN
)
3002 /* Intel little endian, 64-bit mantissa followed by 16-bit
3003 sign+exponent and then either 16 or 48 bits of gap. */
3004 ex
= adjust_address (temp
, iemode
, 8);
3005 hi
= adjust_address (temp
, imode
, 4);
3006 lo
= adjust_address (temp
, imode
, 0);
3010 /* Big endian Itanium. */
3011 ex
= adjust_address (temp
, iemode
, 0);
3012 hi
= adjust_address (temp
, imode
, 2);
3013 lo
= adjust_address (temp
, imode
, 6);
3015 rtx val
= GEN_INT (HOST_WIDE_INT_M1U
<< 30);
3016 gcc_assert (fmt
->qnan_msb_set
);
3017 rtx mask
= GEN_INT (0x7fff);
3018 rtx bit
= GEN_INT (HOST_WIDE_INT_1U
<< 30);
3019 /* For Intel/Motorola extended format, expand to:
3020 (ex & mask) == mask && ((hi ^ bit) | ((lo | -lo) >> 31)) > val. */
3021 rtx nlo
= expand_unop (imode
, neg_optab
, lo
, NULL_RTX
, 0);
3022 lo
= expand_binop (imode
, ior_optab
, lo
, nlo
,
3023 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3024 lo
= expand_shift (RSHIFT_EXPR
, imode
, lo
, 31, NULL_RTX
, 1);
3025 temp
= expand_binop (imode
, xor_optab
, hi
, bit
,
3026 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3027 temp
= expand_binop (imode
, ior_optab
, temp
, lo
,
3028 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3029 temp
= emit_store_flag_force (target
, GTU
, temp
, val
, imode
, 1, 1);
3030 ex
= expand_binop (iemode
, and_optab
, ex
, mask
,
3031 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3032 ex
= emit_store_flag_force (gen_reg_rtx (GET_MODE (temp
)), EQ
,
3033 ex
, mask
, iemode
, 1, 1);
3034 temp
= expand_binop (GET_MODE (temp
), and_optab
, temp
, ex
,
3035 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
3045 /* Expand a call to one of the builtin rounding functions gcc defines
3046 as an extension (lfloor and lceil). As these are gcc extensions we
3047 do not need to worry about setting errno to EDOM.
3048 If expanding via optab fails, lower expression to (int)(floor(x)).
3049 EXP is the expression that is a call to the builtin function;
3050 if convenient, the result should be placed in TARGET. */
3053 expand_builtin_int_roundingfn (tree exp
, rtx target
)
3055 convert_optab builtin_optab
;
3058 tree fndecl
= get_callee_fndecl (exp
);
3059 enum built_in_function fallback_fn
;
3060 tree fallback_fndecl
;
3064 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
3067 arg
= CALL_EXPR_ARG (exp
, 0);
3069 switch (DECL_FUNCTION_CODE (fndecl
))
3071 CASE_FLT_FN (BUILT_IN_ICEIL
):
3072 CASE_FLT_FN (BUILT_IN_LCEIL
):
3073 CASE_FLT_FN (BUILT_IN_LLCEIL
):
3074 builtin_optab
= lceil_optab
;
3075 fallback_fn
= BUILT_IN_CEIL
;
3078 CASE_FLT_FN (BUILT_IN_IFLOOR
):
3079 CASE_FLT_FN (BUILT_IN_LFLOOR
):
3080 CASE_FLT_FN (BUILT_IN_LLFLOOR
):
3081 builtin_optab
= lfloor_optab
;
3082 fallback_fn
= BUILT_IN_FLOOR
;
3089 /* Make a suitable register to place result in. */
3090 mode
= TYPE_MODE (TREE_TYPE (exp
));
3092 target
= gen_reg_rtx (mode
);
3094 /* Wrap the computation of the argument in a SAVE_EXPR, as we may
3095 need to expand the argument again. This way, we will not perform
3096 side-effects more the once. */
3097 CALL_EXPR_ARG (exp
, 0) = arg
= builtin_save_expr (arg
);
3099 op0
= expand_expr (arg
, NULL
, VOIDmode
, EXPAND_NORMAL
);
3103 /* Compute into TARGET. */
3104 if (expand_sfix_optab (target
, op0
, builtin_optab
))
3106 /* Output the entire sequence. */
3107 insns
= get_insns ();
3113 /* If we were unable to expand via the builtin, stop the sequence
3114 (without outputting the insns). */
3117 /* Fall back to floating point rounding optab. */
3118 fallback_fndecl
= mathfn_built_in (TREE_TYPE (arg
), fallback_fn
);
3120 /* For non-C99 targets we may end up without a fallback fndecl here
3121 if the user called __builtin_lfloor directly. In this case emit
3122 a call to the floor/ceil variants nevertheless. This should result
3123 in the best user experience for not full C99 targets. */
3124 if (fallback_fndecl
== NULL_TREE
)
3127 const char *name
= NULL
;
3129 switch (DECL_FUNCTION_CODE (fndecl
))
3131 case BUILT_IN_ICEIL
:
3132 case BUILT_IN_LCEIL
:
3133 case BUILT_IN_LLCEIL
:
3136 case BUILT_IN_ICEILF
:
3137 case BUILT_IN_LCEILF
:
3138 case BUILT_IN_LLCEILF
:
3141 case BUILT_IN_ICEILL
:
3142 case BUILT_IN_LCEILL
:
3143 case BUILT_IN_LLCEILL
:
3146 case BUILT_IN_IFLOOR
:
3147 case BUILT_IN_LFLOOR
:
3148 case BUILT_IN_LLFLOOR
:
3151 case BUILT_IN_IFLOORF
:
3152 case BUILT_IN_LFLOORF
:
3153 case BUILT_IN_LLFLOORF
:
3156 case BUILT_IN_IFLOORL
:
3157 case BUILT_IN_LFLOORL
:
3158 case BUILT_IN_LLFLOORL
:
3165 fntype
= build_function_type_list (TREE_TYPE (arg
),
3166 TREE_TYPE (arg
), NULL_TREE
);
3167 fallback_fndecl
= build_fn_decl (name
, fntype
);
3170 exp
= build_call_nofold_loc (EXPR_LOCATION (exp
), fallback_fndecl
, 1, arg
);
3172 tmp
= expand_normal (exp
);
3173 tmp
= maybe_emit_group_store (tmp
, TREE_TYPE (exp
));
3175 /* Truncate the result of floating point optab to integer
3176 via expand_fix (). */
3177 target
= gen_reg_rtx (mode
);
3178 expand_fix (target
, tmp
, 0);
3183 /* Expand a call to one of the builtin math functions doing integer
3185 Return 0 if a normal call should be emitted rather than expanding the
3186 function in-line. EXP is the expression that is a call to the builtin
3187 function; if convenient, the result should be placed in TARGET. */
3190 expand_builtin_int_roundingfn_2 (tree exp
, rtx target
)
3192 convert_optab builtin_optab
;
3195 tree fndecl
= get_callee_fndecl (exp
);
3198 enum built_in_function fallback_fn
= BUILT_IN_NONE
;
3200 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
3203 arg
= CALL_EXPR_ARG (exp
, 0);
3205 switch (DECL_FUNCTION_CODE (fndecl
))
3207 CASE_FLT_FN (BUILT_IN_IRINT
):
3208 fallback_fn
= BUILT_IN_LRINT
;
3210 CASE_FLT_FN (BUILT_IN_LRINT
):
3211 CASE_FLT_FN (BUILT_IN_LLRINT
):
3212 builtin_optab
= lrint_optab
;
3215 CASE_FLT_FN (BUILT_IN_IROUND
):
3216 fallback_fn
= BUILT_IN_LROUND
;
3218 CASE_FLT_FN (BUILT_IN_LROUND
):
3219 CASE_FLT_FN (BUILT_IN_LLROUND
):
3220 builtin_optab
= lround_optab
;
3227 /* There's no easy way to detect the case we need to set EDOM. */
3228 if (flag_errno_math
&& fallback_fn
== BUILT_IN_NONE
)
3231 /* Make a suitable register to place result in. */
3232 mode
= TYPE_MODE (TREE_TYPE (exp
));
3234 /* There's no easy way to detect the case we need to set EDOM. */
3235 if (!flag_errno_math
)
3237 rtx result
= gen_reg_rtx (mode
);
3239 /* Wrap the computation of the argument in a SAVE_EXPR, as we may
3240 need to expand the argument again. This way, we will not perform
3241 side-effects more the once. */
3242 CALL_EXPR_ARG (exp
, 0) = arg
= builtin_save_expr (arg
);
3244 op0
= expand_expr (arg
, NULL
, VOIDmode
, EXPAND_NORMAL
);
3248 if (expand_sfix_optab (result
, op0
, builtin_optab
))
3250 /* Output the entire sequence. */
3251 insns
= get_insns ();
3257 /* If we were unable to expand via the builtin, stop the sequence
3258 (without outputting the insns) and call to the library function
3259 with the stabilized argument list. */
3263 if (fallback_fn
!= BUILT_IN_NONE
)
3265 /* Fall back to rounding to long int. Use implicit_p 0 - for non-C99
3266 targets, (int) round (x) should never be transformed into
3267 BUILT_IN_IROUND and if __builtin_iround is called directly, emit
3268 a call to lround in the hope that the target provides at least some
3269 C99 functions. This should result in the best user experience for
3270 not full C99 targets.
3271 As scalar float conversions with same mode are useless in GIMPLE,
3272 we can end up e.g. with _Float32 argument passed to float builtin,
3273 try to get the type from the builtin prototype first. */
3274 tree fallback_fndecl
= NULL_TREE
;
3275 if (tree argtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
3277 = mathfn_built_in_1 (TREE_VALUE (argtypes
),
3278 as_combined_fn (fallback_fn
), 0);
3279 if (fallback_fndecl
== NULL_TREE
)
3281 = mathfn_built_in_1 (TREE_TYPE (arg
),
3282 as_combined_fn (fallback_fn
), 0);
3283 if (fallback_fndecl
)
3285 exp
= build_call_nofold_loc (EXPR_LOCATION (exp
),
3286 fallback_fndecl
, 1, arg
);
3288 target
= expand_call (exp
, NULL_RTX
, target
== const0_rtx
);
3289 target
= maybe_emit_group_store (target
, TREE_TYPE (exp
));
3290 return convert_to_mode (mode
, target
, 0);
3294 return expand_call (exp
, target
, target
== const0_rtx
);
3297 /* Expand a call to the powi built-in mathematical function. Return NULL_RTX if
3298 a normal call should be emitted rather than expanding the function
3299 in-line. EXP is the expression that is a call to the builtin
3300 function; if convenient, the result should be placed in TARGET. */
3303 expand_builtin_powi (tree exp
, rtx target
)
3310 if (! validate_arglist (exp
, REAL_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
3313 arg0
= CALL_EXPR_ARG (exp
, 0);
3314 arg1
= CALL_EXPR_ARG (exp
, 1);
3315 mode
= TYPE_MODE (TREE_TYPE (exp
));
3317 /* Emit a libcall to libgcc. */
3319 /* Mode of the 2nd argument must match that of an int. */
3320 mode2
= int_mode_for_size (INT_TYPE_SIZE
, 0).require ();
3322 if (target
== NULL_RTX
)
3323 target
= gen_reg_rtx (mode
);
3325 op0
= expand_expr (arg0
, NULL_RTX
, mode
, EXPAND_NORMAL
);
3326 if (GET_MODE (op0
) != mode
)
3327 op0
= convert_to_mode (mode
, op0
, 0);
3328 op1
= expand_expr (arg1
, NULL_RTX
, mode2
, EXPAND_NORMAL
);
3329 if (GET_MODE (op1
) != mode2
)
3330 op1
= convert_to_mode (mode2
, op1
, 0);
3332 target
= emit_library_call_value (optab_libfunc (powi_optab
, mode
),
3333 target
, LCT_CONST
, mode
,
3334 op0
, mode
, op1
, mode2
);
3339 /* Expand expression EXP which is a call to the strlen builtin. Return
3340 NULL_RTX if we failed and the caller should emit a normal call, otherwise
3341 try to get the result in TARGET, if convenient. */
3344 expand_builtin_strlen (tree exp
, rtx target
,
3345 machine_mode target_mode
)
3347 if (!validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
3350 tree src
= CALL_EXPR_ARG (exp
, 0);
3352 /* If the length can be computed at compile-time, return it. */
3353 if (tree len
= c_strlen (src
, 0))
3354 return expand_expr (len
, target
, target_mode
, EXPAND_NORMAL
);
3356 /* If the length can be computed at compile-time and is constant
3357 integer, but there are side-effects in src, evaluate
3358 src for side-effects, then return len.
3359 E.g. x = strlen (i++ ? "xfoo" + 1 : "bar");
3360 can be optimized into: i++; x = 3; */
3361 tree len
= c_strlen (src
, 1);
3362 if (len
&& TREE_CODE (len
) == INTEGER_CST
)
3364 expand_expr (src
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
3365 return expand_expr (len
, target
, target_mode
, EXPAND_NORMAL
);
3368 unsigned int align
= get_pointer_alignment (src
) / BITS_PER_UNIT
;
3370 /* If SRC is not a pointer type, don't do this operation inline. */
3374 /* Bail out if we can't compute strlen in the right mode. */
3375 machine_mode insn_mode
;
3376 enum insn_code icode
= CODE_FOR_nothing
;
3377 FOR_EACH_MODE_FROM (insn_mode
, target_mode
)
3379 icode
= optab_handler (strlen_optab
, insn_mode
);
3380 if (icode
!= CODE_FOR_nothing
)
3383 if (insn_mode
== VOIDmode
)
3386 /* Make a place to hold the source address. We will not expand
3387 the actual source until we are sure that the expansion will
3388 not fail -- there are trees that cannot be expanded twice. */
3389 rtx src_reg
= gen_reg_rtx (Pmode
);
3391 /* Mark the beginning of the strlen sequence so we can emit the
3392 source operand later. */
3393 rtx_insn
*before_strlen
= get_last_insn ();
3395 class expand_operand ops
[4];
3396 create_output_operand (&ops
[0], target
, insn_mode
);
3397 create_fixed_operand (&ops
[1], gen_rtx_MEM (BLKmode
, src_reg
));
3398 create_integer_operand (&ops
[2], 0);
3399 create_integer_operand (&ops
[3], align
);
3400 if (!maybe_expand_insn (icode
, 4, ops
))
3403 /* Check to see if the argument was declared attribute nonstring
3404 and if so, issue a warning since at this point it's not known
3405 to be nul-terminated. */
3406 maybe_warn_nonstring_arg (get_callee_fndecl (exp
), exp
);
3408 /* Now that we are assured of success, expand the source. */
3410 rtx pat
= expand_expr (src
, src_reg
, Pmode
, EXPAND_NORMAL
);
3413 #ifdef POINTERS_EXTEND_UNSIGNED
3414 if (GET_MODE (pat
) != Pmode
)
3415 pat
= convert_to_mode (Pmode
, pat
,
3416 POINTERS_EXTEND_UNSIGNED
);
3418 emit_move_insn (src_reg
, pat
);
3424 emit_insn_after (pat
, before_strlen
);
3426 emit_insn_before (pat
, get_insns ());
3428 /* Return the value in the proper mode for this function. */
3429 if (GET_MODE (ops
[0].value
) == target_mode
)
3430 target
= ops
[0].value
;
3431 else if (target
!= 0)
3432 convert_move (target
, ops
[0].value
, 0);
3434 target
= convert_to_mode (target_mode
, ops
[0].value
, 0);
3439 /* Expand call EXP to the strnlen built-in, returning the result
3440 and setting it in TARGET. Otherwise return NULL_RTX on failure. */
3443 expand_builtin_strnlen (tree exp
, rtx target
, machine_mode target_mode
)
3445 if (!validate_arglist (exp
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
3448 tree src
= CALL_EXPR_ARG (exp
, 0);
3449 tree bound
= CALL_EXPR_ARG (exp
, 1);
3454 location_t loc
= UNKNOWN_LOCATION
;
3455 if (EXPR_HAS_LOCATION (exp
))
3456 loc
= EXPR_LOCATION (exp
);
3458 /* FIXME: Change c_strlen() to return sizetype instead of ssizetype
3459 so these conversions aren't necessary. */
3460 c_strlen_data lendata
= { };
3461 tree len
= c_strlen (src
, 0, &lendata
, 1);
3463 len
= fold_convert_loc (loc
, TREE_TYPE (bound
), len
);
3465 if (TREE_CODE (bound
) == INTEGER_CST
)
3470 len
= fold_build2_loc (loc
, MIN_EXPR
, size_type_node
, len
, bound
);
3471 return expand_expr (len
, target
, target_mode
, EXPAND_NORMAL
);
3474 if (TREE_CODE (bound
) != SSA_NAME
)
3479 get_global_range_query ()->range_of_expr (r
, bound
);
3480 if (r
.kind () != VR_RANGE
)
3482 min
= r
.lower_bound ();
3483 max
= r
.upper_bound ();
3485 if (!len
|| TREE_CODE (len
) != INTEGER_CST
)
3488 lendata
.decl
= unterminated_array (src
, &len
, &exact
);
3496 if (wi::gtu_p (min
, wi::to_wide (len
)))
3497 return expand_expr (len
, target
, target_mode
, EXPAND_NORMAL
);
3499 len
= fold_build2_loc (loc
, MIN_EXPR
, TREE_TYPE (len
), len
, bound
);
3500 return expand_expr (len
, target
, target_mode
, EXPAND_NORMAL
);
3503 /* Callback routine for store_by_pieces. Read GET_MODE_BITSIZE (MODE)
3504 bytes from bytes at DATA + OFFSET and return it reinterpreted as
3505 a target constant. */
3508 builtin_memcpy_read_str (void *data
, void *, HOST_WIDE_INT offset
,
3509 fixed_size_mode mode
)
3511 /* The REPresentation pointed to by DATA need not be a nul-terminated
3512 string but the caller guarantees it's large enough for MODE. */
3513 const char *rep
= (const char *) data
;
3515 /* The by-pieces infrastructure does not try to pick a vector mode
3516 for memcpy expansion. */
3517 return c_readstr (rep
+ offset
, as_a
<scalar_int_mode
> (mode
),
3518 /*nul_terminated=*/false);
3521 /* LEN specify length of the block of memcpy/memset operation.
3522 Figure out its range and put it into MIN_SIZE/MAX_SIZE.
3523 In some cases we can make very likely guess on max size, then we
3524 set it into PROBABLE_MAX_SIZE. */
3527 determine_block_size (tree len
, rtx len_rtx
,
3528 unsigned HOST_WIDE_INT
*min_size
,
3529 unsigned HOST_WIDE_INT
*max_size
,
3530 unsigned HOST_WIDE_INT
*probable_max_size
)
3532 if (CONST_INT_P (len_rtx
))
3534 *min_size
= *max_size
= *probable_max_size
= UINTVAL (len_rtx
);
3540 enum value_range_kind range_type
= VR_UNDEFINED
;
3542 /* Determine bounds from the type. */
3543 if (tree_fits_uhwi_p (TYPE_MIN_VALUE (TREE_TYPE (len
))))
3544 *min_size
= tree_to_uhwi (TYPE_MIN_VALUE (TREE_TYPE (len
)));
3547 if (tree_fits_uhwi_p (TYPE_MAX_VALUE (TREE_TYPE (len
))))
3548 *probable_max_size
= *max_size
3549 = tree_to_uhwi (TYPE_MAX_VALUE (TREE_TYPE (len
)));
3551 *probable_max_size
= *max_size
= GET_MODE_MASK (GET_MODE (len_rtx
));
3553 if (TREE_CODE (len
) == SSA_NAME
)
3556 get_global_range_query ()->range_of_expr (r
, len
);
3557 range_type
= r
.kind ();
3558 if (range_type
!= VR_UNDEFINED
)
3560 min
= wi::to_wide (r
.min ());
3561 max
= wi::to_wide (r
.max ());
3564 if (range_type
== VR_RANGE
)
3566 if (wi::fits_uhwi_p (min
) && *min_size
< min
.to_uhwi ())
3567 *min_size
= min
.to_uhwi ();
3568 if (wi::fits_uhwi_p (max
) && *max_size
> max
.to_uhwi ())
3569 *probable_max_size
= *max_size
= max
.to_uhwi ();
3571 else if (range_type
== VR_ANTI_RANGE
)
3579 Produce anti range allowing negative values of N. We still
3580 can use the information and make a guess that N is not negative.
3582 if (!wi::leu_p (max
, 1 << 30) && wi::fits_uhwi_p (min
))
3583 *probable_max_size
= min
.to_uhwi () - 1;
3586 gcc_checking_assert (*max_size
<=
3587 (unsigned HOST_WIDE_INT
)
3588 GET_MODE_MASK (GET_MODE (len_rtx
)));
3591 /* Expand a call EXP to the memcpy builtin.
3592 Return NULL_RTX if we failed, the caller should emit a normal call,
3593 otherwise try to get the result in TARGET, if convenient (and in
3594 mode MODE if that's convenient). */
3597 expand_builtin_memcpy (tree exp
, rtx target
)
3599 if (!validate_arglist (exp
,
3600 POINTER_TYPE
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
3603 tree dest
= CALL_EXPR_ARG (exp
, 0);
3604 tree src
= CALL_EXPR_ARG (exp
, 1);
3605 tree len
= CALL_EXPR_ARG (exp
, 2);
3607 return expand_builtin_memory_copy_args (dest
, src
, len
, target
, exp
,
3608 /*retmode=*/ RETURN_BEGIN
, false);
3611 /* Check a call EXP to the memmove built-in for validity.
3612 Return NULL_RTX on both success and failure. */
3615 expand_builtin_memmove (tree exp
, rtx target
)
3617 if (!validate_arglist (exp
,
3618 POINTER_TYPE
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
3621 tree dest
= CALL_EXPR_ARG (exp
, 0);
3622 tree src
= CALL_EXPR_ARG (exp
, 1);
3623 tree len
= CALL_EXPR_ARG (exp
, 2);
3625 return expand_builtin_memory_copy_args (dest
, src
, len
, target
, exp
,
3626 /*retmode=*/ RETURN_BEGIN
, true);
3629 /* Expand a call EXP to the mempcpy builtin.
3630 Return NULL_RTX if we failed; the caller should emit a normal call,
3631 otherwise try to get the result in TARGET, if convenient (and in
3632 mode MODE if that's convenient). */
3635 expand_builtin_mempcpy (tree exp
, rtx target
)
3637 if (!validate_arglist (exp
,
3638 POINTER_TYPE
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
3641 tree dest
= CALL_EXPR_ARG (exp
, 0);
3642 tree src
= CALL_EXPR_ARG (exp
, 1);
3643 tree len
= CALL_EXPR_ARG (exp
, 2);
3645 /* Policy does not generally allow using compute_objsize (which
3646 is used internally by check_memop_size) to change code generation
3647 or drive optimization decisions.
3649 In this instance it is safe because the code we generate has
3650 the same semantics regardless of the return value of
3651 check_memop_sizes. Exactly the same amount of data is copied
3652 and the return value is exactly the same in both cases.
3654 Furthermore, check_memop_size always uses mode 0 for the call to
3655 compute_objsize, so the imprecise nature of compute_objsize is
3658 /* Avoid expanding mempcpy into memcpy when the call is determined
3659 to overflow the buffer. This also prevents the same overflow
3660 from being diagnosed again when expanding memcpy. */
3662 return expand_builtin_mempcpy_args (dest
, src
, len
,
3663 target
, exp
, /*retmode=*/ RETURN_END
);
3666 /* Helper function to do the actual work for expand of memory copy family
3667 functions (memcpy, mempcpy, stpcpy). Expansing should assign LEN bytes
3668 of memory from SRC to DEST and assign to TARGET if convenient. Return
3669 value is based on RETMODE argument. */
3672 expand_builtin_memory_copy_args (tree dest
, tree src
, tree len
,
3673 rtx target
, tree exp
, memop_ret retmode
,
3676 unsigned int src_align
= get_pointer_alignment (src
);
3677 unsigned int dest_align
= get_pointer_alignment (dest
);
3678 rtx dest_mem
, src_mem
, dest_addr
, len_rtx
;
3679 HOST_WIDE_INT expected_size
= -1;
3680 unsigned int expected_align
= 0;
3681 unsigned HOST_WIDE_INT min_size
;
3682 unsigned HOST_WIDE_INT max_size
;
3683 unsigned HOST_WIDE_INT probable_max_size
;
3687 /* If DEST is not a pointer type, call the normal function. */
3688 if (dest_align
== 0)
3691 /* If either SRC is not a pointer type, don't do this
3692 operation in-line. */
3696 if (currently_expanding_gimple_stmt
)
3697 stringop_block_profile (currently_expanding_gimple_stmt
,
3698 &expected_align
, &expected_size
);
3700 if (expected_align
< dest_align
)
3701 expected_align
= dest_align
;
3702 dest_mem
= get_memory_rtx (dest
, len
);
3703 set_mem_align (dest_mem
, dest_align
);
3704 len_rtx
= expand_normal (len
);
3705 determine_block_size (len
, len_rtx
, &min_size
, &max_size
,
3706 &probable_max_size
);
3708 /* Try to get the byte representation of the constant SRC points to,
3709 with its byte size in NBYTES. */
3710 unsigned HOST_WIDE_INT nbytes
;
3711 const char *rep
= getbyterep (src
, &nbytes
);
3713 /* If the function's constant bound LEN_RTX is less than or equal
3714 to the byte size of the representation of the constant argument,
3715 and if block move would be done by pieces, we can avoid loading
3716 the bytes from memory and only store the computed constant.
3717 This works in the overlap (memmove) case as well because
3718 store_by_pieces just generates a series of stores of constants
3719 from the representation returned by getbyterep(). */
3721 && CONST_INT_P (len_rtx
)
3722 && (unsigned HOST_WIDE_INT
) INTVAL (len_rtx
) <= nbytes
3723 && can_store_by_pieces (INTVAL (len_rtx
), builtin_memcpy_read_str
,
3724 CONST_CAST (char *, rep
),
3727 dest_mem
= store_by_pieces (dest_mem
, INTVAL (len_rtx
),
3728 builtin_memcpy_read_str
,
3729 CONST_CAST (char *, rep
),
3730 dest_align
, false, retmode
);
3731 dest_mem
= force_operand (XEXP (dest_mem
, 0), target
);
3732 dest_mem
= convert_memory_address (ptr_mode
, dest_mem
);
3736 src_mem
= get_memory_rtx (src
, len
);
3737 set_mem_align (src_mem
, src_align
);
3739 /* Copy word part most expediently. */
3740 enum block_op_methods method
= BLOCK_OP_NORMAL
;
3741 if (CALL_EXPR_TAILCALL (exp
)
3742 && (retmode
== RETURN_BEGIN
|| target
== const0_rtx
))
3743 method
= BLOCK_OP_TAILCALL
;
3744 bool use_mempcpy_call
= (targetm
.libc_has_fast_function (BUILT_IN_MEMPCPY
)
3745 && retmode
== RETURN_END
3747 && target
!= const0_rtx
);
3748 if (use_mempcpy_call
)
3749 method
= BLOCK_OP_NO_LIBCALL_RET
;
3750 dest_addr
= emit_block_move_hints (dest_mem
, src_mem
, len_rtx
, method
,
3751 expected_align
, expected_size
,
3752 min_size
, max_size
, probable_max_size
,
3753 use_mempcpy_call
, &is_move_done
,
3756 /* Bail out when a mempcpy call would be expanded as libcall and when
3757 we have a target that provides a fast implementation
3758 of mempcpy routine. */
3762 if (dest_addr
== pc_rtx
)
3767 dest_addr
= force_operand (XEXP (dest_mem
, 0), target
);
3768 dest_addr
= convert_memory_address (ptr_mode
, dest_addr
);
3771 if (retmode
!= RETURN_BEGIN
&& target
!= const0_rtx
)
3773 dest_addr
= gen_rtx_PLUS (ptr_mode
, dest_addr
, len_rtx
);
3774 /* stpcpy pointer to last byte. */
3775 if (retmode
== RETURN_END_MINUS_ONE
)
3776 dest_addr
= gen_rtx_MINUS (ptr_mode
, dest_addr
, const1_rtx
);
3783 expand_builtin_mempcpy_args (tree dest
, tree src
, tree len
,
3784 rtx target
, tree orig_exp
, memop_ret retmode
)
3786 return expand_builtin_memory_copy_args (dest
, src
, len
, target
, orig_exp
,
3790 /* Expand into a movstr instruction, if one is available. Return NULL_RTX if
3791 we failed, the caller should emit a normal call, otherwise try to
3792 get the result in TARGET, if convenient.
3793 Return value is based on RETMODE argument. */
3796 expand_movstr (tree dest
, tree src
, rtx target
, memop_ret retmode
)
3798 class expand_operand ops
[3];
3802 if (!targetm
.have_movstr ())
3805 dest_mem
= get_memory_rtx (dest
, NULL
);
3806 src_mem
= get_memory_rtx (src
, NULL
);
3807 if (retmode
== RETURN_BEGIN
)
3809 target
= force_reg (Pmode
, XEXP (dest_mem
, 0));
3810 dest_mem
= replace_equiv_address (dest_mem
, target
);
3813 create_output_operand (&ops
[0],
3814 retmode
!= RETURN_BEGIN
? target
: NULL_RTX
, Pmode
);
3815 create_fixed_operand (&ops
[1], dest_mem
);
3816 create_fixed_operand (&ops
[2], src_mem
);
3817 if (!maybe_expand_insn (targetm
.code_for_movstr
, 3, ops
))
3820 if (retmode
!= RETURN_BEGIN
&& target
!= const0_rtx
)
3822 target
= ops
[0].value
;
3823 /* movstr is supposed to set end to the address of the NUL
3824 terminator. If the caller requested a mempcpy-like return value,
3826 if (retmode
== RETURN_END
)
3828 rtx tem
= plus_constant (GET_MODE (target
),
3829 gen_lowpart (GET_MODE (target
), target
), 1);
3830 emit_move_insn (target
, force_operand (tem
, NULL_RTX
));
3836 /* Expand expression EXP, which is a call to the strcpy builtin. Return
3837 NULL_RTX if we failed the caller should emit a normal call, otherwise
3838 try to get the result in TARGET, if convenient (and in mode MODE if that's
3842 expand_builtin_strcpy (tree exp
, rtx target
)
3844 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
3847 tree dest
= CALL_EXPR_ARG (exp
, 0);
3848 tree src
= CALL_EXPR_ARG (exp
, 1);
3850 return expand_builtin_strcpy_args (exp
, dest
, src
, target
);
3853 /* Helper function to do the actual work for expand_builtin_strcpy. The
3854 arguments to the builtin_strcpy call DEST and SRC are broken out
3855 so that this can also be called without constructing an actual CALL_EXPR.
3856 The other arguments and return value are the same as for
3857 expand_builtin_strcpy. */
3860 expand_builtin_strcpy_args (tree
, tree dest
, tree src
, rtx target
)
3862 return expand_movstr (dest
, src
, target
, /*retmode=*/ RETURN_BEGIN
);
3865 /* Expand a call EXP to the stpcpy builtin.
3866 Return NULL_RTX if we failed the caller should emit a normal call,
3867 otherwise try to get the result in TARGET, if convenient (and in
3868 mode MODE if that's convenient). */
3871 expand_builtin_stpcpy_1 (tree exp
, rtx target
, machine_mode mode
)
3874 location_t loc
= EXPR_LOCATION (exp
);
3876 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
3879 dst
= CALL_EXPR_ARG (exp
, 0);
3880 src
= CALL_EXPR_ARG (exp
, 1);
3882 /* If return value is ignored, transform stpcpy into strcpy. */
3883 if (target
== const0_rtx
&& builtin_decl_implicit (BUILT_IN_STRCPY
))
3885 tree fn
= builtin_decl_implicit (BUILT_IN_STRCPY
);
3886 tree result
= build_call_nofold_loc (loc
, fn
, 2, dst
, src
);
3887 return expand_expr (result
, target
, mode
, EXPAND_NORMAL
);
3894 /* Ensure we get an actual string whose length can be evaluated at
3895 compile-time, not an expression containing a string. This is
3896 because the latter will potentially produce pessimized code
3897 when used to produce the return value. */
3898 c_strlen_data lendata
= { };
3900 || !(len
= c_strlen (src
, 0, &lendata
, 1)))
3901 return expand_movstr (dst
, src
, target
,
3902 /*retmode=*/ RETURN_END_MINUS_ONE
);
3904 lenp1
= size_binop_loc (loc
, PLUS_EXPR
, len
, ssize_int (1));
3905 ret
= expand_builtin_mempcpy_args (dst
, src
, lenp1
,
3907 /*retmode=*/ RETURN_END_MINUS_ONE
);
3912 if (TREE_CODE (len
) == INTEGER_CST
)
3914 rtx len_rtx
= expand_normal (len
);
3916 if (CONST_INT_P (len_rtx
))
3918 ret
= expand_builtin_strcpy_args (exp
, dst
, src
, target
);
3924 if (mode
!= VOIDmode
)
3925 target
= gen_reg_rtx (mode
);
3927 target
= gen_reg_rtx (GET_MODE (ret
));
3929 if (GET_MODE (target
) != GET_MODE (ret
))
3930 ret
= gen_lowpart (GET_MODE (target
), ret
);
3932 ret
= plus_constant (GET_MODE (ret
), ret
, INTVAL (len_rtx
));
3933 ret
= emit_move_insn (target
, force_operand (ret
, NULL_RTX
));
3941 return expand_movstr (dst
, src
, target
,
3942 /*retmode=*/ RETURN_END_MINUS_ONE
);
3946 /* Expand a call EXP to the stpcpy builtin and diagnose uses of nonstring
3947 arguments while being careful to avoid duplicate warnings (which could
3948 be issued if the expander were to expand the call, resulting in it
3949 being emitted in expand_call(). */
3952 expand_builtin_stpcpy (tree exp
, rtx target
, machine_mode mode
)
3954 if (rtx ret
= expand_builtin_stpcpy_1 (exp
, target
, mode
))
3956 /* The call has been successfully expanded. Check for nonstring
3957 arguments and issue warnings as appropriate. */
3958 maybe_warn_nonstring_arg (get_callee_fndecl (exp
), exp
);
3965 /* Callback routine for store_by_pieces. Read GET_MODE_BITSIZE (MODE)
3966 bytes from constant string DATA + OFFSET and return it as target
3970 builtin_strncpy_read_str (void *data
, void *, HOST_WIDE_INT offset
,
3971 fixed_size_mode mode
)
3973 const char *str
= (const char *) data
;
3975 if ((unsigned HOST_WIDE_INT
) offset
> strlen (str
))
3978 /* The by-pieces infrastructure does not try to pick a vector mode
3979 for strncpy expansion. */
3980 return c_readstr (str
+ offset
, as_a
<scalar_int_mode
> (mode
));
3983 /* Helper to check the sizes of sequences and the destination of calls
3984 to __builtin_strncat and __builtin___strncat_chk. Returns true on
3985 success (no overflow or invalid sizes), false otherwise. */
3988 check_strncat_sizes (tree exp
, tree objsize
)
3990 tree dest
= CALL_EXPR_ARG (exp
, 0);
3991 tree src
= CALL_EXPR_ARG (exp
, 1);
3992 tree maxread
= CALL_EXPR_ARG (exp
, 2);
3994 /* Try to determine the range of lengths that the source expression
3996 c_strlen_data lendata
= { };
3997 get_range_strlen (src
, &lendata
, /* eltsize = */ 1);
3999 /* Try to verify that the destination is big enough for the shortest
4002 access_data
data (nullptr, exp
, access_read_write
, maxread
, true);
4003 if (!objsize
&& warn_stringop_overflow
)
4005 /* If it hasn't been provided by __strncat_chk, try to determine
4006 the size of the destination object into which the source is
4008 objsize
= compute_objsize (dest
, warn_stringop_overflow
- 1, &data
.dst
);
4011 /* Add one for the terminating nul. */
4012 tree srclen
= (lendata
.minlen
4013 ? fold_build2 (PLUS_EXPR
, size_type_node
, lendata
.minlen
,
4017 /* The strncat function copies at most MAXREAD bytes and always appends
4018 the terminating nul so the specified upper bound should never be equal
4019 to (or greater than) the size of the destination. */
4020 if (tree_fits_uhwi_p (maxread
) && tree_fits_uhwi_p (objsize
)
4021 && tree_int_cst_equal (objsize
, maxread
))
4023 location_t loc
= EXPR_LOCATION (exp
);
4024 warning_at (loc
, OPT_Wstringop_overflow_
,
4025 "%qD specified bound %E equals destination size",
4026 get_callee_fndecl (exp
), maxread
);
4032 || (maxread
&& tree_fits_uhwi_p (maxread
)
4033 && tree_fits_uhwi_p (srclen
)
4034 && tree_int_cst_lt (maxread
, srclen
)))
4037 /* The number of bytes to write is LEN but check_access will alsoa
4038 check SRCLEN if LEN's value isn't known. */
4039 return check_access (exp
, /*dstwrite=*/NULL_TREE
, maxread
, srclen
,
4040 objsize
, data
.mode
, &data
);
4043 /* Expand expression EXP, which is a call to the strncpy builtin. Return
4044 NULL_RTX if we failed the caller should emit a normal call. */
4047 expand_builtin_strncpy (tree exp
, rtx target
)
4049 location_t loc
= EXPR_LOCATION (exp
);
4051 if (!validate_arglist (exp
,
4052 POINTER_TYPE
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
4054 tree dest
= CALL_EXPR_ARG (exp
, 0);
4055 tree src
= CALL_EXPR_ARG (exp
, 1);
4056 /* The number of bytes to write (not the maximum). */
4057 tree len
= CALL_EXPR_ARG (exp
, 2);
4059 /* The length of the source sequence. */
4060 tree slen
= c_strlen (src
, 1);
4062 /* We must be passed a constant len and src parameter. */
4063 if (!tree_fits_uhwi_p (len
) || !slen
|| !tree_fits_uhwi_p (slen
))
4066 slen
= size_binop_loc (loc
, PLUS_EXPR
, slen
, ssize_int (1));
4068 /* We're required to pad with trailing zeros if the requested
4069 len is greater than strlen(s2)+1. In that case try to
4070 use store_by_pieces, if it fails, punt. */
4071 if (tree_int_cst_lt (slen
, len
))
4073 unsigned int dest_align
= get_pointer_alignment (dest
);
4074 const char *p
= c_getstr (src
);
4077 if (!p
|| dest_align
== 0 || !tree_fits_uhwi_p (len
)
4078 || !can_store_by_pieces (tree_to_uhwi (len
),
4079 builtin_strncpy_read_str
,
4080 CONST_CAST (char *, p
),
4084 dest_mem
= get_memory_rtx (dest
, len
);
4085 store_by_pieces (dest_mem
, tree_to_uhwi (len
),
4086 builtin_strncpy_read_str
,
4087 CONST_CAST (char *, p
), dest_align
, false,
4089 dest_mem
= force_operand (XEXP (dest_mem
, 0), target
);
4090 dest_mem
= convert_memory_address (ptr_mode
, dest_mem
);
4097 /* Return the RTL of a register in MODE generated from PREV in the
4098 previous iteration. */
4101 gen_memset_value_from_prev (by_pieces_prev
*prev
, fixed_size_mode mode
)
4103 rtx target
= nullptr;
4104 if (prev
!= nullptr && prev
->data
!= nullptr)
4106 /* Use the previous data in the same mode. */
4107 if (prev
->mode
== mode
)
4110 fixed_size_mode prev_mode
= prev
->mode
;
4112 /* Don't use the previous data to write QImode if it is in a
4114 if (VECTOR_MODE_P (prev_mode
) && mode
== QImode
)
4117 rtx prev_rtx
= prev
->data
;
4119 if (REG_P (prev_rtx
)
4120 && HARD_REGISTER_P (prev_rtx
)
4121 && lowpart_subreg_regno (REGNO (prev_rtx
), prev_mode
, mode
) < 0)
4123 /* This case occurs when PREV_MODE is a vector and when
4124 MODE is too small to store using vector operations.
4125 After register allocation, the code will need to move the
4126 lowpart of the vector register into a non-vector register.
4128 Also, the target has chosen to use a hard register
4129 instead of going with the default choice of using a
4130 pseudo register. We should respect that choice and try to
4131 avoid creating a pseudo register with the same mode as the
4132 current hard register.
4134 In principle, we could just use a lowpart MODE subreg of
4135 the vector register. However, the vector register mode might
4136 be too wide for non-vector registers, and we already know
4137 that the non-vector mode is too small for vector registers.
4138 It's therefore likely that we'd need to spill to memory in
4139 the vector mode and reload the non-vector value from there.
4141 Try to avoid that by reducing the vector register to the
4142 smallest size that it can hold. This should increase the
4143 chances that non-vector registers can hold both the inner
4144 and outer modes of the subreg that we generate later. */
4146 fixed_size_mode candidate
;
4147 FOR_EACH_MODE_IN_CLASS (m
, GET_MODE_CLASS (mode
))
4148 if (is_a
<fixed_size_mode
> (m
, &candidate
))
4150 if (GET_MODE_SIZE (candidate
)
4151 >= GET_MODE_SIZE (prev_mode
))
4153 if (GET_MODE_SIZE (candidate
) >= GET_MODE_SIZE (mode
)
4154 && lowpart_subreg_regno (REGNO (prev_rtx
),
4155 prev_mode
, candidate
) >= 0)
4157 target
= lowpart_subreg (candidate
, prev_rtx
,
4160 prev_mode
= candidate
;
4164 if (target
== nullptr)
4165 prev_rtx
= copy_to_reg (prev_rtx
);
4168 target
= lowpart_subreg (mode
, prev_rtx
, prev_mode
);
4173 /* Callback routine for store_by_pieces. Read GET_MODE_BITSIZE (MODE)
4174 bytes from constant string DATA + OFFSET and return it as target
4175 constant. If PREV isn't nullptr, it has the RTL info from the
4176 previous iteration. */
4179 builtin_memset_read_str (void *data
, void *prev
,
4180 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
4181 fixed_size_mode mode
)
4183 const char *c
= (const char *) data
;
4184 unsigned int size
= GET_MODE_SIZE (mode
);
4186 rtx target
= gen_memset_value_from_prev ((by_pieces_prev
*) prev
,
4188 if (target
!= nullptr)
4190 rtx src
= gen_int_mode (*c
, QImode
);
4192 if (VECTOR_MODE_P (mode
))
4194 gcc_assert (GET_MODE_INNER (mode
) == QImode
);
4196 rtx const_vec
= gen_const_vec_duplicate (mode
, src
);
4198 /* Return CONST_VECTOR when called by a query function. */
4201 /* Use the move expander with CONST_VECTOR. */
4202 target
= targetm
.gen_memset_scratch_rtx (mode
);
4203 emit_move_insn (target
, const_vec
);
4207 char *p
= XALLOCAVEC (char, size
);
4209 memset (p
, *c
, size
);
4211 /* Vector modes should be handled above. */
4212 return c_readstr (p
, as_a
<scalar_int_mode
> (mode
));
4215 /* Callback routine for store_by_pieces. Return the RTL of a register
4216 containing GET_MODE_SIZE (MODE) consecutive copies of the unsigned
4217 char value given in the RTL register data. For example, if mode is
4218 4 bytes wide, return the RTL for 0x01010101*data. If PREV isn't
4219 nullptr, it has the RTL info from the previous iteration. */
4222 builtin_memset_gen_str (void *data
, void *prev
,
4223 HOST_WIDE_INT offset ATTRIBUTE_UNUSED
,
4224 fixed_size_mode mode
)
4230 size
= GET_MODE_SIZE (mode
);
4234 target
= gen_memset_value_from_prev ((by_pieces_prev
*) prev
, mode
);
4235 if (target
!= nullptr)
4238 if (VECTOR_MODE_P (mode
))
4240 gcc_assert (GET_MODE_INNER (mode
) == QImode
);
4242 /* vec_duplicate_optab is a precondition to pick a vector mode for
4243 the memset expander. */
4244 insn_code icode
= optab_handler (vec_duplicate_optab
, mode
);
4246 target
= targetm
.gen_memset_scratch_rtx (mode
);
4247 class expand_operand ops
[2];
4248 create_output_operand (&ops
[0], target
, mode
);
4249 create_input_operand (&ops
[1], (rtx
) data
, QImode
);
4250 expand_insn (icode
, 2, ops
);
4251 if (!rtx_equal_p (target
, ops
[0].value
))
4252 emit_move_insn (target
, ops
[0].value
);
4257 p
= XALLOCAVEC (char, size
);
4258 memset (p
, 1, size
);
4259 /* Vector modes should be handled above. */
4260 coeff
= c_readstr (p
, as_a
<scalar_int_mode
> (mode
));
4262 target
= convert_to_mode (mode
, (rtx
) data
, 1);
4263 target
= expand_mult (mode
, target
, coeff
, NULL_RTX
, 1);
4264 return force_reg (mode
, target
);
4267 /* Expand expression EXP, which is a call to the memset builtin. Return
4268 NULL_RTX if we failed the caller should emit a normal call, otherwise
4269 try to get the result in TARGET, if convenient (and in mode MODE if that's
4273 expand_builtin_memset (tree exp
, rtx target
, machine_mode mode
)
4275 if (!validate_arglist (exp
,
4276 POINTER_TYPE
, INTEGER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
4279 tree dest
= CALL_EXPR_ARG (exp
, 0);
4280 tree val
= CALL_EXPR_ARG (exp
, 1);
4281 tree len
= CALL_EXPR_ARG (exp
, 2);
4283 return expand_builtin_memset_args (dest
, val
, len
, target
, mode
, exp
);
4286 /* Try to store VAL (or, if NULL_RTX, VALC) in LEN bytes starting at TO.
4287 Return TRUE if successful, FALSE otherwise. TO is assumed to be
4288 aligned at an ALIGN-bits boundary. LEN must be a multiple of
4289 1<<CTZ_LEN between MIN_LEN and MAX_LEN.
4291 The strategy is to issue one store_by_pieces for each power of two,
4292 from most to least significant, guarded by a test on whether there
4293 are at least that many bytes left to copy in LEN.
4295 ??? Should we skip some powers of two in favor of loops? Maybe start
4296 at the max of TO/LEN/word alignment, at least when optimizing for
4297 size, instead of ensuring O(log len) dynamic compares? */
4300 try_store_by_multiple_pieces (rtx to
, rtx len
, unsigned int ctz_len
,
4301 unsigned HOST_WIDE_INT min_len
,
4302 unsigned HOST_WIDE_INT max_len
,
4303 rtx val
, char valc
, unsigned int align
)
4305 int max_bits
= floor_log2 (max_len
);
4306 int min_bits
= floor_log2 (min_len
);
4307 int sctz_len
= ctz_len
;
4309 gcc_checking_assert (sctz_len
>= 0);
4314 /* Bits more significant than TST_BITS are part of the shared prefix
4315 in the binary representation of both min_len and max_len. Since
4316 they're identical, we don't need to test them in the loop. */
4317 int tst_bits
= (max_bits
!= min_bits
? max_bits
4318 : floor_log2 (max_len
^ min_len
));
4320 /* Check whether it's profitable to start by storing a fixed BLKSIZE
4321 bytes, to lower max_bits. In the unlikely case of a constant LEN
4322 (implied by identical MAX_LEN and MIN_LEN), we want to issue a
4323 single store_by_pieces, but otherwise, select the minimum multiple
4324 of the ALIGN (in bytes) and of the MCD of the possible LENs, that
4325 brings MAX_LEN below TST_BITS, if that's lower than min_len. */
4326 unsigned HOST_WIDE_INT blksize
;
4327 if (max_len
> min_len
)
4329 unsigned HOST_WIDE_INT alrng
= MAX (HOST_WIDE_INT_1U
<< ctz_len
,
4330 align
/ BITS_PER_UNIT
);
4331 blksize
= max_len
- (HOST_WIDE_INT_1U
<< tst_bits
) + alrng
;
4332 blksize
&= ~(alrng
- 1);
4334 else if (max_len
== min_len
)
4337 /* Huh, max_len < min_len? Punt. See pr100843.c. */
4339 if (min_len
>= blksize
)
4342 min_bits
= floor_log2 (min_len
);
4344 max_bits
= floor_log2 (max_len
);
4346 tst_bits
= (max_bits
!= min_bits
? max_bits
4347 : floor_log2 (max_len
^ min_len
));
4352 /* Check that we can use store by pieces for the maximum store count
4353 we may issue (initial fixed-size block, plus conditional
4354 power-of-two-sized from max_bits to ctz_len. */
4355 unsigned HOST_WIDE_INT xlenest
= blksize
;
4357 xlenest
+= ((HOST_WIDE_INT_1U
<< max_bits
) * 2
4358 - (HOST_WIDE_INT_1U
<< ctz_len
));
4359 if (!can_store_by_pieces (xlenest
, builtin_memset_read_str
,
4360 &valc
, align
, true))
4363 by_pieces_constfn constfun
;
4367 constfun
= builtin_memset_gen_str
;
4368 constfundata
= val
= force_reg (TYPE_MODE (unsigned_char_type_node
),
4373 constfun
= builtin_memset_read_str
;
4374 constfundata
= &valc
;
4377 rtx ptr
= copy_addr_to_reg (XEXP (to
, 0));
4378 rtx rem
= copy_to_mode_reg (ptr_mode
, convert_to_mode (ptr_mode
, len
, 0));
4379 to
= replace_equiv_address (to
, ptr
);
4380 set_mem_align (to
, align
);
4384 to
= store_by_pieces (to
, blksize
,
4385 constfun
, constfundata
,
4387 max_len
!= 0 ? RETURN_END
: RETURN_BEGIN
);
4391 /* Adjust PTR, TO and REM. Since TO's address is likely
4392 PTR+offset, we have to replace it. */
4393 emit_move_insn (ptr
, force_operand (XEXP (to
, 0), NULL_RTX
));
4394 to
= replace_equiv_address (to
, ptr
);
4395 rtx rem_minus_blksize
= plus_constant (ptr_mode
, rem
, -blksize
);
4396 emit_move_insn (rem
, force_operand (rem_minus_blksize
, NULL_RTX
));
4399 /* Iterate over power-of-two block sizes from the maximum length to
4400 the least significant bit possibly set in the length. */
4401 for (int i
= max_bits
; i
>= sctz_len
; i
--)
4403 rtx_code_label
*label
= NULL
;
4404 blksize
= HOST_WIDE_INT_1U
<< i
;
4406 /* If we're past the bits shared between min_ and max_len, expand
4407 a test on the dynamic length, comparing it with the
4411 label
= gen_label_rtx ();
4412 emit_cmp_and_jump_insns (rem
, GEN_INT (blksize
), LT
, NULL
,
4414 profile_probability::even ());
4416 /* If we are at a bit that is in the prefix shared by min_ and
4417 max_len, skip this BLKSIZE if the bit is clear. */
4418 else if ((max_len
& blksize
) == 0)
4421 /* Issue a store of BLKSIZE bytes. */
4422 to
= store_by_pieces (to
, blksize
,
4423 constfun
, constfundata
,
4425 i
!= sctz_len
? RETURN_END
: RETURN_BEGIN
);
4427 /* Adjust REM and PTR, unless this is the last iteration. */
4430 emit_move_insn (ptr
, force_operand (XEXP (to
, 0), NULL_RTX
));
4431 to
= replace_equiv_address (to
, ptr
);
4432 rtx rem_minus_blksize
= plus_constant (ptr_mode
, rem
, -blksize
);
4433 emit_move_insn (rem
, force_operand (rem_minus_blksize
, NULL_RTX
));
4440 /* Given conditional stores, the offset can no longer be
4441 known, so clear it. */
4442 clear_mem_offset (to
);
4449 /* Helper function to do the actual work for expand_builtin_memset. The
4450 arguments to the builtin_memset call DEST, VAL, and LEN are broken out
4451 so that this can also be called without constructing an actual CALL_EXPR.
4452 The other arguments and return value are the same as for
4453 expand_builtin_memset. */
4456 expand_builtin_memset_args (tree dest
, tree val
, tree len
,
4457 rtx target
, machine_mode mode
, tree orig_exp
)
4460 enum built_in_function fcode
;
4461 machine_mode val_mode
;
4463 unsigned int dest_align
;
4464 rtx dest_mem
, dest_addr
, len_rtx
;
4465 HOST_WIDE_INT expected_size
= -1;
4466 unsigned int expected_align
= 0;
4467 unsigned HOST_WIDE_INT min_size
;
4468 unsigned HOST_WIDE_INT max_size
;
4469 unsigned HOST_WIDE_INT probable_max_size
;
4471 dest_align
= get_pointer_alignment (dest
);
4473 /* If DEST is not a pointer type, don't do this operation in-line. */
4474 if (dest_align
== 0)
4477 if (currently_expanding_gimple_stmt
)
4478 stringop_block_profile (currently_expanding_gimple_stmt
,
4479 &expected_align
, &expected_size
);
4481 if (expected_align
< dest_align
)
4482 expected_align
= dest_align
;
4484 /* If the LEN parameter is zero, return DEST. */
4485 if (integer_zerop (len
))
4487 /* Evaluate and ignore VAL in case it has side-effects. */
4488 expand_expr (val
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
4489 return expand_expr (dest
, target
, mode
, EXPAND_NORMAL
);
4492 /* Stabilize the arguments in case we fail. */
4493 dest
= builtin_save_expr (dest
);
4494 val
= builtin_save_expr (val
);
4495 len
= builtin_save_expr (len
);
4497 len_rtx
= expand_normal (len
);
4498 determine_block_size (len
, len_rtx
, &min_size
, &max_size
,
4499 &probable_max_size
);
4500 dest_mem
= get_memory_rtx (dest
, len
);
4501 val_mode
= TYPE_MODE (unsigned_char_type_node
);
4503 if (TREE_CODE (val
) != INTEGER_CST
4504 || target_char_cast (val
, &c
))
4508 val_rtx
= expand_normal (val
);
4509 val_rtx
= convert_to_mode (val_mode
, val_rtx
, 0);
4511 /* Assume that we can memset by pieces if we can store
4512 * the coefficients by pieces (in the required modes).
4513 * We can't pass builtin_memset_gen_str as that emits RTL. */
4515 if (tree_fits_uhwi_p (len
)
4516 && can_store_by_pieces (tree_to_uhwi (len
),
4517 builtin_memset_read_str
, &c
, dest_align
,
4520 val_rtx
= force_reg (val_mode
, val_rtx
);
4521 store_by_pieces (dest_mem
, tree_to_uhwi (len
),
4522 builtin_memset_gen_str
, val_rtx
, dest_align
,
4523 true, RETURN_BEGIN
);
4525 else if (!set_storage_via_setmem (dest_mem
, len_rtx
, val_rtx
,
4526 dest_align
, expected_align
,
4527 expected_size
, min_size
, max_size
,
4529 && !try_store_by_multiple_pieces (dest_mem
, len_rtx
,
4536 dest_mem
= force_operand (XEXP (dest_mem
, 0), NULL_RTX
);
4537 dest_mem
= convert_memory_address (ptr_mode
, dest_mem
);
4543 if (tree_fits_uhwi_p (len
)
4544 && can_store_by_pieces (tree_to_uhwi (len
),
4545 builtin_memset_read_str
, &c
, dest_align
,
4547 store_by_pieces (dest_mem
, tree_to_uhwi (len
),
4548 builtin_memset_read_str
, &c
, dest_align
, true,
4550 else if (!set_storage_via_setmem (dest_mem
, len_rtx
,
4551 gen_int_mode (c
, val_mode
),
4552 dest_align
, expected_align
,
4553 expected_size
, min_size
, max_size
,
4555 && !try_store_by_multiple_pieces (dest_mem
, len_rtx
,
4562 dest_mem
= force_operand (XEXP (dest_mem
, 0), NULL_RTX
);
4563 dest_mem
= convert_memory_address (ptr_mode
, dest_mem
);
4567 set_mem_align (dest_mem
, dest_align
);
4568 dest_addr
= clear_storage_hints (dest_mem
, len_rtx
,
4569 CALL_EXPR_TAILCALL (orig_exp
)
4570 ? BLOCK_OP_TAILCALL
: BLOCK_OP_NORMAL
,
4571 expected_align
, expected_size
,
4573 probable_max_size
, tree_ctz (len
));
4577 dest_addr
= force_operand (XEXP (dest_mem
, 0), NULL_RTX
);
4578 dest_addr
= convert_memory_address (ptr_mode
, dest_addr
);
4584 fndecl
= get_callee_fndecl (orig_exp
);
4585 fcode
= DECL_FUNCTION_CODE (fndecl
);
4586 if (fcode
== BUILT_IN_MEMSET
)
4587 fn
= build_call_nofold_loc (EXPR_LOCATION (orig_exp
), fndecl
, 3,
4589 else if (fcode
== BUILT_IN_BZERO
)
4590 fn
= build_call_nofold_loc (EXPR_LOCATION (orig_exp
), fndecl
, 2,
4594 gcc_assert (TREE_CODE (fn
) == CALL_EXPR
);
4595 CALL_EXPR_TAILCALL (fn
) = CALL_EXPR_TAILCALL (orig_exp
);
4596 return expand_call (fn
, target
, target
== const0_rtx
);
4599 /* Expand expression EXP, which is a call to the bzero builtin. Return
4600 NULL_RTX if we failed the caller should emit a normal call. */
4603 expand_builtin_bzero (tree exp
)
4605 if (!validate_arglist (exp
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
4608 tree dest
= CALL_EXPR_ARG (exp
, 0);
4609 tree size
= CALL_EXPR_ARG (exp
, 1);
4611 /* New argument list transforming bzero(ptr x, int y) to
4612 memset(ptr x, int 0, size_t y). This is done this way
4613 so that if it isn't expanded inline, we fallback to
4614 calling bzero instead of memset. */
4616 location_t loc
= EXPR_LOCATION (exp
);
4618 return expand_builtin_memset_args (dest
, integer_zero_node
,
4619 fold_convert_loc (loc
,
4620 size_type_node
, size
),
4621 const0_rtx
, VOIDmode
, exp
);
4624 /* Try to expand cmpstr operation ICODE with the given operands.
4625 Return the result rtx on success, otherwise return null. */
4628 expand_cmpstr (insn_code icode
, rtx target
, rtx arg1_rtx
, rtx arg2_rtx
,
4629 HOST_WIDE_INT align
)
4631 machine_mode insn_mode
= insn_data
[icode
].operand
[0].mode
;
4633 if (target
&& (!REG_P (target
) || HARD_REGISTER_P (target
)))
4636 class expand_operand ops
[4];
4637 create_output_operand (&ops
[0], target
, insn_mode
);
4638 create_fixed_operand (&ops
[1], arg1_rtx
);
4639 create_fixed_operand (&ops
[2], arg2_rtx
);
4640 create_integer_operand (&ops
[3], align
);
4641 if (maybe_expand_insn (icode
, 4, ops
))
4642 return ops
[0].value
;
4646 /* Expand expression EXP, which is a call to the memcmp built-in function.
4647 Return NULL_RTX if we failed and the caller should emit a normal call,
4648 otherwise try to get the result in TARGET, if convenient.
4649 RESULT_EQ is true if we can relax the returned value to be either zero
4650 or nonzero, without caring about the sign. */
4653 expand_builtin_memcmp (tree exp
, rtx target
, bool result_eq
)
4655 if (!validate_arglist (exp
,
4656 POINTER_TYPE
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
4659 tree arg1
= CALL_EXPR_ARG (exp
, 0);
4660 tree arg2
= CALL_EXPR_ARG (exp
, 1);
4661 tree len
= CALL_EXPR_ARG (exp
, 2);
4663 /* Due to the performance benefit, always inline the calls first
4664 when result_eq is false. */
4665 rtx result
= NULL_RTX
;
4666 enum built_in_function fcode
= DECL_FUNCTION_CODE (get_callee_fndecl (exp
));
4667 if (!result_eq
&& fcode
!= BUILT_IN_BCMP
)
4669 result
= inline_expand_builtin_bytecmp (exp
, target
);
4674 machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
4675 location_t loc
= EXPR_LOCATION (exp
);
4677 unsigned int arg1_align
= get_pointer_alignment (arg1
) / BITS_PER_UNIT
;
4678 unsigned int arg2_align
= get_pointer_alignment (arg2
) / BITS_PER_UNIT
;
4680 /* If we don't have POINTER_TYPE, call the function. */
4681 if (arg1_align
== 0 || arg2_align
== 0)
4684 rtx arg1_rtx
= get_memory_rtx (arg1
, len
);
4685 rtx arg2_rtx
= get_memory_rtx (arg2
, len
);
4686 rtx len_rtx
= expand_normal (fold_convert_loc (loc
, sizetype
, len
));
4688 /* Set MEM_SIZE as appropriate. */
4689 if (CONST_INT_P (len_rtx
))
4691 set_mem_size (arg1_rtx
, INTVAL (len_rtx
));
4692 set_mem_size (arg2_rtx
, INTVAL (len_rtx
));
4695 by_pieces_constfn constfn
= NULL
;
4697 /* Try to get the byte representation of the constant ARG2 (or, only
4698 when the function's result is used for equality to zero, ARG1)
4699 points to, with its byte size in NBYTES. */
4700 unsigned HOST_WIDE_INT nbytes
;
4701 const char *rep
= getbyterep (arg2
, &nbytes
);
4702 if (result_eq
&& rep
== NULL
)
4704 /* For equality to zero the arguments are interchangeable. */
4705 rep
= getbyterep (arg1
, &nbytes
);
4707 std::swap (arg1_rtx
, arg2_rtx
);
4710 /* If the function's constant bound LEN_RTX is less than or equal
4711 to the byte size of the representation of the constant argument,
4712 and if block move would be done by pieces, we can avoid loading
4713 the bytes from memory and only store the computed constant result. */
4715 && CONST_INT_P (len_rtx
)
4716 && (unsigned HOST_WIDE_INT
) INTVAL (len_rtx
) <= nbytes
)
4717 constfn
= builtin_memcpy_read_str
;
4719 result
= emit_block_cmp_hints (arg1_rtx
, arg2_rtx
, len_rtx
,
4720 TREE_TYPE (len
), target
,
4722 CONST_CAST (char *, rep
));
4726 /* Return the value in the proper mode for this function. */
4727 if (GET_MODE (result
) == mode
)
4732 convert_move (target
, result
, 0);
4736 return convert_to_mode (mode
, result
, 0);
4742 /* Expand expression EXP, which is a call to the strcmp builtin. Return NULL_RTX
4743 if we failed the caller should emit a normal call, otherwise try to get
4744 the result in TARGET, if convenient. */
4747 expand_builtin_strcmp (tree exp
, ATTRIBUTE_UNUSED rtx target
)
4749 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
4752 tree arg1
= CALL_EXPR_ARG (exp
, 0);
4753 tree arg2
= CALL_EXPR_ARG (exp
, 1);
4755 /* Due to the performance benefit, always inline the calls first. */
4756 rtx result
= NULL_RTX
;
4757 result
= inline_expand_builtin_bytecmp (exp
, target
);
4761 insn_code cmpstr_icode
= direct_optab_handler (cmpstr_optab
, SImode
);
4762 insn_code cmpstrn_icode
= direct_optab_handler (cmpstrn_optab
, SImode
);
4763 if (cmpstr_icode
== CODE_FOR_nothing
&& cmpstrn_icode
== CODE_FOR_nothing
)
4766 unsigned int arg1_align
= get_pointer_alignment (arg1
) / BITS_PER_UNIT
;
4767 unsigned int arg2_align
= get_pointer_alignment (arg2
) / BITS_PER_UNIT
;
4769 /* If we don't have POINTER_TYPE, call the function. */
4770 if (arg1_align
== 0 || arg2_align
== 0)
4773 /* Stabilize the arguments in case gen_cmpstr(n)si fail. */
4774 arg1
= builtin_save_expr (arg1
);
4775 arg2
= builtin_save_expr (arg2
);
4777 rtx arg1_rtx
= get_memory_rtx (arg1
, NULL
);
4778 rtx arg2_rtx
= get_memory_rtx (arg2
, NULL
);
4780 /* Try to call cmpstrsi. */
4781 if (cmpstr_icode
!= CODE_FOR_nothing
)
4782 result
= expand_cmpstr (cmpstr_icode
, target
, arg1_rtx
, arg2_rtx
,
4783 MIN (arg1_align
, arg2_align
));
4785 /* Try to determine at least one length and call cmpstrnsi. */
4786 if (!result
&& cmpstrn_icode
!= CODE_FOR_nothing
)
4791 tree len1
= c_strlen (arg1
, 1);
4792 tree len2
= c_strlen (arg2
, 1);
4795 len1
= size_binop (PLUS_EXPR
, ssize_int (1), len1
);
4797 len2
= size_binop (PLUS_EXPR
, ssize_int (1), len2
);
4799 /* If we don't have a constant length for the first, use the length
4800 of the second, if we know it. We don't require a constant for
4801 this case; some cost analysis could be done if both are available
4802 but neither is constant. For now, assume they're equally cheap,
4803 unless one has side effects. If both strings have constant lengths,
4810 else if (TREE_SIDE_EFFECTS (len1
))
4812 else if (TREE_SIDE_EFFECTS (len2
))
4814 else if (TREE_CODE (len1
) != INTEGER_CST
)
4816 else if (TREE_CODE (len2
) != INTEGER_CST
)
4818 else if (tree_int_cst_lt (len1
, len2
))
4823 /* If both arguments have side effects, we cannot optimize. */
4824 if (len
&& !TREE_SIDE_EFFECTS (len
))
4826 arg3_rtx
= expand_normal (len
);
4827 result
= expand_cmpstrn_or_cmpmem
4828 (cmpstrn_icode
, target
, arg1_rtx
, arg2_rtx
, TREE_TYPE (len
),
4829 arg3_rtx
, MIN (arg1_align
, arg2_align
));
4833 tree fndecl
= get_callee_fndecl (exp
);
4836 /* Return the value in the proper mode for this function. */
4837 machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
4838 if (GET_MODE (result
) == mode
)
4841 return convert_to_mode (mode
, result
, 0);
4842 convert_move (target
, result
, 0);
4846 /* Expand the library call ourselves using a stabilized argument
4847 list to avoid re-evaluating the function's arguments twice. */
4848 tree fn
= build_call_nofold_loc (EXPR_LOCATION (exp
), fndecl
, 2, arg1
, arg2
);
4849 copy_warning (fn
, exp
);
4850 gcc_assert (TREE_CODE (fn
) == CALL_EXPR
);
4851 CALL_EXPR_TAILCALL (fn
) = CALL_EXPR_TAILCALL (exp
);
4852 return expand_call (fn
, target
, target
== const0_rtx
);
4855 /* Expand expression EXP, which is a call to the strncmp builtin. Return
4856 NULL_RTX if we failed the caller should emit a normal call, otherwise
4857 try to get the result in TARGET, if convenient. */
4860 expand_builtin_strncmp (tree exp
, ATTRIBUTE_UNUSED rtx target
,
4861 ATTRIBUTE_UNUSED machine_mode mode
)
4863 if (!validate_arglist (exp
,
4864 POINTER_TYPE
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
4867 tree arg1
= CALL_EXPR_ARG (exp
, 0);
4868 tree arg2
= CALL_EXPR_ARG (exp
, 1);
4869 tree arg3
= CALL_EXPR_ARG (exp
, 2);
4871 location_t loc
= EXPR_LOCATION (exp
);
4872 tree len1
= c_strlen (arg1
, 1);
4873 tree len2
= c_strlen (arg2
, 1);
4875 /* Due to the performance benefit, always inline the calls first. */
4876 rtx result
= NULL_RTX
;
4877 result
= inline_expand_builtin_bytecmp (exp
, target
);
4881 /* If c_strlen can determine an expression for one of the string
4882 lengths, and it doesn't have side effects, then emit cmpstrnsi
4883 using length MIN(strlen(string)+1, arg3). */
4884 insn_code cmpstrn_icode
= direct_optab_handler (cmpstrn_optab
, SImode
);
4885 if (cmpstrn_icode
== CODE_FOR_nothing
)
4890 unsigned int arg1_align
= get_pointer_alignment (arg1
) / BITS_PER_UNIT
;
4891 unsigned int arg2_align
= get_pointer_alignment (arg2
) / BITS_PER_UNIT
;
4894 len1
= size_binop_loc (loc
, PLUS_EXPR
, ssize_int (1), len1
);
4896 len2
= size_binop_loc (loc
, PLUS_EXPR
, ssize_int (1), len2
);
4898 tree len3
= fold_convert_loc (loc
, sizetype
, arg3
);
4900 /* If we don't have a constant length for the first, use the length
4901 of the second, if we know it. If neither string is constant length,
4902 use the given length argument. We don't require a constant for
4903 this case; some cost analysis could be done if both are available
4904 but neither is constant. For now, assume they're equally cheap,
4905 unless one has side effects. If both strings have constant lengths,
4914 else if (TREE_SIDE_EFFECTS (len1
))
4916 else if (TREE_SIDE_EFFECTS (len2
))
4918 else if (TREE_CODE (len1
) != INTEGER_CST
)
4920 else if (TREE_CODE (len2
) != INTEGER_CST
)
4922 else if (tree_int_cst_lt (len1
, len2
))
4927 /* If we are not using the given length, we must incorporate it here.
4928 The actual new length parameter will be MIN(len,arg3) in this case. */
4931 len
= fold_convert_loc (loc
, sizetype
, len
);
4932 len
= fold_build2_loc (loc
, MIN_EXPR
, TREE_TYPE (len
), len
, len3
);
4934 rtx arg1_rtx
= get_memory_rtx (arg1
, len
);
4935 rtx arg2_rtx
= get_memory_rtx (arg2
, len
);
4936 rtx arg3_rtx
= expand_normal (len
);
4937 result
= expand_cmpstrn_or_cmpmem (cmpstrn_icode
, target
, arg1_rtx
,
4938 arg2_rtx
, TREE_TYPE (len
), arg3_rtx
,
4939 MIN (arg1_align
, arg2_align
));
4941 tree fndecl
= get_callee_fndecl (exp
);
4944 /* Return the value in the proper mode for this function. */
4945 mode
= TYPE_MODE (TREE_TYPE (exp
));
4946 if (GET_MODE (result
) == mode
)
4949 return convert_to_mode (mode
, result
, 0);
4950 convert_move (target
, result
, 0);
4954 /* Expand the library call ourselves using a stabilized argument
4955 list to avoid re-evaluating the function's arguments twice. */
4956 tree call
= build_call_nofold_loc (loc
, fndecl
, 3, arg1
, arg2
, len
);
4957 copy_warning (call
, exp
);
4958 gcc_assert (TREE_CODE (call
) == CALL_EXPR
);
4959 CALL_EXPR_TAILCALL (call
) = CALL_EXPR_TAILCALL (exp
);
4960 return expand_call (call
, target
, target
== const0_rtx
);
4963 /* Expand a call to __builtin_saveregs, generating the result in TARGET,
4964 if that's convenient. */
4967 expand_builtin_saveregs (void)
4972 /* Don't do __builtin_saveregs more than once in a function.
4973 Save the result of the first call and reuse it. */
4974 if (saveregs_value
!= 0)
4975 return saveregs_value
;
4977 /* When this function is called, it means that registers must be
4978 saved on entry to this function. So we migrate the call to the
4979 first insn of this function. */
4983 /* Do whatever the machine needs done in this case. */
4984 val
= targetm
.calls
.expand_builtin_saveregs ();
4989 saveregs_value
= val
;
4991 /* Put the insns after the NOTE that starts the function. If this
4992 is inside a start_sequence, make the outer-level insn chain current, so
4993 the code is placed at the start of the function. */
4994 push_topmost_sequence ();
4995 emit_insn_after (seq
, entry_of_function ());
4996 pop_topmost_sequence ();
5001 /* Expand a call to __builtin_next_arg. */
5004 expand_builtin_next_arg (void)
5006 /* Checking arguments is already done in fold_builtin_next_arg
5007 that must be called before this function. */
5008 return expand_binop (ptr_mode
, add_optab
,
5009 crtl
->args
.internal_arg_pointer
,
5010 crtl
->args
.arg_offset_rtx
,
5011 NULL_RTX
, 0, OPTAB_LIB_WIDEN
);
5014 /* Make it easier for the backends by protecting the valist argument
5015 from multiple evaluations. */
5018 stabilize_va_list_loc (location_t loc
, tree valist
, int needs_lvalue
)
5020 tree vatype
= targetm
.canonical_va_list_type (TREE_TYPE (valist
));
5022 /* The current way of determining the type of valist is completely
5023 bogus. We should have the information on the va builtin instead. */
5025 vatype
= targetm
.fn_abi_va_list (cfun
->decl
);
5027 if (TREE_CODE (vatype
) == ARRAY_TYPE
)
5029 if (TREE_SIDE_EFFECTS (valist
))
5030 valist
= save_expr (valist
);
5032 /* For this case, the backends will be expecting a pointer to
5033 vatype, but it's possible we've actually been given an array
5034 (an actual TARGET_CANONICAL_VA_LIST_TYPE (valist)).
5036 if (TREE_CODE (TREE_TYPE (valist
)) == ARRAY_TYPE
)
5038 tree p1
= build_pointer_type (TREE_TYPE (vatype
));
5039 valist
= build_fold_addr_expr_with_type_loc (loc
, valist
, p1
);
5044 tree pt
= build_pointer_type (vatype
);
5048 if (! TREE_SIDE_EFFECTS (valist
))
5051 valist
= fold_build1_loc (loc
, ADDR_EXPR
, pt
, valist
);
5052 TREE_SIDE_EFFECTS (valist
) = 1;
5055 if (TREE_SIDE_EFFECTS (valist
))
5056 valist
= save_expr (valist
);
5057 valist
= fold_build2_loc (loc
, MEM_REF
,
5058 vatype
, valist
, build_int_cst (pt
, 0));
5064 /* The "standard" definition of va_list is void*. */
5067 std_build_builtin_va_list (void)
5069 return ptr_type_node
;
5072 /* The "standard" abi va_list is va_list_type_node. */
5075 std_fn_abi_va_list (tree fndecl ATTRIBUTE_UNUSED
)
5077 return va_list_type_node
;
5080 /* The "standard" type of va_list is va_list_type_node. */
5083 std_canonical_va_list_type (tree type
)
5087 wtype
= va_list_type_node
;
5090 if (TREE_CODE (wtype
) == ARRAY_TYPE
)
5092 /* If va_list is an array type, the argument may have decayed
5093 to a pointer type, e.g. by being passed to another function.
5094 In that case, unwrap both types so that we can compare the
5095 underlying records. */
5096 if (TREE_CODE (htype
) == ARRAY_TYPE
5097 || POINTER_TYPE_P (htype
))
5099 wtype
= TREE_TYPE (wtype
);
5100 htype
= TREE_TYPE (htype
);
5103 if (TYPE_MAIN_VARIANT (wtype
) == TYPE_MAIN_VARIANT (htype
))
5104 return va_list_type_node
;
5109 /* The "standard" implementation of va_start: just assign `nextarg' to
5113 std_expand_builtin_va_start (tree valist
, rtx nextarg
)
5115 rtx va_r
= expand_expr (valist
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
5116 convert_move (va_r
, nextarg
, 0);
5119 /* Expand EXP, a call to __builtin_va_start. */
5122 expand_builtin_va_start (tree exp
)
5126 location_t loc
= EXPR_LOCATION (exp
);
5128 if (call_expr_nargs (exp
) < 2)
5130 error_at (loc
, "too few arguments to function %<va_start%>");
5134 if (fold_builtin_next_arg (exp
, true))
5137 nextarg
= expand_builtin_next_arg ();
5138 valist
= stabilize_va_list_loc (loc
, CALL_EXPR_ARG (exp
, 0), 1);
5140 if (targetm
.expand_builtin_va_start
)
5141 targetm
.expand_builtin_va_start (valist
, nextarg
);
5143 std_expand_builtin_va_start (valist
, nextarg
);
5148 /* Expand EXP, a call to __builtin_va_end. */
5151 expand_builtin_va_end (tree exp
)
5153 tree valist
= CALL_EXPR_ARG (exp
, 0);
5155 /* Evaluate for side effects, if needed. I hate macros that don't
5157 if (TREE_SIDE_EFFECTS (valist
))
5158 expand_expr (valist
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5163 /* Expand EXP, a call to __builtin_va_copy. We do this as a
5164 builtin rather than just as an assignment in stdarg.h because of the
5165 nastiness of array-type va_list types. */
5168 expand_builtin_va_copy (tree exp
)
5171 location_t loc
= EXPR_LOCATION (exp
);
5173 dst
= CALL_EXPR_ARG (exp
, 0);
5174 src
= CALL_EXPR_ARG (exp
, 1);
5176 dst
= stabilize_va_list_loc (loc
, dst
, 1);
5177 src
= stabilize_va_list_loc (loc
, src
, 0);
5179 gcc_assert (cfun
!= NULL
&& cfun
->decl
!= NULL_TREE
);
5181 if (TREE_CODE (targetm
.fn_abi_va_list (cfun
->decl
)) != ARRAY_TYPE
)
5183 t
= build2 (MODIFY_EXPR
, targetm
.fn_abi_va_list (cfun
->decl
), dst
, src
);
5184 TREE_SIDE_EFFECTS (t
) = 1;
5185 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
5189 rtx dstb
, srcb
, size
;
5191 /* Evaluate to pointers. */
5192 dstb
= expand_expr (dst
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
5193 srcb
= expand_expr (src
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
5194 size
= expand_expr (TYPE_SIZE_UNIT (targetm
.fn_abi_va_list (cfun
->decl
)),
5195 NULL_RTX
, VOIDmode
, EXPAND_NORMAL
);
5197 dstb
= convert_memory_address (Pmode
, dstb
);
5198 srcb
= convert_memory_address (Pmode
, srcb
);
5200 /* "Dereference" to BLKmode memories. */
5201 dstb
= gen_rtx_MEM (BLKmode
, dstb
);
5202 set_mem_alias_set (dstb
, get_alias_set (TREE_TYPE (TREE_TYPE (dst
))));
5203 set_mem_align (dstb
, TYPE_ALIGN (targetm
.fn_abi_va_list (cfun
->decl
)));
5204 srcb
= gen_rtx_MEM (BLKmode
, srcb
);
5205 set_mem_alias_set (srcb
, get_alias_set (TREE_TYPE (TREE_TYPE (src
))));
5206 set_mem_align (srcb
, TYPE_ALIGN (targetm
.fn_abi_va_list (cfun
->decl
)));
5209 emit_block_move (dstb
, srcb
, size
, BLOCK_OP_NORMAL
);
5215 /* Expand a call to one of the builtin functions __builtin_frame_address or
5216 __builtin_return_address. */
5219 expand_builtin_frame_address (tree fndecl
, tree exp
)
5221 /* The argument must be a nonnegative integer constant.
5222 It counts the number of frames to scan up the stack.
5223 The value is either the frame pointer value or the return
5224 address saved in that frame. */
5225 if (call_expr_nargs (exp
) == 0)
5226 /* Warning about missing arg was already issued. */
5228 else if (! tree_fits_uhwi_p (CALL_EXPR_ARG (exp
, 0)))
5230 error ("invalid argument to %qD", fndecl
);
5235 /* Number of frames to scan up the stack. */
5236 unsigned HOST_WIDE_INT count
= tree_to_uhwi (CALL_EXPR_ARG (exp
, 0));
5238 rtx tem
= expand_builtin_return_addr (DECL_FUNCTION_CODE (fndecl
), count
);
5240 /* Some ports cannot access arbitrary stack frames. */
5243 warning (0, "unsupported argument to %qD", fndecl
);
5249 /* Warn since no effort is made to ensure that any frame
5250 beyond the current one exists or can be safely reached. */
5251 warning (OPT_Wframe_address
, "calling %qD with "
5252 "a nonzero argument is unsafe", fndecl
);
5255 /* For __builtin_frame_address, return what we've got. */
5256 if (DECL_FUNCTION_CODE (fndecl
) == BUILT_IN_FRAME_ADDRESS
)
5260 && ! CONSTANT_P (tem
))
5261 tem
= copy_addr_to_reg (tem
);
5266 /* Expand EXP, a call to the alloca builtin. Return NULL_RTX if we
5267 failed and the caller should emit a normal call. */
5270 expand_builtin_alloca (tree exp
)
5275 tree fndecl
= get_callee_fndecl (exp
);
5276 HOST_WIDE_INT max_size
;
5277 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
5278 bool alloca_for_var
= CALL_ALLOCA_FOR_VAR_P (exp
);
5280 = (fcode
== BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX
5281 ? validate_arglist (exp
, INTEGER_TYPE
, INTEGER_TYPE
, INTEGER_TYPE
,
5283 : fcode
== BUILT_IN_ALLOCA_WITH_ALIGN
5284 ? validate_arglist (exp
, INTEGER_TYPE
, INTEGER_TYPE
, VOID_TYPE
)
5285 : validate_arglist (exp
, INTEGER_TYPE
, VOID_TYPE
));
5290 /* Compute the argument. */
5291 op0
= expand_normal (CALL_EXPR_ARG (exp
, 0));
5293 /* Compute the alignment. */
5294 align
= (fcode
== BUILT_IN_ALLOCA
5296 : TREE_INT_CST_LOW (CALL_EXPR_ARG (exp
, 1)));
5298 /* Compute the maximum size. */
5299 max_size
= (fcode
== BUILT_IN_ALLOCA_WITH_ALIGN_AND_MAX
5300 ? TREE_INT_CST_LOW (CALL_EXPR_ARG (exp
, 2))
5303 /* Allocate the desired space. If the allocation stems from the declaration
5304 of a variable-sized object, it cannot accumulate. */
5306 = allocate_dynamic_stack_space (op0
, 0, align
, max_size
, alloca_for_var
);
5307 result
= convert_memory_address (ptr_mode
, result
);
5309 /* Dynamic allocations for variables are recorded during gimplification. */
5310 if (!alloca_for_var
&& (flag_callgraph_info
& CALLGRAPH_INFO_DYNAMIC_ALLOC
))
5311 record_dynamic_alloc (exp
);
5316 /* Emit a call to __asan_allocas_unpoison call in EXP. Add to second argument
5317 of the call virtual_stack_dynamic_rtx - stack_pointer_rtx, which is the
5318 STACK_DYNAMIC_OFFSET value. See motivation for this in comment to
5319 handle_builtin_stack_restore function. */
5322 expand_asan_emit_allocas_unpoison (tree exp
)
5324 tree arg0
= CALL_EXPR_ARG (exp
, 0);
5325 tree arg1
= CALL_EXPR_ARG (exp
, 1);
5326 rtx top
= expand_expr (arg0
, NULL_RTX
, ptr_mode
, EXPAND_NORMAL
);
5327 rtx bot
= expand_expr (arg1
, NULL_RTX
, ptr_mode
, EXPAND_NORMAL
);
5328 rtx off
= expand_simple_binop (Pmode
, MINUS
, virtual_stack_dynamic_rtx
,
5329 stack_pointer_rtx
, NULL_RTX
, 0,
5331 off
= convert_modes (ptr_mode
, Pmode
, off
, 0);
5332 bot
= expand_simple_binop (ptr_mode
, PLUS
, bot
, off
, NULL_RTX
, 0,
5334 rtx ret
= init_one_libfunc ("__asan_allocas_unpoison");
5335 ret
= emit_library_call_value (ret
, NULL_RTX
, LCT_NORMAL
, ptr_mode
,
5336 top
, ptr_mode
, bot
, ptr_mode
);
5340 /* Expand a call to bswap builtin in EXP.
5341 Return NULL_RTX if a normal call should be emitted rather than expanding the
5342 function in-line. If convenient, the result should be placed in TARGET.
5343 SUBTARGET may be used as the target for computing one of EXP's operands. */
5346 expand_builtin_bswap (machine_mode target_mode
, tree exp
, rtx target
,
5352 if (!validate_arglist (exp
, INTEGER_TYPE
, VOID_TYPE
))
5355 arg
= CALL_EXPR_ARG (exp
, 0);
5356 op0
= expand_expr (arg
,
5357 subtarget
&& GET_MODE (subtarget
) == target_mode
5358 ? subtarget
: NULL_RTX
,
5359 target_mode
, EXPAND_NORMAL
);
5360 if (GET_MODE (op0
) != target_mode
)
5361 op0
= convert_to_mode (target_mode
, op0
, 1);
5363 target
= expand_unop (target_mode
, bswap_optab
, op0
, target
, 1);
5365 gcc_assert (target
);
5367 return convert_to_mode (target_mode
, target
, 1);
5370 /* Expand a call to a unary builtin in EXP.
5371 Return NULL_RTX if a normal call should be emitted rather than expanding the
5372 function in-line. If convenient, the result should be placed in TARGET.
5373 SUBTARGET may be used as the target for computing one of EXP's operands. */
5376 expand_builtin_unop (machine_mode target_mode
, tree exp
, rtx target
,
5377 rtx subtarget
, optab op_optab
)
5381 if (!validate_arglist (exp
, INTEGER_TYPE
, VOID_TYPE
))
5384 /* Compute the argument. */
5385 op0
= expand_expr (CALL_EXPR_ARG (exp
, 0),
5387 && (TYPE_MODE (TREE_TYPE (CALL_EXPR_ARG (exp
, 0)))
5388 == GET_MODE (subtarget
))) ? subtarget
: NULL_RTX
,
5389 VOIDmode
, EXPAND_NORMAL
);
5390 /* Compute op, into TARGET if possible.
5391 Set TARGET to wherever the result comes back. */
5392 target
= expand_unop (TYPE_MODE (TREE_TYPE (CALL_EXPR_ARG (exp
, 0))),
5393 op_optab
, op0
, target
, op_optab
!= clrsb_optab
);
5394 gcc_assert (target
);
5396 return convert_to_mode (target_mode
, target
, 0);
5399 /* Expand a call to __builtin_expect. We just return our argument
5400 as the builtin_expect semantic should've been already executed by
5401 tree branch prediction pass. */
5404 expand_builtin_expect (tree exp
, rtx target
)
5408 if (call_expr_nargs (exp
) < 2)
5410 arg
= CALL_EXPR_ARG (exp
, 0);
5412 target
= expand_expr (arg
, target
, VOIDmode
, EXPAND_NORMAL
);
5413 /* When guessing was done, the hints should be already stripped away. */
5414 gcc_assert (!flag_guess_branch_prob
5415 || optimize
== 0 || seen_error ());
5419 /* Expand a call to __builtin_expect_with_probability. We just return our
5420 argument as the builtin_expect semantic should've been already executed by
5421 tree branch prediction pass. */
5424 expand_builtin_expect_with_probability (tree exp
, rtx target
)
5428 if (call_expr_nargs (exp
) < 3)
5430 arg
= CALL_EXPR_ARG (exp
, 0);
5432 target
= expand_expr (arg
, target
, VOIDmode
, EXPAND_NORMAL
);
5433 /* When guessing was done, the hints should be already stripped away. */
5434 gcc_assert (!flag_guess_branch_prob
5435 || optimize
== 0 || seen_error ());
5440 /* Expand a call to __builtin_assume_aligned. We just return our first
5441 argument as the builtin_assume_aligned semantic should've been already
5445 expand_builtin_assume_aligned (tree exp
, rtx target
)
5447 if (call_expr_nargs (exp
) < 2)
5449 target
= expand_expr (CALL_EXPR_ARG (exp
, 0), target
, VOIDmode
,
5451 gcc_assert (!TREE_SIDE_EFFECTS (CALL_EXPR_ARG (exp
, 1))
5452 && (call_expr_nargs (exp
) < 3
5453 || !TREE_SIDE_EFFECTS (CALL_EXPR_ARG (exp
, 2))));
5458 expand_builtin_trap (void)
5460 if (targetm
.have_trap ())
5462 rtx_insn
*insn
= emit_insn (targetm
.gen_trap ());
5463 /* For trap insns when not accumulating outgoing args force
5464 REG_ARGS_SIZE note to prevent crossjumping of calls with
5465 different args sizes. */
5466 if (!ACCUMULATE_OUTGOING_ARGS
)
5467 add_args_size_note (insn
, stack_pointer_delta
);
5471 tree fn
= builtin_decl_implicit (BUILT_IN_ABORT
);
5472 tree call_expr
= build_call_expr (fn
, 0);
5473 expand_call (call_expr
, NULL_RTX
, false);
5479 /* Expand a call to __builtin_unreachable. We do nothing except emit
5480 a barrier saying that control flow will not pass here.
5482 It is the responsibility of the program being compiled to ensure
5483 that control flow does never reach __builtin_unreachable. */
5485 expand_builtin_unreachable (void)
5487 /* Use gimple_build_builtin_unreachable or builtin_decl_unreachable
5489 gcc_checking_assert (!sanitize_flags_p (SANITIZE_UNREACHABLE
));
5493 /* Expand EXP, a call to fabs, fabsf or fabsl.
5494 Return NULL_RTX if a normal call should be emitted rather than expanding
5495 the function inline. If convenient, the result should be placed
5496 in TARGET. SUBTARGET may be used as the target for computing
5500 expand_builtin_fabs (tree exp
, rtx target
, rtx subtarget
)
5506 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
5509 arg
= CALL_EXPR_ARG (exp
, 0);
5510 CALL_EXPR_ARG (exp
, 0) = arg
= builtin_save_expr (arg
);
5511 mode
= TYPE_MODE (TREE_TYPE (arg
));
5512 op0
= expand_expr (arg
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
5513 return expand_abs (mode
, op0
, target
, 0, safe_from_p (target
, arg
, 1));
5516 /* Expand EXP, a call to copysign, copysignf, or copysignl.
5517 Return NULL is a normal call should be emitted rather than expanding the
5518 function inline. If convenient, the result should be placed in TARGET.
5519 SUBTARGET may be used as the target for computing the operand. */
5522 expand_builtin_copysign (tree exp
, rtx target
, rtx subtarget
)
5527 if (!validate_arglist (exp
, REAL_TYPE
, REAL_TYPE
, VOID_TYPE
))
5530 arg
= CALL_EXPR_ARG (exp
, 0);
5531 op0
= expand_expr (arg
, subtarget
, VOIDmode
, EXPAND_NORMAL
);
5533 arg
= CALL_EXPR_ARG (exp
, 1);
5534 op1
= expand_normal (arg
);
5536 return expand_copysign (op0
, op1
, target
);
5539 /* Emit a call to __builtin___clear_cache. */
5542 default_emit_call_builtin___clear_cache (rtx begin
, rtx end
)
5544 rtx callee
= gen_rtx_SYMBOL_REF (Pmode
,
5545 BUILTIN_ASM_NAME_PTR
5546 (BUILT_IN_CLEAR_CACHE
));
5548 emit_library_call (callee
,
5549 LCT_NORMAL
, VOIDmode
,
5550 convert_memory_address (ptr_mode
, begin
), ptr_mode
,
5551 convert_memory_address (ptr_mode
, end
), ptr_mode
);
5554 /* Emit a call to __builtin___clear_cache, unless the target specifies
5555 it as do-nothing. This function can be used by trampoline
5556 finalizers to duplicate the effects of expanding a call to the
5557 clear_cache builtin. */
5560 maybe_emit_call_builtin___clear_cache (rtx begin
, rtx end
)
5562 gcc_assert ((GET_MODE (begin
) == ptr_mode
|| GET_MODE (begin
) == Pmode
5563 || CONST_INT_P (begin
))
5564 && (GET_MODE (end
) == ptr_mode
|| GET_MODE (end
) == Pmode
5565 || CONST_INT_P (end
)));
5567 if (targetm
.have_clear_cache ())
5569 /* We have a "clear_cache" insn, and it will handle everything. */
5570 class expand_operand ops
[2];
5572 create_address_operand (&ops
[0], begin
);
5573 create_address_operand (&ops
[1], end
);
5575 if (maybe_expand_insn (targetm
.code_for_clear_cache
, 2, ops
))
5580 #ifndef CLEAR_INSN_CACHE
5581 /* There is no "clear_cache" insn, and __clear_cache() in libgcc
5582 does nothing. There is no need to call it. Do nothing. */
5584 #endif /* CLEAR_INSN_CACHE */
5587 targetm
.calls
.emit_call_builtin___clear_cache (begin
, end
);
5590 /* Expand a call to __builtin___clear_cache. */
5593 expand_builtin___clear_cache (tree exp
)
5596 rtx begin_rtx
, end_rtx
;
5598 /* We must not expand to a library call. If we did, any
5599 fallback library function in libgcc that might contain a call to
5600 __builtin___clear_cache() would recurse infinitely. */
5601 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
5603 error ("both arguments to %<__builtin___clear_cache%> must be pointers");
5607 begin
= CALL_EXPR_ARG (exp
, 0);
5608 begin_rtx
= expand_expr (begin
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
5610 end
= CALL_EXPR_ARG (exp
, 1);
5611 end_rtx
= expand_expr (end
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
5613 maybe_emit_call_builtin___clear_cache (begin_rtx
, end_rtx
);
5616 /* Given a trampoline address, make sure it satisfies TRAMPOLINE_ALIGNMENT. */
5619 round_trampoline_addr (rtx tramp
)
5621 rtx temp
, addend
, mask
;
5623 /* If we don't need too much alignment, we'll have been guaranteed
5624 proper alignment by get_trampoline_type. */
5625 if (TRAMPOLINE_ALIGNMENT
<= STACK_BOUNDARY
)
5628 /* Round address up to desired boundary. */
5629 temp
= gen_reg_rtx (Pmode
);
5630 addend
= gen_int_mode (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
- 1, Pmode
);
5631 mask
= gen_int_mode (-TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
, Pmode
);
5633 temp
= expand_simple_binop (Pmode
, PLUS
, tramp
, addend
,
5634 temp
, 0, OPTAB_LIB_WIDEN
);
5635 tramp
= expand_simple_binop (Pmode
, AND
, temp
, mask
,
5636 temp
, 0, OPTAB_LIB_WIDEN
);
5642 expand_builtin_init_trampoline (tree exp
, bool onstack
)
5644 tree t_tramp
, t_func
, t_chain
;
5645 rtx m_tramp
, r_tramp
, r_chain
, tmp
;
5647 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
,
5648 POINTER_TYPE
, VOID_TYPE
))
5651 t_tramp
= CALL_EXPR_ARG (exp
, 0);
5652 t_func
= CALL_EXPR_ARG (exp
, 1);
5653 t_chain
= CALL_EXPR_ARG (exp
, 2);
5655 r_tramp
= expand_normal (t_tramp
);
5656 m_tramp
= gen_rtx_MEM (BLKmode
, r_tramp
);
5657 MEM_NOTRAP_P (m_tramp
) = 1;
5659 /* If ONSTACK, the TRAMP argument should be the address of a field
5660 within the local function's FRAME decl. Either way, let's see if
5661 we can fill in the MEM_ATTRs for this memory. */
5662 if (TREE_CODE (t_tramp
) == ADDR_EXPR
)
5663 set_mem_attributes (m_tramp
, TREE_OPERAND (t_tramp
, 0), true);
5665 /* Creator of a heap trampoline is responsible for making sure the
5666 address is aligned to at least STACK_BOUNDARY. Normally malloc
5667 will ensure this anyhow. */
5668 tmp
= round_trampoline_addr (r_tramp
);
5671 m_tramp
= change_address (m_tramp
, BLKmode
, tmp
);
5672 set_mem_align (m_tramp
, TRAMPOLINE_ALIGNMENT
);
5673 set_mem_size (m_tramp
, TRAMPOLINE_SIZE
);
5676 /* The FUNC argument should be the address of the nested function.
5677 Extract the actual function decl to pass to the hook. */
5678 gcc_assert (TREE_CODE (t_func
) == ADDR_EXPR
);
5679 t_func
= TREE_OPERAND (t_func
, 0);
5680 gcc_assert (TREE_CODE (t_func
) == FUNCTION_DECL
);
5682 r_chain
= expand_normal (t_chain
);
5684 /* Generate insns to initialize the trampoline. */
5685 targetm
.calls
.trampoline_init (m_tramp
, t_func
, r_chain
);
5689 trampolines_created
= 1;
5691 if (targetm
.calls
.custom_function_descriptors
!= 0)
5692 warning_at (DECL_SOURCE_LOCATION (t_func
), OPT_Wtrampolines
,
5693 "trampoline generated for nested function %qD", t_func
);
5700 expand_builtin_adjust_trampoline (tree exp
)
5704 if (!validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
5707 tramp
= expand_normal (CALL_EXPR_ARG (exp
, 0));
5708 tramp
= round_trampoline_addr (tramp
);
5709 if (targetm
.calls
.trampoline_adjust_address
)
5710 tramp
= targetm
.calls
.trampoline_adjust_address (tramp
);
5715 /* Expand a call to the builtin descriptor initialization routine.
5716 A descriptor is made up of a couple of pointers to the static
5717 chain and the code entry in this order. */
5720 expand_builtin_init_descriptor (tree exp
)
5722 tree t_descr
, t_func
, t_chain
;
5723 rtx m_descr
, r_descr
, r_func
, r_chain
;
5725 if (!validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, POINTER_TYPE
,
5729 t_descr
= CALL_EXPR_ARG (exp
, 0);
5730 t_func
= CALL_EXPR_ARG (exp
, 1);
5731 t_chain
= CALL_EXPR_ARG (exp
, 2);
5733 r_descr
= expand_normal (t_descr
);
5734 m_descr
= gen_rtx_MEM (BLKmode
, r_descr
);
5735 MEM_NOTRAP_P (m_descr
) = 1;
5736 set_mem_align (m_descr
, GET_MODE_ALIGNMENT (ptr_mode
));
5738 r_func
= expand_normal (t_func
);
5739 r_chain
= expand_normal (t_chain
);
5741 /* Generate insns to initialize the descriptor. */
5742 emit_move_insn (adjust_address_nv (m_descr
, ptr_mode
, 0), r_chain
);
5743 emit_move_insn (adjust_address_nv (m_descr
, ptr_mode
,
5744 POINTER_SIZE
/ BITS_PER_UNIT
), r_func
);
5749 /* Expand a call to the builtin descriptor adjustment routine. */
5752 expand_builtin_adjust_descriptor (tree exp
)
5756 if (!validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
5759 tramp
= expand_normal (CALL_EXPR_ARG (exp
, 0));
5761 /* Unalign the descriptor to allow runtime identification. */
5762 tramp
= plus_constant (ptr_mode
, tramp
,
5763 targetm
.calls
.custom_function_descriptors
);
5765 return force_operand (tramp
, NULL_RTX
);
5768 /* Expand the call EXP to the built-in signbit, signbitf or signbitl
5769 function. The function first checks whether the back end provides
5770 an insn to implement signbit for the respective mode. If not, it
5771 checks whether the floating point format of the value is such that
5772 the sign bit can be extracted. If that is not the case, error out.
5773 EXP is the expression that is a call to the builtin function; if
5774 convenient, the result should be placed in TARGET. */
5776 expand_builtin_signbit (tree exp
, rtx target
)
5778 const struct real_format
*fmt
;
5779 scalar_float_mode fmode
;
5780 scalar_int_mode rmode
, imode
;
5783 enum insn_code icode
;
5785 location_t loc
= EXPR_LOCATION (exp
);
5787 if (!validate_arglist (exp
, REAL_TYPE
, VOID_TYPE
))
5790 arg
= CALL_EXPR_ARG (exp
, 0);
5791 fmode
= SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (arg
));
5792 rmode
= SCALAR_INT_TYPE_MODE (TREE_TYPE (exp
));
5793 fmt
= REAL_MODE_FORMAT (fmode
);
5795 arg
= builtin_save_expr (arg
);
5797 /* Expand the argument yielding a RTX expression. */
5798 temp
= expand_normal (arg
);
5800 /* Check if the back end provides an insn that handles signbit for the
5802 icode
= optab_handler (signbit_optab
, fmode
);
5803 if (icode
!= CODE_FOR_nothing
)
5805 rtx_insn
*last
= get_last_insn ();
5806 rtx this_target
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp
)));
5807 if (maybe_emit_unop_insn (icode
, this_target
, temp
, UNKNOWN
))
5809 delete_insns_since (last
);
5812 /* For floating point formats without a sign bit, implement signbit
5814 bitpos
= fmt
->signbit_ro
;
5817 /* But we can't do this if the format supports signed zero. */
5818 gcc_assert (!fmt
->has_signed_zero
|| !HONOR_SIGNED_ZEROS (fmode
));
5820 arg
= fold_build2_loc (loc
, LT_EXPR
, TREE_TYPE (exp
), arg
,
5821 build_real (TREE_TYPE (arg
), dconst0
));
5822 return expand_expr (arg
, target
, VOIDmode
, EXPAND_NORMAL
);
5825 if (GET_MODE_SIZE (fmode
) <= UNITS_PER_WORD
)
5827 imode
= int_mode_for_mode (fmode
).require ();
5828 temp
= gen_lowpart (imode
, temp
);
5833 /* Handle targets with different FP word orders. */
5834 if (FLOAT_WORDS_BIG_ENDIAN
)
5835 word
= (GET_MODE_BITSIZE (fmode
) - bitpos
) / BITS_PER_WORD
;
5837 word
= bitpos
/ BITS_PER_WORD
;
5838 temp
= operand_subword_force (temp
, word
, fmode
);
5839 bitpos
= bitpos
% BITS_PER_WORD
;
5842 /* Force the intermediate word_mode (or narrower) result into a
5843 register. This avoids attempting to create paradoxical SUBREGs
5844 of floating point modes below. */
5845 temp
= force_reg (imode
, temp
);
5847 /* If the bitpos is within the "result mode" lowpart, the operation
5848 can be implement with a single bitwise AND. Otherwise, we need
5849 a right shift and an AND. */
5851 if (bitpos
< GET_MODE_BITSIZE (rmode
))
5853 wide_int mask
= wi::set_bit_in_zero (bitpos
, GET_MODE_PRECISION (rmode
));
5855 if (GET_MODE_SIZE (imode
) > GET_MODE_SIZE (rmode
))
5856 temp
= gen_lowpart (rmode
, temp
);
5857 temp
= expand_binop (rmode
, and_optab
, temp
,
5858 immed_wide_int_const (mask
, rmode
),
5859 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
5863 /* Perform a logical right shift to place the signbit in the least
5864 significant bit, then truncate the result to the desired mode
5865 and mask just this bit. */
5866 temp
= expand_shift (RSHIFT_EXPR
, imode
, temp
, bitpos
, NULL_RTX
, 1);
5867 temp
= gen_lowpart (rmode
, temp
);
5868 temp
= expand_binop (rmode
, and_optab
, temp
, const1_rtx
,
5869 NULL_RTX
, 1, OPTAB_LIB_WIDEN
);
5875 /* Expand fork or exec calls. TARGET is the desired target of the
5876 call. EXP is the call. FN is the
5877 identificator of the actual function. IGNORE is nonzero if the
5878 value is to be ignored. */
5881 expand_builtin_fork_or_exec (tree fn
, tree exp
, rtx target
, int ignore
)
5886 /* If we are not profiling, just call the function. */
5887 if (!profile_arc_flag
)
5890 /* Otherwise call the wrapper. This should be equivalent for the rest of
5891 compiler, so the code does not diverge, and the wrapper may run the
5892 code necessary for keeping the profiling sane. */
5894 switch (DECL_FUNCTION_CODE (fn
))
5897 id
= get_identifier ("__gcov_fork");
5900 case BUILT_IN_EXECL
:
5901 id
= get_identifier ("__gcov_execl");
5904 case BUILT_IN_EXECV
:
5905 id
= get_identifier ("__gcov_execv");
5908 case BUILT_IN_EXECLP
:
5909 id
= get_identifier ("__gcov_execlp");
5912 case BUILT_IN_EXECLE
:
5913 id
= get_identifier ("__gcov_execle");
5916 case BUILT_IN_EXECVP
:
5917 id
= get_identifier ("__gcov_execvp");
5920 case BUILT_IN_EXECVE
:
5921 id
= get_identifier ("__gcov_execve");
5928 decl
= build_decl (DECL_SOURCE_LOCATION (fn
),
5929 FUNCTION_DECL
, id
, TREE_TYPE (fn
));
5930 DECL_EXTERNAL (decl
) = 1;
5931 TREE_PUBLIC (decl
) = 1;
5932 DECL_ARTIFICIAL (decl
) = 1;
5933 TREE_NOTHROW (decl
) = 1;
5934 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
5935 DECL_VISIBILITY_SPECIFIED (decl
) = 1;
5936 call
= rewrite_call_expr (EXPR_LOCATION (exp
), exp
, 0, decl
, 0);
5937 return expand_call (call
, target
, ignore
);
5942 /* Reconstitute a mode for a __sync intrinsic operation. Since the type of
5943 the pointer in these functions is void*, the tree optimizers may remove
5944 casts. The mode computed in expand_builtin isn't reliable either, due
5945 to __sync_bool_compare_and_swap.
5947 FCODE_DIFF should be fcode - base, where base is the FOO_1 code for the
5948 group of builtins. This gives us log2 of the mode size. */
5950 static inline machine_mode
5951 get_builtin_sync_mode (int fcode_diff
)
5953 /* The size is not negotiable, so ask not to get BLKmode in return
5954 if the target indicates that a smaller size would be better. */
5955 return int_mode_for_size (BITS_PER_UNIT
<< fcode_diff
, 0).require ();
5958 /* Expand the memory expression LOC and return the appropriate memory operand
5959 for the builtin_sync operations. */
5962 get_builtin_sync_mem (tree loc
, machine_mode mode
)
5965 int addr_space
= TYPE_ADDR_SPACE (POINTER_TYPE_P (TREE_TYPE (loc
))
5966 ? TREE_TYPE (TREE_TYPE (loc
))
5968 scalar_int_mode addr_mode
= targetm
.addr_space
.address_mode (addr_space
);
5970 addr
= expand_expr (loc
, NULL_RTX
, addr_mode
, EXPAND_SUM
);
5971 addr
= convert_memory_address (addr_mode
, addr
);
5973 /* Note that we explicitly do not want any alias information for this
5974 memory, so that we kill all other live memories. Otherwise we don't
5975 satisfy the full barrier semantics of the intrinsic. */
5976 mem
= gen_rtx_MEM (mode
, addr
);
5978 set_mem_addr_space (mem
, addr_space
);
5980 mem
= validize_mem (mem
);
5982 /* The alignment needs to be at least according to that of the mode. */
5983 set_mem_align (mem
, MAX (GET_MODE_ALIGNMENT (mode
),
5984 get_pointer_alignment (loc
)));
5985 set_mem_alias_set (mem
, ALIAS_SET_MEMORY_BARRIER
);
5986 MEM_VOLATILE_P (mem
) = 1;
5991 /* Make sure an argument is in the right mode.
5992 EXP is the tree argument.
5993 MODE is the mode it should be in. */
5996 expand_expr_force_mode (tree exp
, machine_mode mode
)
5999 machine_mode old_mode
;
6001 if (TREE_CODE (exp
) == SSA_NAME
6002 && TYPE_MODE (TREE_TYPE (exp
)) != mode
)
6004 /* Undo argument promotion if possible, as combine might not
6005 be able to do it later due to MEM_VOLATILE_P uses in the
6007 gimple
*g
= get_gimple_for_ssa_name (exp
);
6008 if (g
&& gimple_assign_cast_p (g
))
6010 tree rhs
= gimple_assign_rhs1 (g
);
6011 tree_code code
= gimple_assign_rhs_code (g
);
6012 if (CONVERT_EXPR_CODE_P (code
)
6013 && TYPE_MODE (TREE_TYPE (rhs
)) == mode
6014 && INTEGRAL_TYPE_P (TREE_TYPE (exp
))
6015 && INTEGRAL_TYPE_P (TREE_TYPE (rhs
))
6016 && (TYPE_PRECISION (TREE_TYPE (exp
))
6017 > TYPE_PRECISION (TREE_TYPE (rhs
))))
6022 val
= expand_expr (exp
, NULL_RTX
, mode
, EXPAND_NORMAL
);
6023 /* If VAL is promoted to a wider mode, convert it back to MODE. Take care
6024 of CONST_INTs, where we know the old_mode only from the call argument. */
6026 old_mode
= GET_MODE (val
);
6027 if (old_mode
== VOIDmode
)
6028 old_mode
= TYPE_MODE (TREE_TYPE (exp
));
6029 val
= convert_modes (mode
, old_mode
, val
, 1);
6034 /* Expand the __sync_xxx_and_fetch and __sync_fetch_and_xxx intrinsics.
6035 EXP is the CALL_EXPR. CODE is the rtx code
6036 that corresponds to the arithmetic or logical operation from the name;
6037 an exception here is that NOT actually means NAND. TARGET is an optional
6038 place for us to store the results; AFTER is true if this is the
6039 fetch_and_xxx form. */
6042 expand_builtin_sync_operation (machine_mode mode
, tree exp
,
6043 enum rtx_code code
, bool after
,
6047 location_t loc
= EXPR_LOCATION (exp
);
6049 if (code
== NOT
&& warn_sync_nand
)
6051 tree fndecl
= get_callee_fndecl (exp
);
6052 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
6054 static bool warned_f_a_n
, warned_n_a_f
;
6058 case BUILT_IN_SYNC_FETCH_AND_NAND_1
:
6059 case BUILT_IN_SYNC_FETCH_AND_NAND_2
:
6060 case BUILT_IN_SYNC_FETCH_AND_NAND_4
:
6061 case BUILT_IN_SYNC_FETCH_AND_NAND_8
:
6062 case BUILT_IN_SYNC_FETCH_AND_NAND_16
:
6066 fndecl
= builtin_decl_implicit (BUILT_IN_SYNC_FETCH_AND_NAND_N
);
6067 inform (loc
, "%qD changed semantics in GCC 4.4", fndecl
);
6068 warned_f_a_n
= true;
6071 case BUILT_IN_SYNC_NAND_AND_FETCH_1
:
6072 case BUILT_IN_SYNC_NAND_AND_FETCH_2
:
6073 case BUILT_IN_SYNC_NAND_AND_FETCH_4
:
6074 case BUILT_IN_SYNC_NAND_AND_FETCH_8
:
6075 case BUILT_IN_SYNC_NAND_AND_FETCH_16
:
6079 fndecl
= builtin_decl_implicit (BUILT_IN_SYNC_NAND_AND_FETCH_N
);
6080 inform (loc
, "%qD changed semantics in GCC 4.4", fndecl
);
6081 warned_n_a_f
= true;
6089 /* Expand the operands. */
6090 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6091 val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 1), mode
);
6093 return expand_atomic_fetch_op (target
, mem
, val
, code
, MEMMODEL_SYNC_SEQ_CST
,
6097 /* Expand the __sync_val_compare_and_swap and __sync_bool_compare_and_swap
6098 intrinsics. EXP is the CALL_EXPR. IS_BOOL is
6099 true if this is the boolean form. TARGET is a place for us to store the
6100 results; this is NOT optional if IS_BOOL is true. */
6103 expand_builtin_compare_and_swap (machine_mode mode
, tree exp
,
6104 bool is_bool
, rtx target
)
6106 rtx old_val
, new_val
, mem
;
6109 /* Expand the operands. */
6110 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6111 old_val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 1), mode
);
6112 new_val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 2), mode
);
6114 pbool
= poval
= NULL
;
6115 if (target
!= const0_rtx
)
6122 if (!expand_atomic_compare_and_swap (pbool
, poval
, mem
, old_val
, new_val
,
6123 false, MEMMODEL_SYNC_SEQ_CST
,
6124 MEMMODEL_SYNC_SEQ_CST
))
6130 /* Expand the __sync_lock_test_and_set intrinsic. Note that the most
6131 general form is actually an atomic exchange, and some targets only
6132 support a reduced form with the second argument being a constant 1.
6133 EXP is the CALL_EXPR; TARGET is an optional place for us to store
6137 expand_builtin_sync_lock_test_and_set (machine_mode mode
, tree exp
,
6142 /* Expand the operands. */
6143 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6144 val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 1), mode
);
6146 return expand_sync_lock_test_and_set (target
, mem
, val
);
6149 /* Expand the __sync_lock_release intrinsic. EXP is the CALL_EXPR. */
6152 expand_builtin_sync_lock_release (machine_mode mode
, tree exp
)
6156 /* Expand the operands. */
6157 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6159 expand_atomic_store (mem
, const0_rtx
, MEMMODEL_SYNC_RELEASE
, true);
6162 /* Given an integer representing an ``enum memmodel'', verify its
6163 correctness and return the memory model enum. */
6165 static enum memmodel
6166 get_memmodel (tree exp
)
6168 /* If the parameter is not a constant, it's a run time value so we'll just
6169 convert it to MEMMODEL_SEQ_CST to avoid annoying runtime checking. */
6170 if (TREE_CODE (exp
) != INTEGER_CST
)
6171 return MEMMODEL_SEQ_CST
;
6173 rtx op
= expand_normal (exp
);
6175 unsigned HOST_WIDE_INT val
= INTVAL (op
);
6176 if (targetm
.memmodel_check
)
6177 val
= targetm
.memmodel_check (val
);
6178 else if (val
& ~MEMMODEL_MASK
)
6179 return MEMMODEL_SEQ_CST
;
6181 /* Should never see a user explicit SYNC memodel model, so >= LAST works. */
6182 if (memmodel_base (val
) >= MEMMODEL_LAST
)
6183 return MEMMODEL_SEQ_CST
;
6185 /* Workaround for Bugzilla 59448. GCC doesn't track consume properly, so
6186 be conservative and promote consume to acquire. */
6187 if (val
== MEMMODEL_CONSUME
)
6188 val
= MEMMODEL_ACQUIRE
;
6190 return (enum memmodel
) val
;
6193 /* Expand the __atomic_exchange intrinsic:
6194 TYPE __atomic_exchange (TYPE *object, TYPE desired, enum memmodel)
6195 EXP is the CALL_EXPR.
6196 TARGET is an optional place for us to store the results. */
6199 expand_builtin_atomic_exchange (machine_mode mode
, tree exp
, rtx target
)
6202 enum memmodel model
;
6204 model
= get_memmodel (CALL_EXPR_ARG (exp
, 2));
6206 if (!flag_inline_atomics
)
6209 /* Expand the operands. */
6210 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6211 val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 1), mode
);
6213 return expand_atomic_exchange (target
, mem
, val
, model
);
6216 /* Expand the __atomic_compare_exchange intrinsic:
6217 bool __atomic_compare_exchange (TYPE *object, TYPE *expect,
6218 TYPE desired, BOOL weak,
6219 enum memmodel success,
6220 enum memmodel failure)
6221 EXP is the CALL_EXPR.
6222 TARGET is an optional place for us to store the results. */
6225 expand_builtin_atomic_compare_exchange (machine_mode mode
, tree exp
,
6228 rtx expect
, desired
, mem
, oldval
;
6229 rtx_code_label
*label
;
6233 memmodel success
= get_memmodel (CALL_EXPR_ARG (exp
, 4));
6234 memmodel failure
= get_memmodel (CALL_EXPR_ARG (exp
, 5));
6236 if (failure
> success
)
6237 success
= MEMMODEL_SEQ_CST
;
6239 if (is_mm_release (failure
) || is_mm_acq_rel (failure
))
6241 failure
= MEMMODEL_SEQ_CST
;
6242 success
= MEMMODEL_SEQ_CST
;
6246 if (!flag_inline_atomics
)
6249 /* Expand the operands. */
6250 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6252 expect
= expand_normal (CALL_EXPR_ARG (exp
, 1));
6253 expect
= convert_memory_address (Pmode
, expect
);
6254 expect
= gen_rtx_MEM (mode
, expect
);
6255 desired
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 2), mode
);
6257 weak
= CALL_EXPR_ARG (exp
, 3);
6259 if (tree_fits_shwi_p (weak
) && tree_to_shwi (weak
) != 0)
6262 if (target
== const0_rtx
)
6265 /* Lest the rtl backend create a race condition with an imporoper store
6266 to memory, always create a new pseudo for OLDVAL. */
6269 if (!expand_atomic_compare_and_swap (&target
, &oldval
, mem
, expect
, desired
,
6270 is_weak
, success
, failure
))
6273 /* Conditionally store back to EXPECT, lest we create a race condition
6274 with an improper store to memory. */
6275 /* ??? With a rearrangement of atomics at the gimple level, we can handle
6276 the normal case where EXPECT is totally private, i.e. a register. At
6277 which point the store can be unconditional. */
6278 label
= gen_label_rtx ();
6279 emit_cmp_and_jump_insns (target
, const0_rtx
, NE
, NULL
,
6280 GET_MODE (target
), 1, label
);
6281 emit_move_insn (expect
, oldval
);
6287 /* Helper function for expand_ifn_atomic_compare_exchange - expand
6288 internal ATOMIC_COMPARE_EXCHANGE call into __atomic_compare_exchange_N
6289 call. The weak parameter must be dropped to match the expected parameter
6290 list and the expected argument changed from value to pointer to memory
6294 expand_ifn_atomic_compare_exchange_into_call (gcall
*call
, machine_mode mode
)
6297 vec
<tree
, va_gc
> *vec
;
6300 vec
->quick_push (gimple_call_arg (call
, 0));
6301 tree expected
= gimple_call_arg (call
, 1);
6302 rtx x
= assign_stack_temp_for_type (mode
, GET_MODE_SIZE (mode
),
6303 TREE_TYPE (expected
));
6304 rtx expd
= expand_expr (expected
, x
, mode
, EXPAND_NORMAL
);
6306 emit_move_insn (x
, expd
);
6307 tree v
= make_tree (TREE_TYPE (expected
), x
);
6308 vec
->quick_push (build1 (ADDR_EXPR
,
6309 build_pointer_type (TREE_TYPE (expected
)), v
));
6310 vec
->quick_push (gimple_call_arg (call
, 2));
6311 /* Skip the boolean weak parameter. */
6312 for (z
= 4; z
< 6; z
++)
6313 vec
->quick_push (gimple_call_arg (call
, z
));
6314 /* At present we only have BUILT_IN_ATOMIC_COMPARE_EXCHANGE_{1,2,4,8,16}. */
6315 unsigned int bytes_log2
= exact_log2 (GET_MODE_SIZE (mode
).to_constant ());
6316 gcc_assert (bytes_log2
< 5);
6317 built_in_function fncode
6318 = (built_in_function
) ((int) BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1
6320 tree fndecl
= builtin_decl_explicit (fncode
);
6321 tree fn
= build1 (ADDR_EXPR
, build_pointer_type (TREE_TYPE (fndecl
)),
6323 tree exp
= build_call_vec (boolean_type_node
, fn
, vec
);
6324 tree lhs
= gimple_call_lhs (call
);
6325 rtx boolret
= expand_call (exp
, NULL_RTX
, lhs
== NULL_TREE
);
6328 rtx target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6329 if (GET_MODE (boolret
) != mode
)
6330 boolret
= convert_modes (mode
, GET_MODE (boolret
), boolret
, 1);
6331 x
= force_reg (mode
, x
);
6332 write_complex_part (target
, boolret
, true, true);
6333 write_complex_part (target
, x
, false, false);
6337 /* Expand IFN_ATOMIC_COMPARE_EXCHANGE internal function. */
6340 expand_ifn_atomic_compare_exchange (gcall
*call
)
6342 int size
= tree_to_shwi (gimple_call_arg (call
, 3)) & 255;
6343 gcc_assert (size
== 1 || size
== 2 || size
== 4 || size
== 8 || size
== 16);
6344 machine_mode mode
= int_mode_for_size (BITS_PER_UNIT
* size
, 0).require ();
6346 memmodel success
= get_memmodel (gimple_call_arg (call
, 4));
6347 memmodel failure
= get_memmodel (gimple_call_arg (call
, 5));
6349 if (failure
> success
)
6350 success
= MEMMODEL_SEQ_CST
;
6352 if (is_mm_release (failure
) || is_mm_acq_rel (failure
))
6354 failure
= MEMMODEL_SEQ_CST
;
6355 success
= MEMMODEL_SEQ_CST
;
6358 if (!flag_inline_atomics
)
6360 expand_ifn_atomic_compare_exchange_into_call (call
, mode
);
6364 /* Expand the operands. */
6365 rtx mem
= get_builtin_sync_mem (gimple_call_arg (call
, 0), mode
);
6367 rtx expect
= expand_expr_force_mode (gimple_call_arg (call
, 1), mode
);
6368 rtx desired
= expand_expr_force_mode (gimple_call_arg (call
, 2), mode
);
6370 bool is_weak
= (tree_to_shwi (gimple_call_arg (call
, 3)) & 256) != 0;
6375 if (!expand_atomic_compare_and_swap (&boolret
, &oldval
, mem
, expect
, desired
,
6376 is_weak
, success
, failure
))
6378 expand_ifn_atomic_compare_exchange_into_call (call
, mode
);
6382 tree lhs
= gimple_call_lhs (call
);
6385 rtx target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6386 if (GET_MODE (boolret
) != mode
)
6387 boolret
= convert_modes (mode
, GET_MODE (boolret
), boolret
, 1);
6388 write_complex_part (target
, boolret
, true, true);
6389 write_complex_part (target
, oldval
, false, false);
6393 /* Expand the __atomic_load intrinsic:
6394 TYPE __atomic_load (TYPE *object, enum memmodel)
6395 EXP is the CALL_EXPR.
6396 TARGET is an optional place for us to store the results. */
6399 expand_builtin_atomic_load (machine_mode mode
, tree exp
, rtx target
)
6401 memmodel model
= get_memmodel (CALL_EXPR_ARG (exp
, 1));
6402 if (is_mm_release (model
) || is_mm_acq_rel (model
))
6403 model
= MEMMODEL_SEQ_CST
;
6405 if (!flag_inline_atomics
)
6408 /* Expand the operand. */
6409 rtx mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6411 return expand_atomic_load (target
, mem
, model
);
6415 /* Expand the __atomic_store intrinsic:
6416 void __atomic_store (TYPE *object, TYPE desired, enum memmodel)
6417 EXP is the CALL_EXPR.
6418 TARGET is an optional place for us to store the results. */
6421 expand_builtin_atomic_store (machine_mode mode
, tree exp
)
6423 memmodel model
= get_memmodel (CALL_EXPR_ARG (exp
, 2));
6424 if (!(is_mm_relaxed (model
) || is_mm_seq_cst (model
)
6425 || is_mm_release (model
)))
6426 model
= MEMMODEL_SEQ_CST
;
6428 if (!flag_inline_atomics
)
6431 /* Expand the operands. */
6432 rtx mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6433 rtx val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 1), mode
);
6435 return expand_atomic_store (mem
, val
, model
, false);
6438 /* Expand the __atomic_fetch_XXX intrinsic:
6439 TYPE __atomic_fetch_XXX (TYPE *object, TYPE val, enum memmodel)
6440 EXP is the CALL_EXPR.
6441 TARGET is an optional place for us to store the results.
6442 CODE is the operation, PLUS, MINUS, ADD, XOR, or IOR.
6443 FETCH_AFTER is true if returning the result of the operation.
6444 FETCH_AFTER is false if returning the value before the operation.
6445 IGNORE is true if the result is not used.
6446 EXT_CALL is the correct builtin for an external call if this cannot be
6447 resolved to an instruction sequence. */
6450 expand_builtin_atomic_fetch_op (machine_mode mode
, tree exp
, rtx target
,
6451 enum rtx_code code
, bool fetch_after
,
6452 bool ignore
, enum built_in_function ext_call
)
6455 enum memmodel model
;
6459 model
= get_memmodel (CALL_EXPR_ARG (exp
, 2));
6461 /* Expand the operands. */
6462 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6463 val
= expand_expr_force_mode (CALL_EXPR_ARG (exp
, 1), mode
);
6465 /* Only try generating instructions if inlining is turned on. */
6466 if (flag_inline_atomics
)
6468 ret
= expand_atomic_fetch_op (target
, mem
, val
, code
, model
, fetch_after
);
6473 /* Return if a different routine isn't needed for the library call. */
6474 if (ext_call
== BUILT_IN_NONE
)
6477 /* Change the call to the specified function. */
6478 fndecl
= get_callee_fndecl (exp
);
6479 addr
= CALL_EXPR_FN (exp
);
6482 gcc_assert (TREE_OPERAND (addr
, 0) == fndecl
);
6483 TREE_OPERAND (addr
, 0) = builtin_decl_explicit (ext_call
);
6485 /* If we will emit code after the call, the call cannot be a tail call.
6486 If it is emitted as a tail call, a barrier is emitted after it, and
6487 then all trailing code is removed. */
6489 CALL_EXPR_TAILCALL (exp
) = 0;
6491 /* Expand the call here so we can emit trailing code. */
6492 ret
= expand_call (exp
, target
, ignore
);
6494 /* Replace the original function just in case it matters. */
6495 TREE_OPERAND (addr
, 0) = fndecl
;
6497 /* Then issue the arithmetic correction to return the right result. */
6502 ret
= expand_simple_binop (mode
, AND
, ret
, val
, NULL_RTX
, true,
6504 ret
= expand_simple_unop (mode
, NOT
, ret
, target
, true);
6507 ret
= expand_simple_binop (mode
, code
, ret
, val
, target
, true,
6513 /* Expand IFN_ATOMIC_BIT_TEST_AND_* internal function. */
6516 expand_ifn_atomic_bit_test_and (gcall
*call
)
6518 tree ptr
= gimple_call_arg (call
, 0);
6519 tree bit
= gimple_call_arg (call
, 1);
6520 tree flag
= gimple_call_arg (call
, 2);
6521 tree lhs
= gimple_call_lhs (call
);
6522 enum memmodel model
= MEMMODEL_SYNC_SEQ_CST
;
6523 machine_mode mode
= TYPE_MODE (TREE_TYPE (flag
));
6526 class expand_operand ops
[5];
6528 gcc_assert (flag_inline_atomics
);
6530 if (gimple_call_num_args (call
) == 5)
6531 model
= get_memmodel (gimple_call_arg (call
, 3));
6533 rtx mem
= get_builtin_sync_mem (ptr
, mode
);
6534 rtx val
= expand_expr_force_mode (bit
, mode
);
6536 switch (gimple_call_internal_fn (call
))
6538 case IFN_ATOMIC_BIT_TEST_AND_SET
:
6540 optab
= atomic_bit_test_and_set_optab
;
6542 case IFN_ATOMIC_BIT_TEST_AND_COMPLEMENT
:
6544 optab
= atomic_bit_test_and_complement_optab
;
6546 case IFN_ATOMIC_BIT_TEST_AND_RESET
:
6548 optab
= atomic_bit_test_and_reset_optab
;
6554 if (lhs
== NULL_TREE
)
6556 rtx val2
= expand_simple_binop (mode
, ASHIFT
, const1_rtx
,
6557 val
, NULL_RTX
, true, OPTAB_DIRECT
);
6559 val2
= expand_simple_unop (mode
, NOT
, val2
, NULL_RTX
, true);
6560 if (expand_atomic_fetch_op (const0_rtx
, mem
, val2
, code
, model
, false))
6566 target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6568 target
= gen_reg_rtx (mode
);
6569 enum insn_code icode
= direct_optab_handler (optab
, mode
);
6570 gcc_assert (icode
!= CODE_FOR_nothing
);
6571 create_output_operand (&ops
[0], target
, mode
);
6572 create_fixed_operand (&ops
[1], mem
);
6573 create_convert_operand_to (&ops
[2], val
, mode
, true);
6574 create_integer_operand (&ops
[3], model
);
6575 create_integer_operand (&ops
[4], integer_onep (flag
));
6576 if (maybe_expand_insn (icode
, 5, ops
))
6580 val
= expand_simple_binop (mode
, ASHIFT
, const1_rtx
,
6581 val
, NULL_RTX
, true, OPTAB_DIRECT
);
6584 val
= expand_simple_unop (mode
, NOT
, val
, NULL_RTX
, true);
6585 rtx result
= expand_atomic_fetch_op (gen_reg_rtx (mode
), mem
, val
,
6586 code
, model
, false);
6589 bool is_atomic
= gimple_call_num_args (call
) == 5;
6590 tree tcall
= gimple_call_arg (call
, 3 + is_atomic
);
6591 tree fndecl
= gimple_call_addr_fndecl (tcall
);
6592 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
6593 tree exp
= build_call_nary (type
, tcall
, 2 + is_atomic
, ptr
,
6594 make_tree (type
, val
),
6596 ? gimple_call_arg (call
, 3)
6597 : integer_zero_node
);
6598 result
= expand_builtin (exp
, gen_reg_rtx (mode
), NULL_RTX
,
6603 if (integer_onep (flag
))
6605 result
= expand_simple_binop (mode
, ASHIFTRT
, result
, bitval
,
6606 NULL_RTX
, true, OPTAB_DIRECT
);
6607 result
= expand_simple_binop (mode
, AND
, result
, const1_rtx
, target
,
6608 true, OPTAB_DIRECT
);
6611 result
= expand_simple_binop (mode
, AND
, result
, maskval
, target
, true,
6613 if (result
!= target
)
6614 emit_move_insn (target
, result
);
6617 /* Expand IFN_ATOMIC_*_FETCH_CMP_0 internal function. */
6620 expand_ifn_atomic_op_fetch_cmp_0 (gcall
*call
)
6622 tree cmp
= gimple_call_arg (call
, 0);
6623 tree ptr
= gimple_call_arg (call
, 1);
6624 tree arg
= gimple_call_arg (call
, 2);
6625 tree lhs
= gimple_call_lhs (call
);
6626 enum memmodel model
= MEMMODEL_SYNC_SEQ_CST
;
6627 machine_mode mode
= TYPE_MODE (TREE_TYPE (cmp
));
6630 class expand_operand ops
[5];
6632 gcc_assert (flag_inline_atomics
);
6634 if (gimple_call_num_args (call
) == 5)
6635 model
= get_memmodel (gimple_call_arg (call
, 3));
6637 rtx mem
= get_builtin_sync_mem (ptr
, mode
);
6638 rtx op
= expand_expr_force_mode (arg
, mode
);
6640 switch (gimple_call_internal_fn (call
))
6642 case IFN_ATOMIC_ADD_FETCH_CMP_0
:
6644 optab
= atomic_add_fetch_cmp_0_optab
;
6646 case IFN_ATOMIC_SUB_FETCH_CMP_0
:
6648 optab
= atomic_sub_fetch_cmp_0_optab
;
6650 case IFN_ATOMIC_AND_FETCH_CMP_0
:
6652 optab
= atomic_and_fetch_cmp_0_optab
;
6654 case IFN_ATOMIC_OR_FETCH_CMP_0
:
6656 optab
= atomic_or_fetch_cmp_0_optab
;
6658 case IFN_ATOMIC_XOR_FETCH_CMP_0
:
6660 optab
= atomic_xor_fetch_cmp_0_optab
;
6666 enum rtx_code comp
= UNKNOWN
;
6667 switch (tree_to_uhwi (cmp
))
6669 case ATOMIC_OP_FETCH_CMP_0_EQ
: comp
= EQ
; break;
6670 case ATOMIC_OP_FETCH_CMP_0_NE
: comp
= NE
; break;
6671 case ATOMIC_OP_FETCH_CMP_0_GT
: comp
= GT
; break;
6672 case ATOMIC_OP_FETCH_CMP_0_GE
: comp
= GE
; break;
6673 case ATOMIC_OP_FETCH_CMP_0_LT
: comp
= LT
; break;
6674 case ATOMIC_OP_FETCH_CMP_0_LE
: comp
= LE
; break;
6675 default: gcc_unreachable ();
6679 if (lhs
== NULL_TREE
)
6680 target
= gen_reg_rtx (TYPE_MODE (boolean_type_node
));
6682 target
= expand_expr (lhs
, NULL_RTX
, VOIDmode
, EXPAND_WRITE
);
6683 enum insn_code icode
= direct_optab_handler (optab
, mode
);
6684 gcc_assert (icode
!= CODE_FOR_nothing
);
6685 create_output_operand (&ops
[0], target
, TYPE_MODE (boolean_type_node
));
6686 create_fixed_operand (&ops
[1], mem
);
6687 create_convert_operand_to (&ops
[2], op
, mode
, true);
6688 create_integer_operand (&ops
[3], model
);
6689 create_integer_operand (&ops
[4], comp
);
6690 if (maybe_expand_insn (icode
, 5, ops
))
6693 rtx result
= expand_atomic_fetch_op (gen_reg_rtx (mode
), mem
, op
,
6697 bool is_atomic
= gimple_call_num_args (call
) == 5;
6698 tree tcall
= gimple_call_arg (call
, 3 + is_atomic
);
6699 tree fndecl
= gimple_call_addr_fndecl (tcall
);
6700 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
6701 tree exp
= build_call_nary (type
, tcall
,
6702 2 + is_atomic
, ptr
, arg
,
6704 ? gimple_call_arg (call
, 3)
6705 : integer_zero_node
);
6706 result
= expand_builtin (exp
, gen_reg_rtx (mode
), NULL_RTX
,
6712 result
= emit_store_flag_force (target
, comp
, result
, const0_rtx
, mode
,
6714 if (result
!= target
)
6715 emit_move_insn (target
, result
);
6719 /* Expand an atomic clear operation.
6720 void _atomic_clear (BOOL *obj, enum memmodel)
6721 EXP is the call expression. */
6724 expand_builtin_atomic_clear (tree exp
)
6726 machine_mode mode
= int_mode_for_size (BOOL_TYPE_SIZE
, 0).require ();
6727 rtx mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6728 memmodel model
= get_memmodel (CALL_EXPR_ARG (exp
, 1));
6730 if (is_mm_consume (model
) || is_mm_acquire (model
) || is_mm_acq_rel (model
))
6731 model
= MEMMODEL_SEQ_CST
;
6733 /* Try issuing an __atomic_store, and allow fallback to __sync_lock_release.
6734 Failing that, a store is issued by __atomic_store. The only way this can
6735 fail is if the bool type is larger than a word size. Unlikely, but
6736 handle it anyway for completeness. Assume a single threaded model since
6737 there is no atomic support in this case, and no barriers are required. */
6738 rtx ret
= expand_atomic_store (mem
, const0_rtx
, model
, true);
6740 emit_move_insn (mem
, const0_rtx
);
6744 /* Expand an atomic test_and_set operation.
6745 bool _atomic_test_and_set (BOOL *obj, enum memmodel)
6746 EXP is the call expression. */
6749 expand_builtin_atomic_test_and_set (tree exp
, rtx target
)
6752 enum memmodel model
;
6755 mode
= int_mode_for_size (BOOL_TYPE_SIZE
, 0).require ();
6756 mem
= get_builtin_sync_mem (CALL_EXPR_ARG (exp
, 0), mode
);
6757 model
= get_memmodel (CALL_EXPR_ARG (exp
, 1));
6759 return expand_atomic_test_and_set (target
, mem
, model
);
6763 /* Return true if (optional) argument ARG1 of size ARG0 is always lock free on
6764 this architecture. If ARG1 is NULL, use typical alignment for size ARG0. */
6767 fold_builtin_atomic_always_lock_free (tree arg0
, tree arg1
)
6771 unsigned int mode_align
, type_align
;
6773 if (TREE_CODE (arg0
) != INTEGER_CST
)
6776 /* We need a corresponding integer mode for the access to be lock-free. */
6777 size
= INTVAL (expand_normal (arg0
)) * BITS_PER_UNIT
;
6778 if (!int_mode_for_size (size
, 0).exists (&mode
))
6779 return boolean_false_node
;
6781 mode_align
= GET_MODE_ALIGNMENT (mode
);
6783 if (TREE_CODE (arg1
) == INTEGER_CST
)
6785 unsigned HOST_WIDE_INT val
= UINTVAL (expand_normal (arg1
));
6787 /* Either this argument is null, or it's a fake pointer encoding
6788 the alignment of the object. */
6789 val
= least_bit_hwi (val
);
6790 val
*= BITS_PER_UNIT
;
6792 if (val
== 0 || mode_align
< val
)
6793 type_align
= mode_align
;
6799 tree ttype
= TREE_TYPE (arg1
);
6801 /* This function is usually invoked and folded immediately by the front
6802 end before anything else has a chance to look at it. The pointer
6803 parameter at this point is usually cast to a void *, so check for that
6804 and look past the cast. */
6805 if (CONVERT_EXPR_P (arg1
)
6806 && POINTER_TYPE_P (ttype
)
6807 && VOID_TYPE_P (TREE_TYPE (ttype
))
6808 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1
, 0))))
6809 arg1
= TREE_OPERAND (arg1
, 0);
6811 ttype
= TREE_TYPE (arg1
);
6812 gcc_assert (POINTER_TYPE_P (ttype
));
6814 /* Get the underlying type of the object. */
6815 ttype
= TREE_TYPE (ttype
);
6816 type_align
= TYPE_ALIGN (ttype
);
6819 /* If the object has smaller alignment, the lock free routines cannot
6821 if (type_align
< mode_align
)
6822 return boolean_false_node
;
6824 /* Check if a compare_and_swap pattern exists for the mode which represents
6825 the required size. The pattern is not allowed to fail, so the existence
6826 of the pattern indicates support is present. Also require that an
6827 atomic load exists for the required size. */
6828 if (can_compare_and_swap_p (mode
, true) && can_atomic_load_p (mode
))
6829 return boolean_true_node
;
6831 return boolean_false_node
;
6834 /* Return true if the parameters to call EXP represent an object which will
6835 always generate lock free instructions. The first argument represents the
6836 size of the object, and the second parameter is a pointer to the object
6837 itself. If NULL is passed for the object, then the result is based on
6838 typical alignment for an object of the specified size. Otherwise return
6842 expand_builtin_atomic_always_lock_free (tree exp
)
6845 tree arg0
= CALL_EXPR_ARG (exp
, 0);
6846 tree arg1
= CALL_EXPR_ARG (exp
, 1);
6848 if (TREE_CODE (arg0
) != INTEGER_CST
)
6850 error ("non-constant argument 1 to %qs", "__atomic_always_lock_free");
6854 size
= fold_builtin_atomic_always_lock_free (arg0
, arg1
);
6855 if (size
== boolean_true_node
)
6860 /* Return a one or zero if it can be determined that object ARG1 of size ARG
6861 is lock free on this architecture. */
6864 fold_builtin_atomic_is_lock_free (tree arg0
, tree arg1
)
6866 if (!flag_inline_atomics
)
6869 /* If it isn't always lock free, don't generate a result. */
6870 if (fold_builtin_atomic_always_lock_free (arg0
, arg1
) == boolean_true_node
)
6871 return boolean_true_node
;
6876 /* Return true if the parameters to call EXP represent an object which will
6877 always generate lock free instructions. The first argument represents the
6878 size of the object, and the second parameter is a pointer to the object
6879 itself. If NULL is passed for the object, then the result is based on
6880 typical alignment for an object of the specified size. Otherwise return
6884 expand_builtin_atomic_is_lock_free (tree exp
)
6887 tree arg0
= CALL_EXPR_ARG (exp
, 0);
6888 tree arg1
= CALL_EXPR_ARG (exp
, 1);
6890 if (!INTEGRAL_TYPE_P (TREE_TYPE (arg0
)))
6892 error ("non-integer argument 1 to %qs", "__atomic_is_lock_free");
6896 if (!flag_inline_atomics
)
6899 /* If the value is known at compile time, return the RTX for it. */
6900 size
= fold_builtin_atomic_is_lock_free (arg0
, arg1
);
6901 if (size
== boolean_true_node
)
6907 /* Expand the __atomic_thread_fence intrinsic:
6908 void __atomic_thread_fence (enum memmodel)
6909 EXP is the CALL_EXPR. */
6912 expand_builtin_atomic_thread_fence (tree exp
)
6914 enum memmodel model
= get_memmodel (CALL_EXPR_ARG (exp
, 0));
6915 expand_mem_thread_fence (model
);
6918 /* Expand the __atomic_signal_fence intrinsic:
6919 void __atomic_signal_fence (enum memmodel)
6920 EXP is the CALL_EXPR. */
6923 expand_builtin_atomic_signal_fence (tree exp
)
6925 enum memmodel model
= get_memmodel (CALL_EXPR_ARG (exp
, 0));
6926 expand_mem_signal_fence (model
);
6929 /* Expand the __sync_synchronize intrinsic. */
6932 expand_builtin_sync_synchronize (void)
6934 expand_mem_thread_fence (MEMMODEL_SYNC_SEQ_CST
);
6938 expand_builtin_thread_pointer (tree exp
, rtx target
)
6940 enum insn_code icode
;
6941 if (!validate_arglist (exp
, VOID_TYPE
))
6943 icode
= direct_optab_handler (get_thread_pointer_optab
, Pmode
);
6944 if (icode
!= CODE_FOR_nothing
)
6946 class expand_operand op
;
6947 /* If the target is not sutitable then create a new target. */
6948 if (target
== NULL_RTX
6950 || GET_MODE (target
) != Pmode
)
6951 target
= gen_reg_rtx (Pmode
);
6952 create_output_operand (&op
, target
, Pmode
);
6953 expand_insn (icode
, 1, &op
);
6956 error ("%<__builtin_thread_pointer%> is not supported on this target");
6961 expand_builtin_set_thread_pointer (tree exp
)
6963 enum insn_code icode
;
6964 if (!validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
6966 icode
= direct_optab_handler (set_thread_pointer_optab
, Pmode
);
6967 if (icode
!= CODE_FOR_nothing
)
6969 class expand_operand op
;
6970 rtx val
= expand_expr (CALL_EXPR_ARG (exp
, 0), NULL_RTX
,
6971 Pmode
, EXPAND_NORMAL
);
6972 create_input_operand (&op
, val
, Pmode
);
6973 expand_insn (icode
, 1, &op
);
6976 error ("%<__builtin_set_thread_pointer%> is not supported on this target");
6980 /* Emit code to restore the current value of stack. */
6983 expand_stack_restore (tree var
)
6986 rtx sa
= expand_normal (var
);
6988 sa
= convert_memory_address (Pmode
, sa
);
6990 prev
= get_last_insn ();
6991 emit_stack_restore (SAVE_BLOCK
, sa
);
6993 record_new_stack_level ();
6995 fixup_args_size_notes (prev
, get_last_insn (), 0);
6998 /* Emit code to save the current value of stack. */
7001 expand_stack_save (void)
7005 emit_stack_save (SAVE_BLOCK
, &ret
);
7009 /* Emit code to get the openacc gang, worker or vector id or size. */
7012 expand_builtin_goacc_parlevel_id_size (tree exp
, rtx target
, int ignore
)
7015 rtx fallback_retval
;
7016 rtx_insn
*(*gen_fn
) (rtx
, rtx
);
7017 switch (DECL_FUNCTION_CODE (get_callee_fndecl (exp
)))
7019 case BUILT_IN_GOACC_PARLEVEL_ID
:
7020 name
= "__builtin_goacc_parlevel_id";
7021 fallback_retval
= const0_rtx
;
7022 gen_fn
= targetm
.gen_oacc_dim_pos
;
7024 case BUILT_IN_GOACC_PARLEVEL_SIZE
:
7025 name
= "__builtin_goacc_parlevel_size";
7026 fallback_retval
= const1_rtx
;
7027 gen_fn
= targetm
.gen_oacc_dim_size
;
7033 if (oacc_get_fn_attrib (current_function_decl
) == NULL_TREE
)
7035 error ("%qs only supported in OpenACC code", name
);
7039 tree arg
= CALL_EXPR_ARG (exp
, 0);
7040 if (TREE_CODE (arg
) != INTEGER_CST
)
7042 error ("non-constant argument 0 to %qs", name
);
7046 int dim
= TREE_INT_CST_LOW (arg
);
7050 case GOMP_DIM_WORKER
:
7051 case GOMP_DIM_VECTOR
:
7054 error ("illegal argument 0 to %qs", name
);
7061 if (target
== NULL_RTX
)
7062 target
= gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp
)));
7064 if (!targetm
.have_oacc_dim_size ())
7066 emit_move_insn (target
, fallback_retval
);
7070 rtx reg
= MEM_P (target
) ? gen_reg_rtx (GET_MODE (target
)) : target
;
7071 emit_insn (gen_fn (reg
, GEN_INT (dim
)));
7073 emit_move_insn (target
, reg
);
7078 /* Expand a string compare operation using a sequence of char comparison
7079 to get rid of the calling overhead, with result going to TARGET if
7082 VAR_STR is the variable string source;
7083 CONST_STR is the constant string source;
7084 LENGTH is the number of chars to compare;
7085 CONST_STR_N indicates which source string is the constant string;
7086 IS_MEMCMP indicates whether it's a memcmp or strcmp.
7088 to: (assume const_str_n is 2, i.e., arg2 is a constant string)
7090 target = (int) (unsigned char) var_str[0]
7091 - (int) (unsigned char) const_str[0];
7095 target = (int) (unsigned char) var_str[length - 2]
7096 - (int) (unsigned char) const_str[length - 2];
7099 target = (int) (unsigned char) var_str[length - 1]
7100 - (int) (unsigned char) const_str[length - 1];
7105 inline_string_cmp (rtx target
, tree var_str
, const char *const_str
,
7106 unsigned HOST_WIDE_INT length
,
7107 int const_str_n
, machine_mode mode
)
7109 HOST_WIDE_INT offset
= 0;
7111 = get_memory_rtx (var_str
, build_int_cst (unsigned_type_node
,length
));
7112 rtx var_rtx
= NULL_RTX
;
7113 rtx const_rtx
= NULL_RTX
;
7114 rtx result
= target
? target
: gen_reg_rtx (mode
);
7115 rtx_code_label
*ne_label
= gen_label_rtx ();
7116 tree unit_type_node
= unsigned_char_type_node
;
7117 scalar_int_mode unit_mode
7118 = as_a
<scalar_int_mode
> TYPE_MODE (unit_type_node
);
7122 for (unsigned HOST_WIDE_INT i
= 0; i
< length
; i
++)
7125 = adjust_address (var_rtx_array
, TYPE_MODE (unit_type_node
), offset
);
7126 const_rtx
= c_readstr (const_str
+ offset
, unit_mode
);
7127 rtx op0
= (const_str_n
== 1) ? const_rtx
: var_rtx
;
7128 rtx op1
= (const_str_n
== 1) ? var_rtx
: const_rtx
;
7130 op0
= convert_modes (mode
, unit_mode
, op0
, 1);
7131 op1
= convert_modes (mode
, unit_mode
, op1
, 1);
7132 result
= expand_simple_binop (mode
, MINUS
, op0
, op1
,
7133 result
, 1, OPTAB_WIDEN
);
7135 emit_cmp_and_jump_insns (result
, CONST0_RTX (mode
), NE
, NULL_RTX
,
7136 mode
, true, ne_label
);
7137 offset
+= GET_MODE_SIZE (unit_mode
);
7140 emit_label (ne_label
);
7141 rtx_insn
*insns
= get_insns ();
7148 /* Inline expansion of a call to str(n)cmp and memcmp, with result going
7149 to TARGET if that's convenient.
7150 If the call is not been inlined, return NULL_RTX. */
7153 inline_expand_builtin_bytecmp (tree exp
, rtx target
)
7155 tree fndecl
= get_callee_fndecl (exp
);
7156 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
7157 bool is_ncmp
= (fcode
== BUILT_IN_STRNCMP
|| fcode
== BUILT_IN_MEMCMP
);
7159 /* Do NOT apply this inlining expansion when optimizing for size or
7160 optimization level below 2. */
7161 if (optimize
< 2 || optimize_insn_for_size_p ())
7164 gcc_checking_assert (fcode
== BUILT_IN_STRCMP
7165 || fcode
== BUILT_IN_STRNCMP
7166 || fcode
== BUILT_IN_MEMCMP
);
7168 /* On a target where the type of the call (int) has same or narrower presicion
7169 than unsigned char, give up the inlining expansion. */
7170 if (TYPE_PRECISION (unsigned_char_type_node
)
7171 >= TYPE_PRECISION (TREE_TYPE (exp
)))
7174 tree arg1
= CALL_EXPR_ARG (exp
, 0);
7175 tree arg2
= CALL_EXPR_ARG (exp
, 1);
7176 tree len3_tree
= is_ncmp
? CALL_EXPR_ARG (exp
, 2) : NULL_TREE
;
7178 unsigned HOST_WIDE_INT len1
= 0;
7179 unsigned HOST_WIDE_INT len2
= 0;
7180 unsigned HOST_WIDE_INT len3
= 0;
7182 /* Get the object representation of the initializers of ARG1 and ARG2
7183 as strings, provided they refer to constant objects, with their byte
7184 sizes in LEN1 and LEN2, respectively. */
7185 const char *bytes1
= getbyterep (arg1
, &len1
);
7186 const char *bytes2
= getbyterep (arg2
, &len2
);
7188 /* Fail if neither argument refers to an initialized constant. */
7189 if (!bytes1
&& !bytes2
)
7194 /* Fail if the memcmp/strncmp bound is not a constant. */
7195 if (!tree_fits_uhwi_p (len3_tree
))
7198 len3
= tree_to_uhwi (len3_tree
);
7200 if (fcode
== BUILT_IN_MEMCMP
)
7202 /* Fail if the memcmp bound is greater than the size of either
7203 of the two constant objects. */
7204 if ((bytes1
&& len1
< len3
)
7205 || (bytes2
&& len2
< len3
))
7210 if (fcode
!= BUILT_IN_MEMCMP
)
7212 /* For string functions (i.e., strcmp and strncmp) reduce LEN1
7213 and LEN2 to the length of the nul-terminated string stored
7216 len1
= strnlen (bytes1
, len1
) + 1;
7218 len2
= strnlen (bytes2
, len2
) + 1;
7221 /* See inline_string_cmp. */
7227 else if (len2
> len1
)
7232 /* For strncmp only, compute the new bound as the smallest of
7233 the lengths of the two strings (plus 1) and the bound provided
7235 unsigned HOST_WIDE_INT bound
= (const_str_n
== 1) ? len1
: len2
;
7236 if (is_ncmp
&& len3
< bound
)
7239 /* If the bound of the comparison is larger than the threshold,
7241 if (bound
> (unsigned HOST_WIDE_INT
) param_builtin_string_cmp_inline_length
)
7244 machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
7246 /* Now, start inline expansion the call. */
7247 return inline_string_cmp (target
, (const_str_n
== 1) ? arg2
: arg1
,
7248 (const_str_n
== 1) ? bytes1
: bytes2
, bound
,
7252 /* Expand a call to __builtin_speculation_safe_value_<N>. MODE
7253 represents the size of the first argument to that call, or VOIDmode
7254 if the argument is a pointer. IGNORE will be true if the result
7257 expand_speculation_safe_value (machine_mode mode
, tree exp
, rtx target
,
7261 unsigned nargs
= call_expr_nargs (exp
);
7263 tree arg0
= CALL_EXPR_ARG (exp
, 0);
7265 if (mode
== VOIDmode
)
7267 mode
= TYPE_MODE (TREE_TYPE (arg0
));
7268 gcc_assert (GET_MODE_CLASS (mode
) == MODE_INT
);
7271 val
= expand_expr (arg0
, NULL_RTX
, mode
, EXPAND_NORMAL
);
7273 /* An optional second argument can be used as a failsafe value on
7274 some machines. If it isn't present, then the failsafe value is
7278 tree arg1
= CALL_EXPR_ARG (exp
, 1);
7279 failsafe
= expand_expr (arg1
, NULL_RTX
, mode
, EXPAND_NORMAL
);
7282 failsafe
= const0_rtx
;
7284 /* If the result isn't used, the behavior is undefined. It would be
7285 nice to emit a warning here, but path splitting means this might
7286 happen with legitimate code. So simply drop the builtin
7287 expansion in that case; we've handled any side-effects above. */
7291 /* If we don't have a suitable target, create one to hold the result. */
7292 if (target
== NULL
|| GET_MODE (target
) != mode
)
7293 target
= gen_reg_rtx (mode
);
7295 if (GET_MODE (val
) != mode
&& GET_MODE (val
) != VOIDmode
)
7296 val
= convert_modes (mode
, VOIDmode
, val
, false);
7298 return targetm
.speculation_safe_value (mode
, target
, val
, failsafe
);
7301 /* Expand an expression EXP that calls a built-in function,
7302 with result going to TARGET if that's convenient
7303 (and in mode MODE if that's convenient).
7304 SUBTARGET may be used as the target for computing one of EXP's operands.
7305 IGNORE is nonzero if the value is to be ignored. */
7308 expand_builtin (tree exp
, rtx target
, rtx subtarget
, machine_mode mode
,
7311 tree fndecl
= get_callee_fndecl (exp
);
7312 machine_mode target_mode
= TYPE_MODE (TREE_TYPE (exp
));
7315 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_MD
)
7316 return targetm
.expand_builtin (exp
, target
, subtarget
, mode
, ignore
);
7318 /* When ASan is enabled, we don't want to expand some memory/string
7319 builtins and rely on libsanitizer's hooks. This allows us to avoid
7320 redundant checks and be sure, that possible overflow will be detected
7323 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
7324 if ((flag_sanitize
& SANITIZE_ADDRESS
) && asan_intercepted_p (fcode
))
7325 return expand_call (exp
, target
, ignore
);
7327 /* When not optimizing, generate calls to library functions for a certain
7330 && !called_as_built_in (fndecl
)
7331 && fcode
!= BUILT_IN_FORK
7332 && fcode
!= BUILT_IN_EXECL
7333 && fcode
!= BUILT_IN_EXECV
7334 && fcode
!= BUILT_IN_EXECLP
7335 && fcode
!= BUILT_IN_EXECLE
7336 && fcode
!= BUILT_IN_EXECVP
7337 && fcode
!= BUILT_IN_EXECVE
7338 && fcode
!= BUILT_IN_CLEAR_CACHE
7339 && !ALLOCA_FUNCTION_CODE_P (fcode
)
7340 && fcode
!= BUILT_IN_FREE
)
7341 return expand_call (exp
, target
, ignore
);
7343 /* The built-in function expanders test for target == const0_rtx
7344 to determine whether the function's result will be ignored. */
7346 target
= const0_rtx
;
7348 /* If the result of a pure or const built-in function is ignored, and
7349 none of its arguments are volatile, we can avoid expanding the
7350 built-in call and just evaluate the arguments for side-effects. */
7351 if (target
== const0_rtx
7352 && ((flags
= flags_from_decl_or_type (fndecl
)) & (ECF_CONST
| ECF_PURE
))
7353 && !(flags
& ECF_LOOPING_CONST_OR_PURE
))
7355 bool volatilep
= false;
7357 call_expr_arg_iterator iter
;
7359 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
7360 if (TREE_THIS_VOLATILE (arg
))
7368 FOR_EACH_CALL_EXPR_ARG (arg
, iter
, exp
)
7369 expand_expr (arg
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
7376 CASE_FLT_FN (BUILT_IN_FABS
):
7377 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
7378 case BUILT_IN_FABSD32
:
7379 case BUILT_IN_FABSD64
:
7380 case BUILT_IN_FABSD128
:
7381 target
= expand_builtin_fabs (exp
, target
, subtarget
);
7386 CASE_FLT_FN (BUILT_IN_COPYSIGN
):
7387 CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN
):
7388 target
= expand_builtin_copysign (exp
, target
, subtarget
);
7393 /* Just do a normal library call if we were unable to fold
7395 CASE_FLT_FN (BUILT_IN_CABS
):
7398 CASE_FLT_FN (BUILT_IN_FMA
):
7399 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA
):
7400 target
= expand_builtin_mathfn_ternary (exp
, target
, subtarget
);
7405 CASE_FLT_FN (BUILT_IN_ILOGB
):
7406 if (! flag_unsafe_math_optimizations
)
7409 CASE_FLT_FN (BUILT_IN_ISINF
):
7410 CASE_FLT_FN (BUILT_IN_FINITE
):
7411 case BUILT_IN_ISFINITE
:
7412 case BUILT_IN_ISNORMAL
:
7413 target
= expand_builtin_interclass_mathfn (exp
, target
);
7418 case BUILT_IN_ISSIGNALING
:
7419 target
= expand_builtin_issignaling (exp
, target
);
7424 CASE_FLT_FN (BUILT_IN_ICEIL
):
7425 CASE_FLT_FN (BUILT_IN_LCEIL
):
7426 CASE_FLT_FN (BUILT_IN_LLCEIL
):
7427 CASE_FLT_FN (BUILT_IN_LFLOOR
):
7428 CASE_FLT_FN (BUILT_IN_IFLOOR
):
7429 CASE_FLT_FN (BUILT_IN_LLFLOOR
):
7430 target
= expand_builtin_int_roundingfn (exp
, target
);
7435 CASE_FLT_FN (BUILT_IN_IRINT
):
7436 CASE_FLT_FN (BUILT_IN_LRINT
):
7437 CASE_FLT_FN (BUILT_IN_LLRINT
):
7438 CASE_FLT_FN (BUILT_IN_IROUND
):
7439 CASE_FLT_FN (BUILT_IN_LROUND
):
7440 CASE_FLT_FN (BUILT_IN_LLROUND
):
7441 target
= expand_builtin_int_roundingfn_2 (exp
, target
);
7446 CASE_FLT_FN (BUILT_IN_POWI
):
7447 target
= expand_builtin_powi (exp
, target
);
7452 CASE_FLT_FN (BUILT_IN_CEXPI
):
7453 target
= expand_builtin_cexpi (exp
, target
);
7454 gcc_assert (target
);
7457 CASE_FLT_FN (BUILT_IN_SIN
):
7458 CASE_FLT_FN (BUILT_IN_COS
):
7459 if (! flag_unsafe_math_optimizations
)
7461 target
= expand_builtin_mathfn_3 (exp
, target
, subtarget
);
7466 CASE_FLT_FN (BUILT_IN_SINCOS
):
7467 if (! flag_unsafe_math_optimizations
)
7469 target
= expand_builtin_sincos (exp
);
7474 case BUILT_IN_FEGETROUND
:
7475 target
= expand_builtin_fegetround (exp
, target
, target_mode
);
7480 case BUILT_IN_FECLEAREXCEPT
:
7481 target
= expand_builtin_feclear_feraise_except (exp
, target
, target_mode
,
7482 feclearexcept_optab
);
7487 case BUILT_IN_FERAISEEXCEPT
:
7488 target
= expand_builtin_feclear_feraise_except (exp
, target
, target_mode
,
7489 feraiseexcept_optab
);
7494 case BUILT_IN_APPLY_ARGS
:
7495 return expand_builtin_apply_args ();
7497 /* __builtin_apply (FUNCTION, ARGUMENTS, ARGSIZE) invokes
7498 FUNCTION with a copy of the parameters described by
7499 ARGUMENTS, and ARGSIZE. It returns a block of memory
7500 allocated on the stack into which is stored all the registers
7501 that might possibly be used for returning the result of a
7502 function. ARGUMENTS is the value returned by
7503 __builtin_apply_args. ARGSIZE is the number of bytes of
7504 arguments that must be copied. ??? How should this value be
7505 computed? We'll also need a safe worst case value for varargs
7507 case BUILT_IN_APPLY
:
7508 if (!validate_arglist (exp
, POINTER_TYPE
,
7509 POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
)
7510 && !validate_arglist (exp
, REFERENCE_TYPE
,
7511 POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
7517 ops
[0] = expand_normal (CALL_EXPR_ARG (exp
, 0));
7518 ops
[1] = expand_normal (CALL_EXPR_ARG (exp
, 1));
7519 ops
[2] = expand_normal (CALL_EXPR_ARG (exp
, 2));
7521 return expand_builtin_apply (ops
[0], ops
[1], ops
[2]);
7524 /* __builtin_return (RESULT) causes the function to return the
7525 value described by RESULT. RESULT is address of the block of
7526 memory returned by __builtin_apply. */
7527 case BUILT_IN_RETURN
:
7528 if (validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
7529 expand_builtin_return (expand_normal (CALL_EXPR_ARG (exp
, 0)));
7532 case BUILT_IN_SAVEREGS
:
7533 return expand_builtin_saveregs ();
7535 case BUILT_IN_VA_ARG_PACK
:
7536 /* All valid uses of __builtin_va_arg_pack () are removed during
7538 error ("invalid use of %<__builtin_va_arg_pack ()%>");
7541 case BUILT_IN_VA_ARG_PACK_LEN
:
7542 /* All valid uses of __builtin_va_arg_pack_len () are removed during
7544 error ("invalid use of %<__builtin_va_arg_pack_len ()%>");
7547 /* Return the address of the first anonymous stack arg. */
7548 case BUILT_IN_NEXT_ARG
:
7549 if (fold_builtin_next_arg (exp
, false))
7551 return expand_builtin_next_arg ();
7553 case BUILT_IN_CLEAR_CACHE
:
7554 expand_builtin___clear_cache (exp
);
7557 case BUILT_IN_CLASSIFY_TYPE
:
7558 return expand_builtin_classify_type (exp
);
7560 case BUILT_IN_CONSTANT_P
:
7563 case BUILT_IN_FRAME_ADDRESS
:
7564 case BUILT_IN_RETURN_ADDRESS
:
7565 return expand_builtin_frame_address (fndecl
, exp
);
7567 /* Returns the address of the area where the structure is returned.
7569 case BUILT_IN_AGGREGATE_INCOMING_ADDRESS
:
7570 if (call_expr_nargs (exp
) != 0
7571 || ! AGGREGATE_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl
)))
7572 || !MEM_P (DECL_RTL (DECL_RESULT (current_function_decl
))))
7575 return XEXP (DECL_RTL (DECL_RESULT (current_function_decl
)), 0);
7577 CASE_BUILT_IN_ALLOCA
:
7578 target
= expand_builtin_alloca (exp
);
7583 case BUILT_IN_ASAN_ALLOCAS_UNPOISON
:
7584 return expand_asan_emit_allocas_unpoison (exp
);
7586 case BUILT_IN_STACK_SAVE
:
7587 return expand_stack_save ();
7589 case BUILT_IN_STACK_RESTORE
:
7590 expand_stack_restore (CALL_EXPR_ARG (exp
, 0));
7593 case BUILT_IN_BSWAP16
:
7594 case BUILT_IN_BSWAP32
:
7595 case BUILT_IN_BSWAP64
:
7596 case BUILT_IN_BSWAP128
:
7597 target
= expand_builtin_bswap (target_mode
, exp
, target
, subtarget
);
7602 CASE_INT_FN (BUILT_IN_FFS
):
7603 target
= expand_builtin_unop (target_mode
, exp
, target
,
7604 subtarget
, ffs_optab
);
7609 CASE_INT_FN (BUILT_IN_CLZ
):
7610 target
= expand_builtin_unop (target_mode
, exp
, target
,
7611 subtarget
, clz_optab
);
7616 CASE_INT_FN (BUILT_IN_CTZ
):
7617 target
= expand_builtin_unop (target_mode
, exp
, target
,
7618 subtarget
, ctz_optab
);
7623 CASE_INT_FN (BUILT_IN_CLRSB
):
7624 target
= expand_builtin_unop (target_mode
, exp
, target
,
7625 subtarget
, clrsb_optab
);
7630 CASE_INT_FN (BUILT_IN_POPCOUNT
):
7631 target
= expand_builtin_unop (target_mode
, exp
, target
,
7632 subtarget
, popcount_optab
);
7637 CASE_INT_FN (BUILT_IN_PARITY
):
7638 target
= expand_builtin_unop (target_mode
, exp
, target
,
7639 subtarget
, parity_optab
);
7644 case BUILT_IN_STRLEN
:
7645 target
= expand_builtin_strlen (exp
, target
, target_mode
);
7650 case BUILT_IN_STRNLEN
:
7651 target
= expand_builtin_strnlen (exp
, target
, target_mode
);
7656 case BUILT_IN_STRCPY
:
7657 target
= expand_builtin_strcpy (exp
, target
);
7662 case BUILT_IN_STRNCPY
:
7663 target
= expand_builtin_strncpy (exp
, target
);
7668 case BUILT_IN_STPCPY
:
7669 target
= expand_builtin_stpcpy (exp
, target
, mode
);
7674 case BUILT_IN_MEMCPY
:
7675 target
= expand_builtin_memcpy (exp
, target
);
7680 case BUILT_IN_MEMMOVE
:
7681 target
= expand_builtin_memmove (exp
, target
);
7686 case BUILT_IN_MEMPCPY
:
7687 target
= expand_builtin_mempcpy (exp
, target
);
7692 case BUILT_IN_MEMSET
:
7693 target
= expand_builtin_memset (exp
, target
, mode
);
7698 case BUILT_IN_BZERO
:
7699 target
= expand_builtin_bzero (exp
);
7704 /* Expand it as BUILT_IN_MEMCMP_EQ first. If not successful, change it
7705 back to a BUILT_IN_STRCMP. Remember to delete the 3rd parameter
7706 when changing it to a strcmp call. */
7707 case BUILT_IN_STRCMP_EQ
:
7708 target
= expand_builtin_memcmp (exp
, target
, true);
7712 /* Change this call back to a BUILT_IN_STRCMP. */
7713 TREE_OPERAND (exp
, 1)
7714 = build_fold_addr_expr (builtin_decl_explicit (BUILT_IN_STRCMP
));
7716 /* Delete the last parameter. */
7718 vec
<tree
, va_gc
> *arg_vec
;
7719 vec_alloc (arg_vec
, 2);
7720 for (i
= 0; i
< 2; i
++)
7721 arg_vec
->quick_push (CALL_EXPR_ARG (exp
, i
));
7722 exp
= build_call_vec (TREE_TYPE (exp
), CALL_EXPR_FN (exp
), arg_vec
);
7725 case BUILT_IN_STRCMP
:
7726 target
= expand_builtin_strcmp (exp
, target
);
7731 /* Expand it as BUILT_IN_MEMCMP_EQ first. If not successful, change it
7732 back to a BUILT_IN_STRNCMP. */
7733 case BUILT_IN_STRNCMP_EQ
:
7734 target
= expand_builtin_memcmp (exp
, target
, true);
7738 /* Change it back to a BUILT_IN_STRNCMP. */
7739 TREE_OPERAND (exp
, 1)
7740 = build_fold_addr_expr (builtin_decl_explicit (BUILT_IN_STRNCMP
));
7743 case BUILT_IN_STRNCMP
:
7744 target
= expand_builtin_strncmp (exp
, target
, mode
);
7750 case BUILT_IN_MEMCMP
:
7751 case BUILT_IN_MEMCMP_EQ
:
7752 target
= expand_builtin_memcmp (exp
, target
, fcode
== BUILT_IN_MEMCMP_EQ
);
7755 if (fcode
== BUILT_IN_MEMCMP_EQ
)
7757 tree newdecl
= builtin_decl_explicit (BUILT_IN_MEMCMP
);
7758 TREE_OPERAND (exp
, 1) = build_fold_addr_expr (newdecl
);
7762 case BUILT_IN_SETJMP
:
7763 /* This should have been lowered to the builtins below. */
7766 case BUILT_IN_SETJMP_SETUP
:
7767 /* __builtin_setjmp_setup is passed a pointer to an array of five words
7768 and the receiver label. */
7769 if (validate_arglist (exp
, POINTER_TYPE
, POINTER_TYPE
, VOID_TYPE
))
7771 rtx buf_addr
= expand_expr (CALL_EXPR_ARG (exp
, 0), subtarget
,
7772 VOIDmode
, EXPAND_NORMAL
);
7773 tree label
= TREE_OPERAND (CALL_EXPR_ARG (exp
, 1), 0);
7774 rtx_insn
*label_r
= label_rtx (label
);
7776 expand_builtin_setjmp_setup (buf_addr
, label_r
);
7781 case BUILT_IN_SETJMP_RECEIVER
:
7782 /* __builtin_setjmp_receiver is passed the receiver label. */
7783 if (validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
7785 tree label
= TREE_OPERAND (CALL_EXPR_ARG (exp
, 0), 0);
7786 rtx_insn
*label_r
= label_rtx (label
);
7788 expand_builtin_setjmp_receiver (label_r
);
7789 nonlocal_goto_handler_labels
7790 = gen_rtx_INSN_LIST (VOIDmode
, label_r
,
7791 nonlocal_goto_handler_labels
);
7792 /* ??? Do not let expand_label treat us as such since we would
7793 not want to be both on the list of non-local labels and on
7794 the list of forced labels. */
7795 FORCED_LABEL (label
) = 0;
7800 /* __builtin_longjmp is passed a pointer to an array of five words.
7801 It's similar to the C library longjmp function but works with
7802 __builtin_setjmp above. */
7803 case BUILT_IN_LONGJMP
:
7804 if (validate_arglist (exp
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
7806 rtx buf_addr
= expand_expr (CALL_EXPR_ARG (exp
, 0), subtarget
,
7807 VOIDmode
, EXPAND_NORMAL
);
7808 rtx value
= expand_normal (CALL_EXPR_ARG (exp
, 1));
7810 if (value
!= const1_rtx
)
7812 error ("%<__builtin_longjmp%> second argument must be 1");
7816 expand_builtin_longjmp (buf_addr
, value
);
7821 case BUILT_IN_NONLOCAL_GOTO
:
7822 target
= expand_builtin_nonlocal_goto (exp
);
7827 /* This updates the setjmp buffer that is its argument with the value
7828 of the current stack pointer. */
7829 case BUILT_IN_UPDATE_SETJMP_BUF
:
7830 if (validate_arglist (exp
, POINTER_TYPE
, VOID_TYPE
))
7833 = expand_normal (CALL_EXPR_ARG (exp
, 0));
7835 expand_builtin_update_setjmp_buf (buf_addr
);
7841 expand_builtin_trap ();
7844 case BUILT_IN_UNREACHABLE
:
7845 expand_builtin_unreachable ();
7848 CASE_FLT_FN (BUILT_IN_SIGNBIT
):
7849 case BUILT_IN_SIGNBITD32
:
7850 case BUILT_IN_SIGNBITD64
:
7851 case BUILT_IN_SIGNBITD128
:
7852 target
= expand_builtin_signbit (exp
, target
);
7857 /* Various hooks for the DWARF 2 __throw routine. */
7858 case BUILT_IN_UNWIND_INIT
:
7859 expand_builtin_unwind_init ();
7861 case BUILT_IN_DWARF_CFA
:
7862 return virtual_cfa_rtx
;
7863 #ifdef DWARF2_UNWIND_INFO
7864 case BUILT_IN_DWARF_SP_COLUMN
:
7865 return expand_builtin_dwarf_sp_column ();
7866 case BUILT_IN_INIT_DWARF_REG_SIZES
:
7867 expand_builtin_init_dwarf_reg_sizes (CALL_EXPR_ARG (exp
, 0));
7870 case BUILT_IN_FROB_RETURN_ADDR
:
7871 return expand_builtin_frob_return_addr (CALL_EXPR_ARG (exp
, 0));
7872 case BUILT_IN_EXTRACT_RETURN_ADDR
:
7873 return expand_builtin_extract_return_addr (CALL_EXPR_ARG (exp
, 0));
7874 case BUILT_IN_EH_RETURN
:
7875 expand_builtin_eh_return (CALL_EXPR_ARG (exp
, 0),
7876 CALL_EXPR_ARG (exp
, 1));
7878 case BUILT_IN_EH_RETURN_DATA_REGNO
:
7879 return expand_builtin_eh_return_data_regno (exp
);
7880 case BUILT_IN_EXTEND_POINTER
:
7881 return expand_builtin_extend_pointer (CALL_EXPR_ARG (exp
, 0));
7882 case BUILT_IN_EH_POINTER
:
7883 return expand_builtin_eh_pointer (exp
);
7884 case BUILT_IN_EH_FILTER
:
7885 return expand_builtin_eh_filter (exp
);
7886 case BUILT_IN_EH_COPY_VALUES
:
7887 return expand_builtin_eh_copy_values (exp
);
7889 case BUILT_IN_VA_START
:
7890 return expand_builtin_va_start (exp
);
7891 case BUILT_IN_VA_END
:
7892 return expand_builtin_va_end (exp
);
7893 case BUILT_IN_VA_COPY
:
7894 return expand_builtin_va_copy (exp
);
7895 case BUILT_IN_EXPECT
:
7896 return expand_builtin_expect (exp
, target
);
7897 case BUILT_IN_EXPECT_WITH_PROBABILITY
:
7898 return expand_builtin_expect_with_probability (exp
, target
);
7899 case BUILT_IN_ASSUME_ALIGNED
:
7900 return expand_builtin_assume_aligned (exp
, target
);
7901 case BUILT_IN_PREFETCH
:
7902 expand_builtin_prefetch (exp
);
7905 case BUILT_IN_INIT_TRAMPOLINE
:
7906 return expand_builtin_init_trampoline (exp
, true);
7907 case BUILT_IN_INIT_HEAP_TRAMPOLINE
:
7908 return expand_builtin_init_trampoline (exp
, false);
7909 case BUILT_IN_ADJUST_TRAMPOLINE
:
7910 return expand_builtin_adjust_trampoline (exp
);
7912 case BUILT_IN_INIT_DESCRIPTOR
:
7913 return expand_builtin_init_descriptor (exp
);
7914 case BUILT_IN_ADJUST_DESCRIPTOR
:
7915 return expand_builtin_adjust_descriptor (exp
);
7918 case BUILT_IN_EXECL
:
7919 case BUILT_IN_EXECV
:
7920 case BUILT_IN_EXECLP
:
7921 case BUILT_IN_EXECLE
:
7922 case BUILT_IN_EXECVP
:
7923 case BUILT_IN_EXECVE
:
7924 target
= expand_builtin_fork_or_exec (fndecl
, exp
, target
, ignore
);
7929 case BUILT_IN_SYNC_FETCH_AND_ADD_1
:
7930 case BUILT_IN_SYNC_FETCH_AND_ADD_2
:
7931 case BUILT_IN_SYNC_FETCH_AND_ADD_4
:
7932 case BUILT_IN_SYNC_FETCH_AND_ADD_8
:
7933 case BUILT_IN_SYNC_FETCH_AND_ADD_16
:
7934 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_FETCH_AND_ADD_1
);
7935 target
= expand_builtin_sync_operation (mode
, exp
, PLUS
, false, target
);
7940 case BUILT_IN_SYNC_FETCH_AND_SUB_1
:
7941 case BUILT_IN_SYNC_FETCH_AND_SUB_2
:
7942 case BUILT_IN_SYNC_FETCH_AND_SUB_4
:
7943 case BUILT_IN_SYNC_FETCH_AND_SUB_8
:
7944 case BUILT_IN_SYNC_FETCH_AND_SUB_16
:
7945 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_FETCH_AND_SUB_1
);
7946 target
= expand_builtin_sync_operation (mode
, exp
, MINUS
, false, target
);
7951 case BUILT_IN_SYNC_FETCH_AND_OR_1
:
7952 case BUILT_IN_SYNC_FETCH_AND_OR_2
:
7953 case BUILT_IN_SYNC_FETCH_AND_OR_4
:
7954 case BUILT_IN_SYNC_FETCH_AND_OR_8
:
7955 case BUILT_IN_SYNC_FETCH_AND_OR_16
:
7956 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_FETCH_AND_OR_1
);
7957 target
= expand_builtin_sync_operation (mode
, exp
, IOR
, false, target
);
7962 case BUILT_IN_SYNC_FETCH_AND_AND_1
:
7963 case BUILT_IN_SYNC_FETCH_AND_AND_2
:
7964 case BUILT_IN_SYNC_FETCH_AND_AND_4
:
7965 case BUILT_IN_SYNC_FETCH_AND_AND_8
:
7966 case BUILT_IN_SYNC_FETCH_AND_AND_16
:
7967 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_FETCH_AND_AND_1
);
7968 target
= expand_builtin_sync_operation (mode
, exp
, AND
, false, target
);
7973 case BUILT_IN_SYNC_FETCH_AND_XOR_1
:
7974 case BUILT_IN_SYNC_FETCH_AND_XOR_2
:
7975 case BUILT_IN_SYNC_FETCH_AND_XOR_4
:
7976 case BUILT_IN_SYNC_FETCH_AND_XOR_8
:
7977 case BUILT_IN_SYNC_FETCH_AND_XOR_16
:
7978 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_FETCH_AND_XOR_1
);
7979 target
= expand_builtin_sync_operation (mode
, exp
, XOR
, false, target
);
7984 case BUILT_IN_SYNC_FETCH_AND_NAND_1
:
7985 case BUILT_IN_SYNC_FETCH_AND_NAND_2
:
7986 case BUILT_IN_SYNC_FETCH_AND_NAND_4
:
7987 case BUILT_IN_SYNC_FETCH_AND_NAND_8
:
7988 case BUILT_IN_SYNC_FETCH_AND_NAND_16
:
7989 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_FETCH_AND_NAND_1
);
7990 target
= expand_builtin_sync_operation (mode
, exp
, NOT
, false, target
);
7995 case BUILT_IN_SYNC_ADD_AND_FETCH_1
:
7996 case BUILT_IN_SYNC_ADD_AND_FETCH_2
:
7997 case BUILT_IN_SYNC_ADD_AND_FETCH_4
:
7998 case BUILT_IN_SYNC_ADD_AND_FETCH_8
:
7999 case BUILT_IN_SYNC_ADD_AND_FETCH_16
:
8000 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_ADD_AND_FETCH_1
);
8001 target
= expand_builtin_sync_operation (mode
, exp
, PLUS
, true, target
);
8006 case BUILT_IN_SYNC_SUB_AND_FETCH_1
:
8007 case BUILT_IN_SYNC_SUB_AND_FETCH_2
:
8008 case BUILT_IN_SYNC_SUB_AND_FETCH_4
:
8009 case BUILT_IN_SYNC_SUB_AND_FETCH_8
:
8010 case BUILT_IN_SYNC_SUB_AND_FETCH_16
:
8011 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_SUB_AND_FETCH_1
);
8012 target
= expand_builtin_sync_operation (mode
, exp
, MINUS
, true, target
);
8017 case BUILT_IN_SYNC_OR_AND_FETCH_1
:
8018 case BUILT_IN_SYNC_OR_AND_FETCH_2
:
8019 case BUILT_IN_SYNC_OR_AND_FETCH_4
:
8020 case BUILT_IN_SYNC_OR_AND_FETCH_8
:
8021 case BUILT_IN_SYNC_OR_AND_FETCH_16
:
8022 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_OR_AND_FETCH_1
);
8023 target
= expand_builtin_sync_operation (mode
, exp
, IOR
, true, target
);
8028 case BUILT_IN_SYNC_AND_AND_FETCH_1
:
8029 case BUILT_IN_SYNC_AND_AND_FETCH_2
:
8030 case BUILT_IN_SYNC_AND_AND_FETCH_4
:
8031 case BUILT_IN_SYNC_AND_AND_FETCH_8
:
8032 case BUILT_IN_SYNC_AND_AND_FETCH_16
:
8033 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_AND_AND_FETCH_1
);
8034 target
= expand_builtin_sync_operation (mode
, exp
, AND
, true, target
);
8039 case BUILT_IN_SYNC_XOR_AND_FETCH_1
:
8040 case BUILT_IN_SYNC_XOR_AND_FETCH_2
:
8041 case BUILT_IN_SYNC_XOR_AND_FETCH_4
:
8042 case BUILT_IN_SYNC_XOR_AND_FETCH_8
:
8043 case BUILT_IN_SYNC_XOR_AND_FETCH_16
:
8044 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_XOR_AND_FETCH_1
);
8045 target
= expand_builtin_sync_operation (mode
, exp
, XOR
, true, target
);
8050 case BUILT_IN_SYNC_NAND_AND_FETCH_1
:
8051 case BUILT_IN_SYNC_NAND_AND_FETCH_2
:
8052 case BUILT_IN_SYNC_NAND_AND_FETCH_4
:
8053 case BUILT_IN_SYNC_NAND_AND_FETCH_8
:
8054 case BUILT_IN_SYNC_NAND_AND_FETCH_16
:
8055 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_NAND_AND_FETCH_1
);
8056 target
= expand_builtin_sync_operation (mode
, exp
, NOT
, true, target
);
8061 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_1
:
8062 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_2
:
8063 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4
:
8064 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8
:
8065 case BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_16
:
8066 if (mode
== VOIDmode
)
8067 mode
= TYPE_MODE (boolean_type_node
);
8068 if (!target
|| !register_operand (target
, mode
))
8069 target
= gen_reg_rtx (mode
);
8071 mode
= get_builtin_sync_mode
8072 (fcode
- BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_1
);
8073 target
= expand_builtin_compare_and_swap (mode
, exp
, true, target
);
8078 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_1
:
8079 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_2
:
8080 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_4
:
8081 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_8
:
8082 case BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_16
:
8083 mode
= get_builtin_sync_mode
8084 (fcode
- BUILT_IN_SYNC_VAL_COMPARE_AND_SWAP_1
);
8085 target
= expand_builtin_compare_and_swap (mode
, exp
, false, target
);
8090 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_1
:
8091 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_2
:
8092 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_4
:
8093 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_8
:
8094 case BUILT_IN_SYNC_LOCK_TEST_AND_SET_16
:
8095 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_LOCK_TEST_AND_SET_1
);
8096 target
= expand_builtin_sync_lock_test_and_set (mode
, exp
, target
);
8101 case BUILT_IN_SYNC_LOCK_RELEASE_1
:
8102 case BUILT_IN_SYNC_LOCK_RELEASE_2
:
8103 case BUILT_IN_SYNC_LOCK_RELEASE_4
:
8104 case BUILT_IN_SYNC_LOCK_RELEASE_8
:
8105 case BUILT_IN_SYNC_LOCK_RELEASE_16
:
8106 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SYNC_LOCK_RELEASE_1
);
8107 expand_builtin_sync_lock_release (mode
, exp
);
8110 case BUILT_IN_SYNC_SYNCHRONIZE
:
8111 expand_builtin_sync_synchronize ();
8114 case BUILT_IN_ATOMIC_EXCHANGE_1
:
8115 case BUILT_IN_ATOMIC_EXCHANGE_2
:
8116 case BUILT_IN_ATOMIC_EXCHANGE_4
:
8117 case BUILT_IN_ATOMIC_EXCHANGE_8
:
8118 case BUILT_IN_ATOMIC_EXCHANGE_16
:
8119 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_EXCHANGE_1
);
8120 target
= expand_builtin_atomic_exchange (mode
, exp
, target
);
8125 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1
:
8126 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_2
:
8127 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_4
:
8128 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_8
:
8129 case BUILT_IN_ATOMIC_COMPARE_EXCHANGE_16
:
8131 unsigned int nargs
, z
;
8132 vec
<tree
, va_gc
> *vec
;
8135 get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_COMPARE_EXCHANGE_1
);
8136 target
= expand_builtin_atomic_compare_exchange (mode
, exp
, target
);
8140 /* If this is turned into an external library call, the weak parameter
8141 must be dropped to match the expected parameter list. */
8142 nargs
= call_expr_nargs (exp
);
8143 vec_alloc (vec
, nargs
- 1);
8144 for (z
= 0; z
< 3; z
++)
8145 vec
->quick_push (CALL_EXPR_ARG (exp
, z
));
8146 /* Skip the boolean weak parameter. */
8147 for (z
= 4; z
< 6; z
++)
8148 vec
->quick_push (CALL_EXPR_ARG (exp
, z
));
8149 exp
= build_call_vec (TREE_TYPE (exp
), CALL_EXPR_FN (exp
), vec
);
8153 case BUILT_IN_ATOMIC_LOAD_1
:
8154 case BUILT_IN_ATOMIC_LOAD_2
:
8155 case BUILT_IN_ATOMIC_LOAD_4
:
8156 case BUILT_IN_ATOMIC_LOAD_8
:
8157 case BUILT_IN_ATOMIC_LOAD_16
:
8158 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_LOAD_1
);
8159 target
= expand_builtin_atomic_load (mode
, exp
, target
);
8164 case BUILT_IN_ATOMIC_STORE_1
:
8165 case BUILT_IN_ATOMIC_STORE_2
:
8166 case BUILT_IN_ATOMIC_STORE_4
:
8167 case BUILT_IN_ATOMIC_STORE_8
:
8168 case BUILT_IN_ATOMIC_STORE_16
:
8169 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_STORE_1
);
8170 target
= expand_builtin_atomic_store (mode
, exp
);
8175 case BUILT_IN_ATOMIC_ADD_FETCH_1
:
8176 case BUILT_IN_ATOMIC_ADD_FETCH_2
:
8177 case BUILT_IN_ATOMIC_ADD_FETCH_4
:
8178 case BUILT_IN_ATOMIC_ADD_FETCH_8
:
8179 case BUILT_IN_ATOMIC_ADD_FETCH_16
:
8181 enum built_in_function lib
;
8182 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_ADD_FETCH_1
);
8183 lib
= (enum built_in_function
)((int)BUILT_IN_ATOMIC_FETCH_ADD_1
+
8184 (fcode
- BUILT_IN_ATOMIC_ADD_FETCH_1
));
8185 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, PLUS
, true,
8191 case BUILT_IN_ATOMIC_SUB_FETCH_1
:
8192 case BUILT_IN_ATOMIC_SUB_FETCH_2
:
8193 case BUILT_IN_ATOMIC_SUB_FETCH_4
:
8194 case BUILT_IN_ATOMIC_SUB_FETCH_8
:
8195 case BUILT_IN_ATOMIC_SUB_FETCH_16
:
8197 enum built_in_function lib
;
8198 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_SUB_FETCH_1
);
8199 lib
= (enum built_in_function
)((int)BUILT_IN_ATOMIC_FETCH_SUB_1
+
8200 (fcode
- BUILT_IN_ATOMIC_SUB_FETCH_1
));
8201 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, MINUS
, true,
8207 case BUILT_IN_ATOMIC_AND_FETCH_1
:
8208 case BUILT_IN_ATOMIC_AND_FETCH_2
:
8209 case BUILT_IN_ATOMIC_AND_FETCH_4
:
8210 case BUILT_IN_ATOMIC_AND_FETCH_8
:
8211 case BUILT_IN_ATOMIC_AND_FETCH_16
:
8213 enum built_in_function lib
;
8214 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_AND_FETCH_1
);
8215 lib
= (enum built_in_function
)((int)BUILT_IN_ATOMIC_FETCH_AND_1
+
8216 (fcode
- BUILT_IN_ATOMIC_AND_FETCH_1
));
8217 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, AND
, true,
8223 case BUILT_IN_ATOMIC_NAND_FETCH_1
:
8224 case BUILT_IN_ATOMIC_NAND_FETCH_2
:
8225 case BUILT_IN_ATOMIC_NAND_FETCH_4
:
8226 case BUILT_IN_ATOMIC_NAND_FETCH_8
:
8227 case BUILT_IN_ATOMIC_NAND_FETCH_16
:
8229 enum built_in_function lib
;
8230 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_NAND_FETCH_1
);
8231 lib
= (enum built_in_function
)((int)BUILT_IN_ATOMIC_FETCH_NAND_1
+
8232 (fcode
- BUILT_IN_ATOMIC_NAND_FETCH_1
));
8233 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, NOT
, true,
8239 case BUILT_IN_ATOMIC_XOR_FETCH_1
:
8240 case BUILT_IN_ATOMIC_XOR_FETCH_2
:
8241 case BUILT_IN_ATOMIC_XOR_FETCH_4
:
8242 case BUILT_IN_ATOMIC_XOR_FETCH_8
:
8243 case BUILT_IN_ATOMIC_XOR_FETCH_16
:
8245 enum built_in_function lib
;
8246 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_XOR_FETCH_1
);
8247 lib
= (enum built_in_function
)((int)BUILT_IN_ATOMIC_FETCH_XOR_1
+
8248 (fcode
- BUILT_IN_ATOMIC_XOR_FETCH_1
));
8249 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, XOR
, true,
8255 case BUILT_IN_ATOMIC_OR_FETCH_1
:
8256 case BUILT_IN_ATOMIC_OR_FETCH_2
:
8257 case BUILT_IN_ATOMIC_OR_FETCH_4
:
8258 case BUILT_IN_ATOMIC_OR_FETCH_8
:
8259 case BUILT_IN_ATOMIC_OR_FETCH_16
:
8261 enum built_in_function lib
;
8262 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_OR_FETCH_1
);
8263 lib
= (enum built_in_function
)((int)BUILT_IN_ATOMIC_FETCH_OR_1
+
8264 (fcode
- BUILT_IN_ATOMIC_OR_FETCH_1
));
8265 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, IOR
, true,
8271 case BUILT_IN_ATOMIC_FETCH_ADD_1
:
8272 case BUILT_IN_ATOMIC_FETCH_ADD_2
:
8273 case BUILT_IN_ATOMIC_FETCH_ADD_4
:
8274 case BUILT_IN_ATOMIC_FETCH_ADD_8
:
8275 case BUILT_IN_ATOMIC_FETCH_ADD_16
:
8276 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_FETCH_ADD_1
);
8277 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, PLUS
, false,
8278 ignore
, BUILT_IN_NONE
);
8283 case BUILT_IN_ATOMIC_FETCH_SUB_1
:
8284 case BUILT_IN_ATOMIC_FETCH_SUB_2
:
8285 case BUILT_IN_ATOMIC_FETCH_SUB_4
:
8286 case BUILT_IN_ATOMIC_FETCH_SUB_8
:
8287 case BUILT_IN_ATOMIC_FETCH_SUB_16
:
8288 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_FETCH_SUB_1
);
8289 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, MINUS
, false,
8290 ignore
, BUILT_IN_NONE
);
8295 case BUILT_IN_ATOMIC_FETCH_AND_1
:
8296 case BUILT_IN_ATOMIC_FETCH_AND_2
:
8297 case BUILT_IN_ATOMIC_FETCH_AND_4
:
8298 case BUILT_IN_ATOMIC_FETCH_AND_8
:
8299 case BUILT_IN_ATOMIC_FETCH_AND_16
:
8300 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_FETCH_AND_1
);
8301 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, AND
, false,
8302 ignore
, BUILT_IN_NONE
);
8307 case BUILT_IN_ATOMIC_FETCH_NAND_1
:
8308 case BUILT_IN_ATOMIC_FETCH_NAND_2
:
8309 case BUILT_IN_ATOMIC_FETCH_NAND_4
:
8310 case BUILT_IN_ATOMIC_FETCH_NAND_8
:
8311 case BUILT_IN_ATOMIC_FETCH_NAND_16
:
8312 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_FETCH_NAND_1
);
8313 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, NOT
, false,
8314 ignore
, BUILT_IN_NONE
);
8319 case BUILT_IN_ATOMIC_FETCH_XOR_1
:
8320 case BUILT_IN_ATOMIC_FETCH_XOR_2
:
8321 case BUILT_IN_ATOMIC_FETCH_XOR_4
:
8322 case BUILT_IN_ATOMIC_FETCH_XOR_8
:
8323 case BUILT_IN_ATOMIC_FETCH_XOR_16
:
8324 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_FETCH_XOR_1
);
8325 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, XOR
, false,
8326 ignore
, BUILT_IN_NONE
);
8331 case BUILT_IN_ATOMIC_FETCH_OR_1
:
8332 case BUILT_IN_ATOMIC_FETCH_OR_2
:
8333 case BUILT_IN_ATOMIC_FETCH_OR_4
:
8334 case BUILT_IN_ATOMIC_FETCH_OR_8
:
8335 case BUILT_IN_ATOMIC_FETCH_OR_16
:
8336 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_ATOMIC_FETCH_OR_1
);
8337 target
= expand_builtin_atomic_fetch_op (mode
, exp
, target
, IOR
, false,
8338 ignore
, BUILT_IN_NONE
);
8343 case BUILT_IN_ATOMIC_TEST_AND_SET
:
8344 return expand_builtin_atomic_test_and_set (exp
, target
);
8346 case BUILT_IN_ATOMIC_CLEAR
:
8347 return expand_builtin_atomic_clear (exp
);
8349 case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE
:
8350 return expand_builtin_atomic_always_lock_free (exp
);
8352 case BUILT_IN_ATOMIC_IS_LOCK_FREE
:
8353 target
= expand_builtin_atomic_is_lock_free (exp
);
8358 case BUILT_IN_ATOMIC_THREAD_FENCE
:
8359 expand_builtin_atomic_thread_fence (exp
);
8362 case BUILT_IN_ATOMIC_SIGNAL_FENCE
:
8363 expand_builtin_atomic_signal_fence (exp
);
8366 case BUILT_IN_OBJECT_SIZE
:
8367 case BUILT_IN_DYNAMIC_OBJECT_SIZE
:
8368 return expand_builtin_object_size (exp
);
8370 case BUILT_IN_MEMCPY_CHK
:
8371 case BUILT_IN_MEMPCPY_CHK
:
8372 case BUILT_IN_MEMMOVE_CHK
:
8373 case BUILT_IN_MEMSET_CHK
:
8374 target
= expand_builtin_memory_chk (exp
, target
, mode
, fcode
);
8379 case BUILT_IN_STRCPY_CHK
:
8380 case BUILT_IN_STPCPY_CHK
:
8381 case BUILT_IN_STRNCPY_CHK
:
8382 case BUILT_IN_STPNCPY_CHK
:
8383 case BUILT_IN_STRCAT_CHK
:
8384 case BUILT_IN_STRNCAT_CHK
:
8385 case BUILT_IN_SNPRINTF_CHK
:
8386 case BUILT_IN_VSNPRINTF_CHK
:
8387 maybe_emit_chk_warning (exp
, fcode
);
8390 case BUILT_IN_SPRINTF_CHK
:
8391 case BUILT_IN_VSPRINTF_CHK
:
8392 maybe_emit_sprintf_chk_warning (exp
, fcode
);
8395 case BUILT_IN_THREAD_POINTER
:
8396 return expand_builtin_thread_pointer (exp
, target
);
8398 case BUILT_IN_SET_THREAD_POINTER
:
8399 expand_builtin_set_thread_pointer (exp
);
8402 case BUILT_IN_ACC_ON_DEVICE
:
8403 /* Do library call, if we failed to expand the builtin when
8407 case BUILT_IN_GOACC_PARLEVEL_ID
:
8408 case BUILT_IN_GOACC_PARLEVEL_SIZE
:
8409 return expand_builtin_goacc_parlevel_id_size (exp
, target
, ignore
);
8411 case BUILT_IN_SPECULATION_SAFE_VALUE_PTR
:
8412 return expand_speculation_safe_value (VOIDmode
, exp
, target
, ignore
);
8414 case BUILT_IN_SPECULATION_SAFE_VALUE_1
:
8415 case BUILT_IN_SPECULATION_SAFE_VALUE_2
:
8416 case BUILT_IN_SPECULATION_SAFE_VALUE_4
:
8417 case BUILT_IN_SPECULATION_SAFE_VALUE_8
:
8418 case BUILT_IN_SPECULATION_SAFE_VALUE_16
:
8419 mode
= get_builtin_sync_mode (fcode
- BUILT_IN_SPECULATION_SAFE_VALUE_1
);
8420 return expand_speculation_safe_value (mode
, exp
, target
, ignore
);
8422 default: /* just do library call, if unknown builtin */
8426 /* The switch statement above can drop through to cause the function
8427 to be called normally. */
8428 return expand_call (exp
, target
, ignore
);
8431 /* Determine whether a tree node represents a call to a built-in
8432 function. If the tree T is a call to a built-in function with
8433 the right number of arguments of the appropriate types, return
8434 the DECL_FUNCTION_CODE of the call, e.g. BUILT_IN_SQRT.
8435 Otherwise the return value is END_BUILTINS. */
8437 enum built_in_function
8438 builtin_mathfn_code (const_tree t
)
8440 const_tree fndecl
, arg
, parmlist
;
8441 const_tree argtype
, parmtype
;
8442 const_call_expr_arg_iterator iter
;
8444 if (TREE_CODE (t
) != CALL_EXPR
)
8445 return END_BUILTINS
;
8447 fndecl
= get_callee_fndecl (t
);
8448 if (fndecl
== NULL_TREE
|| !fndecl_built_in_p (fndecl
, BUILT_IN_NORMAL
))
8449 return END_BUILTINS
;
8451 parmlist
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
8452 init_const_call_expr_arg_iterator (t
, &iter
);
8453 for (; parmlist
; parmlist
= TREE_CHAIN (parmlist
))
8455 /* If a function doesn't take a variable number of arguments,
8456 the last element in the list will have type `void'. */
8457 parmtype
= TREE_VALUE (parmlist
);
8458 if (VOID_TYPE_P (parmtype
))
8460 if (more_const_call_expr_args_p (&iter
))
8461 return END_BUILTINS
;
8462 return DECL_FUNCTION_CODE (fndecl
);
8465 if (! more_const_call_expr_args_p (&iter
))
8466 return END_BUILTINS
;
8468 arg
= next_const_call_expr_arg (&iter
);
8469 argtype
= TREE_TYPE (arg
);
8471 if (SCALAR_FLOAT_TYPE_P (parmtype
))
8473 if (! SCALAR_FLOAT_TYPE_P (argtype
))
8474 return END_BUILTINS
;
8476 else if (COMPLEX_FLOAT_TYPE_P (parmtype
))
8478 if (! COMPLEX_FLOAT_TYPE_P (argtype
))
8479 return END_BUILTINS
;
8481 else if (POINTER_TYPE_P (parmtype
))
8483 if (! POINTER_TYPE_P (argtype
))
8484 return END_BUILTINS
;
8486 else if (INTEGRAL_TYPE_P (parmtype
))
8488 if (! INTEGRAL_TYPE_P (argtype
))
8489 return END_BUILTINS
;
8492 return END_BUILTINS
;
8495 /* Variable-length argument list. */
8496 return DECL_FUNCTION_CODE (fndecl
);
8499 /* Fold a call to __builtin_constant_p, if we know its argument ARG will
8500 evaluate to a constant. */
8503 fold_builtin_constant_p (tree arg
)
8505 /* We return 1 for a numeric type that's known to be a constant
8506 value at compile-time or for an aggregate type that's a
8507 literal constant. */
8510 /* If we know this is a constant, emit the constant of one. */
8511 if (CONSTANT_CLASS_P (arg
)
8512 || (TREE_CODE (arg
) == CONSTRUCTOR
8513 && TREE_CONSTANT (arg
)))
8514 return integer_one_node
;
8515 if (TREE_CODE (arg
) == ADDR_EXPR
)
8517 tree op
= TREE_OPERAND (arg
, 0);
8518 if (TREE_CODE (op
) == STRING_CST
8519 || (TREE_CODE (op
) == ARRAY_REF
8520 && integer_zerop (TREE_OPERAND (op
, 1))
8521 && TREE_CODE (TREE_OPERAND (op
, 0)) == STRING_CST
))
8522 return integer_one_node
;
8525 /* If this expression has side effects, show we don't know it to be a
8526 constant. Likewise if it's a pointer or aggregate type since in
8527 those case we only want literals, since those are only optimized
8528 when generating RTL, not later.
8529 And finally, if we are compiling an initializer, not code, we
8530 need to return a definite result now; there's not going to be any
8531 more optimization done. */
8532 if (TREE_SIDE_EFFECTS (arg
)
8533 || AGGREGATE_TYPE_P (TREE_TYPE (arg
))
8534 || POINTER_TYPE_P (TREE_TYPE (arg
))
8536 || folding_initializer
8537 || force_folding_builtin_constant_p
)
8538 return integer_zero_node
;
8543 /* Create builtin_expect or builtin_expect_with_probability
8544 with PRED and EXPECTED as its arguments and return it as a truthvalue.
8545 Fortran FE can also produce builtin_expect with PREDICTOR as third argument.
8546 builtin_expect_with_probability instead uses third argument as PROBABILITY
8550 build_builtin_expect_predicate (location_t loc
, tree pred
, tree expected
,
8551 tree predictor
, tree probability
)
8553 tree fn
, arg_types
, pred_type
, expected_type
, call_expr
, ret_type
;
8555 fn
= builtin_decl_explicit (probability
== NULL_TREE
? BUILT_IN_EXPECT
8556 : BUILT_IN_EXPECT_WITH_PROBABILITY
);
8557 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
8558 ret_type
= TREE_TYPE (TREE_TYPE (fn
));
8559 pred_type
= TREE_VALUE (arg_types
);
8560 expected_type
= TREE_VALUE (TREE_CHAIN (arg_types
));
8562 pred
= fold_convert_loc (loc
, pred_type
, pred
);
8563 expected
= fold_convert_loc (loc
, expected_type
, expected
);
8566 call_expr
= build_call_expr_loc (loc
, fn
, 3, pred
, expected
, probability
);
8568 call_expr
= build_call_expr_loc (loc
, fn
, predictor
? 3 : 2, pred
, expected
,
8571 return build2 (NE_EXPR
, TREE_TYPE (pred
), call_expr
,
8572 build_int_cst (ret_type
, 0));
8575 /* Fold a call to builtin_expect with arguments ARG0, ARG1, ARG2, ARG3. Return
8576 NULL_TREE if no simplification is possible. */
8579 fold_builtin_expect (location_t loc
, tree arg0
, tree arg1
, tree arg2
,
8582 tree inner
, fndecl
, inner_arg0
;
8583 enum tree_code code
;
8585 /* Distribute the expected value over short-circuiting operators.
8586 See through the cast from truthvalue_type_node to long. */
8588 while (CONVERT_EXPR_P (inner_arg0
)
8589 && INTEGRAL_TYPE_P (TREE_TYPE (inner_arg0
))
8590 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (inner_arg0
, 0))))
8591 inner_arg0
= TREE_OPERAND (inner_arg0
, 0);
8593 /* If this is a builtin_expect within a builtin_expect keep the
8594 inner one. See through a comparison against a constant. It
8595 might have been added to create a thruthvalue. */
8598 if (COMPARISON_CLASS_P (inner
)
8599 && TREE_CODE (TREE_OPERAND (inner
, 1)) == INTEGER_CST
)
8600 inner
= TREE_OPERAND (inner
, 0);
8602 if (TREE_CODE (inner
) == CALL_EXPR
8603 && (fndecl
= get_callee_fndecl (inner
))
8604 && (fndecl_built_in_p (fndecl
, BUILT_IN_EXPECT
)
8605 || fndecl_built_in_p (fndecl
, BUILT_IN_EXPECT_WITH_PROBABILITY
)))
8609 code
= TREE_CODE (inner
);
8610 if (code
== TRUTH_ANDIF_EXPR
|| code
== TRUTH_ORIF_EXPR
)
8612 tree op0
= TREE_OPERAND (inner
, 0);
8613 tree op1
= TREE_OPERAND (inner
, 1);
8614 arg1
= save_expr (arg1
);
8616 op0
= build_builtin_expect_predicate (loc
, op0
, arg1
, arg2
, arg3
);
8617 op1
= build_builtin_expect_predicate (loc
, op1
, arg1
, arg2
, arg3
);
8618 inner
= build2 (code
, TREE_TYPE (inner
), op0
, op1
);
8620 return fold_convert_loc (loc
, TREE_TYPE (arg0
), inner
);
8623 /* If the argument isn't invariant then there's nothing else we can do. */
8624 if (!TREE_CONSTANT (inner_arg0
))
8627 /* If we expect that a comparison against the argument will fold to
8628 a constant return the constant. In practice, this means a true
8629 constant or the address of a non-weak symbol. */
8632 if (TREE_CODE (inner
) == ADDR_EXPR
)
8636 inner
= TREE_OPERAND (inner
, 0);
8638 while (TREE_CODE (inner
) == COMPONENT_REF
8639 || TREE_CODE (inner
) == ARRAY_REF
);
8640 if (VAR_OR_FUNCTION_DECL_P (inner
) && DECL_WEAK (inner
))
8644 /* Otherwise, ARG0 already has the proper type for the return value. */
8648 /* Fold a call to __builtin_classify_type with argument ARG. */
8651 fold_builtin_classify_type (tree arg
)
8654 return build_int_cst (integer_type_node
, no_type_class
);
8656 return build_int_cst (integer_type_node
, type_to_class (TREE_TYPE (arg
)));
8659 /* Fold a call EXPR (which may be null) to __builtin_strlen with argument
8663 fold_builtin_strlen (location_t loc
, tree expr
, tree type
, tree arg
)
8665 if (!validate_arg (arg
, POINTER_TYPE
))
8669 c_strlen_data lendata
= { };
8670 tree len
= c_strlen (arg
, 0, &lendata
);
8673 return fold_convert_loc (loc
, type
, len
);
8675 /* TODO: Move this to gimple-ssa-warn-access once the pass runs
8676 also early enough to detect invalid reads in multimensional
8677 arrays and struct members. */
8679 c_strlen (arg
, 1, &lendata
);
8683 if (EXPR_HAS_LOCATION (arg
))
8684 loc
= EXPR_LOCATION (arg
);
8685 else if (loc
== UNKNOWN_LOCATION
)
8686 loc
= input_location
;
8687 warn_string_no_nul (loc
, expr
, "strlen", arg
, lendata
.decl
);
8694 /* Fold a call to __builtin_inf or __builtin_huge_val. */
8697 fold_builtin_inf (location_t loc
, tree type
, int warn
)
8699 /* __builtin_inff is intended to be usable to define INFINITY on all
8700 targets. If an infinity is not available, INFINITY expands "to a
8701 positive constant of type float that overflows at translation
8702 time", footnote "In this case, using INFINITY will violate the
8703 constraint in 6.4.4 and thus require a diagnostic." (C99 7.12#4).
8704 Thus we pedwarn to ensure this constraint violation is
8706 if (!MODE_HAS_INFINITIES (TYPE_MODE (type
)) && warn
)
8707 pedwarn (loc
, 0, "target format does not support infinity");
8709 return build_real (type
, dconstinf
);
8712 /* Fold function call to builtin sincos, sincosf, or sincosl. Return
8713 NULL_TREE if no simplification can be made. */
8716 fold_builtin_sincos (location_t loc
,
8717 tree arg0
, tree arg1
, tree arg2
)
8720 tree fndecl
, call
= NULL_TREE
;
8722 if (!validate_arg (arg0
, REAL_TYPE
)
8723 || !validate_arg (arg1
, POINTER_TYPE
)
8724 || !validate_arg (arg2
, POINTER_TYPE
))
8727 type
= TREE_TYPE (arg0
);
8729 /* Calculate the result when the argument is a constant. */
8730 built_in_function fn
= mathfn_built_in_2 (type
, CFN_BUILT_IN_CEXPI
);
8731 if (fn
== END_BUILTINS
)
8734 /* Canonicalize sincos to cexpi. */
8735 if (TREE_CODE (arg0
) == REAL_CST
)
8737 tree complex_type
= build_complex_type (type
);
8738 call
= fold_const_call (as_combined_fn (fn
), complex_type
, arg0
);
8742 if (!targetm
.libc_has_function (function_c99_math_complex
, type
)
8743 || !builtin_decl_implicit_p (fn
))
8745 fndecl
= builtin_decl_explicit (fn
);
8746 call
= build_call_expr_loc (loc
, fndecl
, 1, arg0
);
8747 call
= builtin_save_expr (call
);
8750 tree ptype
= build_pointer_type (type
);
8751 arg1
= fold_convert (ptype
, arg1
);
8752 arg2
= fold_convert (ptype
, arg2
);
8753 return build2 (COMPOUND_EXPR
, void_type_node
,
8754 build2 (MODIFY_EXPR
, void_type_node
,
8755 build_fold_indirect_ref_loc (loc
, arg1
),
8756 fold_build1_loc (loc
, IMAGPART_EXPR
, type
, call
)),
8757 build2 (MODIFY_EXPR
, void_type_node
,
8758 build_fold_indirect_ref_loc (loc
, arg2
),
8759 fold_build1_loc (loc
, REALPART_EXPR
, type
, call
)));
8762 /* Fold function call to builtin memcmp with arguments ARG1 and ARG2.
8763 Return NULL_TREE if no simplification can be made. */
8766 fold_builtin_memcmp (location_t loc
, tree arg1
, tree arg2
, tree len
)
8768 if (!validate_arg (arg1
, POINTER_TYPE
)
8769 || !validate_arg (arg2
, POINTER_TYPE
)
8770 || !validate_arg (len
, INTEGER_TYPE
))
8773 /* If the LEN parameter is zero, return zero. */
8774 if (integer_zerop (len
))
8775 return omit_two_operands_loc (loc
, integer_type_node
, integer_zero_node
,
8778 /* If ARG1 and ARG2 are the same (and not volatile), return zero. */
8779 if (operand_equal_p (arg1
, arg2
, 0))
8780 return omit_one_operand_loc (loc
, integer_type_node
, integer_zero_node
, len
);
8782 /* If len parameter is one, return an expression corresponding to
8783 (*(const unsigned char*)arg1 - (const unsigned char*)arg2). */
8784 if (tree_fits_uhwi_p (len
) && tree_to_uhwi (len
) == 1)
8786 tree cst_uchar_node
= build_type_variant (unsigned_char_type_node
, 1, 0);
8787 tree cst_uchar_ptr_node
8788 = build_pointer_type_for_mode (cst_uchar_node
, ptr_mode
, true);
8791 = fold_convert_loc (loc
, integer_type_node
,
8792 build1 (INDIRECT_REF
, cst_uchar_node
,
8793 fold_convert_loc (loc
,
8797 = fold_convert_loc (loc
, integer_type_node
,
8798 build1 (INDIRECT_REF
, cst_uchar_node
,
8799 fold_convert_loc (loc
,
8802 return fold_build2_loc (loc
, MINUS_EXPR
, integer_type_node
, ind1
, ind2
);
8808 /* Fold a call to builtin isascii with argument ARG. */
8811 fold_builtin_isascii (location_t loc
, tree arg
)
8813 if (!validate_arg (arg
, INTEGER_TYPE
))
8817 /* Transform isascii(c) -> ((c & ~0x7f) == 0). */
8818 arg
= fold_build2 (BIT_AND_EXPR
, integer_type_node
, arg
,
8819 build_int_cst (integer_type_node
,
8820 ~ (unsigned HOST_WIDE_INT
) 0x7f));
8821 return fold_build2_loc (loc
, EQ_EXPR
, integer_type_node
,
8822 arg
, integer_zero_node
);
8826 /* Fold a call to builtin toascii with argument ARG. */
8829 fold_builtin_toascii (location_t loc
, tree arg
)
8831 if (!validate_arg (arg
, INTEGER_TYPE
))
8834 /* Transform toascii(c) -> (c & 0x7f). */
8835 return fold_build2_loc (loc
, BIT_AND_EXPR
, integer_type_node
, arg
,
8836 build_int_cst (integer_type_node
, 0x7f));
8839 /* Fold a call to builtin isdigit with argument ARG. */
8842 fold_builtin_isdigit (location_t loc
, tree arg
)
8844 if (!validate_arg (arg
, INTEGER_TYPE
))
8848 /* Transform isdigit(c) -> (unsigned)(c) - '0' <= 9. */
8849 /* According to the C standard, isdigit is unaffected by locale.
8850 However, it definitely is affected by the target character set. */
8851 unsigned HOST_WIDE_INT target_digit0
8852 = lang_hooks
.to_target_charset ('0');
8854 if (target_digit0
== 0)
8857 arg
= fold_convert_loc (loc
, unsigned_type_node
, arg
);
8858 arg
= fold_build2 (MINUS_EXPR
, unsigned_type_node
, arg
,
8859 build_int_cst (unsigned_type_node
, target_digit0
));
8860 return fold_build2_loc (loc
, LE_EXPR
, integer_type_node
, arg
,
8861 build_int_cst (unsigned_type_node
, 9));
8865 /* Fold a call to fabs, fabsf or fabsl with argument ARG. */
8868 fold_builtin_fabs (location_t loc
, tree arg
, tree type
)
8870 if (!validate_arg (arg
, REAL_TYPE
))
8873 arg
= fold_convert_loc (loc
, type
, arg
);
8874 return fold_build1_loc (loc
, ABS_EXPR
, type
, arg
);
8877 /* Fold a call to abs, labs, llabs or imaxabs with argument ARG. */
8880 fold_builtin_abs (location_t loc
, tree arg
, tree type
)
8882 if (!validate_arg (arg
, INTEGER_TYPE
))
8885 arg
= fold_convert_loc (loc
, type
, arg
);
8886 return fold_build1_loc (loc
, ABS_EXPR
, type
, arg
);
8889 /* Fold a call to builtin carg(a+bi) -> atan2(b,a). */
8892 fold_builtin_carg (location_t loc
, tree arg
, tree type
)
8894 if (validate_arg (arg
, COMPLEX_TYPE
)
8895 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg
))) == REAL_TYPE
)
8897 tree atan2_fn
= mathfn_built_in (type
, BUILT_IN_ATAN2
);
8901 tree new_arg
= builtin_save_expr (arg
);
8902 tree r_arg
= fold_build1_loc (loc
, REALPART_EXPR
, type
, new_arg
);
8903 tree i_arg
= fold_build1_loc (loc
, IMAGPART_EXPR
, type
, new_arg
);
8904 return build_call_expr_loc (loc
, atan2_fn
, 2, i_arg
, r_arg
);
8911 /* Fold a call to builtin frexp, we can assume the base is 2. */
8914 fold_builtin_frexp (location_t loc
, tree arg0
, tree arg1
, tree rettype
)
8916 if (! validate_arg (arg0
, REAL_TYPE
) || ! validate_arg (arg1
, POINTER_TYPE
))
8921 if (!(TREE_CODE (arg0
) == REAL_CST
&& ! TREE_OVERFLOW (arg0
)))
8924 arg1
= build_fold_indirect_ref_loc (loc
, arg1
);
8926 /* Proceed if a valid pointer type was passed in. */
8927 if (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
)) == integer_type_node
)
8929 const REAL_VALUE_TYPE
*const value
= TREE_REAL_CST_PTR (arg0
);
8930 tree frac
, exp
, res
;
8935 /* For +-0, return (*exp = 0, +-0). */
8936 exp
= integer_zero_node
;
8941 /* For +-NaN or +-Inf, *exp is unspecified, return arg0. */
8942 return omit_one_operand_loc (loc
, rettype
, arg0
, arg1
);
8945 /* Since the frexp function always expects base 2, and in
8946 GCC normalized significands are already in the range
8947 [0.5, 1.0), we have exactly what frexp wants. */
8948 REAL_VALUE_TYPE frac_rvt
= *value
;
8949 SET_REAL_EXP (&frac_rvt
, 0);
8950 frac
= build_real (rettype
, frac_rvt
);
8951 exp
= build_int_cst (integer_type_node
, REAL_EXP (value
));
8958 /* Create the COMPOUND_EXPR (*arg1 = trunc, frac). */
8959 arg1
= fold_build2_loc (loc
, MODIFY_EXPR
, rettype
, arg1
, exp
);
8960 TREE_SIDE_EFFECTS (arg1
) = 1;
8961 res
= fold_build2_loc (loc
, COMPOUND_EXPR
, rettype
, arg1
, frac
);
8962 suppress_warning (res
, OPT_Wunused_value
);
8969 /* Fold a call to builtin modf. */
8972 fold_builtin_modf (location_t loc
, tree arg0
, tree arg1
, tree rettype
)
8974 if (! validate_arg (arg0
, REAL_TYPE
) || ! validate_arg (arg1
, POINTER_TYPE
))
8979 if (!(TREE_CODE (arg0
) == REAL_CST
&& ! TREE_OVERFLOW (arg0
)))
8982 arg1
= build_fold_indirect_ref_loc (loc
, arg1
);
8984 /* Proceed if a valid pointer type was passed in. */
8985 if (TYPE_MAIN_VARIANT (TREE_TYPE (arg1
)) == TYPE_MAIN_VARIANT (rettype
))
8987 const REAL_VALUE_TYPE
*const value
= TREE_REAL_CST_PTR (arg0
);
8988 REAL_VALUE_TYPE trunc
, frac
;
8995 /* For +-NaN or +-0, return (*arg1 = arg0, arg0). */
8996 trunc
= frac
= *value
;
8999 /* For +-Inf, return (*arg1 = arg0, +-0). */
9001 frac
.sign
= value
->sign
;
9005 /* Return (*arg1 = trunc(arg0), arg0-trunc(arg0)). */
9006 real_trunc (&trunc
, VOIDmode
, value
);
9007 real_arithmetic (&frac
, MINUS_EXPR
, value
, &trunc
);
9008 /* If the original number was negative and already
9009 integral, then the fractional part is -0.0. */
9010 if (value
->sign
&& frac
.cl
== rvc_zero
)
9011 frac
.sign
= value
->sign
;
9015 /* Create the COMPOUND_EXPR (*arg1 = trunc, frac). */
9016 arg1
= fold_build2_loc (loc
, MODIFY_EXPR
, rettype
, arg1
,
9017 build_real (rettype
, trunc
));
9018 TREE_SIDE_EFFECTS (arg1
) = 1;
9019 res
= fold_build2_loc (loc
, COMPOUND_EXPR
, rettype
, arg1
,
9020 build_real (rettype
, frac
));
9021 suppress_warning (res
, OPT_Wunused_value
);
9028 /* Given a location LOC, an interclass builtin function decl FNDECL
9029 and its single argument ARG, return an folded expression computing
9030 the same, or NULL_TREE if we either couldn't or didn't want to fold
9031 (the latter happen if there's an RTL instruction available). */
9034 fold_builtin_interclass_mathfn (location_t loc
, tree fndecl
, tree arg
)
9038 if (!validate_arg (arg
, REAL_TYPE
))
9041 if (interclass_mathfn_icode (arg
, fndecl
) != CODE_FOR_nothing
)
9044 mode
= TYPE_MODE (TREE_TYPE (arg
));
9046 bool is_ibm_extended
= MODE_COMPOSITE_P (mode
);
9048 /* If there is no optab, try generic code. */
9049 switch (DECL_FUNCTION_CODE (fndecl
))
9053 CASE_FLT_FN (BUILT_IN_ISINF
):
9055 /* isinf(x) -> isgreater(fabs(x),DBL_MAX). */
9056 tree
const isgr_fn
= builtin_decl_explicit (BUILT_IN_ISGREATER
);
9057 tree type
= TREE_TYPE (arg
);
9061 if (is_ibm_extended
)
9063 /* NaN and Inf are encoded in the high-order double value
9064 only. The low-order value is not significant. */
9065 type
= double_type_node
;
9067 arg
= fold_build1_loc (loc
, NOP_EXPR
, type
, arg
);
9069 get_max_float (REAL_MODE_FORMAT (mode
), buf
, sizeof (buf
), false);
9070 real_from_string (&r
, buf
);
9071 result
= build_call_expr (isgr_fn
, 2,
9072 fold_build1_loc (loc
, ABS_EXPR
, type
, arg
),
9073 build_real (type
, r
));
9076 CASE_FLT_FN (BUILT_IN_FINITE
):
9077 case BUILT_IN_ISFINITE
:
9079 /* isfinite(x) -> islessequal(fabs(x),DBL_MAX). */
9080 tree
const isle_fn
= builtin_decl_explicit (BUILT_IN_ISLESSEQUAL
);
9081 tree type
= TREE_TYPE (arg
);
9085 if (is_ibm_extended
)
9087 /* NaN and Inf are encoded in the high-order double value
9088 only. The low-order value is not significant. */
9089 type
= double_type_node
;
9091 arg
= fold_build1_loc (loc
, NOP_EXPR
, type
, arg
);
9093 get_max_float (REAL_MODE_FORMAT (mode
), buf
, sizeof (buf
), false);
9094 real_from_string (&r
, buf
);
9095 result
= build_call_expr (isle_fn
, 2,
9096 fold_build1_loc (loc
, ABS_EXPR
, type
, arg
),
9097 build_real (type
, r
));
9098 /*result = fold_build2_loc (loc, UNGT_EXPR,
9099 TREE_TYPE (TREE_TYPE (fndecl)),
9100 fold_build1_loc (loc, ABS_EXPR, type, arg),
9101 build_real (type, r));
9102 result = fold_build1_loc (loc, TRUTH_NOT_EXPR,
9103 TREE_TYPE (TREE_TYPE (fndecl)),
9107 case BUILT_IN_ISNORMAL
:
9109 /* isnormal(x) -> isgreaterequal(fabs(x),DBL_MIN) &
9110 islessequal(fabs(x),DBL_MAX). */
9111 tree
const isle_fn
= builtin_decl_explicit (BUILT_IN_ISLESSEQUAL
);
9112 tree type
= TREE_TYPE (arg
);
9113 tree orig_arg
, max_exp
, min_exp
;
9114 machine_mode orig_mode
= mode
;
9115 REAL_VALUE_TYPE rmax
, rmin
;
9118 orig_arg
= arg
= builtin_save_expr (arg
);
9119 if (is_ibm_extended
)
9121 /* Use double to test the normal range of IBM extended
9122 precision. Emin for IBM extended precision is
9123 different to emin for IEEE double, being 53 higher
9124 since the low double exponent is at least 53 lower
9125 than the high double exponent. */
9126 type
= double_type_node
;
9128 arg
= fold_build1_loc (loc
, NOP_EXPR
, type
, arg
);
9130 arg
= fold_build1_loc (loc
, ABS_EXPR
, type
, arg
);
9132 get_max_float (REAL_MODE_FORMAT (mode
), buf
, sizeof (buf
), false);
9133 real_from_string (&rmax
, buf
);
9134 sprintf (buf
, "0x1p%d", REAL_MODE_FORMAT (orig_mode
)->emin
- 1);
9135 real_from_string (&rmin
, buf
);
9136 max_exp
= build_real (type
, rmax
);
9137 min_exp
= build_real (type
, rmin
);
9139 max_exp
= build_call_expr (isle_fn
, 2, arg
, max_exp
);
9140 if (is_ibm_extended
)
9142 /* Testing the high end of the range is done just using
9143 the high double, using the same test as isfinite().
9144 For the subnormal end of the range we first test the
9145 high double, then if its magnitude is equal to the
9146 limit of 0x1p-969, we test whether the low double is
9147 non-zero and opposite sign to the high double. */
9148 tree
const islt_fn
= builtin_decl_explicit (BUILT_IN_ISLESS
);
9149 tree
const isgt_fn
= builtin_decl_explicit (BUILT_IN_ISGREATER
);
9150 tree gt_min
= build_call_expr (isgt_fn
, 2, arg
, min_exp
);
9151 tree eq_min
= fold_build2 (EQ_EXPR
, integer_type_node
,
9153 tree as_complex
= build1 (VIEW_CONVERT_EXPR
,
9154 complex_double_type_node
, orig_arg
);
9155 tree hi_dbl
= build1 (REALPART_EXPR
, type
, as_complex
);
9156 tree lo_dbl
= build1 (IMAGPART_EXPR
, type
, as_complex
);
9157 tree zero
= build_real (type
, dconst0
);
9158 tree hilt
= build_call_expr (islt_fn
, 2, hi_dbl
, zero
);
9159 tree lolt
= build_call_expr (islt_fn
, 2, lo_dbl
, zero
);
9160 tree logt
= build_call_expr (isgt_fn
, 2, lo_dbl
, zero
);
9161 tree ok_lo
= fold_build1 (TRUTH_NOT_EXPR
, integer_type_node
,
9162 fold_build3 (COND_EXPR
,
9165 eq_min
= fold_build2 (TRUTH_ANDIF_EXPR
, integer_type_node
,
9167 min_exp
= fold_build2 (TRUTH_ORIF_EXPR
, integer_type_node
,
9173 = builtin_decl_explicit (BUILT_IN_ISGREATEREQUAL
);
9174 min_exp
= build_call_expr (isge_fn
, 2, arg
, min_exp
);
9176 result
= fold_build2 (BIT_AND_EXPR
, integer_type_node
,
9187 /* Fold a call to __builtin_isnan(), __builtin_isinf, __builtin_finite.
9188 ARG is the argument for the call. */
9191 fold_builtin_classify (location_t loc
, tree fndecl
, tree arg
, int builtin_index
)
9193 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
9195 if (!validate_arg (arg
, REAL_TYPE
))
9198 switch (builtin_index
)
9200 case BUILT_IN_ISINF
:
9201 if (tree_expr_infinite_p (arg
))
9202 return omit_one_operand_loc (loc
, type
, integer_one_node
, arg
);
9203 if (!tree_expr_maybe_infinite_p (arg
))
9204 return omit_one_operand_loc (loc
, type
, integer_zero_node
, arg
);
9207 case BUILT_IN_ISINF_SIGN
:
9209 /* isinf_sign(x) -> isinf(x) ? (signbit(x) ? -1 : 1) : 0 */
9210 /* In a boolean context, GCC will fold the inner COND_EXPR to
9211 1. So e.g. "if (isinf_sign(x))" would be folded to just
9212 "if (isinf(x) ? 1 : 0)" which becomes "if (isinf(x))". */
9213 tree signbit_fn
= builtin_decl_explicit (BUILT_IN_SIGNBIT
);
9214 tree isinf_fn
= builtin_decl_explicit (BUILT_IN_ISINF
);
9215 tree tmp
= NULL_TREE
;
9217 arg
= builtin_save_expr (arg
);
9219 if (signbit_fn
&& isinf_fn
)
9221 tree signbit_call
= build_call_expr_loc (loc
, signbit_fn
, 1, arg
);
9222 tree isinf_call
= build_call_expr_loc (loc
, isinf_fn
, 1, arg
);
9224 signbit_call
= fold_build2_loc (loc
, NE_EXPR
, integer_type_node
,
9225 signbit_call
, integer_zero_node
);
9226 isinf_call
= fold_build2_loc (loc
, NE_EXPR
, integer_type_node
,
9227 isinf_call
, integer_zero_node
);
9229 tmp
= fold_build3_loc (loc
, COND_EXPR
, integer_type_node
, signbit_call
,
9230 integer_minus_one_node
, integer_one_node
);
9231 tmp
= fold_build3_loc (loc
, COND_EXPR
, integer_type_node
,
9239 case BUILT_IN_ISFINITE
:
9240 if (tree_expr_finite_p (arg
))
9241 return omit_one_operand_loc (loc
, type
, integer_one_node
, arg
);
9242 if (tree_expr_nan_p (arg
) || tree_expr_infinite_p (arg
))
9243 return omit_one_operand_loc (loc
, type
, integer_zero_node
, arg
);
9246 case BUILT_IN_ISNAN
:
9247 if (tree_expr_nan_p (arg
))
9248 return omit_one_operand_loc (loc
, type
, integer_one_node
, arg
);
9249 if (!tree_expr_maybe_nan_p (arg
))
9250 return omit_one_operand_loc (loc
, type
, integer_zero_node
, arg
);
9253 bool is_ibm_extended
= MODE_COMPOSITE_P (TYPE_MODE (TREE_TYPE (arg
)));
9254 if (is_ibm_extended
)
9256 /* NaN and Inf are encoded in the high-order double value
9257 only. The low-order value is not significant. */
9258 arg
= fold_build1_loc (loc
, NOP_EXPR
, double_type_node
, arg
);
9261 arg
= builtin_save_expr (arg
);
9262 return fold_build2_loc (loc
, UNORDERED_EXPR
, type
, arg
, arg
);
9264 case BUILT_IN_ISSIGNALING
:
9265 /* Folding to true for REAL_CST is done in fold_const_call_ss.
9266 Don't use tree_expr_signaling_nan_p (arg) -> integer_one_node
9267 and !tree_expr_maybe_signaling_nan_p (arg) -> integer_zero_node
9268 here, so there is some possibility of __builtin_issignaling working
9269 without -fsignaling-nans. Especially when -fno-signaling-nans is
9271 if (!tree_expr_maybe_nan_p (arg
))
9272 return omit_one_operand_loc (loc
, type
, integer_zero_node
, arg
);
9280 /* Fold a call to __builtin_fpclassify(int, int, int, int, int, ...).
9281 This builtin will generate code to return the appropriate floating
9282 point classification depending on the value of the floating point
9283 number passed in. The possible return values must be supplied as
9284 int arguments to the call in the following order: FP_NAN, FP_INFINITE,
9285 FP_NORMAL, FP_SUBNORMAL and FP_ZERO. The ellipses is for exactly
9286 one floating point argument which is "type generic". */
9289 fold_builtin_fpclassify (location_t loc
, tree
*args
, int nargs
)
9291 tree fp_nan
, fp_infinite
, fp_normal
, fp_subnormal
, fp_zero
,
9292 arg
, type
, res
, tmp
;
9297 /* Verify the required arguments in the original call. */
9299 || !validate_arg (args
[0], INTEGER_TYPE
)
9300 || !validate_arg (args
[1], INTEGER_TYPE
)
9301 || !validate_arg (args
[2], INTEGER_TYPE
)
9302 || !validate_arg (args
[3], INTEGER_TYPE
)
9303 || !validate_arg (args
[4], INTEGER_TYPE
)
9304 || !validate_arg (args
[5], REAL_TYPE
))
9308 fp_infinite
= args
[1];
9309 fp_normal
= args
[2];
9310 fp_subnormal
= args
[3];
9313 type
= TREE_TYPE (arg
);
9314 mode
= TYPE_MODE (type
);
9315 arg
= builtin_save_expr (fold_build1_loc (loc
, ABS_EXPR
, type
, arg
));
9319 (fabs(x) == Inf ? FP_INFINITE :
9320 (fabs(x) >= DBL_MIN ? FP_NORMAL :
9321 (x == 0 ? FP_ZERO : FP_SUBNORMAL))). */
9323 tmp
= fold_build2_loc (loc
, EQ_EXPR
, integer_type_node
, arg
,
9324 build_real (type
, dconst0
));
9325 res
= fold_build3_loc (loc
, COND_EXPR
, integer_type_node
,
9326 tmp
, fp_zero
, fp_subnormal
);
9328 sprintf (buf
, "0x1p%d", REAL_MODE_FORMAT (mode
)->emin
- 1);
9329 real_from_string (&r
, buf
);
9330 tmp
= fold_build2_loc (loc
, GE_EXPR
, integer_type_node
,
9331 arg
, build_real (type
, r
));
9332 res
= fold_build3_loc (loc
, COND_EXPR
, integer_type_node
, tmp
, fp_normal
, res
);
9334 if (tree_expr_maybe_infinite_p (arg
))
9336 tmp
= fold_build2_loc (loc
, EQ_EXPR
, integer_type_node
, arg
,
9337 build_real (type
, dconstinf
));
9338 res
= fold_build3_loc (loc
, COND_EXPR
, integer_type_node
, tmp
,
9342 if (tree_expr_maybe_nan_p (arg
))
9344 tmp
= fold_build2_loc (loc
, ORDERED_EXPR
, integer_type_node
, arg
, arg
);
9345 res
= fold_build3_loc (loc
, COND_EXPR
, integer_type_node
, tmp
, res
, fp_nan
);
9351 /* Fold a call to an unordered comparison function such as
9352 __builtin_isgreater(). FNDECL is the FUNCTION_DECL for the function
9353 being called and ARG0 and ARG1 are the arguments for the call.
9354 UNORDERED_CODE and ORDERED_CODE are comparison codes that give
9355 the opposite of the desired result. UNORDERED_CODE is used
9356 for modes that can hold NaNs and ORDERED_CODE is used for
9360 fold_builtin_unordered_cmp (location_t loc
, tree fndecl
, tree arg0
, tree arg1
,
9361 enum tree_code unordered_code
,
9362 enum tree_code ordered_code
)
9364 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
9365 enum tree_code code
;
9367 enum tree_code code0
, code1
;
9368 tree cmp_type
= NULL_TREE
;
9370 type0
= TREE_TYPE (arg0
);
9371 type1
= TREE_TYPE (arg1
);
9373 code0
= TREE_CODE (type0
);
9374 code1
= TREE_CODE (type1
);
9376 if (code0
== REAL_TYPE
&& code1
== REAL_TYPE
)
9377 /* Choose the wider of two real types. */
9378 cmp_type
= TYPE_PRECISION (type0
) >= TYPE_PRECISION (type1
)
9380 else if (code0
== REAL_TYPE
&& code1
== INTEGER_TYPE
)
9382 else if (code0
== INTEGER_TYPE
&& code1
== REAL_TYPE
)
9385 arg0
= fold_convert_loc (loc
, cmp_type
, arg0
);
9386 arg1
= fold_convert_loc (loc
, cmp_type
, arg1
);
9388 if (unordered_code
== UNORDERED_EXPR
)
9390 if (tree_expr_nan_p (arg0
) || tree_expr_nan_p (arg1
))
9391 return omit_two_operands_loc (loc
, type
, integer_one_node
, arg0
, arg1
);
9392 if (!tree_expr_maybe_nan_p (arg0
) && !tree_expr_maybe_nan_p (arg1
))
9393 return omit_two_operands_loc (loc
, type
, integer_zero_node
, arg0
, arg1
);
9394 return fold_build2_loc (loc
, UNORDERED_EXPR
, type
, arg0
, arg1
);
9397 code
= (tree_expr_maybe_nan_p (arg0
) || tree_expr_maybe_nan_p (arg1
))
9398 ? unordered_code
: ordered_code
;
9399 return fold_build1_loc (loc
, TRUTH_NOT_EXPR
, type
,
9400 fold_build2_loc (loc
, code
, type
, arg0
, arg1
));
9403 /* Fold __builtin_{,s,u}{add,sub,mul}{,l,ll}_overflow, either into normal
9404 arithmetics if it can never overflow, or into internal functions that
9405 return both result of arithmetics and overflowed boolean flag in
9406 a complex integer result, or some other check for overflow.
9407 Similarly fold __builtin_{add,sub,mul}_overflow_p to just the overflow
9408 checking part of that. */
9411 fold_builtin_arith_overflow (location_t loc
, enum built_in_function fcode
,
9412 tree arg0
, tree arg1
, tree arg2
)
9414 enum internal_fn ifn
= IFN_LAST
;
9415 /* The code of the expression corresponding to the built-in. */
9416 enum tree_code opcode
= ERROR_MARK
;
9417 bool ovf_only
= false;
9421 case BUILT_IN_ADD_OVERFLOW_P
:
9424 case BUILT_IN_ADD_OVERFLOW
:
9425 case BUILT_IN_SADD_OVERFLOW
:
9426 case BUILT_IN_SADDL_OVERFLOW
:
9427 case BUILT_IN_SADDLL_OVERFLOW
:
9428 case BUILT_IN_UADD_OVERFLOW
:
9429 case BUILT_IN_UADDL_OVERFLOW
:
9430 case BUILT_IN_UADDLL_OVERFLOW
:
9432 ifn
= IFN_ADD_OVERFLOW
;
9434 case BUILT_IN_SUB_OVERFLOW_P
:
9437 case BUILT_IN_SUB_OVERFLOW
:
9438 case BUILT_IN_SSUB_OVERFLOW
:
9439 case BUILT_IN_SSUBL_OVERFLOW
:
9440 case BUILT_IN_SSUBLL_OVERFLOW
:
9441 case BUILT_IN_USUB_OVERFLOW
:
9442 case BUILT_IN_USUBL_OVERFLOW
:
9443 case BUILT_IN_USUBLL_OVERFLOW
:
9444 opcode
= MINUS_EXPR
;
9445 ifn
= IFN_SUB_OVERFLOW
;
9447 case BUILT_IN_MUL_OVERFLOW_P
:
9450 case BUILT_IN_MUL_OVERFLOW
:
9451 case BUILT_IN_SMUL_OVERFLOW
:
9452 case BUILT_IN_SMULL_OVERFLOW
:
9453 case BUILT_IN_SMULLL_OVERFLOW
:
9454 case BUILT_IN_UMUL_OVERFLOW
:
9455 case BUILT_IN_UMULL_OVERFLOW
:
9456 case BUILT_IN_UMULLL_OVERFLOW
:
9458 ifn
= IFN_MUL_OVERFLOW
;
9464 /* For the "generic" overloads, the first two arguments can have different
9465 types and the last argument determines the target type to use to check
9466 for overflow. The arguments of the other overloads all have the same
9468 tree type
= ovf_only
? TREE_TYPE (arg2
) : TREE_TYPE (TREE_TYPE (arg2
));
9470 /* For the __builtin_{add,sub,mul}_overflow_p builtins, when the first two
9471 arguments are constant, attempt to fold the built-in call into a constant
9472 expression indicating whether or not it detected an overflow. */
9474 && TREE_CODE (arg0
) == INTEGER_CST
9475 && TREE_CODE (arg1
) == INTEGER_CST
)
9476 /* Perform the computation in the target type and check for overflow. */
9477 return omit_one_operand_loc (loc
, boolean_type_node
,
9478 arith_overflowed_p (opcode
, type
, arg0
, arg1
)
9479 ? boolean_true_node
: boolean_false_node
,
9482 tree intres
, ovfres
;
9483 if (TREE_CODE (arg0
) == INTEGER_CST
&& TREE_CODE (arg1
) == INTEGER_CST
)
9485 intres
= fold_binary_loc (loc
, opcode
, type
,
9486 fold_convert_loc (loc
, type
, arg0
),
9487 fold_convert_loc (loc
, type
, arg1
));
9488 if (TREE_OVERFLOW (intres
))
9489 intres
= drop_tree_overflow (intres
);
9490 ovfres
= (arith_overflowed_p (opcode
, type
, arg0
, arg1
)
9491 ? boolean_true_node
: boolean_false_node
);
9495 tree ctype
= build_complex_type (type
);
9496 tree call
= build_call_expr_internal_loc (loc
, ifn
, ctype
, 2,
9498 tree tgt
= save_expr (call
);
9499 intres
= build1_loc (loc
, REALPART_EXPR
, type
, tgt
);
9500 ovfres
= build1_loc (loc
, IMAGPART_EXPR
, type
, tgt
);
9501 ovfres
= fold_convert_loc (loc
, boolean_type_node
, ovfres
);
9505 return omit_one_operand_loc (loc
, boolean_type_node
, ovfres
, arg2
);
9507 tree mem_arg2
= build_fold_indirect_ref_loc (loc
, arg2
);
9509 = fold_build2_loc (loc
, MODIFY_EXPR
, void_type_node
, mem_arg2
, intres
);
9510 return build2_loc (loc
, COMPOUND_EXPR
, boolean_type_node
, store
, ovfres
);
9513 /* Fold a call to __builtin_FILE to a constant string. */
9516 fold_builtin_FILE (location_t loc
)
9518 if (const char *fname
= LOCATION_FILE (loc
))
9520 /* The documentation says this builtin is equivalent to the preprocessor
9521 __FILE__ macro so it appears appropriate to use the same file prefix
9523 fname
= remap_macro_filename (fname
);
9524 return build_string_literal (strlen (fname
) + 1, fname
);
9527 return build_string_literal (1, "");
9530 /* Fold a call to __builtin_FUNCTION to a constant string. */
9533 fold_builtin_FUNCTION ()
9535 const char *name
= "";
9537 if (current_function_decl
)
9538 name
= lang_hooks
.decl_printable_name (current_function_decl
, 0);
9540 return build_string_literal (strlen (name
) + 1, name
);
9543 /* Fold a call to __builtin_LINE to an integer constant. */
9546 fold_builtin_LINE (location_t loc
, tree type
)
9548 return build_int_cst (type
, LOCATION_LINE (loc
));
9551 /* Fold a call to built-in function FNDECL with 0 arguments.
9552 This function returns NULL_TREE if no simplification was possible. */
9555 fold_builtin_0 (location_t loc
, tree fndecl
)
9557 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
9558 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9562 return fold_builtin_FILE (loc
);
9564 case BUILT_IN_FUNCTION
:
9565 return fold_builtin_FUNCTION ();
9568 return fold_builtin_LINE (loc
, type
);
9570 CASE_FLT_FN (BUILT_IN_INF
):
9571 CASE_FLT_FN_FLOATN_NX (BUILT_IN_INF
):
9572 case BUILT_IN_INFD32
:
9573 case BUILT_IN_INFD64
:
9574 case BUILT_IN_INFD128
:
9575 return fold_builtin_inf (loc
, type
, true);
9577 CASE_FLT_FN (BUILT_IN_HUGE_VAL
):
9578 CASE_FLT_FN_FLOATN_NX (BUILT_IN_HUGE_VAL
):
9579 return fold_builtin_inf (loc
, type
, false);
9581 case BUILT_IN_CLASSIFY_TYPE
:
9582 return fold_builtin_classify_type (NULL_TREE
);
9584 case BUILT_IN_UNREACHABLE
:
9585 /* Rewrite any explicit calls to __builtin_unreachable. */
9586 if (sanitize_flags_p (SANITIZE_UNREACHABLE
))
9587 return build_builtin_unreachable (loc
);
9596 /* Fold a call to built-in function FNDECL with 1 argument, ARG0.
9597 This function returns NULL_TREE if no simplification was possible. */
9600 fold_builtin_1 (location_t loc
, tree expr
, tree fndecl
, tree arg0
)
9602 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
9603 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9605 if (TREE_CODE (arg0
) == ERROR_MARK
)
9608 if (tree ret
= fold_const_call (as_combined_fn (fcode
), type
, arg0
))
9613 case BUILT_IN_CONSTANT_P
:
9615 tree val
= fold_builtin_constant_p (arg0
);
9617 /* Gimplification will pull the CALL_EXPR for the builtin out of
9618 an if condition. When not optimizing, we'll not CSE it back.
9619 To avoid link error types of regressions, return false now. */
9620 if (!val
&& !optimize
)
9621 val
= integer_zero_node
;
9626 case BUILT_IN_CLASSIFY_TYPE
:
9627 return fold_builtin_classify_type (arg0
);
9629 case BUILT_IN_STRLEN
:
9630 return fold_builtin_strlen (loc
, expr
, type
, arg0
);
9632 CASE_FLT_FN (BUILT_IN_FABS
):
9633 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
9634 case BUILT_IN_FABSD32
:
9635 case BUILT_IN_FABSD64
:
9636 case BUILT_IN_FABSD128
:
9637 return fold_builtin_fabs (loc
, arg0
, type
);
9641 case BUILT_IN_LLABS
:
9642 case BUILT_IN_IMAXABS
:
9643 return fold_builtin_abs (loc
, arg0
, type
);
9645 CASE_FLT_FN (BUILT_IN_CONJ
):
9646 if (validate_arg (arg0
, COMPLEX_TYPE
)
9647 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
))) == REAL_TYPE
)
9648 return fold_build1_loc (loc
, CONJ_EXPR
, type
, arg0
);
9651 CASE_FLT_FN (BUILT_IN_CREAL
):
9652 if (validate_arg (arg0
, COMPLEX_TYPE
)
9653 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
))) == REAL_TYPE
)
9654 return non_lvalue_loc (loc
, fold_build1_loc (loc
, REALPART_EXPR
, type
, arg0
));
9657 CASE_FLT_FN (BUILT_IN_CIMAG
):
9658 if (validate_arg (arg0
, COMPLEX_TYPE
)
9659 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
))) == REAL_TYPE
)
9660 return non_lvalue_loc (loc
, fold_build1_loc (loc
, IMAGPART_EXPR
, type
, arg0
));
9663 CASE_FLT_FN (BUILT_IN_CARG
):
9664 return fold_builtin_carg (loc
, arg0
, type
);
9666 case BUILT_IN_ISASCII
:
9667 return fold_builtin_isascii (loc
, arg0
);
9669 case BUILT_IN_TOASCII
:
9670 return fold_builtin_toascii (loc
, arg0
);
9672 case BUILT_IN_ISDIGIT
:
9673 return fold_builtin_isdigit (loc
, arg0
);
9675 CASE_FLT_FN (BUILT_IN_FINITE
):
9676 case BUILT_IN_FINITED32
:
9677 case BUILT_IN_FINITED64
:
9678 case BUILT_IN_FINITED128
:
9679 case BUILT_IN_ISFINITE
:
9681 tree ret
= fold_builtin_classify (loc
, fndecl
, arg0
, BUILT_IN_ISFINITE
);
9684 return fold_builtin_interclass_mathfn (loc
, fndecl
, arg0
);
9687 CASE_FLT_FN (BUILT_IN_ISINF
):
9688 case BUILT_IN_ISINFD32
:
9689 case BUILT_IN_ISINFD64
:
9690 case BUILT_IN_ISINFD128
:
9692 tree ret
= fold_builtin_classify (loc
, fndecl
, arg0
, BUILT_IN_ISINF
);
9695 return fold_builtin_interclass_mathfn (loc
, fndecl
, arg0
);
9698 case BUILT_IN_ISNORMAL
:
9699 return fold_builtin_interclass_mathfn (loc
, fndecl
, arg0
);
9701 case BUILT_IN_ISINF_SIGN
:
9702 return fold_builtin_classify (loc
, fndecl
, arg0
, BUILT_IN_ISINF_SIGN
);
9704 CASE_FLT_FN (BUILT_IN_ISNAN
):
9705 case BUILT_IN_ISNAND32
:
9706 case BUILT_IN_ISNAND64
:
9707 case BUILT_IN_ISNAND128
:
9708 return fold_builtin_classify (loc
, fndecl
, arg0
, BUILT_IN_ISNAN
);
9710 case BUILT_IN_ISSIGNALING
:
9711 return fold_builtin_classify (loc
, fndecl
, arg0
, BUILT_IN_ISSIGNALING
);
9714 if (integer_zerop (arg0
))
9715 return build_empty_stmt (loc
);
9726 /* Folds a call EXPR (which may be null) to built-in function FNDECL
9727 with 2 arguments, ARG0 and ARG1. This function returns NULL_TREE
9728 if no simplification was possible. */
9731 fold_builtin_2 (location_t loc
, tree expr
, tree fndecl
, tree arg0
, tree arg1
)
9733 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
9734 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9736 if (TREE_CODE (arg0
) == ERROR_MARK
9737 || TREE_CODE (arg1
) == ERROR_MARK
)
9740 if (tree ret
= fold_const_call (as_combined_fn (fcode
), type
, arg0
, arg1
))
9745 CASE_FLT_FN_REENT (BUILT_IN_GAMMA
): /* GAMMA_R */
9746 CASE_FLT_FN_REENT (BUILT_IN_LGAMMA
): /* LGAMMA_R */
9747 if (validate_arg (arg0
, REAL_TYPE
)
9748 && validate_arg (arg1
, POINTER_TYPE
))
9749 return do_mpfr_lgamma_r (arg0
, arg1
, type
);
9752 CASE_FLT_FN (BUILT_IN_FREXP
):
9753 return fold_builtin_frexp (loc
, arg0
, arg1
, type
);
9755 CASE_FLT_FN (BUILT_IN_MODF
):
9756 return fold_builtin_modf (loc
, arg0
, arg1
, type
);
9758 case BUILT_IN_STRSPN
:
9759 return fold_builtin_strspn (loc
, expr
, arg0
, arg1
);
9761 case BUILT_IN_STRCSPN
:
9762 return fold_builtin_strcspn (loc
, expr
, arg0
, arg1
);
9764 case BUILT_IN_STRPBRK
:
9765 return fold_builtin_strpbrk (loc
, expr
, arg0
, arg1
, type
);
9767 case BUILT_IN_EXPECT
:
9768 return fold_builtin_expect (loc
, arg0
, arg1
, NULL_TREE
, NULL_TREE
);
9770 case BUILT_IN_ISGREATER
:
9771 return fold_builtin_unordered_cmp (loc
, fndecl
,
9772 arg0
, arg1
, UNLE_EXPR
, LE_EXPR
);
9773 case BUILT_IN_ISGREATEREQUAL
:
9774 return fold_builtin_unordered_cmp (loc
, fndecl
,
9775 arg0
, arg1
, UNLT_EXPR
, LT_EXPR
);
9776 case BUILT_IN_ISLESS
:
9777 return fold_builtin_unordered_cmp (loc
, fndecl
,
9778 arg0
, arg1
, UNGE_EXPR
, GE_EXPR
);
9779 case BUILT_IN_ISLESSEQUAL
:
9780 return fold_builtin_unordered_cmp (loc
, fndecl
,
9781 arg0
, arg1
, UNGT_EXPR
, GT_EXPR
);
9782 case BUILT_IN_ISLESSGREATER
:
9783 return fold_builtin_unordered_cmp (loc
, fndecl
,
9784 arg0
, arg1
, UNEQ_EXPR
, EQ_EXPR
);
9785 case BUILT_IN_ISUNORDERED
:
9786 return fold_builtin_unordered_cmp (loc
, fndecl
,
9787 arg0
, arg1
, UNORDERED_EXPR
,
9790 /* We do the folding for va_start in the expander. */
9791 case BUILT_IN_VA_START
:
9794 case BUILT_IN_OBJECT_SIZE
:
9795 case BUILT_IN_DYNAMIC_OBJECT_SIZE
:
9796 return fold_builtin_object_size (arg0
, arg1
, fcode
);
9798 case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE
:
9799 return fold_builtin_atomic_always_lock_free (arg0
, arg1
);
9801 case BUILT_IN_ATOMIC_IS_LOCK_FREE
:
9802 return fold_builtin_atomic_is_lock_free (arg0
, arg1
);
9810 /* Fold a call to built-in function FNDECL with 3 arguments, ARG0, ARG1,
9812 This function returns NULL_TREE if no simplification was possible. */
9815 fold_builtin_3 (location_t loc
, tree fndecl
,
9816 tree arg0
, tree arg1
, tree arg2
)
9818 tree type
= TREE_TYPE (TREE_TYPE (fndecl
));
9819 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9821 if (TREE_CODE (arg0
) == ERROR_MARK
9822 || TREE_CODE (arg1
) == ERROR_MARK
9823 || TREE_CODE (arg2
) == ERROR_MARK
)
9826 if (tree ret
= fold_const_call (as_combined_fn (fcode
), type
,
9833 CASE_FLT_FN (BUILT_IN_SINCOS
):
9834 return fold_builtin_sincos (loc
, arg0
, arg1
, arg2
);
9836 CASE_FLT_FN (BUILT_IN_REMQUO
):
9837 if (validate_arg (arg0
, REAL_TYPE
)
9838 && validate_arg (arg1
, REAL_TYPE
)
9839 && validate_arg (arg2
, POINTER_TYPE
))
9840 return do_mpfr_remquo (arg0
, arg1
, arg2
);
9843 case BUILT_IN_MEMCMP
:
9844 return fold_builtin_memcmp (loc
, arg0
, arg1
, arg2
);
9846 case BUILT_IN_EXPECT
:
9847 return fold_builtin_expect (loc
, arg0
, arg1
, arg2
, NULL_TREE
);
9849 case BUILT_IN_EXPECT_WITH_PROBABILITY
:
9850 return fold_builtin_expect (loc
, arg0
, arg1
, NULL_TREE
, arg2
);
9852 case BUILT_IN_ADD_OVERFLOW
:
9853 case BUILT_IN_SUB_OVERFLOW
:
9854 case BUILT_IN_MUL_OVERFLOW
:
9855 case BUILT_IN_ADD_OVERFLOW_P
:
9856 case BUILT_IN_SUB_OVERFLOW_P
:
9857 case BUILT_IN_MUL_OVERFLOW_P
:
9858 case BUILT_IN_SADD_OVERFLOW
:
9859 case BUILT_IN_SADDL_OVERFLOW
:
9860 case BUILT_IN_SADDLL_OVERFLOW
:
9861 case BUILT_IN_SSUB_OVERFLOW
:
9862 case BUILT_IN_SSUBL_OVERFLOW
:
9863 case BUILT_IN_SSUBLL_OVERFLOW
:
9864 case BUILT_IN_SMUL_OVERFLOW
:
9865 case BUILT_IN_SMULL_OVERFLOW
:
9866 case BUILT_IN_SMULLL_OVERFLOW
:
9867 case BUILT_IN_UADD_OVERFLOW
:
9868 case BUILT_IN_UADDL_OVERFLOW
:
9869 case BUILT_IN_UADDLL_OVERFLOW
:
9870 case BUILT_IN_USUB_OVERFLOW
:
9871 case BUILT_IN_USUBL_OVERFLOW
:
9872 case BUILT_IN_USUBLL_OVERFLOW
:
9873 case BUILT_IN_UMUL_OVERFLOW
:
9874 case BUILT_IN_UMULL_OVERFLOW
:
9875 case BUILT_IN_UMULLL_OVERFLOW
:
9876 return fold_builtin_arith_overflow (loc
, fcode
, arg0
, arg1
, arg2
);
9884 /* Folds a call EXPR (which may be null) to built-in function FNDECL.
9885 ARGS is an array of NARGS arguments. IGNORE is true if the result
9886 of the function call is ignored. This function returns NULL_TREE
9887 if no simplification was possible. */
9890 fold_builtin_n (location_t loc
, tree expr
, tree fndecl
, tree
*args
,
9893 tree ret
= NULL_TREE
;
9898 ret
= fold_builtin_0 (loc
, fndecl
);
9901 ret
= fold_builtin_1 (loc
, expr
, fndecl
, args
[0]);
9904 ret
= fold_builtin_2 (loc
, expr
, fndecl
, args
[0], args
[1]);
9907 ret
= fold_builtin_3 (loc
, fndecl
, args
[0], args
[1], args
[2]);
9910 ret
= fold_builtin_varargs (loc
, fndecl
, args
, nargs
);
9915 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
9916 SET_EXPR_LOCATION (ret
, loc
);
9922 /* Construct a new CALL_EXPR to FNDECL using the tail of the argument
9923 list ARGS along with N new arguments in NEWARGS. SKIP is the number
9924 of arguments in ARGS to be omitted. OLDNARGS is the number of
9925 elements in ARGS. */
9928 rewrite_call_expr_valist (location_t loc
, int oldnargs
, tree
*args
,
9929 int skip
, tree fndecl
, int n
, va_list newargs
)
9931 int nargs
= oldnargs
- skip
+ n
;
9938 buffer
= XALLOCAVEC (tree
, nargs
);
9939 for (i
= 0; i
< n
; i
++)
9940 buffer
[i
] = va_arg (newargs
, tree
);
9941 for (j
= skip
; j
< oldnargs
; j
++, i
++)
9942 buffer
[i
] = args
[j
];
9945 buffer
= args
+ skip
;
9947 return build_call_expr_loc_array (loc
, fndecl
, nargs
, buffer
);
9950 /* Return true if FNDECL shouldn't be folded right now.
9951 If a built-in function has an inline attribute always_inline
9952 wrapper, defer folding it after always_inline functions have
9953 been inlined, otherwise e.g. -D_FORTIFY_SOURCE checking
9954 might not be performed. */
9957 avoid_folding_inline_builtin (tree fndecl
)
9959 return (DECL_DECLARED_INLINE_P (fndecl
)
9960 && DECL_DISREGARD_INLINE_LIMITS (fndecl
)
9962 && !cfun
->always_inline_functions_inlined
9963 && lookup_attribute ("always_inline", DECL_ATTRIBUTES (fndecl
)));
9966 /* A wrapper function for builtin folding that prevents warnings for
9967 "statement without effect" and the like, caused by removing the
9968 call node earlier than the warning is generated. */
9971 fold_call_expr (location_t loc
, tree exp
, bool ignore
)
9973 tree ret
= NULL_TREE
;
9974 tree fndecl
= get_callee_fndecl (exp
);
9975 if (fndecl
&& fndecl_built_in_p (fndecl
)
9976 /* If CALL_EXPR_VA_ARG_PACK is set, the arguments aren't finalized
9977 yet. Defer folding until we see all the arguments
9978 (after inlining). */
9979 && !CALL_EXPR_VA_ARG_PACK (exp
))
9981 int nargs
= call_expr_nargs (exp
);
9983 /* Before gimplification CALL_EXPR_VA_ARG_PACK is not set, but
9984 instead last argument is __builtin_va_arg_pack (). Defer folding
9985 even in that case, until arguments are finalized. */
9986 if (nargs
&& TREE_CODE (CALL_EXPR_ARG (exp
, nargs
- 1)) == CALL_EXPR
)
9988 tree fndecl2
= get_callee_fndecl (CALL_EXPR_ARG (exp
, nargs
- 1));
9989 if (fndecl2
&& fndecl_built_in_p (fndecl2
, BUILT_IN_VA_ARG_PACK
))
9993 if (avoid_folding_inline_builtin (fndecl
))
9996 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_MD
)
9997 return targetm
.fold_builtin (fndecl
, call_expr_nargs (exp
),
9998 CALL_EXPR_ARGP (exp
), ignore
);
10001 tree
*args
= CALL_EXPR_ARGP (exp
);
10002 ret
= fold_builtin_n (loc
, exp
, fndecl
, args
, nargs
, ignore
);
10010 /* Fold a CALL_EXPR with type TYPE with FN as the function expression.
10011 N arguments are passed in the array ARGARRAY. Return a folded
10012 expression or NULL_TREE if no simplification was possible. */
10015 fold_builtin_call_array (location_t loc
, tree
,
10020 if (TREE_CODE (fn
) != ADDR_EXPR
)
10023 tree fndecl
= TREE_OPERAND (fn
, 0);
10024 if (TREE_CODE (fndecl
) == FUNCTION_DECL
10025 && fndecl_built_in_p (fndecl
))
10027 /* If last argument is __builtin_va_arg_pack (), arguments to this
10028 function are not finalized yet. Defer folding until they are. */
10029 if (n
&& TREE_CODE (argarray
[n
- 1]) == CALL_EXPR
)
10031 tree fndecl2
= get_callee_fndecl (argarray
[n
- 1]);
10032 if (fndecl2
&& fndecl_built_in_p (fndecl2
, BUILT_IN_VA_ARG_PACK
))
10035 if (avoid_folding_inline_builtin (fndecl
))
10037 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_MD
)
10038 return targetm
.fold_builtin (fndecl
, n
, argarray
, false);
10040 return fold_builtin_n (loc
, NULL_TREE
, fndecl
, argarray
, n
, false);
10046 /* Construct a new CALL_EXPR using the tail of the argument list of EXP
10047 along with N new arguments specified as the "..." parameters. SKIP
10048 is the number of arguments in EXP to be omitted. This function is used
10049 to do varargs-to-varargs transformations. */
10052 rewrite_call_expr (location_t loc
, tree exp
, int skip
, tree fndecl
, int n
, ...)
10058 t
= rewrite_call_expr_valist (loc
, call_expr_nargs (exp
),
10059 CALL_EXPR_ARGP (exp
), skip
, fndecl
, n
, ap
);
10065 /* Validate a single argument ARG against a tree code CODE representing
10066 a type. Return true when argument is valid. */
10069 validate_arg (const_tree arg
, enum tree_code code
)
10073 else if (code
== POINTER_TYPE
)
10074 return POINTER_TYPE_P (TREE_TYPE (arg
));
10075 else if (code
== INTEGER_TYPE
)
10076 return INTEGRAL_TYPE_P (TREE_TYPE (arg
));
10077 return code
== TREE_CODE (TREE_TYPE (arg
));
10080 /* This function validates the types of a function call argument list
10081 against a specified list of tree_codes. If the last specifier is a 0,
10082 that represents an ellipses, otherwise the last specifier must be a
10085 This is the GIMPLE version of validate_arglist. Eventually we want to
10086 completely convert builtins.cc to work from GIMPLEs and the tree based
10087 validate_arglist will then be removed. */
10090 validate_gimple_arglist (const gcall
*call
, ...)
10092 enum tree_code code
;
10098 va_start (ap
, call
);
10103 code
= (enum tree_code
) va_arg (ap
, int);
10107 /* This signifies an ellipses, any further arguments are all ok. */
10111 /* This signifies an endlink, if no arguments remain, return
10112 true, otherwise return false. */
10113 res
= (i
== gimple_call_num_args (call
));
10116 /* If no parameters remain or the parameter's code does not
10117 match the specified code, return false. Otherwise continue
10118 checking any remaining arguments. */
10119 arg
= gimple_call_arg (call
, i
++);
10120 if (!validate_arg (arg
, code
))
10127 /* We need gotos here since we can only have one VA_CLOSE in a
10135 /* Default target-specific builtin expander that does nothing. */
10138 default_expand_builtin (tree exp ATTRIBUTE_UNUSED
,
10139 rtx target ATTRIBUTE_UNUSED
,
10140 rtx subtarget ATTRIBUTE_UNUSED
,
10141 machine_mode mode ATTRIBUTE_UNUSED
,
10142 int ignore ATTRIBUTE_UNUSED
)
10147 /* Returns true is EXP represents data that would potentially reside
10148 in a readonly section. */
10151 readonly_data_expr (tree exp
)
10155 if (TREE_CODE (exp
) != ADDR_EXPR
)
10158 exp
= get_base_address (TREE_OPERAND (exp
, 0));
10162 /* Make sure we call decl_readonly_section only for trees it
10163 can handle (since it returns true for everything it doesn't
10165 if (TREE_CODE (exp
) == STRING_CST
10166 || TREE_CODE (exp
) == CONSTRUCTOR
10167 || (VAR_P (exp
) && TREE_STATIC (exp
)))
10168 return decl_readonly_section (exp
, 0);
10173 /* Simplify a call to the strpbrk builtin. S1 and S2 are the arguments
10174 to the call, and TYPE is its return type.
10176 Return NULL_TREE if no simplification was possible, otherwise return the
10177 simplified form of the call as a tree.
10179 The simplified form may be a constant or other expression which
10180 computes the same value, but in a more efficient manner (including
10181 calls to other builtin functions).
10183 The call may contain arguments which need to be evaluated, but
10184 which are not useful to determine the result of the call. In
10185 this case we return a chain of COMPOUND_EXPRs. The LHS of each
10186 COMPOUND_EXPR will be an argument which must be evaluated.
10187 COMPOUND_EXPRs are chained through their RHS. The RHS of the last
10188 COMPOUND_EXPR in the chain will contain the tree for the simplified
10189 form of the builtin function call. */
10192 fold_builtin_strpbrk (location_t loc
, tree
, tree s1
, tree s2
, tree type
)
10194 if (!validate_arg (s1
, POINTER_TYPE
)
10195 || !validate_arg (s2
, POINTER_TYPE
))
10199 const char *p1
, *p2
;
10201 p2
= c_getstr (s2
);
10205 p1
= c_getstr (s1
);
10208 const char *r
= strpbrk (p1
, p2
);
10212 return build_int_cst (TREE_TYPE (s1
), 0);
10214 /* Return an offset into the constant string argument. */
10215 tem
= fold_build_pointer_plus_hwi_loc (loc
, s1
, r
- p1
);
10216 return fold_convert_loc (loc
, type
, tem
);
10220 /* strpbrk(x, "") == NULL.
10221 Evaluate and ignore s1 in case it had side-effects. */
10222 return omit_one_operand_loc (loc
, type
, integer_zero_node
, s1
);
10225 return NULL_TREE
; /* Really call strpbrk. */
10227 fn
= builtin_decl_implicit (BUILT_IN_STRCHR
);
10231 /* New argument list transforming strpbrk(s1, s2) to
10232 strchr(s1, s2[0]). */
10233 return build_call_expr_loc (loc
, fn
, 2, s1
,
10234 build_int_cst (integer_type_node
, p2
[0]));
10237 /* Simplify a call to the strspn builtin. S1 and S2 are the arguments
10240 Return NULL_TREE if no simplification was possible, otherwise return the
10241 simplified form of the call as a tree.
10243 The simplified form may be a constant or other expression which
10244 computes the same value, but in a more efficient manner (including
10245 calls to other builtin functions).
10247 The call may contain arguments which need to be evaluated, but
10248 which are not useful to determine the result of the call. In
10249 this case we return a chain of COMPOUND_EXPRs. The LHS of each
10250 COMPOUND_EXPR will be an argument which must be evaluated.
10251 COMPOUND_EXPRs are chained through their RHS. The RHS of the last
10252 COMPOUND_EXPR in the chain will contain the tree for the simplified
10253 form of the builtin function call. */
10256 fold_builtin_strspn (location_t loc
, tree expr
, tree s1
, tree s2
)
10258 if (!validate_arg (s1
, POINTER_TYPE
)
10259 || !validate_arg (s2
, POINTER_TYPE
))
10262 if (!check_nul_terminated_array (expr
, s1
)
10263 || !check_nul_terminated_array (expr
, s2
))
10266 const char *p1
= c_getstr (s1
), *p2
= c_getstr (s2
);
10268 /* If either argument is "", return NULL_TREE. */
10269 if ((p1
&& *p1
== '\0') || (p2
&& *p2
== '\0'))
10270 /* Evaluate and ignore both arguments in case either one has
10272 return omit_two_operands_loc (loc
, size_type_node
, size_zero_node
,
10277 /* Simplify a call to the strcspn builtin. S1 and S2 are the arguments
10280 Return NULL_TREE if no simplification was possible, otherwise return the
10281 simplified form of the call as a tree.
10283 The simplified form may be a constant or other expression which
10284 computes the same value, but in a more efficient manner (including
10285 calls to other builtin functions).
10287 The call may contain arguments which need to be evaluated, but
10288 which are not useful to determine the result of the call. In
10289 this case we return a chain of COMPOUND_EXPRs. The LHS of each
10290 COMPOUND_EXPR will be an argument which must be evaluated.
10291 COMPOUND_EXPRs are chained through their RHS. The RHS of the last
10292 COMPOUND_EXPR in the chain will contain the tree for the simplified
10293 form of the builtin function call. */
10296 fold_builtin_strcspn (location_t loc
, tree expr
, tree s1
, tree s2
)
10298 if (!validate_arg (s1
, POINTER_TYPE
)
10299 || !validate_arg (s2
, POINTER_TYPE
))
10302 if (!check_nul_terminated_array (expr
, s1
)
10303 || !check_nul_terminated_array (expr
, s2
))
10306 /* If the first argument is "", return NULL_TREE. */
10307 const char *p1
= c_getstr (s1
);
10308 if (p1
&& *p1
== '\0')
10310 /* Evaluate and ignore argument s2 in case it has
10312 return omit_one_operand_loc (loc
, size_type_node
,
10313 size_zero_node
, s2
);
10316 /* If the second argument is "", return __builtin_strlen(s1). */
10317 const char *p2
= c_getstr (s2
);
10318 if (p2
&& *p2
== '\0')
10320 tree fn
= builtin_decl_implicit (BUILT_IN_STRLEN
);
10322 /* If the replacement _DECL isn't initialized, don't do the
10327 return build_call_expr_loc (loc
, fn
, 1, s1
);
10332 /* Fold the next_arg or va_start call EXP. Returns true if there was an error
10333 produced. False otherwise. This is done so that we don't output the error
10334 or warning twice or three times. */
10337 fold_builtin_next_arg (tree exp
, bool va_start_p
)
10339 tree fntype
= TREE_TYPE (current_function_decl
);
10340 int nargs
= call_expr_nargs (exp
);
10342 /* There is good chance the current input_location points inside the
10343 definition of the va_start macro (perhaps on the token for
10344 builtin) in a system header, so warnings will not be emitted.
10345 Use the location in real source code. */
10346 location_t current_location
=
10347 linemap_unwind_to_first_non_reserved_loc (line_table
, input_location
,
10350 if (!stdarg_p (fntype
))
10352 error ("%<va_start%> used in function with fixed arguments");
10358 if (va_start_p
&& (nargs
!= 2))
10360 error ("wrong number of arguments to function %<va_start%>");
10363 arg
= CALL_EXPR_ARG (exp
, 1);
10365 /* We use __builtin_va_start (ap, 0, 0) or __builtin_next_arg (0, 0)
10366 when we checked the arguments and if needed issued a warning. */
10371 /* Evidently an out of date version of <stdarg.h>; can't validate
10372 va_start's second argument, but can still work as intended. */
10373 warning_at (current_location
,
10375 "%<__builtin_next_arg%> called without an argument");
10378 else if (nargs
> 1)
10380 error ("wrong number of arguments to function %<__builtin_next_arg%>");
10383 arg
= CALL_EXPR_ARG (exp
, 0);
10386 if (TREE_CODE (arg
) == SSA_NAME
10387 && SSA_NAME_VAR (arg
))
10388 arg
= SSA_NAME_VAR (arg
);
10390 /* We destructively modify the call to be __builtin_va_start (ap, 0)
10391 or __builtin_next_arg (0) the first time we see it, after checking
10392 the arguments and if needed issuing a warning. */
10393 if (!integer_zerop (arg
))
10395 tree last_parm
= tree_last (DECL_ARGUMENTS (current_function_decl
));
10397 /* Strip off all nops for the sake of the comparison. This
10398 is not quite the same as STRIP_NOPS. It does more.
10399 We must also strip off INDIRECT_EXPR for C++ reference
10401 while (CONVERT_EXPR_P (arg
)
10402 || TREE_CODE (arg
) == INDIRECT_REF
)
10403 arg
= TREE_OPERAND (arg
, 0);
10404 if (arg
!= last_parm
)
10406 /* FIXME: Sometimes with the tree optimizers we can get the
10407 not the last argument even though the user used the last
10408 argument. We just warn and set the arg to be the last
10409 argument so that we will get wrong-code because of
10411 warning_at (current_location
,
10413 "second parameter of %<va_start%> not last named argument");
10416 /* Undefined by C99 7.15.1.4p4 (va_start):
10417 "If the parameter parmN is declared with the register storage
10418 class, with a function or array type, or with a type that is
10419 not compatible with the type that results after application of
10420 the default argument promotions, the behavior is undefined."
10422 else if (DECL_REGISTER (arg
))
10424 warning_at (current_location
,
10426 "undefined behavior when second parameter of "
10427 "%<va_start%> is declared with %<register%> storage");
10430 /* We want to verify the second parameter just once before the tree
10431 optimizers are run and then avoid keeping it in the tree,
10432 as otherwise we could warn even for correct code like:
10433 void foo (int i, ...)
10434 { va_list ap; i++; va_start (ap, i); va_end (ap); } */
10436 CALL_EXPR_ARG (exp
, 1) = integer_zero_node
;
10438 CALL_EXPR_ARG (exp
, 0) = integer_zero_node
;
10444 /* Expand a call EXP to __builtin_object_size. */
10447 expand_builtin_object_size (tree exp
)
10450 int object_size_type
;
10451 tree fndecl
= get_callee_fndecl (exp
);
10453 if (!validate_arglist (exp
, POINTER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
10455 error ("first argument of %qD must be a pointer, second integer constant",
10457 expand_builtin_trap ();
10461 ost
= CALL_EXPR_ARG (exp
, 1);
10464 if (TREE_CODE (ost
) != INTEGER_CST
10465 || tree_int_cst_sgn (ost
) < 0
10466 || compare_tree_int (ost
, 3) > 0)
10468 error ("last argument of %qD is not integer constant between 0 and 3",
10470 expand_builtin_trap ();
10474 object_size_type
= tree_to_shwi (ost
);
10476 return object_size_type
< 2 ? constm1_rtx
: const0_rtx
;
10479 /* Expand EXP, a call to the __mem{cpy,pcpy,move,set}_chk builtin.
10480 FCODE is the BUILT_IN_* to use.
10481 Return NULL_RTX if we failed; the caller should emit a normal call,
10482 otherwise try to get the result in TARGET, if convenient (and in
10483 mode MODE if that's convenient). */
10486 expand_builtin_memory_chk (tree exp
, rtx target
, machine_mode mode
,
10487 enum built_in_function fcode
)
10489 if (!validate_arglist (exp
,
10491 fcode
== BUILT_IN_MEMSET_CHK
10492 ? INTEGER_TYPE
: POINTER_TYPE
,
10493 INTEGER_TYPE
, INTEGER_TYPE
, VOID_TYPE
))
10496 tree dest
= CALL_EXPR_ARG (exp
, 0);
10497 tree src
= CALL_EXPR_ARG (exp
, 1);
10498 tree len
= CALL_EXPR_ARG (exp
, 2);
10499 tree size
= CALL_EXPR_ARG (exp
, 3);
10501 /* FIXME: Set access mode to write only for memset et al. */
10502 bool sizes_ok
= check_access (exp
, len
, /*maxread=*/NULL_TREE
,
10503 /*srcstr=*/NULL_TREE
, size
, access_read_write
);
10505 if (!tree_fits_uhwi_p (size
))
10508 if (tree_fits_uhwi_p (len
) || integer_all_onesp (size
))
10510 /* Avoid transforming the checking call to an ordinary one when
10511 an overflow has been detected or when the call couldn't be
10512 validated because the size is not constant. */
10513 if (!sizes_ok
&& !integer_all_onesp (size
) && tree_int_cst_lt (size
, len
))
10516 tree fn
= NULL_TREE
;
10517 /* If __builtin_mem{cpy,pcpy,move,set}_chk is used, assume
10518 mem{cpy,pcpy,move,set} is available. */
10521 case BUILT_IN_MEMCPY_CHK
:
10522 fn
= builtin_decl_explicit (BUILT_IN_MEMCPY
);
10524 case BUILT_IN_MEMPCPY_CHK
:
10525 fn
= builtin_decl_explicit (BUILT_IN_MEMPCPY
);
10527 case BUILT_IN_MEMMOVE_CHK
:
10528 fn
= builtin_decl_explicit (BUILT_IN_MEMMOVE
);
10530 case BUILT_IN_MEMSET_CHK
:
10531 fn
= builtin_decl_explicit (BUILT_IN_MEMSET
);
10540 fn
= build_call_nofold_loc (EXPR_LOCATION (exp
), fn
, 3, dest
, src
, len
);
10541 gcc_assert (TREE_CODE (fn
) == CALL_EXPR
);
10542 CALL_EXPR_TAILCALL (fn
) = CALL_EXPR_TAILCALL (exp
);
10543 return expand_expr (fn
, target
, mode
, EXPAND_NORMAL
);
10545 else if (fcode
== BUILT_IN_MEMSET_CHK
)
10549 unsigned int dest_align
= get_pointer_alignment (dest
);
10551 /* If DEST is not a pointer type, call the normal function. */
10552 if (dest_align
== 0)
10555 /* If SRC and DEST are the same (and not volatile), do nothing. */
10556 if (operand_equal_p (src
, dest
, 0))
10560 if (fcode
!= BUILT_IN_MEMPCPY_CHK
)
10562 /* Evaluate and ignore LEN in case it has side-effects. */
10563 expand_expr (len
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
10564 return expand_expr (dest
, target
, mode
, EXPAND_NORMAL
);
10567 expr
= fold_build_pointer_plus (dest
, len
);
10568 return expand_expr (expr
, target
, mode
, EXPAND_NORMAL
);
10571 /* __memmove_chk special case. */
10572 if (fcode
== BUILT_IN_MEMMOVE_CHK
)
10574 unsigned int src_align
= get_pointer_alignment (src
);
10576 if (src_align
== 0)
10579 /* If src is categorized for a readonly section we can use
10580 normal __memcpy_chk. */
10581 if (readonly_data_expr (src
))
10583 tree fn
= builtin_decl_explicit (BUILT_IN_MEMCPY_CHK
);
10586 fn
= build_call_nofold_loc (EXPR_LOCATION (exp
), fn
, 4,
10587 dest
, src
, len
, size
);
10588 gcc_assert (TREE_CODE (fn
) == CALL_EXPR
);
10589 CALL_EXPR_TAILCALL (fn
) = CALL_EXPR_TAILCALL (exp
);
10590 return expand_expr (fn
, target
, mode
, EXPAND_NORMAL
);
10597 /* Emit warning if a buffer overflow is detected at compile time. */
10600 maybe_emit_chk_warning (tree exp
, enum built_in_function fcode
)
10602 /* The source string. */
10603 tree srcstr
= NULL_TREE
;
10604 /* The size of the destination object returned by __builtin_object_size. */
10605 tree objsize
= NULL_TREE
;
10606 /* The string that is being concatenated with (as in __strcat_chk)
10607 or null if it isn't. */
10608 tree catstr
= NULL_TREE
;
10609 /* The maximum length of the source sequence in a bounded operation
10610 (such as __strncat_chk) or null if the operation isn't bounded
10611 (such as __strcat_chk). */
10612 tree maxread
= NULL_TREE
;
10613 /* The exact size of the access (such as in __strncpy_chk). */
10614 tree size
= NULL_TREE
;
10615 /* The access by the function that's checked. Except for snprintf
10616 both writing and reading is checked. */
10617 access_mode mode
= access_read_write
;
10621 case BUILT_IN_STRCPY_CHK
:
10622 case BUILT_IN_STPCPY_CHK
:
10623 srcstr
= CALL_EXPR_ARG (exp
, 1);
10624 objsize
= CALL_EXPR_ARG (exp
, 2);
10627 case BUILT_IN_STRCAT_CHK
:
10628 /* For __strcat_chk the warning will be emitted only if overflowing
10629 by at least strlen (dest) + 1 bytes. */
10630 catstr
= CALL_EXPR_ARG (exp
, 0);
10631 srcstr
= CALL_EXPR_ARG (exp
, 1);
10632 objsize
= CALL_EXPR_ARG (exp
, 2);
10635 case BUILT_IN_STRNCAT_CHK
:
10636 catstr
= CALL_EXPR_ARG (exp
, 0);
10637 srcstr
= CALL_EXPR_ARG (exp
, 1);
10638 maxread
= CALL_EXPR_ARG (exp
, 2);
10639 objsize
= CALL_EXPR_ARG (exp
, 3);
10642 case BUILT_IN_STRNCPY_CHK
:
10643 case BUILT_IN_STPNCPY_CHK
:
10644 srcstr
= CALL_EXPR_ARG (exp
, 1);
10645 size
= CALL_EXPR_ARG (exp
, 2);
10646 objsize
= CALL_EXPR_ARG (exp
, 3);
10649 case BUILT_IN_SNPRINTF_CHK
:
10650 case BUILT_IN_VSNPRINTF_CHK
:
10651 maxread
= CALL_EXPR_ARG (exp
, 1);
10652 objsize
= CALL_EXPR_ARG (exp
, 3);
10653 /* The only checked access the write to the destination. */
10654 mode
= access_write_only
;
10657 gcc_unreachable ();
10660 if (catstr
&& maxread
)
10662 /* Check __strncat_chk. There is no way to determine the length
10663 of the string to which the source string is being appended so
10664 just warn when the length of the source string is not known. */
10665 check_strncat_sizes (exp
, objsize
);
10669 check_access (exp
, size
, maxread
, srcstr
, objsize
, mode
);
10672 /* Emit warning if a buffer overflow is detected at compile time
10673 in __sprintf_chk/__vsprintf_chk calls. */
10676 maybe_emit_sprintf_chk_warning (tree exp
, enum built_in_function fcode
)
10678 tree size
, len
, fmt
;
10679 const char *fmt_str
;
10680 int nargs
= call_expr_nargs (exp
);
10682 /* Verify the required arguments in the original call. */
10686 size
= CALL_EXPR_ARG (exp
, 2);
10687 fmt
= CALL_EXPR_ARG (exp
, 3);
10689 if (! tree_fits_uhwi_p (size
) || integer_all_onesp (size
))
10692 /* Check whether the format is a literal string constant. */
10693 fmt_str
= c_getstr (fmt
);
10694 if (fmt_str
== NULL
)
10697 if (!init_target_chars ())
10700 /* If the format doesn't contain % args or %%, we know its size. */
10701 if (strchr (fmt_str
, target_percent
) == 0)
10702 len
= build_int_cstu (size_type_node
, strlen (fmt_str
));
10703 /* If the format is "%s" and first ... argument is a string literal,
10705 else if (fcode
== BUILT_IN_SPRINTF_CHK
10706 && strcmp (fmt_str
, target_percent_s
) == 0)
10712 arg
= CALL_EXPR_ARG (exp
, 4);
10713 if (! POINTER_TYPE_P (TREE_TYPE (arg
)))
10716 len
= c_strlen (arg
, 1);
10717 if (!len
|| ! tree_fits_uhwi_p (len
))
10723 /* Add one for the terminating nul. */
10724 len
= fold_build2 (PLUS_EXPR
, TREE_TYPE (len
), len
, size_one_node
);
10726 check_access (exp
, /*size=*/NULL_TREE
, /*maxread=*/NULL_TREE
, len
, size
,
10727 access_write_only
);
10730 /* Fold a call to __builtin_object_size with arguments PTR and OST,
10734 fold_builtin_object_size (tree ptr
, tree ost
, enum built_in_function fcode
)
10737 int object_size_type
;
10739 if (!validate_arg (ptr
, POINTER_TYPE
)
10740 || !validate_arg (ost
, INTEGER_TYPE
))
10745 if (TREE_CODE (ost
) != INTEGER_CST
10746 || tree_int_cst_sgn (ost
) < 0
10747 || compare_tree_int (ost
, 3) > 0)
10750 object_size_type
= tree_to_shwi (ost
);
10752 /* __builtin_object_size doesn't evaluate side-effects in its arguments;
10753 if there are any side-effects, it returns (size_t) -1 for types 0 and 1
10754 and (size_t) 0 for types 2 and 3. */
10755 if (TREE_SIDE_EFFECTS (ptr
))
10756 return build_int_cst_type (size_type_node
, object_size_type
< 2 ? -1 : 0);
10758 if (fcode
== BUILT_IN_DYNAMIC_OBJECT_SIZE
)
10759 object_size_type
|= OST_DYNAMIC
;
10761 if (TREE_CODE (ptr
) == ADDR_EXPR
)
10763 compute_builtin_object_size (ptr
, object_size_type
, &bytes
);
10764 if ((object_size_type
& OST_DYNAMIC
)
10765 || int_fits_type_p (bytes
, size_type_node
))
10766 return fold_convert (size_type_node
, bytes
);
10768 else if (TREE_CODE (ptr
) == SSA_NAME
)
10770 /* If object size is not known yet, delay folding until
10771 later. Maybe subsequent passes will help determining
10773 if (compute_builtin_object_size (ptr
, object_size_type
, &bytes
)
10774 && ((object_size_type
& OST_DYNAMIC
)
10775 || int_fits_type_p (bytes
, size_type_node
)))
10776 return fold_convert (size_type_node
, bytes
);
10782 /* Builtins with folding operations that operate on "..." arguments
10783 need special handling; we need to store the arguments in a convenient
10784 data structure before attempting any folding. Fortunately there are
10785 only a few builtins that fall into this category. FNDECL is the
10786 function, EXP is the CALL_EXPR for the call. */
10789 fold_builtin_varargs (location_t loc
, tree fndecl
, tree
*args
, int nargs
)
10791 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
10792 tree ret
= NULL_TREE
;
10796 case BUILT_IN_FPCLASSIFY
:
10797 ret
= fold_builtin_fpclassify (loc
, args
, nargs
);
10805 ret
= build1 (NOP_EXPR
, TREE_TYPE (ret
), ret
);
10806 SET_EXPR_LOCATION (ret
, loc
);
10807 suppress_warning (ret
);
10813 /* Initialize format string characters in the target charset. */
10816 init_target_chars (void)
10821 target_newline
= lang_hooks
.to_target_charset ('\n');
10822 target_percent
= lang_hooks
.to_target_charset ('%');
10823 target_c
= lang_hooks
.to_target_charset ('c');
10824 target_s
= lang_hooks
.to_target_charset ('s');
10825 if (target_newline
== 0 || target_percent
== 0 || target_c
== 0
10829 target_percent_c
[0] = target_percent
;
10830 target_percent_c
[1] = target_c
;
10831 target_percent_c
[2] = '\0';
10833 target_percent_s
[0] = target_percent
;
10834 target_percent_s
[1] = target_s
;
10835 target_percent_s
[2] = '\0';
10837 target_percent_s_newline
[0] = target_percent
;
10838 target_percent_s_newline
[1] = target_s
;
10839 target_percent_s_newline
[2] = target_newline
;
10840 target_percent_s_newline
[3] = '\0';
10847 /* Helper function for do_mpfr_arg*(). Ensure M is a normal number
10848 and no overflow/underflow occurred. INEXACT is true if M was not
10849 exactly calculated. TYPE is the tree type for the result. This
10850 function assumes that you cleared the MPFR flags and then
10851 calculated M to see if anything subsequently set a flag prior to
10852 entering this function. Return NULL_TREE if any checks fail. */
10855 do_mpfr_ckconv (mpfr_srcptr m
, tree type
, int inexact
)
10857 /* Proceed iff we get a normal number, i.e. not NaN or Inf and no
10858 overflow/underflow occurred. If -frounding-math, proceed iff the
10859 result of calling FUNC was exact. */
10860 if (mpfr_number_p (m
) && !mpfr_overflow_p () && !mpfr_underflow_p ()
10861 && (!flag_rounding_math
|| !inexact
))
10863 REAL_VALUE_TYPE rr
;
10865 real_from_mpfr (&rr
, m
, type
, MPFR_RNDN
);
10866 /* Proceed iff GCC's REAL_VALUE_TYPE can hold the MPFR value,
10867 check for overflow/underflow. If the REAL_VALUE_TYPE is zero
10868 but the mpft_t is not, then we underflowed in the
10870 if (real_isfinite (&rr
)
10871 && (rr
.cl
== rvc_zero
) == (mpfr_zero_p (m
) != 0))
10873 REAL_VALUE_TYPE rmode
;
10875 real_convert (&rmode
, TYPE_MODE (type
), &rr
);
10876 /* Proceed iff the specified mode can hold the value. */
10877 if (real_identical (&rmode
, &rr
))
10878 return build_real (type
, rmode
);
10884 /* Helper function for do_mpc_arg*(). Ensure M is a normal complex
10885 number and no overflow/underflow occurred. INEXACT is true if M
10886 was not exactly calculated. TYPE is the tree type for the result.
10887 This function assumes that you cleared the MPFR flags and then
10888 calculated M to see if anything subsequently set a flag prior to
10889 entering this function. Return NULL_TREE if any checks fail, if
10890 FORCE_CONVERT is true, then bypass the checks. */
10893 do_mpc_ckconv (mpc_srcptr m
, tree type
, int inexact
, int force_convert
)
10895 /* Proceed iff we get a normal number, i.e. not NaN or Inf and no
10896 overflow/underflow occurred. If -frounding-math, proceed iff the
10897 result of calling FUNC was exact. */
10899 || (mpfr_number_p (mpc_realref (m
)) && mpfr_number_p (mpc_imagref (m
))
10900 && !mpfr_overflow_p () && !mpfr_underflow_p ()
10901 && (!flag_rounding_math
|| !inexact
)))
10903 REAL_VALUE_TYPE re
, im
;
10905 real_from_mpfr (&re
, mpc_realref (m
), TREE_TYPE (type
), MPFR_RNDN
);
10906 real_from_mpfr (&im
, mpc_imagref (m
), TREE_TYPE (type
), MPFR_RNDN
);
10907 /* Proceed iff GCC's REAL_VALUE_TYPE can hold the MPFR values,
10908 check for overflow/underflow. If the REAL_VALUE_TYPE is zero
10909 but the mpft_t is not, then we underflowed in the
10912 || (real_isfinite (&re
) && real_isfinite (&im
)
10913 && (re
.cl
== rvc_zero
) == (mpfr_zero_p (mpc_realref (m
)) != 0)
10914 && (im
.cl
== rvc_zero
) == (mpfr_zero_p (mpc_imagref (m
)) != 0)))
10916 REAL_VALUE_TYPE re_mode
, im_mode
;
10918 real_convert (&re_mode
, TYPE_MODE (TREE_TYPE (type
)), &re
);
10919 real_convert (&im_mode
, TYPE_MODE (TREE_TYPE (type
)), &im
);
10920 /* Proceed iff the specified mode can hold the value. */
10922 || (real_identical (&re_mode
, &re
)
10923 && real_identical (&im_mode
, &im
)))
10924 return build_complex (type
, build_real (TREE_TYPE (type
), re_mode
),
10925 build_real (TREE_TYPE (type
), im_mode
));
10931 /* If arguments ARG0 and ARG1 are REAL_CSTs, call mpfr_remquo() to set
10932 the pointer *(ARG_QUO) and return the result. The type is taken
10933 from the type of ARG0 and is used for setting the precision of the
10934 calculation and results. */
10937 do_mpfr_remquo (tree arg0
, tree arg1
, tree arg_quo
)
10939 tree
const type
= TREE_TYPE (arg0
);
10940 tree result
= NULL_TREE
;
10945 /* To proceed, MPFR must exactly represent the target floating point
10946 format, which only happens when the target base equals two. */
10947 if (REAL_MODE_FORMAT (TYPE_MODE (type
))->b
== 2
10948 && TREE_CODE (arg0
) == REAL_CST
&& !TREE_OVERFLOW (arg0
)
10949 && TREE_CODE (arg1
) == REAL_CST
&& !TREE_OVERFLOW (arg1
))
10951 const REAL_VALUE_TYPE
*const ra0
= TREE_REAL_CST_PTR (arg0
);
10952 const REAL_VALUE_TYPE
*const ra1
= TREE_REAL_CST_PTR (arg1
);
10954 if (real_isfinite (ra0
) && real_isfinite (ra1
))
10956 const struct real_format
*fmt
= REAL_MODE_FORMAT (TYPE_MODE (type
));
10957 const int prec
= fmt
->p
;
10958 const mpfr_rnd_t rnd
= fmt
->round_towards_zero
? MPFR_RNDZ
: MPFR_RNDN
;
10963 mpfr_inits2 (prec
, m0
, m1
, NULL
);
10964 mpfr_from_real (m0
, ra0
, MPFR_RNDN
);
10965 mpfr_from_real (m1
, ra1
, MPFR_RNDN
);
10966 mpfr_clear_flags ();
10967 mpfr_remquo (m0
, &integer_quo
, m0
, m1
, rnd
);
10968 /* Remquo is independent of the rounding mode, so pass
10969 inexact=0 to do_mpfr_ckconv(). */
10970 result_rem
= do_mpfr_ckconv (m0
, type
, /*inexact=*/ 0);
10971 mpfr_clears (m0
, m1
, NULL
);
10974 /* MPFR calculates quo in the host's long so it may
10975 return more bits in quo than the target int can hold
10976 if sizeof(host long) > sizeof(target int). This can
10977 happen even for native compilers in LP64 mode. In
10978 these cases, modulo the quo value with the largest
10979 number that the target int can hold while leaving one
10980 bit for the sign. */
10981 if (sizeof (integer_quo
) * CHAR_BIT
> INT_TYPE_SIZE
)
10982 integer_quo
%= (long)(1UL << (INT_TYPE_SIZE
- 1));
10984 /* Dereference the quo pointer argument. */
10985 arg_quo
= build_fold_indirect_ref (arg_quo
);
10986 /* Proceed iff a valid pointer type was passed in. */
10987 if (TYPE_MAIN_VARIANT (TREE_TYPE (arg_quo
)) == integer_type_node
)
10989 /* Set the value. */
10991 = fold_build2 (MODIFY_EXPR
, TREE_TYPE (arg_quo
), arg_quo
,
10992 build_int_cst (TREE_TYPE (arg_quo
),
10994 TREE_SIDE_EFFECTS (result_quo
) = 1;
10995 /* Combine the quo assignment with the rem. */
10996 result
= fold_build2 (COMPOUND_EXPR
, type
,
10997 result_quo
, result_rem
);
10998 suppress_warning (result
, OPT_Wunused_value
);
10999 result
= non_lvalue (result
);
11007 /* If ARG is a REAL_CST, call mpfr_lgamma() on it and return the
11008 resulting value as a tree with type TYPE. The mpfr precision is
11009 set to the precision of TYPE. We assume that this mpfr function
11010 returns zero if the result could be calculated exactly within the
11011 requested precision. In addition, the integer pointer represented
11012 by ARG_SG will be dereferenced and set to the appropriate signgam
11016 do_mpfr_lgamma_r (tree arg
, tree arg_sg
, tree type
)
11018 tree result
= NULL_TREE
;
11022 /* To proceed, MPFR must exactly represent the target floating point
11023 format, which only happens when the target base equals two. Also
11024 verify ARG is a constant and that ARG_SG is an int pointer. */
11025 if (REAL_MODE_FORMAT (TYPE_MODE (type
))->b
== 2
11026 && TREE_CODE (arg
) == REAL_CST
&& !TREE_OVERFLOW (arg
)
11027 && TREE_CODE (TREE_TYPE (arg_sg
)) == POINTER_TYPE
11028 && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (arg_sg
))) == integer_type_node
)
11030 const REAL_VALUE_TYPE
*const ra
= TREE_REAL_CST_PTR (arg
);
11032 /* In addition to NaN and Inf, the argument cannot be zero or a
11033 negative integer. */
11034 if (real_isfinite (ra
)
11035 && ra
->cl
!= rvc_zero
11036 && !(real_isneg (ra
) && real_isinteger (ra
, TYPE_MODE (type
))))
11038 const struct real_format
*fmt
= REAL_MODE_FORMAT (TYPE_MODE (type
));
11039 const int prec
= fmt
->p
;
11040 const mpfr_rnd_t rnd
= fmt
->round_towards_zero
? MPFR_RNDZ
: MPFR_RNDN
;
11045 mpfr_init2 (m
, prec
);
11046 mpfr_from_real (m
, ra
, MPFR_RNDN
);
11047 mpfr_clear_flags ();
11048 inexact
= mpfr_lgamma (m
, &sg
, m
, rnd
);
11049 result_lg
= do_mpfr_ckconv (m
, type
, inexact
);
11055 /* Dereference the arg_sg pointer argument. */
11056 arg_sg
= build_fold_indirect_ref (arg_sg
);
11057 /* Assign the signgam value into *arg_sg. */
11058 result_sg
= fold_build2 (MODIFY_EXPR
,
11059 TREE_TYPE (arg_sg
), arg_sg
,
11060 build_int_cst (TREE_TYPE (arg_sg
), sg
));
11061 TREE_SIDE_EFFECTS (result_sg
) = 1;
11062 /* Combine the signgam assignment with the lgamma result. */
11063 result
= non_lvalue (fold_build2 (COMPOUND_EXPR
, type
,
11064 result_sg
, result_lg
));
11072 /* If arguments ARG0 and ARG1 are a COMPLEX_CST, call the two-argument
11073 mpc function FUNC on it and return the resulting value as a tree
11074 with type TYPE. The mpfr precision is set to the precision of
11075 TYPE. We assume that function FUNC returns zero if the result
11076 could be calculated exactly within the requested precision. If
11077 DO_NONFINITE is true, then fold expressions containing Inf or NaN
11078 in the arguments and/or results. */
11081 do_mpc_arg2 (tree arg0
, tree arg1
, tree type
, int do_nonfinite
,
11082 int (*func
)(mpc_ptr
, mpc_srcptr
, mpc_srcptr
, mpc_rnd_t
))
11084 tree result
= NULL_TREE
;
11089 /* To proceed, MPFR must exactly represent the target floating point
11090 format, which only happens when the target base equals two. */
11091 if (TREE_CODE (arg0
) == COMPLEX_CST
&& !TREE_OVERFLOW (arg0
)
11092 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg0
))) == REAL_TYPE
11093 && TREE_CODE (arg1
) == COMPLEX_CST
&& !TREE_OVERFLOW (arg1
)
11094 && TREE_CODE (TREE_TYPE (TREE_TYPE (arg1
))) == REAL_TYPE
11095 && REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0
))))->b
== 2)
11097 const REAL_VALUE_TYPE
*const re0
= TREE_REAL_CST_PTR (TREE_REALPART (arg0
));
11098 const REAL_VALUE_TYPE
*const im0
= TREE_REAL_CST_PTR (TREE_IMAGPART (arg0
));
11099 const REAL_VALUE_TYPE
*const re1
= TREE_REAL_CST_PTR (TREE_REALPART (arg1
));
11100 const REAL_VALUE_TYPE
*const im1
= TREE_REAL_CST_PTR (TREE_IMAGPART (arg1
));
11103 || (real_isfinite (re0
) && real_isfinite (im0
)
11104 && real_isfinite (re1
) && real_isfinite (im1
)))
11106 const struct real_format
*const fmt
=
11107 REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (type
)));
11108 const int prec
= fmt
->p
;
11109 const mpfr_rnd_t rnd
= fmt
->round_towards_zero
11110 ? MPFR_RNDZ
: MPFR_RNDN
;
11111 const mpc_rnd_t crnd
= fmt
->round_towards_zero
? MPC_RNDZZ
: MPC_RNDNN
;
11115 mpc_init2 (m0
, prec
);
11116 mpc_init2 (m1
, prec
);
11117 mpfr_from_real (mpc_realref (m0
), re0
, rnd
);
11118 mpfr_from_real (mpc_imagref (m0
), im0
, rnd
);
11119 mpfr_from_real (mpc_realref (m1
), re1
, rnd
);
11120 mpfr_from_real (mpc_imagref (m1
), im1
, rnd
);
11121 mpfr_clear_flags ();
11122 inexact
= func (m0
, m0
, m1
, crnd
);
11123 result
= do_mpc_ckconv (m0
, type
, inexact
, do_nonfinite
);
11132 /* A wrapper function for builtin folding that prevents warnings for
11133 "statement without effect" and the like, caused by removing the
11134 call node earlier than the warning is generated. */
11137 fold_call_stmt (gcall
*stmt
, bool ignore
)
11139 tree ret
= NULL_TREE
;
11140 tree fndecl
= gimple_call_fndecl (stmt
);
11141 location_t loc
= gimple_location (stmt
);
11142 if (fndecl
&& fndecl_built_in_p (fndecl
)
11143 && !gimple_call_va_arg_pack_p (stmt
))
11145 int nargs
= gimple_call_num_args (stmt
);
11146 tree
*args
= (nargs
> 0
11147 ? gimple_call_arg_ptr (stmt
, 0)
11148 : &error_mark_node
);
11150 if (avoid_folding_inline_builtin (fndecl
))
11152 if (DECL_BUILT_IN_CLASS (fndecl
) == BUILT_IN_MD
)
11154 return targetm
.fold_builtin (fndecl
, nargs
, args
, ignore
);
11158 ret
= fold_builtin_n (loc
, NULL_TREE
, fndecl
, args
, nargs
, ignore
);
11161 /* Propagate location information from original call to
11162 expansion of builtin. Otherwise things like
11163 maybe_emit_chk_warning, that operate on the expansion
11164 of a builtin, will use the wrong location information. */
11165 if (gimple_has_location (stmt
))
11167 tree realret
= ret
;
11168 if (TREE_CODE (ret
) == NOP_EXPR
)
11169 realret
= TREE_OPERAND (ret
, 0);
11170 if (CAN_HAVE_LOCATION_P (realret
)
11171 && !EXPR_HAS_LOCATION (realret
))
11172 SET_EXPR_LOCATION (realret
, loc
);
11182 /* Look up the function in builtin_decl that corresponds to DECL
11183 and set ASMSPEC as its user assembler name. DECL must be a
11184 function decl that declares a builtin. */
11187 set_builtin_user_assembler_name (tree decl
, const char *asmspec
)
11189 gcc_assert (fndecl_built_in_p (decl
, BUILT_IN_NORMAL
)
11192 tree builtin
= builtin_decl_explicit (DECL_FUNCTION_CODE (decl
));
11193 set_user_assembler_name (builtin
, asmspec
);
11195 if (DECL_FUNCTION_CODE (decl
) == BUILT_IN_FFS
11196 && INT_TYPE_SIZE
< BITS_PER_WORD
)
11198 scalar_int_mode mode
= int_mode_for_size (INT_TYPE_SIZE
, 0).require ();
11199 set_user_assembler_libfunc ("ffs", asmspec
);
11200 set_optab_libfunc (ffs_optab
, mode
, "ffs");
11204 /* Return true if DECL is a builtin that expands to a constant or similarly
11207 is_simple_builtin (tree decl
)
11209 if (decl
&& fndecl_built_in_p (decl
, BUILT_IN_NORMAL
))
11210 switch (DECL_FUNCTION_CODE (decl
))
11212 /* Builtins that expand to constants. */
11213 case BUILT_IN_CONSTANT_P
:
11214 case BUILT_IN_EXPECT
:
11215 case BUILT_IN_OBJECT_SIZE
:
11216 case BUILT_IN_UNREACHABLE
:
11217 /* Simple register moves or loads from stack. */
11218 case BUILT_IN_ASSUME_ALIGNED
:
11219 case BUILT_IN_RETURN_ADDRESS
:
11220 case BUILT_IN_EXTRACT_RETURN_ADDR
:
11221 case BUILT_IN_FROB_RETURN_ADDR
:
11222 case BUILT_IN_RETURN
:
11223 case BUILT_IN_AGGREGATE_INCOMING_ADDRESS
:
11224 case BUILT_IN_FRAME_ADDRESS
:
11225 case BUILT_IN_VA_END
:
11226 case BUILT_IN_STACK_SAVE
:
11227 case BUILT_IN_STACK_RESTORE
:
11228 case BUILT_IN_DWARF_CFA
:
11229 /* Exception state returns or moves registers around. */
11230 case BUILT_IN_EH_FILTER
:
11231 case BUILT_IN_EH_POINTER
:
11232 case BUILT_IN_EH_COPY_VALUES
:
11242 /* Return true if DECL is a builtin that is not expensive, i.e., they are
11243 most probably expanded inline into reasonably simple code. This is a
11244 superset of is_simple_builtin. */
11246 is_inexpensive_builtin (tree decl
)
11250 else if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_MD
)
11252 else if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
)
11253 switch (DECL_FUNCTION_CODE (decl
))
11256 CASE_BUILT_IN_ALLOCA
:
11257 case BUILT_IN_BSWAP16
:
11258 case BUILT_IN_BSWAP32
:
11259 case BUILT_IN_BSWAP64
:
11260 case BUILT_IN_BSWAP128
:
11262 case BUILT_IN_CLZIMAX
:
11263 case BUILT_IN_CLZL
:
11264 case BUILT_IN_CLZLL
:
11266 case BUILT_IN_CTZIMAX
:
11267 case BUILT_IN_CTZL
:
11268 case BUILT_IN_CTZLL
:
11270 case BUILT_IN_FFSIMAX
:
11271 case BUILT_IN_FFSL
:
11272 case BUILT_IN_FFSLL
:
11273 case BUILT_IN_IMAXABS
:
11274 case BUILT_IN_FINITE
:
11275 case BUILT_IN_FINITEF
:
11276 case BUILT_IN_FINITEL
:
11277 case BUILT_IN_FINITED32
:
11278 case BUILT_IN_FINITED64
:
11279 case BUILT_IN_FINITED128
:
11280 case BUILT_IN_FPCLASSIFY
:
11281 case BUILT_IN_ISFINITE
:
11282 case BUILT_IN_ISINF_SIGN
:
11283 case BUILT_IN_ISINF
:
11284 case BUILT_IN_ISINFF
:
11285 case BUILT_IN_ISINFL
:
11286 case BUILT_IN_ISINFD32
:
11287 case BUILT_IN_ISINFD64
:
11288 case BUILT_IN_ISINFD128
:
11289 case BUILT_IN_ISNAN
:
11290 case BUILT_IN_ISNANF
:
11291 case BUILT_IN_ISNANL
:
11292 case BUILT_IN_ISNAND32
:
11293 case BUILT_IN_ISNAND64
:
11294 case BUILT_IN_ISNAND128
:
11295 case BUILT_IN_ISNORMAL
:
11296 case BUILT_IN_ISGREATER
:
11297 case BUILT_IN_ISGREATEREQUAL
:
11298 case BUILT_IN_ISLESS
:
11299 case BUILT_IN_ISLESSEQUAL
:
11300 case BUILT_IN_ISLESSGREATER
:
11301 case BUILT_IN_ISUNORDERED
:
11302 case BUILT_IN_VA_ARG_PACK
:
11303 case BUILT_IN_VA_ARG_PACK_LEN
:
11304 case BUILT_IN_VA_COPY
:
11305 case BUILT_IN_TRAP
:
11306 case BUILT_IN_SAVEREGS
:
11307 case BUILT_IN_POPCOUNTL
:
11308 case BUILT_IN_POPCOUNTLL
:
11309 case BUILT_IN_POPCOUNTIMAX
:
11310 case BUILT_IN_POPCOUNT
:
11311 case BUILT_IN_PARITYL
:
11312 case BUILT_IN_PARITYLL
:
11313 case BUILT_IN_PARITYIMAX
:
11314 case BUILT_IN_PARITY
:
11315 case BUILT_IN_LABS
:
11316 case BUILT_IN_LLABS
:
11317 case BUILT_IN_PREFETCH
:
11318 case BUILT_IN_ACC_ON_DEVICE
:
11322 return is_simple_builtin (decl
);
11328 /* Return true if T is a constant and the value cast to a target char
11329 can be represented by a host char.
11330 Store the casted char constant in *P if so. */
11333 target_char_cst_p (tree t
, char *p
)
11335 if (!tree_fits_uhwi_p (t
) || CHAR_TYPE_SIZE
!= HOST_BITS_PER_CHAR
)
11338 *p
= (char)tree_to_uhwi (t
);
11342 /* Return true if the builtin DECL is implemented in a standard library.
11343 Otherwise return false which doesn't guarantee it is not (thus the list
11344 of handled builtins below may be incomplete). */
11347 builtin_with_linkage_p (tree decl
)
11349 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
)
11350 switch (DECL_FUNCTION_CODE (decl
))
11352 CASE_FLT_FN (BUILT_IN_ACOS
):
11353 CASE_FLT_FN (BUILT_IN_ACOSH
):
11354 CASE_FLT_FN (BUILT_IN_ASIN
):
11355 CASE_FLT_FN (BUILT_IN_ASINH
):
11356 CASE_FLT_FN (BUILT_IN_ATAN
):
11357 CASE_FLT_FN (BUILT_IN_ATANH
):
11358 CASE_FLT_FN (BUILT_IN_ATAN2
):
11359 CASE_FLT_FN (BUILT_IN_CBRT
):
11360 CASE_FLT_FN (BUILT_IN_CEIL
):
11361 CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL
):
11362 CASE_FLT_FN (BUILT_IN_COPYSIGN
):
11363 CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN
):
11364 CASE_FLT_FN (BUILT_IN_COS
):
11365 CASE_FLT_FN (BUILT_IN_COSH
):
11366 CASE_FLT_FN (BUILT_IN_ERF
):
11367 CASE_FLT_FN (BUILT_IN_ERFC
):
11368 CASE_FLT_FN (BUILT_IN_EXP
):
11369 CASE_FLT_FN (BUILT_IN_EXP2
):
11370 CASE_FLT_FN (BUILT_IN_EXPM1
):
11371 CASE_FLT_FN (BUILT_IN_FABS
):
11372 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
11373 CASE_FLT_FN (BUILT_IN_FDIM
):
11374 CASE_FLT_FN (BUILT_IN_FLOOR
):
11375 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR
):
11376 CASE_FLT_FN (BUILT_IN_FMA
):
11377 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA
):
11378 CASE_FLT_FN (BUILT_IN_FMAX
):
11379 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX
):
11380 CASE_FLT_FN (BUILT_IN_FMIN
):
11381 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN
):
11382 CASE_FLT_FN (BUILT_IN_FMOD
):
11383 CASE_FLT_FN (BUILT_IN_FREXP
):
11384 CASE_FLT_FN (BUILT_IN_HYPOT
):
11385 CASE_FLT_FN (BUILT_IN_ILOGB
):
11386 CASE_FLT_FN (BUILT_IN_LDEXP
):
11387 CASE_FLT_FN (BUILT_IN_LGAMMA
):
11388 CASE_FLT_FN (BUILT_IN_LLRINT
):
11389 CASE_FLT_FN (BUILT_IN_LLROUND
):
11390 CASE_FLT_FN (BUILT_IN_LOG
):
11391 CASE_FLT_FN (BUILT_IN_LOG10
):
11392 CASE_FLT_FN (BUILT_IN_LOG1P
):
11393 CASE_FLT_FN (BUILT_IN_LOG2
):
11394 CASE_FLT_FN (BUILT_IN_LOGB
):
11395 CASE_FLT_FN (BUILT_IN_LRINT
):
11396 CASE_FLT_FN (BUILT_IN_LROUND
):
11397 CASE_FLT_FN (BUILT_IN_MODF
):
11398 CASE_FLT_FN (BUILT_IN_NAN
):
11399 CASE_FLT_FN (BUILT_IN_NEARBYINT
):
11400 CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT
):
11401 CASE_FLT_FN (BUILT_IN_NEXTAFTER
):
11402 CASE_FLT_FN (BUILT_IN_NEXTTOWARD
):
11403 CASE_FLT_FN (BUILT_IN_POW
):
11404 CASE_FLT_FN (BUILT_IN_REMAINDER
):
11405 CASE_FLT_FN (BUILT_IN_REMQUO
):
11406 CASE_FLT_FN (BUILT_IN_RINT
):
11407 CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT
):
11408 CASE_FLT_FN (BUILT_IN_ROUND
):
11409 CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND
):
11410 CASE_FLT_FN (BUILT_IN_SCALBLN
):
11411 CASE_FLT_FN (BUILT_IN_SCALBN
):
11412 CASE_FLT_FN (BUILT_IN_SIN
):
11413 CASE_FLT_FN (BUILT_IN_SINH
):
11414 CASE_FLT_FN (BUILT_IN_SINCOS
):
11415 CASE_FLT_FN (BUILT_IN_SQRT
):
11416 CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT
):
11417 CASE_FLT_FN (BUILT_IN_TAN
):
11418 CASE_FLT_FN (BUILT_IN_TANH
):
11419 CASE_FLT_FN (BUILT_IN_TGAMMA
):
11420 CASE_FLT_FN (BUILT_IN_TRUNC
):
11421 CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC
):
11424 case BUILT_IN_STPCPY
:
11425 case BUILT_IN_STPNCPY
:
11426 /* stpcpy is both referenced in libiberty's pex-win32.c and provided
11427 by libiberty's stpcpy.c for MinGW targets so we need to return true
11428 in order to be able to build libiberty in LTO mode for them. */
11437 /* Return true if OFFRNG is bounded to a subrange of offset values
11438 valid for the largest possible object. */
11441 access_ref::offset_bounded () const
11443 tree min
= TYPE_MIN_VALUE (ptrdiff_type_node
);
11444 tree max
= TYPE_MAX_VALUE (ptrdiff_type_node
);
11445 return wi::to_offset (min
) <= offrng
[0] && offrng
[1] <= wi::to_offset (max
);
11448 /* If CALLEE has known side effects, fill in INFO and return true.
11449 See tree-ssa-structalias.cc:find_func_aliases
11450 for the list of builtins we might need to handle here. */
11453 builtin_fnspec (tree callee
)
11455 built_in_function code
= DECL_FUNCTION_CODE (callee
);
11459 /* All the following functions read memory pointed to by
11460 their second argument and write memory pointed to by first
11462 strcat/strncat additionally reads memory pointed to by the first
11464 case BUILT_IN_STRCAT
:
11465 case BUILT_IN_STRCAT_CHK
:
11467 case BUILT_IN_STRNCAT
:
11468 case BUILT_IN_STRNCAT_CHK
:
11470 case BUILT_IN_STRCPY
:
11471 case BUILT_IN_STRCPY_CHK
:
11473 case BUILT_IN_STPCPY
:
11474 case BUILT_IN_STPCPY_CHK
:
11476 case BUILT_IN_STRNCPY
:
11477 case BUILT_IN_MEMCPY
:
11478 case BUILT_IN_MEMMOVE
:
11479 case BUILT_IN_TM_MEMCPY
:
11480 case BUILT_IN_TM_MEMMOVE
:
11481 case BUILT_IN_STRNCPY_CHK
:
11482 case BUILT_IN_MEMCPY_CHK
:
11483 case BUILT_IN_MEMMOVE_CHK
:
11485 case BUILT_IN_MEMPCPY
:
11486 case BUILT_IN_MEMPCPY_CHK
:
11488 case BUILT_IN_STPNCPY
:
11489 case BUILT_IN_STPNCPY_CHK
:
11491 case BUILT_IN_BCOPY
:
11493 case BUILT_IN_BZERO
:
11495 case BUILT_IN_MEMCMP
:
11496 case BUILT_IN_MEMCMP_EQ
:
11497 case BUILT_IN_BCMP
:
11498 case BUILT_IN_STRNCMP
:
11499 case BUILT_IN_STRNCMP_EQ
:
11500 case BUILT_IN_STRNCASECMP
:
11503 /* The following functions read memory pointed to by their
11505 CASE_BUILT_IN_TM_LOAD (1):
11506 CASE_BUILT_IN_TM_LOAD (2):
11507 CASE_BUILT_IN_TM_LOAD (4):
11508 CASE_BUILT_IN_TM_LOAD (8):
11509 CASE_BUILT_IN_TM_LOAD (FLOAT
):
11510 CASE_BUILT_IN_TM_LOAD (DOUBLE
):
11511 CASE_BUILT_IN_TM_LOAD (LDOUBLE
):
11512 CASE_BUILT_IN_TM_LOAD (M64
):
11513 CASE_BUILT_IN_TM_LOAD (M128
):
11514 CASE_BUILT_IN_TM_LOAD (M256
):
11515 case BUILT_IN_TM_LOG
:
11516 case BUILT_IN_TM_LOG_1
:
11517 case BUILT_IN_TM_LOG_2
:
11518 case BUILT_IN_TM_LOG_4
:
11519 case BUILT_IN_TM_LOG_8
:
11520 case BUILT_IN_TM_LOG_FLOAT
:
11521 case BUILT_IN_TM_LOG_DOUBLE
:
11522 case BUILT_IN_TM_LOG_LDOUBLE
:
11523 case BUILT_IN_TM_LOG_M64
:
11524 case BUILT_IN_TM_LOG_M128
:
11525 case BUILT_IN_TM_LOG_M256
:
11528 case BUILT_IN_INDEX
:
11529 case BUILT_IN_RINDEX
:
11530 case BUILT_IN_STRCHR
:
11531 case BUILT_IN_STRLEN
:
11532 case BUILT_IN_STRRCHR
:
11534 case BUILT_IN_STRNLEN
:
11537 /* These read memory pointed to by the first argument.
11538 Allocating memory does not have any side-effects apart from
11539 being the definition point for the pointer.
11540 Unix98 specifies that errno is set on allocation failure. */
11541 case BUILT_IN_STRDUP
:
11543 case BUILT_IN_STRNDUP
:
11545 /* Allocating memory does not have any side-effects apart from
11546 being the definition point for the pointer. */
11547 case BUILT_IN_MALLOC
:
11548 case BUILT_IN_ALIGNED_ALLOC
:
11549 case BUILT_IN_CALLOC
:
11550 case BUILT_IN_GOMP_ALLOC
:
11552 CASE_BUILT_IN_ALLOCA
:
11554 /* These read memory pointed to by the first argument with size
11555 in the third argument. */
11556 case BUILT_IN_MEMCHR
:
11558 /* These read memory pointed to by the first and second arguments. */
11559 case BUILT_IN_STRSTR
:
11560 case BUILT_IN_STRPBRK
:
11561 case BUILT_IN_STRCASECMP
:
11562 case BUILT_IN_STRCSPN
:
11563 case BUILT_IN_STRSPN
:
11564 case BUILT_IN_STRCMP
:
11565 case BUILT_IN_STRCMP_EQ
:
11567 /* Freeing memory kills the pointed-to memory. More importantly
11568 the call has to serve as a barrier for moving loads and stores
11570 case BUILT_IN_STACK_RESTORE
:
11571 case BUILT_IN_FREE
:
11572 case BUILT_IN_GOMP_FREE
:
11574 case BUILT_IN_VA_END
:
11576 /* Realloc serves both as allocation point and deallocation point. */
11577 case BUILT_IN_REALLOC
:
11579 case BUILT_IN_GAMMA_R
:
11580 case BUILT_IN_GAMMAF_R
:
11581 case BUILT_IN_GAMMAL_R
:
11582 case BUILT_IN_LGAMMA_R
:
11583 case BUILT_IN_LGAMMAF_R
:
11584 case BUILT_IN_LGAMMAL_R
:
11586 case BUILT_IN_FREXP
:
11587 case BUILT_IN_FREXPF
:
11588 case BUILT_IN_FREXPL
:
11589 case BUILT_IN_MODF
:
11590 case BUILT_IN_MODFF
:
11591 case BUILT_IN_MODFL
:
11593 case BUILT_IN_REMQUO
:
11594 case BUILT_IN_REMQUOF
:
11595 case BUILT_IN_REMQUOL
:
11597 case BUILT_IN_SINCOS
:
11598 case BUILT_IN_SINCOSF
:
11599 case BUILT_IN_SINCOSL
:
11601 case BUILT_IN_MEMSET
:
11602 case BUILT_IN_MEMSET_CHK
:
11603 case BUILT_IN_TM_MEMSET
:
11605 CASE_BUILT_IN_TM_STORE (1):
11606 CASE_BUILT_IN_TM_STORE (2):
11607 CASE_BUILT_IN_TM_STORE (4):
11608 CASE_BUILT_IN_TM_STORE (8):
11609 CASE_BUILT_IN_TM_STORE (FLOAT
):
11610 CASE_BUILT_IN_TM_STORE (DOUBLE
):
11611 CASE_BUILT_IN_TM_STORE (LDOUBLE
):
11612 CASE_BUILT_IN_TM_STORE (M64
):
11613 CASE_BUILT_IN_TM_STORE (M128
):
11614 CASE_BUILT_IN_TM_STORE (M256
):
11616 case BUILT_IN_STACK_SAVE
:
11617 case BUILT_IN_RETURN
:
11618 case BUILT_IN_EH_POINTER
:
11619 case BUILT_IN_EH_FILTER
:
11620 case BUILT_IN_UNWIND_RESUME
:
11621 case BUILT_IN_CXA_END_CLEANUP
:
11622 case BUILT_IN_EH_COPY_VALUES
:
11623 case BUILT_IN_FRAME_ADDRESS
:
11624 case BUILT_IN_APPLY_ARGS
:
11625 case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT
:
11626 case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT
:
11627 case BUILT_IN_PREFETCH
:
11628 case BUILT_IN_DWARF_CFA
:
11629 case BUILT_IN_RETURN_ADDRESS
:
11631 case BUILT_IN_ASSUME_ALIGNED
:
11633 /* But posix_memalign stores a pointer into the memory pointed to
11634 by its first argument. */
11635 case BUILT_IN_POSIX_MEMALIGN
: