Debian Codegraph @

gcc/config/riscv/riscv-vector-builtins.h

raw
1 /* Builtins definitions for RISC-V 'V' Extension for GNU compiler.
2 Copyright (C) 2022-2025 Free Software Foundation, Inc.
3 Contributed by Ju-Zhe Zhong ([email protected]), RiVAI Technologies Ltd.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #ifndef GCC_RISCV_VECTOR_BUILTINS_H
22 #define GCC_RISCV_VECTOR_BUILTINS_H
23
24 /* The full name of an RVV intrinsic function is the concatenation of:
25
26 - the base name ("vadd", etc.)
27 - the operand suffix ("_vv", "_vx", etc.)
28 - the type suffix ("_i32m1", "_i32mf2", etc.)
29 - the predication suffix ("_tamu", "_tumu", etc.)
30
31 Each piece of information is individually useful, so we retain this
32 classification throughout:
33
34 - function_base represents the base name.
35
36 - operand_type_index can be used as an index to get operand suffix.
37
38 - rvv_op_info can be used as an index to get argument suffix.
39
40 - predication_type_index can be used as an index to get predication suffix.
41
42 In addition to its unique full name, a function may have a shorter
43 overloaded alias. This alias removes pieces of the suffixes that
44 can be inferred from the arguments, such as by shortening the mode
45 suffix or dropping some of the type suffixes. The base name and the
46 predication suffix stay the same.
47
48 - The function_instance class describes contains all properties of each
49 individual function. Such these information will be used by
50 function_builder, function_base, function_shape, gimple_folder,
51 function_expander, etc.
52
53 - The function_builder class provides several helper function to add an
54 intrinsic function.
55
56 - The function_shape class describes how that instruction has been presented
57 at the language level:
58
59 1. Determine the function name for C and C++ overload function which can
60 be recognized by compiler at language level for each instruction
61 according to members of function_instance (base name, operand suffix,
62 type suffix, predication suffix, etc.).
63
64 2. Specify the arguments type and return type of each function to
65 describe how that instruction has presented at language level.
66
67 - The function_base describes how the underlying instruction behaves.
68
69 The static list of functions uses function_group to describe a group
70 of related functions. The function_builder class is responsible for
71 expanding this static description into a list of individual functions
72 and registering the associated built-in functions. function_instance
73 describes one of these individual functions in terms of the properties
74 described above.
75
76 The classes involved in compiling a function call are:
77
78 - function_resolver, which resolves an overloaded function call to a
79 specific function_instance and its associated function decl.
80
81 - function_checker, which checks whether the values of the arguments
82 conform to the RVV ISA specification.
83
84 - gimple_folder, which tries to fold a function call at the gimple level
85
86 - function_expander, which expands a function call into rtl instructions
87
88 function_resolver and function_checker operate at the language level
89 and so are associated with the function_shape. gimple_folder and
90 function_expander are concerned with the behavior of the function
91 and so are associated with the function_base. */
92
93 namespace riscv_vector {
94
95 /* Flags that describe what a function might do, in addition to reading
96 its arguments and returning a result. */
97 static const unsigned int CP_READ_FPCR = 1U << 0;
98 static const unsigned int CP_RAISE_FP_EXCEPTIONS = 1U << 1;
99 static const unsigned int CP_READ_MEMORY = 1U << 2;
100 static const unsigned int CP_WRITE_MEMORY = 1U << 3;
101 static const unsigned int CP_READ_CSR = 1U << 4;
102 static const unsigned int CP_WRITE_CSR = 1U << 5;
103
104 /* Bit values used to identify required extensions for RVV intrinsics. */
105 #define RVV_REQUIRE_RV64BIT (1 << 0) /* Require RV64. */
106 #define RVV_REQUIRE_ELEN_64 (1 << 1) /* Require TARGET_VECTOR_ELEN_64. */
107 #define RVV_REQUIRE_ELEN_FP_32 (1 << 2) /* Require FP ELEN >= 32. */
108 #define RVV_REQUIRE_ELEN_FP_64 (1 << 3) /* Require FP ELEN >= 64. */
109 #define RVV_REQUIRE_FULL_V (1 << 4) /* Require Full 'V' extension. */
110 #define RVV_REQUIRE_MIN_VLEN_64 (1 << 5) /* Require TARGET_MIN_VLEN >= 64. */
111 #define RVV_REQUIRE_ELEN_FP_16 (1 << 6) /* Require FP ELEN >= 32. */
112 #define RVV_REQUIRE_ELEN_BF_16 (1 << 7) /* Require BF16. */
113
114 /* Enumerates the required extensions. */
115 enum required_ext
116 {
117 VECTOR_EXT, /* Vector extension */
118 ZVBB_EXT, /* Crypto vector Zvbb sub-ext */
119 ZVBB_OR_ZVKB_EXT, /* Crypto vector Zvbb or zvkb sub-ext */
120 ZVBC_EXT, /* Crypto vector Zvbc sub-ext */
121 ZVKG_EXT, /* Crypto vector Zvkg sub-ext */
122 ZVKNED_EXT, /* Crypto vector Zvkned sub-ext */
123 ZVKNHA_OR_ZVKNHB_EXT, /* Crypto vector Zvknh[ab] sub-ext */
124 ZVKNHB_EXT, /* Crypto vector Zvknhb sub-ext */
125 ZVKSED_EXT, /* Crypto vector Zvksed sub-ext */
126 ZVKSH_EXT, /* Crypto vector Zvksh sub-ext */
127 XTHEADVECTOR_EXT, /* XTheadVector extension */
128 ZVFBFMIN_EXT, /* Zvfbfmin extension */
129 ZVFBFWMA_EXT, /* Zvfbfwma extension */
130 XSFVQMACCQOQ_EXT, /* XSFVQMACCQOQ extension */
131 XSFVQMACCDOD_EXT, /* XSFVQMACCDOD extension */
132 XSFVFNRCLIPXFQF_EXT, /* XSFVFNRCLIPXFQF extension */
133 /* Please update below to isa_name func when add or remove enum type(s). */
134 };
135
136 static inline const char * required_ext_to_isa_name (enum required_ext required)
137 {
138 switch (required)
139 {
140 case VECTOR_EXT:
141 return "v";
142 case ZVBB_EXT:
143 return "zvbb";
144 case ZVBB_OR_ZVKB_EXT:
145 return "zvbb or zvkb";
146 case ZVBC_EXT:
147 return "zvbc";
148 case ZVKG_EXT:
149 return "zvkg";
150 case ZVKNED_EXT:
151 return "zvkned";
152 case ZVKNHA_OR_ZVKNHB_EXT:
153 return "zvknha or zvknhb";
154 case ZVKNHB_EXT:
155 return "zvknhb";
156 case ZVKSED_EXT:
157 return "zvksed";
158 case ZVKSH_EXT:
159 return "zvksh";
160 case XTHEADVECTOR_EXT:
161 return "xtheadvector";
162 case ZVFBFMIN_EXT:
163 return "zvfbfmin";
164 case ZVFBFWMA_EXT:
165 return "zvfbfwma";
166 case XSFVQMACCQOQ_EXT:
167 return "xsfvqmaccqoq";
168 case XSFVQMACCDOD_EXT:
169 return "xsfvqmaccdod";
170 case XSFVFNRCLIPXFQF_EXT:
171 return "xsfvfnrclipxfqf";
172 default:
173 gcc_unreachable ();
174 }
175
176 gcc_unreachable ();
177 }
178
179 static inline bool required_extensions_specified (enum required_ext required)
180 {
181 switch (required)
182 {
183 case VECTOR_EXT:
184 return TARGET_VECTOR;;
185 case ZVBB_EXT:
186 return TARGET_ZVBB;
187 case ZVBB_OR_ZVKB_EXT:
188 return TARGET_ZVBB || TARGET_ZVKB;
189 case ZVBC_EXT:
190 return TARGET_ZVBC;
191 case ZVKG_EXT:
192 return TARGET_ZVKG;
193 case ZVKNED_EXT:
194 return TARGET_ZVKNED;
195 case ZVKNHA_OR_ZVKNHB_EXT:
196 return TARGET_ZVKNHA || TARGET_ZVKNHB;
197 case ZVKNHB_EXT:
198 return TARGET_ZVKNHB;
199 case ZVKSED_EXT:
200 return TARGET_ZVKSED;
201 case ZVKSH_EXT:
202 return TARGET_ZVKSH;
203 case XTHEADVECTOR_EXT:
204 return TARGET_XTHEADVECTOR;
205 case ZVFBFMIN_EXT:
206 return TARGET_ZVFBFMIN;
207 case ZVFBFWMA_EXT:
208 return TARGET_ZVFBFWMA;
209 case XSFVQMACCQOQ_EXT:
210 return TARGET_XSFVQMACCQOQ;
211 case XSFVQMACCDOD_EXT:
212 return TARGET_XSFVQMACCDOD;
213 case XSFVFNRCLIPXFQF_EXT:
214 return TARGET_XSFVFNRCLIPXFQF;
215 default:
216 gcc_unreachable ();
217 }
218
219 gcc_unreachable ();
220 }
221
222 /* Enumerates the RVV operand types. */
223 enum operand_type_index
224 {
225 OP_TYPE_none,
226 #define DEF_RVV_OP_TYPE(NAME) OP_TYPE_##NAME,
227 #include "riscv-vector-builtins.def"
228 NUM_OP_TYPES
229 };
230
231 /* Enumerates the RVV types, together called
232 "vector types" for brevity. */
233 enum vector_type_index
234 {
235 #define DEF_RVV_TYPE(NAME, ABI_NAME, NCHARS, ARGS...) VECTOR_TYPE_##NAME,
236 #define DEF_RVV_TUPLE_TYPE(NAME, ABI_NAME, NCHARS, ARGS...) VECTOR_TYPE_##NAME,
237 #include "riscv-vector-builtins.def"
238 NUM_VECTOR_TYPES,
239 VECTOR_TYPE_INVALID = NUM_VECTOR_TYPES
240 };
241
242 /* Enumerates the RVV governing predication types. */
243 enum predication_type_index
244 {
245 PRED_TYPE_none,
246 #define DEF_RVV_PRED_TYPE(NAME) PRED_TYPE_##NAME,
247 #include "riscv-vector-builtins.def"
248 NUM_PRED_TYPES
249 };
250
251 /* Enumerates the RVV base types. */
252 enum rvv_base_type
253 {
254 #define DEF_RVV_BASE_TYPE(NAME, ARGS...) RVV_BASE_##NAME,
255 #include "riscv-vector-builtins.def"
256 NUM_BASE_TYPES
257 };
258
259 /* Builtin types that are used to register RVV intrinsics. */
260 struct GTY (()) rvv_builtin_types_t
261 {
262 tree vector;
263 tree scalar;
264 tree vector_ptr;
265 tree scalar_ptr;
266 tree scalar_const_ptr;
267 };
268
269 /* Builtin suffix that are used to register RVV intrinsics. */
270 struct rvv_builtin_suffixes
271 {
272 const char *vector;
273 const char *scalar;
274 const char *vsetvl;
275 };
276
277 /* Builtin base type used to specify the type of builtin function
278 argument or return result. */
279 struct function_type_info
280 {
281 enum vector_type_index type_indexes[NUM_BASE_TYPES];
282 };
283
284 /* RVV Builtin argument information. */
285 struct rvv_arg_type_info
286 {
287 CONSTEXPR rvv_arg_type_info (rvv_base_type base_type_in)
288 : base_type (base_type_in)
289 {}
290 enum rvv_base_type base_type;
291
292 tree get_scalar_ptr_type (vector_type_index) const;
293 tree get_scalar_const_ptr_type (vector_type_index) const;
294 vector_type_index get_function_type_index (vector_type_index) const;
295 tree get_scalar_type (vector_type_index) const;
296 tree get_vector_type (vector_type_index) const;
297 tree get_tree_type (vector_type_index) const;
298 tree get_tuple_subpart_type (vector_type_index) const;
299 tree get_xfqf_float_type (vector_type_index) const;
300 };
301
302 /* Static information for each operand. */
303 struct rvv_type_info
304 {
305 enum vector_type_index index;
306 uint64_t required_extensions;
307 };
308
309 /* RVV Builtin operands information. */
310 struct rvv_op_info
311 {
312 const rvv_type_info *types;
313 const operand_type_index op;
314 rvv_arg_type_info ret;
315 const rvv_arg_type_info *args;
316 };
317
318 class registered_function;
319 class function_base;
320 class function_shape;
321
322 /* Static information about a set of functions. */
323 struct function_group_info
324 {
325 /* Return true if required extension is enabled */
326 bool match (required_ext ext_value) const
327 {
328 switch (ext_value)
329 {
330 case VECTOR_EXT:
331 return TARGET_VECTOR;
332 case ZVBB_EXT:
333 return TARGET_ZVBB;
334 case ZVBB_OR_ZVKB_EXT:
335 return (TARGET_ZVBB || TARGET_ZVKB);
336 case ZVBC_EXT:
337 return TARGET_ZVBC;
338 case ZVKG_EXT:
339 return TARGET_ZVKG;
340 case ZVKNED_EXT:
341 return TARGET_ZVKNED;
342 case ZVKNHA_OR_ZVKNHB_EXT:
343 return (TARGET_ZVKNHA || TARGET_ZVKNHB);
344 case ZVKNHB_EXT:
345 return TARGET_ZVKNHB;
346 case ZVKSED_EXT:
347 return TARGET_ZVKSED;
348 case ZVKSH_EXT:
349 return TARGET_ZVKSH;
350 case XTHEADVECTOR_EXT:
351 return TARGET_XTHEADVECTOR;
352 case ZVFBFMIN_EXT:
353 return TARGET_ZVFBFMIN;
354 case ZVFBFWMA_EXT:
355 return TARGET_ZVFBFWMA;
356 case XSFVQMACCQOQ_EXT:
357 return TARGET_XSFVQMACCQOQ;
358 case XSFVQMACCDOD_EXT:
359 return TARGET_XSFVQMACCDOD;
360 case XSFVFNRCLIPXFQF_EXT:
361 return TARGET_XSFVFNRCLIPXFQF;
362 default:
363 gcc_unreachable ();
364 }
365 }
366 /* The base name, as a string. */
367 const char *base_name;
368
369 /* Describes the behavior associated with the function base name. */
370 const function_base *const *base;
371
372 /* The shape of the functions, as described above the class definition.
373 It's possible to have entries with the same base name but different
374 shapes. */
375 const function_shape *const *shape;
376
377 /* A list of the available operand types, predication types,
378 and of the available operand datatype.
379 The function supports every combination of the two.
380 The list of predication is terminated by two NUM_PRED_TYPES,
381 while the list of operand info is terminated by NUM_BASE_TYPES.
382 The list of these type suffix is lexicographically ordered based
383 on the index value. */
384 const predication_type_index *preds;
385 const rvv_op_info ops_infos;
386 /* The required extension value, using it to get the enabled flag. */
387 required_ext required_extensions;
388 };
389
390 class GTY ((user)) function_instance
391 {
392 public:
393 function_instance (const char *, const function_base *,
394 const function_shape *, rvv_type_info,
395 predication_type_index, const rvv_op_info *);
396
397 bool operator== (const function_instance &) const;
398 bool operator!= (const function_instance &) const;
399 hashval_t hash () const;
400
401 unsigned int call_properties () const;
402 bool reads_global_state_p () const;
403 bool modifies_global_state_p () const;
404 bool could_trap_p () const;
405
406 /* Return true if return type or arguments are floating point type. */
407 bool any_type_float_p () const;
408
409 tree get_return_type () const;
410 bool function_returns_void_p () const;
411 tree get_arg_type (unsigned opno) const;
412
413 /* The properties of the function. (The explicit "enum"s are required
414 for gengtype.) */
415 const char *base_name;
416 const function_base *base;
417 const function_shape *shape;
418 rvv_type_info type;
419 enum predication_type_index pred;
420 const rvv_op_info *op_info;
421 };
422
423 /* A class for building and registering function decls. */
424 class function_builder
425 {
426 public:
427 function_builder ();
428 ~function_builder ();
429
430 void allocate_argument_types (const function_instance &, vec<tree> &) const;
431 void apply_predication (const function_instance &, tree, vec<tree> &) const;
432 void add_unique_function (const function_instance &, const function_shape *,
433 tree, vec<tree> &, enum required_ext);
434 void add_overloaded_function (const function_instance &,
435 const function_shape *,
436 enum required_ext);
437 void register_function_group (const function_group_info &);
438 void append_name (const char *);
439 void append_base_name (const char *);
440 void append_sew (int);
441 void append_nf (int);
442 char *finish_name ();
443
444 private:
445 tree get_attributes (const function_instance &);
446
447 registered_function &add_function (const function_instance &, const char *,
448 tree, tree, bool, const char *,
449 const vec<tree> &, enum required_ext,
450 bool);
451
452 /* True if we should create a separate decl for each instance of an
453 overloaded function, instead of using function_builder. */
454 bool m_direct_overloads;
455
456 /* Used for building up function names. */
457 obstack m_string_obstack;
458 };
459
460 /* A base class for handling calls to built-in functions. */
461 class function_call_info : public function_instance
462 {
463 public:
464 function_call_info (location_t, const function_instance &, tree);
465
466 /* The location of the call. */
467 location_t location;
468
469 /* The FUNCTION_DECL that is being called. */
470 tree fndecl;
471 };
472
473 /* A class for folding a gimple function call. */
474 class gimple_folder : public function_call_info
475 {
476 public:
477 gimple_folder (const function_instance &, tree, gimple_stmt_iterator *,
478 gcall *);
479
480 gimple *fold ();
481
482 /* Where to insert extra statements that feed the final replacement. */
483 gimple_stmt_iterator *gsi;
484
485 /* The call we're folding. */
486 gcall *call;
487
488 /* The result of the call, or null if none. */
489 tree lhs;
490 };
491
492 /* A class for expanding a function call into RTL. */
493 class function_expander : public function_call_info
494 {
495 public:
496 function_expander (const function_instance &, tree, tree, rtx);
497 rtx expand ();
498
499 void add_input_operand (machine_mode, rtx);
500 void add_input_operand (unsigned);
501 void add_output_operand (machine_mode, rtx);
502 void add_all_one_mask_operand (machine_mode);
503 void add_scalar_move_mask_operand (machine_mode);
504 void add_vundef_operand (machine_mode);
505 void add_fixed_operand (rtx);
506 void add_integer_operand (rtx);
507 void add_mem_operand (machine_mode, unsigned);
508
509 machine_mode vector_mode (void) const;
510 machine_mode index_mode (void) const;
511 machine_mode arg_mode (int) const;
512 machine_mode mask_mode (void) const;
513 machine_mode ret_mode (void) const;
514
515 rtx use_exact_insn (insn_code);
516 int prepare_contiguous_load_insn ();
517 rtx use_contiguous_load_insn (insn_code);
518 rtx use_fof_load_insn ();
519 rtx use_contiguous_store_insn (insn_code);
520 rtx use_compare_insn (rtx_code, insn_code);
521 rtx use_ternop_insn (bool, insn_code);
522 rtx use_widen_ternop_insn (insn_code);
523 rtx use_scalar_move_insn (insn_code);
524 rtx generate_insn (insn_code);
525
526 /* The function call expression. */
527 tree exp;
528
529 /* For functions that return a value, this is the preferred location
530 of that value. It could be null or could have a different mode
531 from the function return type. */
532 rtx target;
533
534 /* The number of the operands. */
535 int opno;
536
537 private:
538 /* Used to build up the operands to an instruction. */
539 struct expand_operand m_ops[MAX_RECOG_OPERANDS];
540 };
541
542 /* Provides information about a particular function base name, and handles
543 tasks related to the base name. */
544 class function_base
545 {
546 public:
547 /* Return a set of CP_* flags that describe what the function might do,
548 in addition to reading its arguments and returning a result. */
549 virtual unsigned int call_properties (const function_instance &) const;
550
551 /* Return true if intrinsics should apply vl operand. */
552 virtual bool apply_vl_p () const;
553
554 /* Return true if intrinsics should apply tail policy operand. */
555 virtual bool apply_tail_policy_p () const;
556
557 /* Return true if intrinsics should apply mask policy operand. */
558 virtual bool apply_mask_policy_p () const;
559
560 /* Return true if intrinsic can be overloaded. */
561 virtual bool can_be_overloaded_p (enum predication_type_index) const;
562
563 /* Return true if intrinsics use mask predication. */
564 virtual bool use_mask_predication_p () const;
565
566 /* Return true if intrinsics has merge operand. */
567 virtual bool has_merge_operand_p () const;
568
569 /* Return true if intrinsics has rounding mode operand. */
570 virtual bool has_rounding_mode_operand_p () const;
571
572 /* Return true if intrinsics maybe require vxrm operand. */
573 virtual bool may_require_vxrm_p () const;
574
575 /* Return true if intrinsics maybe require frm operand. */
576 virtual bool may_require_frm_p () const;
577
578 /* Try to fold the given gimple call. Return the new gimple statement
579 on success, otherwise return null. */
580 virtual gimple *fold (gimple_folder &) const { return NULL; }
581
582 /* Expand the given call into rtl. Return the result of the function,
583 or an arbitrary value if the function doesn't return a result. */
584 virtual rtx expand (function_expander &) const = 0;
585 };
586
587 /* A class for checking that the semantic constraints on a function call are
588 satisfied, such as arguments being integer constant expressions with
589 a particular range. The parent class's FNDECL is the decl that was
590 called in the original source, before overload resolution. */
591 class function_checker : public function_call_info
592 {
593 public:
594 function_checker (location_t, const function_instance &, tree, tree,
595 unsigned int, tree *);
596
597 machine_mode arg_mode (unsigned int) const;
598 machine_mode ret_mode (void) const;
599 unsigned int arg_num (void) const;
600 bool check (void);
601
602 bool require_immediate (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT) const;
603 bool require_immediate_range_or (unsigned int, HOST_WIDE_INT,
604 HOST_WIDE_INT, HOST_WIDE_INT) const;
605
606 private:
607 bool require_immediate_range (unsigned int, HOST_WIDE_INT,
608 HOST_WIDE_INT) const;
609 void report_non_ice (unsigned int) const;
610 void report_out_of_range (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT,
611 HOST_WIDE_INT) const;
612 void report_out_of_range_and_not (unsigned int, HOST_WIDE_INT, HOST_WIDE_INT,
613 HOST_WIDE_INT, HOST_WIDE_INT) const;
614
615 /* The type of the resolved function. */
616 tree m_fntype;
617
618 /* The arguments to the function. */
619 unsigned int m_nargs;
620 tree *m_args;
621 };
622
623 /* Classifies functions into "shapes" base on:
624
625 - Base name of the intrinsic function.
626
627 - Operand types list.
628
629 - Argument type list.
630
631 - Predication type list. */
632 class function_shape
633 {
634 public:
635 /* Shape the function name according to function_instance. */
636 virtual char *get_name (function_builder &, const function_instance &,
637 bool) const
638 = 0;
639
640 /* Define all functions associated with the given group. */
641 virtual void build (function_builder &, const function_group_info &) const
642 = 0;
643
644 /* Check whether the given call is semantically valid. Return true
645 if it is, otherwise report an error and return false. */
646 virtual bool check (function_checker &) const { return true; }
647 };
648
649 extern const char *const operand_suffixes[NUM_OP_TYPES];
650 extern const rvv_builtin_suffixes type_suffixes[NUM_VECTOR_TYPES + 1];
651 extern const char *const predication_suffixes[NUM_PRED_TYPES];
652 extern rvv_builtin_types_t builtin_types[NUM_VECTOR_TYPES + 1];
653 extern function_instance get_read_vl_instance (void);
654 extern tree get_read_vl_decl (void);
655
656 inline tree
657 rvv_arg_type_info::get_scalar_type (vector_type_index type_idx) const
658 {
659 return get_function_type_index (type_idx) == VECTOR_TYPE_INVALID
660 ? NULL_TREE
661 : builtin_types[get_function_type_index (type_idx)].scalar;
662 }
663
664 inline tree
665 rvv_arg_type_info::get_vector_type (vector_type_index type_idx) const
666 {
667 return get_function_type_index (type_idx) == VECTOR_TYPE_INVALID
668 ? NULL_TREE
669 : builtin_types[get_function_type_index (type_idx)].vector;
670 }
671
672 inline bool
673 function_instance::operator!= (const function_instance &other) const
674 {
675 return !operator== (other);
676 }
677
678 /* Expand the call and return its lhs. */
679 inline rtx
680 function_expander::expand ()
681 {
682 return base->expand (*this);
683 }
684
685 /* Create op and add it into M_OPS and increase OPNO. */
686 inline void
687 function_expander::add_input_operand (machine_mode mode, rtx op)
688 {
689 create_input_operand (&m_ops[opno++], op, mode);
690 }
691
692 /* Create output and add it into M_OPS and increase OPNO. */
693 inline void
694 function_expander::add_output_operand (machine_mode mode, rtx target)
695 {
696 create_output_operand (&m_ops[opno++], target, mode);
697 }
698
699 /* Since we may normalize vop/vop_tu/vop_m/vop_tumu.. into a single patter.
700 We add a fake all true mask for the intrinsics that don't need a real mask.
701 */
702 inline void
703 function_expander::add_all_one_mask_operand (machine_mode mode)
704 {
705 add_input_operand (mode, CONSTM1_RTX (mode));
706 }
707
708 /* Add mask operand for scalar move instruction. */
709 inline void
710 function_expander::add_scalar_move_mask_operand (machine_mode mode)
711 {
712 add_input_operand (mode, gen_scalar_move_mask (mode));
713 }
714
715 /* Add an operand that must be X. The only way of legitimizing an
716 invalid X is to reload the address of a MEM. */
717 inline void
718 function_expander::add_fixed_operand (rtx x)
719 {
720 create_fixed_operand (&m_ops[opno++], x);
721 }
722
723 /* Add an integer operand X. */
724 inline void
725 function_expander::add_integer_operand (rtx x)
726 {
727 create_integer_operand (&m_ops[opno++], INTVAL (x));
728 }
729
730 /* Return the machine_mode of the corresponding vector type. */
731 inline machine_mode
732 function_expander::vector_mode (void) const
733 {
734 return TYPE_MODE (builtin_types[type.index].vector);
735 }
736
737 /* Return the machine_mode of the corresponding index type. */
738 inline machine_mode
739 function_expander::index_mode (void) const
740 {
741 return TYPE_MODE (op_info->args[1].get_tree_type (type.index));
742 }
743
744 /* Return the machine_mode of the corresponding arg type. */
745 inline machine_mode
746 function_expander::arg_mode (int idx) const
747 {
748 return TYPE_MODE (op_info->args[idx].get_tree_type (type.index));
749 }
750
751 /* Return the machine_mode of the corresponding return type. */
752 inline machine_mode
753 function_expander::ret_mode (void) const
754 {
755 return TYPE_MODE (op_info->ret.get_tree_type (type.index));
756 }
757
758 inline machine_mode
759 function_checker::arg_mode (unsigned int argno) const
760 {
761 return TYPE_MODE (TREE_TYPE (m_args[argno]));
762 }
763
764 inline machine_mode
765 function_checker::ret_mode () const
766 {
767 return TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl)));
768 }
769
770 inline unsigned int
771 function_checker::arg_num () const
772 {
773 return m_nargs;
774 }
775
776 /* Default implementation of function_base::call_properties, with conservatively
777 correct behavior for floating-point instructions. */
778 inline unsigned int
779 function_base::call_properties (const function_instance &instance) const
780 {
781 unsigned int flags = 0;
782 if (instance.any_type_float_p ())
783 return flags | CP_READ_FPCR | CP_RAISE_FP_EXCEPTIONS;
784 return flags;
785 }
786
787 /* We choose to apply vl operand by default since most of the intrinsics
788 has vl operand. */
789 inline bool
790 function_base::apply_vl_p () const
791 {
792 return true;
793 }
794
795 /* We choose to apply tail policy operand by default since most of the
796 intrinsics has tail policy operand. */
797 inline bool
798 function_base::apply_tail_policy_p () const
799 {
800 return true;
801 }
802
803 /* We choose to apply mask policy operand by default since most of the
804 intrinsics has mask policy operand. */
805 inline bool
806 function_base::apply_mask_policy_p () const
807 {
808 return true;
809 }
810
811 /* We choose to return true by default since most of the intrinsics use
812 mask predication. */
813 inline bool
814 function_base::use_mask_predication_p () const
815 {
816 return true;
817 }
818
819 /* We choose to return true by default since most of the intrinsics use
820 has merge operand. */
821 inline bool
822 function_base::has_merge_operand_p () const
823 {
824 return true;
825 }
826
827 /* We choose to return false by default since most of the intrinsics does
828 not have rounding mode operand. */
829 inline bool
830 function_base::has_rounding_mode_operand_p () const
831 {
832 return false;
833 }
834
835 /* We choose to return false by default since most of the intrinsics does
836 not need frm operand. */
837 inline bool
838 function_base::may_require_frm_p () const
839 {
840 return false;
841 }
842
843 /* We choose to return false by default since most of the intrinsics does
844 not need vxrm operand. */
845 inline bool
846 function_base::may_require_vxrm_p () const
847 {
848 return false;
849 }
850
851 /* Since most of intrinsics can be overloaded, we set it true by default. */
852 inline bool
853 function_base::can_be_overloaded_p (enum predication_type_index) const
854 {
855 return true;
856 }
857
858 /* Return the single field in tuple type TYPE. */
859 inline tree
860 tuple_type_field (tree type)
861 {
862 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
863 if (TREE_CODE (field) == FIELD_DECL)
864 return field;
865 gcc_unreachable ();
866 }
867
868 } // end namespace riscv_vector
869
870 #endif