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]

RFA: Check PCH state of all target options


This patch follows on from:

    http://gcc.gnu.org/ml/gcc-patches/2005-05/msg02594.html
    http://gcc.gnu.org/ml/gcc-patches/2005-05/msg02686.html

The second of the above messages said:

    This patch makes the PCH validity routines check every target .opt
    option with a Var(), Mask() or InverseMask() flag.  Once that's done,
    the next step will be to make sure that every target option is treated
    as if it had such a flag, with the options scripts attaching a static
    variable to options that don't otherwise meet the criteria.  We'll
    then be back to where we were before the whole .opt thing started.

This is the patch to do that.  It adds a new opt-functions.awk
function, needs_state_p, to say whether a variable must have a
state variable attached to it.  At present, this function just
returns true for Target options.  If an option doesn't have a
global state (if the new global_state_p function returns false),
the options scripts will add a local variable for it instead.
This works for all types of options: booleans, integers and
strings.

Like I said in the quote above, this brings us back to the
pre-.opt situation, in which every target option was checked.
That's my main goal at the moment and I think it completes the
.opt transition.  I went on to say:

    Once _that's_ done, it might be worth adding some sort of flag
    to say whether an option affects PCH or not.  But I'd like to
    discuss that separately.

I still think it's best to do that separately.  I have no specific need
for it myself, so I doubt I'll do it in the short term.  This patch does
make it easier to implement such a flag later though.

Tested by bootstrapping & regression testing on i686-pc-linux-gnu.
Also tested on mips-elf and mipsisa64-elf.  I checked that the PCH
routines now check MIPS options like -mabi= and -mips, which they
didn't before the patch.  OK to install?

Richard


	* opt-functions.awk (global_state_p, needs_state_p, static_var): New.
	(var_ref): Take the option's flags as a second parameter.  Check
	static_var.
	* optc-gen.awk: Declare local state variables.  Pass flags to var_ref.

Index: opt-functions.awk
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opt-functions.awk,v
retrieving revision 2.6
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.6 opt-functions.awk
--- opt-functions.awk	26 May 2005 05:27:27 -0000	2.6
+++ opt-functions.awk	12 Jun 2005 18:13:24 -0000
@@ -89,6 +89,32 @@ function var_name(flags)
 	return nth_arg(0, opt_args("Var", flags))
 }
 
+# Return true if the option described by FLAGS has a globally-visible state.
+function global_state_p(flags)
+{
+	return (var_name(flags) != "" \
+		|| opt_args("Mask", flags) != "" \
+		|| opt_args("InverseMask", flags) != "")
+}
+
+# Return true if the option described by FLAGS must have some state
+# associated with it.
+function needs_state_p(flags)
+{
+	return flag_set_p("Target", flags)
+}
+
+# If FLAGS describes an option that needs a static state variable,
+# return the name of that variable, otherwise return "".  NAME is
+# the name of the option.
+function static_var(name, flags)
+{
+	if (global_state_p(flags) || !needs_state_p(flags))
+		return ""
+	gsub ("[^A-Za-z0-9]", "_", name)
+	return "VAR_" name
+}
+
 # Return the type of variable that should be associated with the given flags.
 function var_type(flags)
 {
@@ -128,11 +154,11 @@ function var_set(flags)
 	return "CLVC_BOOLEAN, 0"
 }
 
-# Given that an option has flags FLAGS, return an initializer for the
-# "flag_var" field of its cl_options[] entry.
-function var_ref(flags)
+# Given that an option called NAME has flags FLAGS, return an initializer
+# for the "flag_var" field of its cl_options[] entry.
+function var_ref(name, flags)
 {
-	name = var_name(flags)
+	name = var_name(flags) static_var(name, flags)
 	if (name != "")
 		return "&" name
 	if (opt_args("Mask", flags) != "")
Index: optc-gen.awk
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optc-gen.awk,v
retrieving revision 2.9
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.9 optc-gen.awk
--- optc-gen.awk	26 May 2005 05:27:27 -0000	2.9
+++ optc-gen.awk	12 Jun 2005 18:13:24 -0000
@@ -85,6 +85,14 @@ for (i = 0; i < n_opts; i++) {
 	var_seen[name] = 1;
 }
 
+print ""
+print "/* Local state variables.  */"
+for (i = 0; i < n_opts; i++) {
+	name = static_var(opts[i], flags[i]);
+	if (name != "")
+		print "static " var_type(flags[i]) name ";"
+}
+print ""
 
 print "const char * const lang_names[] =\n{"
 for (i = 0; i < n_langs; i++) {
@@ -152,7 +160,8 @@ for (i = 0; i < n_opts; i++) {
 		       condition, cl_flags, cl_flags)
 	else
 		printf("    %s,\n", cl_flags)
-	printf("    %s, %s }%s\n", var_ref(flags[i]), var_set(flags[i]), comma)
+	printf("    %s, %s }%s\n", var_ref(opts[i], flags[i]),
+	       var_set(flags[i]), comma)
 }
 
 print "};"


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