OSDN Git Service

* loop.c (regs_patch_p): Add prototype.
[pf3gnuchains/gcc-fork.git] / gcc / genemit.c
index 86ed20d..209fe09 100644 (file)
@@ -1,5 +1,5 @@
 /* Generate code from machine description to emit insns as rtl.
-   Copyright (C) 1987-1991 Free Software Foundation, Inc.
+   Copyright (C) 1987, 88, 91, 94, 95, 97, 1998 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -15,11 +15,12 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
-#include <stdio.h>
-#include "config.h"
+#include "hconfig.h"
+#include "system.h"
 #include "rtl.h"
 #include "obstack.h"
 
@@ -29,11 +30,12 @@ struct obstack *rtl_obstack = &obstack;
 #define obstack_chunk_alloc xmalloc
 #define obstack_chunk_free free
 
-extern void free ();
-
-char *xmalloc ();
+char *xmalloc PROTO((unsigned));
 static void fatal ();
-void fancy_abort ();
+void fancy_abort PROTO((void));
+
+/* Define this so we can link with print-rtl.o to get debug_rtx function.  */
+char **insn_name_ptr = 0;
 
 static int max_opno;
 static int max_dup_opno;
@@ -47,12 +49,31 @@ static int insn_index_number;
 
 struct clobber_pat
 {
-  int code_number;             /* Counts only insns.  */
+  struct clobber_ent *insns;
   rtx pattern;
   int first_clobber;
   struct clobber_pat *next;
 } *clobber_list;
 
+/* Records one insn that uses the clobber list.  */
+
+struct clobber_ent
+{
+  int code_number;             /* Counts only insns.  */
+  struct clobber_ent *next;
+};
+
+static void max_operand_1              PROTO((rtx));
+static int max_operand_vec             PROTO((rtx, int));
+static void print_code                 PROTO((RTX_CODE));
+static void gen_exp                    PROTO((rtx));
+static void gen_insn                   PROTO((rtx));
+static void gen_expand                 PROTO((rtx));
+static void gen_split                  PROTO((rtx));
+static void output_add_clobbers                PROTO((void));
+static void output_init_mov_optab      PROTO((void));
+
+\f
 static void
 max_operand_1 (x)
      rtx x;
@@ -74,7 +95,7 @@ max_operand_1 (x)
   if (code == MATCH_OPERAND || code == MATCH_OPERATOR
       || code == MATCH_PARALLEL)
     max_opno = MAX (max_opno, XINT (x, 0));
-  if (code == MATCH_DUP || code == MATCH_OP_DUP)
+  if (code == MATCH_DUP || code == MATCH_OP_DUP || code == MATCH_PAR_DUP)
     max_dup_opno = MAX (max_dup_opno, XINT (x, 0));
 
   fmt = GET_RTX_FORMAT (code);
@@ -137,7 +158,7 @@ gen_exp (x)
 
   if (x == 0)
     {
-      printf ("0");
+      printf ("NULL_RTX");
       return;
     }
 
@@ -173,11 +194,12 @@ gen_exp (x)
       return;
 
     case MATCH_PARALLEL:
+    case MATCH_PAR_DUP:
       printf ("operand%d", XINT (x, 0));
       return;
 
     case MATCH_SCRATCH:
-      printf ("gen_rtx (SCRATCH, %smode, 0)", GET_MODE_NAME (GET_MODE (x)));
+      printf ("gen_rtx_SCRATCH (%smode)", GET_MODE_NAME (GET_MODE (x)));
       return;
 
     case ADDRESS:
@@ -193,30 +215,33 @@ gen_exp (x)
 
     case CONST_INT:
       if (INTVAL (x) == 0)
+       printf ("const0_rtx");
+      else if (INTVAL (x) == 1)
+       printf ("const1_rtx");
+      else if (INTVAL (x) == -1)
+       printf ("constm1_rtx");
+      else if (INTVAL (x) == STORE_FLAG_VALUE)
+       printf ("const_true_rtx");
+      else
        {
-         printf ("const0_rtx");
-         return;
-       }
-      if (INTVAL (x) == 1)
-       {
-         printf ("const1_rtx");
-         return;
-       }
-      if (INTVAL (x) == -1)
-       {
-         printf ("constm1_rtx");
-         return;
-       }
-      if (INTVAL (x) == STORE_FLAG_VALUE)
-       {
-         printf ("const_true_rtx");
-         return;
+         printf ("GEN_INT (");
+         printf (HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+         printf (")");
        }
+      return;
+
+    case CONST_DOUBLE:
+      /* These shouldn't be written in MD files.  Instead, the appropriate
+        routines in varasm.c should be called.  */
+      abort ();
+
+    default:
+      break;
     }
 
-  printf ("gen_rtx (");
+  printf ("gen_rtx_");
   print_code (code);
-  printf ("%smode", GET_MODE_NAME (GET_MODE (x)));
+  printf (" (%smode", GET_MODE_NAME (GET_MODE (x)));
 
   fmt = GET_RTX_FORMAT (code);
   len = GET_RTX_LENGTH (code);
@@ -224,11 +249,11 @@ gen_exp (x)
     {
       if (fmt[i] == '0')
        break;
-      printf (", ");
+      printf (",\n\t");
       if (fmt[i] == 'e' || fmt[i] == 'u')
        gen_exp (XEXP (x, i));
       else if (fmt[i] == 'i')
-       printf ("%u", (unsigned) XINT (x, i));
+       printf ("%u", XINT (x, i));
       else if (fmt[i] == 's')
        printf ("\"%s\"", XSTR (x, i));
       else if (fmt[i] == 'E')
@@ -259,7 +284,7 @@ gen_insn (insn)
 
   /* See if the pattern for this insn ends with a group of CLOBBERs of (hard)
      registers or MATCH_SCRATCHes.  If so, store away the information for
-     later. */
+     later.  */
 
   if (XVEC (insn, 1))
     {
@@ -271,20 +296,62 @@ gen_insn (insn)
 
       if (i != XVECLEN (insn, 1) - 1)
        {
-         register struct clobber_pat *new
-           = (struct clobber_pat *) xmalloc (sizeof (struct clobber_pat));
+         register struct clobber_pat *p;
+         register struct clobber_ent *link
+           = (struct clobber_ent *) xmalloc (sizeof (struct clobber_ent));
+         register int j;
+
+         link->code_number = insn_code_number;
+
+         /* See if any previous CLOBBER_LIST entry is the same as this
+            one.  */
+
+         for (p = clobber_list; p; p = p->next)
+           {
+             if (p->first_clobber != i + 1
+                 || XVECLEN (p->pattern, 1) != XVECLEN (insn, 1))
+               continue;
+
+             for (j = i + 1; j < XVECLEN (insn, 1); j++)
+               {
+                 rtx old = XEXP (XVECEXP (p->pattern, 1, j), 0);
+                 rtx new = XEXP (XVECEXP (insn, 1, j), 0);
+
+                 /* OLD and NEW are the same if both are to be a SCRATCH
+                    of the same mode, 
+                    or if both are registers of the same mode and number.  */
+                 if (! (GET_MODE (old) == GET_MODE (new)
+                        && ((GET_CODE (old) == MATCH_SCRATCH
+                             && GET_CODE (new) == MATCH_SCRATCH)
+                            || (GET_CODE (old) == REG && GET_CODE (new) == REG
+                                && REGNO (old) == REGNO (new)))))
+                   break;
+               }
+      
+             if (j == XVECLEN (insn, 1))
+               break;
+           }
+
+         if (p == 0)
+           {
+             p = (struct clobber_pat *) xmalloc (sizeof (struct clobber_pat));
          
-         new->code_number = insn_code_number;
-         new->pattern = insn;
-         new->first_clobber = i + 1;
-         new->next = clobber_list;
-         clobber_list = new;
+             p->insns = 0;
+             p->pattern = insn;
+             p->first_clobber = i + 1;
+             p->next = clobber_list;
+             clobber_list = p;
+           }
+
+         link->next = p->insns;
+         p->insns = link;
        }
     }
 
-  /* Don't mention instructions whose names are the null string.
-     They are in the machine description just to be recognized.  */
-  if (strlen (XSTR (insn, 0)) == 0)
+  /* Don't mention instructions whose names are the null string
+     or begin with '*'.  They are in the machine description just
+     to be recognized.  */
+  if (XSTR (insn, 0)[0] == 0 || XSTR (insn, 0)[0] == '*')
     return;
 
   /* Find out how many operands this function has,
@@ -313,7 +380,7 @@ gen_insn (insn)
     }
   else
     {
-      printf ("  return gen_rtx (PARALLEL, VOIDmode, gen_rtvec (%d", XVECLEN (insn, 1));
+      printf ("  return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (%d", XVECLEN (insn, 1));
       for (i = 0; i < XVECLEN (insn, 1); i++)
        {
          printf (",\n\t\t");
@@ -443,14 +510,13 @@ gen_expand (expand)
   /* Call `gen_sequence' to make a SEQUENCE out of all the
      insns emitted within this gen_... function.  */
 
-  printf (" _done:\n");
   printf ("  _val = gen_sequence ();\n");
-  printf (" _fail:\n");
   printf ("  end_sequence ();\n");
   printf ("  return _val;\n}\n\n");
 }
 
 /* Like gen_expand, but generates a SEQUENCE.  */
+
 static void
 gen_split (split)
      rtx split;
@@ -459,9 +525,10 @@ gen_split (split)
   int operands;
 
   if (XVEC (split, 0) == 0)
-    fatal ("define_split %d lacks a pattern", insn_index_number);
+    fatal ("define_split (definition %d) lacks a pattern", insn_index_number);
   else if (XVEC (split, 2) == 0)
-    fatal ("define_split %d lacks a replacement pattern", insn_index_number);
+    fatal ("define_split (definition %d) lacks a replacement pattern",
+          insn_index_number);
 
   /* Find out how many operands this function has.  */
 
@@ -476,7 +543,7 @@ gen_split (split)
   /* Declare all local variables.  */
   for (i = 0; i < operands; i++)
     printf ("  rtx operand%d;\n", i);
-  printf ("  rtx _val;\n");
+  printf ("  rtx _val = 0;\n");
   printf ("  start_sequence ();\n");
 
   /* The fourth operand of DEFINE_SPLIT is some code to be executed
@@ -531,9 +598,7 @@ gen_split (split)
   /* Call `gen_sequence' to make a SEQUENCE out of all the
      insns emitted within this gen_... function.  */
 
-  printf (" _done:\n");
   printf ("  _val = gen_sequence ();\n");
-  printf (" _fail:\n");
   printf ("  end_sequence ();\n");
   printf ("  return _val;\n}\n\n");
 }
@@ -546,6 +611,7 @@ static void
 output_add_clobbers ()
 {
   struct clobber_pat *clobber;
+  struct clobber_ent *ent;
   int i;
 
   printf ("\n\nvoid\nadd_clobbers (pattern, insn_code_number)\n");
@@ -557,7 +623,8 @@ output_add_clobbers ()
 
   for (clobber = clobber_list; clobber; clobber = clobber->next)
     {
-      printf ("    case %d:\n", clobber->code_number);
+      for (ent = clobber->insns; ent; ent = ent->next)
+       printf ("    case %d:\n", ent->code_number);
 
       for (i = clobber->first_clobber; i < XVECLEN (clobber->pattern, 1); i++)
        {
@@ -566,7 +633,7 @@ output_add_clobbers ()
          printf (";\n");
        }
 
-      printf ("      break;\n");
+      printf ("      break;\n\n");
     }
 
   printf ("    default:\n");
@@ -584,7 +651,7 @@ output_init_mov_optab ()
 #ifdef EXTRA_CC_NAMES
   static char *cc_names[] = { EXTRA_CC_NAMES };
   char *p;
-  int i;
+  size_t i;
 
   printf ("\nvoid\ninit_mov_optab ()\n{\n");
 
@@ -658,7 +725,6 @@ main (argc, argv)
 {
   rtx desc;
   FILE *infile;
-  extern rtx read_rtx ();
   register int c;
 
   obstack_init (rtl_obstack);
@@ -685,9 +751,11 @@ main (argc, argv)
 from the machine description file `md'.  */\n\n");
 
   printf ("#include \"config.h\"\n");
+  printf ("#include \"system.h\"\n");
   printf ("#include \"rtl.h\"\n");
   printf ("#include \"expr.h\"\n");
   printf ("#include \"real.h\"\n");
+  printf ("#include \"flags.h\"\n");
   printf ("#include \"output.h\"\n");
   printf ("#include \"insn-config.h\"\n\n");
   printf ("#include \"insn-flags.h\"\n\n");
@@ -695,8 +763,8 @@ from the machine description file `md'.  */\n\n");
   printf ("extern char *insn_operand_constraint[][MAX_RECOG_OPERANDS];\n\n");
   printf ("extern rtx recog_operand[];\n");
   printf ("#define operands emit_operand\n\n");
-  printf ("#define FAIL goto _fail\n\n");
-  printf ("#define DONE goto _done\n\n");
+  printf ("#define FAIL do {end_sequence (); return _val;} while (0)\n");
+  printf ("#define DONE do {_val = gen_sequence (); end_sequence (); return _val;} while (0)\n");
 
   /* Read the machine description.  */