RISC-V: Error if function declared with different interrupt modes.
[official-gcc.git] / gcc / config / mcore / predicates.md
blob0cbda50ea30a957d4958051fb5117b69b804398f
1 ;; Predicate definitions for Motorola MCore.
2 ;; Copyright (C) 2005-2018 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.
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))
26     return 0;
28   if (GET_CODE (op) == SUBREG)
29     op = SUBREG_REG (op);
31   if (GET_CODE (op) == REG)
32     return REGNO (op) != CC_REG;
34   return 1;
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)
44     return 1;
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)
55     return 0;
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))
67     return 1;
69   if (! reload_in_progress)
70     return 0;
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))
81     return 1;
83   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_J (INTVAL (op)))
84     return 1;
86   return 0;
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))
95     return 1;
97   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
98     return 1;
100   return 0;
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))
109     return 1;
111   if (   GET_CODE (op) == CONST_INT
112       && CONST_OK_FOR_K (INTVAL (op))
113       && INTVAL (op) != 0)
114     return 1;
116   return 0;
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))
125     return 1;
127   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_M (INTVAL (op)))
128     return 1;
130   return 0;
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))
139     return 1;
141   if (GET_CODE (op) == CONST_INT)
142     {
143       if (CONST_OK_FOR_K (INTVAL (op)) || (mcore_num_zeros (INTVAL (op)) <= 2))
144         return 1;
145     }
147   return 0;
150 ;; Nonzero if OP is a valid source operand for a cmov with two consts
151 ;; +/- 1.
153 (define_predicate "mcore_arith_O_operand"
154   (match_code "const_int,reg,subreg")
156   if (register_operand (op, mode))
157     return 1;
159   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_O (INTVAL (op)))
160     return 1;
162   return 0;
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))
171     return 1;
173   if (GET_CODE (op) == CONST_INT && const_ok_for_mcore (INTVAL (op)))
174     return 1;
176   return 0;
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))
185     return 1;
187   if (GET_CODE (op) == CONST_INT)
188     return 1;
190   return 0;
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)))
199     return 1;
201   return 0;
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))
210     return 1;
212   if (GET_CODE (op) == CONST_INT)
213     {
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
220       
221       if (CONST_OK_FOR_J (INTVAL (op)) || CONST_OK_FOR_L (INTVAL (op)))
222         return 1;
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))
228         return 0;
230       return 1;
232     }
234   return 0;
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))
243     return 1;
245   if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
246     return 1;
248   return 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);
258   int dest_regno;
259   rtx src_addr;
260   int i;
262   /* Perform a quick check so we don't blow up below.  */
263   if (count <= 1
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)
267     return 0;
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++)
273     {
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)
286         return 0;
287     }
289   return 1;
292 ;; Similar, but tests for store multiple.
294 (define_predicate "mcore_store_multiple_operation"
295   (match_code "parallel")
297   int count = XVECLEN (op, 0);
298   int src_regno;
299   rtx dest_addr;
300   int i;
302   /* Perform a quick check so we don't blow up below.  */
303   if (count <= 1
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)
307     return 0;
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++)
313     {
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)
326         return 0;
327     }
329   return 1;
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);