OSDN Git Service

* config/darwin.c, config/darwin.h, config/freebsd-spec.h,
[pf3gnuchains/gcc-fork.git] / gcc / config / ia64 / predicates.md
1 ;; Predicate definitions for IA-64.
2 ;; Copyright (C) 2004, 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 ;; True if OP is a valid operand for the MEM of a CALL insn.
22 (define_predicate "call_operand"
23   (ior (match_code "symbol_ref")
24        (match_operand 0 "register_operand")))
25
26 ;; True if OP refers to any kind of symbol.
27 ;; For roughly the same reasons that pmode_register_operand exists, this
28 ;; predicate ignores its mode argument.
29 (define_special_predicate "symbolic_operand" 
30    (match_code "symbol_ref,const,label_ref"))
31
32 ;; True if OP is a SYMBOL_REF which refers to a function.
33 (define_predicate "function_operand"
34   (and (match_code "symbol_ref")
35        (match_test "SYMBOL_REF_FUNCTION_P (op)")))
36
37 ;; True if OP refers to a symbol, and is appropriate for a GOT load.
38 (define_predicate "got_symbolic_operand" 
39   (match_operand 0 "symbolic_operand" "")
40 {
41   switch (GET_CODE (op))
42     {
43     case LABEL_REF:
44       return true;
45
46     case SYMBOL_REF:
47       /* This sort of load should not be used for things in sdata.  */
48       return !SYMBOL_REF_SMALL_ADDR_P (op);
49
50     case CONST:
51       /* Accept only (plus (symbol_ref) (const_int)).  */
52       op = XEXP (op, 0);
53       if (GET_CODE (op) != PLUS
54           || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
55           || GET_CODE (XEXP (op, 1)) != CONST_INT)
56         return false;
57
58       /* Ok if we're not using GOT entries at all.  */
59       if (TARGET_NO_PIC || TARGET_AUTO_PIC)
60         return true;
61
62       /* The low 14 bits of the constant have been forced to zero
63          by ia64_expand_load_address, so that we do not use up so
64          many GOT entries.  Prevent cse from undoing this.  */
65       op = XEXP (op, 1);
66       return (INTVAL (op) & 0x3fff) == 0;
67
68     default:
69       abort ();
70     }
71 })
72
73 ;; True if OP refers to a symbol in the sdata section.
74 (define_predicate "sdata_symbolic_operand" 
75   (match_code "symbol_ref,const")
76 {
77   HOST_WIDE_INT offset = 0, size = 0;
78
79   switch (GET_CODE (op))
80     {
81     case CONST:
82       op = XEXP (op, 0);
83       if (GET_CODE (op) != PLUS
84           || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
85           || GET_CODE (XEXP (op, 1)) != CONST_INT)
86         return false;
87       offset = INTVAL (XEXP (op, 1));
88       op = XEXP (op, 0);
89       /* FALLTHRU */
90
91     case SYMBOL_REF:
92       if (CONSTANT_POOL_ADDRESS_P (op))
93         {
94           size = GET_MODE_SIZE (get_pool_mode (op));
95           if (size > ia64_section_threshold)
96             return false;
97         }
98       else
99         {
100           tree t;
101
102           if (!SYMBOL_REF_LOCAL_P (op) || !SYMBOL_REF_SMALL_P (op))
103             return false;
104
105           /* Note that in addition to DECLs, we can get various forms
106              of constants here.  */
107           t = SYMBOL_REF_DECL (op);
108           if (DECL_P (t))
109             t = DECL_SIZE_UNIT (t);
110           else
111             t = TYPE_SIZE_UNIT (TREE_TYPE (t));
112           if (t && host_integerp (t, 0))
113             {
114               size = tree_low_cst (t, 0);
115               if (size < 0)
116                 size = 0;
117             }
118         }
119
120       /* Deny the stupid user trick of addressing outside the object.  Such
121          things quickly result in GPREL22 relocation overflows.  Of course,
122          they're also highly undefined.  From a pure pedant's point of view
123          they deserve a slap on the wrist (such as provided by a relocation
124          overflow), but that just leads to bugzilla noise.  */
125       return (offset >= 0 && offset <= size);
126
127     default:
128       abort ();
129     }
130 })
131
132 ;; Like nonimmediate_operand, but don't allow MEMs that try to use a
133 ;; POST_MODIFY with a REG as displacement.
134 (define_predicate "destination_operand"
135   (and (match_operand 0 "nonimmediate_operand")
136        (match_test "GET_CODE (op) != MEM
137                     || GET_CODE (XEXP (op, 0)) != POST_MODIFY
138                     || GET_CODE (XEXP (XEXP (XEXP (op, 0), 1), 1)) != REG")))
139
140 ;; Like memory_operand, but don't allow post-increments.
141 (define_predicate "not_postinc_memory_operand"
142   (and (match_operand 0 "memory_operand")
143        (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0))) != RTX_AUTOINC")))
144
145 ;; True if OP is a general operand, excluding tls symbolic operands.
146 (define_predicate "move_operand"
147   (and (match_operand 0 "general_operand")
148        (not (match_test 
149              "GET_CODE (op) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (op)"))))
150
151 ;; True if OP is a register operand that is (or could be) a GR reg.
152 (define_predicate "gr_register_operand"
153   (match_operand 0 "register_operand")
154 {
155   unsigned int regno;
156   if (GET_CODE (op) == SUBREG)
157     op = SUBREG_REG (op);
158
159   regno = REGNO (op);
160   return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
161 })
162
163 ;; True if OP is a register operand that is (or could be) an FR reg.
164 (define_predicate "fr_register_operand"
165   (match_operand 0 "register_operand")
166 {
167   unsigned int regno;
168   if (GET_CODE (op) == SUBREG)
169     op = SUBREG_REG (op);
170
171   regno = REGNO (op);
172   return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
173 })
174
175 ;; True if OP is a register operand that is (or could be) a GR/FR reg.
176 (define_predicate "grfr_register_operand"
177   (match_operand 0 "register_operand")
178 {
179   unsigned int regno;
180   if (GET_CODE (op) == SUBREG)
181     op = SUBREG_REG (op);
182
183   regno = REGNO (op);
184   return (regno >= FIRST_PSEUDO_REGISTER
185           || GENERAL_REGNO_P (regno)
186           || FR_REGNO_P (regno));
187 })
188
189 ;; True if OP is a nonimmediate operand that is (or could be) a GR reg.
190 (define_predicate "gr_nonimmediate_operand"
191   (match_operand 0 "nonimmediate_operand")
192 {
193   unsigned int regno;
194
195   if (GET_CODE (op) == MEM)
196     return true;
197   if (GET_CODE (op) == SUBREG)
198     op = SUBREG_REG (op);
199
200   regno = REGNO (op);
201   return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
202 })
203
204 ;; True if OP is a nonimmediate operand that is (or could be) a FR reg.
205 (define_predicate "fr_nonimmediate_operand"
206   (match_operand 0 "nonimmediate_operand")
207 {
208   unsigned int regno;
209
210   if (GET_CODE (op) == MEM)
211     return true;
212   if (GET_CODE (op) == SUBREG)
213     op = SUBREG_REG (op);
214
215   regno = REGNO (op);
216   return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
217 })
218
219 ;; True if OP is a nonimmediate operand that is (or could be) a GR/FR reg.
220 (define_predicate "grfr_nonimmediate_operand"
221   (match_operand 0 "nonimmediate_operand")
222 {
223   unsigned int regno;
224
225   if (GET_CODE (op) == MEM)
226     return true;
227   if (GET_CODE (op) == SUBREG)
228     op = SUBREG_REG (op);
229
230   regno = REGNO (op);
231   return (regno >= FIRST_PSEUDO_REGISTER
232           || GENERAL_REGNO_P (regno)
233           || FR_REGNO_P (regno));
234 })
235
236 ;; True if OP is a GR register operand, or zero.
237 (define_predicate "gr_reg_or_0_operand"
238   (ior (match_operand 0 "gr_register_operand")
239        (and (match_code "const_int,const_double,const_vector")
240             (match_test "op == CONST0_RTX (GET_MODE (op))"))))
241
242 ;; True if OP is a GR register operand, or a 5 bit immediate operand.
243 (define_predicate "gr_reg_or_5bit_operand"
244   (ior (match_operand 0 "gr_register_operand")
245        (and (match_code "const_int")
246             (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32"))))
247
248 ;; True if OP is a GR register operand, or a 6 bit immediate operand.
249 (define_predicate "gr_reg_or_6bit_operand"
250   (ior (match_operand 0 "gr_register_operand")
251        (and (match_code "const_int")
252             (match_test "CONST_OK_FOR_M (INTVAL (op))"))))
253
254 ;; True if OP is a GR register operand, or an 8 bit immediate operand.
255 (define_predicate "gr_reg_or_8bit_operand"
256   (ior (match_operand 0 "gr_register_operand")
257        (and (match_code "const_int")
258             (match_test "CONST_OK_FOR_K (INTVAL (op))"))))
259
260 ;; True if OP is a GR/FR register operand, or an 8 bit immediate operand.
261 (define_predicate "grfr_reg_or_8bit_operand"
262   (ior (match_operand 0 "grfr_register_operand")
263        (and (match_code "const_int")
264             (match_test "CONST_OK_FOR_K (INTVAL (op))"))))
265
266 ;; True if OP is a register operand, or an 8 bit adjusted immediate operand.
267 (define_predicate "gr_reg_or_8bit_adjusted_operand"
268   (ior (match_operand 0 "gr_register_operand")
269        (and (match_code "const_int")
270             (match_test "CONST_OK_FOR_L (INTVAL (op))"))))
271
272 ;; True if OP is a register operand, or is valid for both an 8 bit
273 ;; immediate and an 8 bit adjusted immediate operand.  This is necessary
274 ;; because when we emit a compare, we don't know what the condition will be,
275 ;; so we need the union of the immediates accepted by GT and LT.
276 (define_predicate "gr_reg_or_8bit_and_adjusted_operand"
277   (ior (match_operand 0 "gr_register_operand")
278        (and (match_code "const_int")
279             (match_test "CONST_OK_FOR_K (INTVAL (op))
280                          && CONST_OK_FOR_L (INTVAL (op))"))))
281
282 ;; True if OP is a register operand, or a 14 bit immediate operand.
283 (define_predicate "gr_reg_or_14bit_operand"
284   (ior (match_operand 0 "gr_register_operand")
285        (and (match_code "const_int")
286             (match_test "CONST_OK_FOR_I (INTVAL (op))"))))
287
288 ;;  True if OP is a register operand, or a 22 bit immediate operand.
289 (define_predicate "gr_reg_or_22bit_operand"
290   (ior (match_operand 0 "gr_register_operand")
291        (and (match_code "const_int")
292             (match_test "CONST_OK_FOR_J (INTVAL (op))"))))
293
294 ;; True if OP is a 7 bit immediate operand.
295 (define_predicate "dshift_count_operand"
296   (and (match_code "const_int")
297        (match_test "INTVAL (op) >= 0 && INTVAL (op) < 128")))
298
299 ;; True if OP is a 6 bit immediate operand.
300 (define_predicate "shift_count_operand"
301   (and (match_code "const_int")
302        (match_test "CONST_OK_FOR_M (INTVAL (op))")))
303
304 ;; True if OP is a 5 bit immediate operand.
305 (define_predicate "shift_32bit_count_operand"
306    (and (match_code "const_int")
307         (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32")))
308
309 ;; True if OP is one of the immediate values 2, 4, 8, or 16.
310 (define_predicate "shladd_operand"
311   (and (match_code "const_int")
312        (match_test "INTVAL (op) == 2 || INTVAL (op) == 4 ||
313                     INTVAL (op) == 8 || INTVAL (op) == 16")))
314
315 ;; True if OP is one of the immediate values 1, 2, 3, or 4.
316 (define_predicate "shladd_log2_operand"
317   (and (match_code "const_int")
318        (match_test "INTVAL (op) >= 1 && INTVAL (op) <= 4")))
319
320 ;; True if OP is one of the immediate values  -16, -8, -4, -1, 1, 4, 8, 16.
321 (define_predicate "fetchadd_operand"
322   (and (match_code "const_int")
323        (match_test "INTVAL (op) == -16 || INTVAL (op) == -8 ||
324                     INTVAL (op) == -4  || INTVAL (op) == -1 ||
325                     INTVAL (op) == 1   || INTVAL (op) == 4  ||
326                     INTVAL (op) == 8   || INTVAL (op) == 16")))
327
328 ;; True if OP is 0..3.
329 (define_predicate "const_int_2bit_operand"
330   (and (match_code "const_int")
331         (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 3")))
332
333 ;; True if OP is a floating-point constant zero, one, or a register.
334 (define_predicate "fr_reg_or_fp01_operand"
335   (ior (match_operand 0 "fr_register_operand")
336        (and (match_code "const_double")
337             (match_test "CONST_DOUBLE_OK_FOR_G (op)"))))
338
339 ;; Like fr_reg_or_fp01_operand, but don't allow any SUBREGs.
340 (define_predicate "xfreg_or_fp01_operand"
341   (and (match_operand 0 "fr_reg_or_fp01_operand")
342        (not (match_code "subreg"))))
343
344 ;; True if OP is a constant zero, or a register.
345 (define_predicate "fr_reg_or_0_operand"
346   (ior (match_operand 0 "fr_register_operand")
347        (and (match_code "const_double,const_vector")
348             (match_test "op == CONST0_RTX (GET_MODE (op))"))))
349
350 ;; True if this is a comparison operator, which accepts a normal 8-bit
351 ;; signed immediate operand.
352 (define_predicate "normal_comparison_operator"
353   (match_code "eq,ne,gt,le,gtu,leu"))
354
355 ;; True if this is a comparison operator, which accepts an adjusted 8-bit
356 ;; signed immediate operand.
357 (define_predicate "adjusted_comparison_operator"
358   (match_code "lt,ge,ltu,geu"))
359
360 ;; True if this is a signed inequality operator.
361 (define_predicate "signed_inequality_operator"
362   (match_code "ge,gt,le,lt"))
363
364 ;; True if this operator is valid for predication.
365 (define_predicate "predicate_operator"
366   (match_code "eq,ne"))
367
368 ;; True if this operator can be used in a conditional operation.
369 (define_predicate "condop_operator"
370   (match_code "plus,minus,ior,xor,and"))
371
372 ;; These three are hardware registers that can only be addressed in
373 ;; DImode.  It's not strictly necessary to test mode == DImode here,
374 ;; but it makes decent insurance against someone writing a
375 ;; match_operand wrong.
376
377 ;; True if this is the ar.lc register.
378 (define_predicate "ar_lc_reg_operand"
379   (and (match_code "reg")
380        (match_test "mode == DImode && REGNO (op) == AR_LC_REGNUM")))
381
382 ;; True if this is the ar.ccv register.
383 (define_predicate "ar_ccv_reg_operand"
384   (and (match_code "reg")
385        (match_test "mode == DImode && REGNO (op) == AR_CCV_REGNUM")))
386
387 ;; True if this is the ar.pfs register.
388 (define_predicate "ar_pfs_reg_operand"
389   (and (match_code "reg")
390        (match_test "mode == DImode && REGNO (op) == AR_PFS_REGNUM")))
391
392 ;; True if OP is valid as a base register in a reg + offset address.
393 ;; ??? Should I copy the flag_omit_frame_pointer and cse_not_expected
394 ;; checks from pa.c basereg_operand as well?  Seems to be OK without them
395 ;; in test runs.
396 (define_predicate "basereg_operand"
397   (match_operand 0 "register_operand")
398 {
399   if (GET_CODE (op) == SUBREG)
400     op = SUBREG_REG (op);
401   return REG_POINTER (op);
402 })
403