Debian Codegraph @

gcc/config/xtensa/predicates.md

raw
1 ;; Predicate definitions for Xtensa.
2 ;; Copyright (C) 2005-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
7 ;; it 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,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU 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 (define_predicate "add_operand"
21 (ior (and (match_code "const_int")
22 (match_test "xtensa_simm8 (INTVAL (op))
23 || xtensa_simm8x256 (INTVAL (op))"))
24 (match_operand 0 "register_operand")))
25
26 (define_predicate "addsubx_operand"
27 (and (match_code "const_int")
28 (match_test "IN_RANGE (INTVAL (op), 1, 3)")))
29
30 (define_predicate "arith_operand"
31 (ior (and (match_code "const_int")
32 (match_test "xtensa_simm8 (INTVAL (op))"))
33 (match_operand 0 "register_operand")))
34
35 ;; Non-immediate operand excluding the constant pool.
36 (define_predicate "nonimmed_operand"
37 (ior (and (match_operand 0 "memory_operand")
38 (match_test "!constantpool_mem_p (op)"))
39 (match_operand 0 "register_operand")))
40
41 ;; Memory operand excluding the constant pool.
42 (define_predicate "mem_operand"
43 (and (match_operand 0 "memory_operand")
44 (match_test "!constantpool_mem_p (op)")))
45
46 ;; Memory operand in the constant pool.
47 (define_predicate "constantpool_operand"
48 (match_test "constantpool_mem_p (op)"))
49
50 (define_predicate "mask_operand"
51 (ior (and (match_code "const_int")
52 (match_test "xtensa_mask_immediate (INTVAL (op))"))
53 (match_operand 0 "register_operand")))
54
55 (define_predicate "shifted_mask_operand"
56 (match_code "const_int")
57 {
58 HOST_WIDE_INT mask = INTVAL (op);
59 int shift = ctz_hwi (mask);
60
61 return IN_RANGE (shift, 1, 31)
62 && xtensa_mask_immediate ((uint32_t)mask >> shift);
63 })
64
65 (define_predicate "extui_fldsz_operand"
66 (and (match_code "const_int")
67 (match_test "IN_RANGE (INTVAL (op), 1, 16)")))
68
69 (define_predicate "sext_operand"
70 (if_then_else (match_test "TARGET_SEXT")
71 (match_operand 0 "nonimmed_operand")
72 (match_operand 0 "mem_operand")))
73
74 (define_predicate "sext_fldsz_operand"
75 (and (match_code "const_int")
76 (match_test "IN_RANGE (INTVAL (op), 8, 23)")))
77
78 (define_predicate "lsbitnum_operand"
79 (and (match_code "const_int")
80 (match_test "BITS_BIG_ENDIAN
81 ? (INTVAL (op) == BITS_PER_WORD - 1)
82 : (INTVAL (op) == 0)")))
83
84 (define_predicate "branch_operand"
85 (ior (and (match_code "const_int")
86 (match_test "xtensa_b4const_or_zero (INTVAL (op))"))
87 (match_operand 0 "register_operand")))
88
89 (define_predicate "ubranch_operand"
90 (ior (and (match_code "const_int")
91 (match_test "xtensa_b4constu (INTVAL (op))"))
92 (match_operand 0 "register_operand")))
93
94 (define_predicate "call_insn_operand"
95 (match_code "const_int,const,symbol_ref,reg")
96 {
97 if ((GET_CODE (op) == REG)
98 && (op != arg_pointer_rtx)
99 && ((REGNO (op) < FRAME_POINTER_REGNUM)
100 || (REGNO (op) > LAST_VIRTUAL_REGISTER)))
101 return true;
102
103 if (CONSTANT_ADDRESS_P (op))
104 {
105 /* Direct calls only allowed to static functions with PIC. */
106 if (flag_pic)
107 {
108 tree callee;
109 const char * callee_sec, * caller_sec;
110
111 if (GET_CODE (op) != SYMBOL_REF
112 || !SYMBOL_REF_LOCAL_P (op) || SYMBOL_REF_EXTERNAL_P (op))
113 return false;
114
115 /* Don't attempt a direct call if the callee is known to be in
116 a different section, since there's a good chance it will be
117 out of range. */
118
119 if (flag_function_sections
120 || DECL_ONE_ONLY (current_function_decl))
121 return false;
122 caller_sec = DECL_SECTION_NAME (current_function_decl);
123 callee = SYMBOL_REF_DECL (op);
124 if (callee)
125 {
126 if (DECL_ONE_ONLY (callee))
127 return false;
128 callee_sec = DECL_SECTION_NAME (callee);
129 if (((caller_sec == NULL) ^ (callee_sec == NULL))
130 || (caller_sec != NULL
131 && caller_sec != callee_sec))
132 return false;
133 }
134 else if (caller_sec)
135 return false;
136 }
137 return true;
138 }
139
140 return false;
141 })
142
143 (define_predicate "move_operand"
144 (ior
145 (ior (match_operand 0 "register_operand")
146 (match_operand 0 "memory_operand"))
147 (ior (and (match_code "const_int")
148 (match_test "(GET_MODE_CLASS (mode) == MODE_INT
149 && xtensa_simm12b (INTVAL (op)))
150 || ! xtensa_split1_finished_p ()"))
151 (and (match_code "const_int,const_double,const,symbol_ref,label_ref")
152 (match_test "(TARGET_CONST16 || TARGET_AUTO_LITPOOLS)
153 && CONSTANT_P (op)")))))
154
155 ;; Accept the floating point constant 1 in the appropriate mode.
156 (define_predicate "const_float_1_operand"
157 (match_code "const_double")
158 {
159 return real_equal (CONST_DOUBLE_REAL_VALUE (op), &dconst1);
160 })
161
162 (define_predicate "fix_scaling_operand"
163 (match_code "const_double")
164 {
165 REAL_VALUE_TYPE r = *CONST_DOUBLE_REAL_VALUE (op);
166 int exp = REAL_EXP (&r) - 1;
167
168 SET_REAL_EXP (&r, 1);
169 return real_equal (&r, &dconst1) && IN_RANGE (exp, 2, 15);
170 })
171
172 (define_predicate "float_scaling_operand"
173 (match_code "const_double")
174 {
175 REAL_VALUE_TYPE r = *CONST_DOUBLE_REAL_VALUE (op);
176 int exp = REAL_EXP (&r) - 1;
177
178 SET_REAL_EXP (&r, 1);
179 return real_equal (&r, &dconst1) && IN_RANGE (-exp, 1, 15);
180 })
181
182 (define_predicate "fpmem_offset_operand"
183 (and (match_code "const_int")
184 (match_test "xtensa_mem_offset (INTVAL (op), SFmode)")))
185
186 (define_predicate "reload_operand"
187 (match_code "mem")
188 {
189 const_rtx addr = XEXP (op, 0);
190 if (REG_P (addr))
191 return REGNO (addr) == A1_REG;
192 if (GET_CODE (addr) == PLUS)
193 return REG_P (XEXP (addr, 0))
194 && REGNO (XEXP (addr, 0)) == A1_REG
195 && CONST_INT_P (XEXP (addr, 1));
196 return false;
197 })
198
199 (define_predicate "branch_operator"
200 (match_code "eq,ne,lt,ge"))
201
202 (define_predicate "ubranch_operator"
203 (match_code "ltu,geu"))
204
205 (define_predicate "boolean_operator"
206 (match_code "eq,ne"))
207
208 (define_predicate "logical_shift_operator"
209 (match_code "ashift,lshiftrt"))
210
211 (define_predicate "addsub_operator"
212 (match_code "plus,minus"))
213
214 (define_predicate "xtensa_cstoresi_operator"
215 (match_code "eq,ne,gt,ge,lt,le,gtu,geu,ltu,leu"))
216
217 (define_predicate "xtensa_shift_per_byte_operator"
218 (match_code "ashift,ashiftrt,lshiftrt"))
219
220 (define_predicate "xtensa_bit_join_operator"
221 (match_code "plus,ior"))
222
223 (define_predicate "subreg_HQI_lowpart_operator"
224 (match_code "subreg")
225 {
226 int ofs = SUBREG_BYTE (op), pos = 0;
227 switch (GET_MODE (op))
228 {
229 case QImode:
230 if (BYTES_BIG_ENDIAN)
231 pos = 3;
232 break;
233 case HImode:
234 if (BYTES_BIG_ENDIAN)
235 pos = 2;
236 break;
237 default:
238 return false;
239 }
240 return ofs == pos;
241 })
242
243 (define_predicate "xtensa_sminmax_operator"
244 (match_code "smin,smax"))
245
246 (define_predicate "tls_symbol_operand"
247 (and (match_code "symbol_ref")
248 (match_test "SYMBOL_REF_TLS_MODEL (op) != 0")))