[PATCH] Add Save/Explicit option support from function specific branch

Michael Meissner michael.meissner@amd.com
Thu Jun 5 20:56:00 GMT 2008


This patch is a rewritten patch from the function specific branch that adds the
infrastructure for declaring the options that the backend needs to save and
restore selected options.  It adds two new options 'Save' and 'Explicit' to the
*.opt files.  It also optimizes the options.h file by suppressing putting out
more than one declaration for switches that use a common mask variable.

'Save' declares which option variables need to be saved and restored.

'Explicit' adds a variable declaration <var>_explicit that can be used by the
backend to know which options were used explicitly.  Right now, the x86 port
for instance declares a variable ix86_isa_flags_explicit to hold this
information.  Having 'Explicit' will automatically save both the variable and
the explicit in the save structure.

For more detail on the Function Specific Optimization the wiki site is:
http://gcc.gnu.org/wiki/FunctionSpecificOpt

In this release, we are only doing stage 1 to add the ability to compile a
specific file with target specific options.

This particular patch is the infrastructure work only.  I bootstrapped the
compiler on x86_64-unknown-linux-gnu, and ran make check with no regressions.
Is this ok to install?

-- 
Michael Meissner, AMD
90 Central Street, MS 83-29, Boxborough, MA, 01719, USA
michael.meissner@amd.com
-------------- next part --------------
2008-06-05  Michael Meissner  <michael.meissner@amd.com>
	    Karthik Kumar  <karthikkumar@gmail.com>

	* opth-gen.awk: Add support for a 'Save' flag which says to give
	the port a way to save and preserve selected command line
	options.  Add support for an 'Explicit' flag which says to add an
	additional variable for noting when the switch has been explicitly
	set.  Do not emit the same declaration more than once.

	* optc-gen.awk: If a 'Save' flag is used, create the
	cl_options_save and cl_options_restore to save/restore the
	selected options.

	* doc/options.texi (Save): Document.
	(Explicit): Ditto.

Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi	(revision 136408)
+++ gcc/doc/options.texi	(working copy)
@@ -221,4 +221,14 @@ The option should only be accepted if pr
 option will be present even if @var{cond} is false; @var{cond} simply
 controls whether the option is accepted and whether it is printed in
 the @option{--help} output.
+
+@item Save
+Build the @code{cl_option_save} structure to hold a copy of the
+option, add the functions @code{cl_options_save} and
+@code{cl_options_restore} to save and restore the option.
+
+@item Explicit
+If the option is a @code{MASK} option, create an additional variable
+@var{var}_explicit which is available to hold whether the option was
+set explicitly or implicitly via another option.
 @end table
Index: gcc/optc-gen.awk
===================================================================
--- gcc/optc-gen.awk	(revision 136408)
+++ gcc/optc-gen.awk	(working copy)
@@ -67,7 +67,11 @@ print "int target_flags;"
 print "#endif /* GCC_DRIVER */"
 print ""
 
+have_save = 0;
 for (i = 0; i < n_opts; i++) {
+	if (flag_set_p("Save", flags[i]))
+		have_save = 1;
+
 	name = var_name(flags[i]);
 	if (name == "")
 		continue;
@@ -93,6 +97,8 @@ for (i = 0; i < n_opts; i++) {
 	print "/* Set by -" opts[i] "."
 	print "   " help[i] "  */"
 	print var_type(flags[i]) name init ";"
+	if (flag_set_p("Explicit", flags[i]))
+		print var_type(flags[i]) name "_explicit;"
 	if (gcc_driver == 1)
 		print "#endif /* GCC_DRIVER */"
 	print ""
@@ -210,4 +216,55 @@ for (i = 0; i < n_opts; i++) {
 }
 
 print "};"
+
+if (have_save) {
+	print "";
+	print "/* Save selected option variables into a structure.  */"
+	print "void";
+	print "cl_options_save (struct cl_option_save *ptr)";
+	print "{";
+
+	for (i = 0; i < n_opts; i++) {
+		if (flag_set_p("Save", flags[i])) {
+			name = var_name(flags[i]);
+			if (name == "")
+				name = "target_flags";
+
+			if (name in var_seen_save)
+				continue;
+
+			var_seen_save[name] = 1;
+			print "  ptr->" name " = " name ";";
+			if (name == "target_flags" || flag_set_p("Explicit", flags[i]))
+				print "  ptr->" name "_explicit = " name "_explicit;";
+		}
+	}
+
+	print "}";
+
+	print "";
+	print "/* Restore selected current options from a structure.  */";
+	print "void";
+	print "cl_options_restore (struct cl_option_save *ptr)";
+	print "{";
+
+	for (i = 0; i < n_opts; i++) {
+		if (flag_set_p("Save", flags[i])) {
+			name = var_name(flags[i]);
+			if (name == "")
+				name = "target_flags";
+
+			if (name in var_seen_restore)
+				continue;
+
+			var_seen_restore[name] = 1;
+			print "  " name " = ptr->" name ";";
+			if (name == "target_flags" || flag_set_p("Explicit", flags[i]))
+				print "  " name "_explicit = ptr->" name "_explicit;";
+		}
+	}
+
+	print "}";
+}
+
 }
Index: gcc/opth-gen.awk
===================================================================
--- gcc/opth-gen.awk	(revision 136408)
+++ gcc/opth-gen.awk	(working copy)
@@ -64,15 +64,61 @@ print "extern int target_flags;"
 print "extern int target_flags_explicit;"
 print ""
 
+have_save = 0;
+
 for (i = 0; i < n_opts; i++) {
+	if (flag_set_p("Save", flags[i]))
+		have_save = 1;
+
 	name = var_name(flags[i]);
 	if (name == "")
 		continue;
 
+	if (name in var_seen)
+		continue;
+
+	var_seen[name] = 1;
 	print "extern " var_type(flags[i]) name ";"
+
+	if (flag_set_p("Explicit", flags[i]) && !(name in var_explicit)) {
+	    var_explicit[name] = 1;
+	    print "extern " var_type(flags[i]) name "_explicit;";
+	}
+
 }
 print ""
 
+if (have_save) {
+	print "/* Structure to save/restore selected options.  */";
+	print "struct cl_option_save GTY(())";
+	print "{";
+
+	for (i = 0; i < n_opts; i++) {
+		if (flag_set_p("Save", flags[i])) {
+			name = var_name(flags[i])
+			if(name == "")
+				name = "target_flags";
+
+			if(name in var_save_seen)
+				continue;
+
+			var_save_seen[name] ++	
+			print "  " var_type(flags[i]) name ";";
+			if (name == "target_flags" || flag_set_p("Explicit", flags[i]))
+				print "  " var_type(flags[i]) name "_explicit;";
+		}
+	}
+
+	print "};";
+	print "";
+	print "/* Save selected option variables into a structure.  */"
+	print "extern void cl_options_save (struct cl_option_save *);";
+	print "";
+	print "/* Restore selected current options from a structure.  */";
+	print "extern void cl_options_restore (struct cl_option_save *);";
+	print "";
+}
+
 for (i = 0; i < n_opts; i++) {
 	name = opt_args("Mask", flags[i])
 	vname = var_name(flags[i])


More information about the Gcc-patches mailing list