Debian Codegraph @

gcc/config/aarch64/aarch64-sve-builtins.h

raw
1 /* ACLE support for AArch64 SVE
2 Copyright (C) 2018-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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)
9 any later version.
10
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.
15
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/>. */
19
20 #ifndef GCC_AARCH64_SVE_BUILTINS_H
21 #define GCC_AARCH64_SVE_BUILTINS_H
22
23 #include "aarch64-builtins.h"
24
25 /* The full name of an SVE ACLE function is the concatenation of:
26
27 - the base name ("svadd", etc.)
28 - the "mode" suffix ("_n", "_index", etc.)
29 - the type suffixes ("_s32", "_b8", etc.)
30 - the predication suffix ("_x", "_z", etc.)
31 - the "_fpm" suffix when the floating point mode register is set
32
33 Each piece of information is individually useful, so we retain this
34 classification throughout:
35
36 - function_base represents the base name
37
38 - mode_suffix_index represents the mode suffix
39
40 - type_suffix_index represents individual type suffixes, while
41 type_suffix_pair represents a pair of them
42
43 - prediction_index extends the predication suffix with an additional
44 alternative: PRED_implicit for implicitly-predicated operations
45
46 - fpm_mode represents whether the fpm register is set or not
47
48 In addition to its unique full name, a function may have a shorter
49 overloaded alias. This alias removes pieces of the suffixes that
50 can be inferred from the arguments, such as by shortening the mode
51 suffix or dropping some of the type suffixes. The base name and the
52 predication suffix stay the same.
53
54 The function_shape class describes what arguments a given function
55 takes and what its overloaded alias is called. In broad terms,
56 function_base describes how the underlying instruction behaves while
57 function_shape describes how that instruction has been presented at
58 the language level.
59
60 The static list of functions uses function_group to describe a group
61 of related functions. The function_builder class is responsible for
62 expanding this static description into a list of individual functions
63 and registering the associated built-in functions. function_instance
64 describes one of these individual functions in terms of the properties
65 described above.
66
67 The classes involved in compiling a function call are:
68
69 - function_resolver, which resolves an overloaded function call to a
70 specific function_instance and its associated function decl
71
72 - function_checker, which checks whether the values of the arguments
73 conform to the ACLE specification
74
75 - gimple_folder, which tries to fold a function call at the gimple level
76
77 - function_expander, which expands a function call into rtl instructions
78
79 function_resolver and function_checker operate at the language level
80 and so are associated with the function_shape. gimple_folder and
81 function_expander are concerned with the behavior of the function
82 and so are associated with the function_base.
83
84 Note that we've specifically chosen not to fold calls in the frontend,
85 since SVE intrinsics will hardly ever fold a useful language-level
86 constant. */
87 namespace aarch64_sve
88 {
89 /* The maximum number of vectors in an ACLE tuple type. */
90 const unsigned int MAX_TUPLE_SIZE = 4;
91
92 /* Used to represent the default merge argument index for _m functions.
93 The actual index depends on how many arguments the function takes. */
94 const unsigned int DEFAULT_MERGE_ARGNO = ~0U;
95
96 /* Flags that describe what a function might do, in addition to reading
97 its arguments and returning a result. */
98 const unsigned int CP_READ_FPCR = 1U << 0;
99 const unsigned int CP_RAISE_FP_EXCEPTIONS = 1U << 1;
100 const unsigned int CP_READ_MEMORY = 1U << 2;
101 const unsigned int CP_PREFETCH_MEMORY = 1U << 3;
102 const unsigned int CP_WRITE_MEMORY = 1U << 4;
103 const unsigned int CP_READ_FFR = 1U << 5;
104 const unsigned int CP_WRITE_FFR = 1U << 6;
105 const unsigned int CP_READ_ZA = 1U << 7;
106 const unsigned int CP_WRITE_ZA = 1U << 8;
107 const unsigned int CP_READ_ZT0 = 1U << 9;
108 const unsigned int CP_WRITE_ZT0 = 1U << 10;
109
110 /* Enumerates the SVE predicate and (data) vector types, together called
111 "vector types" for brevity. */
112 enum vector_type_index
113 {
114 #define DEF_SVE_TYPE(ACLE_NAME, NCHARS, ABI_NAME, SCALAR_TYPE) \
115 VECTOR_TYPE_ ## ACLE_NAME,
116 #include "aarch64-sve-builtins.def"
117 NUM_VECTOR_TYPES
118 };
119
120 /* Classifies the available measurement units for an address displacement. */
121 enum units_index
122 {
123 UNITS_none,
124 UNITS_bytes,
125 UNITS_elements,
126 UNITS_vectors
127 };
128
129 /* Enumerates the pragma handlers. */
130 enum handle_pragma_index
131 {
132 arm_sve_handle,
133 arm_sme_handle,
134 arm_neon_sve_handle,
135 NUM_PRAGMA_HANDLERS
136 };
137
138 /* Describes the various uses of a governing predicate. */
139 enum predication_index
140 {
141 /* No governing predicate is present. */
142 PRED_none,
143
144 /* A governing predicate is present but there is no predication suffix
145 associated with it. This is used when the result is neither a vector
146 nor a predicate, since the distinction between "zeroing" and "merging"
147 doesn't apply in that case. It is also used when a suffix would be
148 redundant (such as for loads and comparisons, which are inherently
149 zeroing operations). */
150 PRED_implicit,
151
152 /* Merging predication: copy inactive lanes from the first data argument
153 to the vector result. */
154 PRED_m,
155
156 /* "Don't care" predication: set inactive lanes of the vector result
157 to arbitrary values. */
158 PRED_x,
159
160 /* Zero predication: set inactive lanes of the vector result to zero. */
161 PRED_z,
162
163 /* Merging predication for SME's ZA: merge into slices of the array
164 instead of overwriting the whole slices. */
165 PRED_za_m,
166
167 NUM_PREDS
168 };
169
170 /* Classifies intrinsics on whether they set the FPM register */
171 enum fpm_mode_index
172 {
173 FPM_unused,
174 FPM_set,
175 NUM_FPM_MODES
176 };
177
178 /* Classifies element types, based on type suffixes with the bit count
179 removed. "count" isn't really an element type, but we pretend it is
180 for consistency. */
181 enum type_class_index
182 {
183 TYPE_bool,
184 TYPE_bfloat,
185 TYPE_count,
186 TYPE_float,
187 TYPE_mfloat,
188 TYPE_signed,
189 TYPE_unsigned,
190 NUM_TYPE_CLASSES
191 };
192
193 /* Classifies an operation into "modes"; for example, to distinguish
194 vector-scalar operations from vector-vector operations, or to
195 distinguish between different addressing modes. This classification
196 accounts for the function suffixes that occur between the base name
197 and the first type suffix. */
198 enum mode_suffix_index
199 {
200 #define DEF_SVE_MODE(NAME, BASE, DISPLACEMENT, UNITS) MODE_##NAME,
201 #include "aarch64-sve-builtins.def"
202 MODE_none
203 };
204
205 /* Enumerates the possible type suffixes. Each suffix is associated with
206 a vector type, but for predicates provides extra information about the
207 element size. */
208 enum type_suffix_index
209 {
210 #define DEF_SVE_TYPE_SUFFIX(NAME, ACLE_TYPE, CLASS, BITS, MODE) \
211 TYPE_SUFFIX_ ## NAME,
212 #define DEF_SME_ZA_SUFFIX(NAME, BITS, MODE) \
213 TYPE_SUFFIX_ ## NAME,
214 #include "aarch64-sve-builtins.def"
215 NUM_TYPE_SUFFIXES
216 };
217
218 /* Enumerates the possible group suffixes. Each suffix combines two
219 optional pieces of information: the vector group size in a ZA index,
220 and the number of vectors in the largest tuple argument. */
221 enum group_suffix_index
222 {
223 #define DEF_SVE_GROUP_SUFFIX(NAME, VG, VECTORS_PER_TUPLE) GROUP_##NAME,
224 #include "aarch64-sve-builtins.def"
225 GROUP_none,
226 NUM_GROUP_SUFFIXES
227 };
228
229 /* Combines two type suffixes. */
230 typedef enum type_suffix_index type_suffix_pair[2];
231
232 class function_base;
233 class function_shape;
234
235 /* Static information about a mode suffix. */
236 struct mode_suffix_info
237 {
238 /* The suffix string itself. */
239 const char *string;
240
241 /* The type of the vector base address, or NUM_VECTOR_TYPES if the
242 mode does not include a vector base address. */
243 vector_type_index base_vector_type;
244
245 /* The type of the vector displacement, or NUM_VECTOR_TYPES if the
246 mode does not include a vector displacement. (Note that scalar
247 displacements are always int64_t.) */
248 vector_type_index displacement_vector_type;
249
250 /* The units in which the vector or scalar displacement is measured,
251 or UNITS_none if the mode doesn't take a displacement. */
252 units_index displacement_units;
253 };
254
255 #define ENTRY(E, M, Q, G) E,
256 enum aarch64_simd_type
257 {
258 #include "aarch64-simd-builtin-types.def"
259 ARM_NEON_H_TYPES_LAST
260 };
261 #undef ENTRY
262
263 /* Static information about a type suffix. */
264 struct type_suffix_info
265 {
266 /* The suffix string itself. */
267 const char *string;
268
269 /* The associated ACLE vector or predicate type. */
270 vector_type_index vector_type : 8;
271
272 /* What kind of type the suffix represents. */
273 type_class_index tclass : 8;
274
275 /* The number of bits and bytes in an element. For predicates this
276 measures the associated data elements. */
277 unsigned int element_bits : 8;
278 unsigned int element_bytes : 8;
279
280 /* True if the suffix is for an integer type. */
281 unsigned int integer_p : 1;
282 /* True if the suffix is for an unsigned type. */
283 unsigned int unsigned_p : 1;
284 /* True if the suffix is for a floating-point type. */
285 unsigned int float_p : 1;
286 /* True if the suffix is for a vector type (integer or float). */
287 unsigned int vector_p : 1;
288 /* True if the suffix is for a boolean type. */
289 unsigned int bool_p : 1;
290 /* True if the suffix is for SME's ZA. */
291 unsigned int za_p : 1;
292 unsigned int spare : 10;
293
294 /* The associated vector or predicate mode. */
295 machine_mode vector_mode : 16;
296
297 /* The corresponding 64-bit and 128-bit arm_neon.h types, or
298 ARM_NEON_H_TYPES_LAST if none. */
299 aarch64_simd_type neon64_type;
300 aarch64_simd_type neon128_type;
301 };
302
303 /* Static information about a group suffix. */
304 struct group_suffix_info
305 {
306 /* The suffix string itself. */
307 const char *string;
308
309 /* If the suffix describes a vector group in a ZA index, this is the
310 size of that group, otherwise it is zero. */
311 unsigned int vg;
312
313 /* The number of vectors in the largest (or only) tuple argument,
314 or 1 if the suffix does not convey this information. */
315 unsigned int vectors_per_tuple;
316 };
317
318 /* Represents an SVE vector, predicate, tuple of vectors, or tuple of
319 predicates. There is also a representation of "no type"/"invalid type". */
320 struct sve_type
321 {
322 sve_type () = default;
323 sve_type (type_suffix_index type) : type (type), num_vectors (1) {}
324 sve_type (type_suffix_index type, unsigned int num_vectors)
325 : type (type), num_vectors (num_vectors) {}
326
327 /* Return true if the type is valid. */
328 explicit operator bool () const { return type != NUM_TYPE_SUFFIXES; }
329
330 bool operator== (const sve_type &) const;
331 bool operator!= (const sve_type &x) const { return !operator== (x); }
332
333 /* This is one of:
334
335 - TYPE_SUFFIX_b for svbool_t-based types
336 - TYPE_SUFFIX_c for svcount_t-based types
337 - the type suffix of a data element for SVE data vectors and tuples
338 - NUM_TYPE_SUFFIXES for invalid types. */
339 type_suffix_index type = NUM_TYPE_SUFFIXES;
340
341 /* If the type is a tuple, this is the number of vectors in the tuple,
342 otherwise it is 1. */
343 unsigned int num_vectors = 1;
344 };
345
346 inline bool
347 sve_type::operator== (const sve_type &other) const
348 {
349 return type == other.type && num_vectors == other.num_vectors;
350 }
351
352 /* Static information about a set of functions. */
353 struct function_group_info
354 {
355 /* The base name, as a string. */
356 const char *base_name;
357
358 /* Describes the behavior associated with the function base name. */
359 const function_base *const *base;
360
361 /* The shape of the functions, as described above the class definition.
362 It's possible to have entries with the same base name but different
363 shapes. */
364 const function_shape *const *shape;
365
366 /* A list of the available type suffixes, group suffixes, and predication
367 types. The function supports every combination of the three.
368
369 The list of type suffixes is terminated by two NUM_TYPE_SUFFIXES.
370 It is lexicographically ordered based on the index value.
371
372 The list of group suffixes is terminated by NUM_GROUP_SUFFIXES
373 and the list of predication types is terminated by NUM_PREDS. */
374 const type_suffix_pair *types;
375 const group_suffix_index *groups;
376 const predication_index *preds;
377
378 /* The architecture extensions that the functions require. */
379 aarch64_required_extensions required_extensions;
380
381 /* Whether the floating point register is set */
382 fpm_mode_index fpm_mode;
383 };
384
385 /* Describes a single fully-resolved function (i.e. one that has a
386 unique full name). */
387 class GTY((user)) function_instance
388 {
389 public:
390 function_instance (const char *, const function_base *,
391 const function_shape *, mode_suffix_index,
392 const type_suffix_pair &, group_suffix_index,
393 predication_index, fpm_mode_index);
394
395 bool operator== (const function_instance &) const;
396 bool operator!= (const function_instance &) const;
397 hashval_t hash () const;
398
399 unsigned int call_properties () const;
400 bool reads_global_state_p () const;
401 bool modifies_global_state_p () const;
402 bool could_trap_p () const;
403
404 vector_type_index gp_type_index () const;
405 tree gp_value (gcall *) const;
406 tree inactive_values (gcall *) const;
407 tree gp_type () const;
408
409 unsigned int vectors_per_tuple () const;
410 tree memory_scalar_type () const;
411 machine_mode memory_vector_mode () const;
412
413 const mode_suffix_info &mode_suffix () const;
414 tree base_vector_type () const;
415 tree displacement_vector_type () const;
416 units_index displacement_units () const;
417
418 unsigned int num_za_tiles () const;
419
420 const type_suffix_info &type_suffix (unsigned int) const;
421 const group_suffix_info &group_suffix () const;
422
423 tree scalar_type (unsigned int) const;
424 tree vector_type (unsigned int) const;
425 tree tuple_type (unsigned int) const;
426 unsigned int elements_per_vq (unsigned int) const;
427 machine_mode vector_mode (unsigned int) const;
428 machine_mode tuple_mode (unsigned int) const;
429 machine_mode gp_mode (unsigned int) const;
430
431 /* The properties of the function. */
432 const char *base_name;
433 const function_base *base;
434 const function_shape *shape;
435 mode_suffix_index mode_suffix_id;
436 type_suffix_pair type_suffix_ids;
437 group_suffix_index group_suffix_id;
438 predication_index pred;
439 fpm_mode_index fpm_mode;
440 int gp_index;
441 };
442
443 class registered_function;
444
445 /* A class for building and registering function decls. */
446 class function_builder
447 {
448 public:
449 function_builder (handle_pragma_index, bool);
450 ~function_builder ();
451
452 void add_unique_function (const function_instance &, tree,
453 vec<tree> &, aarch64_required_extensions, bool);
454 void add_overloaded_function (const function_instance &,
455 aarch64_required_extensions);
456 void add_overloaded_functions (const function_group_info &,
457 mode_suffix_index);
458
459 void register_function_group (const function_group_info &);
460
461 private:
462 void append_name (const char *);
463 char *finish_name ();
464
465 char *get_name (const function_instance &, bool);
466
467 tree get_attributes (const function_instance &, aarch64_required_extensions);
468
469 registered_function &add_function (const function_instance &,
470 const char *, tree, tree,
471 aarch64_required_extensions, bool, bool);
472
473 /* The function type to use for functions that are resolved by
474 function_resolver. */
475 tree m_overload_type;
476
477 /* True if we should create a separate decl for each instance of an
478 overloaded function, instead of using function_resolver. */
479 bool m_direct_overloads;
480
481 /* Used for building up function names. */
482 obstack m_string_obstack;
483
484 /* Used to store the index for the current function. */
485 unsigned int m_function_index;
486
487 /* Stores the mode of the current pragma handler. */
488 bool m_function_nulls;
489 };
490
491 /* A base class for handling calls to built-in functions. */
492 class function_call_info : public function_instance
493 {
494 public:
495 function_call_info (location_t, const function_instance &, tree);
496
497 bool function_returns_void_p ();
498
499 /* The location of the call. */
500 location_t location;
501
502 /* The FUNCTION_DECL that is being called. */
503 tree fndecl;
504 };
505
506 /* A class for resolving an overloaded function call. */
507 class function_resolver : public function_call_info
508 {
509 public:
510 enum target_type_restrictions { TARGET_ANY, TARGET_32_64 };
511 enum { SAME_SIZE = 256, HALF_SIZE, QUARTER_SIZE };
512 static const type_class_index SAME_TYPE_CLASS = NUM_TYPE_CLASSES;
513
514 function_resolver (location_t, const function_instance &, tree,
515 vec<tree, va_gc> &);
516
517 const char *get_scalar_type_name (type_suffix_index);
518 tree get_argument_type (unsigned int);
519 bool scalar_argument_p (unsigned int);
520
521 void report_incorrect_num_vectors (unsigned int, sve_type, unsigned int);
522 void report_mismatched_num_vectors (unsigned int, sve_type,
523 unsigned int, sve_type);
524
525 tree report_no_such_form (sve_type);
526 tree lookup_form (mode_suffix_index,
527 type_suffix_index = NUM_TYPE_SUFFIXES,
528 type_suffix_index = NUM_TYPE_SUFFIXES,
529 group_suffix_index = GROUP_none);
530 tree lookup_form (mode_suffix_index, sve_type);
531 tree resolve_to (mode_suffix_index,
532 type_suffix_index = NUM_TYPE_SUFFIXES,
533 type_suffix_index = NUM_TYPE_SUFFIXES,
534 group_suffix_index = GROUP_none);
535 tree resolve_to (mode_suffix_index, sve_type);
536 tree resolve_conversion (mode_suffix_index, sve_type);
537
538 vector_type_index infer_predicate_type (unsigned int);
539 type_suffix_index infer_integer_scalar_type (unsigned int);
540 type_suffix_index infer_64bit_scalar_integer_pair (unsigned int);
541 type_suffix_index infer_pointer_type (unsigned int, bool = false,
542 target_type_restrictions = TARGET_ANY);
543 sve_type infer_sve_type (unsigned int);
544 sve_type infer_vector_or_tuple_type (unsigned int, unsigned int);
545 type_suffix_index infer_vector_type (unsigned int);
546 type_suffix_index infer_integer_vector_type (unsigned int);
547 type_suffix_index infer_neon128_vector_type (unsigned int);
548 type_suffix_index infer_unsigned_vector_type (unsigned int);
549 type_suffix_index infer_sd_vector_type (unsigned int);
550 sve_type infer_tuple_type (unsigned int);
551
552 bool require_vector_or_scalar_type (unsigned int);
553
554 bool require_matching_predicate_type (vector_type_index, sve_type);
555 bool require_vector_type (unsigned int, vector_type_index);
556 bool require_matching_vector_type (unsigned int, unsigned int, sve_type);
557 bool require_derived_vector_type (unsigned int, unsigned int, sve_type,
558 type_class_index = SAME_TYPE_CLASS,
559 unsigned int = SAME_SIZE,
560 unsigned int = 1);
561
562 bool require_scalar_type (unsigned int, const char *);
563 bool require_nonscalar_type (unsigned int);
564 bool require_pointer_type (unsigned int);
565 bool require_matching_integer_scalar_type (unsigned int, unsigned int,
566 type_suffix_index);
567 bool require_derived_scalar_type (unsigned int, type_class_index,
568 unsigned int = SAME_SIZE);
569 bool require_matching_pointer_type (unsigned int, unsigned int,
570 type_suffix_index);
571 bool require_integer_immediate (unsigned int);
572
573 vector_type_index infer_vector_base_type (unsigned int);
574 vector_type_index infer_vector_displacement_type (unsigned int);
575
576 mode_suffix_index resolve_sv_displacement (unsigned int,
577 type_suffix_index, bool);
578 mode_suffix_index resolve_gather_address (unsigned int,
579 type_suffix_index, bool);
580 mode_suffix_index resolve_adr_address (unsigned int);
581
582 bool check_num_arguments (unsigned int);
583 bool check_gp_argument (unsigned int, unsigned int &, unsigned int &);
584 tree resolve_unary (type_class_index = SAME_TYPE_CLASS,
585 unsigned int = SAME_SIZE, bool = false);
586 tree resolve_uniform (unsigned int, unsigned int = 0);
587 tree resolve_uniform_opt_n (unsigned int);
588 tree finish_opt_n_resolution (unsigned int, unsigned int, type_suffix_index,
589 type_class_index = SAME_TYPE_CLASS,
590 unsigned int = SAME_SIZE,
591 type_suffix_index = NUM_TYPE_SUFFIXES);
592 tree finish_opt_single_resolution (unsigned int, unsigned int, sve_type,
593 type_class_index = SAME_TYPE_CLASS);
594
595 tree resolve ();
596
597 private:
598 /* The arguments to the overloaded function. */
599 vec<tree, va_gc> &m_arglist;
600 };
601
602 /* A class for checking that the semantic constraints on a function call are
603 satisfied, such as arguments being integer constant expressions with
604 a particular range. The parent class's FNDECL is the decl that was
605 called in the original source, before overload resolution. */
606 class function_checker : public function_call_info
607 {
608 public:
609 function_checker (location_t, const function_instance &, tree,
610 tree, unsigned int, tree *);
611
612 bool require_immediate_either_or (unsigned int, HOST_WIDE_INT,
613 HOST_WIDE_INT);
614 bool require_immediate_enum (unsigned int, tree);
615 bool require_immediate_lane_index (unsigned int, unsigned int,
616 unsigned int = 1);
617 bool require_immediate_one_of (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT,
618 HOST_WIDE_INT, HOST_WIDE_INT);
619 bool require_immediate_range (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT);
620
621 bool check ();
622
623 private:
624 bool argument_exists_p (unsigned int);
625
626 bool require_immediate (unsigned int, HOST_WIDE_INT &);
627
628 /* The type of the resolved function. */
629 tree m_fntype;
630
631 /* The arguments to the function. */
632 unsigned int m_nargs;
633 tree *m_args;
634
635 /* The first argument not associated with the function's predication
636 type. */
637 unsigned int m_base_arg;
638 };
639
640 /* A class for folding a gimple function call. */
641 class gimple_folder : public function_call_info
642 {
643 public:
644 gimple_folder (const function_instance &, tree,
645 gimple_stmt_iterator *, gcall *);
646
647 tree force_vector (gimple_seq &, tree, tree);
648 tree convert_pred (gimple_seq &, tree, unsigned int);
649 tree fold_contiguous_base (gimple_seq &, tree);
650 tree load_store_cookie (tree);
651
652 gcall *redirect_call (const function_instance &);
653 gimple *redirect_pred_x ();
654 gimple *fold_pfalse ();
655 gimple *convert_and_fold (tree, gimple *(*) (gimple_folder &,
656 tree, vec<tree> &));
657
658 gimple *fold_to_cstu (poly_uint64);
659 gimple *fold_to_pfalse ();
660 gimple *fold_to_ptrue ();
661 gimple *fold_to_vl_pred (unsigned int);
662 gimple *fold_const_binary (enum tree_code);
663 gimple *fold_active_lanes_to (tree);
664 gimple *fold_call_to (tree);
665 gimple *fold_to_stmt_vops (gimple *);
666
667 gimple *fold ();
668
669 /* Where to insert extra statements that feed the final replacement. */
670 gimple_stmt_iterator *gsi;
671
672 /* The call we're folding. */
673 gcall *call;
674
675 /* The result of the call, or null if none. */
676 tree lhs;
677 };
678
679 /* A class for expanding a function call into RTL. */
680 class function_expander : public function_call_info
681 {
682 public:
683 function_expander (const function_instance &, tree, tree, rtx);
684 rtx expand ();
685
686 insn_code direct_optab_handler (optab, unsigned int = 0);
687 insn_code direct_optab_handler_for_sign (optab, optab, unsigned int = 0,
688 machine_mode = E_VOIDmode);
689 insn_code convert_optab_handler_for_sign (optab, optab, unsigned int,
690 machine_mode, machine_mode);
691
692 machine_mode result_mode () const;
693
694 bool overlaps_input_p (rtx);
695
696 rtx convert_to_pmode (rtx);
697 rtx get_contiguous_base (machine_mode, unsigned int = 1, unsigned int = 2,
698 aarch64_feature_flags = 0);
699 rtx get_fallback_value (machine_mode, unsigned int,
700 unsigned int, unsigned int &);
701 rtx get_reg_target ();
702 rtx get_nonoverlapping_reg_target ();
703
704 void add_output_operand (insn_code);
705 void add_input_operand (insn_code, rtx);
706 void add_integer_operand (poly_int64);
707 void add_mem_operand (machine_mode, rtx);
708 void add_address_operand (rtx);
709 void add_fixed_operand (rtx);
710 rtx generate_insn (insn_code);
711
712 void prepare_gather_address_operands (unsigned int, bool = true);
713 void prepare_prefetch_operands ();
714 void add_ptrue_hint (unsigned int, machine_mode);
715 void rotate_inputs_left (unsigned int, unsigned int);
716 bool try_negating_argument (unsigned int, machine_mode);
717
718 rtx use_exact_insn (insn_code);
719 rtx use_unpred_insn (insn_code);
720 rtx use_pred_x_insn (insn_code);
721 rtx use_cond_insn (insn_code, unsigned int = DEFAULT_MERGE_ARGNO);
722 rtx use_vcond_mask_insn (insn_code, unsigned int = DEFAULT_MERGE_ARGNO);
723 rtx use_contiguous_load_insn (insn_code, bool = false);
724 rtx use_contiguous_prefetch_insn (insn_code);
725 rtx use_contiguous_store_insn (insn_code);
726
727 rtx map_to_rtx_codes (rtx_code, rtx_code, int, int,
728 unsigned int = DEFAULT_MERGE_ARGNO);
729 rtx map_to_unspecs (int, int, int, unsigned int = DEFAULT_MERGE_ARGNO);
730
731 /* The function call expression. */
732 tree call_expr;
733
734 /* For functions that return a value, this is the preferred location
735 of that value. It could be null or could have a different mode
736 from the function return type. */
737 rtx possible_target;
738
739 /* The expanded arguments. */
740 auto_vec<rtx, 16> args;
741
742 private:
743 /* Used to build up the operands to an instruction. */
744 auto_vec<expand_operand, 8> m_ops;
745 };
746
747 /* Provides information about a particular function base name, and handles
748 tasks related to the base name. */
749 class function_base
750 {
751 public:
752 /* Return a set of CP_* flags that describe what the function might do,
753 in addition to reading its arguments and returning a result. */
754 virtual unsigned int call_properties (const function_instance &) const;
755
756 /* If the function operates on tuples of vectors, return the number
757 of vectors in the tuples, otherwise return 1. */
758 virtual unsigned int vectors_per_tuple (const function_instance &) const;
759
760 /* If the function addresses memory, return the type of a single
761 scalar memory element. */
762 virtual tree
763 memory_scalar_type (const function_instance &) const
764 {
765 gcc_unreachable ();
766 }
767
768 /* If the function addresses memory, return a vector mode whose
769 GET_MODE_NUNITS is the number of elements addressed and whose
770 GET_MODE_INNER is the mode of a single scalar memory element. */
771 virtual machine_mode
772 memory_vector_mode (const function_instance &) const
773 {
774 gcc_unreachable ();
775 }
776
777 /* Try to fold the given gimple call. Return the new gimple statement
778 on success, otherwise return null. */
779 virtual gimple *fold (gimple_folder &) const { return NULL; }
780
781 /* Expand the given call into rtl. Return the result of the function,
782 or an arbitrary value if the function doesn't return a result. */
783 virtual rtx expand (function_expander &) const = 0;
784 };
785
786 /* Classifies functions into "shapes". The idea is to take all the
787 type signatures for a set of functions, remove the governing predicate
788 (if any), and classify what's left based on:
789
790 - the number of arguments
791
792 - the process of determining the types in the signature from the mode
793 and type suffixes in the function name (including types that are not
794 affected by the suffixes)
795
796 - which arguments must be integer constant expressions, and what range
797 those arguments have
798
799 - the process for mapping overloaded names to "full" names. */
800 class function_shape
801 {
802 public:
803 virtual bool has_merge_argument_p (const function_instance &,
804 unsigned int) const;
805
806 virtual bool has_gp_argument_p (const function_instance &) const;
807
808 virtual bool explicit_type_suffix_p (unsigned int) const = 0;
809
810 /* True if the group suffix is present in overloaded names.
811 This isn't meaningful for pre-SME intrinsics, and true is
812 more common than false, so provide a default definition. */
813 virtual bool explicit_group_suffix_p () const { return true; }
814
815 virtual type_suffix_index vector_base_type (type_suffix_index) const;
816
817 /* Define all functions associated with the given group. */
818 virtual void build (function_builder &,
819 const function_group_info &) const = 0;
820
821 /* Try to resolve the overloaded call. Return the non-overloaded
822 function decl on success and error_mark_node on failure. */
823 virtual tree resolve (function_resolver &) const = 0;
824
825 /* Check whether the given call is semantically valid. Return true
826 if it is, otherwise report an error and return false. */
827 virtual bool check (function_checker &) const { return true; }
828 };
829
830 /* RAII class for temporarily disabling the effect of any -fpack-struct option.
831 This is used to ensure that sve vector tuple types are defined with the
832 correct alignment. */
833 class sve_alignment_switcher
834 {
835 public:
836 sve_alignment_switcher ();
837 ~sve_alignment_switcher ();
838
839 private:
840 unsigned int m_old_maximum_field_alignment;
841 };
842
843 extern const type_suffix_info type_suffixes[NUM_TYPE_SUFFIXES + 1];
844 extern const mode_suffix_info mode_suffixes[MODE_none + 1];
845 extern const group_suffix_info group_suffixes[NUM_GROUP_SUFFIXES];
846
847 extern tree scalar_types[NUM_VECTOR_TYPES + 1];
848 extern tree acle_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
849 extern tree acle_svpattern;
850 extern tree acle_svprfop;
851
852 bool vector_cst_all_same (tree, unsigned int);
853 bool is_ptrue (tree, unsigned int);
854 bool is_pfalse (tree);
855 const function_instance *lookup_fndecl (tree);
856
857 /* Try to find a mode with the given mode_suffix_info fields. Return the
858 mode on success or MODE_none on failure. */
859 inline mode_suffix_index
860 find_mode_suffix (vector_type_index base_vector_type,
861 vector_type_index displacement_vector_type,
862 units_index displacement_units)
863 {
864 for (unsigned int mode_i = 0; mode_i < ARRAY_SIZE (mode_suffixes); ++mode_i)
865 {
866 const mode_suffix_info &mode = mode_suffixes[mode_i];
867 if (mode.base_vector_type == base_vector_type
868 && mode.displacement_vector_type == displacement_vector_type
869 && mode.displacement_units == displacement_units)
870 return mode_suffix_index (mode_i);
871 }
872 return MODE_none;
873 }
874
875 /* Return the type suffix associated with ELEMENT_BITS-bit elements of type
876 class TCLASS. */
877 inline type_suffix_index
878 find_type_suffix (type_class_index tclass, unsigned int element_bits)
879 {
880 for (unsigned int i = 0; i < NUM_TYPE_SUFFIXES; ++i)
881 if (type_suffixes[i].tclass == tclass
882 && type_suffixes[i].element_bits == element_bits)
883 return type_suffix_index (i);
884 gcc_unreachable ();
885 }
886
887 /* Return the single field in tuple type TYPE. */
888 inline tree
889 tuple_type_field (tree type)
890 {
891 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
892 if (TREE_CODE (field) == FIELD_DECL)
893 return field;
894 gcc_unreachable ();
895 }
896
897 /* Return the vector type associated with TYPE. */
898 inline tree
899 get_vector_type (sve_type type)
900 {
901 auto vector_type = type_suffixes[type.type].vector_type;
902 return acle_vector_types[type.num_vectors - 1][vector_type];
903 }
904
905 inline function_instance::
906 function_instance (const char *base_name_in, const function_base *base_in,
907 const function_shape *shape_in,
908 mode_suffix_index mode_suffix_id_in,
909 const type_suffix_pair &type_suffix_ids_in,
910 group_suffix_index group_suffix_id_in,
911 predication_index pred_in, fpm_mode_index fpm_mode_in)
912 : base_name (base_name_in), base (base_in), shape (shape_in),
913 mode_suffix_id (mode_suffix_id_in), group_suffix_id (group_suffix_id_in),
914 pred (pred_in), fpm_mode (fpm_mode_in)
915 {
916 memcpy (type_suffix_ids, type_suffix_ids_in, sizeof (type_suffix_ids));
917 }
918
919 inline bool
920 function_instance::operator== (const function_instance &other) const
921 {
922 return (base == other.base
923 && shape == other.shape
924 && mode_suffix_id == other.mode_suffix_id
925 && type_suffix_ids[0] == other.type_suffix_ids[0]
926 && type_suffix_ids[1] == other.type_suffix_ids[1]
927 && group_suffix_id == other.group_suffix_id
928 && pred == other.pred
929 && fpm_mode == other.fpm_mode);
930 }
931
932 inline bool
933 function_instance::operator!= (const function_instance &other) const
934 {
935 return !operator== (other);
936 }
937
938 /* Return the index of the type that should be used as the governing
939 predicate of this function. */
940 inline vector_type_index
941 function_instance::gp_type_index () const
942 {
943 if (group_suffix ().vectors_per_tuple > 1)
944 return VECTOR_TYPE_svcount_t;
945 return VECTOR_TYPE_svbool_t;
946 }
947
948 /* Return the type that should be used as the governing predicate of
949 this function. */
950 inline tree
951 function_instance::gp_type () const
952 {
953 return acle_vector_types[0][gp_type_index ()];
954 }
955
956 /* Return the tree value that should be used as the governing predicate of
957 this function. If none then return NULL_TREE. */
958 inline tree
959 function_instance::gp_value (gcall *call) const
960 {
961 if (gp_index < 0)
962 return NULL_TREE;
963
964 return gimple_call_arg (call, gp_index);
965 }
966
967 /* Return the tree value that should be used for the inactive lanes should this
968 function be a predicated function with a gp. Otherwise return NULL_TREE. */
969 inline tree
970 function_instance::inactive_values (gcall *call) const
971 {
972 if (gp_index < 0)
973 return NULL_TREE;
974
975 /* Function is unary with m predicate. */
976 if (gp_index == 1)
977 return gimple_call_arg (call, 0);
978
979 /* Else the inactive values are the next element. */
980 return gimple_call_arg (call, 1);
981 }
982
983 /* If the function operates on tuples of vectors, return the number
984 of vectors in the tuples, otherwise return 1. */
985 inline unsigned int
986 function_instance::vectors_per_tuple () const
987 {
988 return base->vectors_per_tuple (*this);
989 }
990
991 /* If the function addresses memory, return the type of a single
992 scalar memory element. */
993 inline tree
994 function_instance::memory_scalar_type () const
995 {
996 return base->memory_scalar_type (*this);
997 }
998
999 /* If the function addresses memory, return a vector mode whose
1000 GET_MODE_NUNITS is the number of elements addressed and whose
1001 GET_MODE_INNER is the mode of a single scalar memory element. */
1002 inline machine_mode
1003 function_instance::memory_vector_mode () const
1004 {
1005 return base->memory_vector_mode (*this);
1006 }
1007
1008 /* Return information about the function's mode suffix. */
1009 inline const mode_suffix_info &
1010 function_instance::mode_suffix () const
1011 {
1012 return mode_suffixes[mode_suffix_id];
1013 }
1014
1015 /* Return the type of the function's vector base address argument,
1016 or null it doesn't have a vector base address. */
1017 inline tree
1018 function_instance::base_vector_type () const
1019 {
1020 return acle_vector_types[0][mode_suffix ().base_vector_type];
1021 }
1022
1023 /* Return the type of the function's vector index or offset argument,
1024 or null if doesn't have a vector index or offset argument. */
1025 inline tree
1026 function_instance::displacement_vector_type () const
1027 {
1028 return acle_vector_types[0][mode_suffix ().displacement_vector_type];
1029 }
1030
1031 /* Return the number of ZA tiles associated with the _za<N> suffix
1032 (which is always the first type suffix). */
1033 inline unsigned int
1034 function_instance::num_za_tiles () const
1035 {
1036 auto &suffix = type_suffix (0);
1037 gcc_checking_assert (suffix.za_p);
1038 return suffix.element_bytes;
1039 }
1040
1041 /* If the function takes a vector or scalar displacement, return the units
1042 in which the displacement is measured, otherwise return UNITS_none. */
1043 inline units_index
1044 function_instance::displacement_units () const
1045 {
1046 return mode_suffix ().displacement_units;
1047 }
1048
1049 /* Return information about type suffix I. */
1050 inline const type_suffix_info &
1051 function_instance::type_suffix (unsigned int i) const
1052 {
1053 return type_suffixes[type_suffix_ids[i]];
1054 }
1055
1056 /* Return information about the function's group suffix. */
1057 inline const group_suffix_info &
1058 function_instance::group_suffix () const
1059 {
1060 return group_suffixes[group_suffix_id];
1061 }
1062
1063 /* Return the scalar type associated with type suffix I. */
1064 inline tree
1065 function_instance::scalar_type (unsigned int i) const
1066 {
1067 return scalar_types[type_suffix (i).vector_type];
1068 }
1069
1070 /* Return the vector type associated with type suffix I. */
1071 inline tree
1072 function_instance::vector_type (unsigned int i) const
1073 {
1074 return acle_vector_types[0][type_suffix (i).vector_type];
1075 }
1076
1077 /* If the function operates on tuples of vectors, return the tuple type
1078 associated with type suffix I, otherwise return the vector type associated
1079 with type suffix I. */
1080 inline tree
1081 function_instance::tuple_type (unsigned int i) const
1082 {
1083 unsigned int num_vectors = vectors_per_tuple ();
1084 return acle_vector_types[num_vectors - 1][type_suffix (i).vector_type];
1085 }
1086
1087 /* Return the number of elements of type suffix I that fit within a
1088 128-bit block. */
1089 inline unsigned int
1090 function_instance::elements_per_vq (unsigned int i) const
1091 {
1092 return 128 / type_suffix (i).element_bits;
1093 }
1094
1095 /* Return the vector or predicate mode associated with type suffix I. */
1096 inline machine_mode
1097 function_instance::vector_mode (unsigned int i) const
1098 {
1099 return type_suffix (i).vector_mode;
1100 }
1101
1102 /* Return the mode of tuple_type (I). */
1103 inline machine_mode
1104 function_instance::tuple_mode (unsigned int i) const
1105 {
1106 if (group_suffix ().vectors_per_tuple > 1)
1107 return TYPE_MODE (tuple_type (i));
1108 return vector_mode (i);
1109 }
1110
1111 /* Return the mode of the governing predicate to use when operating on
1112 type suffix I. */
1113 inline machine_mode
1114 function_instance::gp_mode (unsigned int i) const
1115 {
1116 /* Multi-vector operations are predicated on an svcount_t, which has
1117 mode VNx16BI. */
1118 if (group_suffix ().vectors_per_tuple > 1)
1119 return VNx16BImode;
1120 return aarch64_sve_pred_mode (type_suffix (i).element_bytes).require ();
1121 }
1122
1123 /* Return true if the function has no return value. */
1124 inline bool
1125 function_call_info::function_returns_void_p ()
1126 {
1127 return TREE_TYPE (TREE_TYPE (fndecl)) == void_type_node;
1128 }
1129
1130 /* Default implementation of function::call_properties, with conservatively
1131 correct behavior for floating-point instructions. */
1132 inline unsigned int
1133 function_base::call_properties (const function_instance &instance) const
1134 {
1135 unsigned int flags = 0;
1136 if (instance.type_suffix (0).float_p || instance.type_suffix (1).float_p)
1137 flags |= CP_READ_FPCR | CP_RAISE_FP_EXCEPTIONS;
1138 return flags;
1139 }
1140
1141 inline unsigned int
1142 function_base::vectors_per_tuple (const function_instance &instance) const
1143 {
1144 return instance.group_suffix ().vectors_per_tuple;
1145 }
1146
1147 /* Return true if INSTANCE (which has NARGS arguments) has an initial
1148 vector argument whose only purpose is to specify the values of
1149 inactive lanes. */
1150 inline bool
1151 function_shape::has_merge_argument_p (const function_instance &instance,
1152 unsigned int nargs) const
1153 {
1154 return nargs == 1 && instance.pred == PRED_m;
1155 }
1156
1157 /* Return true if INSTANCE has an predicate argument that can be used as the global
1158 predicate. */
1159 inline bool
1160 function_shape::has_gp_argument_p (const function_instance &instance) const
1161 {
1162 return instance.pred != PRED_none;
1163 }
1164
1165 /* Return the mode of the result of a call. */
1166 inline machine_mode
1167 function_expander::result_mode () const
1168 {
1169 return TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl)));
1170 }
1171
1172 }
1173
1174 #endif