Patchwork [4.7] Avoid global state in iq2000_handle_option

login
register
mail settings
Submitter Joseph S. Myers
Date March 4, 2011, 3:41 a.m.
Message ID <Pine.LNX.4.64.1103040340360.6189@digraph.polyomino.org.uk>
Download mbox | patch
Permalink /patch/85362/
State New
Headers show

Comments

Joseph S. Myers - March 4, 2011, 3:41 a.m.
This patch, for 4.7 and relative to a tree with
<http://gcc.gnu.org/ml/gcc-patches/2011-02/msg01709.html> applied,
stops the IQ2000 handle_option hook from using global state.  Because
all the hook did was handle fixed sets of arguments to particular
options (setting a variable for one, ignoring the other), the handling
is converted to use the Enum .opt failure, with a .opt Variable entry
for the variable the code previously set.  In the case of the -march=
option, whose arguments were checked but otherwise ignored, Enum is
used without Var (a valid, if unusual, combination of .opt features)
so that the option continues to check but otherwise ignore its
argument.

Tested building cc1 and xgcc for cross to iq2000-elf.  Will commit to
trunk for 4.7 in the absence of target maintainer objections.

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

	* config/iq2000/iq2000-opts.h: New.
	* config/iq2000/iq2000.c: Don't include opts.h.
	(iq2000_tune, iq2000_handle_option, TARGET_HANDLE_OPTION): Remove.
	* config/iq2000/iq2000.h (enum processor_type, iq2000_tune):
	Remove.
	* config/iq2000/iq2000.opt (config/iq2000/iq2000-opts.h): New
	HeaderInclude entry.
	(iq2000_tune): New Variable entry.
	(march=): Add comment.  Use Enum.
	(iq2000_arch): New Enum and EnumValue entries.
	(mcpu=): Use Enum and Var.
	(iq2000_tune): New Enum and EnumValue entries.
Nick Clifton - March 4, 2011, 12:56 p.m.
Hi Joseph,

> Tested building cc1 and xgcc for cross to iq2000-elf.  Will commit to
> trunk for 4.7 in the absence of target maintainer objections.

No objections - please commit.

Cheers
   Nick

Patch

diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/iq2000/iq2000-opts.h gcc-mainline/gcc/config/iq2000/iq2000-opts.h
--- gcc-mainline-1/gcc/config/iq2000/iq2000-opts.h	1969-12-31 16:00:00.000000000 -0800
+++ gcc-mainline/gcc/config/iq2000/iq2000-opts.h	2011-03-03 10:20:14.000000000 -0800
@@ -0,0 +1,33 @@ 
+/* Definitions for option handling for Vitesse IQ2000 processors.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   Free Software Foundation, Inc.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef IQ2000_OPTS_H
+#define IQ2000_OPTS_H
+
+/* Which processor to schedule for.  */
+
+enum processor_type
+{
+  PROCESSOR_DEFAULT,
+  PROCESSOR_IQ2000,
+  PROCESSOR_IQ10
+};
+
+#endif
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/iq2000/iq2000.c gcc-mainline/gcc/config/iq2000/iq2000.c
--- gcc-mainline-1/gcc/config/iq2000/iq2000.c	2011-02-23 15:50:10.000000000 -0800
+++ gcc-mainline/gcc/config/iq2000/iq2000.c	2011-03-03 10:27:50.000000000 -0800
@@ -45,7 +45,6 @@  along with GCC; see the file COPYING3.  
 #include "target-def.h"
 #include "langhooks.h"
 #include "df.h"
-#include "opts.h"
 
 /* Enumeration for all of the relational tests, so that we can build
    arrays indexed by the test type, and not worry about the order
@@ -112,9 +111,6 @@  struct GTY(()) machine_function
 /* List of all IQ2000 punctuation characters used by iq2000_print_operand.  */
 static char iq2000_print_operand_punct[256];
 
-/* The target cpu for optimization and scheduling.  */
-enum processor_type iq2000_tune;
-
 /* Which instruction set architecture to use.  */
 int iq2000_isa;
 
@@ -146,10 +142,6 @@  static enum machine_mode gpr_mode;
 
 /* Initialize the GCC target structure.  */
 static struct machine_function* iq2000_init_machine_status (void);
-static bool iq2000_handle_option      (struct gcc_options *,
-				       struct gcc_options *,
-				       const struct cl_decoded_option *,
-				       location_t);
 static void iq2000_option_override    (void);
 static section *iq2000_select_rtx_section (enum machine_mode, rtx,
 					   unsigned HOST_WIDE_INT);
@@ -197,8 +189,6 @@  static const struct default_options iq20
 #define TARGET_EXPAND_BUILTIN 		iq2000_expand_builtin
 #undef  TARGET_ASM_SELECT_RTX_SECTION
 #define TARGET_ASM_SELECT_RTX_SECTION	iq2000_select_rtx_section
-#undef  TARGET_HANDLE_OPTION
-#define TARGET_HANDLE_OPTION		iq2000_handle_option
 #undef  TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE		iq2000_option_override
 #undef  TARGET_OPTION_OPTIMIZATION_TABLE
@@ -1438,41 +1428,6 @@  iq2000_init_machine_status (void)
   return ggc_alloc_cleared_machine_function ();
 }
 
-/* Implement TARGET_HANDLE_OPTION.  */
-
-static bool
-iq2000_handle_option (struct gcc_options *opts, struct gcc_options *opts_set,
-		      const struct cl_decoded_option *decoded,
-		      location_t loc ATTRIBUTE_UNUSED)
-{
-  size_t code = decoded->opt_index;
-  const char *arg = decoded->arg;
-
-  gcc_assert (opts == &global_options);
-  gcc_assert (opts_set == &global_options_set);
-
-  switch (code)
-    {
-    case OPT_mcpu_:
-      if (strcmp (arg, "iq10") == 0)
-	iq2000_tune = PROCESSOR_IQ10;
-      else if (strcmp (arg, "iq2000") == 0)
-	iq2000_tune = PROCESSOR_IQ2000;
-      else
-	return false;
-      return true;
-
-    case OPT_march_:
-      /* This option has no effect at the moment.  */
-      return (strcmp (arg, "default") == 0
-	      || strcmp (arg, "DEFAULT") == 0
-	      || strcmp (arg, "iq2000") == 0);
-
-    default:
-      return true;
-    }
-}
-
 /* Detect any conflicts in the switches.  */
 
 static void
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/iq2000/iq2000.h gcc-mainline/gcc/config/iq2000/iq2000.h
--- gcc-mainline-1/gcc/config/iq2000/iq2000.h	2011-02-15 12:55:19.000000000 -0800
+++ gcc-mainline/gcc/config/iq2000/iq2000.h	2011-03-03 10:20:07.000000000 -0800
@@ -1,6 +1,6 @@ 
 /* Definitions of target machine for GNU compiler.  
    Vitesse IQ2000 processors
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    This file is part of GCC.
@@ -609,15 +609,6 @@  enum delay_type
   DELAY_FCMP				/* Delay after doing c.<xx>.{d,s}.  */
 };
 
-/* Which processor to schedule for.  */
-
-enum processor_type
-{
-  PROCESSOR_DEFAULT,
-  PROCESSOR_IQ2000,
-  PROCESSOR_IQ10
-};
-
 /* Recast the cpu class to be the cpu attribute.  */
 #define iq2000_cpu_attr ((enum attr_cpu) iq2000_tune)
 
@@ -850,9 +841,6 @@  enum processor_type
 #define SDATA_SECTION_ASM_OP	"\t.sdata"	/* Small data.  */
 
 
-/* The target cpu for optimization and scheduling.  */
-extern enum processor_type iq2000_tune;
-
 /* Which instruction set architecture to use.  */
 extern int iq2000_isa;
 
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/iq2000/iq2000.opt gcc-mainline/gcc/config/iq2000/iq2000.opt
--- gcc-mainline-1/gcc/config/iq2000/iq2000.opt	2009-03-28 00:38:25.000000000 -0700
+++ gcc-mainline/gcc/config/iq2000/iq2000.opt	2011-03-03 10:26:58.000000000 -0800
@@ -1,6 +1,6 @@ 
 ; Options for the Vitesse IQ2000 port of the compiler.
 
-; Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+; Copyright (C) 2005, 2007, 2011 Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
 ;
@@ -18,14 +18,44 @@ 
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
 
+HeaderInclude
+config/iq2000/iq2000-opts.h
+
+; The target cpu for optimization and scheduling.
+Variable
+enum processor_type iq2000_tune
+
+; This option has no effect at the moment.
 march=
-Target RejectNegative Joined
+Target RejectNegative Joined Enum(iq2000_arch)
 Specify CPU for code generation purposes
 
+Enum
+Name(iq2000_arch) Type(int)
+
+EnumValue
+Enum(iq2000_arch) String(default) Value(0)
+
+EnumValue
+Enum(iq2000_arch) String(DEFAULT) Value(0)
+
+EnumValue
+Enum(iq2000_arch) String(iq2000) Value(0)
+
 mcpu=
-Target RejectNegative Joined
+Target RejectNegative Joined Enum(iq2000_tune) Var(iq2000_tune)
 Specify CPU for scheduling purposes
 
+Enum
+Name(iq2000_tune) Type(enum processor_type)
+Known IQ2000 CPUs (for use with the -mcpu= option):
+
+EnumValue
+Enum(iq2000_tune) String(iq10) Value(PROCESSOR_IQ10)
+
+EnumValue
+Enum(iq2000_tune) String(iq2000) Value(PROCESSOR_IQ2000)
+
 membedded-data
 Target Mask(EMBEDDED_DATA)
 Use ROM instead of RAM