]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/tilegx/predicates.md
Add support for the -mcmodel=MODEL flag on TILE-Gx.
[thirdparty/gcc.git] / gcc / config / tilegx / predicates.md
1 ;; Predicate definitions for Tilera TILE-Gx.
2 ;; Copyright (C) 2011, 2012
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Walter Lee (walt@tilera.com)
5 ;;
6 ;; This file is part of GCC.
7 ;;
8 ;; GCC is free software; you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 3, or (at your
11 ;; option) any later version.
12 ;;
13 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
14 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 ;; 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 ;; Return true if OP is the zero constant for MODE.
23 (define_predicate "const_zero_operand"
24 (and (match_code "const_int,const_double,const_vector")
25 (match_test "op == CONST0_RTX (mode)")))
26
27 ;; Returns true if OP is either the constant zero or a register.
28 (define_predicate "reg_or_0_operand"
29 (and (ior (match_operand 0 "register_operand")
30 (match_operand 0 "const_zero_operand"))
31 (match_test "GET_MODE_SIZE (mode) <= UNITS_PER_WORD")))
32
33 ; Return 1 if OP is a valid Pmode pointer.
34 (define_predicate "pointer_operand"
35 (and (match_operand 0 "address_operand")
36 (ior (match_operand 0 "pmode_register_operand")
37 (match_operand 0 "const_zero_operand"))))
38
39 ; Return 1 if OP is a network register identifier.
40 (define_predicate "netreg_operand"
41 (and (match_code "const_int")
42 (match_test "IN_RANGE (INTVAL (op), 0, 5)")))
43
44 ; Return 1 if OP is an unsigned 6-bit constant.
45 (define_predicate "u6bit_cint_operand"
46 (and (match_code "const_int")
47 (match_test "INTVAL (op) == (INTVAL (op) & 0x3F)")))
48
49 ;; Return 1 if OP is an unsigned 16-bit constant.
50 (define_predicate "u16bit_cint_operand"
51 (and (match_code "const_int")
52 (match_test "(unsigned HOST_WIDE_INT)INTVAL (op) < (1U << 16)")))
53
54 ;; Return 1 if OP is a signed 8-bit constant.
55 (define_predicate "s8bit_cint_operand"
56 (and (match_code "const_int")
57 (match_test "satisfies_constraint_I (op)")))
58
59 ;; Return 1 if OP is a signed 16-bit constant.
60 (define_predicate "s16bit_cint_operand"
61 (and (match_code "const_int")
62 (match_test "satisfies_constraint_J (op)")))
63
64 ;; Return 1 if OP is an unsigned 14-bit constant.
65 (define_predicate "u14bit_cint_operand"
66 (and (match_code "const_int")
67 (match_test "(unsigned HOST_WIDE_INT)INTVAL (op) < (1U << 14)")))
68
69 ;; Return 1 if OP is a constant or any register.
70 (define_predicate "reg_or_cint_operand"
71 (ior (match_operand 0 "register_operand")
72 (match_operand 0 "const_int_operand")))
73
74 ;; Returns 1 if OP is a "last" unspec wrapper for a symbol, got, or
75 ;; tls reference.
76 (define_predicate "const_last_symbolic_operand"
77 (and (match_code "const")
78 (match_test "GET_CODE (XEXP (op,0)) == UNSPEC")
79 (ior (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_LAST")
80 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST")
81 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW2_LAST")
82 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST_PCREL")
83 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW2_LAST_PCREL")
84 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_LAST_GOT")
85 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST_GOT")
86 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST_TLS_GD")
87 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST_TLS_IE")
88 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST_TLS_LE")
89 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_LAST_PLT_PCREL")
90 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW2_LAST_PLT_PCREL"))))
91
92 ;; Returns 1 if OP is an unspec wrapper for a symbol, got, or tls
93 ;; reference.
94 (define_predicate "const_symbolic_operand"
95 (and (match_code "const")
96 (match_test "GET_CODE (XEXP (op,0)) == UNSPEC")
97 (ior (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0")
98 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1")
99 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW2")
100 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW3")
101 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_PCREL")
102 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_PCREL")
103 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_GOT")
104 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_TLS_GD")
105 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_TLS_IE")
106 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_TLS_LE")
107 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW0_PLT_PCREL")
108 (match_test "XINT (XEXP (op,0), 1) == UNSPEC_HW1_PLT_PCREL"))))
109
110 ;; Return 1 if OP is a 8-element vector constant with identical signed
111 ;; 8-bit elements or any register.
112 (define_predicate "reg_or_v8s8bit_operand"
113 (ior (match_operand 0 "register_operand")
114 (and (match_code "const_vector")
115 (match_test "CONST_VECTOR_NUNITS (op) == 8
116 && satisfies_constraint_I (CONST_VECTOR_ELT (op, 0))
117 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 1)
118 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 2)
119 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 3)
120 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 4)
121 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 5)
122 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 6)
123 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 7)"))))
124
125 ;; Return 1 if OP is a 4-element vector constant with identical signed
126 ;; 8-bit elements or any register.
127 (define_predicate "reg_or_v4s8bit_operand"
128 (ior (match_operand 0 "register_operand")
129 (and (match_code "const_vector")
130 (match_test "CONST_VECTOR_NUNITS (op) == 4
131 && satisfies_constraint_I (CONST_VECTOR_ELT (op, 0))
132 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 1)
133 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 2)
134 && CONST_VECTOR_ELT (op, 0) == CONST_VECTOR_ELT (op, 3)"))))
135
136 ;; Return 1 if the operand is a valid second operand to an add insn.
137 (define_predicate "add_operand"
138 (if_then_else (match_code "const_int")
139 (match_test "satisfies_constraint_J (op)")
140 (ior (match_operand 0 "register_operand")
141 (match_operand 0 "const_last_symbolic_operand"))))
142
143 ;; Return 1 if the operand is a register or signed 8-bit immediate operand.
144 (define_predicate "reg_or_s8bit_operand"
145 (if_then_else (match_code "const_int")
146 (match_test "satisfies_constraint_I (op)")
147 (match_operand 0 "register_operand")))
148
149 ;; Return 1 if the operand is a register or unsigned 5-bit immediate operand.
150 (define_predicate "reg_or_u5bit_operand"
151 (if_then_else (match_code "const_int")
152 (match_test "INTVAL (op) == (INTVAL (op) & 0x1F)")
153 (match_operand 0 "register_operand")))
154
155 ;; Return 1 if the operand is a register or unsigned 6-bit immediate operand.
156 (define_predicate "reg_or_u6bit_operand"
157 (if_then_else (match_code "const_int")
158 (match_test "INTVAL (op) == (INTVAL (op) & 0x3F)")
159 (match_operand 0 "register_operand")))
160
161 ;; Return 1 for an operand suitable for ANDing with a register.
162 (define_predicate "and_operand"
163 (if_then_else (match_code "const_int")
164 (match_test "satisfies_constraint_I (op) || satisfies_constraint_M (op)")
165 (match_operand 0 "register_operand")))
166
167 ; Return 1 if the operand is 2, 4 or 8.
168 (define_predicate "cint_248_operand"
169 (and (match_code "const_int")
170 (match_test
171 "INTVAL (op) == 2 || INTVAL (op) == 4 || INTVAL (op) == 8")))
172
173 ;; Return true if OP is a TLS symbolic operand.
174 (define_predicate "tls_symbolic_operand"
175 (and (match_code "symbol_ref")
176 (match_test "SYMBOL_REF_TLS_MODEL (op) != TLS_MODEL_NONE")))
177
178 ;; Return true if OP is a symbolic operand for the TLS Global Dynamic model.
179 (define_predicate "tls_gd_symbolic_operand"
180 (and (match_code "symbol_ref")
181 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_GLOBAL_DYNAMIC")))
182
183 ;; Return true if OP is a symbolic operand for the TLS Local Dynamic model.
184 (define_predicate "tls_ld_symbolic_operand"
185 (and (match_code "symbol_ref")
186 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
187
188 ;; Return true if OP is a symbolic operand that can be used for the
189 ;; TLS Initial Exec model.
190 (define_predicate "tls_ie_symbolic_operand"
191 (and (match_code "symbol_ref")
192 (ior (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC")
193 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC"))))
194
195 ;; Return true if OP is a symbolic operand for the TLS Local Exec model.
196 (define_predicate "tls_le_symbolic_operand"
197 (and (match_code "symbol_ref")
198 (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC")))
199
200 ;; Returns true if OP is any general operand except for an
201 ;; auto-incrementing address operand.
202 (define_predicate "nonautoinc_operand"
203 (and (match_operand 0 "general_operand")
204 (not (ior (match_code "pre_dec") (match_code "pre_inc")
205 (match_code "post_dec") (match_code "post_inc")
206 (match_code "post_modify") (match_code "pre_modify")))))
207
208 ;; Returns true if OP is a non-auto-incrementing memory operand.
209 (define_predicate "nonautoincmem_operand"
210 (match_operand 0 "memory_operand")
211 {
212 return nonautoinc_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
213 })
214
215 ;; Returns true if OP is a non-auto-incrementing memory, general
216 ;; operand.
217 (define_predicate "nonautoincmem_general_operand"
218 (match_operand 0 "general_operand")
219 {
220 if (memory_operand (op, mode))
221 return nonautoinc_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
222 else
223 return true;
224 })
225
226 ;; Returns true if OP is a non-auto-incrementing memory, non-immediate
227 ;; operand.
228 (define_predicate "nonautoincmem_nonimmediate_operand"
229 (match_operand 0 "nonimmediate_operand")
230 {
231 if (memory_operand (op, mode))
232 return nonautoinc_operand (XEXP (op, 0), GET_MODE (XEXP (op, 0)));
233 else
234 return true;
235 })
236
237 ;; Return true if OP is a valid operand for the source of a move insn.
238 (define_predicate "move_operand"
239 (match_operand 0 "general_operand")
240 {
241 /* If both modes are non-void they must be the same. */
242 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
243 return false;
244
245 switch (GET_CODE (op))
246 {
247 case CONST_INT:
248 return (satisfies_constraint_J (op)
249 || satisfies_constraint_K (op)
250 || (mode == DImode &&
251 (satisfies_constraint_N (op)
252 || satisfies_constraint_P (op))));
253
254 case MEM:
255 return memory_address_p (mode, XEXP (op, 0));
256
257 case CONST:
258 return const_last_symbolic_operand (op, mode);
259
260 default:
261 return register_operand (op, mode);
262 }
263 })
264
265 ;; Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
266 ;; possibly with an offset.
267 (define_predicate "symbolic_operand"
268 (ior (match_code "symbol_ref,label_ref")
269 (and (match_code "const")
270 (match_test "GET_CODE (XEXP (op,0)) == PLUS
271 && (GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
272 || GET_CODE (XEXP (XEXP (op,0), 0)) == LABEL_REF)
273 && CONST_INT_P (XEXP (XEXP (op,0), 1))"))))
274
275 ;; Return 1 for an unsigned 16 bit or a const symbolc operand.
276 (define_predicate "u16bit_or_const_symbolic_operand"
277 (ior (match_operand 0 "u16bit_cint_operand")
278 (match_operand 0 "const_symbolic_operand")))
279
280 ;; Return true if OP is an address suitable for a call insn.
281 ;; Call insn on TILE can take a PC-relative constant address
282 ;; or any regular memory address.
283 (define_predicate "call_address_operand"
284 (ior (match_operand 0 "symbolic_operand")
285 (match_test "memory_address_p (Pmode, op)")))
286
287 ;; Return true if OP is an operand suitable for a call insn.
288 (define_predicate "call_operand"
289 (and (match_code "mem")
290 (match_test "call_address_operand (XEXP (op, 0), mode)")))
291
292 ;; Return 1 if OP is a signed comparison operation.
293 ;; We can use these directly in compares against zero.
294 (define_predicate "signed_comparison_operator"
295 (match_code "eq,ne,le,lt,ge,gt"))
296
297 ;; Return 1 if OP is a equal or not-equal operation.
298 (define_predicate "eqne_operator"
299 (match_code "eq,ne"))