OSDN Git Service

* config/xtensa/xtensa.c (xtensa_init_machine_status): Fix
[pf3gnuchains/gcc-fork.git] / gcc / genrecog.c
index 3636215..1e8f854 100644 (file)
@@ -1,22 +1,23 @@
 /* Generate code from machine description to recognize rtl as insns.
-   Copyright (C) 1987, 88, 92-95, 97-98, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1997, 1998,
+   1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
-   This file is part of GNU CC.
+   This file is part of GCC.
 
-   GNU CC is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
+   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.
 
-   GNU CC 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.
+   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 GNU CC; see the file COPYING.  If not, write to
-   the Free Software Foundation, 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   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.  */
 
 
 /* This program is used to produce insn-recog.c, which contains a
 #include "hconfig.h"
 #include "system.h"
 #include "rtl.h"
-#include "obstack.h"
 #include "errors.h"
+#include "gensupport.h"
+
 
 #define OUTPUT_LABEL(INDENT_STRING, LABEL_NUMBER) \
   printf("%sL%d: ATTRIBUTE_UNUSED_LABEL\n", (INDENT_STRING), (LABEL_NUMBER))
 
-static struct obstack obstack;
-struct obstack *rtl_obstack = &obstack;
-
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
-
 /* Holds an array of names indexed by insn_code_number.  */
 static char **insn_name_ptr = 0;
 static int insn_name_ptr_size = 0;
@@ -77,7 +73,7 @@ struct decision_head
   struct decision *first;
   struct decision *last;
 };
-    
+
 /* A single test.  The two accept types aren't tests per-se, but
    their equality (or lack thereof) does affect tree merging so
    it is convenient to keep them here.  */
@@ -88,12 +84,13 @@ struct decision_test
   struct decision_test *next;
 
   /* These types are roughly in the order in which we'd like to test them.  */
-  enum decision_type {
-    DT_mode, DT_code, DT_veclen,
-    DT_elt_zero_int, DT_elt_one_int, DT_elt_zero_wide,
-    DT_dup, DT_pred, DT_c_test, 
-    DT_accept_op, DT_accept_insn
-  } type;
+  enum decision_type
+    {
+      DT_mode, DT_code, DT_veclen,
+      DT_elt_zero_int, DT_elt_one_int, DT_elt_zero_wide, DT_elt_zero_wide_safe,
+      DT_veclen_ge, DT_dup, DT_pred, DT_c_test,
+      DT_accept_op, DT_accept_insn
+    } type;
 
   union
   {
@@ -184,10 +181,10 @@ static int error_count;
    of tree nodes.  Also, if a predicate can match only one code, we can
    hardwire that code into the node testing the predicate.  */
 
-static struct pred_table
+static const struct pred_table
 {
-  const char *name;
-  RTX_CODE codes[NUM_RTX_CODE];
+  const char *const name;
+  const RTX_CODE codes[NUM_RTX_CODE];
 } preds[] = {
   {"general_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF,
                       LABEL_REF, SUBREG, REG, MEM}},
@@ -197,6 +194,7 @@ static struct pred_table
   {"address_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF,
                       LABEL_REF, SUBREG, REG, MEM, PLUS, MINUS, MULT}},
   {"register_operand", {SUBREG, REG}},
+  {"pmode_register_operand", {SUBREG, REG}},
   {"scratch_operand", {SCRATCH, REG}},
   {"immediate_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF,
                         LABEL_REF}},
@@ -209,124 +207,108 @@ static struct pred_table
   {"pop_operand", {MEM}},
   {"memory_operand", {SUBREG, MEM}},
   {"indirect_operand", {SUBREG, MEM}},
-  {"comparison_operator", {EQ, NE, LE, LT, GE, GT, LEU, LTU, GEU, GTU}},
+  {"comparison_operator", {EQ, NE, LE, LT, GE, GT, LEU, LTU, GEU, GTU,
+                          UNORDERED, ORDERED, UNEQ, UNGE, UNGT, UNLE,
+                          UNLT, LTGT}},
   {"mode_independent_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF,
                                LABEL_REF, SUBREG, REG, MEM}}
 };
 
-#define NUM_KNOWN_PREDS (sizeof preds / sizeof preds[0])
+#define NUM_KNOWN_PREDS ARRAY_SIZE (preds)
 
-static const char * special_mode_pred_table[] = {
+static const char *const special_mode_pred_table[] = {
 #ifdef SPECIAL_MODE_PREDICATES
   SPECIAL_MODE_PREDICATES
 #endif
-  NULL
+  "pmode_register_operand"
 };
 
-#define NUM_SPECIAL_MODE_PREDS \
-  (sizeof (special_mode_pred_table) / sizeof (const char *) - 1)
+#define NUM_SPECIAL_MODE_PREDS ARRAY_SIZE (special_mode_pred_table)
 
 static struct decision *new_decision
-  PROTO((const char *, struct decision_head *));
+  PARAMS ((const char *, struct decision_head *));
 static struct decision_test *new_decision_test
-  PROTO((enum decision_type, struct decision_test ***));
+  PARAMS ((enum decision_type, struct decision_test ***));
 static rtx find_operand
-  PROTO((rtx, int));
+  PARAMS ((rtx, int));
+static rtx find_matching_operand
+  PARAMS ((rtx, int));
 static void validate_pattern
-  PROTO((rtx, rtx, int));
+  PARAMS ((rtx, rtx, rtx, int));
 static struct decision *add_to_sequence
-  PROTO((rtx, struct decision_head *, const char *, enum routine_type, int));
+  PARAMS ((rtx, struct decision_head *, const char *, enum routine_type, int));
 
 static int maybe_both_true_2
-  PROTO((struct decision_test *, struct decision_test *));
+  PARAMS ((struct decision_test *, struct decision_test *));
 static int maybe_both_true_1
-  PROTO((struct decision_test *, struct decision_test *));
+  PARAMS ((struct decision_test *, struct decision_test *));
 static int maybe_both_true
-  PROTO((struct decision *, struct decision *, int));
+  PARAMS ((struct decision *, struct decision *, int));
 
 static int nodes_identical_1
-  PROTO((struct decision_test *, struct decision_test *));
+  PARAMS ((struct decision_test *, struct decision_test *));
 static int nodes_identical
-  PROTO((struct decision *, struct decision *));
+  PARAMS ((struct decision *, struct decision *));
 static void merge_accept_insn
-  PROTO((struct decision *, struct decision *));
+  PARAMS ((struct decision *, struct decision *));
 static void merge_trees
-  PROTO((struct decision_head *, struct decision_head *));
+  PARAMS ((struct decision_head *, struct decision_head *));
 
 static void factor_tests
-  PROTO((struct decision_head *));
+  PARAMS ((struct decision_head *));
 static void simplify_tests
-  PROTO((struct decision_head *));
+  PARAMS ((struct decision_head *));
 static int break_out_subroutines
-  PROTO((struct decision_head *, int));
+  PARAMS ((struct decision_head *, int));
 static void find_afterward
-  PROTO((struct decision_head *, struct decision *));
+  PARAMS ((struct decision_head *, struct decision *));
 
 static void change_state
-  PROTO((const char *, const char *, struct decision *, const char *));
+  PARAMS ((const char *, const char *, struct decision *, const char *));
 static void print_code
-  PROTO((enum rtx_code));
+  PARAMS ((enum rtx_code));
 static void write_afterward
-  PROTO((struct decision *, struct decision *, const char *));
+  PARAMS ((struct decision *, struct decision *, const char *));
 static struct decision *write_switch
-  PROTO((struct decision *, int));
+  PARAMS ((struct decision *, int));
 static void write_cond
-  PROTO((struct decision_test *, int, enum routine_type));
+  PARAMS ((struct decision_test *, int, enum routine_type));
 static void write_action
-  PROTO((struct decision_test *, int, int, struct decision *,
-        enum routine_type));
+  PARAMS ((struct decision *, struct decision_test *, int, int,
+          struct decision *, enum routine_type));
 static int is_unconditional
-  PROTO((struct decision_test *, enum routine_type));
+  PARAMS ((struct decision_test *, enum routine_type));
 static int write_node
-  PROTO((struct decision *, int, enum routine_type));
+  PARAMS ((struct decision *, int, enum routine_type));
 static void write_tree_1
-  PROTO((struct decision_head *, int, enum routine_type));
+  PARAMS ((struct decision_head *, int, enum routine_type));
 static void write_tree
-  PROTO((struct decision_head *, const char *, enum routine_type, int));
+  PARAMS ((struct decision_head *, const char *, enum routine_type, int));
 static void write_subroutine
-  PROTO((struct decision_head *, enum routine_type));
+  PARAMS ((struct decision_head *, enum routine_type));
 static void write_subroutines
-  PROTO((struct decision_head *, enum routine_type));
+  PARAMS ((struct decision_head *, enum routine_type));
 static void write_header
-  PROTO((void));
+  PARAMS ((void));
 
 static struct decision_head make_insn_sequence
-  PROTO((rtx, enum routine_type));
+  PARAMS ((rtx, enum routine_type));
 static void process_tree
-  PROTO((struct decision_head *, enum routine_type));
-  
+  PARAMS ((struct decision_head *, enum routine_type));
+
 static void record_insn_name
-  PROTO((int, const char *));
+  PARAMS ((int, const char *));
 
+static void debug_decision_0
+  PARAMS ((struct decision *, int, int));
 static void debug_decision_1
-  PROTO((struct decision *, int));
+  PARAMS ((struct decision *, int));
 static void debug_decision_2
-  PROTO((struct decision_test *));
+  PARAMS ((struct decision_test *));
 extern void debug_decision
-  PROTO((struct decision *));
-\f
-static void
-message_with_line VPROTO ((int lineno, const char *msg, ...))
-{
-#ifndef ANSI_PROTOTYPES
-  int lineno;
-  const char *msg;
-#endif
-  va_list ap;
-
-  VA_START (ap, msg);
-
-#ifndef ANSI_PROTOTYPES
-  lineno = va_arg (ap, int);
-  msg = va_arg (ap, const char *);
-#endif
-
-  fprintf (stderr, "%s:%d: ", read_rtx_filename, lineno);
-  vfprintf (stderr, msg, ap);
-  fputc ('\n', stderr);
-
-  va_end (ap);
-}
+  PARAMS ((struct decision *));
+extern void debug_decision_list
+  PARAMS ((struct decision *));
 \f
 /* Create a new node in sequence after LAST.  */
 
@@ -335,7 +317,7 @@ new_decision (position, last)
      const char *position;
      struct decision_head *last;
 {
-  register struct decision *new
+  struct decision *new
     = (struct decision *) xmalloc (sizeof (struct decision));
 
   memset (new, 0, sizeof (*new));
@@ -400,6 +382,11 @@ find_operand (pattern, n)
            return r;
          break;
 
+       case 'V':
+         if (! XVEC (pattern, i))
+           break;
+         /* FALLTHRU */
+
        case 'E':
          for (j = 0; j < XVECLEN (pattern, i); j++)
            if ((r = find_operand (XVECEXP (pattern, i, j), n)) != NULL_RTX)
@@ -417,13 +404,70 @@ find_operand (pattern, n)
   return NULL;
 }
 
-/* Check for various errors in patterns.  */
+/* Search for and return operand M, such that it has a matching
+   constraint for operand N.  */
+
+static rtx
+find_matching_operand (pattern, n)
+     rtx pattern;
+     int n;
+{
+  const char *fmt;
+  RTX_CODE code;
+  int i, j, len;
+  rtx r;
+
+  code = GET_CODE (pattern);
+  if (code == MATCH_OPERAND
+      && (XSTR (pattern, 2)[0] == '0' + n
+         || (XSTR (pattern, 2)[0] == '%'
+             && XSTR (pattern, 2)[1] == '0' + n)))
+    return pattern;
+
+  fmt = GET_RTX_FORMAT (code);
+  len = GET_RTX_LENGTH (code);
+  for (i = 0; i < len; i++)
+    {
+      switch (fmt[i])
+       {
+       case 'e': case 'u':
+         if ((r = find_matching_operand (XEXP (pattern, i), n)))
+           return r;
+         break;
+
+       case 'V':
+         if (! XVEC (pattern, i))
+           break;
+         /* FALLTHRU */
+
+       case 'E':
+         for (j = 0; j < XVECLEN (pattern, i); j++)
+           if ((r = find_matching_operand (XVECEXP (pattern, i, j), n)))
+             return r;
+         break;
+
+       case 'i': case 'w': case '0': case 's':
+         break;
+
+       default:
+         abort ();
+       }
+    }
+
+  return NULL;
+}
+
+
+/* Check for various errors in patterns.  SET is nonnull for a destination,
+   and is the complete set pattern.  SET_CODE is '=' for normal sets, and
+   '+' within a context that requires in-out constraints.  */
 
 static void
-validate_pattern (pattern, insn, set_dest)
+validate_pattern (pattern, insn, set, set_code)
      rtx pattern;
      rtx insn;
-     int set_dest;
+     rtx set;
+     int set_code;
 {
   const char *fmt;
   RTX_CODE code;
@@ -501,51 +545,90 @@ validate_pattern (pattern, insn, set_dest)
                }
          }
 
+       if (code == MATCH_OPERAND)
+         {
+           const char constraints0 = XSTR (pattern, 2)[0];
+
+           /* In DEFINE_EXPAND, DEFINE_SPLIT, and DEFINE_PEEPHOLE2, we 
+              don't use the MATCH_OPERAND constraint, only the predicate.
+              This is confusing to folks doing new ports, so help them
+              not make the mistake.  */
+           if (GET_CODE (insn) == DEFINE_EXPAND
+               || GET_CODE (insn) == DEFINE_SPLIT
+               || GET_CODE (insn) == DEFINE_PEEPHOLE2)
+             {
+               if (constraints0)
+                 message_with_line (pattern_lineno,
+                                    "warning: constraints not supported in %s",
+                                    rtx_name[GET_CODE (insn)]);
+             }
+             
+           /* A MATCH_OPERAND that is a SET should have an output reload.  */
+           else if (set && constraints0)
+             {
+               if (set_code == '+')
+                 {
+                   if (constraints0 == '+')
+                     ;
+                   /* If we've only got an output reload for this operand,
+                      we'd better have a matching input operand.  */
+                   else if (constraints0 == '='
+                            && find_matching_operand (insn, XINT (pattern, 0)))
+                     ;
+                   else
+                     {
+                       message_with_line (pattern_lineno,
+                                          "operand %d missing in-out reload",
+                                          XINT (pattern, 0));
+                       error_count++;
+                     }
+                 }
+               else if (constraints0 != '=' && constraints0 != '+')
+                 {
+                   message_with_line (pattern_lineno,
+                                      "operand %d missing output reload", 
+                                      XINT (pattern, 0));
+                   error_count++;
+                 }
+             }
+         }
+
        /* Allowing non-lvalues in destinations -- particularly CONST_INT --
           while not likely to occur at runtime, results in less efficient
           code from insn-recog.c.  */
-       if (set_dest
+       if (set
            && pred_name[0] != '\0'
            && allows_non_lvalue)
          {
            message_with_line (pattern_lineno,
-                              "warning: `%s' allows non-lvalue,",
-                              pred_name);
-           message_with_line (pattern_lineno,
-                              "  and used as destination of a set");
+                       "warning: destination operand %d allows non-lvalue",
+                       XINT (pattern, 0));
          }
 
        /* A modeless MATCH_OPERAND can be handy when we can
           check for multiple modes in the c_test.  In most other cases,
           it is a mistake.  Only DEFINE_INSN is eligible, since SPLIT
-          and PEEP2 can FAIL within the output pattern.  */
+          and PEEP2 can FAIL within the output pattern.  Exclude
+          address_operand, since its mode is related to the mode of
+          the memory not the operand.  Exclude the SET_DEST of a call
+          instruction, as that is a common idiom.  */
 
        if (GET_MODE (pattern) == VOIDmode
            && code == MATCH_OPERAND
-           && pred_name[0] != '\0'
+           && GET_CODE (insn) == DEFINE_INSN
            && allows_non_const
            && ! special_mode_pred
+           && pred_name[0] != '\0'
+           && strcmp (pred_name, "address_operand") != 0
            && strstr (c_test, "operands") == NULL
-           && GET_CODE (insn) == DEFINE_INSN)
+           && ! (set
+                 && GET_CODE (set) == SET
+                 && GET_CODE (SET_SRC (set)) == CALL))
          {
            message_with_line (pattern_lineno,
                               "warning: operand %d missing mode?",
                               XINT (pattern, 0));
          }
-
-       /* A MATCH_OPERAND that is a SET should have an output reload.  */
-       if (set_dest
-           && code == MATCH_OPERAND
-           && XSTR (pattern, 2)[0] != '\0'
-           && XSTR (pattern, 2)[0] != '='
-           && XSTR (pattern, 2)[0] != '+')
-         {
-           message_with_line (pattern_lineno,
-                              "operand %d missing output reload", 
-                              XINT (pattern, 0));
-           error_count++;
-         }
-
        return;
       }
 
@@ -557,6 +640,11 @@ validate_pattern (pattern, insn, set_dest)
        dest = SET_DEST (pattern);
        src = SET_SRC (pattern);
 
+       /* STRICT_LOW_PART is a wrapper.  Its argument is the real
+          destination, and it's mode should match the source.  */
+       if (GET_CODE (dest) == STRICT_LOW_PART)
+         dest = XEXP (dest, 0);
+
        /* Find the referant for a DUP.  */
 
        if (GET_CODE (dest) == MATCH_DUP
@@ -569,11 +657,6 @@ validate_pattern (pattern, insn, set_dest)
            || GET_CODE (src) == MATCH_PAR_DUP)
          src = find_operand (insn, XINT (src, 0));
 
-       /* STRICT_LOW_PART is a wrapper.  Its argument is the real
-          destination, and it's mode should match the source.  */
-       if (GET_CODE (dest) == STRICT_LOW_PART)
-         dest = XEXP (dest, 0);
-
        dmode = GET_MODE (dest);
        smode = GET_MODE (src);
 
@@ -593,11 +676,13 @@ validate_pattern (pattern, insn, set_dest)
            error_count++;
          }
 
-       /* If only one of the operands is VOIDmode, and PC or CC0 is 
+       /* If only one of the operands is VOIDmode, and PC or CC0 is
           not involved, it's probably a mistake.  */
        else if (dmode != smode
                 && GET_CODE (dest) != PC
                 && GET_CODE (dest) != CC0
+                && GET_CODE (src) != PC
+                && GET_CODE (src) != CC0
                 && GET_CODE (src) != CONST_INT)
          {
            const char *which;
@@ -607,14 +692,24 @@ validate_pattern (pattern, insn, set_dest)
          }
 
        if (dest != SET_DEST (pattern))
-         validate_pattern (dest, insn, 1);
-       validate_pattern (SET_DEST (pattern), insn, 1);
-        validate_pattern (SET_SRC (pattern), insn, 0);
+         validate_pattern (dest, insn, pattern, '=');
+       validate_pattern (SET_DEST (pattern), insn, pattern, '=');
+        validate_pattern (SET_SRC (pattern), insn, NULL_RTX, 0);
         return;
       }
 
     case CLOBBER:
-      validate_pattern (SET_DEST (pattern), insn, 1);
+      validate_pattern (SET_DEST (pattern), insn, pattern, '=');
+      return;
+
+    case ZERO_EXTRACT:
+      validate_pattern (XEXP (pattern, 0), insn, set, set ? '+' : 0);
+      validate_pattern (XEXP (pattern, 1), insn, NULL_RTX, 0);
+      validate_pattern (XEXP (pattern, 2), insn, NULL_RTX, 0);
+      return;
+
+    case STRICT_LOW_PART:
+      validate_pattern (XEXP (pattern, 0), insn, set, set ? '+' : 0);
       return;
 
     case LABEL_REF:
@@ -638,12 +733,12 @@ validate_pattern (pattern, insn, set_dest)
       switch (fmt[i])
        {
        case 'e': case 'u':
-         validate_pattern (XEXP (pattern, i), insn, 0);
+         validate_pattern (XEXP (pattern, i), insn, NULL_RTX, 0);
          break;
 
        case 'E':
          for (j = 0; j < XVECLEN (pattern, i); j++)
-           validate_pattern (XVECEXP (pattern, i, j), insn, 0);
+           validate_pattern (XVECEXP (pattern, i, j), insn, NULL_RTX, 0);
          break;
 
        case 'i': case 'w': case '0': case 's':
@@ -680,8 +775,8 @@ add_to_sequence (pattern, last, position, insn_type, top)
   struct decision_test *test;
   struct decision_test **place;
   char *subpos;
-  register size_t i;
-  register const char *fmt;
+  size_t i;
+  const char *fmt;
   int depth = strlen (position);
   int len;
   enum machine_mode mode;
@@ -689,7 +784,7 @@ add_to_sequence (pattern, last, position, insn_type, top)
   if (depth > max_depth)
     max_depth = depth;
 
-  subpos = (char *) alloca (depth + 2);
+  subpos = (char *) xmalloc (depth + 2);
   strcpy (subpos, position);
   subpos[depth + 1] = 0;
 
@@ -703,7 +798,7 @@ add_to_sequence (pattern, last, position, insn_type, top)
   switch (code)
     {
     case PARALLEL:
-      /* Toplevel peephole pattern. */
+      /* Toplevel peephole pattern.  */
       if (insn_type == PEEPHOLE2 && top)
        {
          /* We don't need the node we just created -- unlink it.  */
@@ -712,23 +807,32 @@ add_to_sequence (pattern, last, position, insn_type, top)
          for (i = 0; i < (size_t) XVECLEN (pattern, 0); i++)
            {
              /* Which insn we're looking at is represented by A-Z. We don't
-                ever use 'A', however; it is always implied. */
+                ever use 'A', however; it is always implied.  */
 
              subpos[depth] = (i > 0 ? 'A' + i : 0);
              sub = add_to_sequence (XVECEXP (pattern, 0, i),
                                     last, subpos, insn_type, 0);
              last = &sub->success;
            }
-         return sub;
+         goto ret;
        }
 
       /* Else nothing special.  */
       break;
 
+    case MATCH_PARALLEL:
+      /* The explicit patterns within a match_parallel enforce a minimum
+        length on the vector.  The match_parallel predicate may allow
+        for more elements.  We do need to check for this minimum here
+        or the code generated to match the internals may reference data
+        beyond the end of the vector.  */
+      test = new_decision_test (DT_veclen_ge, &place);
+      test->u.veclen = XVECLEN (pattern, 2);
+      /* FALLTHRU */
+
     case MATCH_OPERAND:
     case MATCH_SCRATCH:
     case MATCH_OPERATOR:
-    case MATCH_PARALLEL:
     case MATCH_INSN:
       {
        const char *pred_name;
@@ -749,30 +853,22 @@ add_to_sequence (pattern, last, position, insn_type, top)
              code = UNKNOWN;
          }
 
-       /* We know exactly what const_int_operand matches -- any CONST_INT.  */
-       if (strcmp ("const_int_operand", pred_name) == 0)
-         {
-           code = CONST_INT;
-           mode = VOIDmode;
-         }
-       else if (pred_name[0] != 0)
+       if (pred_name[0] != 0)
          {
            test = new_decision_test (DT_pred, &place);
            test->u.pred.name = pred_name;
            test->u.pred.mode = mode;
 
-           /* See if we know about this predicate and save its number.  If
-              we do, and it only accepts one code, note that fact.  The
-              predicate `const_int_operand' only tests for a CONST_INT, so
-              if we do so we can avoid calling it at all.
+           /* See if we know about this predicate and save its number.
+              If we do, and it only accepts one code, note that fact.
 
-              Finally, if we know that the predicate does not allow
-              CONST_INT, we know that the only way the predicate can match
-              is if the modes match (here we use the kludge of relying on
-              the fact that "address_operand" accepts CONST_INT; otherwise,
-              it would have to be a special case), so we can test the mode
-              (but we need not).  This fact should considerably simplify the
-              generated code.  */
+              If we know that the predicate does not allow CONST_INT,
+              we know that the only way the predicate can match is if
+              the modes match (here we use the kludge of relying on the
+              fact that "address_operand" accepts CONST_INT; otherwise,
+              it would have to be a special case), so we can test the
+              mode (but we need not).  This fact should considerably
+              simplify the generated code.  */
 
            for (i = 0; i < NUM_KNOWN_PREDS; i++)
              if (! strcmp (preds[i].name, pred_name))
@@ -876,10 +972,16 @@ add_to_sequence (pattern, last, position, insn_type, top)
        }
       else if (fmt[i] == 'w')
        {
+         /* If this value actually fits in an int, we can use a switch
+            statement here, so indicate that.  */
+         enum decision_type type
+           = ((int) XWINT (pattern, i) == XWINT (pattern, i))
+             ? DT_elt_zero_wide_safe : DT_elt_zero_wide;
+
          if (i != 0)
            abort ();
 
-         test = new_decision_test (DT_elt_zero_wide, &place);
+         test = new_decision_test (type, &place);
          test->u.intval = XWINT (pattern, i);
        }
       else if (fmt[i] == 'E')
@@ -905,7 +1007,7 @@ add_to_sequence (pattern, last, position, insn_type, top)
 
        case 'E':
          {
-           register int j;
+           int j;
            for (j = 0; j < XVECLEN (pattern, i); j++)
              {
                subpos[depth] = 'a' + j;
@@ -947,6 +1049,8 @@ add_to_sequence (pattern, last, position, insn_type, top)
   if (this->tests == NULL)
     abort ();
 
+ ret:
+  free (subpos);
   return sub;
 }
 \f
@@ -973,6 +1077,7 @@ maybe_both_true_2 (d1, d2)
        case DT_elt_zero_int:
        case DT_elt_one_int:
        case DT_elt_zero_wide:
+       case DT_elt_zero_wide_safe:
          return d1->u.intval == d2->u.intval;
 
        default:
@@ -997,7 +1102,12 @@ maybe_both_true_2 (d1, d2)
        {
          if (d2->type == DT_mode)
            {
-             if (d1->u.pred.mode != d2->u.mode)
+             if (d1->u.pred.mode != d2->u.mode
+                 /* The mode of an address_operand predicate is the
+                    mode of the memory, not the operand.  It can only
+                    be used for testing the predicate, so we must
+                    ignore it here.  */
+                 && strcmp (d1->u.pred.name, "address_operand") != 0)
                return 0;
            }
          /* Don't check two predicate modes here, because if both predicates
@@ -1046,6 +1156,12 @@ maybe_both_true_2 (d1, d2)
        }
     }
 
+  /* Tests vs veclen may be known when strict equality is involved.  */
+  if (d1->type == DT_veclen && d2->type == DT_veclen_ge)
+    return d1->u.veclen >= d2->u.veclen;
+  if (d1->type == DT_veclen_ge && d2->type == DT_veclen)
+    return d2->u.veclen >= d1->u.veclen;
+
   return -1;
 }
 
@@ -1059,7 +1175,7 @@ maybe_both_true_1 (d1, d2)
   struct decision_test *t1, *t2;
 
   /* A match_operand with no predicate can match anything.  Recognize
-     this by the existance of a lone DT_accept_op test.  */
+     this by the existence of a lone DT_accept_op test.  */
   if (d1->type == DT_accept_op || d2->type == DT_accept_op)
     return 1;
 
@@ -1117,14 +1233,14 @@ maybe_both_true (d1, d2, toplevel)
   if (cmp != 0)
     {
       if (toplevel)
-       abort();
+       abort ();
 
       /* If the d2->position was lexically lower, swap.  */
       if (cmp > 0)
        p1 = d1, d1 = d2, d2 = p1;
 
       if (d1->success.first == 0)
-       return 0;
+       return 1;
       for (p1 = d1->success.first; p1; p1 = p1->next)
        if (maybe_both_true (p1, d2, 0))
          return 1;
@@ -1176,6 +1292,7 @@ nodes_identical_1 (d1, d2)
       return strcmp (d1->u.c_test, d2->u.c_test) == 0;
 
     case DT_veclen:
+    case DT_veclen_ge:
       return d1->u.veclen == d2->u.veclen;
 
     case DT_dup:
@@ -1184,6 +1301,7 @@ nodes_identical_1 (d1, d2)
     case DT_elt_zero_int:
     case DT_elt_one_int:
     case DT_elt_zero_wide:
+    case DT_elt_zero_wide_safe:
       return d1->u.intval == d2->u.intval;
 
     case DT_accept_op:
@@ -1199,7 +1317,7 @@ nodes_identical_1 (d1, d2)
 }
 
 /* True iff the two nodes are identical (on one level only).  Due
-   to the way these lists are constructed, we shouldn't have to 
+   to the way these lists are constructed, we shouldn't have to
    consider different orderings on the tests.  */
 
 static int
@@ -1217,13 +1335,25 @@ nodes_identical (d1, d2)
     }
 
   /* For success, they should now both be null.  */
-  return t1 == t2;
+  if (t1 != t2)
+    return 0;
+
+  /* Check that their subnodes are at the same position, as any one set
+     of sibling decisions must be at the same position.  Allowing this
+     requires complications to find_afterward and when change_state is
+     invoked.  */
+  if (d1->success.first
+      && d2->success.first
+      && strcmp (d1->success.first->position, d2->success.first->position))
+    return 0;
+
+  return 1;
 }
 
 /* A subroutine of merge_trees; given two nodes that have been declared
    identical, cope with two insn accept states.  If they differ in the
    number of clobbers, then the conflict was created by make_insn_sequence
-   and we can drop the with-clobbers version on the floor.  If both 
+   and we can drop the with-clobbers version on the floor.  If both
    nodes have no additional clobbers, we have found an ambiguity in the
    source machine description.  */
 
@@ -1311,7 +1441,7 @@ merge_trees (oldh, addh)
         that tests just the same mode.
 
         If we have no match, place NEW after the closest match we found.  */
-        
+
       for (old = oldh->last; old; old = old->prev)
        {
          if (nodes_identical (old, add))
@@ -1328,7 +1458,7 @@ merge_trees (oldh, addh)
             how expensive/important the test is.  Given that the tests
             are also ordered within the list, examining the first is
             sufficient.  */
-         if (add->tests->type < old->tests->type)
+         if ((int) add->tests->type < (int) old->tests->type)
            insert_before = old;
        }
 
@@ -1353,7 +1483,7 @@ merge_trees (oldh, addh)
     }
 }
 \f
-/* Walk the tree looking for sub-nodes that perform common tests.  
+/* Walk the tree looking for sub-nodes that perform common tests.
    Factor out the common test into a new node.  This enables us
    (depending on the test type) to emit switch statements later.  */
 
@@ -1375,14 +1505,14 @@ factor_tests (head)
       if (next->tests->type != type)
        continue;
 
-      /* Don't want all node types, just those we can turn into 
+      /* Don't want all node types, just those we can turn into
         switch statements.  */
       if (type != DT_mode
          && type != DT_code
          && type != DT_veclen
          && type != DT_elt_zero_int
          && type != DT_elt_one_int
-         && type != DT_elt_zero_wide)
+         && type != DT_elt_zero_wide_safe)
        continue;
 
       /* If we'd been performing more than one test, create a new node
@@ -1393,7 +1523,7 @@ factor_tests (head)
          new->tests = first->tests->next;
          first->tests->next = NULL;
        }
-       
+
       /* Crop the node tree off after our first test.  */
       first->next = NULL;
       old_last = head->last;
@@ -1510,7 +1640,7 @@ find_afterward (head, real_afterward)
 {
   struct decision *p, *q, *afterward;
 
-  /* We can't propogate alternatives across subroutine boundaries. 
+  /* We can't propagate alternatives across subroutine boundaries.
      This is not incorrect, merely a minor optimization loss.  */
 
   p = head->first;
@@ -1523,7 +1653,7 @@ find_afterward (head, real_afterward)
        if (maybe_both_true (p, q, 1))
          break;
 
-      /* If we reached the end of the list without finding one, 
+      /* If we reached the end of the list without finding one,
         use the incoming afterward position.  */
       if (!q)
        q = afterward;
@@ -1550,7 +1680,7 @@ find_afterward (head, real_afterward)
    new state, branch to node AFTERWARD if non-zero, otherwise return.
 
    Failure to move to the new state can only occur if we are trying to
-   match multiple insns and we try to step past the end of the stream. */
+   match multiple insns and we try to step past the end of the stream.  */
 
 static void
 change_state (oldpos, newpos, afterward, indent)
@@ -1570,42 +1700,37 @@ change_state (oldpos, newpos, afterward, indent)
 
   /* Hunt for the last [A-Z] in both strings.  */
   for (old_has_insn = odepth - 1; old_has_insn >= 0; --old_has_insn)
-    if (oldpos[old_has_insn] >= 'A' && oldpos[old_has_insn] <= 'Z')
+    if (ISUPPER (oldpos[old_has_insn]))
       break;
-  for (new_has_insn = odepth - 1; new_has_insn >= 0; --new_has_insn)
-    if (newpos[new_has_insn] >= 'A' && newpos[new_has_insn] <= 'Z')
+  for (new_has_insn = ndepth - 1; new_has_insn >= 0; --new_has_insn)
+    if (ISUPPER (newpos[new_has_insn]))
       break;
 
-  /* Make sure to reset the _last_insn pointer when popping back up.  */
-  if (old_has_insn >= 0 && new_has_insn < 0)
-    printf ("%s_last_insn = insn;\n", indent);
-
   /* Go down to desired level.  */
   while (depth < ndepth)
     {
-      /* It's a different insn from the first one. */
-      if (newpos[depth] >= 'A' && newpos[depth] <= 'Z')
+      /* It's a different insn from the first one.  */
+      if (ISUPPER (newpos[depth]))
        {
          /* We can only fail if we're moving down the tree.  */
          if (old_has_insn >= 0 && oldpos[old_has_insn] >= newpos[depth])
            {
-             printf ("%s_last_insn = recog_next_insn (insn, %d);\n", 
+             printf ("%stem = peep2_next_insn (%d);\n",
                      indent, newpos[depth] - 'A');
            }
          else
            {
-             printf ("%stem = recog_next_insn (insn, %d);\n", 
+             printf ("%stem = peep2_next_insn (%d);\n",
                      indent, newpos[depth] - 'A');
              printf ("%sif (tem == NULL_RTX)\n", indent);
              if (afterward)
                printf ("%s  goto L%d;\n", indent, afterward->number);
              else
                printf ("%s  goto ret0;\n", indent);
-             printf ("%s_last_insn = tem;\n", indent);
            }
-         printf ("%sx%d = PATTERN (_last_insn);\n", indent, depth + 1);
+         printf ("%sx%d = PATTERN (tem);\n", indent, depth + 1);
        }
-      else if (newpos[depth] >= 'a' && newpos[depth] <= 'z')
+      else if (ISLOWER (newpos[depth]))
        printf ("%sx%d = XVECEXP (x%d, 0, %d);\n",
                indent, depth + 1, depth, newpos[depth] - 'a');
       else
@@ -1622,7 +1747,7 @@ static void
 print_code (code)
      enum rtx_code code;
 {
-  register const char *p;
+  const char *p;
   for (p = GET_RTX_NAME (code); *p; p++)
     putchar (TOUPPER (*p));
 }
@@ -1644,7 +1769,7 @@ write_afterward (start, afterward, indent)
     }
 }
 
-/* Emit a switch statement, if possible, for an initial sequence of 
+/* Emit a switch statement, if possible, for an initial sequence of
    nodes at START.  Return the first node yet untested.  */
 
 static struct decision *
@@ -1654,6 +1779,7 @@ write_switch (start, depth)
 {
   struct decision *p = start;
   enum decision_type type = p->tests->type;
+  struct decision *needs_label = NULL;
 
   /* If we have two or more nodes in sequence that test the same one
      thing, we may be able to use a switch statement.  */
@@ -1661,7 +1787,8 @@ write_switch (start, depth)
   if (!p->next
       || p->tests->next
       || p->next->tests->type != type
-      || p->next->tests->next)
+      || p->next->tests->next
+      || nodes_identical_1 (p->tests, p->next->tests))
     return p;
 
   /* DT_code is special in that we can do interesting things with
@@ -1670,13 +1797,17 @@ write_switch (start, depth)
     {
       char codemap[NUM_RTX_CODE];
       struct decision *ret;
+      RTX_CODE code;
 
       memset (codemap, 0, sizeof(codemap));
 
       printf ("  switch (GET_CODE (x%d))\n    {\n", depth);
-      do 
+      code = p->tests->u.code;
+      do
        {
-         RTX_CODE code = p->tests->u.code;
+         if (p != start && p->need_label && needs_label == NULL)
+           needs_label = p;
+
          printf ("    case ");
          print_code (code);
          printf (":\n      goto L%d;\n", p->success.first->number);
@@ -1685,7 +1816,10 @@ write_switch (start, depth)
          codemap[code] = 1;
          p = p->next;
        }
-      while (p && p->tests->type == DT_code && !p->tests->next);
+      while (p
+            && ! p->tests->next
+            && p->tests->type == DT_code
+            && ! codemap[code = p->tests->u.code]);
 
       /* If P is testing a predicate that we know about and we haven't
         seen any of the codes that are valid for the predicate, we can
@@ -1697,7 +1831,10 @@ write_switch (start, depth)
         we don't actually write the test here, as it gets kinda messy.
         It is trivial to leave this to later by telling our caller that
         we only processed the CODE tests.  */
-      ret = p;
+      if (needs_label != NULL)
+       ret = needs_label;
+      else
+       ret = p;
 
       while (p && p->tests->type == DT_pred
             && p->tests->u.pred.index >= 0)
@@ -1745,37 +1882,56 @@ write_switch (start, depth)
           || type == DT_veclen
           || type == DT_elt_zero_int
           || type == DT_elt_one_int
-          || type == DT_elt_zero_wide)
+          || type == DT_elt_zero_wide_safe)
     {
-      const char *str;
+      const char *indent = "";
 
-      printf ("  switch (");
+      /* We cast switch parameter to integer, so we must ensure that the value
+        fits.  */
+      if (type == DT_elt_zero_wide_safe)
+       {
+         indent = "  ";
+         printf("  if ((int) XWINT (x%d, 0) == XWINT (x%d, 0))\n", depth, depth);
+       }
+      printf ("%s  switch (", indent);
       switch (type)
        {
        case DT_mode:
-         str = "GET_MODE (x%d)";
+         printf ("GET_MODE (x%d)", depth);
          break;
        case DT_veclen:
-         str = "XVECLEN (x%d, 0)";
+         printf ("XVECLEN (x%d, 0)", depth);
          break;
        case DT_elt_zero_int:
-         str = "XINT (x%d, 0)";
+         printf ("XINT (x%d, 0)", depth);
          break;
        case DT_elt_one_int:
-         str = "XINT (x%d, 1)";
+         printf ("XINT (x%d, 1)", depth);
          break;
-       case DT_elt_zero_wide:
-         str = "XWINT (x%d, 0)";
+       case DT_elt_zero_wide_safe:
+         /* Convert result of XWINT to int for portability since some C
+            compilers won't do it and some will.  */
+         printf ("(int) XWINT (x%d, 0)", depth);
          break;
        default:
          abort ();
        }
-      printf (str, depth);
-      printf (")\n    {\n");
+      printf (")\n%s    {\n", indent);
 
       do
        {
-         printf ("    case ");
+         /* Merge trees will not unify identical nodes if their
+            sub-nodes are at different levels.  Thus we must check
+            for duplicate cases.  */
+         struct decision *q;
+         for (q = start; q != p; q = q->next)
+           if (nodes_identical_1 (p->tests, q->tests))
+             goto case_done;
+
+         if (p != start && p->need_label && needs_label == NULL)
+           needs_label = p;
+
+         printf ("%s    case ", indent);
          switch (type)
            {
            case DT_mode:
@@ -1787,21 +1943,24 @@ write_switch (start, depth)
            case DT_elt_zero_int:
            case DT_elt_one_int:
            case DT_elt_zero_wide:
+           case DT_elt_zero_wide_safe:
              printf (HOST_WIDE_INT_PRINT_DEC, p->tests->u.intval);
              break;
            default:
              abort ();
            }
-         printf (":\n      goto L%d;\n", p->success.first->number);
+         printf (":\n%s      goto L%d;\n", indent, p->success.first->number);
          p->success.first->need_label = 1;
 
          p = p->next;
        }
       while (p && p->tests->type == type && !p->tests->next);
-      
-      printf ("    default:\n      break;\n    }\n");
 
-      return p;
+    case_done:
+      printf ("%s    default:\n%s      break;\n%s    }\n",
+             indent, indent, indent);
+
+      return needs_label != NULL ? needs_label : p;
     }
   else
     {
@@ -1842,10 +2001,15 @@ write_cond (p, depth, subroutine_type)
       break;
 
     case DT_elt_zero_wide:
+    case DT_elt_zero_wide_safe:
       printf ("XWINT (x%d, 0) == ", depth);
       printf (HOST_WIDE_INT_PRINT_DEC, p->u.intval);
       break;
 
+    case DT_veclen_ge:
+      printf ("XVECLEN (x%d, 0) >= %d", depth, p->u.veclen);
+      break;
+
     case DT_dup:
       printf ("rtx_equal_p (x%d, operands[%d])", depth, p->u.dup);
       break;
@@ -1883,7 +2047,8 @@ write_cond (p, depth, subroutine_type)
    perform a state change.  For the `accept' tests we must do more work.  */
 
 static void
-write_action (test, depth, uncond, success, subroutine_type)
+write_action (p, test, depth, uncond, success, subroutine_type)
+     struct decision *p;
      struct decision_test *test;
      int depth, uncond;
      struct decision *success;
@@ -1937,9 +2102,20 @@ write_action (test, depth, uncond, success, subroutine_type)
          break;
 
        case PEEPHOLE2:
-         printf ("%stem = gen_peephole2_%d (insn, operands);\n",
-                 indent, test->u.insn.code_number);
-         printf ("%sif (tem != 0)\n%s  goto ret1;\n", indent, indent);
+         {
+           int match_len = 0, i;
+
+           for (i = strlen (p->position) - 1; i >= 0; --i)
+             if (ISUPPER (p->position[i]))
+               {
+                 match_len = p->position[i] - 'A';
+                 break;
+               }
+           printf ("%s*_pmatch_len = %d;\n", indent, match_len);
+           printf ("%stem = gen_peephole2_%d (insn, operands);\n",
+                   indent, test->u.insn.code_number);
+           printf ("%sif (tem != 0)\n%s  return tem;\n", indent, indent);
+         }
          break;
 
        default:
@@ -2022,7 +2198,7 @@ write_node (p, depth, subroutine_type)
       printf (")\n");
     }
 
-  write_action (last_test, depth, uncond, p->success.first, subroutine_type);
+  write_action (p, last_test, depth, uncond, p->success.first, subroutine_type);
 
   return uncond > 0;
 }
@@ -2072,7 +2248,7 @@ write_tree (head, prevpos, type, initial)
      enum routine_type type;
      int initial;
 {
-  register struct decision *p = head->first;
+  struct decision *p = head->first;
 
   putchar ('\n');
   if (p->need_label)
@@ -2085,7 +2261,7 @@ write_tree (head, prevpos, type, initial)
       };
 
       static const char * const call_suffix[] = {
-         ", pnum_clobbers", "", ", _plast_insn"
+         ", pnum_clobbers", "", ", _pmatch_len"
       };
 
       /* This node has been broken out into a separate subroutine.
@@ -2130,36 +2306,11 @@ write_subroutine (head, type)
      struct decision_head *head;
      enum routine_type type;
 {
-  static const char * const proto_pattern[] = {
-    "%sint recog%s PROTO ((rtx, rtx, int *));\n",
-    "%srtx split%s PROTO ((rtx, rtx));\n",
-    "%srtx peephole2%s PROTO ((rtx, rtx, rtx *));\n"
-  };
-
-  static const char * const decl_pattern[] = {
-"%sint\n\
-recog%s (x0, insn, pnum_clobbers)\n\
-     register rtx x0;\n\
-     rtx insn ATTRIBUTE_UNUSED;\n\
-     int *pnum_clobbers ATTRIBUTE_UNUSED;\n",
-
-"%srtx\n\
-split%s (x0, insn)\n\
-     register rtx x0;\n\
-     rtx insn ATTRIBUTE_UNUSED;\n",
-
-"%srtx\n\
-peephole2%s (x0, insn, _plast_insn)\n\
-     register rtx x0;\n\
-     rtx insn ATTRIBUTE_UNUSED;\n\
-     rtx *_plast_insn ATTRIBUTE_UNUSED;\n"
-  };
-     
   int subfunction = head->first ? head->first->subroutine_number : 0;
   const char *s_or_e;
   char extension[32];
   int i;
-  
+
   s_or_e = subfunction ? "static " : "";
 
   if (subfunction)
@@ -2169,24 +2320,48 @@ peephole2%s (x0, insn, _plast_insn)\n\
   else
     strcpy (extension, "_insns");
 
-  printf (proto_pattern[type], s_or_e, extension);
-  printf (decl_pattern[type], s_or_e, extension);
+  switch (type)
+    {
+    case RECOG:
+      printf ("%sint recog%s PARAMS ((rtx, rtx, int *));\n", s_or_e, extension);
+      printf ("%sint\n\
+recog%s (x0, insn, pnum_clobbers)\n\
+     rtx x0 ATTRIBUTE_UNUSED;\n\
+     rtx insn ATTRIBUTE_UNUSED;\n\
+     int *pnum_clobbers ATTRIBUTE_UNUSED;\n", s_or_e, extension);
+      break;
+    case SPLIT:
+      printf ("%srtx split%s PARAMS ((rtx, rtx));\n", s_or_e, extension);
+      printf ("%srtx\n\
+split%s (x0, insn)\n\
+     rtx x0 ATTRIBUTE_UNUSED;\n\
+     rtx insn ATTRIBUTE_UNUSED;\n", s_or_e, extension);
+      break;
+    case PEEPHOLE2:
+      printf ("%srtx peephole2%s PARAMS ((rtx, rtx, int *));\n",
+             s_or_e, extension);
+      printf ("%srtx\n\
+peephole2%s (x0, insn, _pmatch_len)\n\
+     rtx x0 ATTRIBUTE_UNUSED;\n\
+     rtx insn ATTRIBUTE_UNUSED;\n\
+     int *_pmatch_len ATTRIBUTE_UNUSED;\n", s_or_e, extension);
+      break;
+    }
 
-  printf ("{\n  register rtx * const operands = &recog_data.operand[0];\n");
+  printf ("{\n  rtx * const operands ATTRIBUTE_UNUSED = &recog_data.operand[0];\n");
   for (i = 1; i <= max_depth; i++)
-    printf ("  register rtx x%d ATTRIBUTE_UNUSED;\n", i);
+    printf ("  rtx x%d ATTRIBUTE_UNUSED;\n", i);
 
-  if (type == PEEPHOLE2)
-    printf ("  register rtx _last_insn = insn;\n");
   printf ("  %s tem ATTRIBUTE_UNUSED;\n", IS_SPLIT (type) ? "rtx" : "int");
 
+  if (!subfunction)
+    printf ("  recog_data.insn = NULL_RTX;\n");
+
   if (head->first)
     write_tree (head, "", type, 1);
   else
     printf ("  goto ret0;\n");
 
-  if (type == PEEPHOLE2)
-    printf (" ret1:\n  *_plast_insn = _last_insn;\n  return tem;\n");
   printf (" ret0:\n  return %d;\n}\n\n", IS_SPLIT (type) ? 0 : -1);
 }
 
@@ -2229,6 +2404,8 @@ write_header ()
 #include \"flags.h\"\n\
 #include \"hard-reg-set.h\"\n\
 #include \"resource.h\"\n\
+#include \"toplev.h\"\n\
+#include \"reload.h\"\n\
 \n");
 
   puts ("\n\
@@ -2239,13 +2416,14 @@ write_header ()
    returns a nonnegative number which is the insn code number for the\n\
    pattern that matched.  This is the same as the order in the machine\n\
    description of the entry that matched.  This number can be used as an\n\
-   index into `insn_data' and other tables.\n\
-\n\
+   index into `insn_data' and other tables.\n");
+  puts ("\
    The third argument to recog is an optional pointer to an int.  If\n\
    present, recog will accept a pattern if it matches except for missing\n\
    CLOBBER expressions at the end.  In that case, the value pointed to by\n\
    the optional pointer will be set to the number of CLOBBERs that need\n\
-   to be added (it should be initialized to zero by the caller).  If it\n\
+   to be added (it should be initialized to zero by the caller).  If it");
+  puts ("\
    is set nonzero, the caller should allocate a PARALLEL of the\n\
    appropriate size, copy the initial entries, and call add_clobbers\n\
    (found in insn-emit.c) to fill in the CLOBBERs.\n\
@@ -2277,9 +2455,11 @@ make_insn_sequence (insn, type)
   struct decision *last;
   struct decision_test *test, **place;
   struct decision_head head;
+  char c_test_pos[2];
 
   record_insn_name (next_insn_code, (type == RECOG ? XSTR (insn, 0) : NULL));
 
+  c_test_pos[0] = '\0';
   if (type == PEEPHOLE2)
     {
       int i, j;
@@ -2301,6 +2481,9 @@ make_insn_sequence (insn, type)
            }
        }
       XVECLEN (x, 0) = j;
+
+      c_test_pos[0] = 'A' + j - 1;
+      c_test_pos[1] = '\0';
     }
   else if (XVECLEN (insn, type == RECOG) == 1)
     x = XVECEXP (insn, type == RECOG, 0);
@@ -2311,7 +2494,7 @@ make_insn_sequence (insn, type)
       PUT_MODE (x, VOIDmode);
     }
 
-  validate_pattern (x, insn, 0);
+  validate_pattern (x, insn, NULL_RTX, 0);
 
   memset(&head, 0, sizeof(head));
   last = add_to_sequence (x, &head, "", type, 1);
@@ -2326,7 +2509,7 @@ make_insn_sequence (insn, type)
       /* Need a new node if we have another test to add.  */
       if (test->type == DT_accept_op)
        {
-         last = new_decision ("", &last->success);
+         last = new_decision (c_test_pos, &last->success);
          place = &last->tests;
        }
       test = new_decision_test (DT_c_test, &place);
@@ -2412,16 +2595,15 @@ make_insn_sequence (insn, type)
 
     case SPLIT:
       /* Define the subroutine we will call below and emit in genemit.  */
-      printf ("extern rtx gen_split_%d PROTO ((rtx *));\n", next_insn_code);
+      printf ("extern rtx gen_split_%d PARAMS ((rtx *));\n", next_insn_code);
       break;
 
     case PEEPHOLE2:
       /* Define the subroutine we will call below and emit in genemit.  */
-      printf ("extern rtx gen_peephole2_%d PROTO ((rtx, rtx *));\n",
+      printf ("extern rtx gen_peephole2_%d PARAMS ((rtx, rtx *));\n",
              next_insn_code);
       break;
     }
-  next_insn_code++;
 
   return head;
 }
@@ -2456,6 +2638,8 @@ process_tree (head, subroutine_type)
   write_subroutine (head, subroutine_type);
 }
 \f
+extern int main PARAMS ((int, char **));
+
 int
 main (argc, argv)
      int argc;
@@ -2463,26 +2647,18 @@ main (argc, argv)
 {
   rtx desc;
   struct decision_head recog_tree, split_tree, peephole2_tree, h;
-  FILE *infile;
-  register int c;
 
   progname = "genrecog";
-  obstack_init (rtl_obstack);
 
   memset (&recog_tree, 0, sizeof recog_tree);
   memset (&split_tree, 0, sizeof split_tree);
   memset (&peephole2_tree, 0, sizeof peephole2_tree);
 
   if (argc <= 1)
-    fatal ("No input file name.");
+    fatal ("no input file name");
 
-  infile = fopen (argv[1], "r");
-  if (infile == 0)
-    {
-      perror (argv[1]);
-      return FATAL_EXIT_CODE;
-    }
-  read_rtx_filename = argv[1];
+  if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE)
+    return (FATAL_EXIT_CODE);
 
   next_insn_code = 0;
   next_index = 0;
@@ -2493,13 +2669,10 @@ main (argc, argv)
 
   while (1)
     {
-      c = read_skip_spaces (infile);
-      if (c == EOF)
+      desc = read_md_rtx (&pattern_lineno, &next_insn_code);
+      if (desc == NULL)
        break;
-      ungetc (c, infile);
-      pattern_lineno = read_rtx_lineno;
 
-      desc = read_rtx (infile);
       if (GET_CODE (desc) == DEFINE_INSN)
        {
          h = make_insn_sequence (desc, RECOG);
@@ -2515,10 +2688,7 @@ main (argc, argv)
          h = make_insn_sequence (desc, PEEPHOLE2);
          merge_trees (&peephole2_tree, &h);
        }
-       
-      if (GET_CODE (desc) == DEFINE_PEEPHOLE
-         || GET_CODE (desc) == DEFINE_EXPAND)
-       next_insn_code++;
+
       next_index++;
     }
 
@@ -2561,7 +2731,7 @@ record_insn_name (code, name)
       new_size = (insn_name_ptr_size ? insn_name_ptr_size * 2 : 512);
       insn_name_ptr =
        (char **) xrealloc (insn_name_ptr, sizeof(char *) * new_size);
-      memset (insn_name_ptr + insn_name_ptr_size, 0, 
+      memset (insn_name_ptr + insn_name_ptr_size, 0,
              sizeof(char *) * (new_size - insn_name_ptr_size));
       insn_name_ptr_size = new_size;
     }
@@ -2576,44 +2746,8 @@ record_insn_name (code, name)
       last_real_name = new = xstrdup (name);
       last_real_code = code;
     }
-  
-  insn_name_ptr[code] = new;
-}  
-\f
-char *
-xstrdup (input)
-  const char *input;
-{
-  register size_t len = strlen (input) + 1;
-  register char *output = xmalloc (len);
-  memcpy (output, input, len);
-  return output;
-}
 
-PTR
-xrealloc (old, size)
-  PTR old;
-  size_t size;
-{
-  register PTR ptr;
-  if (old)
-    ptr = (PTR) realloc (old, size);
-  else
-    ptr = (PTR) malloc (size);
-  if (!ptr)
-    fatal ("virtual memory exhausted");
-  return ptr;
-}
-
-PTR
-xmalloc (size)
-  size_t size;
-{
-  register PTR val = (PTR) malloc (size);
-
-  if (val == 0)
-    fatal ("virtual memory exhausted");
-  return val;
+  insn_name_ptr[code] = new;
 }
 \f
 static void
@@ -2641,6 +2775,13 @@ debug_decision_2 (test)
       fprintf (stderr, "elt0_w=");
       fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, test->u.intval);
       break;
+    case DT_elt_zero_wide_safe:
+      fprintf (stderr, "elt0_ws=");
+      fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, test->u.intval);
+      break;
+    case DT_veclen_ge:
+      fprintf (stderr, "veclen>=%d", test->u.veclen);
+      break;
     case DT_dup:
       fprintf (stderr, "dup=%d", test->u.dup);
       break;
@@ -2660,7 +2801,7 @@ debug_decision_2 (test)
       fprintf (stderr, "A_op=%d", test->u.opno);
       break;
     case DT_accept_insn:
-      fprintf (stderr, "A_insn=(%d,%d)", 
+      fprintf (stderr, "A_insn=(%d,%d)",
               test->u.insn.code_number, test->u.insn.num_clobbers_to_add);
       break;