1 ;; Predicate definitions for NEC V850.
2 ;; Copyright (C) 2005 Free Software Foundation, Inc.
4 ;; This file is part of GCC.
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 2, or (at your option)
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.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
19 ;; Boston, MA 02111-1307, USA.
21 ;; Return true if OP is either a register or 0.
23 (define_predicate "reg_or_0_operand"
24 (match_code "reg,subreg,const_int,const_double")
26 if (GET_CODE (op) == CONST_INT)
27 return INTVAL (op) == 0;
29 else if (GET_CODE (op) == CONST_DOUBLE)
30 return CONST_DOUBLE_OK_FOR_G (op);
33 return register_operand (op, mode);
36 ;; Return true if OP is either a register or a signed five bit
39 (define_predicate "reg_or_int5_operand"
40 (match_code "reg,subreg,const_int")
42 if (GET_CODE (op) == CONST_INT)
43 return CONST_OK_FOR_J (INTVAL (op));
46 return register_operand (op, mode);
49 ;; Return true if OP is either a register or a signed nine bit
52 (define_predicate "reg_or_int9_operand"
53 (match_code "reg,subreg,const_int")
55 if (GET_CODE (op) == CONST_INT)
56 return CONST_OK_FOR_O (INTVAL (op));
58 return register_operand (op, mode);
61 ;; Return true if OP is either a register or a const integer.
63 (define_predicate "reg_or_const_operand"
64 (match_code "reg,const_int")
66 if (GET_CODE (op) == CONST_INT)
69 return register_operand (op, mode);
72 ;; Return true if OP is a valid call operand.
74 (define_predicate "call_address_operand"
75 (match_code "reg,symbol_ref")
77 /* Only registers are valid call operands if TARGET_LONG_CALLS. */
78 if (TARGET_LONG_CALLS)
79 return GET_CODE (op) == REG;
80 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
83 ;; TODO: Add a comment here.
85 (define_predicate "movsi_source_operand"
86 (match_code "label_ref,symbol_ref,const_int,const_double,const,high,mem,reg,subreg")
88 /* Some constants, as well as symbolic operands
89 must be done with HIGH & LO_SUM patterns. */
91 && GET_CODE (op) != HIGH
92 && !(GET_CODE (op) == CONST_INT
93 && (CONST_OK_FOR_J (INTVAL (op))
94 || CONST_OK_FOR_K (INTVAL (op))
95 || CONST_OK_FOR_L (INTVAL (op)))))
96 return special_symbolref_operand (op, mode);
98 return general_operand (op, mode);
101 ;; TODO: Add a comment here.
103 (define_predicate "special_symbolref_operand"
104 (match_code "symbol_ref")
106 if (GET_CODE (op) == CONST
107 && GET_CODE (XEXP (op, 0)) == PLUS
108 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
109 && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))))
110 op = XEXP (XEXP (op, 0), 0);
112 if (GET_CODE (op) == SYMBOL_REF)
113 return (SYMBOL_REF_FLAGS (op)
114 & (SYMBOL_FLAG_ZDA | SYMBOL_FLAG_TDA | SYMBOL_FLAG_SDA)) != 0;
119 ;; TODO: Add a comment here.
121 (define_predicate "power_of_two_operand"
122 (match_code "const_int")
124 if (GET_CODE (op) != CONST_INT)
127 if (exact_log2 (INTVAL (op)) == -1)
132 ;; Return nonzero if the given RTX is suitable for collapsing into a
133 ;; jump to a function prologue.
135 (define_predicate "pattern_is_ok_for_prologue"
136 (match_code "parallel")
138 int count = XVECLEN (op, 0);
142 /* If there are no registers to save then the function prologue
147 /* The pattern matching has already established that we are adjusting the
148 stack and pushing at least one register. We must now check that the
149 remaining entries in the vector to make sure that they are also register
150 pushes, except for the last entry which should be a CLOBBER of r10.
152 The test below performs the C equivalent of this machine description
155 (set (mem:SI (plus:SI (reg:SI 3)
156 (match_operand:SI 2 "immediate_operand" "i")))
157 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
161 for (i = 2; i < count - (TARGET_LONG_CALLS ? 2: 1); i++)
167 vector_element = XVECEXP (op, 0, i);
169 if (GET_CODE (vector_element) != SET)
172 dest = SET_DEST (vector_element);
173 src = SET_SRC (vector_element);
175 if (GET_CODE (dest) != MEM
176 || GET_MODE (dest) != SImode
177 || GET_CODE (src) != REG
178 || GET_MODE (src) != SImode
179 || ! register_is_ok_for_epilogue (src, SImode))
182 plus = XEXP (dest, 0);
184 if ( GET_CODE (plus) != PLUS
185 || GET_CODE (XEXP (plus, 0)) != REG
186 || GET_MODE (XEXP (plus, 0)) != SImode
187 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
188 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
191 /* If the register is being pushed somewhere other than the stack
192 space just acquired by the first operand then abandon this quest.
193 Note: the test is <= because both values are negative. */
194 if (INTVAL (XEXP (plus, 1))
195 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
201 /* Make sure that the last entries in the vector are clobbers. */
202 for (; i < count; i++)
204 vector_element = XVECEXP (op, 0, i);
206 if (GET_CODE (vector_element) != CLOBBER
207 || GET_CODE (XEXP (vector_element, 0)) != REG
208 || !(REGNO (XEXP (vector_element, 0)) == 10
209 || (TARGET_LONG_CALLS ? (REGNO (XEXP (vector_element, 0)) == 11) : 0 )))
216 ;; Return nonzero if the given RTX is suitable for collapsing into
217 ;; jump to a function epilogue.
219 (define_predicate "pattern_is_ok_for_epilogue"
220 (match_code "parallel")
222 int count = XVECLEN (op, 0);
225 /* If there are no registers to restore then the function epilogue
230 /* The pattern matching has already established that we are performing a
231 function epilogue and that we are popping at least one register. We must
232 now check the remaining entries in the vector to make sure that they are
233 also register pops. There is no good reason why there should ever be
234 anything else in this vector, but being paranoid always helps...
236 The test below performs the C equivalent of this machine description
239 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
240 (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
243 for (i = 3; i < count; i++)
245 rtx vector_element = XVECEXP (op, 0, i);
250 if (GET_CODE (vector_element) != SET)
253 dest = SET_DEST (vector_element);
254 src = SET_SRC (vector_element);
256 if (GET_CODE (dest) != REG
257 || GET_MODE (dest) != SImode
258 || ! register_is_ok_for_epilogue (dest, SImode)
259 || GET_CODE (src) != MEM
260 || GET_MODE (src) != SImode)
263 plus = XEXP (src, 0);
265 if (GET_CODE (plus) != PLUS
266 || GET_CODE (XEXP (plus, 0)) != REG
267 || GET_MODE (XEXP (plus, 0)) != SImode
268 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
269 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
276 ;; Return true if the given RTX is a register which can be restored by
277 ;; a function epilogue.
279 (define_predicate "register_is_ok_for_epilogue"
282 /* The save/restore routines can only cope with registers 20 - 31. */
283 return ((GET_CODE (op) == REG)
284 && (((REGNO (op) >= 20) && REGNO (op) <= 31)));
287 ;; Return nonzero if the given RTX is suitable for collapsing into a
288 ;; DISPOSE instruction.
290 (define_predicate "pattern_is_ok_for_dispose"
291 (match_code "parallel")
293 int count = XVECLEN (op, 0);
296 /* If there are no registers to restore then
297 the dispose instruction is not suitable. */
301 /* The pattern matching has already established that we are performing a
302 function epilogue and that we are popping at least one register. We must
303 now check the remaining entries in the vector to make sure that they are
304 also register pops. There is no good reason why there should ever be
305 anything else in this vector, but being paranoid always helps...
307 The test below performs the C equivalent of this machine description
310 (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
311 (mem:SI (plus:SI (reg:SI 3)
312 (match_operand:SI n "immediate_operand" "i"))))
315 for (i = 3; i < count; i++)
317 rtx vector_element = XVECEXP (op, 0, i);
322 if (GET_CODE (vector_element) != SET)
325 dest = SET_DEST (vector_element);
326 src = SET_SRC (vector_element);
328 if ( GET_CODE (dest) != REG
329 || GET_MODE (dest) != SImode
330 || ! register_is_ok_for_epilogue (dest, SImode)
331 || GET_CODE (src) != MEM
332 || GET_MODE (src) != SImode)
335 plus = XEXP (src, 0);
337 if ( GET_CODE (plus) != PLUS
338 || GET_CODE (XEXP (plus, 0)) != REG
339 || GET_MODE (XEXP (plus, 0)) != SImode
340 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
341 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
348 ;; Return nonzero if the given RTX is suitable for collapsing into a
349 ;; PREPARE instruction.
351 (define_predicate "pattern_is_ok_for_prepare"
352 (match_code "parallel")
354 int count = XVECLEN (op, 0);
357 /* If there are no registers to restore then the prepare instruction
362 /* The pattern matching has already established that we are adjusting the
363 stack and pushing at least one register. We must now check that the
364 remaining entries in the vector to make sure that they are also register
367 The test below performs the C equivalent of this machine description
370 (set (mem:SI (plus:SI (reg:SI 3)
371 (match_operand:SI 2 "immediate_operand" "i")))
372 (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
376 for (i = 2; i < count; i++)
378 rtx vector_element = XVECEXP (op, 0, i);
383 if (GET_CODE (vector_element) != SET)
386 dest = SET_DEST (vector_element);
387 src = SET_SRC (vector_element);
389 if ( GET_CODE (dest) != MEM
390 || GET_MODE (dest) != SImode
391 || GET_CODE (src) != REG
392 || GET_MODE (src) != SImode
393 || ! register_is_ok_for_epilogue (src, SImode)
397 plus = XEXP (dest, 0);
399 if ( GET_CODE (plus) != PLUS
400 || GET_CODE (XEXP (plus, 0)) != REG
401 || GET_MODE (XEXP (plus, 0)) != SImode
402 || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
403 || GET_CODE (XEXP (plus, 1)) != CONST_INT)
406 /* If the register is being pushed somewhere other than the stack
407 space just acquired by the first operand then abandon this quest.
408 Note: the test is <= because both values are negative. */
409 if (INTVAL (XEXP (plus, 1))
410 <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
417 ;; TODO: Add a comment here.
419 (define_predicate "not_power_of_two_operand"
420 (match_code "const_int")
426 else if (mode == HImode)
428 else if (mode == SImode)
433 if (GET_CODE (op) != CONST_INT)
436 if (exact_log2 (~INTVAL (op) & mask) == -1)