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, 51 Franklin Street, Fifth Floor,
19;; Boston, MA 02110-1301, 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 in the sdata section.
38(define_predicate "sdata_symbolic_operand" 
39  (match_code "symbol_ref,const")
40{
41  HOST_WIDE_INT offset = 0, size = 0;
42
43  switch (GET_CODE (op))
44    {
45    case CONST:
46      op = XEXP (op, 0);
47      if (GET_CODE (op) != PLUS
48	  || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
49	  || GET_CODE (XEXP (op, 1)) != CONST_INT)
50	return false;
51      offset = INTVAL (XEXP (op, 1));
52      op = XEXP (op, 0);
53      /* FALLTHRU */
54
55    case SYMBOL_REF:
56      if (CONSTANT_POOL_ADDRESS_P (op))
57	{
58	  size = GET_MODE_SIZE (get_pool_mode (op));
59	  if (size > ia64_section_threshold)
60	    return false;
61	}
62      else
63	{
64	  tree t;
65
66	  if (!SYMBOL_REF_LOCAL_P (op) || !SYMBOL_REF_SMALL_P (op))
67	    return false;
68
69	  /* Note that in addition to DECLs, we can get various forms
70	     of constants here.  */
71	  t = SYMBOL_REF_DECL (op);
72	  if (DECL_P (t))
73	    t = DECL_SIZE_UNIT (t);
74	  else
75	    t = TYPE_SIZE_UNIT (TREE_TYPE (t));
76	  if (t && host_integerp (t, 0))
77	    {
78	      size = tree_low_cst (t, 0);
79	      if (size < 0)
80		size = 0;
81	    }
82	}
83
84      /* Deny the stupid user trick of addressing outside the object.  Such
85	 things quickly result in GPREL22 relocation overflows.  Of course,
86	 they're also highly undefined.  From a pure pedant's point of view
87	 they deserve a slap on the wrist (such as provided by a relocation
88	 overflow), but that just leads to bugzilla noise.  */
89      return (offset >= 0 && offset <= size);
90
91    default:
92      gcc_unreachable ();
93    }
94})
95
96;; True if OP refers to a symbol in the small address area.
97(define_predicate "small_addr_symbolic_operand" 
98  (match_code "symbol_ref,const")
99{
100  switch (GET_CODE (op))
101    {
102    case CONST:
103      op = XEXP (op, 0);
104      if (GET_CODE (op) != PLUS
105	  || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
106	  || GET_CODE (XEXP (op, 1)) != CONST_INT)
107	return false;
108      op = XEXP (op, 0);
109      /* FALLTHRU */
110
111    case SYMBOL_REF:
112      return SYMBOL_REF_SMALL_ADDR_P (op);
113
114    default:
115      gcc_unreachable ();
116    }
117})
118
119;; True if OP refers to a symbol with which we may use any offset.
120(define_predicate "any_offset_symbol_operand"
121  (match_code "symbol_ref")
122{
123  if (TARGET_NO_PIC || TARGET_AUTO_PIC)
124    return true;
125  if (SYMBOL_REF_SMALL_ADDR_P (op))
126    return true;
127  if (SYMBOL_REF_FUNCTION_P (op))
128    return false;
129  if (sdata_symbolic_operand (op, mode))
130    return true;
131  return false;
132})
133
134;; True if OP refers to a symbol with which we may use 14-bit aligned offsets.
135;; False if OP refers to a symbol with which we may not use any offset at any
136;; time.
137(define_predicate "aligned_offset_symbol_operand"
138  (and (match_code "symbol_ref")
139       (match_test "! SYMBOL_REF_FUNCTION_P (op)")))
140
141;; True if OP refers to a symbol, and is appropriate for a GOT load.
142(define_predicate "got_symbolic_operand" 
143  (match_operand 0 "symbolic_operand" "")
144{
145  HOST_WIDE_INT addend = 0;
146
147  switch (GET_CODE (op))
148    {
149    case LABEL_REF:
150      return true;
151
152    case CONST:
153      /* Accept only (plus (symbol_ref) (const_int)).  */
154      op = XEXP (op, 0);
155      if (GET_CODE (op) != PLUS
156	  || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
157          || GET_CODE (XEXP (op, 1)) != CONST_INT)
158        return false;
159
160      addend = INTVAL (XEXP (op, 1));
161      op = XEXP (op, 0);
162      /* FALLTHRU */
163
164    case SYMBOL_REF:
165      /* These symbols shouldn't be used with got loads.  */
166      if (SYMBOL_REF_SMALL_ADDR_P (op))
167	return false;
168      if (SYMBOL_REF_TLS_MODEL (op) != 0)
169	return false;
170
171      if (any_offset_symbol_operand (op, mode))
172	return true;
173
174      /* The low 14 bits of the constant have been forced to zero
175	 so that we do not use up so many GOT entries.  Prevent cse
176	 from undoing this.  */
177      if (aligned_offset_symbol_operand (op, mode))
178	return (addend & 0x3fff) == 0;
179
180      return addend == 0;
181
182    default:
183      gcc_unreachable ();
184    }
185})
186
187;; Return true if OP is a valid thread local storage symbolic operand.
188(define_predicate "tls_symbolic_operand"
189  (match_code "symbol_ref,const")
190{
191  switch (GET_CODE (op))
192    {
193    case SYMBOL_REF:
194      return SYMBOL_REF_TLS_MODEL (op) != 0;
195
196    case CONST:
197      op = XEXP (op, 0);
198      if (GET_CODE (op) != PLUS
199	  || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
200	  || GET_CODE (XEXP (op, 1)) != CONST_INT)
201	return false;
202
203      /* We only allow certain offsets for certain tls models.  */
204      switch (SYMBOL_REF_TLS_MODEL (XEXP (op, 0)))
205	{
206	case TLS_MODEL_GLOBAL_DYNAMIC:
207	case TLS_MODEL_LOCAL_DYNAMIC:
208	  return false;
209
210	case TLS_MODEL_INITIAL_EXEC:
211	  return (INTVAL (XEXP (op, 1)) & 0x3fff) == 0;
212
213	case TLS_MODEL_LOCAL_EXEC:
214	  return true;
215
216	default:
217	  return false;
218	}
219
220    default:
221      gcc_unreachable ();
222    }
223})
224
225;; Return true if OP is a local-dynamic thread local storage symbolic operand.
226(define_predicate "ld_tls_symbolic_operand"
227  (and (match_code "symbol_ref")
228       (match_test "SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_DYNAMIC")))
229
230;; Return true if OP is an initial-exec thread local storage symbolic operand.
231(define_predicate "ie_tls_symbolic_operand"
232  (match_code "symbol_ref,const")
233{
234  switch (GET_CODE (op))
235    {
236    case CONST:
237      op = XEXP (op, 0);
238      if (GET_CODE (op) != PLUS
239	  || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
240	  || GET_CODE (XEXP (op, 1)) != CONST_INT
241	  || (INTVAL (XEXP (op, 1)) & 0x3fff) != 0)
242	return false;
243      op = XEXP (op, 0);
244      /* FALLTHRU */
245
246    case SYMBOL_REF:
247      return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_INITIAL_EXEC;
248
249    default:
250      gcc_unreachable ();
251    }
252})
253
254;; Return true if OP is a local-exec thread local storage symbolic operand.
255(define_predicate "le_tls_symbolic_operand"
256  (match_code "symbol_ref,const")
257{
258  switch (GET_CODE (op))
259    {
260    case CONST:
261      op = XEXP (op, 0);
262      if (GET_CODE (op) != PLUS
263          || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
264          || GET_CODE (XEXP (op, 1)) != CONST_INT)
265        return false;
266      op = XEXP (op, 0);
267      /* FALLTHRU */
268
269    case SYMBOL_REF:
270      return SYMBOL_REF_TLS_MODEL (op) == TLS_MODEL_LOCAL_EXEC;
271
272    default:
273      gcc_unreachable ();
274    }
275})
276
277;; Like nonimmediate_operand, but don't allow MEMs that try to use a
278;; POST_MODIFY with a REG as displacement.
279(define_predicate "destination_operand"
280  (and (match_operand 0 "nonimmediate_operand")
281       (match_test "GET_CODE (op) != MEM
282		    || GET_CODE (XEXP (op, 0)) != POST_MODIFY
283		    || GET_CODE (XEXP (XEXP (XEXP (op, 0), 1), 1)) != REG")))
284
285;; Like memory_operand, but don't allow post-increments.
286(define_predicate "not_postinc_memory_operand"
287  (and (match_operand 0 "memory_operand")
288       (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0))) != RTX_AUTOINC")))
289
290;; True if OP is a general operand, with some restrictions on symbols.
291(define_predicate "move_operand"
292  (match_operand 0 "general_operand")
293{
294  switch (GET_CODE (op))
295    {
296    case CONST:
297      {
298	HOST_WIDE_INT addend;
299
300	/* Accept only (plus (symbol_ref) (const_int)).  */
301	op = XEXP (op, 0);
302	if (GET_CODE (op) != PLUS
303	    || GET_CODE (XEXP (op, 0)) != SYMBOL_REF
304            || GET_CODE (XEXP (op, 1)) != CONST_INT)
305	  return false;
306
307	addend = INTVAL (XEXP (op, 1));
308	op = XEXP (op, 0);
309
310	/* After reload, we want to allow any offset whatsoever.  This
311	   allows reload the opportunity to avoid spilling addresses to
312	   the stack, and instead simply substitute in the value from a
313	   REG_EQUIV.  We'll split this up again when splitting the insn.  */
314	if (reload_in_progress || reload_completed)
315	  return true;
316
317	/* Some symbol types we allow to use with any offset.  */
318	if (any_offset_symbol_operand (op, mode))
319	  return true;
320
321	/* Some symbol types we allow offsets with the low 14 bits of the
322	   constant forced to zero so that we do not use up so many GOT
323	   entries.  We want to prevent cse from undoing this.  */
324	if (aligned_offset_symbol_operand (op, mode))
325	  return (addend & 0x3fff) == 0;
326
327	/* The remaining symbol types may never be used with an offset.  */
328	return false;
329      }
330
331    default:
332      return true;
333    }
334})
335
336;; True if OP is a register operand that is (or could be) a GR reg.
337(define_predicate "gr_register_operand"
338  (match_operand 0 "register_operand")
339{
340  unsigned int regno;
341  if (GET_CODE (op) == SUBREG)
342    op = SUBREG_REG (op);
343
344  regno = REGNO (op);
345  return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
346})
347
348;; True if OP is a register operand that is (or could be) an FR reg.
349(define_predicate "fr_register_operand"
350  (match_operand 0 "register_operand")
351{
352  unsigned int regno;
353  if (GET_CODE (op) == SUBREG)
354    op = SUBREG_REG (op);
355
356  regno = REGNO (op);
357  return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
358})
359
360;; True if OP is a register operand that is (or could be) a GR/FR reg.
361(define_predicate "grfr_register_operand"
362  (match_operand 0 "register_operand")
363{
364  unsigned int regno;
365  if (GET_CODE (op) == SUBREG)
366    op = SUBREG_REG (op);
367
368  regno = REGNO (op);
369  return (regno >= FIRST_PSEUDO_REGISTER
370	  || GENERAL_REGNO_P (regno)
371	  || FR_REGNO_P (regno));
372})
373
374;; True if OP is a nonimmediate operand that is (or could be) a GR reg.
375(define_predicate "gr_nonimmediate_operand"
376  (match_operand 0 "nonimmediate_operand")
377{
378  unsigned int regno;
379
380  if (GET_CODE (op) == MEM)
381    return true;
382  if (GET_CODE (op) == SUBREG)
383    op = SUBREG_REG (op);
384
385  regno = REGNO (op);
386  return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
387})
388
389;; True if OP is a nonimmediate operand that is (or could be) a FR reg.
390(define_predicate "fr_nonimmediate_operand"
391  (match_operand 0 "nonimmediate_operand")
392{
393  unsigned int regno;
394
395  if (GET_CODE (op) == MEM)
396    return true;
397  if (GET_CODE (op) == SUBREG)
398    op = SUBREG_REG (op);
399
400  regno = REGNO (op);
401  return (regno >= FIRST_PSEUDO_REGISTER || FR_REGNO_P (regno));
402})
403
404;; True if OP is a nonimmediate operand that is (or could be) a GR/FR reg.
405(define_predicate "grfr_nonimmediate_operand"
406  (match_operand 0 "nonimmediate_operand")
407{
408  unsigned int regno;
409
410  if (GET_CODE (op) == MEM)
411    return true;
412  if (GET_CODE (op) == SUBREG)
413    op = SUBREG_REG (op);
414
415  regno = REGNO (op);
416  return (regno >= FIRST_PSEUDO_REGISTER
417	  || GENERAL_REGNO_P (regno)
418	  || FR_REGNO_P (regno));
419})
420
421;; True if OP is a GR register operand, or zero.
422(define_predicate "gr_reg_or_0_operand"
423  (ior (match_operand 0 "gr_register_operand")
424       (and (match_code "const_int,const_double,const_vector")
425	    (match_test "op == CONST0_RTX (GET_MODE (op))"))))
426
427;; True if OP is a GR register operand, or a 5 bit immediate operand.
428(define_predicate "gr_reg_or_5bit_operand"
429  (ior (match_operand 0 "gr_register_operand")
430       (and (match_code "const_int")
431	    (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32"))))
432
433;; True if OP is a GR register operand, or a 6 bit immediate operand.
434(define_predicate "gr_reg_or_6bit_operand"
435  (ior (match_operand 0 "gr_register_operand")
436       (and (match_code "const_int")
437	    (match_test "CONST_OK_FOR_M (INTVAL (op))"))))
438
439;; True if OP is a GR register operand, or an 8 bit immediate operand.
440(define_predicate "gr_reg_or_8bit_operand"
441  (ior (match_operand 0 "gr_register_operand")
442       (and (match_code "const_int")
443	    (match_test "CONST_OK_FOR_K (INTVAL (op))"))))
444
445;; True if OP is a GR/FR register operand, or an 8 bit immediate operand.
446(define_predicate "grfr_reg_or_8bit_operand"
447  (ior (match_operand 0 "grfr_register_operand")
448       (and (match_code "const_int")
449	    (match_test "CONST_OK_FOR_K (INTVAL (op))"))))
450
451;; True if OP is a register operand, or an 8 bit adjusted immediate operand.
452(define_predicate "gr_reg_or_8bit_adjusted_operand"
453  (ior (match_operand 0 "gr_register_operand")
454       (and (match_code "const_int")
455	    (match_test "CONST_OK_FOR_L (INTVAL (op))"))))
456
457;; True if OP is a register operand, or is valid for both an 8 bit
458;; immediate and an 8 bit adjusted immediate operand.  This is necessary
459;; because when we emit a compare, we don't know what the condition will be,
460;; so we need the union of the immediates accepted by GT and LT.
461(define_predicate "gr_reg_or_8bit_and_adjusted_operand"
462  (ior (match_operand 0 "gr_register_operand")
463       (and (match_code "const_int")
464	    (match_test "CONST_OK_FOR_K (INTVAL (op))
465                         && CONST_OK_FOR_L (INTVAL (op))"))))
466
467;; True if OP is a register operand, or a 14 bit immediate operand.
468(define_predicate "gr_reg_or_14bit_operand"
469  (ior (match_operand 0 "gr_register_operand")
470       (and (match_code "const_int")
471	    (match_test "CONST_OK_FOR_I (INTVAL (op))"))))
472
473;;  True if OP is a register operand, or a 22 bit immediate operand.
474(define_predicate "gr_reg_or_22bit_operand"
475  (ior (match_operand 0 "gr_register_operand")
476       (and (match_code "const_int")
477	    (match_test "CONST_OK_FOR_J (INTVAL (op))"))))
478
479;; True if OP is a 7 bit immediate operand.
480(define_predicate "dshift_count_operand"
481  (and (match_code "const_int")
482       (match_test "INTVAL (op) >= 0 && INTVAL (op) < 128")))
483
484;; True if OP is a 6 bit immediate operand.
485(define_predicate "shift_count_operand"
486  (and (match_code "const_int")
487       (match_test "CONST_OK_FOR_M (INTVAL (op))")))
488
489;; True if OP-1 is a 6 bit immediate operand, used in extr instruction.
490(define_predicate "extr_len_operand"
491  (and (match_code "const_int")
492       (match_test "CONST_OK_FOR_M (INTVAL (op) - 1)")))
493
494;; True if OP is a 5 bit immediate operand.
495(define_predicate "shift_32bit_count_operand"
496   (and (match_code "const_int")
497        (match_test "INTVAL (op) >= 0 && INTVAL (op) < 32")))
498
499;; True if OP is one of the immediate values 2, 4, 8, or 16.
500(define_predicate "shladd_operand"
501  (and (match_code "const_int")
502       (match_test "INTVAL (op) == 2 || INTVAL (op) == 4 ||
503	            INTVAL (op) == 8 || INTVAL (op) == 16")))
504
505;; True if OP is one of the immediate values 1, 2, 3, or 4.
506(define_predicate "shladd_log2_operand"
507  (and (match_code "const_int")
508       (match_test "INTVAL (op) >= 1 && INTVAL (op) <= 4")))
509
510;; True if OP is one of the immediate values  -16, -8, -4, -1, 1, 4, 8, 16.
511(define_predicate "fetchadd_operand"
512  (and (match_code "const_int")
513       (match_test "INTVAL (op) == -16 || INTVAL (op) == -8 ||
514                    INTVAL (op) == -4  || INTVAL (op) == -1 ||
515                    INTVAL (op) == 1   || INTVAL (op) == 4  ||
516                    INTVAL (op) == 8   || INTVAL (op) == 16")))
517
518;; True if OP is 0..3.
519(define_predicate "const_int_2bit_operand"
520  (and (match_code "const_int")
521        (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 3")))
522
523;; True if OP is a floating-point constant zero, one, or a register.
524(define_predicate "fr_reg_or_fp01_operand"
525  (ior (match_operand 0 "fr_register_operand")
526       (and (match_code "const_double")
527	    (match_test "CONST_DOUBLE_OK_FOR_G (op)"))))
528
529;; Like fr_reg_or_fp01_operand, but don't allow any SUBREGs.
530(define_predicate "xfreg_or_fp01_operand"
531  (and (match_operand 0 "fr_reg_or_fp01_operand")
532       (not (match_code "subreg"))))
533
534;; True if OP is a constant zero, or a register.
535(define_predicate "fr_reg_or_0_operand"
536  (ior (match_operand 0 "fr_register_operand")
537       (and (match_code "const_double,const_vector")
538	    (match_test "op == CONST0_RTX (GET_MODE (op))"))))
539
540;; True if this is a comparison operator, which accepts a normal 8-bit
541;; signed immediate operand.
542(define_predicate "normal_comparison_operator"
543  (match_code "eq,ne,gt,le,gtu,leu"))
544
545;; True if this is a comparison operator, which accepts an adjusted 8-bit
546;; signed immediate operand.
547(define_predicate "adjusted_comparison_operator"
548  (match_code "lt,ge,ltu,geu"))
549
550;; True if this is a signed inequality operator.
551(define_predicate "signed_inequality_operator"
552  (match_code "ge,gt,le,lt"))
553
554;; True if this operator is valid for predication.
555(define_predicate "predicate_operator"
556  (match_code "eq,ne"))
557
558;; True if this operator can be used in a conditional operation.
559(define_predicate "condop_operator"
560  (match_code "plus,minus,ior,xor,and"))
561
562;; These three are hardware registers that can only be addressed in
563;; DImode.  It's not strictly necessary to test mode == DImode here,
564;; but it makes decent insurance against someone writing a
565;; match_operand wrong.
566
567;; True if this is the ar.lc register.
568(define_predicate "ar_lc_reg_operand"
569  (and (match_code "reg")
570       (match_test "mode == DImode && REGNO (op) == AR_LC_REGNUM")))
571
572;; True if this is the ar.ccv register.
573(define_predicate "ar_ccv_reg_operand"
574  (and (match_code "reg")
575       (match_test "mode == DImode && REGNO (op) == AR_CCV_REGNUM")))
576
577;; True if this is the ar.pfs register.
578(define_predicate "ar_pfs_reg_operand"
579  (and (match_code "reg")
580       (match_test "mode == DImode && REGNO (op) == AR_PFS_REGNUM")))
581
582;; True if OP is valid as a base register in a reg + offset address.
583;; ??? Should I copy the flag_omit_frame_pointer and cse_not_expected
584;; checks from pa.c basereg_operand as well?  Seems to be OK without them
585;; in test runs.
586(define_predicate "basereg_operand"
587  (match_operand 0 "register_operand")
588{
589  return REG_P (op) && REG_POINTER (op);
590})
591
592