OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / predicates.md
1 ;; Predicate definitions for Motorola 68000.
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, 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.
20
21 ;; Special case of a general operand that's used as a source
22 ;; operand. Use this to permit reads from PC-relative memory when
23 ;; -mpcrel is specified.
24
25 (define_predicate "general_src_operand"
26   (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
27 {
28   if (TARGET_PCREL
29       && GET_CODE (op) == MEM
30       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
31           || GET_CODE (XEXP (op, 0)) == LABEL_REF
32           || GET_CODE (XEXP (op, 0)) == CONST))
33     return 1;
34   return general_operand (op, mode);
35 })
36
37 ;; Special case of a nonimmediate operand that's used as a source. Use
38 ;; this to permit reads from PC-relative memory when -mpcrel is
39 ;; specified.
40
41 (define_predicate "nonimmediate_src_operand"
42   (match_code "subreg,reg,mem")
43 {
44   if (TARGET_PCREL && GET_CODE (op) == MEM
45       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
46           || GET_CODE (XEXP (op, 0)) == LABEL_REF
47           || GET_CODE (XEXP (op, 0)) == CONST))
48     return 1;
49   return nonimmediate_operand (op, mode);
50 })
51
52 ;; Special case of a memory operand that's used as a source. Use this
53 ;; to permit reads from PC-relative memory when -mpcrel is specified.
54
55 (define_predicate "memory_src_operand"
56   (match_code "subreg,mem")
57 {
58   if (TARGET_PCREL && GET_CODE (op) == MEM
59       && (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
60           || GET_CODE (XEXP (op, 0)) == LABEL_REF
61           || GET_CODE (XEXP (op, 0)) == CONST))
62     return 1;
63   return memory_operand (op, mode);
64 })
65
66 ;; Similar to general_operand, but exclude stack_pointer_rtx.
67
68 (define_predicate "not_sp_operand"
69   (match_code "subreg,reg,mem")
70 {
71   return op != stack_pointer_rtx && nonimmediate_operand (op, mode);
72 })
73
74 ;; Predicate that accepts only a pc-relative address.  This is needed
75 ;; because pc-relative addresses don't satisfy the predicate
76 ;; "general_src_operand".
77
78 (define_predicate "pcrel_address"
79   (match_code "symbol_ref,label_ref,const"))
80
81 ;; Accept integer operands in the range 0..0xffffffff.  We have to
82 ;; check the range carefully since this predicate is used in DImode
83 ;; contexts.  Also, we need some extra crud to make it work when
84 ;; hosted on 64-bit machines.
85
86 (define_predicate "const_uint32_operand"
87   (match_code "const_int,const_double")
88 {
89   /* It doesn't make sense to ask this question with a mode that is
90      not larger than 32 bits.  */
91   gcc_assert (GET_MODE_BITSIZE (mode) > 32);
92
93 #if HOST_BITS_PER_WIDE_INT > 32
94   /* All allowed constants will fit a CONST_INT.  */
95   return (GET_CODE (op) == CONST_INT
96           && (INTVAL (op) >= 0 && INTVAL (op) <= 0xffffffffL));
97 #else
98   return (GET_CODE (op) == CONST_INT
99           || (GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_HIGH (op) == 0));
100 #endif
101 })
102
103 ;; Accept integer operands in the range -0x80000000..0x7fffffff.  We
104 ;; have to check the range carefully since this predicate is used in
105 ;; DImode contexts.
106
107 (define_predicate "const_sint32_operand"
108   (match_code "const_int")
109 {
110   /* It doesn't make sense to ask this question with a mode that is
111      not larger than 32 bits.  */
112   gcc_assert (GET_MODE_BITSIZE (mode) > 32);
113
114   /* All allowed constants will fit a CONST_INT.  */
115   return (GET_CODE (op) == CONST_INT
116           && (INTVAL (op) >= (-0x7fffffff - 1) && INTVAL (op) <= 0x7fffffff));
117 })
118
119 ;; Return true if X is a valid comparison operator for the dbcc
120 ;; instruction.  Note it rejects floating point comparison
121 ;; operators. (In the future we could use Fdbcc).  It also rejects
122 ;; some comparisons when CC_NO_OVERFLOW is set.
123
124 (define_predicate "valid_dbcc_comparison_p"
125   (and (match_code "eq,ne,gtu,ltu,geu,leu,gt,lt,ge,le")
126        (match_test "valid_dbcc_comparison_p_2 (op, mode)")))
127
128 ;; Check for sign_extend or zero_extend.  Used for bit-count operands.
129
130 (define_predicate "extend_operator"
131   (match_code "sign_extend,zero_extend"))
132
133 ;; Returns true if OP is either a symbol reference or a sum of a
134 ;; symbol reference and a constant.
135
136 (define_predicate "symbolic_operand"
137   (match_code "symbol_ref,label_ref,const")
138 {
139   switch (GET_CODE (op))
140     {
141     case SYMBOL_REF:
142     case LABEL_REF:
143       return true;
144
145     case CONST:
146       op = XEXP (op, 0);
147       return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
148                || GET_CODE (XEXP (op, 0)) == LABEL_REF)
149               && GET_CODE (XEXP (op, 1)) == CONST_INT);
150
151 #if 0 /* Deleted, with corresponding change in m68k.h,
152          so as to fit the specs.  No CONST_DOUBLE is ever symbolic.  */
153     case CONST_DOUBLE:
154       return GET_MODE (op) == mode;
155 #endif
156
157     default:
158       return false;
159     }
160 })
161
162 ;; A constant that can be used the address in a call insn.
163 (define_predicate "const_call_operand"
164   (ior (match_operand 0 "const_int_operand")
165        (and (match_test "m68k_symbolic_call != NULL")
166             (match_operand 0 "symbolic_operand"))))
167
168 ;; An operand that can be used as the address in a call insn.
169 (define_predicate "call_operand"
170   (ior (match_operand 0 "const_call_operand")
171        (match_operand 0 "register_operand")))
172
173 ;; TODO: Add a comment here.
174
175 (define_predicate "post_inc_operand"
176   (and (match_code "mem")
177        (match_test "GET_CODE (XEXP (op, 0)) == POST_INC")))
178
179 ;; TODO: Add a comment here.
180
181 (define_predicate "pre_dec_operand"
182   (and (match_code "mem")
183        (match_test "GET_CODE (XEXP (op, 0)) == PRE_DEC")))