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]
Other format: [Raw text]

[incremental] Patch: FYI: save and restore options and params


I'm checking this in on the incremental-compiler branch.

We need to save the default settings of options and params and restore
them after each compilation.  Otherwise, having a build where an
option is enabled for one compilation and disabled for the next will
do the wrong thing.  This came up when building gdb.

This new code largely works automatically.  There are a few options
that aren't handled via the tables, though, which we must handle
specially.  Also, front ends which wish to be incremental must be
aware of this.  I believe the C front end, currently the only
incremental front end, is ok.

Tom

ChangeLog:
2008-03-24  Tom Tromey  <tromey@redhat.com>

	* toplev.c (lang_independent_params): Update for params.h change.
	(DEFPARAM): Likewise.
	* opts.c (option_value): New typedef.
	(default_values, defaults_saved): New globals.
	(verbose): Move out of function scope.
	(type_explicit): Likewise.
	(clean_up): Call restore_default_option_values, reset_params.
	(decode_options): Call save_default_option_values.
	(common_handle_option): Move 'verbose' to file scope.
	(set_debug_level): Move 'type_explicit' to file scope.
	(save_default_option_values): New function.
	(restore_default_option_values): Likewise.
	* params.c (reset_params): New function.
	* params.h (param_info) <default_value>: New field.
	(reset_params): Declare.

Index: params.c
===================================================================
--- params.c	(revision 132956)
+++ params.c	(working copy)
@@ -1,5 +1,5 @@
 /* params.c - Run-time parameters.
-   Copyright (C) 2001, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
 This file is part of GCC.
@@ -84,3 +84,16 @@
   /* If we didn't find this parameter, issue an error message.  */
   error ("invalid parameter %qs", name);
 }
+
+/* Reset each parameter to the default setting.  */
+
+void
+reset_params (void)
+{
+  size_t i;
+  for (i = 0; i < num_compiler_params; ++i)
+    {
+      compiler_params[i].value = compiler_params[i].default_value;
+      compiler_params[i].set = false;
+    }
+}
Index: params.h
===================================================================
--- params.h	(revision 132956)
+++ params.h	(working copy)
@@ -1,5 +1,5 @@
 /* params.h - Run-time parameters.
-   Copyright (C) 2001, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2003, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
    Written by Mark Mitchell <mark@codesourcery.com>.
 
 This file is part of GCC.
@@ -43,6 +43,7 @@
   /* The name used with the `--param <name>=<value>' switch to set this
      value.  */
   const char *const option;
+
   /* The associated value.  */
   int value;
 
@@ -55,6 +56,9 @@
   /* Maximum acceptable value, if greater than minimum  */
   int max_value;
   
+  /* The default value.  */
+  int default_value;
+
   /* A short description of the option.  */
   const char *const help;
 } param_info;
@@ -72,6 +76,9 @@
 
 extern void set_param_value (const char *name, int value);
 
+/* Reset the all params to their default values.  */
+extern void reset_params (void);
+
 
 /* The parameters in use by language-independent code.  */
 
Index: toplev.c
===================================================================
--- toplev.c	(revision 133353)
+++ toplev.c	(working copy)
@@ -373,10 +373,10 @@
 
 static const param_info lang_independent_params[] = {
 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
-  { OPTION, DEFAULT, false, MIN, MAX, HELP },
+  { OPTION, DEFAULT, false, MIN, MAX, DEFAULT, HELP },
 #include "params.def"
 #undef DEFPARAM
-  { NULL, 0, false, 0, 0, NULL }
+  { NULL, 0, false, 0, 0, 0, NULL }
 };
 
 /* Output files for assembler code (real compiler output)
Index: opts.c
===================================================================
--- opts.c	(revision 132956)
+++ opts.c	(working copy)
@@ -1,5 +1,5 @@
 /* Command line option handling.
-   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
+   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Neil Booth.
 
@@ -42,6 +42,19 @@
 #include "dbgcnt.h"
 #include "debug.h"
 
+/* We save the default values of options using this type.  */
+typedef union
+{
+  const char *strvalue;
+  int intvalue;
+} option_value;
+
+static option_value default_values[N_OPTS];
+
+static bool defaults_saved;
+
+static bool verbose = false;
+
 /* Value of the -G xx switch, and whether it was passed or not.  */
 unsigned HOST_WIDE_INT g_switch_value;
 bool g_switch_set;
@@ -386,6 +399,8 @@
 static void handle_options (unsigned int, const char **, unsigned int);
 static void set_debug_level (enum debug_info_type type, int extended,
 			     const char *arg);
+static void save_default_option_values (void);
+static void restore_default_option_values (void);
 
 /* If ARG is a non-negative integer made up solely of digits, return its
    value, otherwise return -1.  */
@@ -782,6 +797,9 @@
       in_fnames = NULL;
       num_in_fnames = 0;
     }
+
+  restore_default_option_values ();
+  reset_params ();
 }
 
 /* Parse command line options and set default flag values.  Do minimal
@@ -791,8 +809,16 @@
 {
   unsigned int i, lang_mask;
 
-  /* Clean up from previous run.  */
-  clean_up ();
+  if (! defaults_saved)
+    {
+      save_default_option_values ();
+      defaults_saved = true;
+    }
+  else
+    {
+      /* Clean up from previous run.  */
+      clean_up ();
+    }
 
   /* Perform language-specific options initialization.  */
   lang_mask = lang_hooks.init_options (argc, argv);
@@ -1368,7 +1394,6 @@
 common_handle_option (size_t scode, const char *arg, int value,
 		      unsigned int lang_mask)
 {
-  static bool verbose = false;
   enum opt_code code = (enum opt_code) scode;
 
   switch (code)
@@ -2020,13 +2045,13 @@
 	  && !flag_errno_math);
 }
 
+static bool type_explicit;
+
 /* Handle a debug output -g switch.  EXTENDED is true or false to support
    extended output (2 is special and means "-ggdb" was given).  */
 static void
 set_debug_level (enum debug_info_type type, int extended, const char *arg)
 {
-  static bool type_explicit;
-
   use_gnu_debug_info_extensions = extended;
 
   if (type == NO_DEBUG)
@@ -2167,3 +2192,86 @@
     }
   free (new_option);
 }
+
+/* Save the default values of all options.  */
+static void
+save_default_option_values (void)
+{
+  int i;
+  for (i = 0; i < N_OPTS; ++i)
+    {
+      if (! cl_options[i].flag_var)
+	continue;
+      if (cl_options[i].var_type == CLVC_STRING)
+	default_values[i].strvalue = *(const char **) cl_options[i].flag_var;
+      else
+	{
+	  /* All others have type int.  */
+	  default_values[i].intvalue = *(int *) cl_options[i].flag_var;
+	}
+    }
+}
+
+/* Restore the default values of all options.  */
+static void
+restore_default_option_values (void)
+{
+  int i;
+  gcc_assert (defaults_saved);
+  for (i = 0; i < N_OPTS; ++i)
+    {
+      if (! cl_options[i].flag_var)
+	continue;
+      if (cl_options[i].var_type == CLVC_STRING)
+	*(const char **) cl_options[i].flag_var = default_values[i].strvalue;
+      else
+	{
+	  /* All others have type int.  */
+	  *(int *) cl_options[i].flag_var = default_values[i].intvalue;
+	}
+    }
+
+  /* Reset option variables which are not described in cl_options.  */
+  verbose = false;
+  g_switch_value = 0;
+  g_switch_set = false;
+  extra_warnings = false;
+  warn_larger_than = 0;
+  larger_than_size = 0;
+  warn_frame_larger_than = false;
+  frame_larger_than_size = 0;
+  maybe_warn_unused_parameter = false;
+  write_symbols = NO_DEBUG;
+  debug_info_level = DINFO_LEVEL_NONE;
+
+  debug_struct_ordinary[0] = DINFO_STRUCT_FILE_ANY;
+  debug_struct_ordinary[1] = DINFO_STRUCT_FILE_ANY;
+  debug_struct_ordinary[2] = DINFO_STRUCT_FILE_ANY;
+  debug_struct_generic[0] = DINFO_STRUCT_FILE_ANY;
+  debug_struct_generic[1] = DINFO_STRUCT_FILE_ANY;
+  debug_struct_generic[2] = DINFO_STRUCT_FILE_ANY;
+
+  use_gnu_debug_info_extensions = false;
+  default_visibility = VISIBILITY_DEFAULT;
+
+  no_unit_at_a_time_default = false;
+
+  memset (&visibility_options, 0, sizeof (struct visibility_flags));
+
+  profile_arc_flag_set = flag_profile_values_set = false;
+  flag_unroll_loops_set = flag_tracer_set = false;
+  flag_value_profile_transformations_set = false;
+  flag_peel_loops_set = flag_branch_probabilities_set = false;
+  flag_inline_functions_set = false;
+
+  VEC_free (char_p, heap, flag_instrument_functions_exclude_functions);
+  VEC_free (char_p, heap, flag_instrument_functions_exclude_files);
+  VEC_free (const_char_p, heap, ignored_options);
+
+  type_explicit = false;
+
+  optimize = 0;
+  optimize_size = 0;
+
+  stack_limit_rtx = NULL_RTX;
+}


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