OSDN Git Service

PR ada/40166
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / predicates.md
1 ;; Predicate definitions for Motorola 68000.
2 ;; Copyright (C) 2005, 2007 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.
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 COPYING3.  If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 ;; Special case of a general operand that's used as a source
21 ;; operand. Use this to permit reads from PC-relative memory when
22 ;; -mpcrel is specified.
23
24 (define_predicate "general_src_operand"
25   (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
26 {
27   if (TARGET_PCREL
28       && GET_CODE (op) == MEM
29       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
30           || GET_CODE (XEXP (op, 0)) == LABEL_REF
31           || GET_CODE (XEXP (op, 0)) == CONST))
32     return 1;
33   return general_operand (op, mode);
34 })
35
36 ;; Special case of a nonimmediate operand that's used as a source. Use
37 ;; this to permit reads from PC-relative memory when -mpcrel is
38 ;; specified.
39
40 (define_predicate "nonimmediate_src_operand"
41   (match_code "subreg,reg,mem")
42 {
43   if (TARGET_PCREL && GET_CODE (op) == MEM
44       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
45           || GET_CODE (XEXP (op, 0)) == LABEL_REF
46           || GET_CODE (XEXP (op, 0)) == CONST))
47     return 1;
48   return nonimmediate_operand (op, mode);
49 })
50
51 ;; Special case of a memory operand that's used as a source. Use this
52 ;; to permit reads from PC-relative memory when -mpcrel is specified.
53
54 (define_predicate "memory_src_operand"
55   (match_code "subreg,mem")
56 {
57   if (TARGET_PCREL && GET_CODE (op) == MEM
58       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
59           || GET_CODE (XEXP (op, 0)) == LABEL_REF
60           || GET_CODE (XEXP (op, 0)) == CONST))
61     return 1;
62   return memory_operand (op, mode);
63 })
64
65 ;; Similar to general_operand, but exclude stack_pointer_rtx.
66
67 (define_predicate "not_sp_operand"
68   (match_code "subreg,reg,mem")
69 {
70   return op != stack_pointer_rtx && nonimmediate_operand (op, mode);
71 })
72
73 ;; Predicate that accepts only a pc-relative address.  This is needed
74 ;; because pc-relative addresses don't satisfy the predicate
75 ;; "general_src_operand".
76
77 (define_predicate "pcrel_address"
78   (match_code "symbol_ref,label_ref,const"))
79
80 ;; Accept integer operands in the range 0..0xffffffff.  We have to
81 ;; check the range carefully since this predicate is used in DImode
82 ;; contexts.  Also, we need some extra crud to make it work when
83 ;; hosted on 64-bit machines.
84
85 (define_predicate "const_uint32_operand"
86   (match_code "const_int,const_double")
87 {
88   /* It doesn't make sense to ask this question with a mode that is
89      not larger than 32 bits.  */
90   gcc_assert (GET_MODE_BITSIZE (mode) > 32);
91
92 #if HOST_BITS_PER_WIDE_INT > 32
93   /* All allowed constants will fit a CONST_INT.  */
94   return (GET_CODE (op) == CONST_INT
95           && (INTVAL (op) >= 0 && INTVAL (op) <= 0xffffffffL));
96 #else
97   return (GET_CODE (op) == CONST_INT
98           || (GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_HIGH (op) == 0));
99 #endif
100 })
101
102 ;; Accept integer operands in the range -0x80000000..0x7fffffff.  We
103 ;; have to check the range carefully since this predicate is used in
104 ;; DImode contexts.
105
106 (define_predicate "const_sint32_operand"
107   (match_code "const_int")
108 {
109   /* It doesn't make sense to ask this question with a mode that is
110      not larger than 32 bits.  */
111   gcc_assert (GET_MODE_BITSIZE (mode) > 32);
112
113   /* All allowed constants will fit a CONST_INT.  */
114   return (GET_CODE (op) == CONST_INT
115           && (INTVAL (op) >= (-0x7fffffff - 1) && INTVAL (op) <= 0x7fffffff));
116 })
117
118 ;; Return true if X is a valid comparison operator for the dbcc
119 ;; instruction.  Note it rejects floating point comparison
120 ;; operators. (In the future we could use Fdbcc).  It also rejects
121 ;; some comparisons when CC_NO_OVERFLOW is set.
122
123 (define_predicate "valid_dbcc_comparison_p"
124   (and (match_code "eq,ne,gtu,ltu,geu,leu,gt,lt,ge,le")
125        (match_test "valid_dbcc_comparison_p_2 (op, mode)")))
126
127 (define_predicate "m68k_cstore_comparison_operator"
128   (if_then_else (match_test "TARGET_68881")
129                 (match_operand 0 "comparison_operator")
130                 (match_operand 0 "ordered_comparison_operator")))
131
132 ;; Check for sign_extend or zero_extend.  Used for bit-count operands.
133
134 (define_predicate "extend_operator"
135   (match_code "sign_extend,zero_extend"))
136
137 ;; Returns true if OP is either a symbol reference or a sum of a
138 ;; symbol reference and a constant.
139
140 (define_predicate "symbolic_operand"
141   (match_code "symbol_ref,label_ref,const")
142 {
143   switch (GET_CODE (op))
144     {
145     case SYMBOL_REF:
146     case LABEL_REF:
147       return true;
148
149     case CONST:
150       op = XEXP (op, 0);
151       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
152                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
153               && GET_CODE (XEXP (op, 1)) == CONST_INT);
154
155 #if 0 /* Deleted, with corresponding change in m68k.h,
156          so as to fit the specs.  No CONST_DOUBLE is ever symbolic.  */
157     case CONST_DOUBLE:
158       return GET_MODE (op) == mode;
159 #endif
160
161     default:
162       return false;
163     }
164 })
165
166 ;; A constant that can be used the address in a call insn
167 (define_predicate "const_call_operand"
168   (ior (match_operand 0 "const_int_operand")
169        (and (match_test "m68k_symbolic_call != NULL")
170             (match_operand 0 "symbolic_operand"))))
171
172 ;; An operand that can be used as the address in a call insn.
173 (define_predicate "call_operand"
174   (ior (match_operand 0 "const_call_operand")
175        (match_operand 0 "register_operand")))
176
177 ;; A constant that can be used the address in a sibcall insn
178 (define_predicate "const_sibcall_operand"
179   (ior (match_operand 0 "const_int_operand")
180        (and (match_test "m68k_symbolic_jump != NULL")
181             (match_operand 0 "symbolic_operand"))))
182
183 ;; An operand that can be used as the address in a sibcall insn.
184 (define_predicate "sibcall_operand"
185   (ior (match_operand 0 "const_sibcall_operand")
186        (and (match_code "reg")
187             (match_test "REGNO (op) == STATIC_CHAIN_REGNUM"))))
188
189 ;; TODO: Add a comment here.
190
191 (define_predicate "post_inc_operand"
192   (and (match_code "mem")
193        (match_test "GET_CODE (XEXP (op, 0)) == POST_INC")))
194
195 ;; TODO: Add a comment here.
196
197 (define_predicate "pre_dec_operand"
198   (and (match_code "mem")
199        (match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")))
200
201 ;; A zero constant.
202 (define_predicate "const0_operand"
203   (and (match_code "const_int,const_double,const_vector")
204        (match_test "op == CONST0_RTX (mode)")))
205
206 ;; A one constant (operand for conditional_trap).
207 (define_predicate "const1_operand"
208   (and (match_code "const_int")
209        (match_test "op == const1_rtx")))
210
211 ;; A valid operand for a HImode or QImode conditional operation.
212 ;; ColdFire has tst patterns, but not cmp patterns.
213 (define_predicate "m68k_subword_comparison_operand"
214   (if_then_else (match_test "TARGET_COLDFIRE")
215                 (and (match_code "const_int")
216                      (match_test "op == const0_rtx"))
217                 (match_operand 0 "general_src_operand")))
218
219 ;; An operand for movsi_const0 pattern.
220 (define_predicate "movsi_const0_operand"
221   (and (match_operand 0 "nonimmediate_operand")
222        (match_test "(TARGET_68010 || TARGET_COLDFIRE)
223                     || !(MEM_P (op) && MEM_VOLATILE_P (op))")))
224  
225 ;; A non-symbolic call operand.
226 ;; We need to special case 'const_int' to ignore its mode while matching.
227 (define_predicate "non_symbolic_call_operand"
228   (and (match_operand 0 "call_operand")
229        (ior (and (match_code "const_int")
230                  (match_test "!symbolic_operand (op, mode)"))
231             (match_test "!symbolic_operand (op,mode)"))))
232
233 ;; Special case of general_src_operand, which rejects a few fp
234 ;; constants (which we prefer in registers) before reload.
235
236 (define_predicate "fp_src_operand"
237   (match_operand 0 "general_src_operand")
238 {
239   return !CONSTANT_P (op)
240          || (TARGET_68881
241              && (!standard_68881_constant_p (op)
242                  || reload_in_progress
243                  || reload_completed));
244 })