1 ;; Predicate definitions for Motorola MCore.
2 ;; Copyright (C) 2005-2018 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 3, 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 COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
20 ;; Nonzero if OP is a normal arithmetic register.
22 (define_predicate "mcore_arith_reg_operand"
23 (match_code "reg,subreg")
25 if (! register_operand (op, mode))
28 if (GET_CODE (op) == SUBREG)
31 if (GET_CODE (op) == REG)
32 return REGNO (op) != CC_REG;
37 ;; Nonzero if OP can be source of a simple move operation.
39 (define_predicate "mcore_general_movsrc_operand"
40 (match_code "mem,const_int,reg,subreg,symbol_ref,label_ref,const")
42 /* Any (MEM LABEL_REF) is OK. That is a pc-relative load. */
43 if (GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == LABEL_REF)
46 return general_operand (op, mode);
49 ;; Nonzero if OP can be destination of a simple move operation.
51 (define_predicate "mcore_general_movdst_operand"
52 (match_code "mem,reg,subreg")
54 if (GET_CODE (op) == REG && REGNO (op) == CC_REG)
57 return general_operand (op, mode);
60 ;; Nonzero if OP should be recognized during reload for an ixh/ixw
61 ;; operand. See the ixh/ixw patterns.
63 (define_predicate "mcore_reload_operand"
64 (match_code "mem,reg,subreg")
66 if (mcore_arith_reg_operand (op, mode))
69 if (! reload_in_progress)
72 return GET_CODE (op) == MEM;
75 ;; Nonzero if OP is a valid source operand for an arithmetic insn.
77 (define_predicate "mcore_arith_J_operand"
78 (match_code "const_int,reg,subreg")
80 if (register_operand (op, mode))
83 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_J (INTVAL (op)))
89 ;; Nonzero if OP is a valid source operand for an arithmetic insn.
91 (define_predicate "mcore_arith_K_operand"
92 (match_code "const_int,reg,subreg")
94 if (register_operand (op, mode))
97 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
103 ;; Nonzero if OP is a valid source operand for a shift or rotate insn.
105 (define_predicate "mcore_arith_K_operand_not_0"
106 (match_code "const_int,reg,subreg")
108 if (register_operand (op, mode))
111 if ( GET_CODE (op) == CONST_INT
112 && CONST_OK_FOR_K (INTVAL (op))
119 ;; TODO: Add a comment here.
121 (define_predicate "mcore_arith_M_operand"
122 (match_code "const_int,reg,subreg")
124 if (register_operand (op, mode))
127 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_M (INTVAL (op)))
133 ;; TODO: Add a comment here.
135 (define_predicate "mcore_arith_K_S_operand"
136 (match_code "const_int,reg,subreg")
138 if (register_operand (op, mode))
141 if (GET_CODE (op) == CONST_INT)
143 if (CONST_OK_FOR_K (INTVAL (op)) || (mcore_num_zeros (INTVAL (op)) <= 2))
150 ;; Nonzero if OP is a valid source operand for a cmov with two consts
153 (define_predicate "mcore_arith_O_operand"
154 (match_code "const_int,reg,subreg")
156 if (register_operand (op, mode))
159 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_O (INTVAL (op)))
165 ;; Nonzero if OP is a valid source operand for loading.
167 (define_predicate "mcore_arith_imm_operand"
168 (match_code "const_int,reg,subreg")
170 if (register_operand (op, mode))
173 if (GET_CODE (op) == CONST_INT && const_ok_for_mcore (INTVAL (op)))
179 ;; TODO: Add a comment here.
181 (define_predicate "mcore_arith_any_imm_operand"
182 (match_code "const_int,reg,subreg")
184 if (register_operand (op, mode))
187 if (GET_CODE (op) == CONST_INT)
193 ;; Nonzero if OP is a valid source operand for a btsti.
195 (define_predicate "mcore_literal_K_operand"
196 (match_code "const_int")
198 if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
204 ;; Nonzero if OP is a valid source operand for an add/sub insn.
206 (define_predicate "mcore_addsub_operand"
207 (match_code "const_int,reg,subreg")
209 if (register_operand (op, mode))
212 if (GET_CODE (op) == CONST_INT)
214 /* The following has been removed because it precludes large constants from being
215 returned as valid source operands for and add/sub insn. While large
216 constants may not directly be used in an add/sub, they may if first loaded
217 into a register. Thus, this predicate should indicate that they are valid,
218 and the constraint in mcore.md should control whether an additional load to
219 register is needed. (see mcore.md, addsi). -- DAC 4/2/1998
221 if (CONST_OK_FOR_J (INTVAL (op)) || CONST_OK_FOR_L (INTVAL (op)))
224 However we do still need to check to make sure that the constant is not too
225 big, especially if we are running on a 64-bit OS... Nickc 8/1/07. */
227 if (trunc_int_for_mode (INTVAL (op), mode) != INTVAL (op))
237 ;; Nonzero if OP is a valid source operand for a compare operation.
239 (define_predicate "mcore_compare_operand"
240 (match_code "const_int,reg,subreg")
242 if (register_operand (op, mode))
245 if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
251 ;; Return 1 if OP is a load multiple operation. It is known to be a
252 ;; PARALLEL and the first section will be tested.
254 (define_predicate "mcore_load_multiple_operation"
255 (match_code "parallel")
257 int count = XVECLEN (op, 0);
262 /* Perform a quick check so we don't blow up below. */
264 || GET_CODE (XVECEXP (op, 0, 0)) != SET
265 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
266 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
269 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
270 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
272 for (i = 1; i < count; i++)
274 rtx elt = XVECEXP (op, 0, i);
276 if (GET_CODE (elt) != SET
277 || GET_CODE (SET_DEST (elt)) != REG
278 || GET_MODE (SET_DEST (elt)) != SImode
279 || REGNO (SET_DEST (elt)) != (unsigned) (dest_regno + i)
280 || GET_CODE (SET_SRC (elt)) != MEM
281 || GET_MODE (SET_SRC (elt)) != SImode
282 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
283 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
284 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
285 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
292 ;; Similar, but tests for store multiple.
294 (define_predicate "mcore_store_multiple_operation"
295 (match_code "parallel")
297 int count = XVECLEN (op, 0);
302 /* Perform a quick check so we don't blow up below. */
304 || GET_CODE (XVECEXP (op, 0, 0)) != SET
305 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
306 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
309 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
310 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
312 for (i = 1; i < count; i++)
314 rtx elt = XVECEXP (op, 0, i);
316 if (GET_CODE (elt) != SET
317 || GET_CODE (SET_SRC (elt)) != REG
318 || GET_MODE (SET_SRC (elt)) != SImode
319 || REGNO (SET_SRC (elt)) != (unsigned) (src_regno + i)
320 || GET_CODE (SET_DEST (elt)) != MEM
321 || GET_MODE (SET_DEST (elt)) != SImode
322 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
323 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
324 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
325 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
332 ;; TODO: Add a comment here.
334 (define_predicate "mcore_call_address_operand"
335 (match_code "reg,subreg,const_int,symbol_ref")
337 return register_operand (op, mode) || CONSTANT_P (op);