Debian Codegraph @

gcc/config/iq2000/predicates.md

raw
1 ;; Predicate definitions for Vitesse IQ2000.
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 ;; Return 1 if OP can be used as an operand where a 16-bit
21 ;; unsigned integer is needed.
22
23 (define_predicate "uns_arith_constant"
24 (match_code "const_int")
25 {
26 return SMALL_INT_UNSIGNED (op);
27 })
28
29 ;; Return 1 if OP can be used as an operand where a register or 16-bit
30 ;; unsigned integer is needed.
31
32 (define_predicate "uns_arith_operand"
33 (match_code "reg,const_int,subreg")
34 {
35 if (GET_CODE (op) == CONST_INT && SMALL_INT_UNSIGNED (op))
36 return 1;
37
38 return register_operand (op, mode);
39 })
40
41 ;; Return 1 if OP can be used as an operand where a 16-bit integer is
42 ;; needed.
43
44 (define_predicate "arith_operand"
45 (match_code "reg,const_int,subreg")
46 {
47 if (GET_CODE (op) == CONST_INT && SMALL_INT (op))
48 return 1;
49
50 return register_operand (op, mode);
51 })
52
53 ;; Return 1 if OP is a register or a constant. gen_int_relational
54 ;; takes care of forcing out-of-range constants into a register.
55
56 (define_predicate "reg_or_const_operand"
57 (ior (match_code "const_int")
58 (and (match_code "reg,subreg")
59 (match_operand 0 "register_operand"))))
60
61 ;; Return 1 if OP is a integer which fits in 16 bits.
62
63 (define_predicate "small_int"
64 (match_code "const_int")
65 {
66 return (GET_CODE (op) == CONST_INT && SMALL_INT (op));
67 })
68
69 ;; Return 1 if OP is a 32-bit integer which is too big to be loaded
70 ;; with one instruction.
71
72 (define_predicate "large_int"
73 (match_code "const_int")
74 {
75 HOST_WIDE_INT value;
76
77 if (GET_CODE (op) != CONST_INT)
78 return 0;
79
80 value = INTVAL (op);
81
82 /* IOR reg,$r0,value. */
83 if ((value & ~ ((HOST_WIDE_INT) 0x0000ffff)) == 0)
84 return 0;
85
86 /* SUBU reg,$r0,value. */
87 if (((unsigned HOST_WIDE_INT) (value + 32768)) <= 32767)
88 return 0;
89
90 /* LUI reg,value >> 16. */
91 if ((value & 0x0000ffff) == 0)
92 return 0;
93
94 return 1;
95 })
96
97 ;; Return 1 if OP is a register or the constant 0.
98
99 (define_predicate "reg_or_0_operand"
100 (match_code "reg,const_int,const_double,subreg")
101 {
102 switch (GET_CODE (op))
103 {
104 case CONST_INT:
105 return INTVAL (op) == 0;
106
107 case CONST_DOUBLE:
108 return op == CONST0_RTX (mode);
109
110 case REG:
111 case SUBREG:
112 return register_operand (op, mode);
113
114 default:
115 break;
116 }
117
118 return 0;
119 })
120
121 ;; Return 1 if OP is a memory operand that fits in a single
122 ;; instruction (i.e., register + small offset).
123
124 (define_predicate "simple_memory_operand"
125 (match_code "mem,subreg")
126 {
127 rtx addr, plus0, plus1;
128
129 /* Eliminate non-memory operations. */
130 if (GET_CODE (op) != MEM)
131 return 0;
132
133 /* Dword operations really put out 2 instructions, so eliminate them. */
134 if (GET_MODE_SIZE (GET_MODE (op)) > (unsigned) UNITS_PER_WORD)
135 return 0;
136
137 /* Decode the address now. */
138 addr = XEXP (op, 0);
139 switch (GET_CODE (addr))
140 {
141 case REG:
142 case LO_SUM:
143 return 1;
144
145 case CONST_INT:
146 return SMALL_INT (addr);
147
148 case PLUS:
149 plus0 = XEXP (addr, 0);
150 plus1 = XEXP (addr, 1);
151 if (GET_CODE (plus0) == REG
152 && GET_CODE (plus1) == CONST_INT && SMALL_INT (plus1)
153 && SMALL_INT_UNSIGNED (plus1) /* No negative offsets. */)
154 return 1;
155
156 else if (GET_CODE (plus1) == REG
157 && GET_CODE (plus0) == CONST_INT && SMALL_INT (plus0)
158 && SMALL_INT_UNSIGNED (plus1) /* No negative offsets. */)
159 return 1;
160
161 else
162 return 0;
163
164 case SYMBOL_REF:
165 return 0;
166
167 default:
168 break;
169 }
170
171 return 0;
172 })
173
174 ;; Return nonzero if the code of this rtx pattern is EQ or NE.
175
176 (define_predicate "equality_op"
177 (match_code "eq,ne")
178 {
179 if (mode != GET_MODE (op))
180 return 0;
181
182 return GET_CODE (op) == EQ || GET_CODE (op) == NE;
183 })
184
185 ;; Return nonzero if the code is a relational operations (EQ, LE,
186 ;; etc).
187
188 (define_predicate "cmp_op"
189 (match_code "eq,ne,gt,ge,gtu,geu,lt,le,ltu,leu")
190 {
191 if (mode != GET_MODE (op))
192 return 0;
193
194 return COMPARISON_P (op);
195 })
196
197 ;; Return nonzero if the operand is either the PC or a label_ref.
198
199 (define_special_predicate "pc_or_label_operand"
200 (match_code "pc,label_ref")
201 {
202 if (op == pc_rtx)
203 return 1;
204
205 if (GET_CODE (op) == LABEL_REF)
206 return 1;
207
208 return 0;
209 })
210
211 ;; Return nonzero if OP is a valid operand for a call instruction.
212
213 (define_predicate "call_insn_operand"
214 (match_code "const_int,const,symbol_ref,reg")
215 {
216 return (CONSTANT_ADDRESS_P (op)
217 || (GET_CODE (op) == REG && op != arg_pointer_rtx
218 && ! VIRTUAL_REGISTER_P (op)));
219 })
220
221 ;; Return nonzero if OP is valid as a source operand for a move
222 ;; instruction.
223
224 (define_predicate "move_operand"
225 (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
226 {
227 /* Accept any general operand after reload has started; doing so
228 avoids losing if reload does an in-place replacement of a register
229 with a SYMBOL_REF or CONST. */
230 return (general_operand (op, mode)
231 && (! (iq2000_check_split (op, mode))
232 || reload_in_progress || reload_completed));
233 })
234
235 ;; Return nonzero if OP is a constant power of 2.
236
237 (define_predicate "power_of_2_operand"
238 (match_code "const_int")
239 {
240 int intval;
241
242 if (GET_CODE (op) != CONST_INT)
243 return 0;
244 else
245 intval = INTVAL (op);
246
247 return ((intval & ((unsigned)(intval) - 1)) == 0);
248 })