1 /* ACLE support for Arm MVE
2 Copyright (C) 2021-2023 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
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 #define IN_TARGET_CODE 1
24 #include "coretypes.h"
30 #include "insn-codes.h"
34 #include "basic-block.h"
36 #include "fold-const.h"
38 #include "gimple-iterator.h"
40 #include "langhooks.h"
41 #include "stringpool.h"
43 #include "diagnostic.h"
44 #include "arm-protos.h"
45 #include "arm-builtins.h"
46 #include "arm-mve-builtins.h"
47 #include "arm-mve-builtins-base.h"
48 #include "arm-mve-builtins-shapes.h"
52 /* Static information about each single-predicate or single-vector
54 struct vector_type_info
56 /* The name of the type as declared by arm_mve.h. */
57 const char *acle_name
;
59 /* Whether the type requires a floating point abi. */
60 const bool requires_float
;
63 /* Describes a function decl. */
64 class GTY(()) registered_function
67 /* The ACLE function that the decl represents. */
68 function_instance instance
GTY ((skip
));
70 /* The decl itself. */
73 /* Whether the function requires a floating point abi. */
76 /* True if the decl represents an overloaded function that needs to be
77 resolved by function_resolver. */
81 /* Hash traits for registered_function. */
82 struct registered_function_hasher
: nofree_ptr_hash
<registered_function
>
84 typedef function_instance compare_type
;
86 static hashval_t
hash (value_type
);
87 static bool equal (value_type
, const compare_type
&);
90 /* Flag indicating whether the arm MVE types have been handled. */
91 static bool handle_arm_mve_types_p
;
93 /* Information about each single-predicate or single-vector type. */
94 static CONSTEXPR
const vector_type_info vector_types
[] = {
95 #define DEF_MVE_TYPE(ACLE_NAME, SCALAR_TYPE) \
96 { #ACLE_NAME, REQUIRES_FLOAT },
97 #include "arm-mve-builtins.def"
100 /* The function name suffix associated with each predication type. */
101 static const char *const pred_suffixes
[NUM_PREDS
+ 1] = {
110 /* Static information about each mode_suffix_index. */
111 CONSTEXPR
const mode_suffix_info mode_suffixes
[] = {
112 #define VECTOR_TYPE_none NUM_VECTOR_TYPES
113 #define DEF_MVE_MODE(NAME, BASE, DISPLACEMENT, UNITS) \
114 { "_" #NAME, VECTOR_TYPE_##BASE, VECTOR_TYPE_##DISPLACEMENT, UNITS_##UNITS },
115 #include "arm-mve-builtins.def"
116 #undef VECTOR_TYPE_none
117 { "", NUM_VECTOR_TYPES
, NUM_VECTOR_TYPES
, UNITS_none
}
120 /* Static information about each type_suffix_index. */
121 CONSTEXPR
const type_suffix_info type_suffixes
[NUM_TYPE_SUFFIXES
+ 1] = {
122 #define DEF_MVE_TYPE_SUFFIX(NAME, ACLE_TYPE, CLASS, BITS, MODE) \
124 VECTOR_TYPE_##ACLE_TYPE, \
127 BITS / BITS_PER_UNIT, \
128 TYPE_##CLASS == TYPE_signed || TYPE_##CLASS == TYPE_unsigned, \
129 TYPE_##CLASS == TYPE_unsigned, \
130 TYPE_##CLASS == TYPE_float, \
133 #include "arm-mve-builtins.def"
134 { "", NUM_VECTOR_TYPES
, TYPE_bool
, 0, 0, false, false, false,
138 /* Define a TYPES_<combination> macro for each combination of type
139 suffixes that an ACLE function can have, where <combination> is the
140 name used in DEF_MVE_FUNCTION entries.
142 Use S (T) for single type suffix T and D (T1, T2) for a pair of type
143 suffixes T1 and T2. Use commas to separate the suffixes.
145 Although the order shouldn't matter, the convention is to sort the
146 suffixes lexicographically after dividing suffixes into a type
147 class ("b", "f", etc.) and a numerical bit count. */
150 #define TYPES_float16(S, D) \
154 #define TYPES_all_float(S, D) \
158 #define TYPES_integer_8(S, D) \
163 #define TYPES_integer_8_16(S, D) \
164 S (s8), S (s16), S (u8), S(u16)
168 #define TYPES_integer_16_32(S, D) \
173 #define TYPES_signed_16_32(S, D) \
177 #define TYPES_all_signed(S, D) \
178 S (s8), S (s16), S (s32)
181 #define TYPES_all_unsigned(S, D) \
182 S (u8), S (u16), S (u32)
186 #define TYPES_all_integer(S, D) \
187 TYPES_all_signed (S, D), TYPES_all_unsigned (S, D)
189 /* _s8 _s16 _s32 _s64
190 _u8 _u16 _u32 _u64. */
191 #define TYPES_all_integer_with_64(S, D) \
192 TYPES_all_signed (S, D), S (s64), TYPES_all_unsigned (S, D), S (u64)
195 #define TYPES_integer_32(S, D) \
199 #define TYPES_signed_32(S, D) \
202 #define TYPES_reinterpret_signed1(D, A) \
203 D (A, s8), D (A, s16), D (A, s32), D (A, s64)
205 #define TYPES_reinterpret_unsigned1(D, A) \
206 D (A, u8), D (A, u16), D (A, u32), D (A, u64)
208 #define TYPES_reinterpret_integer(S, D) \
209 TYPES_reinterpret_unsigned1 (D, s8), \
210 D (s8, s16), D (s8, s32), D (s8, s64), \
211 TYPES_reinterpret_unsigned1 (D, s16), \
212 D (s16, s8), D (s16, s32), D (s16, s64), \
213 TYPES_reinterpret_unsigned1 (D, s32), \
214 D (s32, s8), D (s32, s16), D (s32, s64), \
215 TYPES_reinterpret_unsigned1 (D, s64), \
216 D (s64, s8), D (s64, s16), D (s64, s32), \
217 TYPES_reinterpret_signed1 (D, u8), \
218 D (u8, u16), D (u8, u32), D (u8, u64), \
219 TYPES_reinterpret_signed1 (D, u16), \
220 D (u16, u8), D (u16, u32), D (u16, u64), \
221 TYPES_reinterpret_signed1 (D, u32), \
222 D (u32, u8), D (u32, u16), D (u32, u64), \
223 TYPES_reinterpret_signed1 (D, u64), \
224 D (u64, u8), D (u64, u16), D (u64, u32)
226 /* { _s8 _s16 _s32 _s64 } x { _s8 _s16 _s32 _s64 }
227 { _u8 _u16 _u32 _u64 } { _u8 _u16 _u32 _u64 }. */
228 #define TYPES_reinterpret_integer1(D, A) \
229 TYPES_reinterpret_signed1 (D, A), \
230 TYPES_reinterpret_unsigned1 (D, A)
232 #define TYPES_reinterpret_float1(D, A) \
233 D (A, f16), D (A, f32)
235 #define TYPES_reinterpret_float(S, D) \
236 TYPES_reinterpret_float1 (D, s8), \
237 TYPES_reinterpret_float1 (D, s16), \
238 TYPES_reinterpret_float1 (D, s32), \
239 TYPES_reinterpret_float1 (D, s64), \
240 TYPES_reinterpret_float1 (D, u8), \
241 TYPES_reinterpret_float1 (D, u16), \
242 TYPES_reinterpret_float1 (D, u32), \
243 TYPES_reinterpret_float1 (D, u64), \
244 TYPES_reinterpret_integer1 (D, f16), \
245 TYPES_reinterpret_integer1 (D, f32), \
246 D (f16, f32), D (f32, f16)
248 /* Describe a pair of type suffixes in which only the first is used. */
249 #define DEF_VECTOR_TYPE(X) { TYPE_SUFFIX_ ## X, NUM_TYPE_SUFFIXES }
251 /* Describe a pair of type suffixes in which both are used. */
252 #define DEF_DOUBLE_TYPE(X, Y) { TYPE_SUFFIX_ ## X, TYPE_SUFFIX_ ## Y }
254 /* Create an array that can be used in arm-mve-builtins.def to
255 select the type suffixes in TYPES_<NAME>. */
256 #define DEF_MVE_TYPES_ARRAY(NAME) \
257 static const type_suffix_pair types_##NAME[] = { \
258 TYPES_##NAME (DEF_VECTOR_TYPE, DEF_DOUBLE_TYPE), \
259 { NUM_TYPE_SUFFIXES, NUM_TYPE_SUFFIXES } \
262 /* For functions that don't take any type suffixes. */
263 static const type_suffix_pair types_none
[] = {
264 { NUM_TYPE_SUFFIXES
, NUM_TYPE_SUFFIXES
},
265 { NUM_TYPE_SUFFIXES
, NUM_TYPE_SUFFIXES
}
268 DEF_MVE_TYPES_ARRAY (all_integer
);
269 DEF_MVE_TYPES_ARRAY (all_integer_with_64
);
270 DEF_MVE_TYPES_ARRAY (float16
);
271 DEF_MVE_TYPES_ARRAY (all_float
);
272 DEF_MVE_TYPES_ARRAY (all_signed
);
273 DEF_MVE_TYPES_ARRAY (all_unsigned
);
274 DEF_MVE_TYPES_ARRAY (integer_8
);
275 DEF_MVE_TYPES_ARRAY (integer_8_16
);
276 DEF_MVE_TYPES_ARRAY (integer_16_32
);
277 DEF_MVE_TYPES_ARRAY (integer_32
);
278 DEF_MVE_TYPES_ARRAY (signed_16_32
);
279 DEF_MVE_TYPES_ARRAY (signed_32
);
280 DEF_MVE_TYPES_ARRAY (reinterpret_integer
);
281 DEF_MVE_TYPES_ARRAY (reinterpret_float
);
283 /* Used by functions that have no governing predicate. */
284 static const predication_index preds_none
[] = { PRED_none
, NUM_PREDS
};
286 /* Used by functions that have the m (merging) predicated form, and in
287 addition have an unpredicated form. */
288 const predication_index preds_m_or_none
[] = {
289 PRED_m
, PRED_none
, NUM_PREDS
292 /* Used by functions that have the mx (merging and "don't care"
293 predicated forms, and in addition have an unpredicated form. */
294 static const predication_index preds_mx_or_none
[] = {
295 PRED_m
, PRED_x
, PRED_none
, NUM_PREDS
298 /* Used by functions that have the p predicated form, in addition to
299 an unpredicated form. */
300 static const predication_index preds_p_or_none
[] = {
301 PRED_p
, PRED_none
, NUM_PREDS
304 /* A list of all MVE ACLE functions. */
305 static CONSTEXPR
const function_group_info function_groups
[] = {
306 #define DEF_MVE_FUNCTION(NAME, SHAPE, TYPES, PREDS) \
307 { #NAME, &functions::NAME, &shapes::SHAPE, types_##TYPES, preds_##PREDS, \
309 #include "arm-mve-builtins.def"
312 /* The scalar type associated with each vector type. */
313 extern GTY(()) tree scalar_types
[NUM_VECTOR_TYPES
];
314 tree scalar_types
[NUM_VECTOR_TYPES
];
316 /* The single-predicate and single-vector types, with their built-in
317 "__simd128_..._t" name. Allow an index of NUM_VECTOR_TYPES, which always
318 yields a null tree. */
319 static GTY(()) tree abi_vector_types
[NUM_VECTOR_TYPES
+ 1];
321 /* Same, but with the arm_mve.h names. */
322 extern GTY(()) tree acle_vector_types
[MAX_TUPLE_SIZE
][NUM_VECTOR_TYPES
+ 1];
323 tree acle_vector_types
[MAX_TUPLE_SIZE
][NUM_VECTOR_TYPES
+ 1];
325 /* The list of all registered function decls, indexed by code. */
326 static GTY(()) vec
<registered_function
*, va_gc
> *registered_functions
;
328 /* All registered function decls, hashed on the function_instance
329 that they implement. This is used for looking up implementations of
330 overloaded functions. */
331 static hash_table
<registered_function_hasher
> *function_table
;
333 /* True if we've already complained about attempts to use functions
334 when the required extension is disabled. */
335 static bool reported_missing_float_p
;
337 /* Return the MVE abi type with element of type TYPE. */
339 arm_mve_type_for_scalar_type (tree eltype
)
341 for (unsigned int i
= 0; i
< __TYPE_FINAL
; ++i
)
342 if (arm_simd_types
[i
].eltype
== eltype
343 && GET_MODE_SIZE (arm_simd_types
[i
].mode
) == 16)
344 return arm_simd_types
[i
].itype
;
349 /* Register the built-in MVE ABI vector types, such as uint32x4_t. */
351 register_builtin_types ()
353 #define DEF_MVE_TYPE(ACLE_NAME, SCALAR_TYPE) \
354 scalar_types[VECTOR_TYPE_ ## ACLE_NAME] = SCALAR_TYPE;
355 #include "arm-mve-builtins.def"
356 for (unsigned int i
= 0; i
< NUM_VECTOR_TYPES
; ++i
)
358 if (vector_types
[i
].requires_float
&& !TARGET_HAVE_MVE_FLOAT
)
360 tree eltype
= scalar_types
[i
];
362 if (eltype
== boolean_type_node
)
364 vectype
= get_typenode_from_name (UINT16_TYPE
);
365 gcc_assert (GET_MODE_SIZE (TYPE_MODE (vectype
)) == 2);
369 vectype
= arm_mve_type_for_scalar_type (eltype
);
370 gcc_assert (VECTOR_MODE_P (TYPE_MODE (vectype
))
371 && GET_MODE_SIZE (TYPE_MODE (vectype
)) == 16);
373 abi_vector_types
[i
] = vectype
;
377 /* Register vector type TYPE under its arm_mve.h name. */
379 register_vector_type (vector_type_index type
)
382 /* If the target does not have the mve.fp extension, but the type requires
383 it, then it needs to be assigned a non-dummy type so that functions
384 with those types in their signature can be registered. This allows for
385 diagnostics about the missing extension, rather than about a missing
386 function definition. */
387 if (vector_types
[type
].requires_float
&& !TARGET_HAVE_MVE_FLOAT
)
389 acle_vector_types
[0][type
] = void_type_node
;
393 tree vectype
= abi_vector_types
[type
];
394 tree id
= get_identifier (vector_types
[type
].acle_name
);
395 tree decl
= build_decl (input_location
, TYPE_DECL
, id
, vectype
);
396 decl
= lang_hooks
.decls
.pushdecl (decl
);
398 /* Record the new ACLE type if pushdecl succeeded without error. Use
399 the ABI type otherwise, so that the type we record at least has the
400 right form, even if it doesn't have the right name. This should give
401 better error recovery behavior than installing error_mark_node or
402 installing an incorrect type. */
404 && TREE_CODE (decl
) == TYPE_DECL
405 && TREE_TYPE (decl
) != error_mark_node
406 && TYPE_MAIN_VARIANT (TREE_TYPE (decl
)) == vectype
)
407 vectype
= TREE_TYPE (decl
);
408 acle_vector_types
[0][type
] = vectype
;
411 /* Register tuple types of element type TYPE under their arm_mve_types.h
414 register_builtin_tuple_types (vector_type_index type
)
416 const vector_type_info
* info
= &vector_types
[type
];
418 /* If the target does not have the mve.fp extension, but the type requires
419 it, then it needs to be assigned a non-dummy type so that functions
420 with those types in their signature can be registered. This allows for
421 diagnostics about the missing extension, rather than about a missing
422 function definition. */
423 if (scalar_types
[type
] == boolean_type_node
424 || (info
->requires_float
&& !TARGET_HAVE_MVE_FLOAT
))
426 for (unsigned int num_vectors
= 2; num_vectors
<= 4; num_vectors
+= 2)
427 acle_vector_types
[num_vectors
>> 1][type
] = void_type_node
;
431 const char *vector_type_name
= info
->acle_name
;
432 char buffer
[sizeof ("float32x4x2_t")];
433 for (unsigned int num_vectors
= 2; num_vectors
<= 4; num_vectors
+= 2)
435 snprintf (buffer
, sizeof (buffer
), "%.*sx%d_t",
436 (int) strlen (vector_type_name
) - 2, vector_type_name
,
439 tree vectype
= acle_vector_types
[0][type
];
440 tree arrtype
= build_array_type_nelts (vectype
, num_vectors
);
441 gcc_assert (TYPE_MODE_RAW (arrtype
) == TYPE_MODE (arrtype
));
442 tree field
= build_decl (input_location
, FIELD_DECL
,
443 get_identifier ("val"), arrtype
);
445 tree t
= lang_hooks
.types
.simulate_record_decl (input_location
, buffer
,
446 make_array_slice (&field
,
448 gcc_assert (TYPE_MODE_RAW (t
) == TYPE_MODE (t
));
449 acle_vector_types
[num_vectors
>> 1][type
] = TREE_TYPE (t
);
453 /* Implement #pragma GCC arm "arm_mve_types.h". */
455 handle_arm_mve_types_h ()
457 if (handle_arm_mve_types_p
)
459 error ("duplicate definition of %qs", "arm_mve_types.h");
462 handle_arm_mve_types_p
= true;
463 if (!TARGET_HAVE_MVE
)
465 error ("this definition requires the MVE ISA extension");
468 register_builtin_types ();
469 for (unsigned int type_i
= 0; type_i
< NUM_VECTOR_TYPES
; ++type_i
)
471 vector_type_index type
= vector_type_index (type_i
);
472 register_vector_type (type
);
473 if (type_i
!= VECTOR_TYPE_mve_pred16_t
)
474 register_builtin_tuple_types (type
);
478 /* Implement #pragma GCC arm "arm_mve.h" <bool>. */
480 handle_arm_mve_h (bool preserve_user_namespace
)
484 error ("duplicate definition of %qs", "arm_mve.h");
488 /* Define MVE functions. */
489 function_table
= new hash_table
<registered_function_hasher
> (1023);
490 function_builder builder
;
491 for (unsigned int i
= 0; i
< ARRAY_SIZE (function_groups
); ++i
)
492 builder
.register_function_group (function_groups
[i
],
493 preserve_user_namespace
);
496 /* Return true if CANDIDATE is equivalent to MODEL_TYPE for overloading
499 matches_type_p (const_tree model_type
, const_tree candidate
)
501 if (VECTOR_TYPE_P (model_type
))
503 if (!VECTOR_TYPE_P (candidate
)
504 || maybe_ne (TYPE_VECTOR_SUBPARTS (model_type
),
505 TYPE_VECTOR_SUBPARTS (candidate
))
506 || TYPE_MODE (model_type
) != TYPE_MODE (candidate
))
509 model_type
= TREE_TYPE (model_type
);
510 candidate
= TREE_TYPE (candidate
);
512 return (candidate
!= error_mark_node
513 && TYPE_MAIN_VARIANT (model_type
) == TYPE_MAIN_VARIANT (candidate
));
516 /* Report an error against LOCATION that the user has tried to use
517 a floating point function when the mve.fp extension is disabled. */
519 report_missing_float (location_t location
, tree fndecl
)
521 /* Avoid reporting a slew of messages for a single oversight. */
522 if (reported_missing_float_p
)
525 error_at (location
, "ACLE function %qD requires ISA extension %qs",
527 inform (location
, "you can enable mve.fp by using the command-line"
528 " option %<-march%>, or by using the %<target%>"
529 " attribute or pragma");
530 reported_missing_float_p
= true;
533 /* Report that LOCATION has a call to FNDECL in which argument ARGNO
534 was not an integer constant expression. ARGNO counts from zero. */
536 report_non_ice (location_t location
, tree fndecl
, unsigned int argno
)
538 error_at (location
, "argument %d of %qE must be an integer constant"
539 " expression", argno
+ 1, fndecl
);
542 /* Report that LOCATION has a call to FNDECL in which argument ARGNO has
543 the value ACTUAL, whereas the function requires a value in the range
544 [MIN, MAX]. ARGNO counts from zero. */
546 report_out_of_range (location_t location
, tree fndecl
, unsigned int argno
,
547 HOST_WIDE_INT actual
, HOST_WIDE_INT min
,
550 error_at (location
, "passing %wd to argument %d of %qE, which expects"
551 " a value in the range [%wd, %wd]", actual
, argno
+ 1, fndecl
,
555 /* Report that LOCATION has a call to FNDECL in which argument ARGNO has
556 the value ACTUAL, whereas the function requires a valid value of
557 enum type ENUMTYPE. ARGNO counts from zero. */
559 report_not_enum (location_t location
, tree fndecl
, unsigned int argno
,
560 HOST_WIDE_INT actual
, tree enumtype
)
562 error_at (location
, "passing %wd to argument %d of %qE, which expects"
563 " a valid %qT value", actual
, argno
+ 1, fndecl
, enumtype
);
566 /* Checks that the mve.fp extension is enabled, given that REQUIRES_FLOAT
567 indicates whether it is required or not for function FNDECL.
568 Report an error against LOCATION if not. */
570 check_requires_float (location_t location
, tree fndecl
,
573 if (requires_float
&& !TARGET_HAVE_MVE_FLOAT
)
575 report_missing_float (location
, fndecl
);
582 /* Return a hash code for a function_instance. */
584 function_instance::hash () const
587 /* BASE uniquely determines BASE_NAME, so we don't need to hash both. */
590 h
.add_int (mode_suffix_id
);
591 h
.add_int (type_suffix_ids
[0]);
592 h
.add_int (type_suffix_ids
[1]);
597 /* Return a set of CP_* flags that describe what the function could do,
598 taking the command-line flags into account. */
600 function_instance::call_properties () const
602 unsigned int flags
= base
->call_properties (*this);
604 /* -fno-trapping-math means that we can assume any FP exceptions
605 are not user-visible. */
606 if (!flag_trapping_math
)
607 flags
&= ~CP_RAISE_FP_EXCEPTIONS
;
612 /* Return true if calls to the function could read some form of
615 function_instance::reads_global_state_p () const
617 unsigned int flags
= call_properties ();
619 /* Preserve any dependence on rounding mode, flush to zero mode, etc.
620 There is currently no way of turning this off; in particular,
621 -fno-rounding-math (which is the default) means that we should make
622 the usual assumptions about rounding mode, which for intrinsics means
623 acting as the instructions do. */
624 if (flags
& CP_READ_FPCR
)
630 /* Return true if calls to the function could modify some form of
633 function_instance::modifies_global_state_p () const
635 unsigned int flags
= call_properties ();
637 /* Preserve any exception state written back to the FPCR,
638 unless -fno-trapping-math says this is unnecessary. */
639 if (flags
& CP_RAISE_FP_EXCEPTIONS
)
642 /* Handle direct modifications of global state. */
643 return flags
& CP_WRITE_MEMORY
;
646 /* Return true if calls to the function could raise a signal. */
648 function_instance::could_trap_p () const
650 unsigned int flags
= call_properties ();
652 /* Handle functions that could raise SIGFPE. */
653 if (flags
& CP_RAISE_FP_EXCEPTIONS
)
656 /* Handle functions that could raise SIGBUS or SIGSEGV. */
657 if (flags
& (CP_READ_MEMORY
| CP_WRITE_MEMORY
))
663 /* Return true if the function has an implicit "inactive" argument.
664 This is the case of most _m predicated functions, but not all.
665 The list will be updated as needed. */
667 function_instance::has_inactive_argument () const
672 if (mode_suffix_id
== MODE_r
673 || (base
== functions::vorrq
&& mode_suffix_id
== MODE_n
)
674 || (base
== functions::vqrshlq
&& mode_suffix_id
== MODE_n
)
675 || base
== functions::vqrshrnbq
676 || base
== functions::vqrshrntq
677 || base
== functions::vqrshrunbq
678 || base
== functions::vqrshruntq
679 || base
== functions::vqshrnbq
680 || base
== functions::vqshrntq
681 || base
== functions::vqshrunbq
682 || base
== functions::vqshruntq
683 || (base
== functions::vrshlq
&& mode_suffix_id
== MODE_n
)
684 || base
== functions::vrshrnbq
685 || base
== functions::vrshrntq
686 || base
== functions::vshrnbq
687 || base
== functions::vshrntq
)
694 registered_function_hasher::hash (value_type value
)
696 return value
->instance
.hash ();
700 registered_function_hasher::equal (value_type value
, const compare_type
&key
)
702 return value
->instance
== key
;
705 function_builder::function_builder ()
707 m_overload_type
= build_function_type (void_type_node
, void_list_node
);
708 m_direct_overloads
= lang_GNU_CXX ();
709 gcc_obstack_init (&m_string_obstack
);
712 function_builder::~function_builder ()
714 obstack_free (&m_string_obstack
, NULL
);
717 /* Add NAME to the end of the function name being built. */
719 function_builder::append_name (const char *name
)
721 obstack_grow (&m_string_obstack
, name
, strlen (name
));
724 /* Zero-terminate and complete the function name being built. */
726 function_builder::finish_name ()
728 obstack_1grow (&m_string_obstack
, 0);
729 return (char *) obstack_finish (&m_string_obstack
);
732 /* Return the overloaded or full function name for INSTANCE, with optional
733 prefix; PRESERVE_USER_NAMESPACE selects the prefix, and OVERLOADED_P
734 selects which the overloaded or full function name. Allocate the string on
735 m_string_obstack; the caller must use obstack_free to free it after use. */
737 function_builder::get_name (const function_instance
&instance
,
738 bool preserve_user_namespace
,
741 if (preserve_user_namespace
)
742 append_name ("__arm_");
743 append_name (instance
.base_name
);
744 append_name (pred_suffixes
[instance
.pred
]);
746 || instance
.shape
->explicit_mode_suffix_p (instance
.pred
,
747 instance
.mode_suffix_id
))
748 append_name (instance
.mode_suffix ().string
);
749 for (unsigned int i
= 0; i
< 2; ++i
)
751 || instance
.shape
->explicit_type_suffix_p (i
, instance
.pred
,
752 instance
.mode_suffix_id
))
753 append_name (instance
.type_suffix (i
).string
);
754 return finish_name ();
757 /* Add attribute NAME to ATTRS. */
759 add_attribute (const char *name
, tree attrs
)
761 return tree_cons (get_identifier (name
), NULL_TREE
, attrs
);
764 /* Return the appropriate function attributes for INSTANCE. */
766 function_builder::get_attributes (const function_instance
&instance
)
768 tree attrs
= NULL_TREE
;
770 if (!instance
.modifies_global_state_p ())
772 if (instance
.reads_global_state_p ())
773 attrs
= add_attribute ("pure", attrs
);
775 attrs
= add_attribute ("const", attrs
);
778 if (!flag_non_call_exceptions
|| !instance
.could_trap_p ())
779 attrs
= add_attribute ("nothrow", attrs
);
781 return add_attribute ("leaf", attrs
);
784 /* Add a function called NAME with type FNTYPE and attributes ATTRS.
785 INSTANCE describes what the function does and OVERLOADED_P indicates
786 whether it is overloaded. REQUIRES_FLOAT indicates whether the function
787 requires the mve.fp extension. */
788 registered_function
&
789 function_builder::add_function (const function_instance
&instance
,
790 const char *name
, tree fntype
, tree attrs
,
795 unsigned int code
= vec_safe_length (registered_functions
);
796 code
= (code
<< ARM_BUILTIN_SHIFT
) | ARM_BUILTIN_MVE
;
798 /* We need to be able to generate placeholders to ensure that we have a
799 consistent numbering scheme for function codes between the C and C++
800 frontends, so that everything ties up in LTO.
802 Currently, tree-streamer-in.cc:unpack_ts_function_decl_value_fields
803 validates that tree nodes returned by TARGET_BUILTIN_DECL are non-NULL and
804 some node other than error_mark_node. This is a holdover from when builtin
805 decls were streamed by code rather than by value.
807 Ultimately, we should be able to remove this validation of BUILT_IN_MD
808 nodes and remove the target hook. For now, however, we need to appease the
809 validation and return a non-NULL, non-error_mark_node node, so we
810 arbitrarily choose integer_zero_node. */
811 tree decl
= placeholder_p
813 : simulate_builtin_function_decl (input_location
, name
, fntype
,
816 registered_function
&rfn
= *ggc_alloc
<registered_function
> ();
817 rfn
.instance
= instance
;
819 rfn
.requires_float
= requires_float
;
820 rfn
.overloaded_p
= overloaded_p
;
821 vec_safe_push (registered_functions
, &rfn
);
826 /* Add a built-in function for INSTANCE, with the argument types given
827 by ARGUMENT_TYPES and the return type given by RETURN_TYPE.
828 REQUIRES_FLOAT indicates whether the function requires the mve.fp extension,
829 and PRESERVE_USER_NAMESPACE indicates whether the function should also be
830 registered under its non-prefixed name. */
832 function_builder::add_unique_function (const function_instance
&instance
,
834 vec
<tree
> &argument_types
,
835 bool preserve_user_namespace
,
837 bool force_direct_overloads
)
839 /* Add the function under its full (unique) name with prefix. */
840 char *name
= get_name (instance
, true, false);
841 tree fntype
= build_function_type_array (return_type
,
842 argument_types
.length (),
843 argument_types
.address ());
844 tree attrs
= get_attributes (instance
);
845 registered_function
&rfn
= add_function (instance
, name
, fntype
, attrs
,
846 requires_float
, false, false);
848 /* Enter the function into the hash table. */
849 hashval_t hash
= instance
.hash ();
850 registered_function
**rfn_slot
851 = function_table
->find_slot_with_hash (instance
, hash
, INSERT
);
852 gcc_assert (!*rfn_slot
);
855 /* Also add the non-prefixed non-overloaded function, if the user namespace
856 does not need to be preserved. */
857 if (!preserve_user_namespace
)
859 char *noprefix_name
= get_name (instance
, false, false);
860 tree attrs
= get_attributes (instance
);
861 add_function (instance
, noprefix_name
, fntype
, attrs
, requires_float
,
865 /* Also add the function under its overloaded alias, if we want
866 a separate decl for each instance of an overloaded function. */
867 char *overload_name
= get_name (instance
, true, true);
868 if (strcmp (name
, overload_name
) != 0)
870 /* Attribute lists shouldn't be shared. */
871 tree attrs
= get_attributes (instance
);
872 bool placeholder_p
= !(m_direct_overloads
|| force_direct_overloads
);
873 add_function (instance
, overload_name
, fntype
, attrs
,
874 requires_float
, false, placeholder_p
);
876 /* Also add the non-prefixed overloaded function, if the user namespace
877 does not need to be preserved. */
878 if (!preserve_user_namespace
)
880 char *noprefix_overload_name
= get_name (instance
, false, true);
881 tree attrs
= get_attributes (instance
);
882 add_function (instance
, noprefix_overload_name
, fntype
, attrs
,
883 requires_float
, false, placeholder_p
);
887 obstack_free (&m_string_obstack
, name
);
890 /* Add one function decl for INSTANCE, to be used with manual overload
891 resolution. REQUIRES_FLOAT indicates whether the function requires the
894 For simplicity, partition functions by instance and required extensions,
895 and check whether the required extensions are available as part of resolving
896 the function to the relevant unique function. */
898 function_builder::add_overloaded_function (const function_instance
&instance
,
899 bool preserve_user_namespace
,
902 char *name
= get_name (instance
, true, true);
903 if (registered_function
**map_value
= m_overload_names
.get (name
))
905 gcc_assert ((*map_value
)->instance
== instance
);
906 obstack_free (&m_string_obstack
, name
);
910 registered_function
&rfn
911 = add_function (instance
, name
, m_overload_type
, NULL_TREE
,
912 requires_float
, true, m_direct_overloads
);
913 m_overload_names
.put (name
, &rfn
);
914 if (!preserve_user_namespace
)
916 char *noprefix_name
= get_name (instance
, false, true);
917 registered_function
&noprefix_rfn
918 = add_function (instance
, noprefix_name
, m_overload_type
,
919 NULL_TREE
, requires_float
, true,
921 m_overload_names
.put (noprefix_name
, &noprefix_rfn
);
926 /* If we are using manual overload resolution, add one function decl
927 for each overloaded function in GROUP. Take the function base name
928 from GROUP and the mode from MODE. */
930 function_builder::add_overloaded_functions (const function_group_info
&group
,
931 mode_suffix_index mode
,
932 bool preserve_user_namespace
)
934 for (unsigned int pi
= 0; group
.preds
[pi
] != NUM_PREDS
; ++pi
)
936 unsigned int explicit_type0
937 = (*group
.shape
)->explicit_type_suffix_p (0, group
.preds
[pi
], mode
);
938 unsigned int explicit_type1
939 = (*group
.shape
)->explicit_type_suffix_p (1, group
.preds
[pi
], mode
);
941 if ((*group
.shape
)->skip_overload_p (group
.preds
[pi
], mode
))
944 if (!explicit_type0
&& !explicit_type1
)
946 /* Deal with the common case in which there is one overloaded
947 function for all type combinations. */
948 function_instance
instance (group
.base_name
, *group
.base
,
949 *group
.shape
, mode
, types_none
[0],
951 add_overloaded_function (instance
, preserve_user_namespace
,
952 group
.requires_float
);
955 for (unsigned int ti
= 0; group
.types
[ti
][0] != NUM_TYPE_SUFFIXES
;
958 /* Stub out the types that are determined by overload
960 type_suffix_pair types
= {
961 explicit_type0
? group
.types
[ti
][0] : NUM_TYPE_SUFFIXES
,
962 explicit_type1
? group
.types
[ti
][1] : NUM_TYPE_SUFFIXES
964 function_instance
instance (group
.base_name
, *group
.base
,
965 *group
.shape
, mode
, types
,
967 add_overloaded_function (instance
, preserve_user_namespace
,
968 group
.requires_float
);
973 /* Register all the functions in GROUP. */
975 function_builder::register_function_group (const function_group_info
&group
,
976 bool preserve_user_namespace
)
978 (*group
.shape
)->build (*this, group
, preserve_user_namespace
);
981 function_call_info::function_call_info (location_t location_in
,
982 const function_instance
&instance_in
,
984 : function_instance (instance_in
), location (location_in
), fndecl (fndecl_in
)
988 function_resolver::function_resolver (location_t location
,
989 const function_instance
&instance
,
990 tree fndecl
, vec
<tree
, va_gc
> &arglist
)
991 : function_call_info (location
, instance
, fndecl
), m_arglist (arglist
)
995 /* Return the vector type associated with type suffix TYPE. */
997 function_resolver::get_vector_type (type_suffix_index type
)
999 return acle_vector_types
[0][type_suffixes
[type
].vector_type
];
1002 /* Return the <stdint.h> name associated with TYPE. Using the <stdint.h>
1003 name should be more user-friendly than the underlying canonical type,
1004 since it makes the signedness and bitwidth explicit. */
1006 function_resolver::get_scalar_type_name (type_suffix_index type
)
1008 return vector_types
[type_suffixes
[type
].vector_type
].acle_name
+ 2;
1011 /* Return the type of argument I, or error_mark_node if it isn't
1014 function_resolver::get_argument_type (unsigned int i
)
1016 tree arg
= m_arglist
[i
];
1017 return arg
== error_mark_node
? arg
: TREE_TYPE (arg
);
1020 /* Return true if argument I is some form of scalar value. */
1022 function_resolver::scalar_argument_p (unsigned int i
)
1024 tree type
= get_argument_type (i
);
1025 return (INTEGRAL_TYPE_P (type
)
1026 /* Allow pointer types, leaving the frontend to warn where
1028 || POINTER_TYPE_P (type
)
1029 || SCALAR_FLOAT_TYPE_P (type
));
1032 /* Report that the function has no form that takes type suffix TYPE.
1033 Return error_mark_node. */
1035 function_resolver::report_no_such_form (type_suffix_index type
)
1037 error_at (location
, "%qE has no form that takes %qT arguments",
1038 fndecl
, get_vector_type (type
));
1039 return error_mark_node
;
1042 /* Silently check whether there is an instance of the function with the
1043 mode suffix given by MODE and the type suffixes given by TYPE0 and TYPE1.
1044 Return its function decl if so, otherwise return null. */
1046 function_resolver::lookup_form (mode_suffix_index mode
,
1047 type_suffix_index type0
,
1048 type_suffix_index type1
)
1050 type_suffix_pair types
= { type0
, type1
};
1051 function_instance
instance (base_name
, base
, shape
, mode
, types
, pred
);
1052 registered_function
*rfn
1053 = function_table
->find_with_hash (instance
, instance
.hash ());
1054 return rfn
? rfn
->decl
: NULL_TREE
;
1057 /* Resolve the function to one with the mode suffix given by MODE and the
1058 type suffixes given by TYPE0 and TYPE1. Return its function decl on
1059 success, otherwise report an error and return error_mark_node. */
1061 function_resolver::resolve_to (mode_suffix_index mode
,
1062 type_suffix_index type0
,
1063 type_suffix_index type1
)
1065 tree res
= lookup_form (mode
, type0
, type1
);
1068 if (type1
== NUM_TYPE_SUFFIXES
)
1069 return report_no_such_form (type0
);
1070 if (type0
== type_suffix_ids
[0])
1071 return report_no_such_form (type1
);
1072 /* To be filled in when we have other cases. */
1078 /* Require argument ARGNO to be a single vector or a tuple of NUM_VECTORS
1079 vectors; NUM_VECTORS is 1 for the former. Return the associated type
1080 suffix on success, using TYPE_SUFFIX_b for predicates. Report an error
1081 and return NUM_TYPE_SUFFIXES on failure. */
1083 function_resolver::infer_vector_or_tuple_type (unsigned int argno
,
1084 unsigned int num_vectors
)
1086 tree actual
= get_argument_type (argno
);
1087 if (actual
== error_mark_node
)
1088 return NUM_TYPE_SUFFIXES
;
1090 /* A linear search should be OK here, since the code isn't hot and
1091 the number of types is only small. */
1092 for (unsigned int size_i
= 0; size_i
< MAX_TUPLE_SIZE
; ++size_i
)
1093 for (unsigned int suffix_i
= 0; suffix_i
< NUM_TYPE_SUFFIXES
; ++suffix_i
)
1095 vector_type_index type_i
= type_suffixes
[suffix_i
].vector_type
;
1096 tree type
= acle_vector_types
[size_i
][type_i
];
1097 if (type
&& matches_type_p (type
, actual
))
1099 if (size_i
+ 1 == num_vectors
)
1100 return type_suffix_index (suffix_i
);
1102 if (num_vectors
== 1)
1103 error_at (location
, "passing %qT to argument %d of %qE, which"
1104 " expects a single MVE vector rather than a tuple",
1105 actual
, argno
+ 1, fndecl
);
1106 else if (size_i
== 0 && type_i
!= VECTOR_TYPE_mve_pred16_t
)
1107 /* num_vectors is always != 1, so the singular isn't needed. */
1108 error_n (location
, num_vectors
, "%qT%d%qE%d",
1109 "passing single vector %qT to argument %d"
1110 " of %qE, which expects a tuple of %d vectors",
1111 actual
, argno
+ 1, fndecl
, num_vectors
);
1113 /* num_vectors is always != 1, so the singular isn't needed. */
1114 error_n (location
, num_vectors
, "%qT%d%qE%d",
1115 "passing %qT to argument %d of %qE, which"
1116 " expects a tuple of %d vectors", actual
, argno
+ 1,
1117 fndecl
, num_vectors
);
1118 return NUM_TYPE_SUFFIXES
;
1122 if (num_vectors
== 1)
1123 error_at (location
, "passing %qT to argument %d of %qE, which"
1124 " expects an MVE vector type", actual
, argno
+ 1, fndecl
);
1126 error_at (location
, "passing %qT to argument %d of %qE, which"
1127 " expects an MVE tuple type", actual
, argno
+ 1, fndecl
);
1128 return NUM_TYPE_SUFFIXES
;
1131 /* Require argument ARGNO to have some form of vector type. Return the
1132 associated type suffix on success, using TYPE_SUFFIX_b for predicates.
1133 Report an error and return NUM_TYPE_SUFFIXES on failure. */
1135 function_resolver::infer_vector_type (unsigned int argno
)
1137 return infer_vector_or_tuple_type (argno
, 1);
1140 /* Require argument ARGNO to be a vector or scalar argument. Return true
1141 if it is, otherwise report an appropriate error. */
1143 function_resolver::require_vector_or_scalar_type (unsigned int argno
)
1145 tree actual
= get_argument_type (argno
);
1146 if (actual
== error_mark_node
)
1149 if (!scalar_argument_p (argno
) && !VECTOR_TYPE_P (actual
))
1151 error_at (location
, "passing %qT to argument %d of %qE, which"
1152 " expects a vector or scalar type", actual
, argno
+ 1, fndecl
);
1159 /* Require argument ARGNO to have vector type TYPE, in cases where this
1160 requirement holds for all uses of the function. Return true if the
1161 argument has the right form, otherwise report an appropriate error. */
1163 function_resolver::require_vector_type (unsigned int argno
,
1164 vector_type_index type
)
1166 tree expected
= acle_vector_types
[0][type
];
1167 tree actual
= get_argument_type (argno
);
1168 if (actual
== error_mark_node
)
1171 if (!matches_type_p (expected
, actual
))
1173 error_at (location
, "passing %qT to argument %d of %qE, which"
1174 " expects %qT", actual
, argno
+ 1, fndecl
, expected
);
1180 /* Like require_vector_type, but TYPE is inferred from previous arguments
1181 rather than being a fixed part of the function signature. This changes
1182 the nature of the error messages. */
1184 function_resolver::require_matching_vector_type (unsigned int argno
,
1185 type_suffix_index type
)
1187 type_suffix_index new_type
= infer_vector_type (argno
);
1188 if (new_type
== NUM_TYPE_SUFFIXES
)
1191 if (type
!= new_type
)
1193 error_at (location
, "passing %qT to argument %d of %qE, but"
1194 " previous arguments had type %qT",
1195 get_vector_type (new_type
), argno
+ 1, fndecl
,
1196 get_vector_type (type
));
1202 /* Require argument ARGNO to be a vector type with the following properties:
1204 - the type class must be the same as FIRST_TYPE's if EXPECTED_TCLASS
1205 is SAME_TYPE_CLASS, otherwise it must be EXPECTED_TCLASS itself.
1207 - the element size must be:
1209 - the same as FIRST_TYPE's if EXPECTED_BITS == SAME_SIZE
1210 - half of FIRST_TYPE's if EXPECTED_BITS == HALF_SIZE
1211 - a quarter of FIRST_TYPE's if EXPECTED_BITS == QUARTER_SIZE
1212 - EXPECTED_BITS itself otherwise
1214 Return true if the argument has the required type, otherwise report
1215 an appropriate error.
1217 FIRST_ARGNO is the first argument that is known to have type FIRST_TYPE.
1218 Usually it comes before ARGNO, but sometimes it is more natural to resolve
1219 arguments out of order.
1221 If the required properties depend on FIRST_TYPE then both FIRST_ARGNO and
1222 ARGNO contribute to the resolution process. If the required properties
1223 are fixed, only FIRST_ARGNO contributes to the resolution process.
1225 This function is a bit of a Swiss army knife. The complication comes
1226 from trying to give good error messages when FIRST_ARGNO and ARGNO are
1227 inconsistent, since either of them might be wrong. */
1228 bool function_resolver::
1229 require_derived_vector_type (unsigned int argno
,
1230 unsigned int first_argno
,
1231 type_suffix_index first_type
,
1232 type_class_index expected_tclass
,
1233 unsigned int expected_bits
)
1235 /* If the type needs to match FIRST_ARGNO exactly, use the preferred
1236 error message for that case. The VECTOR_TYPE_P test excludes tuple
1237 types, which we handle below instead. */
1238 bool both_vectors_p
= VECTOR_TYPE_P (get_argument_type (first_argno
));
1240 && expected_tclass
== SAME_TYPE_CLASS
1241 && expected_bits
== SAME_SIZE
)
1243 /* There's no need to resolve this case out of order. */
1244 gcc_assert (argno
> first_argno
);
1245 return require_matching_vector_type (argno
, first_type
);
1248 /* Use FIRST_TYPE to get the expected type class and element size. */
1249 type_class_index orig_expected_tclass
= expected_tclass
;
1250 if (expected_tclass
== NUM_TYPE_CLASSES
)
1251 expected_tclass
= type_suffixes
[first_type
].tclass
;
1253 unsigned int orig_expected_bits
= expected_bits
;
1254 if (expected_bits
== SAME_SIZE
)
1255 expected_bits
= type_suffixes
[first_type
].element_bits
;
1256 else if (expected_bits
== HALF_SIZE
)
1257 expected_bits
= type_suffixes
[first_type
].element_bits
/ 2;
1258 else if (expected_bits
== QUARTER_SIZE
)
1259 expected_bits
= type_suffixes
[first_type
].element_bits
/ 4;
1261 /* If the expected type doesn't depend on FIRST_TYPE at all,
1262 just check for the fixed choice of vector type. */
1263 if (expected_tclass
== orig_expected_tclass
1264 && expected_bits
== orig_expected_bits
)
1266 const type_suffix_info
&expected_suffix
1267 = type_suffixes
[find_type_suffix (expected_tclass
, expected_bits
)];
1268 return require_vector_type (argno
, expected_suffix
.vector_type
);
1271 /* Require the argument to be some form of MVE vector type,
1272 without being specific about the type of vector we want. */
1273 type_suffix_index actual_type
= infer_vector_type (argno
);
1274 if (actual_type
== NUM_TYPE_SUFFIXES
)
1277 /* Exit now if we got the right type. */
1278 bool tclass_ok_p
= (type_suffixes
[actual_type
].tclass
== expected_tclass
);
1279 bool size_ok_p
= (type_suffixes
[actual_type
].element_bits
== expected_bits
);
1280 if (tclass_ok_p
&& size_ok_p
)
1283 /* First look for cases in which the actual type contravenes a fixed
1284 size requirement, without having to refer to FIRST_TYPE. */
1285 if (!size_ok_p
&& expected_bits
== orig_expected_bits
)
1287 error_at (location
, "passing %qT to argument %d of %qE, which"
1288 " expects a vector of %d-bit elements",
1289 get_vector_type (actual_type
), argno
+ 1, fndecl
,
1294 /* Likewise for a fixed type class requirement. This is only ever
1295 needed for signed and unsigned types, so don't create unnecessary
1296 translation work for other type classes. */
1297 if (!tclass_ok_p
&& orig_expected_tclass
== TYPE_signed
)
1299 error_at (location
, "passing %qT to argument %d of %qE, which"
1300 " expects a vector of signed integers",
1301 get_vector_type (actual_type
), argno
+ 1, fndecl
);
1304 if (!tclass_ok_p
&& orig_expected_tclass
== TYPE_unsigned
)
1306 error_at (location
, "passing %qT to argument %d of %qE, which"
1307 " expects a vector of unsigned integers",
1308 get_vector_type (actual_type
), argno
+ 1, fndecl
);
1312 /* Make sure that FIRST_TYPE itself is sensible before using it
1313 as a basis for an error message. */
1314 if (resolve_to (mode_suffix_id
, first_type
) == error_mark_node
)
1317 /* If the arguments have consistent type classes, but a link between
1318 the sizes has been broken, try to describe the error in those terms. */
1319 if (both_vectors_p
&& tclass_ok_p
&& orig_expected_bits
== SAME_SIZE
)
1321 if (argno
< first_argno
)
1323 std::swap (argno
, first_argno
);
1324 std::swap (actual_type
, first_type
);
1326 error_at (location
, "arguments %d and %d of %qE must have the"
1327 " same element size, but the values passed here have type"
1328 " %qT and %qT respectively", first_argno
+ 1, argno
+ 1,
1329 fndecl
, get_vector_type (first_type
),
1330 get_vector_type (actual_type
));
1334 /* Likewise in reverse: look for cases in which the sizes are consistent
1335 but a link between the type classes has been broken. */
1338 && orig_expected_tclass
== SAME_TYPE_CLASS
1339 && type_suffixes
[first_type
].integer_p
1340 && type_suffixes
[actual_type
].integer_p
)
1342 if (argno
< first_argno
)
1344 std::swap (argno
, first_argno
);
1345 std::swap (actual_type
, first_type
);
1347 error_at (location
, "arguments %d and %d of %qE must have the"
1348 " same signedness, but the values passed here have type"
1349 " %qT and %qT respectively", first_argno
+ 1, argno
+ 1,
1350 fndecl
, get_vector_type (first_type
),
1351 get_vector_type (actual_type
));
1355 /* The two arguments are wildly inconsistent. */
1356 type_suffix_index expected_type
1357 = find_type_suffix (expected_tclass
, expected_bits
);
1358 error_at (location
, "passing %qT instead of the expected %qT to argument"
1359 " %d of %qE, after passing %qT to argument %d",
1360 get_vector_type (actual_type
), get_vector_type (expected_type
),
1361 argno
+ 1, fndecl
, get_argument_type (first_argno
),
1366 /* Require argument ARGNO to be a (possibly variable) scalar, expecting it
1367 to have the following properties:
1369 - the type class must be the same as for type suffix 0 if EXPECTED_TCLASS
1370 is SAME_TYPE_CLASS, otherwise it must be EXPECTED_TCLASS itself.
1372 - the element size must be the same as for type suffix 0 if EXPECTED_BITS
1373 is SAME_TYPE_SIZE, otherwise it must be EXPECTED_BITS itself.
1375 Return true if the argument is valid, otherwise report an appropriate error.
1377 Note that we don't check whether the scalar type actually has the required
1378 properties, since that's subject to implicit promotions and conversions.
1379 Instead we just use the expected properties to tune the error message. */
1380 bool function_resolver::
1381 require_derived_scalar_type (unsigned int argno
,
1382 type_class_index expected_tclass
,
1383 unsigned int expected_bits
)
1385 gcc_assert (expected_tclass
== SAME_TYPE_CLASS
1386 || expected_tclass
== TYPE_signed
1387 || expected_tclass
== TYPE_unsigned
);
1389 /* If the expected type doesn't depend on the type suffix at all,
1390 just check for the fixed choice of scalar type. */
1391 if (expected_tclass
!= SAME_TYPE_CLASS
&& expected_bits
!= SAME_SIZE
)
1393 type_suffix_index expected_type
1394 = find_type_suffix (expected_tclass
, expected_bits
);
1395 return require_scalar_type (argno
, get_scalar_type_name (expected_type
));
1398 if (scalar_argument_p (argno
))
1401 if (expected_tclass
== SAME_TYPE_CLASS
)
1402 /* It doesn't really matter whether the element is expected to be
1403 the same size as type suffix 0. */
1404 error_at (location
, "passing %qT to argument %d of %qE, which"
1405 " expects a scalar element", get_argument_type (argno
),
1408 /* It doesn't seem useful to distinguish between signed and unsigned
1410 error_at (location
, "passing %qT to argument %d of %qE, which"
1411 " expects a scalar integer", get_argument_type (argno
),
1416 /* Require argument ARGNO to be suitable for an integer constant expression.
1417 Return true if it is, otherwise report an appropriate error.
1419 function_checker checks whether the argument is actually constant and
1420 has a suitable range. The reason for distinguishing immediate arguments
1421 here is because it provides more consistent error messages than
1422 require_scalar_type would. */
1424 function_resolver::require_integer_immediate (unsigned int argno
)
1426 if (!scalar_argument_p (argno
))
1428 report_non_ice (location
, fndecl
, argno
);
1434 /* Require argument ARGNO to be a (possibly variable) scalar, using EXPECTED
1435 as the name of its expected type. Return true if the argument has the
1436 right form, otherwise report an appropriate error. */
1438 function_resolver::require_scalar_type (unsigned int argno
,
1439 const char *expected
)
1441 if (!scalar_argument_p (argno
))
1443 error_at (location
, "passing %qT to argument %d of %qE, which"
1444 " expects %qs", get_argument_type (argno
), argno
+ 1,
1451 /* Require the function to have exactly EXPECTED arguments. Return true
1452 if it does, otherwise report an appropriate error. */
1454 function_resolver::check_num_arguments (unsigned int expected
)
1456 if (m_arglist
.length () < expected
)
1457 error_at (location
, "too few arguments to function %qE", fndecl
);
1458 else if (m_arglist
.length () > expected
)
1459 error_at (location
, "too many arguments to function %qE", fndecl
);
1460 return m_arglist
.length () == expected
;
1463 /* If the function is predicated, check that the last argument is a
1464 suitable predicate. Also check that there are NOPS further
1465 arguments before any predicate, but don't check what they are.
1467 Return true on success, otherwise report a suitable error.
1468 When returning true:
1470 - set I to the number of the last unchecked argument.
1471 - set NARGS to the total number of arguments. */
1473 function_resolver::check_gp_argument (unsigned int nops
,
1474 unsigned int &i
, unsigned int &nargs
)
1477 if (pred
!= PRED_none
)
1482 /* Add first inactive argument if needed, and final predicate. */
1483 if (has_inactive_argument ())
1491 /* Add final predicate. */
1499 if (!check_num_arguments (nargs
)
1500 || !require_vector_type (nargs
- 1, VECTOR_TYPE_mve_pred16_t
))
1508 if (!check_num_arguments (nargs
))
1515 /* Finish resolving a function whose final argument can be a vector
1516 or a scalar, with the function having an implicit "_n" suffix
1517 in the latter case. This "_n" form might only exist for certain
1520 ARGNO is the index of the final argument. The inferred type suffix
1521 was obtained from argument FIRST_ARGNO, which has type FIRST_TYPE.
1522 EXPECTED_TCLASS and EXPECTED_BITS describe the expected properties
1523 of the final vector or scalar argument, in the same way as for
1524 require_derived_vector_type. INFERRED_TYPE is the inferred type
1525 suffix itself, or NUM_TYPE_SUFFIXES if it's the same as FIRST_TYPE.
1527 Return the function decl of the resolved function on success,
1528 otherwise report a suitable error and return error_mark_node. */
1529 tree
function_resolver::
1530 finish_opt_n_resolution (unsigned int argno
, unsigned int first_argno
,
1531 type_suffix_index first_type
,
1532 type_class_index expected_tclass
,
1533 unsigned int expected_bits
,
1534 type_suffix_index inferred_type
)
1536 if (inferred_type
== NUM_TYPE_SUFFIXES
)
1537 inferred_type
= first_type
;
1538 mode_suffix_index scalar_mode
= MODE_n
;
1539 if (mode_suffix_id
== MODE_r
)
1540 scalar_mode
= MODE_r
;
1541 tree scalar_form
= lookup_form (scalar_mode
, inferred_type
);
1543 /* Allow the final argument to be scalar, if an _n form exists. */
1544 if (scalar_argument_p (argno
))
1549 /* Check the vector form normally. If that succeeds, raise an
1550 error about having no corresponding _n form. */
1551 tree res
= resolve_to (mode_suffix_id
, inferred_type
);
1552 if (res
!= error_mark_node
)
1553 error_at (location
, "passing %qT to argument %d of %qE, but its"
1554 " %qT form does not accept scalars",
1555 get_argument_type (argno
), argno
+ 1, fndecl
,
1556 get_vector_type (first_type
));
1557 return error_mark_node
;
1560 /* If an _n form does exist, provide a more accurate message than
1561 require_derived_vector_type would for arguments that are neither
1562 vectors nor scalars. */
1563 if (scalar_form
&& !require_vector_or_scalar_type (argno
))
1564 return error_mark_node
;
1566 /* Check for the correct vector type. */
1567 if (!require_derived_vector_type (argno
, first_argno
, first_type
,
1568 expected_tclass
, expected_bits
))
1569 return error_mark_node
;
1571 return resolve_to (mode_suffix_id
, inferred_type
);
1574 /* Resolve a (possibly predicated) unary function. If the function uses
1575 merge predication or if TREAT_AS_MERGE_P is true, there is an extra
1576 vector argument before the governing predicate that specifies the
1577 values of inactive elements. This argument has the following
1580 - the type class must be the same as for active elements if MERGE_TCLASS
1581 is SAME_TYPE_CLASS, otherwise it must be MERGE_TCLASS itself.
1583 - the element size must be the same as for active elements if MERGE_BITS
1584 is SAME_TYPE_SIZE, otherwise it must be MERGE_BITS itself.
1586 Return the function decl of the resolved function on success,
1587 otherwise report a suitable error and return error_mark_node. */
1589 function_resolver::resolve_unary (type_class_index merge_tclass
,
1590 unsigned int merge_bits
,
1591 bool treat_as_merge_p
)
1593 type_suffix_index type
;
1594 if (pred
== PRED_m
|| treat_as_merge_p
)
1596 if (!check_num_arguments (3))
1597 return error_mark_node
;
1598 if (merge_tclass
== SAME_TYPE_CLASS
&& merge_bits
== SAME_SIZE
)
1600 /* The inactive elements are the same as the active elements,
1601 so we can use normal left-to-right resolution. */
1602 if ((type
= infer_vector_type (0)) == NUM_TYPE_SUFFIXES
1603 /* Predicates are the last argument. */
1604 || !require_vector_type (2 , VECTOR_TYPE_mve_pred16_t
)
1605 || !require_matching_vector_type (1 , type
))
1606 return error_mark_node
;
1610 /* The inactive element type is a function of the active one,
1611 so resolve the active one first. */
1612 if (!require_vector_type (1, VECTOR_TYPE_mve_pred16_t
)
1613 || (type
= infer_vector_type (2)) == NUM_TYPE_SUFFIXES
1614 || !require_derived_vector_type (0, 2, type
, merge_tclass
,
1616 return error_mark_node
;
1621 /* We just need to check the predicate (if any) and the single
1623 unsigned int i
, nargs
;
1624 if (!check_gp_argument (1, i
, nargs
)
1625 || (type
= infer_vector_type (i
)) == NUM_TYPE_SUFFIXES
)
1626 return error_mark_node
;
1629 /* Handle convert-like functions in which the first type suffix is
1631 if (type_suffix_ids
[0] != NUM_TYPE_SUFFIXES
)
1632 return resolve_to (mode_suffix_id
, type_suffix_ids
[0], type
);
1634 return resolve_to (mode_suffix_id
, type
);
1637 /* Resolve a (possibly predicated) unary function taking a scalar
1638 argument (_n suffix). If the function uses merge predication,
1639 there is an extra vector argument in the first position, and the
1640 final governing predicate that specifies the values of inactive
1643 Return the function decl of the resolved function on success,
1644 otherwise report a suitable error and return error_mark_node. */
1646 function_resolver::resolve_unary_n ()
1648 type_suffix_index type
;
1650 /* Currently only support overrides for _m (vdupq). */
1652 return error_mark_node
;
1656 if (!check_num_arguments (3))
1657 return error_mark_node
;
1659 /* The inactive elements are the same as the active elements,
1660 so we can use normal left-to-right resolution. */
1661 if ((type
= infer_vector_type (0)) == NUM_TYPE_SUFFIXES
1662 /* Predicates are the last argument. */
1663 || !require_vector_type (2 , VECTOR_TYPE_mve_pred16_t
))
1664 return error_mark_node
;
1667 /* Make sure the argument is scalar. */
1668 tree scalar_form
= lookup_form (MODE_n
, type
);
1670 if (scalar_argument_p (1) && scalar_form
)
1673 return error_mark_node
;
1676 /* Resolve a (possibly predicated) function that takes NOPS like-typed
1677 vector arguments followed by NIMM integer immediates. Return the
1678 function decl of the resolved function on success, otherwise report
1679 a suitable error and return error_mark_node. */
1681 function_resolver::resolve_uniform (unsigned int nops
, unsigned int nimm
)
1683 unsigned int i
, nargs
;
1684 type_suffix_index type
;
1685 if (!check_gp_argument (nops
+ nimm
, i
, nargs
)
1686 || (type
= infer_vector_type (0 )) == NUM_TYPE_SUFFIXES
)
1687 return error_mark_node
;
1689 unsigned int last_arg
= i
+ 1 - nimm
;
1690 for (i
= 0; i
< last_arg
; i
++)
1691 if (!require_matching_vector_type (i
, type
))
1692 return error_mark_node
;
1694 for (i
= last_arg
; i
< nargs
; ++i
)
1695 if (!require_integer_immediate (i
))
1696 return error_mark_node
;
1698 return resolve_to (mode_suffix_id
, type
);
1701 /* Resolve a (possibly predicated) function that offers a choice between
1704 - NOPS like-typed vector arguments or
1705 - NOPS - 1 like-typed vector arguments followed by a scalar argument
1707 Return the function decl of the resolved function on success,
1708 otherwise report a suitable error and return error_mark_node. */
1710 function_resolver::resolve_uniform_opt_n (unsigned int nops
)
1712 unsigned int i
, nargs
;
1713 type_suffix_index type
;
1714 if (!check_gp_argument (nops
, i
, nargs
)
1715 /* Unary operators should use resolve_unary, so using i - 1 is
1717 || (type
= infer_vector_type (i
- 1)) == NUM_TYPE_SUFFIXES
)
1718 return error_mark_node
;
1720 /* Skip last argument, may be scalar. */
1721 unsigned int last_arg
= i
;
1722 for (i
= 0; i
< last_arg
; i
++)
1723 if (!require_matching_vector_type (i
, type
))
1724 return error_mark_node
;
1726 return finish_opt_n_resolution (last_arg
, 0, type
);
1729 /* If the call is erroneous, report an appropriate error and return
1730 error_mark_node. Otherwise, if the function is overloaded, return
1731 the decl of the non-overloaded function. Return NULL_TREE otherwise,
1732 indicating that the call should be processed in the normal way. */
1734 function_resolver::resolve ()
1736 return shape
->resolve (*this);
1739 function_checker::function_checker (location_t location
,
1740 const function_instance
&instance
,
1741 tree fndecl
, tree fntype
,
1742 unsigned int nargs
, tree
*args
)
1743 : function_call_info (location
, instance
, fndecl
),
1744 m_fntype (fntype
), m_nargs (nargs
), m_args (args
)
1746 if (instance
.has_inactive_argument ())
1752 /* Return true if argument ARGNO exists. which it might not for
1753 erroneous calls. It is safe to wave through checks if this
1754 function returns false. */
1756 function_checker::argument_exists_p (unsigned int argno
)
1758 gcc_assert (argno
< (unsigned int) type_num_arguments (m_fntype
));
1759 return argno
< m_nargs
;
1762 /* Check that argument ARGNO is an integer constant expression and
1763 store its value in VALUE_OUT if so. The caller should first
1764 check that argument ARGNO exists. */
1766 function_checker::require_immediate (unsigned int argno
,
1767 HOST_WIDE_INT
&value_out
)
1769 gcc_assert (argno
< m_nargs
);
1770 tree arg
= m_args
[argno
];
1772 /* The type and range are unsigned, so read the argument as an
1773 unsigned rather than signed HWI. */
1774 if (!tree_fits_uhwi_p (arg
))
1776 report_non_ice (location
, fndecl
, argno
);
1780 /* ...but treat VALUE_OUT as signed for error reporting, since printing
1781 -1 is more user-friendly than the maximum uint64_t value. */
1782 value_out
= tree_to_uhwi (arg
);
1786 /* Check that argument REL_ARGNO is an integer constant expression that has
1787 a valid value for enumeration type TYPE. REL_ARGNO counts from the end
1788 of the predication arguments. */
1790 function_checker::require_immediate_enum (unsigned int rel_argno
, tree type
)
1792 unsigned int argno
= m_base_arg
+ rel_argno
;
1793 if (!argument_exists_p (argno
))
1796 HOST_WIDE_INT actual
;
1797 if (!require_immediate (argno
, actual
))
1800 for (tree entry
= TYPE_VALUES (type
); entry
; entry
= TREE_CHAIN (entry
))
1802 /* The value is an INTEGER_CST for C and a CONST_DECL wrapper
1803 around an INTEGER_CST for C++. */
1804 tree value
= TREE_VALUE (entry
);
1805 if (TREE_CODE (value
) == CONST_DECL
)
1806 value
= DECL_INITIAL (value
);
1807 if (wi::to_widest (value
) == actual
)
1811 report_not_enum (location
, fndecl
, argno
, actual
, type
);
1815 /* Check that argument REL_ARGNO is an integer constant expression in the
1816 range [MIN, MAX]. REL_ARGNO counts from the end of the predication
1819 function_checker::require_immediate_range (unsigned int rel_argno
,
1823 unsigned int argno
= m_base_arg
+ rel_argno
;
1824 if (!argument_exists_p (argno
))
1827 /* Required because of the tree_to_uhwi -> HOST_WIDE_INT conversion
1828 in require_immediate. */
1829 gcc_assert (min
>= 0 && min
<= max
);
1830 HOST_WIDE_INT actual
;
1831 if (!require_immediate (argno
, actual
))
1834 if (!IN_RANGE (actual
, min
, max
))
1836 report_out_of_range (location
, fndecl
, argno
, actual
, min
, max
);
1843 /* Perform semantic checks on the call. Return true if the call is valid,
1844 otherwise report a suitable error. */
1846 function_checker::check ()
1848 function_args_iterator iter
;
1851 FOREACH_FUNCTION_ARGS (m_fntype
, type
, iter
)
1853 if (type
== void_type_node
|| i
>= m_nargs
)
1857 && TREE_CODE (type
) == ENUMERAL_TYPE
1858 && !require_immediate_enum (i
- m_base_arg
, type
))
1864 return shape
->check (*this);
1867 gimple_folder::gimple_folder (const function_instance
&instance
, tree fndecl
,
1869 : function_call_info (gimple_location (call_in
), instance
, fndecl
),
1870 call (call_in
), lhs (gimple_call_lhs (call_in
))
1874 /* Try to fold the call. Return the new statement on success and null
1877 gimple_folder::fold ()
1879 /* Don't fold anything when MVE is disabled; emit an error during
1880 expansion instead. */
1881 if (!TARGET_HAVE_MVE
)
1884 /* Punt if the function has a return type and no result location is
1885 provided. The attributes should allow target-independent code to
1886 remove the calls if appropriate. */
1887 if (!lhs
&& TREE_TYPE (gimple_call_fntype (call
)) != void_type_node
)
1890 return base
->fold (*this);
1893 function_expander::function_expander (const function_instance
&instance
,
1894 tree fndecl
, tree call_expr_in
,
1895 rtx possible_target_in
)
1896 : function_call_info (EXPR_LOCATION (call_expr_in
), instance
, fndecl
),
1897 call_expr (call_expr_in
), possible_target (possible_target_in
)
1901 /* Return the handler of direct optab OP for type suffix SUFFIX_I. */
1903 function_expander::direct_optab_handler (optab op
, unsigned int suffix_i
)
1905 return ::direct_optab_handler (op
, vector_mode (suffix_i
));
1908 /* For a function that does the equivalent of:
1910 OUTPUT = COND ? FN (INPUTS) : FALLBACK;
1912 return the value of FALLBACK.
1914 MODE is the mode of OUTPUT.
1915 MERGE_ARGNO is the argument that provides FALLBACK for _m functions,
1916 or DEFAULT_MERGE_ARGNO if we should apply the usual rules.
1918 ARGNO is the caller's index into args. If the returned value is
1919 argument 0 (as for unary _m operations), increment ARGNO past the
1920 returned argument. */
1922 function_expander::get_fallback_value (machine_mode mode
,
1923 unsigned int merge_argno
,
1924 unsigned int &argno
)
1927 return CONST0_RTX (mode
);
1929 gcc_assert (pred
== PRED_m
|| pred
== PRED_x
);
1931 if (merge_argno
== 0)
1932 return args
[argno
++];
1934 return args
[merge_argno
];
1937 /* Return a REG rtx that can be used for the result of the function,
1938 using the preferred target if suitable. */
1940 function_expander::get_reg_target ()
1942 machine_mode target_mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl
)));
1943 if (!possible_target
|| GET_MODE (possible_target
) != target_mode
)
1944 possible_target
= gen_reg_rtx (target_mode
);
1945 return possible_target
;
1948 /* Add an output operand to the instruction we're building, which has
1949 code ICODE. Bind the output to the preferred target rtx if possible. */
1951 function_expander::add_output_operand (insn_code icode
)
1953 unsigned int opno
= m_ops
.length ();
1954 machine_mode mode
= insn_data
[icode
].operand
[opno
].mode
;
1955 m_ops
.safe_grow (opno
+ 1, true);
1956 create_output_operand (&m_ops
.last (), possible_target
, mode
);
1959 /* Add an input operand to the instruction we're building, which has
1960 code ICODE. Calculate the value of the operand as follows:
1962 - If the operand is a predicate, coerce X to have the
1963 mode that the instruction expects.
1965 - Otherwise use X directly. The expand machinery checks that X has
1966 the right mode for the instruction. */
1968 function_expander::add_input_operand (insn_code icode
, rtx x
)
1970 unsigned int opno
= m_ops
.length ();
1971 const insn_operand_data
&operand
= insn_data
[icode
].operand
[opno
];
1972 machine_mode mode
= operand
.mode
;
1973 if (mode
== VOIDmode
)
1975 /* The only allowable use of VOIDmode is the wildcard
1976 arm_any_register_operand, which is used to avoid
1977 combinatorial explosion in the reinterpret patterns. */
1978 gcc_assert (operand
.predicate
== arm_any_register_operand
);
1979 mode
= GET_MODE (x
);
1981 else if (VALID_MVE_PRED_MODE (mode
))
1982 x
= gen_lowpart (mode
, x
);
1984 m_ops
.safe_grow (m_ops
.length () + 1, true);
1985 create_input_operand (&m_ops
.last (), x
, mode
);
1988 /* Add an integer operand with value X to the instruction. */
1990 function_expander::add_integer_operand (HOST_WIDE_INT x
)
1992 m_ops
.safe_grow (m_ops
.length () + 1, true);
1993 create_integer_operand (&m_ops
.last (), x
);
1996 /* Generate instruction ICODE, given that its operands have already
1997 been added to M_OPS. Return the value of the first operand. */
1999 function_expander::generate_insn (insn_code icode
)
2001 expand_insn (icode
, m_ops
.length (), m_ops
.address ());
2002 return function_returns_void_p () ? const0_rtx
: m_ops
[0].value
;
2005 /* Implement the call using instruction ICODE, with a 1:1 mapping between
2006 arguments and input operands. */
2008 function_expander::use_exact_insn (insn_code icode
)
2010 unsigned int nops
= insn_data
[icode
].n_operands
;
2011 if (!function_returns_void_p ())
2013 add_output_operand (icode
);
2016 for (unsigned int i
= 0; i
< nops
; ++i
)
2017 add_input_operand (icode
, args
[i
]);
2018 return generate_insn (icode
);
2021 /* Implement the call using instruction ICODE, which does not use a
2024 function_expander::use_unpred_insn (insn_code icode
)
2026 gcc_assert (pred
== PRED_none
);
2027 /* Discount the output operand. */
2028 unsigned int nops
= insn_data
[icode
].n_operands
- 1;
2031 add_output_operand (icode
);
2032 for (; i
< nops
; ++i
)
2033 add_input_operand (icode
, args
[i
]);
2035 return generate_insn (icode
);
2038 /* Implement the call using instruction ICODE, which is a predicated
2039 operation that returns arbitrary values for inactive lanes. */
2041 function_expander::use_pred_x_insn (insn_code icode
)
2043 gcc_assert (pred
== PRED_x
);
2044 unsigned int nops
= args
.length ();
2046 add_output_operand (icode
);
2047 /* Use first operand as arbitrary inactive input. */
2048 add_input_operand (icode
, possible_target
);
2049 emit_clobber (possible_target
);
2050 /* Copy remaining arguments, including the final predicate. */
2051 for (unsigned int i
= 0; i
< nops
; ++i
)
2052 add_input_operand (icode
, args
[i
]);
2054 return generate_insn (icode
);
2057 /* Implement the call using instruction ICODE, which does the equivalent of:
2059 OUTPUT = COND ? FN (INPUTS) : FALLBACK;
2061 The instruction operands are in the order above: OUTPUT, COND, INPUTS
2062 and FALLBACK. MERGE_ARGNO is the argument that provides FALLBACK for _m
2063 functions, or DEFAULT_MERGE_ARGNO if we should apply the usual rules. */
2065 function_expander::use_cond_insn (insn_code icode
, unsigned int merge_argno
)
2067 /* At present we never need to handle PRED_none, which would involve
2068 creating a new predicate rather than using one supplied by the user. */
2069 gcc_assert (pred
!= PRED_none
);
2070 /* For MVE, we only handle PRED_m at present. */
2071 gcc_assert (pred
== PRED_m
);
2073 /* Discount the output, predicate and fallback value. */
2074 unsigned int nops
= insn_data
[icode
].n_operands
- 3;
2075 machine_mode mode
= insn_data
[icode
].operand
[0].mode
;
2077 unsigned int opno
= 0;
2078 rtx fallback_arg
= NULL_RTX
;
2079 fallback_arg
= get_fallback_value (mode
, merge_argno
, opno
);
2080 rtx pred_arg
= args
[nops
+ 1];
2082 add_output_operand (icode
);
2083 add_input_operand (icode
, fallback_arg
);
2084 for (unsigned int i
= 0; i
< nops
; ++i
)
2085 add_input_operand (icode
, args
[opno
+ i
]);
2086 add_input_operand (icode
, pred_arg
);
2087 return generate_insn (icode
);
2090 /* Implement the call using a normal unpredicated optab for PRED_none.
2092 <optab> corresponds to:
2094 - CODE_FOR_SINT for signed integers
2095 - CODE_FOR_UINT for unsigned integers
2096 - CODE_FOR_FP for floating-point values */
2098 function_expander::map_to_rtx_codes (rtx_code code_for_sint
,
2099 rtx_code code_for_uint
,
2100 rtx_code code_for_fp
)
2102 gcc_assert (pred
== PRED_none
);
2103 rtx_code code
= type_suffix (0).integer_p
?
2104 (type_suffix (0).unsigned_p
? code_for_uint
: code_for_sint
)
2106 insn_code icode
= direct_optab_handler (code_to_optab (code
), 0);
2107 if (icode
== CODE_FOR_nothing
)
2110 return use_unpred_insn (icode
);
2113 /* Expand the call and return its lhs. */
2115 function_expander::expand ()
2117 unsigned int nargs
= call_expr_nargs (call_expr
);
2118 args
.reserve (nargs
);
2119 for (unsigned int i
= 0; i
< nargs
; ++i
)
2120 args
.quick_push (expand_normal (CALL_EXPR_ARG (call_expr
, i
)));
2122 return base
->expand (*this);
2125 /* If we're implementing manual overloading, check whether the MVE
2126 function with subcode CODE is overloaded, and if so attempt to
2127 determine the corresponding non-overloaded function. The call
2128 occurs at location LOCATION and has the arguments given by ARGLIST.
2130 If the call is erroneous, report an appropriate error and return
2131 error_mark_node. Otherwise, if the function is overloaded, return
2132 the decl of the non-overloaded function. Return NULL_TREE otherwise,
2133 indicating that the call should be processed in the normal way. */
2135 resolve_overloaded_builtin (location_t location
, unsigned int code
,
2136 vec
<tree
, va_gc
> *arglist
)
2138 if (code
>= vec_safe_length (registered_functions
))
2141 registered_function
&rfn
= *(*registered_functions
)[code
];
2142 if (rfn
.overloaded_p
)
2143 return function_resolver (location
, rfn
.instance
, rfn
.decl
,
2144 *arglist
).resolve ();
2148 /* Perform any semantic checks needed for a call to the MVE function
2149 with subcode CODE, such as testing for integer constant expressions.
2150 The call occurs at location LOCATION and has NARGS arguments,
2151 given by ARGS. FNDECL is the original function decl, before
2152 overload resolution.
2154 Return true if the call is valid, otherwise report a suitable error. */
2156 check_builtin_call (location_t location
, vec
<location_t
>, unsigned int code
,
2157 tree fndecl
, unsigned int nargs
, tree
*args
)
2159 const registered_function
&rfn
= *(*registered_functions
)[code
];
2160 if (!check_requires_float (location
, rfn
.decl
, rfn
.requires_float
))
2163 return function_checker (location
, rfn
.instance
, fndecl
,
2164 TREE_TYPE (rfn
.decl
), nargs
, args
).check ();
2167 /* Attempt to fold STMT, given that it's a call to the MVE function
2168 with subcode CODE. Return the new statement on success and null
2169 on failure. Insert any other new statements at GSI. */
2171 gimple_fold_builtin (unsigned int code
, gcall
*stmt
)
2173 registered_function
&rfn
= *(*registered_functions
)[code
];
2174 return gimple_folder (rfn
.instance
, rfn
.decl
, stmt
).fold ();
2177 /* Expand a call to the MVE function with subcode CODE. EXP is the call
2178 expression and TARGET is the preferred location for the result.
2179 Return the value of the lhs. */
2181 expand_builtin (unsigned int code
, tree exp
, rtx target
)
2183 registered_function
&rfn
= *(*registered_functions
)[code
];
2184 if (!check_requires_float (EXPR_LOCATION (exp
), rfn
.decl
,
2185 rfn
.requires_float
))
2187 return function_expander (rfn
.instance
, rfn
.decl
, exp
, target
).expand ();
2190 } /* end namespace arm_mve */
2192 using namespace arm_mve
;
2195 gt_ggc_mx (function_instance
*)
2200 gt_pch_nx (function_instance
*)
2205 gt_pch_nx (function_instance
*, gt_pointer_operator
, void *)
2209 #include "gt-arm-mve-builtins.h"