diff mbox

[4.7] Avoid global state in frv_handle_option

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

Commit Message

Joseph Myers March 3, 2011, 2:45 a.m. UTC
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 FR-V handle_option hook from using global state.  Because
all the hook did was check for a fixed set of possible arguments to
-mcpu= and convert them to enumeration values, the relevant variable
is moved to a .opt Variable entry, the -mcpu handling is made to use
the Enum feature and the hook is completely removed as no longer
needed.  A help text "Known FR-V CPUs (for use with the -mcpu=
option):" is added on the Enum entry, so that the possible -mcpu
values will now be listed in --help output.

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

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

	* config/frv/frv-opts.h: New.
	* config/frv/frv-protos.h (enum frv_cpu, frv_cpu_t): Move to
	frv-opts.h.
	(frv_cpu_type): Remove.
	* config/frv/frv.c: Don't include opts.h.
	(frv_cpu_type, frv_handle_option, TARGET_HANDLE_OPTION): Remove.
	* config/frv/frv.opt (config/frv/frv-opts.h): New HeaderInclude
	entry.
	(frv_cpu_type): New Variable entry.
	(frv_cpu): New Enum and EnumValue entries.

Comments

Nick Clifton March 3, 2011, 9:17 a.m. UTC | #1
Hi Joseph,

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

No objections.  In fact I am happy to see the patch applied.

Cheers
   Nick
diff mbox

Patch

diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/frv/frv-opts.h gcc-mainline/gcc/config/frv/frv-opts.h
--- gcc-mainline-1/gcc/config/frv/frv-opts.h	1969-12-31 16:00:00.000000000 -0800
+++ gcc-mainline/gcc/config/frv/frv-opts.h	2011-03-02 13:05:23.000000000 -0800
@@ -0,0 +1,39 @@ 
+/* Frv option-handling defitions.
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 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 FRV_OPTS_H
+#define FRV_OPTS_H
+
+/* CPU type.  This must be identical to the cpu enumeration in frv.md.  */
+typedef enum frv_cpu
+{
+  FRV_CPU_GENERIC,
+  FRV_CPU_FR550,
+  FRV_CPU_FR500,
+  FRV_CPU_FR450,
+  FRV_CPU_FR405,
+  FRV_CPU_FR400,
+  FRV_CPU_FR300,
+  FRV_CPU_SIMPLE,
+  FRV_CPU_TOMCAT
+} frv_cpu_t;
+
+#endif
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/frv/frv-protos.h gcc-mainline/gcc/config/frv/frv-protos.h
--- gcc-mainline-1/gcc/config/frv/frv-protos.h	2010-11-22 05:28:24.000000000 -0800
+++ gcc-mainline/gcc/config/frv/frv-protos.h	2011-03-02 13:05:52.000000000 -0800
@@ -1,5 +1,6 @@ 
 /* Frv prototypes.
-   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
+   2011
    Free Software Foundation, Inc.
    Contributed by Red Hat, Inc.
 
@@ -19,22 +20,6 @@  You should have received a copy of the G
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-/* CPU type.  This must be identical to the cpu enumeration in frv.md.  */
-typedef enum frv_cpu
-{
-  FRV_CPU_GENERIC,
-  FRV_CPU_FR550,
-  FRV_CPU_FR500,
-  FRV_CPU_FR450,
-  FRV_CPU_FR405,
-  FRV_CPU_FR400,
-  FRV_CPU_FR300,
-  FRV_CPU_SIMPLE,
-  FRV_CPU_TOMCAT
-} frv_cpu_t;
-
-extern frv_cpu_t frv_cpu_type;			/* value of -mcpu= */
-
 /* Define functions defined in frv.c */
 extern void frv_expand_prologue			(void);
 extern void frv_expand_epilogue			(bool);
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/frv/frv.c gcc-mainline/gcc/config/frv/frv.c
--- gcc-mainline-1/gcc/config/frv/frv.c	2011-02-23 14:54:12.000000000 -0800
+++ gcc-mainline/gcc/config/frv/frv.c	2011-03-02 13:13:37.000000000 -0800
@@ -49,7 +49,6 @@  along with GCC; see the file COPYING3.  
 #include "integrate.h"
 #include "langhooks.h"
 #include "df.h"
-#include "opts.h"
 
 #ifndef FRV_INLINE
 #define FRV_INLINE inline
@@ -256,15 +255,8 @@  enum reg_class regno_reg_class[FIRST_PSE
 /* Cached value of frv_stack_info.  */
 static frv_stack_t *frv_stack_cache = (frv_stack_t *)0;
 
-/* -mcpu= support */
-frv_cpu_t frv_cpu_type = CPU_TYPE;	/* value of -mcpu= */
-
 /* Forward references */
 
-static bool frv_handle_option			(struct gcc_options *,
-						 struct gcc_options *,
-						 const struct cl_decoded_option *,
-						 location_t);
 static void frv_option_override			(void);
 static bool frv_legitimate_address_p		(enum machine_mode, rtx, bool);
 static int frv_default_flags_for_cpu		(void);
@@ -444,8 +436,6 @@  static const struct default_options frv_
    | MASK_VLIW_BRANCH				\
    | MASK_MULTI_CE				\
    | MASK_NESTED_CE)
-#undef TARGET_HANDLE_OPTION
-#define TARGET_HANDLE_OPTION frv_handle_option
 #undef TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE frv_option_override
 #undef TARGET_OPTION_OPTIMIZATION_TABLE
@@ -631,49 +621,6 @@  frv_cannot_force_const_mem (rtx x ATTRIB
   return TARGET_FDPIC;
 }
 
-/* Implement TARGET_HANDLE_OPTION.  */
-
-static bool
-frv_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, "simple") == 0)
-	frv_cpu_type = FRV_CPU_SIMPLE;
-      else if (strcmp (arg, "tomcat") == 0)
-	frv_cpu_type = FRV_CPU_TOMCAT;
-      else if (strcmp (arg, "fr550") == 0)
-	frv_cpu_type = FRV_CPU_FR550;
-      else if (strcmp (arg, "fr500") == 0)
-	frv_cpu_type = FRV_CPU_FR500;
-      else if (strcmp (arg, "fr450") == 0)
-	frv_cpu_type = FRV_CPU_FR450;
-      else if (strcmp (arg, "fr405") == 0)
-	frv_cpu_type = FRV_CPU_FR405;
-      else if (strcmp (arg, "fr400") == 0)
-	frv_cpu_type = FRV_CPU_FR400;
-      else if (strcmp (arg, "fr300") == 0)
-	frv_cpu_type = FRV_CPU_FR300;
-      else if (strcmp (arg, "frv") == 0)
-	frv_cpu_type = FRV_CPU_GENERIC;
-      else
-	return false;
-      return true;
-
-    default:
-      return true;
-    }
-}
-
 static int
 frv_default_flags_for_cpu (void)
 {
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/frv/frv.opt gcc-mainline/gcc/config/frv/frv.opt
--- gcc-mainline-1/gcc/config/frv/frv.opt	2009-03-28 00:38:00.000000000 -0700
+++ gcc-mainline/gcc/config/frv/frv.opt	2011-03-02 13:26:47.000000000 -0800
@@ -1,6 +1,6 @@ 
 ; Options for the FR-V 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,6 +18,13 @@ 
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
 
+HeaderInclude
+config/frv/frv-opts.h
+
+; Value of -mcpu=.
+Variable
+frv_cpu_t frv_cpu_type = CPU_TYPE
+
 macc-4
 Target Report RejectNegative Mask(ACC_4)
 Use 4 media accumulators
@@ -58,9 +65,40 @@  Target Report Mask(COND_MOVE)
 Enable conditional moves
 
 mcpu=
-Target RejectNegative Joined
+Target RejectNegative Joined Enum(frv_cpu) Var(frv_cpu_type)
 Set the target CPU type
 
+Enum
+Name(frv_cpu) Type(frv_cpu_t)
+Known FR-V CPUs (for use with the -mcpu= option):
+
+EnumValue
+Enum(frv_cpu) String(simple) Value(FRV_CPU_SIMPLE)
+
+EnumValue
+Enum(frv_cpu) String(tomcat) Value(FRV_CPU_TOMCAT)
+
+EnumValue
+Enum(frv_cpu) String(fr550) Value(FRV_CPU_FR550)
+
+EnumValue
+Enum(frv_cpu) String(fr500) Value(FRV_CPU_FR500)
+
+EnumValue
+Enum(frv_cpu) String(fr450) Value(FRV_CPU_FR450)
+
+EnumValue
+Enum(frv_cpu) String(fr405) Value(FRV_CPU_FR405)
+
+EnumValue
+Enum(frv_cpu) String(fr400) Value(FRV_CPU_FR400)
+
+EnumValue
+Enum(frv_cpu) String(fr300) Value(FRV_CPU_FR300)
+
+EnumValue
+Enum(frv_cpu) String(frv) Value(FRV_CPU_GENERIC)
+
 mdebug
 Target Undocumented Var(TARGET_DEBUG)