[RFA] Skip back-end initialization when possible

Neil Booth neil@daikokuya.co.uk
Mon Jul 1 23:02:00 GMT 2002


The integrated preprocessor carries the baggage of back end
initialization.  This patch improves the lang hooks so that
the front end can indicate, after option parsing, whether
the compiler back end is needed.  With the work on cleaning
up toplev.c initialization earlier this year, back end
initialization is cleanly separated and easily skipped.

Bootstrapped x86 Linux without regressions.  OK to commit?

Neil.

	* c-common.c (c_common_post_options): Update prototype;
	don't init backends if preprocessing only.
	* langhooks-def.h (LANG_HOOKS_POST_OPTIONS): Update.
	* langhooks.h (struct lang_hooks): Update post_options to
	return a boolean.
	* toplev.c (parse_options_and_default_flags, do_compile,
	lang_independent_init): Update prototypes.  Allow the
	front end to specify that there is no need to initialize
	the back end.
	(general_init): Move call to hex_init here...
	(toplev_main): ...from here.  Pass flag for back end init
	suppression.
java:
	* lang.c (java_post_options): Update prototype.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.346
diff -u -p -r1.346 c-common.c
--- c-common.c	1 Jul 2002 23:06:59 -0000	1.346
+++ c-common.c	2 Jul 2002 05:53:37 -0000
@@ -4272,7 +4272,7 @@ c_common_init_options (lang)
 }
 
 /* Post-switch processing.  */
-void
+bool
 c_common_post_options ()
 {
   cpp_post_options (parse_in);
@@ -4314,6 +4314,8 @@ c_common_post_options ()
   /* If an error has occurred in cpplib, note it so we fail
      immediately.  */
   errorcount += cpp_errors (parse_in);
+
+  return flag_preprocess_only;
 }
 
 /* Hook that registers front end and target-specific built-ins.  */
Index: langhooks-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks-def.h,v
retrieving revision 1.34
diff -u -p -r1.34 langhooks-def.h
--- langhooks-def.h	4 Jun 2002 07:07:49 -0000	1.34
+++ langhooks-def.h	2 Jul 2002 05:53:37 -0000
@@ -88,7 +88,7 @@ tree lhd_tree_inlining_convert_parm_for_
 #define LANG_HOOKS_CLEAR_BINDING_STACK	lhd_clear_binding_stack
 #define LANG_HOOKS_INIT_OPTIONS		lhd_do_nothing
 #define LANG_HOOKS_DECODE_OPTION	lhd_decode_option
-#define LANG_HOOKS_POST_OPTIONS		hook_void_void
+#define LANG_HOOKS_POST_OPTIONS		hook_void_bool_false
 #define LANG_HOOKS_GET_ALIAS_SET	lhd_get_alias_set
 #define LANG_HOOKS_EXPAND_CONSTANT	lhd_return_tree
 #define LANG_HOOKS_EXPAND_EXPR		lhd_expand_expr
Index: langhooks.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/langhooks.h,v
retrieving revision 1.42
diff -u -p -r1.42 langhooks.h
--- langhooks.h	4 Jun 2002 07:07:50 -0000	1.42
+++ langhooks.h	2 Jul 2002 05:53:37 -0000
@@ -198,9 +198,12 @@ struct lang_hooks
      initialization should be left to the "init" callback, since GC
      and the identifier hashes are set up between now and then.
 
+     Should return zero unless the compiler back-end does not need to
+     be initialized, such as with the -E option.
+     
      If errorcount is non-zero after this call the compiler exits
      immediately and the finish hook is not called.  */
-  void (*post_options) PARAMS ((void));
+  bool (*post_options) PARAMS ((void));
 
   /* Called after post_options, to initialize the front end.  The main
      input filename is passed, which may be NULL; the front end should
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.654
diff -u -p -r1.654 toplev.c
--- toplev.c	16 Jun 2002 19:31:01 -0000	1.654
+++ toplev.c	2 Jul 2002 05:53:38 -0000
@@ -96,10 +96,10 @@ extern int size_directive_output;
 extern tree last_assemble_variable_decl;
 
 static void general_init PARAMS ((char *));
-static void parse_options_and_default_flags PARAMS ((int, char **));
-static void do_compile PARAMS ((void));
+static bool parse_options_and_default_flags PARAMS ((int, char **));
+static void do_compile PARAMS ((int));
 static void process_options PARAMS ((void));
-static void lang_independent_init PARAMS ((void));
+static void lang_independent_init PARAMS ((int));
 static int lang_dependent_init PARAMS ((const char *));
 static void init_asm_output PARAMS ((const char *));
 static void finalize PARAMS ((void));
@@ -4583,6 +4583,8 @@ general_init (argv0)
 
   xmalloc_set_program_name (progname);
 
+  hex_init ();
+
   gcc_init_libintl ();
 
   /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
@@ -4613,8 +4615,10 @@ general_init (argv0)
 /* Parse command line options and set default flag values, called
    after language-independent option-independent initialization.  Do
    minimal options processing.  Outputting diagnostics is OK, but GC
-   and identifier hashtables etc. are not initialized yet.  */
-static void
+   and identifier hashtables etc. are not initialized yet.
+
+   Return non-zero to suppress compiler back end initialization.  */
+static bool
 parse_options_and_default_flags (argc, argv)
      int argc;
      char **argv;
@@ -4845,7 +4849,7 @@ parse_options_and_default_flags (argc, a
 
   /* All command line options have been parsed; allow the front end to
      perform consistency checks, etc.  */
-  (*lang_hooks.post_options) ();
+  return (*lang_hooks.post_options) ();
 }
 
 /* Process the options that have been parsed.  */
@@ -5024,7 +5028,8 @@ process_options ()
 /* Language-independent initialization, before language-dependent
    initialization.  */
 static void
-lang_independent_init ()
+lang_independent_init (no_backend)
+     int no_backend;
 {
   /* Initialize the garbage-collector, and string pools.  */
   init_ggc ();
@@ -5032,6 +5037,9 @@ lang_independent_init ()
   init_stringpool ();
   init_obstacks ();
 
+  if (no_backend)
+    return;
+
   /* init_emit_once uses reg_raw_mode and therefore must be called
      after init_regs which initialized reg_raw_mode.  */
   init_regs ();
@@ -5166,7 +5174,8 @@ finalize ()
 
 /* Initialize the compiler, and compile the input file.  */
 static void
-do_compile ()
+do_compile (no_backend)
+     int no_backend;
 {
   /* The bulk of command line switch processing.  */
   process_options ();
@@ -5177,8 +5186,8 @@ do_compile ()
   timevar_start (TV_TOTAL);
 
   /* Language-independent initialization.  Also sets up GC, identifier
-     hashes etc.  */
-  lang_independent_init ();
+     hashes etc., and the back-end if requested.  */
+  lang_independent_init (no_backend);
 
   /* Language-dependent initialization.  Returns true on success.  */
   if (lang_dependent_init (filename))
@@ -5203,18 +5212,18 @@ toplev_main (argc, argv)
      int argc;
      char **argv;
 {
-  hex_init ();
+  bool no_backend;
 
   /* Initialization of GCC's environment, and diagnostics.  */
   general_init (argv[0]);
 
   /* Parse the options and do minimal processing; basically just
      enough to default flags appropriately.  */
-  parse_options_and_default_flags (argc, argv);
+  no_backend = parse_options_and_default_flags (argc, argv);
 
   /* Exit early if we can (e.g. -help).  */
   if (!errorcount && !exit_after_options)
-    do_compile ();
+    do_compile (no_backend);
 
   if (errorcount || sorrycount)
     return (FATAL_EXIT_CODE);
Index: java/lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lang.c,v
retrieving revision 1.103
diff -u -p -r1.103 lang.c
--- java/lang.c	10 Jun 2002 05:11:42 -0000	1.103
+++ java/lang.c	2 Jul 2002 05:53:38 -0000
@@ -51,7 +51,7 @@ struct string_option
 static const char *java_init PARAMS ((const char *));
 static void java_finish PARAMS ((void));
 static void java_init_options PARAMS ((void));
-static void java_post_options PARAMS ((void));
+static bool java_post_options PARAMS ((void));
 
 static int java_decode_option PARAMS ((int, char **));
 static void put_decl_string PARAMS ((const char *, int));
@@ -780,7 +780,7 @@ java_init_options ()
 }
 
 /* Post-switch processing.  */
-static void
+static bool
 java_post_options ()
 {
   /* Turn off RTL inliner unless -finline-functions was really specified.  */
@@ -789,6 +789,9 @@ java_post_options ()
       flag_no_inline = 1;
       flag_inline_functions = 0;
     }
+
+  /* Initialize the compiler back end.  */
+  return false;
 }
 
 #include "gt-java-lang.h"



More information about the Gcc-patches mailing list