OSDN Git Service

59f43c9a4524086d38cc5d0a00b21b81c215296d
[pf3gnuchains/gcc-fork.git] / gcc / config / mcore / predicates.md
1 ;; Predicate definitions for Motorola MCore.
2 ;; Copyright (C) 2005 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 2, 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 COPYING.  If not, write to
18 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
19 ;; Boston, MA 02111-1307, USA.
20
21 ;; Nonzero if OP is a normal arithmetic register.
22
23 (define_predicate "mcore_arith_reg_operand"
24   (match_code "reg,subreg")
25 {
26   if (! register_operand (op, mode))
27     return 0;
28
29   if (GET_CODE (op) == SUBREG)
30     op = SUBREG_REG (op);
31
32   if (GET_CODE (op) == REG)
33     return REGNO (op) != CC_REG;
34
35   return 1;
36 })
37
38 ;; Nonzero if OP can be source of a simple move operation.
39
40 (define_predicate "mcore_general_movsrc_operand"
41   (match_code "mem,const_int,reg,subreg,symbol_ref,label_ref")
42 {
43   /* Any (MEM LABEL_REF) is OK.  That is a pc-relative load.  */
44   if (GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == LABEL_REF)
45     return 1;
46
47   return general_operand (op, mode);
48 })
49
50 ;; Nonzero if OP can be destination of a simple move operation.
51
52 (define_predicate "mcore_general_movdst_operand"
53   (match_code "mem,const_int,reg,subreg")
54 {
55   if (GET_CODE (op) == REG && REGNO (op) == CC_REG)
56     return 0;
57
58   return general_operand (op, mode);
59 })
60
61 ;; Nonzero if OP should be recognized during reload for an ixh/ixw
62 ;; operand.  See the ixh/ixw patterns.
63
64 (define_predicate "mcore_reload_operand"
65   (match_code "mem,reg,subreg")
66 {
67   if (mcore_arith_reg_operand (op, mode))
68     return 1;
69
70   if (! reload_in_progress)
71     return 0;
72
73   return GET_CODE (op) == MEM;
74 })
75
76 ;; Nonzero if OP is a valid source operand for an arithmetic insn.
77
78 (define_predicate "mcore_arith_J_operand"
79   (match_code "const_int,reg,subreg")
80 {
81   if (register_operand (op, mode))
82     return 1;
83
84   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_J (INTVAL (op)))
85     return 1;
86
87   return 0;
88 })
89
90 ;; Nonzero if OP is a valid source operand for an arithmetic insn.
91
92 (define_predicate "mcore_arith_K_operand"
93   (match_code "const_int,reg,subreg")
94 {
95   if (register_operand (op, mode))
96     return 1;
97
98   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
99     return 1;
100
101   return 0;
102 })
103
104 ;; Nonzero if OP is a valid source operand for a shift or rotate insn.
105
106 (define_predicate "mcore_arith_K_operand_not_0"
107   (match_code "const_int,reg,subreg")
108 {
109   if (register_operand (op, mode))
110     return 1;
111
112   if (   GET_CODE (op) == CONST_INT
113       && CONST_OK_FOR_K (INTVAL (op))
114       && INTVAL (op) != 0)
115     return 1;
116
117   return 0;
118 })
119
120 ;; TODO: Add a comment here.
121
122 (define_predicate "mcore_arith_M_operand"
123   (match_code "const_int,reg,subreg")
124 {
125   if (register_operand (op, mode))
126     return 1;
127
128   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_M (INTVAL (op)))
129     return 1;
130
131   return 0;
132 })
133
134 ;; TODO: Add a comment here.
135
136 (define_predicate "mcore_arith_K_S_operand"
137   (match_code "const_int,reg,subreg")
138 {
139   if (register_operand (op, mode))
140     return 1;
141
142   if (GET_CODE (op) == CONST_INT)
143     {
144       if (CONST_OK_FOR_K (INTVAL (op)) || CONST_OK_FOR_M (~INTVAL (op)))
145         return 1;
146     }
147
148   return 0;
149 })
150
151 ;; Nonzero if OP is a valid source operand for a cmov with two consts
152 ;; +/- 1.
153
154 (define_predicate "mcore_arith_O_operand"
155   (match_code "const_int,reg,subreg")
156 {
157   if (register_operand (op, mode))
158     return 1;
159
160   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_O (INTVAL (op)))
161     return 1;
162
163   return 0;
164 })
165
166 ;; Nonzero if OP is a valid source operand for loading.
167
168 (define_predicate "mcore_arith_imm_operand"
169   (match_code "const_int,reg,subreg")
170 {
171   if (register_operand (op, mode))
172     return 1;
173
174   if (GET_CODE (op) == CONST_INT && const_ok_for_mcore (INTVAL (op)))
175     return 1;
176
177   return 0;
178 })
179
180 ;; TODO: Add a comment here.
181
182 (define_predicate "mcore_arith_any_imm_operand"
183   (match_code "const_int,reg,subreg")
184 {
185   if (register_operand (op, mode))
186     return 1;
187
188   if (GET_CODE (op) == CONST_INT)
189     return 1;
190
191   return 0;
192 })
193
194 ;; Nonzero if OP is a valid source operand for a btsti.
195
196 (define_predicate "mcore_literal_K_operand"
197   (match_code "const_int")
198 {
199   if (GET_CODE (op) == CONST_INT && CONST_OK_FOR_K (INTVAL (op)))
200     return 1;
201
202   return 0;
203 })
204
205 ;; Nonzero if OP is a valid source operand for an add/sub insn.
206
207 (define_predicate "mcore_addsub_operand"
208   (match_code "const_int,reg,subreg")
209 {
210   if (register_operand (op, mode))
211     return 1;
212
213   if (GET_CODE (op) == CONST_INT)
214     {
215       return 1;
216
217       /* The following is removed because it precludes large constants from being
218          returned as valid source operands for and add/sub insn.  While large
219          constants may not directly be used in an add/sub, they may if first loaded
220          into a register.  Thus, this predicate should indicate that they are valid,
221          and the constraint in mcore.md should control whether an additional load to
222          register is needed. (see mcore.md, addsi). -- DAC 4/2/1998  */
223       /*
224         if (CONST_OK_FOR_J(INTVAL(op)) || CONST_OK_FOR_L(INTVAL(op)))
225           return 1;
226       */
227     }
228
229   return 0;
230 })
231
232 ;; Nonzero if OP is a valid source operand for a compare operation.
233
234 (define_predicate "mcore_compare_operand"
235   (match_code "const_int,reg,subreg")
236 {
237   if (register_operand (op, mode))
238     return 1;
239
240   if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
241     return 1;
242
243   return 0;
244 })
245
246 ;; Return 1 if OP is a load multiple operation.  It is known to be a
247 ;; PARALLEL and the first section will be tested.
248
249 (define_predicate "mcore_load_multiple_operation"
250   (match_code "parallel")
251 {
252   int count = XVECLEN (op, 0);
253   int dest_regno;
254   rtx src_addr;
255   int i;
256
257   /* Perform a quick check so we don't blow up below.  */
258   if (count <= 1
259       || GET_CODE (XVECEXP (op, 0, 0)) != SET
260       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
261       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
262     return 0;
263
264   dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
265   src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
266
267   for (i = 1; i < count; i++)
268     {
269       rtx elt = XVECEXP (op, 0, i);
270
271       if (GET_CODE (elt) != SET
272           || GET_CODE (SET_DEST (elt)) != REG
273           || GET_MODE (SET_DEST (elt)) != SImode
274           || REGNO (SET_DEST (elt))    != (unsigned) (dest_regno + i)
275           || GET_CODE (SET_SRC (elt))  != MEM
276           || GET_MODE (SET_SRC (elt))  != SImode
277           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
278           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
279           || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
280           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
281         return 0;
282     }
283
284   return 1;
285 })
286
287 ;; Similar, but tests for store multiple.
288
289 (define_predicate "mcore_store_multiple_operation"
290   (match_code "parallel")
291 {
292   int count = XVECLEN (op, 0);
293   int src_regno;
294   rtx dest_addr;
295   int i;
296
297   /* Perform a quick check so we don't blow up below.  */
298   if (count <= 1
299       || GET_CODE (XVECEXP (op, 0, 0)) != SET
300       || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
301       || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
302     return 0;
303
304   src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
305   dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
306
307   for (i = 1; i < count; i++)
308     {
309       rtx elt = XVECEXP (op, 0, i);
310
311       if (GET_CODE (elt) != SET
312           || GET_CODE (SET_SRC (elt)) != REG
313           || GET_MODE (SET_SRC (elt)) != SImode
314           || REGNO (SET_SRC (elt)) != (unsigned) (src_regno + i)
315           || GET_CODE (SET_DEST (elt)) != MEM
316           || GET_MODE (SET_DEST (elt)) != SImode
317           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
318           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
319           || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
320           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
321         return 0;
322     }
323
324   return 1;
325 })
326
327 ;; TODO: Add a comment here.
328
329 (define_predicate "mcore_call_address_operand"
330   (match_code "reg,subreg,const_int,symbol_ref")
331 {
332   return register_operand (op, mode) || CONSTANT_P (op);
333 })