]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/riscv/riscv-protos.h
RISC-V: Add sign-extending variants for vmv.x.s.
[thirdparty/gcc.git] / gcc / config / riscv / riscv-protos.h
CommitLineData
09cae750 1/* Definition of RISC-V target for GNU compiler.
83ffe9cd 2 Copyright (C) 2011-2023 Free Software Foundation, Inc.
09cae750
PD
3 Contributed by Andrew Waterman (andrew@sifive.com).
4 Based on MIPS target for GNU compiler.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GCC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_RISCV_PROTOS_H
23#define GCC_RISCV_PROTOS_H
24
942ab49b
PN
25#include "memmodel.h"
26
09cae750
PD
27/* Symbol types we understand. The order of this list must match that of
28 the unspec enum in riscv.md, subsequent to UNSPEC_ADDRESS_FIRST. */
29enum riscv_symbol_type {
30 SYMBOL_ABSOLUTE,
31 SYMBOL_PCREL,
32 SYMBOL_GOT_DISP,
33 SYMBOL_TLS,
34 SYMBOL_TLS_LE,
35 SYMBOL_TLS_IE,
36 SYMBOL_TLS_GD
37};
38#define NUM_SYMBOL_TYPES (SYMBOL_TLS_GD + 1)
39
e53b6e56 40/* Routines implemented in riscv.cc. */
09cae750
PD
41extern enum riscv_symbol_type riscv_classify_symbolic_expression (rtx);
42extern bool riscv_symbolic_constant_p (rtx, enum riscv_symbol_type *);
b8506a8a 43extern int riscv_regno_mode_ok_for_base_p (int, machine_mode, bool);
b8506a8a 44extern int riscv_address_insns (rtx, machine_mode, bool);
09cae750
PD
45extern int riscv_const_insns (rtx);
46extern int riscv_split_const_insns (rtx);
47extern int riscv_load_store_insns (rtx, rtx_insn *);
48extern rtx riscv_emit_move (rtx, rtx);
05302544 49extern bool riscv_split_symbol (rtx, rtx, machine_mode, rtx *);
09cae750
PD
50extern bool riscv_split_symbol_type (enum riscv_symbol_type);
51extern rtx riscv_unspec_address (rtx, enum riscv_symbol_type);
05302544 52extern void riscv_move_integer (rtx, rtx, HOST_WIDE_INT, machine_mode);
b8506a8a 53extern bool riscv_legitimize_move (machine_mode, rtx, rtx);
09cae750
PD
54extern rtx riscv_subword (rtx, bool);
55extern bool riscv_split_64bit_move_p (rtx, rtx);
56extern void riscv_split_doubleword_move (rtx, rtx);
57extern const char *riscv_output_move (rtx, rtx);
8cad5b14 58extern const char *riscv_output_return ();
02fcaf41 59
09cae750
PD
60#ifdef RTX_CODE
61extern void riscv_expand_int_scc (rtx, enum rtx_code, rtx, rtx);
62extern void riscv_expand_float_scc (rtx, enum rtx_code, rtx, rtx);
63extern void riscv_expand_conditional_branch (rtx, enum rtx_code, rtx, rtx);
99bfdb07 64extern rtx riscv_emit_binary (enum rtx_code code, rtx dest, rtx x, rtx y);
09cae750 65#endif
8e7ffe12 66extern bool riscv_expand_conditional_move (rtx, rtx, rtx, rtx);
09cae750
PD
67extern rtx riscv_legitimize_call_address (rtx);
68extern void riscv_set_return_address (rtx, rtx);
69extern bool riscv_expand_block_move (rtx, rtx, rtx);
70extern rtx riscv_return_addr (int, rtx);
3496ca4e 71extern poly_int64 riscv_initial_elimination_offset (int, int);
09cae750 72extern void riscv_expand_prologue (void);
fd1e52dc 73extern void riscv_expand_epilogue (int);
d0ebdd9f 74extern bool riscv_epilogue_uses (unsigned int);
09cae750 75extern bool riscv_can_use_return_insn (void);
6ed01e6b 76extern rtx riscv_function_value (const_tree, const_tree, enum machine_mode);
6ed01e6b 77extern bool riscv_expand_block_move (rtx, rtx, rtx);
88108b27 78extern bool riscv_store_data_bypass_p (rtx_insn *, rtx_insn *);
d0e0c130
KC
79extern rtx riscv_gen_gpr_save_insn (struct riscv_frame_info *);
80extern bool riscv_gpr_save_operation_p (rtx);
b4feb49c 81extern void riscv_reinit (void);
f556cd8b 82extern poly_uint64 riscv_regmode_natural_size (machine_mode);
7e924ba3 83extern bool riscv_v_ext_vector_mode_p (machine_mode);
12847288 84extern bool riscv_v_ext_tuple_mode_p (machine_mode);
787ac959 85extern bool riscv_shamt_matches_mask_p (int, HOST_WIDE_INT);
f797260a
PN
86extern void riscv_subword_address (rtx, rtx *, rtx *, rtx *, rtx *);
87extern void riscv_lshift_subword (machine_mode, rtx, rtx, rtx *);
942ab49b 88extern enum memmodel riscv_union_memmodels (enum memmodel, enum memmodel);
09cae750 89
e53b6e56 90/* Routines implemented in riscv-c.cc. */
09cae750 91void riscv_cpu_cpp_builtins (cpp_reader *);
7d935cdd 92void riscv_register_pragmas (void);
09cae750 93
e53b6e56 94/* Routines implemented in riscv-builtins.cc. */
09cae750 95extern void riscv_atomic_assign_expand_fenv (tree *, tree *, tree *);
60bd33bc 96extern bool riscv_gimple_fold_builtin (gimple_stmt_iterator *);
b8506a8a 97extern rtx riscv_expand_builtin (tree, rtx, rtx, machine_mode, int);
09cae750
PD
98extern tree riscv_builtin_decl (unsigned int, bool);
99extern void riscv_init_builtins (void);
100
e53b6e56 101/* Routines implemented in riscv-common.cc. */
f908b69c 102extern std::string riscv_arch_str (bool version_p = true);
b4feb49c 103extern void riscv_parse_arch_string (const char *, struct gcc_options *, location_t);
8e966210 104
e0a5b313
KC
105extern bool riscv_hard_regno_rename_ok (unsigned, unsigned);
106
de6320a8 107rtl_opt_pass * make_pass_shorten_memrefs (gcc::context *ctxt);
9243c3d1 108rtl_opt_pass * make_pass_vsetvl (gcc::context *ctxt);
de6320a8 109
72eb8335
KC
110/* Information about one CPU we know about. */
111struct riscv_cpu_info {
112 /* This CPU's canonical name. */
113 const char *name;
114
115 /* Default arch for this CPU, could be NULL if no default arch. */
116 const char *arch;
117
118 /* Which automaton to use for tuning. */
119 const char *tune;
120};
121
122extern const riscv_cpu_info *riscv_find_cpu (const char *);
123
b4feb49c 124/* Routines implemented in riscv-selftests.cc. */
125#if CHECKING_P
126namespace selftest {
3b6d44f4 127void riscv_run_selftests (void);
b4feb49c 128} // namespace selftest
129#endif
130
7d935cdd 131namespace riscv_vector {
fa144175 132#define RVV_VLMAX gen_rtx_REG (Pmode, X0_REGNUM)
272e119d 133#define RVV_VUNDEF(MODE) \
7caa1ae5
JZZ
134 gen_rtx_UNSPEC (MODE, gen_rtvec (1, gen_rtx_REG (SImode, X0_REGNUM)), \
135 UNSPEC_VUNDEF)
51fd69ec
JZ
136enum insn_type
137{
138 RVV_MISC_OP = 1,
139 RVV_UNOP = 2,
140 RVV_BINOP = 3,
bf9eee73 141 RVV_BINOP_MU = RVV_BINOP + 2,
e0600a02
JZ
142 RVV_MERGE_OP = 4,
143 RVV_CMP_OP = 4,
144 RVV_CMP_MU_OP = RVV_CMP_OP + 2, /* +2 means mask and maskoff operand. */
a1b23dcf 145 RVV_UNOP_MU = RVV_UNOP + 2, /* Likewise. */
c48d7a6e 146 RVV_TERNOP = 5,
88604bd1 147 RVV_WIDEN_TERNOP = 4,
a99dc11f 148 RVV_SCALAR_MOV_OP = 4, /* +1 for VUNDEF according to vector.md. */
51795b91 149 RVV_SLIDE_OP = 4, /* Dest, VUNDEF, source and offset. */
51fd69ec 150};
3b16afeb
JZZ
151enum vlmul_type
152{
153 LMUL_1 = 0,
154 LMUL_2 = 1,
155 LMUL_4 = 2,
156 LMUL_8 = 3,
157 LMUL_RESERVED = 4,
158 LMUL_F8 = 5,
159 LMUL_F4 = 6,
160 LMUL_F2 = 7,
ec99ffab 161 NUM_LMUL = 8
3b16afeb 162};
9243c3d1
JZZ
163
164enum avl_type
165{
166 NONVLMAX,
167 VLMAX,
168};
7d935cdd 169/* Routines implemented in riscv-vector-builtins.cc. */
3b6d44f4
JZZ
170void init_builtins (void);
171const char *mangle_builtin_type (const_tree);
7d935cdd 172#ifdef GCC_TARGET_H
3b6d44f4 173bool verify_type_context (location_t, type_context_kind, const_tree, bool);
631e86b7
JZ
174bool expand_vec_perm_const (machine_mode, machine_mode, rtx, rtx, rtx,
175 const vec_perm_indices &);
7d935cdd 176#endif
3b6d44f4
JZZ
177void handle_pragma_vector (void);
178tree builtin_decl (unsigned, bool);
60bd33bc 179gimple *gimple_fold_builtin (unsigned int, gimple_stmt_iterator *, gcall *);
3b6d44f4 180rtx expand_builtin (unsigned int, tree, rtx);
7caa1ae5
JZZ
181bool check_builtin_call (location_t, vec<location_t>, unsigned int,
182 tree, unsigned int, tree *);
3b6d44f4 183bool const_vec_all_same_in_range_p (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
51fd69ec 184bool legitimize_move (rtx, rtx);
cd0c433e 185void emit_vlmax_vsetvl (machine_mode, rtx);
40fc8e3d 186void emit_hard_vlmax_vsetvl (machine_mode, rtx);
2203da51 187void emit_vlmax_insn (unsigned, int, rtx *, rtx = 0);
c48d7a6e 188void emit_vlmax_ternary_insn (unsigned, int, rtx *, rtx = 0);
2203da51 189void emit_nonvlmax_insn (unsigned, int, rtx *, rtx);
51795b91
RD
190void emit_vlmax_slide_insn (unsigned, rtx *);
191void emit_nonvlmax_slide_tu_insn (unsigned, rtx *, rtx);
e0600a02
JZ
192void emit_vlmax_merge_insn (unsigned, int, rtx *);
193void emit_vlmax_cmp_insn (unsigned, rtx *);
194void emit_vlmax_cmp_mu_insn (unsigned, rtx *);
a1b23dcf 195void emit_vlmax_masked_mu_insn (unsigned, int, rtx *);
51795b91
RD
196void emit_scalar_move_insn (unsigned, rtx *);
197void emit_nonvlmax_integer_move_insn (unsigned, rtx *, rtx);
3b6d44f4
JZZ
198enum vlmul_type get_vlmul (machine_mode);
199unsigned int get_ratio (machine_mode);
12847288
JZZ
200unsigned int get_nf (machine_mode);
201machine_mode get_subpart_mode (machine_mode);
3b6d44f4
JZZ
202int get_ta (rtx);
203int get_ma (rtx);
204int get_avl_type (rtx);
205unsigned int calculate_ratio (unsigned int, enum vlmul_type);
f556cd8b
JZZ
206enum tail_policy
207{
208 TAIL_UNDISTURBED = 0,
209 TAIL_AGNOSTIC = 1,
9243c3d1 210 TAIL_ANY = 2,
f556cd8b
JZZ
211};
212
213enum mask_policy
214{
215 MASK_UNDISTURBED = 0,
216 MASK_AGNOSTIC = 1,
9243c3d1 217 MASK_ANY = 2,
f556cd8b 218};
9243c3d1
JZZ
219enum tail_policy get_prefer_tail_policy ();
220enum mask_policy get_prefer_mask_policy ();
a143c3f7 221rtx get_avl_type_rtx (enum avl_type);
6c9bcb6c 222opt_machine_mode get_vector_mode (scalar_mode, poly_uint64);
12847288 223opt_machine_mode get_tuple_mode (machine_mode, unsigned int);
3b6d44f4
JZZ
224bool simm5_p (rtx);
225bool neg_simm5_p (rtx);
a035d133 226#ifdef RTX_CODE
3b6d44f4 227bool has_vi_variant_p (rtx_code, rtx);
e0600a02
JZ
228void expand_vec_cmp (rtx, rtx_code, rtx, rtx);
229bool expand_vec_cmp_float (rtx, rtx_code, rtx, rtx, bool);
a035d133 230#endif
51fd69ec 231bool sew64_scalar_helper (rtx *, rtx *, rtx, machine_mode,
3cb0fa12 232 bool, void (*)(rtx *, rtx));
ec99ffab 233rtx gen_scalar_move_mask (machine_mode);
1bff101b
JZZ
234
235/* RVV vector register sizes.
236 TODO: Currently, we only add RVV_32/RVV_64/RVV_128, we may need to
237 support other values in the future. */
238enum vlen_enum
239{
240 RVV_32 = 32,
241 RVV_64 = 64,
242 RVV_65536 = 65536
243};
244bool slide1_sew64_helper (int, machine_mode, machine_mode,
245 machine_mode, rtx *);
db4f7a9b 246rtx gen_avl_for_scalar_move (rtx);
51fd69ec 247void expand_tuple_move (rtx *);
2d76f2b4 248machine_mode preferred_simd_mode (scalar_mode);
bf839c15 249opt_machine_mode get_mask_mode (machine_mode);
003f388c 250void expand_vec_series (rtx, rtx, rtx);
1c1a9d8e 251void expand_vec_init (rtx, rtx);
e0600a02 252void expand_vcond (rtx *);
2418cdfc 253void expand_vec_perm (rtx, rtx, rtx, rtx);
55dcf277 254void expand_select_vl (rtx *);
5ed88078
JZ
255/* Rounding mode bitfield for fixed point VXRM. */
256enum vxrm_field_enum
257{
258 VXRM_RNU,
259 VXRM_RNE,
260 VXRM_RDN,
261 VXRM_ROD
262};
7f4644f8
PL
263/* Rounding mode bitfield for floating point FRM. The value of enum comes
264 from the below link.
265 https://github.com/riscv/riscv-isa-manual/blob/main/src/f-st-ext.adoc#floating-point-control-and-status-register
266 */
8cd140d3
JZ
267enum frm_field_enum
268{
7f4644f8
PL
269 FRM_RNE = 0, /* Aka 0b000. */
270 FRM_RTZ = 1, /* Aka 0b001. */
271 FRM_RDN = 2, /* Aka 0b010. */
272 FRM_RUP = 3, /* Aka 0b011. */
273 FRM_RMM = 4, /* Aka 0b100. */
274 FRM_DYN = 7, /* Aka 0b111. */
8cd140d3 275};
25907509
RD
276
277opt_machine_mode vectorize_related_mode (machine_mode, scalar_mode,
278 poly_uint64);
279unsigned int autovectorize_vector_modes (vec<machine_mode> *, bool);
7d935cdd
JZZ
280}
281
cbd50570
JZZ
282/* We classify builtin types into two classes:
283 1. General builtin class which is defined in riscv_builtins.
284 2. Vector builtin class which is a special builtin architecture
285 that implement intrinsic short into "pragma". */
286enum riscv_builtin_class
287{
288 RISCV_BUILTIN_GENERAL,
289 RISCV_BUILTIN_VECTOR
290};
291
292const unsigned int RISCV_BUILTIN_SHIFT = 1;
293
294/* Mask that selects the riscv_builtin_class part of a function code. */
295const unsigned int RISCV_BUILTIN_CLASS = (1 << RISCV_BUILTIN_SHIFT) - 1;
296
02fcaf41
CM
297/* Routines implemented in thead.cc. */
298extern bool th_mempair_operands_p (rtx[4], bool, machine_mode);
299extern void th_mempair_order_operands (rtx[4], bool, machine_mode);
300extern void th_mempair_prepare_save_restore_operands (rtx[4], bool,
301 machine_mode,
302 int, HOST_WIDE_INT,
303 int, HOST_WIDE_INT);
304extern void th_mempair_save_restore_regs (rtx[4], bool, machine_mode);
305#ifdef RTX_CODE
306extern const char*
307th_mempair_output_move (rtx[4], bool, machine_mode, RTX_CODE);
308#endif
309
065be0ff 310extern bool riscv_use_divmod_expander (void);
1d4d302a
YW
311void riscv_init_cumulative_args (CUMULATIVE_ARGS *, tree, rtx, tree, int);
312
09cae750 313#endif /* ! GCC_RISCV_PROTOS_H */