diff mbox

Negative option alias facility

Message ID Pine.LNX.4.64.1103301302090.17837@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers March 30, 2011, 1:03 p.m. UTC
This patch adds a NegativeAlias .opt facility, for one option to be
marked as an alias for the negative form of another option.  There are
quite a lot of options like that, and this is of particular use where
it allows option handler code to be removed because the aliases can
now be handled purely in the .opt file (as opposed to the case where
both positive and negative options are fully described by their Var
settings).

In particular, this patch also converts the legacy rs6000 options
-mvrsave=, -misel=, -mspe= to aliases for the standard forms of the
options (via listing the =yes and =no forms of each option as separate
aliases), so simplifying the rs6000 option handling code.

Bootstrapped with no regressions on x86_64-unknown-linux-gnu, and
tested building cc1 and xgcc for cross to powerpc-eabispe.  Will
commit to trunk in the absence of target maintainer objections.

2011-03-30  Joseph Myers  <joseph@codesourcery.com>

	* doc/options.texi (NegativeAlias): Document.
	(Alias): Mention NegativeAlias.
	* opt-functions.awk: Handle NegativeAlias.
	* optc-gen.awk: Disallow NegativeAlias with multiple Alias
	arguments.
	* opts-common.c (decode_cmdline_option): Handle CL_NEGATIVE_ALIAS.
	* opts.h (CL_NEGATIVE_ALIAS): Define.
	* config/rs6000/rs6000.c (rs6000_parse_yes_no_option): Remove.
	(rs6000_handle_option): Don't handle OPT_mvrsave_, OPT_misel_ and
	OPT_mspe_.
	* config/rs6000/rs6000.opt (mvrsave=, misel=, mspe=): Replace with
	Alias entries.
	* config/rs6000/t-spe (MULTILIB_OPTIONS, MULTILIB_EXCEPTIONS): Use
	mno-spe and mno-isel instead of mspe=no and -misel=no.
diff mbox

Patch

Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi	(revision 171701)
+++ gcc/doc/options.texi	(working copy)
@@ -364,7 +364,8 @@  for later processing.
 @item Alias(@var{opt})
 @itemx Alias(@var{opt}, @var{arg})
 @itemx Alias(@var{opt}, @var{posarg}, @var{negarg})
-The option is an alias for @option{-@var{opt}}.  In the first form,
+The option is an alias for @option{-@var{opt}} (or the negative form
+of that option, depending on @code{NegativeAlias}).  In the first form,
 any argument passed to the alias is considered to be passed to
 @option{-@var{opt}}, and @option{-@var{opt}} is considered to be
 negated if the alias is used in negated form.  In the second form, the
@@ -387,6 +388,13 @@  not need to handle it and no @samp{OPT_}
 for it; only the canonical form of the option will be seen in those
 places.
 
+@item NegativeAlias
+For an option marked with @code{Alias(@var{opt})}, the option is
+considered to be an alias for the positive form of @option{-@var{opt}}
+if negated and for the negative form of @option{-@var{opt}} if not
+negated.  @code{NegativeAlias} may not be used with the forms of
+@code{Alias} taking more than one argument.
+
 @item Ignore
 This option is ignored apart from printing any warning specified using
 @code{Warn}.  The option will not be seen by specs and no @samp{OPT_}
Index: gcc/opts-common.c
===================================================================
--- gcc/opts-common.c	(revision 171701)
+++ gcc/opts-common.c	(working copy)
@@ -507,6 +507,7 @@  decode_cmdline_option (const char **argv
 	    {
 	      gcc_assert (option->alias_arg != NULL);
 	      gcc_assert (arg == NULL);
+	      gcc_assert (!(option->flags & CL_NEGATIVE_ALIAS));
 	      if (value)
 		arg = option->alias_arg;
 	      else
@@ -517,9 +518,13 @@  decode_cmdline_option (const char **argv
 	    {
 	      gcc_assert (value == 1);
 	      gcc_assert (arg == NULL);
+	      gcc_assert (!(option->flags & CL_NEGATIVE_ALIAS));
 	      arg = option->alias_arg;
 	    }
 
+	  if (option->flags & CL_NEGATIVE_ALIAS)
+	    value = !value;
+
 	  opt_index = new_opt_index;
 	  option = new_option;
 
Index: gcc/opts.h
===================================================================
--- gcc/opts.h	(revision 171701)
+++ gcc/opts.h	(working copy)
@@ -115,6 +115,7 @@  extern const unsigned int cl_lang_count;
 #define CL_MISSING_OK		(1U << 28) /* Missing argument OK (joined).  */
 #define CL_UINTEGER		(1U << 29) /* Argument is an integer >=0.  */
 #define CL_UNDOCUMENTED		(1U << 30) /* Do not output with --help.  */
+#define CL_NEGATIVE_ALIAS	(1U << 31) /* Alias to negative form of option.  */
 
 /* Flags for an enumerated option argument.  */
 #define CL_ENUM_CANONICAL	(1 << 0) /* Canonical for this value.  */
Index: gcc/optc-gen.awk
===================================================================
--- gcc/optc-gen.awk	(revision 171701)
+++ gcc/optc-gen.awk	(working copy)
@@ -362,6 +362,11 @@  for (i = 0; i < n_opts; i++) {
 				print "#error Alias with single argument " \
 					"allowing negative form"
 		}
+		if (alias_posarg != "" \
+		    && flag_set_p("NegativeAlias", flags[i])) {
+			print "#error Alias with multiple arguments " \
+				"used with NegativeAlias"
+		}
 
 		alias_opt = opt_enum(alias_opt)
 		if (alias_posarg == "")
Index: gcc/opt-functions.awk
===================================================================
--- gcc/opt-functions.awk	(revision 171701)
+++ gcc/opt-functions.awk	(working copy)
@@ -1,4 +1,4 @@ 
-#  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010
+#  Copyright (C) 2003, 2004, 2007, 2008, 2009, 2010, 2011
 #  Free Software Foundation, Inc.
 #  Contributed by Kelley Cook, June 2004.
 #  Original code from Neil Booth, May 2003.
@@ -90,6 +90,7 @@  function switch_flags (flags)
 	  test_flag("RejectDriver", flags, " | CL_REJECT_DRIVER") \
 	  test_flag("NoDriverArg", flags, " | CL_NO_DRIVER_ARG") \
 	  test_flag("SeparateAlias", flags, " | CL_SEPARATE_ALIAS") \
+	  test_flag("NegativeAlias", flags, " | CL_NEGATIVE_ALIAS") \
 	  test_flag("Save", flags, " | CL_SAVE") \
 	  test_flag("Joined", flags, " | CL_JOINED") \
 	  test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
Index: gcc/config/rs6000/t-spe
===================================================================
--- gcc/config/rs6000/t-spe	(revision 171701)
+++ gcc/config/rs6000/t-spe	(working copy)
@@ -1,6 +1,6 @@ 
 # Multilibs for e500
 #
-# Copyright (C) 2003 Free Software Foundation, Inc.
+# Copyright (C) 2003, 2011 Free Software Foundation, Inc.
 #
 # This file is part of GCC.
 #
@@ -36,51 +36,51 @@  INSTALL_LIBGCC = install-multilib
 #	-mcpu=7400 -maltivec -mabi=altivec
 #	-mcpu=7400 -msoft-float
 #	-msoft-float
-#	-mspe=no -mabi=no-spe -misel=no
+#	-mno-spe -mabi=no-spe -mno-isel
 # so we'll need to create exceptions later below.
 
 MULTILIB_OPTIONS	= mcpu=7400 \
 			  maltivec \
 			  mabi=altivec \
 			  msoft-float \
-			  mspe=no \
+			  mno-spe \
 			  mabi=no-spe \
-			  misel=no \
+			  mno-isel \
 			  mlittle
 
 MULTILIB_DIRNAMES	= mpc7400 altivec abi-altivec \
 			  nof no-spe no-abi-spe no-isel le
 
-MULTILIB_EXCEPTIONS	= maltivec mabi=altivec mspe=no mabi=no-spe misel=no \
+MULTILIB_EXCEPTIONS	= maltivec mabi=altivec mno-spe mabi=no-spe mno-isel \
 			  maltivec/mabi=altivec \
 			  mcpu=7400/maltivec \
 			  mcpu=7400/mabi=altivec \
-			  *mcpu=7400/*mspe=no* \
+			  *mcpu=7400/*mno-spe* \
 			  *mcpu=7400/*mabi=no-spe* \
-			  *mcpu=7400/*misel=no* \
+			  *mcpu=7400/*mno-isel* \
 			  *maltivec/*msoft-float* \
-			  *maltivec/*mspe=no* \
+			  *maltivec/*mno-spe* \
 			  *maltivec/*mabi=no-spe* \
-			  *maltivec/*misel=no* \
+			  *maltivec/*mno-isel* \
 			  *mabi=altivec/*msoft-float* \
-			  *mabi=altivec/*mspe=no* \
+			  *mabi=altivec/*mno-spe* \
 			  *mabi=altivec/*mabi=no-spe* \
-			  *mabi=altivec/*misel=no* \
-			  *msoft-float/*mspe=no* \
+			  *mabi=altivec/*mno-isel* \
+			  *msoft-float/*mno-spe* \
 			  *msoft-float/*mabi=no-spe* \
-			  *msoft-float/*misel=no* \
-			  mspe=no/mabi=no-spe \
-			  mspe=no/misel=no \
-			  mabi=no-spe/misel=no \
-			  misel=no/mlittle \
-			  mabi=no-spe/misel=no/mlittle \
-			  mspe=no/mlittle \
+			  *msoft-float/*mno-isel* \
+			  mno-spe/mabi=no-spe \
+			  mno-spe/mno-isel \
+			  mabi=no-spe/mno-isel \
+			  mno-isel/mlittle \
+			  mabi=no-spe/mno-isel/mlittle \
+			  mno-spe/mlittle \
 			  mabi=spe/mlittle \
 			  mcpu=7400/mabi=altivec/mlittle \
 			  mcpu=7400/maltivec/mlittle \
 			  mabi=no-spe/mlittle \
-			  mspe=no/misel=no/mlittle \
-			  mspe=no/mabi=no-spe/mlittle \
+			  mno-spe/mno-isel/mlittle \
+			  mno-spe/mabi=no-spe/mlittle \
 			  mabi=altivec/mlittle \
 			  maltivec/mlittle \
 			  maltivec/mabi=altivec/mlittle
Index: gcc/config/rs6000/rs6000.opt
===================================================================
--- gcc/config/rs6000/rs6000.opt	(revision 171701)
+++ gcc/config/rs6000/rs6000.opt	(working copy)
@@ -1,6 +1,6 @@ 
 ; Options for the rs6000 port of the compiler
 ;
-; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
 ; Foundation, Inc.
 ; Contributed by Aldy Hernandez <aldy@quesejoda.com>.
 ;
@@ -353,9 +353,13 @@  mvrsave
 Target Report Var(TARGET_ALTIVEC_VRSAVE) Save
 Generate VRSAVE instructions when generating AltiVec code
 
-mvrsave=
-Target RejectNegative Joined
--mvrsave=yes/no	Deprecated option.  Use -mvrsave/-mno-vrsave instead
+mvrsave=no
+Target RejectNegative Alias(mvrsave) NegativeAlias
+Deprecated option.  Use -mno-vrsave instead
+
+mvrsave=yes
+Target RejectNegative Alias(mvrsave)
+Deprecated option.  Use -mvrsave instead
 
 mblock-move-inline-limit=
 Target Report Var(rs6000_block_move_inline_limit) Init(0) RejectNegative Joined UInteger Save
@@ -365,9 +369,13 @@  misel
 Target Report Mask(ISEL) Save
 Generate isel instructions
 
-misel=
-Target RejectNegative Joined
--misel=yes/no	Deprecated option.  Use -misel/-mno-isel instead
+misel=no
+Target RejectNegative Alias(misel) NegativeAlias
+Deprecated option.  Use -mno-isel instead
+
+misel=yes
+Target RejectNegative Alias(misel)
+Deprecated option.  Use -misel instead
 
 mspe
 Target
@@ -377,9 +385,13 @@  mpaired
 Target Var(rs6000_paired_float) Save
 Generate PPC750CL paired-single instructions
 
-mspe=
-Target RejectNegative Joined
--mspe=yes/no	Deprecated option.  Use -mspe/-mno-spe instead
+mspe=no
+Target RejectNegative Alias(mspe) NegativeAlias
+Deprecated option.  Use -mno-spe instead
+
+mspe=yes
+Target RejectNegative Alias(mspe)
+Deprecated option.  Use -mspe instead
 
 mdebug=
 Target RejectNegative Joined
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	(revision 171701)
+++ gcc/config/rs6000/rs6000.c	(working copy)
@@ -1082,7 +1082,6 @@  static bool rs6000_handle_option (struct
 				  const struct cl_decoded_option *,
 				  location_t);
 static int rs6000_loop_align_max_skip (rtx);
-static void rs6000_parse_yes_no_option (const char *, const char *, int *);
 static int first_altivec_reg_to_save (void);
 static unsigned int compute_vrsave_mask (void);
 static void compute_save_world_info (rs6000_stack_t *info_ptr);
@@ -3820,24 +3819,6 @@  rs6000_preferred_simd_mode (enum machine
   return word_mode;
 }
 
-/* Handle generic options of the form -mfoo=yes/no.
-   NAME is the option name.
-   VALUE is the option value.
-   FLAG is the pointer to the flag where to store a 1 or 0, depending on
-   whether the option value is 'yes' or 'no' respectively.  */
-static void
-rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
-{
-  if (value == 0)
-    return;
-  else if (!strcmp (value, "yes"))
-    *flag = 1;
-  else if (!strcmp (value, "no"))
-    *flag = 0;
-  else
-    error ("unknown -m%s= option specified: '%s'", name, value);
-}
-
 /* Implement TARGET_OPTION_INIT_STRUCT.  */
 
 static void
@@ -4337,31 +4318,11 @@  rs6000_handle_option (struct gcc_options
       TARGET_ALTIVEC_VRSAVE = value;
       break;
 
-    case OPT_mvrsave_:
-      rs6000_explicit_options.vrsave = true;
-      rs6000_parse_yes_no_option ("vrsave", arg, &(TARGET_ALTIVEC_VRSAVE));
-      break;
-
-    case OPT_misel_:
-      target_flags_explicit |= MASK_ISEL;
-      isel = 0;
-      rs6000_parse_yes_no_option ("isel", arg, &isel);
-      if (isel)
-	target_flags |= MASK_ISEL;
-      else
-	target_flags &= ~MASK_ISEL;
-      break;
-
     case OPT_mspe:
       rs6000_explicit_options.spe = true;
       rs6000_spe = value;
       break;
 
-    case OPT_mspe_:
-      rs6000_explicit_options.spe = true;
-      rs6000_parse_yes_no_option ("spe", arg, &(rs6000_spe));
-      break;
-
     case OPT_mdebug_:
       p = ASTRDUP (arg);
       rs6000_debug = 0;