1;; Operand and operator predicates for the GCC CRIS port.
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
22;; Operator predicates.
23
24(define_predicate "cris_orthogonal_operator"
25  (match_code "plus, minus, ior, and, umin"))
26
27(define_predicate "cris_commutative_orth_op"
28  (match_code "plus, ior, and, umin"))
29
30;; By the name, you might think we should include MULT.  We don't because
31;; it doesn't accept the same addressing modes as the others (only
32;; registers) and there's also the problem of handling TARGET_MUL_BUG.
33
34(define_predicate "cris_operand_extend_operator"
35  (match_code "plus, minus, umin"))
36
37(define_predicate "cris_additive_operand_extend_operator"
38  (match_code "plus, minus"))
39
40(define_predicate "cris_extend_operator"
41  (match_code "zero_extend, sign_extend"))
42
43(define_predicate "cris_plus_or_bound_operator"
44  (match_code "plus, umin"))
45
46;; Used as an operator to get a handle on a already-known-valid MEM rtx:es
47;; (no need to validate the address), where some address expression parts
48;; have their own match_operand.
49
50(define_predicate "cris_mem_op"
51  (match_code "mem"))
52
53(define_predicate "cris_load_multiple_op"
54  (and (match_code "parallel")
55       (match_test "cris_movem_load_rest_p (op, 0)")))
56
57(define_predicate "cris_store_multiple_op"
58  (and (match_code "parallel")
59       (match_test "cris_store_multiple_op_p (op)")))
60
61
62;; Operand helper predicates.
63
64(define_predicate "cris_bdap_const_operand"
65  (and (match_code "label_ref, symbol_ref, const_int, const_double, const")
66       (ior (not (match_test "flag_pic"))
67	    (match_test "cris_valid_pic_const (op)"))))
68
69(define_predicate "cris_simple_address_operand"
70  (ior (match_operand:SI 0 "register_operand")
71       (and (match_code "post_inc")
72	    (match_test "register_operand (XEXP (op, 0), Pmode)"))))
73
74(define_predicate "cris_simple_operand"
75  (ior (match_operand 0 "register_operand")
76       (and (match_code "mem")
77	    (match_test "cris_simple_address_operand (XEXP (op, 0),
78						      Pmode)"))))
79
80;; The caller needs to use :SI.
81(define_predicate "cris_bdap_sign_extend_operand"
82  (and (match_code "sign_extend")
83       (and (match_test "MEM_P (XEXP (op, 0))")
84	    (match_test "cris_simple_address_operand (XEXP (XEXP (op, 0), 0),
85						      Pmode)"))))
86
87;; FIXME: Should not have to test for 1.
88(define_predicate "cris_scale_int_operand"
89  (and (match_code "const_int")
90       (ior (ior (match_test "op == GEN_INT (4)")
91		 (match_test "op == const2_rtx"))
92	    (match_test "op == const1_rtx"))))
93
94;; FIXME: Should be able to assume (reg int).
95(define_predicate "cris_biap_mult_operand"
96  (and (match_code "mult")
97       (ior (and (match_test "register_operand (XEXP (op, 0), Pmode)")
98		 (match_test "cris_scale_int_operand (XEXP (op, 1), Pmode)"))
99	    (and (match_test "cris_scale_int_operand (XEXP (op, 0), Pmode)")
100		 (match_test "register_operand (XEXP (op, 1), Pmode)")))))
101
102
103;; Operand predicates.
104
105;; This checks a part of an address, the one that is not a plain register
106;; for an addressing mode using BDAP.
107;; Allowed operands are either:
108;; a) a register
109;; b) a CONST operand (but not a symbol when generating PIC)
110;; c) a [r] or [r+] in SImode, or sign-extend from HI or QI.
111
112(define_predicate "cris_bdap_operand"
113  (ior (match_operand 0 "cris_bdap_const_operand")
114       (ior (match_operand:SI 0 "cris_simple_operand")
115	    (match_operand:SI 0 "cris_bdap_sign_extend_operand"))))
116
117;; This is similar to cris_bdap_operand:
118;; It checks a part of an address, the one that is not a plain register
119;; for an addressing mode using BDAP or BIAP.
120;; Allowed operands are either:
121;; a) a register
122;; b) a CONST operand (but not a symbol when generating PIC)
123;; c) a mult of (1, 2 or 4) and a register
124;; d) a [r] or [r+] in SImode, or sign-extend from HI or QI.  */
125
126(define_predicate "cris_bdap_biap_operand"
127  (ior (match_operand 0 "cris_bdap_operand")
128       (match_operand 0 "cris_biap_mult_operand")))
129
130;; Since with -fPIC, not all symbols are valid PIC symbols or indeed
131;; general_operands, we have to have a predicate that matches it for the
132;; "movsi" expander.
133;; FIXME: Can s/special_// when PR 20413 is fixed.
134
135(define_special_predicate "cris_general_operand_or_symbol"
136  (ior (match_operand 0 "general_operand")
137       (and (match_code "const, symbol_ref, label_ref")
138       	    ; The following test is actually just an assertion.
139	    (match_test "cris_pic_symbol_type_of (op) != cris_no_symbol"))))
140
141;; Since a PLT symbol is not a general_operand, we have to have a
142;; predicate that matches it when we need it.  We use this in the expanded
143;; "call" and "call_value" anonymous patterns.
144
145(define_predicate "cris_general_operand_or_plt_symbol"
146  (ior (match_operand 0 "general_operand")
147       (and (match_code "const")
148	    (and (match_test "GET_CODE (XEXP (op, 0)) == UNSPEC")
149		 (not (match_test "TARGET_AVOID_GOTPLT"))))))
150
151;; This matches a (MEM (general_operand)) or
152;; (MEM (cris_general_operand_or_symbol)).  The second one isn't a valid
153;; memory_operand, so we need this predicate to recognize call
154;; destinations before we change them to a PLT operand (by wrapping in
155;; UNSPEC CRIS_UNSPEC_PLT).
156
157(define_predicate "cris_mem_call_operand"
158  (and (match_code "mem")
159       (ior (match_operand 0 "memory_operand")
160	    (match_test "cris_general_operand_or_symbol (XEXP (op, 0),
161							 Pmode)"))))
162