Debian Codegraph @

gcc/config/riscv/constraints.md

raw
1 ;; Constraint definitions for RISC-V target.
2 ;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
3 ;; Contributed by Andrew Waterman ([email protected]).
4 ;; Based on MIPS target for GNU compiler.
5 ;;
6 ;; This file is part of GCC.
7 ;;
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
12 ;;
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3. If not see
20 ;; <http://www.gnu.org/licenses/>.
21
22 ;; Register constraints
23
24 (define_register_constraint "f" "TARGET_HARD_FLOAT ? FP_REGS :
25 (TARGET_ZFINX ? GR_REGS : NO_REGS)"
26 "A floating-point register (if available, reuse GPR as FPR when use zfinx).")
27
28 (define_register_constraint "j" "SIBCALL_REGS"
29 "@internal")
30
31 (define_register_constraint "R" "GR_REGS"
32 "Even-odd general purpose register pair."
33 "regno % 2 == 0")
34
35 ;; Avoid using register t0 for JALR's argument, because for some
36 ;; microarchitectures that is a return-address stack hint.
37 (define_register_constraint "l" "JALR_REGS"
38 "@internal")
39
40 (define_register_constraint "cr" "RVC_GR_REGS"
41 "RVC general purpose register (x8-x15).")
42
43 (define_register_constraint "cf" "TARGET_HARD_FLOAT ? RVC_FP_REGS : (TARGET_ZFINX ? RVC_GR_REGS : NO_REGS)"
44 "RVC floating-point registers (f8-f15), if available, reuse GPR as FPR when use zfinx.")
45
46 ;; General constraints
47
48 (define_constraint "I"
49 "An I-type 12-bit signed immediate."
50 (and (match_code "const_int")
51 (match_test "SMALL_OPERAND (ival)")))
52
53 (define_constraint "J"
54 "Integer zero."
55 (and (match_code "const_int")
56 (match_test "ival == 0")))
57
58 (define_constraint "k01"
59 "Constant value 1."
60 (and (match_code "const_int")
61 (match_test "ival == 1")))
62
63 (define_constraint "k02"
64 "Constant value 2"
65 (and (match_code "const_int")
66 (match_test "ival == 2")))
67
68 (define_constraint "k03"
69 "Constant value 3"
70 (and (match_code "const_int")
71 (match_test "ival == 3")))
72
73 (define_constraint "k04"
74 "Constant value 4"
75 (and (match_code "const_int")
76 (match_test "ival == 4")))
77
78 (define_constraint "k08"
79 "Constant value 8"
80 (and (match_code "const_int")
81 (match_test "ival == 8")))
82
83 (define_constraint "P"
84 "A 5-bit signed immediate for vmv.v.i."
85 (and (match_code "const_int")
86 (match_test "IN_RANGE (ival, -16, 15)")))
87
88 (define_constraint "K"
89 "A 5-bit unsigned immediate for CSR access instructions."
90 (and (match_code "const_int")
91 (match_test "IN_RANGE (ival, 0, 31)")))
92
93 (define_constraint "L"
94 "A U-type 20-bit signed immediate."
95 (and (match_code "const_int")
96 (match_test "LUI_OPERAND (ival)")))
97
98 (define_constraint "MiG"
99 "const can be represented as sum of any S12 values."
100 (and (match_code "const_int")
101 (ior (match_test "IN_RANGE (ival, 2048, 4094)")
102 (match_test "IN_RANGE (ival, -4096, -2049)"))))
103
104 (define_constraint "Ds3"
105 "@internal
106 1, 2 or 3 immediate"
107 (and (match_code "const_int")
108 (match_test "IN_RANGE (ival, 1, 3)")))
109
110 (define_constraint "DsS"
111 "@internal
112 31 immediate"
113 (and (match_code "const_int")
114 (match_test "(ival & 31) == 31")))
115
116 (define_constraint "DsD"
117 "@internal
118 63 immediate"
119 (and (match_code "const_int")
120 (match_test "(ival & 63) == 63")))
121
122 (define_constraint "DbS"
123 "@internal"
124 (and (match_code "const_int")
125 (match_test "SINGLE_BIT_MASK_OPERAND (ival)")))
126
127 (define_constraint "DnS"
128 "@internal"
129 (and (match_code "const_int")
130 (match_test "SINGLE_BIT_MASK_OPERAND (~ival)")))
131
132 ;; Floating-point constant +0.0, used for FCVT-based moves when FMV is
133 ;; not available in RV32.
134 (define_constraint "G"
135 "@internal"
136 (and (match_code "const_double")
137 (match_test "op == CONST0_RTX (mode)")))
138
139 (define_memory_constraint "A"
140 "An address that is held in a general-purpose register."
141 (and (match_code "mem")
142 (match_test "GET_CODE(XEXP(op,0)) == REG")))
143
144 (define_constraint "S"
145 "A constraint that matches an absolute symbolic address."
146 (match_operand 0 "absolute_symbolic_operand"))
147
148 (define_constraint "U"
149 "@internal
150 A PLT-indirect call address."
151 (match_operand 0 "plt_symbolic_operand"))
152
153 (define_constraint "T"
154 "@internal
155 A constant @code{move_operand}."
156 (and (match_operand 0 "move_operand")
157 (match_test "CONSTANT_P (op)")))
158
159 ;; Zfa constraints.
160
161 (define_constraint "zfli"
162 "A floating point number that can be loaded using instruction `fli` in zfa."
163 (and (match_code "const_double")
164 (match_test "TARGET_ZFA && (riscv_float_const_rtx_index_for_fli (op) != -1)")))
165
166 (define_register_constraint "zmvf" "(TARGET_ZFA || TARGET_XTHEADFMV) ? FP_REGS : NO_REGS"
167 "A floating-point register for ZFA or XTheadFmv.")
168
169 (define_register_constraint "zmvr" "(TARGET_ZFA || TARGET_XTHEADFMV) ? GR_REGS : NO_REGS"
170 "An integer register for ZFA or XTheadFmv.")
171
172 ;; Vector constraints.
173
174 (define_register_constraint "vr" "TARGET_VECTOR ? V_REGS : NO_REGS"
175 "A vector register (if available).")
176
177 (define_register_constraint "vd" "TARGET_VECTOR ? VD_REGS : NO_REGS"
178 "A vector register except mask register (if available).")
179
180 (define_register_constraint "vm" "TARGET_VECTOR ? VM_REGS : NO_REGS"
181 "A vector mask register (if available).")
182
183 ;; This constraint is used to match instruction "csrr %0, vlenb" which is generated in "mov<mode>".
184 ;; VLENB is a run-time constant which represent the vector register length in bytes.
185 ;; BYTES_PER_RISCV_VECTOR represent runtime invariant of vector register length in bytes.
186 ;; We should only allow the poly equal to BYTES_PER_RISCV_VECTOR.
187 (define_constraint "vp"
188 "POLY_INT"
189 (and (match_code "const_poly_int")
190 (match_test "known_eq (rtx_to_poly_int64 (op), BYTES_PER_RISCV_VECTOR)")))
191
192 (define_constraint "vu"
193 "A undefined vector value."
194 (and (match_code "unspec")
195 (match_test "XINT (op, 1) == UNSPEC_VUNDEF")))
196
197 (define_constraint "vi"
198 "A vector 5-bit signed immediate."
199 (and (match_code "const_vector")
200 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -16, 15)")))
201
202 (define_constraint "vj"
203 "A vector negated 5-bit signed immediate."
204 (and (match_code "const_vector")
205 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, -15, 16)")))
206
207 (define_constraint "vk"
208 "A vector 5-bit unsigned immediate."
209 (and (match_code "const_vector")
210 (match_test "riscv_vector::const_vec_all_same_in_range_p (op, 0, 31)")))
211
212 (define_constraint "vl"
213 "A uimm5 for Vector or zero for XTheadVector."
214 (and (match_code "const_int")
215 (ior (match_test "!TARGET_XTHEADVECTOR && satisfies_constraint_K (op)")
216 (match_test "TARGET_XTHEADVECTOR && satisfies_constraint_J (op)"))))
217
218 (define_constraint "Wc0"
219 "@internal
220 A constraint that matches a vector of immediate all zeros."
221 (and (match_code "const_vector")
222 (match_test "op == CONST0_RTX (GET_MODE (op))")))
223
224 (define_constraint "Wc1"
225 "@internal
226 A constraint that matches a vector of immediate all ones."
227 (and (match_code "const_vector")
228 (match_test "op == CONSTM1_RTX (GET_MODE (op))")))
229
230 (define_constraint "Wb1"
231 "@internal
232 A constraint that matches a BOOL vector of {...,0,...0,1}"
233 (and (match_code "const_vector")
234 (match_test "rtx_equal_p (op, riscv_vector::gen_scalar_move_mask (GET_MODE (op)))")))
235
236 (define_memory_constraint "Wdm"
237 "Vector duplicate memory operand"
238 (and (match_code "mem")
239 (match_code "reg" "0")))
240
241 ;; Vendor ISA extension constraints.
242
243 (define_memory_constraint "th_m_mia"
244 "@internal
245 A MEM with a valid address for th.[l|s]*ia instructions."
246 (and (match_code "mem")
247 (match_test "th_memidx_legitimate_modify_p (op, true)")))
248
249 (define_memory_constraint "th_m_mib"
250 "@internal
251 A MEM with a valid address for th.[l|s]*ib instructions."
252 (and (match_code "mem")
253 (match_test "th_memidx_legitimate_modify_p (op, false)")))
254
255 (define_memory_constraint "th_m_mir"
256 "@internal
257 A MEM with a valid address for th.[l|s]*r* instructions."
258 (and (match_code "mem")
259 (match_test "th_memidx_legitimate_index_p (op, false)")))
260
261 (define_memory_constraint "th_m_miu"
262 "@internal
263 A MEM with a valid address for th.[l|s]*ur* instructions."
264 (and (match_code "mem")
265 (match_test "th_memidx_legitimate_index_p (op, true)")))
266
267 (define_memory_constraint "th_m_noi"
268 "@internal
269 A MEM with does not match XTheadMemIdx operands."
270 (and (match_code "mem")
271 (and (match_test "!th_memidx_legitimate_modify_p (op, true)")
272 (and (match_test "!th_memidx_legitimate_modify_p (op, false)")
273 (and (match_test "!th_memidx_legitimate_index_p (op, false)")
274 (match_test "!th_memidx_legitimate_index_p (op, true)"))))))
275
276 ;; CORE-V Constraints
277 (define_constraint "CV_alu_pow2"
278 "@internal
279 Checking for CORE-V ALU clip if ival plus 1 is a power of 2"
280 (and (match_code "const_int")
281 (and (match_test "IN_RANGE (ival, 0, 1073741823)")
282 (match_test "exact_log2 (ival + 1) != -1"))))
283
284 (define_constraint "CV_bi_sign5"
285 "@internal
286 A 5-bit signed immediate for CORE-V Immediate Branch."
287 (and (match_code "const_int")
288 (match_test "IN_RANGE (ival, -16, 15)")))
289
290 (define_constraint "CV_simd_si6"
291 "A 6-bit signed immediate for SIMD."
292 (and (match_code "const_int")
293 (match_test "IN_RANGE (ival, -32, 31)")))
294
295 (define_constraint "CV_simd_un6"
296 "A 6-bit unsigned immediate for SIMD."
297 (and (match_code "const_int")
298 (match_test "IN_RANGE (ival, 0, 63)")))
299
300 (define_constraint "CV_simd_i01"
301 "Shifting immediate for SIMD shufflei1."
302 (and (match_code "const_int")
303 (match_test "IN_RANGE (ival, 64, 127)")))
304
305 (define_constraint "CV_simd_i02"
306 "Shifting immediate for SIMD shufflei2."
307 (and (match_code "const_int")
308 (match_test "IN_RANGE (ival, -128, -65)")))
309
310 (define_constraint "CV_simd_i03"
311 "Shifting immediate for SIMD shufflei3."
312 (and (match_code "const_int")
313 (match_test "IN_RANGE (ival, -64, -1)")))
314
315 (define_constraint "Q"
316 "An address operand that is valid for a prefetch instruction"
317 (match_operand 0 "prefetch_operand"))