Patchwork convert stormy16 to constraints.md

login
register
mail settings
Submitter Nathan Froyd
Date Feb. 14, 2011, 8:24 p.m.
Message ID <20110214202459.GG6247@codesourcery.com>
Download mbox | patch
Permalink /patch/83155/
State New
Headers show

Comments

Nathan Froyd - Feb. 14, 2011, 8:24 p.m.
As $SUBJECT suggests.  The fiddling with stormy16-protos.h comes about
from needing to export xstormy16_legitimate_address_p for the 'S'
constraint.

Tested with cross to xstormy16-elf.  OK to commit?

-Nathan

	* config/stormy16/constraints.md: New file.
	* config/stormy16/predicates.md (nonimmediate_nonstack_operand):
	Use satisfies_constraint_Q and satisfies_constraint_R.
	* config/stormy16/stomry16-protos.h (xstormy16_extra_constraint_p):
	Delete.
	(xstormy16_legitiamte_address_p): Declare.
	* config/stormy16/stormy16.h (REG_CLASS_FROM_LETTER): Delete.
	(CONST_OK_FOR_LETTER_P, CONST_DOUBLE_OK_FOR_LETTER_P): Delete.
	(EXTRA_CONSTRAINT): Delete.
	* config/stormy16/stormy16.c (xstormy16_legitiamte_address_p):
	Un-staticize.
	(xstormy16_extra_constraint_p): Delete.
Richard Henderson - Feb. 14, 2011, 8:50 p.m.
On 02/14/2011 12:24 PM, Nathan Froyd wrote:
> 	* config/stormy16/constraints.md: New file.
> 	* config/stormy16/predicates.md (nonimmediate_nonstack_operand):
> 	Use satisfies_constraint_Q and satisfies_constraint_R.
> 	* config/stormy16/stomry16-protos.h (xstormy16_extra_constraint_p):
> 	Delete.
> 	(xstormy16_legitiamte_address_p): Declare.
> 	* config/stormy16/stormy16.h (REG_CLASS_FROM_LETTER): Delete.
> 	(CONST_OK_FOR_LETTER_P, CONST_DOUBLE_OK_FOR_LETTER_P): Delete.
> 	(EXTRA_CONSTRAINT): Delete.
> 	* config/stormy16/stormy16.c (xstormy16_legitiamte_address_p):
> 	Un-staticize.
> 	(xstormy16_extra_constraint_p): Delete.

Ok except,

> +(define_constraint "W"
> +  "@internal"
> +  (match_test "xstormy16_below100_operand (op, mode)"))

I believe this is exactly

  (match_operand 0 "xstormy16_below100_operand")


For the to-do list, there's a whole set of define_predicates that use
match_code + C code where ior + match_operand would do.  There are also
a couple of predicates with match_code + C code, where the C code
contains a test redundant with the match_code.


r~
Nathan Froyd - Feb. 14, 2011, 8:54 p.m.
On Mon, Feb 14, 2011 at 12:50:39PM -0800, Richard Henderson wrote:
> Ok except,
> 
> > +(define_constraint "W"
> > +  "@internal"
> > +  (match_test "xstormy16_below100_operand (op, mode)"))
> 
> I believe this is exactly
> 
>   (match_operand 0 "xstormy16_below100_operand")
> 
> For the to-do list, there's a whole set of define_predicates that use
> match_code + C code where ior + match_operand would do.  There are also
> a couple of predicates with match_code + C code, where the C code
> contains a test redundant with the match_code.

Thanks for the review.  FAOD, you're talking about cleanups across
config/*/predicates.md?

-Nathan
Richard Henderson - Feb. 14, 2011, 9:02 p.m.
On 02/14/2011 12:54 PM, Nathan Froyd wrote:
>> For the to-do list, there's a whole set of define_predicates that use
>> match_code + C code where ior + match_operand would do.  There are also
>> a couple of predicates with match_code + C code, where the C code
>> contains a test redundant with the match_code.
> 
> Thanks for the review.  FAOD, you're talking about cleanups across
> config/*/predicates.md?

I was talking about stormy16 here in particular, but certainly the
review probably ought to be done across all the ports.

If we start talking across all the ports, we also ought to fix the
fact that the two-argument (match_code "x" "loc") and the implicit
variables (ival etc) only work with define_constraint and not with
define_predicate.  That would enable even more cleanups.


r~
Nathan Froyd - Feb. 14, 2011, 10:17 p.m.
On Mon, Feb 14, 2011 at 01:02:22PM -0800, Richard Henderson wrote:
> On 02/14/2011 12:54 PM, Nathan Froyd wrote:
> >> For the to-do list, there's a whole set of define_predicates that use
> >> match_code + C code where ior + match_operand would do.  There are also
> >> a couple of predicates with match_code + C code, where the C code
> >> contains a test redundant with the match_code.
> > 
> > Thanks for the review.  FAOD, you're talking about cleanups across
> > config/*/predicates.md?
> 
> I was talking about stormy16 here in particular, but certainly the
> review probably ought to be done across all the ports.
> 
> If we start talking across all the ports, we also ought to fix the
> fact that the two-argument (match_code "x" "loc") and the implicit
> variables (ival etc) only work with define_constraint and not with
> define_predicate.  That would enable even more cleanups.

As long as we're wishing, WDYT about something like:

  (match_c_predicate "name" "path-specifier")

(name suggestions welcome: overloading match_test didn't seem too nice
and match_predicate might be confusing...)

so that you don't have to write something like:

  (and (match_code "mem")
       (match_code "add" "0")
       (match_code "symbol_ref" "00")
       (match_test "PREDICATE (XEXP (XEXP (...)))"))

but instead:

  (and (match_code "mem")
       (match_code "add" "0")
       (match_code "symbol_ref" "00")
       (match_c_predicate "PREDICATE" "00"))
?

Even better would be some notation where you could write a single
identifier for a called function, or some sort of C expression where the
rtx denoted by the path-specifier could be automagically referenced.

-Nathan
Nick Clifton - Feb. 15, 2011, 11:05 a.m.
Hi Nathan,

> 	* config/stormy16/constraints.md: New file.
> 	* config/stormy16/predicates.md (nonimmediate_nonstack_operand):
> 	Use satisfies_constraint_Q and satisfies_constraint_R.
> 	* config/stormy16/stomry16-protos.h (xstormy16_extra_constraint_p):
> 	Delete.
> 	(xstormy16_legitiamte_address_p): Declare.
> 	* config/stormy16/stormy16.h (REG_CLASS_FROM_LETTER): Delete.
> 	(CONST_OK_FOR_LETTER_P, CONST_DOUBLE_OK_FOR_LETTER_P): Delete.
> 	(EXTRA_CONSTRAINT): Delete.
> 	* config/stormy16/stormy16.c (xstormy16_legitiamte_address_p):
> 	Un-staticize.
> 	(xstormy16_extra_constraint_p): Delete.

Approved - please apply.

Cheers
   Nick

Patch

diff --git a/gcc/config/stormy16/constraints.md b/gcc/config/stormy16/constraints.md
new file mode 100644
index 0000000..aab5ec1
--- /dev/null
+++ b/gcc/config/stormy16/constraints.md
@@ -0,0 +1,119 @@ 
+;; Constraint definitions for XSTORMY16.
+;; Copyright (C) 2011 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 3, 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 COPYING3.  If not see
+;; <http://www.gnu.org/licenses/>.
+
+;; Register constraints.
+(define_register_constraint "a" "R0_REGS"
+  "@internal")
+
+(define_register_constraint "b" "R1_REGS"
+  "@internal")
+
+(define_register_constraint "c" "R2_REGS"
+  "@internal")
+
+(define_register_constraint "d" "R8_REGS"
+  "@internal")
+
+(define_register_constraint "e" "EIGHT_REGS"
+  "@internal")
+
+(define_register_constraint "t" "TWO_REGS"
+  "@internal")
+
+(define_register_constraint "z" "ICALL_REGS"
+  "@internal")
+
+;; Integer constraints.
+(define_constraint "I"
+  "An integer between 0 and 3."
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (ival, 0, 3)")))
+
+(define_constraint "J"
+  "A power of two."
+  (and (match_code "const_int")
+       (match_test "exact_log2 (ival) != -1")))
+
+(define_constraint "K"
+  "A power of two when inverted."
+  (and (match_code "const_int")
+       (match_test "exact_log2 (~ival) != -1")))
+
+(define_constraint "L"
+  "An 8-bit unsigned integer."
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (ival, 0, 255)")))
+
+(define_constraint "M"
+  "An integer between -255 and 0."
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (ival, -255, 0)")))
+
+(define_constraint "N"
+  "An integer between -3 and 0."
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (ival, -3, 0)")))
+
+(define_constraint "O"
+  "An integer between 1 and 4."
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (ival, 1, 4)")))
+
+(define_constraint "P"
+  "An integer between -4 and -1."
+  (and (match_code "const_int")
+       (match_test "IN_RANGE (ival, -4, -1)")))
+
+;; Extra constraints.
+(define_constraint "Q"
+  "A register push operation."
+  (and (match_code "mem")
+       (match_code "post_inc" "0")
+       (match_test "XEXP (XEXP (op, 0), 0) == stack_pointer_rtx")))
+
+(define_constraint "R"
+  "A register pop operation."
+  (and (match_code "mem")
+       (match_code "pre_dec" "0")
+       (match_test "XEXP (XEXP (op, 0), 0) == stack_pointer_rtx")))
+
+(define_constraint "S"
+  "An immediate memory address."
+  (and (match_code "mem")
+       (match_code "const_int" "0")
+       (match_test "xstormy16_legitimate_address_p (VOIDmode, XEXP (op, 0), false)")))
+
+(define_constraint "T"
+  "@internal"
+  ;; For Rx; not implemented yet.
+  (match_test "0"))
+
+(define_constraint "U"
+  "An integer not between 2 and 15."
+  (and (match_code "const_int")
+       (match_test "!IN_RANGE (ival, 2, 15)")))
+
+(define_constraint "W"
+  "@internal"
+  (match_test "xstormy16_below100_operand (op, mode)"))
+
+(define_constraint "Z"
+  "Zero."
+  (and (match_code "const_int")
+       (match_test "ival == 0")))
\ No newline at end of file
diff --git a/gcc/config/stormy16/predicates.md b/gcc/config/stormy16/predicates.md
index 0e1d394..7270c7f 100644
--- a/gcc/config/stormy16/predicates.md
+++ b/gcc/config/stormy16/predicates.md
@@ -140,8 +140,8 @@ 
 {
   /* 'Q' is for pushes, 'R' for pops.  */
   return (nonimmediate_operand (op, mode) 
-	  && ! xstormy16_extra_constraint_p (op, 'Q')
-	  && ! xstormy16_extra_constraint_p (op, 'R'));
+	  && ! satisfies_constraint_Q (op)
+	  && ! satisfies_constraint_R (op));
 })
 
 (define_predicate "xstormy16_carry_plus_operand"
diff --git a/gcc/config/stormy16/stormy16-protos.h b/gcc/config/stormy16/stormy16-protos.h
index 3edbc33..ad44e15 100644
--- a/gcc/config/stormy16/stormy16-protos.h
+++ b/gcc/config/stormy16/stormy16-protos.h
@@ -45,7 +45,6 @@  extern void xstormy16_emit_cbranch (enum rtx_code, rtx, rtx, rtx);
 extern char *xstormy16_output_cbranch_hi (rtx, const char *, int, rtx);
 extern char *xstormy16_output_cbranch_si (rtx, const char *, int, rtx);
 extern int xstormy16_mode_dependent_address_p (rtx);
-extern int xstormy16_extra_constraint_p (rtx, int);
 
 extern void xstormy16_print_operand (FILE *, rtx, int);
 extern void xstormy16_print_operand_address (FILE *, rtx);
@@ -72,5 +71,6 @@  extern const char * xstormy16_output_shift (enum machine_mode, enum rtx_code,
 					    rtx, rtx, rtx);
 extern int  xstormy16_below100_symbol (rtx, enum machine_mode);
 extern int  xstormy16_splittable_below100_operand (rtx, enum machine_mode);
+extern bool xstormy16_legitimate_address_p (enum machine_mode, rtx, bool);
 #endif
 
diff --git a/gcc/config/stormy16/stormy16.c b/gcc/config/stormy16/stormy16.c
index fa5c5b5..e4cd10e 100644
--- a/gcc/config/stormy16/stormy16.c
+++ b/gcc/config/stormy16/stormy16.c
@@ -615,7 +615,7 @@  xstormy16_expand_andqi3 (rtx *operands)
   && INTVAL (X) + (OFFSET) < 0x8000					 \
   && (INTVAL (X) + (OFFSET) < 0x100 || INTVAL (X) + (OFFSET) >= 0x7F00))
 
-static bool
+bool
 xstormy16_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
 				rtx x, bool strict)
 {
@@ -683,60 +683,6 @@  xstormy16_mode_dependent_address_p (rtx x)
   return 0;
 }
 
-/* A C expression that defines the optional machine-dependent constraint
-   letters (`Q', `R', `S', `T', `U') that can be used to segregate specific
-   types of operands, usually memory references, for the target machine.
-   Normally this macro will not be defined.  If it is required for a particular
-   target machine, it should return 1 if VALUE corresponds to the operand type
-   represented by the constraint letter C.  If C is not defined as an extra
-   constraint, the value returned should be 0 regardless of VALUE.  */
-
-int
-xstormy16_extra_constraint_p (rtx x, int c)
-{
-  switch (c)
-    {
-      /* 'Q' is for pushes.  */
-    case 'Q':
-      return (MEM_P (x)
-	      && GET_CODE (XEXP (x, 0)) == POST_INC
-	      && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx);
-
-      /* 'R' is for pops.  */
-    case 'R':
-      return (MEM_P (x)
-	      && GET_CODE (XEXP (x, 0)) == PRE_DEC
-	      && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx);
-
-      /* 'S' is for immediate memory addresses.  */
-    case 'S':
-      return (MEM_P (x)
-	      && CONST_INT_P (XEXP (x, 0))
-	      && xstormy16_legitimate_address_p (VOIDmode, XEXP (x, 0), 0));
-
-      /* 'T' is for Rx.  */
-    case 'T':
-      /* Not implemented yet.  */
-      return 0;
-
-      /* 'U' is for CONST_INT values not between 2 and 15 inclusive,
-	 for allocating a scratch register for 32-bit shifts.  */
-    case 'U':
-      return (CONST_INT_P (x) && (! IN_RANGE (INTVAL (x), 2, 15)));
-
-      /* 'Z' is for CONST_INT value zero.  This is for adding zero to
-	 a register in addhi3, which would otherwise require a carry.  */
-    case 'Z':
-      return (CONST_INT_P (x) && (INTVAL (x) == 0));
-
-    case 'W':
-      return xstormy16_below100_operand (x, GET_MODE (x));
-
-    default:
-      return 0;
-    }
-}
-
 int
 short_memory_operand (rtx x, enum machine_mode mode)
 {
diff --git a/gcc/config/stormy16/stormy16.h b/gcc/config/stormy16/stormy16.h
index 8789d90..c92af1d 100644
--- a/gcc/config/stormy16/stormy16.h
+++ b/gcc/config/stormy16/stormy16.h
@@ -225,26 +225,6 @@  enum reg_class
 
 #define INDEX_REG_CLASS GENERAL_REGS
 
-/*   The following letters are unavailable, due to being used as
-   constraints:
-	'0'..'9'
-	'<', '>'
-	'E', 'F', 'G', 'H'
-	'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
-	'Q', 'R', 'S', 'T', 'U'
-	'V', 'X'
-	'g', 'i', 'm', 'n', 'o', 'p', 'r', 's'.  */
-
-#define REG_CLASS_FROM_LETTER(CHAR)		\
- (  (CHAR) == 'a' ? R0_REGS			\
-  : (CHAR) == 'b' ? R1_REGS			\
-  : (CHAR) == 'c' ? R2_REGS			\
-  : (CHAR) == 'd' ? R8_REGS			\
-  : (CHAR) == 'e' ? EIGHT_REGS			\
-  : (CHAR) == 't' ? TWO_REGS			\
-  : (CHAR) == 'z' ? ICALL_REGS			\
-  : NO_REGS)
-
 #define REGNO_OK_FOR_BASE_P(NUM) 1
 
 #define REGNO_OK_FOR_INDEX_P(NUM) REGNO_OK_FOR_BASE_P (NUM)
@@ -263,22 +243,6 @@  enum reg_class
 #define CLASS_MAX_NREGS(CLASS, MODE) \
   ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
 
-#define CONST_OK_FOR_LETTER_P(VALUE, C)			\
-  (  (C) == 'I' ? (VALUE) >= 0 && (VALUE) <= 3		\
-   : (C) == 'J' ? exact_log2 (VALUE) != -1		\
-   : (C) == 'K' ? exact_log2 (~(VALUE)) != -1		\
-   : (C) == 'L' ? (VALUE) >= 0 && (VALUE) <= 255	\
-   : (C) == 'M' ? (VALUE) >= -255 && (VALUE) <= 0	\
-   : (C) == 'N' ? (VALUE) >= -3 && (VALUE) <= 0		\
-   : (C) == 'O' ? (VALUE) >= 1 && (VALUE) <= 4		\
-   : (C) == 'P' ? (VALUE) >= -4 && (VALUE) <= -1	\
-   : 0 )
-
-#define CONST_DOUBLE_OK_FOR_LETTER_P(VALUE, C) 0
-
-#define EXTRA_CONSTRAINT(VALUE, C) \
-  xstormy16_extra_constraint_p (VALUE, C)
-
 
 /* Basic Stack Layout.  */
 
diff --git a/gcc/config/stormy16/stormy16.md b/gcc/config/stormy16/stormy16.md
index 8c6fd9d..3eb74b7 100644
--- a/gcc/config/stormy16/stormy16.md
+++ b/gcc/config/stormy16/stormy16.md
@@ -95,6 +95,7 @@ 
 			(set_attr "psw_operand" "clobber")])
 
 (include "predicates.md")
+(include "constraints.md")
 
 ;; ::::::::::::::::::::
 ;; ::