This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] cris: Move predicates to predicates.md.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 17 Mar 2005 19:30:14 -0500 (EST)
- Subject: [patch] cris: Move predicates to predicates.md.
Hi,
Attached is a patch to move predicates to predicates.md.
Built cc1 for cris-elf. OK to apply?
p.s.
If you could test this patch on a simulator, that would be greatly
appreciated.
Kazu Hirata
2005-03-18 Kazu Hirata <kazu@cs.umass.edu>
* config/cris/cris.c (cris_bdap_operand,
cris_bdap_biap_operand, cris_orthogonal_operator,
cris_commutative_orth_op, cris_operand_extend_operator,
cris_additive_operand_extend_operator, cris_extend_operator,
cris_plus_or_bound_operator, cris_mem_op,
cris_general_operand_or_symbol,
cris_general_operand_or_gotless_symbol,
cris_general_operand_or_plt_symbol, cris_mem_call_operand):
Move to predicates.md.
* config/cris/cris.h (PREDICATE_CODES): Remove.
* config/cris/cris.md: Include predicates.md.
* config/cris/predicates.md: New.
Index: cris.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/cris/cris.c,v
retrieving revision 1.68
diff -u -d -p -r1.68 cris.c
--- cris.c 3 Mar 2005 03:53:28 -0000 1.68
+++ cris.c 18 Mar 2005 00:25:49 -0000
@@ -202,276 +202,6 @@ int cris_cpu_version = CRIS_DEFAULT_CPU_
struct gcc_target targetm = TARGET_INITIALIZER;
-/* Predicate functions. */
-
-/* This checks a part of an address, the one that is not a plain register
- for an addressing mode using BDAP.
- Allowed operands is either:
- a) a register
- b) a CONST operand (but not a symbol when generating PIC)
- c) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
-
-int
-cris_bdap_operand (rtx op, enum machine_mode mode)
-{
- register enum rtx_code code = GET_CODE (op);
-
- if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
- return 0;
-
- /* Just return whether this is a simple register or constant. */
- if (register_operand (op, mode)
- || (CONSTANT_P (op) && !(flag_pic && cris_symbol (op))))
- return 1;
-
- /* Is it a [r] or possibly a [r+]? */
- if (code == MEM)
- {
- rtx tem = XEXP (op, 0);
-
- if (mode == SImode
- && (register_operand (tem, SImode)
- || (GET_CODE (tem) == POST_INC
- && register_operand (XEXP (tem, 0), SImode))))
- return 1;
- else
- return 0;
- }
-
- /* Perhaps a sign-extended mem: [r].(b|w) or [r+].(b|w)? */
- if (code == SIGN_EXTEND)
- {
- rtx tem = XEXP (op, 0);
-
- if (GET_CODE (tem) != MEM)
- return 0;
-
- tem = XEXP (tem, 0);
- if (mode == SImode
- && (register_operand (tem, SImode)
- || (GET_CODE (tem) == POST_INC
- && register_operand (XEXP (tem, 0), SImode))))
- return 1;
- else
- return 0;
- }
-
- return 0;
-}
-
-/* This is similar to cris_bdap_operand:
- It checks a part of an address, the one that is not a plain register
- for an addressing mode using BDAP *or* BIAP.
- Allowed operands is either:
- a) a register
- b) a CONST operand (but not a symbol when generating PIC)
- c) a mult of (1, 2 or 4) and a register
- d) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
-
-int
-cris_bdap_biap_operand (rtx op, enum machine_mode mode)
-{
- register enum rtx_code code = GET_CODE (op);
- rtx reg;
- rtx val;
-
- /* Check for bdap operand. */
- if (cris_bdap_operand (op, mode))
- return 1;
-
- if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
- return 0;
-
- /* Check that we're looking at a BIAP operand. */
- if (code != MULT)
- return 0;
-
- /* Canonicalize register and multiplicand. */
- if (GET_CODE (XEXP (op, 0)) == CONST_INT)
- {
- val = XEXP (op, 0);
- reg = XEXP (op, 1);
- }
- else
- {
- val = XEXP (op, 1);
- reg = XEXP (op, 0);
- }
-
- /* Check that the operands are correct after canonicalization. */
- if (! register_operand (reg, SImode) || GET_CODE (val) != CONST_INT)
- return 0;
-
- /* Check that the multiplicand has a valid value. */
- if ((code == MULT
- && (INTVAL (val) == 1 || INTVAL (val) == 2 || INTVAL (val) == 4)))
- return 1;
-
- return 0;
-}
-
-/* Check if MODE is same as mode for X, and X is PLUS, MINUS, IOR or
- AND or UMIN. */
-
-int
-cris_orthogonal_operator (rtx x, enum machine_mode mode)
-{
- enum rtx_code code = GET_CODE (x);
-
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return (GET_MODE (x) == mode
- && (code == PLUS || code == MINUS
- || code == IOR || code == AND || code == UMIN));
-}
-
-/* Check if MODE is same as mode for X, and X is PLUS, IOR or AND or
- UMIN. */
-
-int
-cris_commutative_orth_op (rtx x, enum machine_mode mode)
-{
- enum rtx_code code = GET_CODE (x);
-
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return (GET_MODE (x) == mode &&
- (code == PLUS
- || code == IOR || code == AND || code == UMIN));
-}
-
-/* Check if MODE is same as mode for X, and X is PLUS or MINUS or UMIN.
- By the name, you might think we should include MULT. We don't because
- it doesn't accept the same addressing modes as the others (ony
- registers) and there's also the problem of handling TARGET_MUL_BUG. */
-
-int
-cris_operand_extend_operator (rtx x, enum machine_mode mode)
-{
- enum rtx_code code = GET_CODE (x);
-
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return (GET_MODE (x) == mode
- && (code == PLUS || code == MINUS || code == UMIN));
-}
-
-/* Check if MODE is same as mode for X, and X is PLUS or MINUS. */
-
-int
-cris_additive_operand_extend_operator (rtx x, enum machine_mode mode)
-{
- enum rtx_code code = GET_CODE (x);
-
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return (GET_MODE (x) == mode
- && (code == PLUS || code == MINUS));
-}
-
-/* Check to see if MODE is same as mode for X, and X is SIGN_EXTEND or
- ZERO_EXTEND. */
-
-int
-cris_extend_operator (rtx x, enum machine_mode mode)
-{
- enum rtx_code code = GET_CODE (x);
-
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return
- (GET_MODE (x) == mode && (code == SIGN_EXTEND || code == ZERO_EXTEND));
-}
-
-/* Check to see if MODE is same as mode for X, and X is PLUS or BOUND. */
-
-int
-cris_plus_or_bound_operator (rtx x, enum machine_mode mode)
-{
- enum rtx_code code = GET_CODE (x);
-
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return
- (GET_MODE (x) == mode && (code == UMIN || code == PLUS));
-}
-
-/* Used as an operator to get a handle on a already-known-valid MEM rtx:es
- (no need to validate the address), where some address expression parts
- have their own match_operand. */
-
-int
-cris_mem_op (rtx x, enum machine_mode mode)
-{
- if (mode == VOIDmode)
- mode = GET_MODE (x);
-
- return GET_MODE (x) == mode && GET_CODE (x) == MEM;
-}
-
-/* Since with -fPIC, not all symbols are valid PIC symbols or indeed
- general_operands, we have to have a predicate that matches it for the
- "movsi" expander. */
-
-int
-cris_general_operand_or_symbol (rtx op, enum machine_mode mode)
-{
- return general_operand (op, mode)
- || (CONSTANT_P (op) && cris_symbol (op));
-}
-
-/* Since a PIC symbol without a GOT entry is not a general_operand, we
- have to have a predicate that matches it. We use this in the expanded
- "movsi" anonymous pattern for PIC symbols. */
-
-int
-cris_general_operand_or_gotless_symbol (rtx op, enum machine_mode mode)
-{
- return general_operand (op, mode)
- || (CONSTANT_P (op) && cris_gotless_symbol (op));
-}
-
-/* Since a PLT symbol is not a general_operand, we have to have a
- predicate that matches it when we need it. We use this in the expanded
- "call" and "call_value" anonymous patterns. */
-
-int
-cris_general_operand_or_plt_symbol (rtx op, enum machine_mode mode)
-{
- return general_operand (op, mode)
- || (GET_CODE (op) == CONST
- && GET_CODE (XEXP (op, 0)) == UNSPEC
- && !TARGET_AVOID_GOTPLT);
-}
-
-/* This matches a (MEM (general_operand)) or
- (MEM (cris_general_operand_or_symbol)). The second one isn't a valid
- memory_operand, so we need this predicate to recognize call
- destinations before we change them to a PLT operand (by wrapping in
- UNSPEC 0). */
-
-int
-cris_mem_call_operand (rtx op, enum machine_mode mode)
-{
- rtx xmem;
-
- if (GET_CODE (op) != MEM)
- return 0;
-
- if (memory_operand (op, mode))
- return 1;
-
- xmem = XEXP (op, 0);
-
- return cris_general_operand_or_symbol (xmem, GET_MODE (op));
-}
-
/* The CONDITIONAL_REGISTER_USAGE worker. */
void
Index: cris.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/cris/cris.h,v
retrieving revision 1.87
diff -u -d -p -r1.87 cris.h
--- cris.h 3 Mar 2005 03:53:29 -0000 1.87
+++ cris.h 18 Mar 2005 00:25:50 -0000
@@ -1611,40 +1611,6 @@ struct cum_args {int regs;};
/* Node: Misc */
-/* FIXME: Check this one more time. */
-#define PREDICATE_CODES \
- {"cris_orthogonal_operator", \
- {PLUS, MINUS, IOR, AND, UMIN}}, \
- {"cris_commutative_orth_op", \
- {PLUS, IOR, AND, UMIN}}, \
- {"cris_operand_extend_operator", \
- {PLUS, MINUS, UMIN}}, \
- {"cris_additive_operand_extend_operator", \
- {PLUS, MINUS}}, \
- {"cris_extend_operator", \
- {ZERO_EXTEND, SIGN_EXTEND}}, \
- {"cris_plus_or_bound_operator", \
- {PLUS, UMIN}}, \
- {"cris_mem_op", \
- {MEM}}, \
- {"cris_bdap_operand", \
- {SUBREG, REG, LABEL_REF, SYMBOL_REF, MEM, CONST_INT, \
- CONST_DOUBLE, CONST, SIGN_EXTEND}}, \
- {"cris_bdap_biap_operand", \
- {SUBREG, REG, LABEL_REF, SYMBOL_REF, MEM, CONST_INT, \
- CONST_DOUBLE, CONST, SIGN_EXTEND, MULT}}, \
- {"cris_general_operand_or_gotless_symbol", \
- {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, \
- LABEL_REF, SUBREG, REG, MEM}}, \
- {"cris_general_operand_or_symbol", \
- {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, \
- LABEL_REF, SUBREG, REG, MEM}}, \
- {"cris_general_operand_or_plt_symbol", \
- {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, \
- LABEL_REF, SUBREG, REG, MEM}}, \
- {"cris_mem_call_operand", \
- {MEM}},
-
/* A combination of the bound (umin) insn together with a
sign-extended add via the table to PC seems optimal.
If the table overflows, the assembler will take care of it.
Index: cris.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/cris/cris.md,v
retrieving revision 1.25
diff -u -d -p -r1.25 cris.md
--- cris.md 3 Mar 2005 03:53:29 -0000 1.25
+++ cris.md 18 Mar 2005 00:25:50 -0000
@@ -129,6 +129,8 @@
(define_delay (eq_attr "slottable" "has_slot")
[(eq_attr "slottable" "yes") (nil) (nil)])
+
+(include "predicates.md")
;; Test insns.
--- /dev/null 2005-03-04 04:24:27.812945112 -0500
+++ predicates.md 2005-03-17 19:17:24.059427928 -0500
@@ -0,0 +1,288 @@
+;; Predicate definitions for CRIS.
+;; Copyright (C) 2005 Free Software Foundation, Inc.
+;;
+;; This file is part of GCC.
+;;
+;; GCC is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+;;
+;; GCC is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GCC; see the file COPYING. If not, write to
+;; the Free Software Foundation, 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;; Check if MODE is same as mode for OP, and OP is PLUS, MINUS, IOR or
+;; AND or UMIN.
+
+(define_predicate "cris_orthogonal_operator"
+ (match_code "plus,minus,ior,and,umin")
+{
+ enum rtx_code code = GET_CODE (op);
+
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return (GET_MODE (op) == mode
+ && (code == PLUS || code == MINUS
+ || code == IOR || code == AND || code == UMIN));
+})
+
+;; Check if MODE is same as mode for OP, and OP is PLUS, IOR or AND or
+;; UMIN.
+
+(define_predicate "cris_commutative_orth_op"
+ (match_code "plus,ior,and,umin")
+{
+ enum rtx_code code = GET_CODE (op);
+
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return (GET_MODE (op) == mode &&
+ (code == PLUS
+ || code == IOR || code == AND || code == UMIN));
+})
+
+;; Check if MODE is same as mode for X, and OP is PLUS or MINUS or
+;; UMIN. By the name, you might think we should include MULT. We
+;; don't because it doesn't accept the same addressing modes as the
+;; others (ony registers) and there's also the problem of handling
+;; TARGET_MUL_BUG.
+
+(define_predicate "cris_operand_extend_operator"
+ (match_code "plus,minus,umin")
+{
+ enum rtx_code code = GET_CODE (op);
+
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return (GET_MODE (op) == mode
+ && (code == PLUS || code == MINUS || code == UMIN));
+})
+
+;; Check if MODE is same as mode for OP, and OP is PLUS or MINUS.
+
+(define_predicate "cris_additive_operand_extend_operator"
+ (match_code "plus,minus")
+{
+ enum rtx_code code = GET_CODE (op);
+
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return (GET_MODE (op) == mode
+ && (code == PLUS || code == MINUS));
+})
+
+;; Check to see if MODE is same as mode for OP, and OP is SIGN_EXTEND
+;; or ZERO_EXTEND.
+
+(define_predicate "cris_extend_operator"
+ (match_code "zero_extend,sign_extend")
+{
+ enum rtx_code code = GET_CODE (op);
+
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return
+ (GET_MODE (op) == mode && (code == SIGN_EXTEND || code == ZERO_EXTEND));
+})
+
+;; Check to see if MODE is same as mode for OP, and OP is PLUS or
+;; BOUND.
+
+(define_predicate "cris_plus_or_bound_operator"
+ (match_code "plus,umin")
+{
+ enum rtx_code code = GET_CODE (op);
+
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return
+ (GET_MODE (op) == mode && (code == UMIN || code == PLUS));
+})
+
+;; Used as an operator to get a handle on a already-known-valid MEM
+;; rtx:es (no need to validate the address), where some address
+;; expression parts have their own match_operand.
+
+(define_predicate "cris_mem_op"
+ (match_code "mem")
+{
+ if (mode == VOIDmode)
+ mode = GET_MODE (op);
+
+ return GET_MODE (op) == mode && GET_CODE (op) == MEM;
+})
+
+;; This checks a part of an address, the one that is not a plain
+;; register for an addressing mode using BDAP. Allowed operands is
+;; either:
+;; a) a register
+;; b) a CONST operand (but not a symbol when generating PIC)
+;; c) a [r] or [r+] in SImode, or sign-extend from HI or QI.
+
+(define_predicate "cris_bdap_operand"
+ (match_code "subreg,reg,label_ref,symbol_ref,mem,const_int,const_double,const,sign_extend")
+{
+ register enum rtx_code code = GET_CODE (op);
+
+ if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
+ return 0;
+
+ /* Just return whether this is a simple register or constant. */
+ if (register_operand (op, mode)
+ || (CONSTANT_P (op) && !(flag_pic && cris_symbol (op))))
+ return 1;
+
+ /* Is it a [r] or possibly a [r+]? */
+ if (code == MEM)
+ {
+ rtx tem = XEXP (op, 0);
+
+ if (mode == SImode
+ && (register_operand (tem, SImode)
+ || (GET_CODE (tem) == POST_INC
+ && register_operand (XEXP (tem, 0), SImode))))
+ return 1;
+ else
+ return 0;
+ }
+
+ /* Perhaps a sign-extended mem: [r].(b|w) or [r+].(b|w)? */
+ if (code == SIGN_EXTEND)
+ {
+ rtx tem = XEXP (op, 0);
+
+ if (GET_CODE (tem) != MEM)
+ return 0;
+
+ tem = XEXP (tem, 0);
+ if (mode == SImode
+ && (register_operand (tem, SImode)
+ || (GET_CODE (tem) == POST_INC
+ && register_operand (XEXP (tem, 0), SImode))))
+ return 1;
+ else
+ return 0;
+ }
+
+ return 0;
+})
+
+;; This is similar to cris_bdap_operand: It checks a part of an
+;; address, the one that is not a plain register for an addressing
+;; mode using BDAP *or* BIAP. Allowed operands is either:
+;; a) a register
+;; b) a CONST operand (but not a symbol when generating PIC)
+;; c) a mult of (1, 2 or 4) and a register
+;; d) a [r] or [r+] in SImode, or sign-extend from HI or QI.
+
+(define_predicate "cris_bdap_biap_operand"
+ (match_code "subreg,reg,label_ref,symbol_ref,mem,const_int,const_double,const,sign_extend,mult")
+{
+ register enum rtx_code code = GET_CODE (op);
+ rtx reg;
+ rtx val;
+
+ /* Check for bdap operand. */
+ if (cris_bdap_operand (op, mode))
+ return 1;
+
+ if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
+ return 0;
+
+ /* Check that we're looking at a BIAP operand. */
+ if (code != MULT)
+ return 0;
+
+ /* Canonicalize register and multiplicand. */
+ if (GET_CODE (XEXP (op, 0)) == CONST_INT)
+ {
+ val = XEXP (op, 0);
+ reg = XEXP (op, 1);
+ }
+ else
+ {
+ val = XEXP (op, 1);
+ reg = XEXP (op, 0);
+ }
+
+ /* Check that the operands are correct after canonicalization. */
+ if (! register_operand (reg, SImode) || GET_CODE (val) != CONST_INT)
+ return 0;
+
+ /* Check that the multiplicand has a valid value. */
+ if ((code == MULT
+ && (INTVAL (val) == 1 || INTVAL (val) == 2 || INTVAL (val) == 4)))
+ return 1;
+
+ return 0;
+})
+
+;; Since a PIC symbol without a GOT entry is not a general_operand, we
+;; have to have a predicate that matches it. We use this in the
+;; expanded "movsi" anonymous pattern for PIC symbols.
+
+(define_predicate "cris_general_operand_or_gotless_symbol"
+ (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
+{
+ return general_operand (op, mode)
+ || (CONSTANT_P (op) && cris_gotless_symbol (op));
+})
+
+;; Since with -fPIC, not all symbols are valid PIC symbols or indeed
+;; general_operands, we have to have a predicate that matches it for
+;; the "movsi" expander.
+
+(define_predicate "cris_general_operand_or_symbol"
+ (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
+{
+ return general_operand (op, mode)
+ || (CONSTANT_P (op) && cris_symbol (op));
+})
+
+;; Since a PLT symbol is not a general_operand, we have to have a
+;; predicate that matches it when we need it. We use this in the
+;; expanded "call" and "call_value" anonymous patterns.
+
+(define_predicate "cris_general_operand_or_plt_symbol"
+ (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem")
+{
+ return general_operand (op, mode)
+ || (GET_CODE (op) == CONST
+ && GET_CODE (XEXP (op, 0)) == UNSPEC
+ && !TARGET_AVOID_GOTPLT);
+})
+
+;; This matches a (MEM (general_operand)) or (MEM
+;; (cris_general_operand_or_symbol)). The second one isn't a valid
+;; memory_operand, so we need this predicate to recognize call
+;; destinations before we change them to a PLT operand (by wrapping in
+;; UNSPEC 0).
+
+(define_predicate "cris_mem_call_operand"
+ (match_code "mem")
+{
+ rtx xmem;
+
+ if (GET_CODE (op) != MEM)
+ return 0;
+
+ if (memory_operand (op, mode))
+ return 1;
+
+ xmem = XEXP (op, 0);
+
+ return cris_general_operand_or_symbol (xmem, GET_MODE (op));
+})