This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

splitting up gencodes


This patch splits gencodes into three programs, and insn-codes.h into three
separate headers.

Originally, insn-codes.h contained the definition of enum insn_code,
and nothing else.  Recently it's been changed to include #defines
generated from (define_constants) expressions in the MD file, and
prototypes for all the target-specific predicates.  Those are wanted
in much more of the compiler than enum insn_code is, so we wound up
including insn-codes.h from config.h.  And that meant that any time
enum insn_code changed - which it does if you simply add another pattern
to the machine description, for instance - the entire compiler had to
be rebuilt, when the chunk of code that actually cared about that change
was much smaller.

The situation was even worse than apparent since insn-codes.h was forced
to include machmode.h, and therefore there was a dependency of the whole
compiler on that header, but someone forgot to add that to the makefile.
Fortunately machmode.h/machmode.def changes only rarely.

Having too much stuff in insn-codes.h also causes problems with
experimental code I am working on, that needs some but not all the
information in insn-codes.h, but has to run before gencodes does.

[the situation is similar, but nastier, with insn-flags.h.  I'm not
touching that one just yet.]

Anyhow, this patch just creates new generated headers, insn-constants.h
and tm-preds.h.  The former is included in config.h, the latter in
tm_p.h.  tconfig.h and hconfig.h no longer include any insn-* headers.
insn-codes.h is still included by config.h; I didn't want to clutter
up this patch with the mostly mechanical changes to take it out.  That's
coming as a follow-on.  tm-preds.h uses #ifdef RTX_CODE rather than
including machmode.h itself, which matches the *-protos.h files.

Bootstrapping i386-linux.  OK presuming it succeeds?  (It's got through
to the beginning of stage3 already.  Also, make -j stage1_build had
no problems (but I only have a single CPU).

zw

	* Makefile.in (HOST_CFLAGS): Take out -DGENERATOR_FILE.
	(CONFIG_H, TCONFIG_H, TM_P_H): Update.
	(GEN, STAGESTUFF): Add new files.
	(insn-constants.h, s-constants, tm-preds.h, s-preds,
	genconstants, genpreds, genconstants.o, genpreds.o): New rules.
	(hashtab.o, safe-ctype.o): Add -DGENERATOR_FILE.
	* mkconfig.sh: Include tm-preds.h in tm_p.h; insn-constants.h
	as well as insn-codes.h and insn-flags.h in config.h; and no
	extra headers in tconfig.h and hconfig.h.

	* gencodes.c: Eliminate code to generate predicate declarations
	or #defines for md-file constants.
	* genconstants.c, genpreds.c: New files.

===================================================================
Index: Makefile.in
--- Makefile.in	2001/08/06 21:07:40	1.716
+++ Makefile.in	2001/08/07 17:45:27
@@ -482,7 +482,7 @@ HOST_PREFIX_1=loser-
 HOST_CC=$(CC)
 # If you change any of the following variables, check whether a
 # similar change is needed in build-make.
-HOST_CFLAGS=$(ALL_CFLAGS) -DGENERATOR_FILE
+HOST_CFLAGS=$(ALL_CFLAGS)
 HOST_LDFLAGS=$(LDFLAGS)
 HOST_CPPFLAGS=$(ALL_CPPFLAGS)
 HOST_OBSTACK=$(OBSTACK)
@@ -550,14 +550,14 @@ all: all.indirect
 
 # GCONFIG_H lists the config files that the generator files depend on, while
 # CONFIG_H lists the the ones ordinary gcc files depend on, which includes
-# a file generated by gencodes.
+# several files generated by those generators.
 GCONFIG_H = config.h $(host_xm_file_list)
 HCONFIG_H = hconfig.h $(build_xm_file_list)
-CONFIG_H = $(GCONFIG_H) insn-codes.h insn-flags.h
-TCONFIG_H = tconfig.h $(xm_file_list) insn-codes.h
+CONFIG_H = $(GCONFIG_H) insn-constants.h insn-codes.h insn-flags.h
+TCONFIG_H = tconfig.h $(xm_file_list)
 TARGET_H = target.h
 TARGET_DEF_H = target-def.h
-TM_P_H = tm_p.h $(tm_p_file_list) insn-codes.h
+TM_P_H = tm_p.h $(tm_p_file_list) tm-preds.h
 
 MACHMODE_H = machmode.h machmode.def
 RTL_BASE_H = rtl.h rtl.def $(MACHMODE_H)
@@ -762,20 +762,22 @@ BACKEND = main.o libbackend.a
 GEN= genemit$(build_exeext) genoutput$(build_exeext) genrecog$(build_exeext) \
  genextract$(build_exeext) genflags$(build_exeext) gencodes$(build_exeext)   \
  genconfig$(build_exeext) genpeep$(build_exeext) gengenrtl$(build_exeext)    \
- gencheck$(build_exeext)
+ gencheck$(build_exeext) genpreds$(build_exeext) genconstants$(build_exeext)
 
 # Files to be copied away after each stage in building.
 STAGESTUFF = *$(objext) insn-flags.h insn-config.h insn-codes.h \
  insn-output.c insn-recog.c insn-emit.c insn-extract.c insn-peep.c \
- insn-attr.h insn-attrtab.c insn-opinit.c tree-check.h \
+ insn-attr.h insn-attrtab.c insn-opinit.c insn-constants.h tm-preds.h \
+ tree-check.h \
  s-flags s-config s-codes s-mlib s-under s-genrtl \
  s-output s-recog s-emit s-extract s-peep s-check \
- s-attr s-attrtab s-opinit s-crt0 \
+ s-attr s-attrtab s-opinit s-preds s-constants s-crt0 \
  genemit$(build_exeext) genoutput$(build_exeext) genrecog$(build_exeext) \
  genextract$(build_exeext) genflags$(build_exeext) gencodes$(build_exeext) \
  genconfig$(build_exeext) genpeep$(build_exeext) genattrtab$(build_exeext) \
  genattr$(build_exeext) genopinit$(build_exeext) gengenrtl$(build_exeext) \
- gencheck$(build_exeext) genrtl.c genrtl.h \
+ gencheck$(build_exeext) genpreds$(build_exeext) genconstants$(build_exeext) \
+ genrtl.c genrtl.h \
  xgcc$(exeext) cpp$(exeext) cc1$(exeext) cpp0$(exeext) $(EXTRA_PASSES) \
  $(EXTRA_PARTS) $(EXTRA_PROGRAMS) gcc-cross$(exeext) cc1obj$(exeext) \
  enquire$(exeext) protoize$(exeext) unprotoize$(exeext) \
@@ -1591,7 +1593,7 @@ halfpic.o: halfpic.c $(CONFIG_H) $(RTL_H
 # Generate header and source files from the machine description,
 # and compile them.
 
-.PRECIOUS: insn-config.h insn-flags.h insn-codes.h \
+.PRECIOUS: insn-config.h insn-flags.h insn-codes.h insn-constants.h \
   insn-emit.c insn-recog.c insn-extract.c insn-output.c insn-peep.c \
   insn-attr.h insn-attrtab.c
 
@@ -1632,6 +1634,12 @@ s-codes : $(md_file) gencodes$(build_exe
 	$(SHELL) $(srcdir)/move-if-change tmp-codes.h insn-codes.h
 	$(STAMP) s-codes
 
+insn-constants.h: s-constants ; @true
+s-constants : $(md_file) genconstants$(build_exeext) $(srcdir)/move-if-change
+	./genconstants$(build_exeext) $(md_file) > tmp-constants.h
+	$(SHELL) $(srcdir)/move-if-change tmp-constants.h insn-constants.h
+	$(STAMP) s-constants
+
 insn-emit.o : insn-emit.c $(CONFIG_H) $(RTL_H) $(EXPR_H) real.h output.h \
   insn-config.h $(SYSTEM_H) reload.h $(RECOG_H) toplev.h \
   function.h flags.h hard-reg-set.h resource.h $(TM_P_H)
@@ -1718,11 +1726,19 @@ genrtl.c genrtl.h : s-genrtl
 	@true	# force gnu make to recheck modification times.
 
 s-genrtl: gengenrtl$(build_exeext) $(srcdir)/move-if-change $(RTL_BASE_H)
-	./gengenrtl$(build_exeext) -h >tmp-genrtl.h
+	./gengenrtl$(build_exeext) -h > tmp-genrtl.h
 	$(SHELL) $(srcdir)/move-if-change tmp-genrtl.h genrtl.h
-	./gengenrtl$(build_exeext) >tmp-genrtl.c
+	./gengenrtl$(build_exeext) > tmp-genrtl.c
 	$(SHELL) $(srcdir)/move-if-change tmp-genrtl.c genrtl.c
 	$(STAMP) s-genrtl
+
+tm-preds.h: s-preds; @true
+
+s-preds: genpreds$(build_exeext) $(srcdir)/move-if-change
+	./genpreds$(build_exeext) > tmp-preds.h
+	$(SHELL) $(srcdir)/move-if-change tmp-preds.h tm-preds.h
+	$(STAMP) s-preds
+
 #
 # Compile the programs that generate insn-* from the machine description.
 # They are compiled with $(HOST_CC), and associated libraries,
@@ -1744,12 +1760,12 @@ gensupport.o: gensupport.c $(RTL_H) $(OB
 hashtab.o: $(srcdir)/../libiberty/hashtab.c $(GCONFIG_H)
 	rm -f hashtab.c
 	$(LN_S) $(srcdir)/../libiberty/hashtab.c hashtab.c
-	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) hashtab.c
+	$(HOST_CC) -c $(HOST_CFLAGS) -DGENERATOR_FILE $(HOST_CPPFLAGS) $(INCLUDES) hashtab.c
 
 safe-ctype.o: $(srcdir)/../libiberty/safe-ctype.c $(GCONFIG_H)
 	rm -f safe-ctype.c
 	$(LN_S) $(srcdir)/../libiberty/safe-ctype.c safe-ctype.c
-	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) safe-ctype.c
+	$(HOST_CC) -c $(HOST_CFLAGS) -DGENERATOR_FILE $(HOST_CPPFLAGS) $(INCLUDES) safe-ctype.c
 
 genconfig$(build_exeext) : genconfig.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
 	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
@@ -1775,6 +1791,13 @@ gencodes.o : gencodes.c $(RTL_H) $(HCONF
   $(SYSTEM_H) errors.h gensupport.h
 	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gencodes.c
 
+genconstants$(build_exeext) : genconstants.o $(HOST_RTL) $(HOST_ERRORS) $(HOST_LIBDEPS)
+	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
+	 genconstants.o $(HOST_RTL) $(HOST_ERRORS) $(HOST_LIBS)
+
+genconstants.o : genconstants.c $(RTL_H) $(HCONFIG_H) $(SYSTEM_H) errors.h
+	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genconstants.c
+
 genemit$(build_exeext) : genemit.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBDEPS)
 	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
 	 genemit.o $(HOST_RTL) $(HOST_PRINT) $(HOST_ERRORS) $(HOST_LIBS)
@@ -1842,6 +1865,14 @@ gengenrtl$(build_exeext) : gengenrtl.o $
 
 gengenrtl.o : gengenrtl.c $(RTL_BASE_H) $(HCONFIG_H) $(SYSTEM_H) real.h
 	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/gengenrtl.c
+
+genpreds$(build_exeext) : genpreds.o $(HOST_LIBDEPS)
+	$(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ \
+	 genpreds.o $(HOST_LIBS)
+
+genpreds.o : genpreds.c $(RTL_BASE_H) $(HCONFIG_H) $(SYSTEM_H)
+	$(HOST_CC) -c $(HOST_CFLAGS) $(HOST_CPPFLAGS) $(INCLUDES) $(srcdir)/genpreds.c
+
 #
 # Compile the libraries to be used by gen*.
 # If we are not cross-building, gen* use the same .o's that cc1 will use,
===================================================================
Index: mkconfig.sh
--- mkconfig.sh	2001/03/25 13:23:30	1.4
+++ mkconfig.sh	2001/08/07 17:45:27
@@ -49,12 +49,25 @@ for def in $DEFINES; do
     echo "#endif"
 done
 
-# Include insn-codes.h last, because it includes machmode.h,
-# and we want EXTRA_CC_MODES to be taken into account.
-echo "#ifndef GENERATOR_FILE"
-echo "#include \"insn-codes.h\""
-echo "#include \"insn-flags.h\""
-echo "#endif"
+# If this is tm_p.h, include tm-preds.h unconditionally.
+# If this is tconfig.h or hconfig.h, include no more files.
+# Otherwise, include insn-constants.h, insn-flags.h, and insn-codes.h,
+# but only if GENERATOR_FILE is not defined. (The last of those is
+# slated to be removed.)
+case $output in
+    *tm_p.h)
+	echo "#include \"tm-preds.h\""
+    ;;
+    *tconfig.h | *hconfig.h)
+    ;;
+    *)
+	echo "#ifndef GENERATOR_FILE"
+	echo "# include \"insn-constants.h\""
+	echo "# include \"insn-codes.h\""
+	echo "# include \"insn-flags.h\""
+	echo "#endif"
+    ;;
+esac
 
 ) > $output.T
 
===================================================================
Index: gencodes.c
--- gencodes.c	2001/04/02 16:29:31	1.39
+++ gencodes.c	2001/08/07 17:45:27
@@ -28,12 +28,9 @@ Boston, MA 02111-1307, USA.  */
 #include "errors.h"
 #include "gensupport.h"
 
-
 static int insn_code_number;
 
 static void gen_insn PARAMS ((rtx));
-static void output_predicate_decls PARAMS ((void));
-static int print_md_constant PARAMS ((void **, void *));
 
 static void
 gen_insn (insn)
@@ -47,30 +44,6 @@ gen_insn (insn)
 	    insn_code_number);
 }
 
-/* Print out declarations for all predicates mentioned in
-   PREDICATE_CODES.  */
-
-static void
-output_predicate_decls ()
-{
-#ifdef PREDICATE_CODES
-  static struct {
-    const char *name;
-    RTX_CODE codes[NUM_RTX_CODE];
-  } predicate[] = {
-    PREDICATE_CODES
-  };
-  size_t i;
-
-  putc ('\n', stdout);
-  puts ("struct rtx_def;\n#include \"machmode.h\"\n");
-  for (i = 0; i < sizeof predicate / sizeof *predicate; i++)
-    printf ("extern int %s PARAMS ((struct rtx_def *, enum machine_mode));\n",
-	    predicate[i].name);
-  putc ('\n', stdout);
-#endif
-}
-
 extern int main PARAMS ((int, char **));
 
 int
@@ -114,10 +87,6 @@ main (argc, argv)
 
   printf ("\n#define MAX_INSN_CODE ((int) CODE_FOR_nothing)\n\n");
 
-  traverse_md_constants (print_md_constant, stdout);
-
-  output_predicate_decls ();
-
   puts("\n#endif /* GCC_INSN_CODES_H */");
 
   if (ferror (stdout) || fflush (stdout) || fclose (stdout))
@@ -133,19 +102,4 @@ get_insn_name (code)
      int code ATTRIBUTE_UNUSED;
 {
   return NULL;
-}
-
-/* Called via traverse_md_constants; emit a #define for
-   the current constant definition.  */
-
-static int
-print_md_constant (slot, info)
-     void **slot;
-     void *info;
-{
-  struct md_constant *def = *slot;
-  FILE *file = info;
-
-  fprintf (file, "#define %s %s\n", def->name, def->value);
-  return 1;
 }
===================================================================
Index: genconstants.c
--- genconstants.c	Tue May  5 13:32:27 1998
+++ genconstants.c	Tue Aug  7 10:45:27 2001
@@ -0,0 +1,88 @@
+/* Generate from machine description:
+   a series of #define statements, one for each constant named in
+   a (define_constants ...) pattern.
+
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+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
+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.
+
+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.  */
+
+/* This program does not use gensupport.c because it does not need to
+   look at insn patterns, only (define_constants), and we want to
+   minimize dependencies.  */
+
+#include "hconfig.h"
+#include "system.h"
+#include "rtl.h"
+#include "errors.h"
+#include "gensupport.h"
+
+static int print_md_constant PARAMS ((void **, void *));
+extern int main PARAMS ((int, char **));
+
+/* Called via traverse_md_constants; emit a #define for
+   the current constant definition.  */
+
+static int
+print_md_constant (slot, info)
+     void **slot;
+     void *info;
+{
+  struct md_constant *def = *slot;
+  FILE *file = info;
+
+  fprintf (file, "#define %s %s\n", def->name, def->value);
+  return 1;
+}
+
+int
+main (argc, argv)
+     int argc;
+     char **argv;
+{
+  int dummy1, dummy2;
+  rtx desc;
+
+  progname = "genconstants";
+
+  if (argc <= 1)
+    fatal ("No input file name.");
+
+  if (init_md_reader (argv[1]) != SUCCESS_EXIT_CODE)
+    return (FATAL_EXIT_CODE);
+
+  /* Scan and discard the entire file.  This has the side effect
+     of loading up the constants table that we wish to scan.  */
+  do
+    desc = read_md_rtx (&dummy1, &dummy2);
+  while (desc);
+
+  puts ("/* Generated automatically by the program `genconstants'");
+  puts ("   from the machine description file `md'.  */\n");
+  puts ("#ifndef GCC_INSN_CONSTANTS_H");
+  puts ("#define GCC_INSN_CONSTANTS_H\n");
+
+  traverse_md_constants (print_md_constant, stdout);
+
+  puts ("\n#endif /* GCC_INSN_CONSTANTS_H */");
+
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
+
+  return SUCCESS_EXIT_CODE;
+}
+
===================================================================
Index: genpreds.c
--- genpreds.c	Tue May  5 13:32:27 1998
+++ genpreds.c	Tue Aug  7 10:45:27 2001
@@ -0,0 +1,65 @@
+/* Generate declarations of all machine-specific predicates.
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+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
+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.
+
+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.  */
+
+#include "hconfig.h"
+#include "system.h"
+
+#define NO_GENRTL_H
+#include "rtl.h"
+
+static void output_predicate_decls PARAMS ((void));
+extern int main PARAMS ((void));
+
+static void
+output_predicate_decls ()
+{
+#ifdef PREDICATE_CODES
+  static struct {
+    const char *name;
+    RTX_CODE codes[NUM_RTX_CODE];
+  } predicate[] = {
+    PREDICATE_CODES
+  };
+  size_t i;
+
+  puts ("#ifdef RTX_CODE\n");
+  for (i = 0; i < sizeof predicate / sizeof *predicate; i++)
+    printf ("extern int %s PARAMS ((rtx, enum machine_mode));\n",
+	    predicate[i].name);
+  puts ("\n#endif /* RTX_CODE */\n");
+#endif
+}
+
+int
+main ()
+{
+  puts ("/* Generated automatically by the program `genpreds'.  */\n");
+  puts ("#ifndef GCC_TM_PREDS_H");
+  puts ("#define GCC_TM_PREDS_H\n");
+
+  output_predicate_decls ();
+
+  puts ("#endif /* GCC_TM_PREDS_H */");
+
+  if (ferror (stdout) || fflush (stdout) || fclose (stdout))
+    return FATAL_EXIT_CODE;
+
+  return SUCCESS_EXIT_CODE;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]