Patchwork [4.7] Avoid global state in bfin_handle_option

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

Comments

Joseph S. Myers - March 2, 2011, 2:04 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 Blackfin handle_option hook from using global state.
bfin_lib_id_given could be replaced by use of the automatically set
global_options_set.x_bfin_library_id, while three variables were moved
to the .opt file (with bfin-opts.h being created to declare the enum
type used by one of them, as for rs6000).  The bfin_cpus array was
made static const to make clear that it is not *modifiable* global
state (and so not problematic for this function to use).  Because of
how additional information beyond a CPU name can go in a -mcpu option
for this target, the option was not a candidate for converting to the
Enum machinery and so the existing logic searching a table of CPUs is
left unchanged (apart from avoiding modifiable global state).

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

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

	* config/bfin/bfin-opts.h: New.
	* config/bfin/bfin.c (bfin_lib_id_given, bfin_cpu_type,
	bfin_si_revision, bfin_workarounds): Remove.
	(bfin_cpus): Make static const.
	(bfin_load_pic_reg): Check global_options_set.x_bfin_library_id
	not bfin_lib_id_given.
	(bfin_handle_option): Don't set bfin_lib_id_given.  Access
	bfin_cpu_type, bfin_si_revision and bfin_workarounds via opts
	pointer. Use error_at.  Don't assert that global structures are in
	use.
	* config/bfin/bfin.h: Include bfin-opts.h.
	(enum bfin_cpu_type, bfin_cpu_t): Move to bfin-opts.h.
	(bfin_cpu_type, bfin_si_revision, bfin_workarounds): Remove.
	* bfin.opt (config/bfin/bfin-opts.h): New HeaderInclude entry.
	(bfin_cpu_type, bfin_si_revision, bfin_workarounds): New Variable
	entries.

Patch

diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/bfin/bfin-opts.h gcc-mainline/gcc/config/bfin/bfin-opts.h
--- gcc-mainline-1/gcc/config/bfin/bfin-opts.h	1969-12-31 16:00:00.000000000 -0800
+++ gcc-mainline/gcc/config/bfin/bfin-opts.h	2011-03-01 17:38:13.000000000 -0800
@@ -0,0 +1,59 @@ 
+/* Definitions for the Blackfin port needed for option handling.
+   Copyright (C) 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 BFIN_OPTS_H
+#define BFIN_OPTS_H
+
+/* CPU type.  */
+typedef enum bfin_cpu_type
+{
+  BFIN_CPU_UNKNOWN,
+  BFIN_CPU_BF512,
+  BFIN_CPU_BF514,
+  BFIN_CPU_BF516,
+  BFIN_CPU_BF518,
+  BFIN_CPU_BF522,
+  BFIN_CPU_BF523,
+  BFIN_CPU_BF524,
+  BFIN_CPU_BF525,
+  BFIN_CPU_BF526,
+  BFIN_CPU_BF527,
+  BFIN_CPU_BF531,
+  BFIN_CPU_BF532,
+  BFIN_CPU_BF533,
+  BFIN_CPU_BF534,
+  BFIN_CPU_BF536,
+  BFIN_CPU_BF537,
+  BFIN_CPU_BF538,
+  BFIN_CPU_BF539,
+  BFIN_CPU_BF542,
+  BFIN_CPU_BF542M,
+  BFIN_CPU_BF544,
+  BFIN_CPU_BF544M,
+  BFIN_CPU_BF547,
+  BFIN_CPU_BF547M,
+  BFIN_CPU_BF548,
+  BFIN_CPU_BF548M,
+  BFIN_CPU_BF549,
+  BFIN_CPU_BF549M,
+  BFIN_CPU_BF561
+} bfin_cpu_t;
+
+#endif
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/bfin/bfin.c gcc-mainline/gcc/config/bfin/bfin.c
--- gcc-mainline-1/gcc/config/bfin/bfin.c	2011-02-23 14:09:21.000000000 -0800
+++ gcc-mainline/gcc/config/bfin/bfin.c	2011-03-01 17:32:46.000000000 -0800
@@ -86,9 +86,6 @@  const char *byte_reg_names[]   =  BYTE_R
 static int arg_regs[] = FUNCTION_ARG_REGISTERS;
 static int ret_regs[] = FUNCTION_RETURN_REGISTERS;
 
-/* Nonzero if -mshared-library-id was given.  */
-static int bfin_lib_id_given;
-
 /* Nonzero if -fschedule-insns2 was given.  We override it and
    call the scheduler ourselves during reorg.  */
 static int bfin_flag_schedule_insns2;
@@ -97,17 +94,6 @@  static int bfin_flag_schedule_insns2;
    reorganization.  */
 static int bfin_flag_var_tracking;
 
-/* -mcpu support */
-bfin_cpu_t bfin_cpu_type = BFIN_CPU_UNKNOWN;
-
-/* -msi-revision support. There are three special values:
-   -1      -msi-revision=none.
-   0xffff  -msi-revision=any.  */
-int bfin_si_revision;
-
-/* The workarounds enabled */
-unsigned int bfin_workarounds = 0;
-
 struct bfin_cpu
 {
   const char *name;
@@ -116,7 +102,7 @@  struct bfin_cpu
   unsigned int workarounds;
 };
 
-struct bfin_cpu bfin_cpus[] =
+static const struct bfin_cpu bfin_cpus[] =
 {
   {"bf512", BFIN_CPU_BF512, 0x0000,
    WA_SPECULATIVE_LOADS | WA_05000074},
@@ -1309,7 +1295,7 @@  bfin_load_pic_reg (rtx dest)
   if (i && i->local)
     return pic_offset_table_rtx;
       
-  if (bfin_lib_id_given)
+  if (global_options_set.x_bfin_library_id)
     addr = plus_constant (pic_offset_table_rtx, -4 - bfin_library_id * 4);
   else
     addr = gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
@@ -2559,24 +2545,21 @@  bfin_class_likely_spilled_p (reg_class_t
 /* Implement TARGET_HANDLE_OPTION.  */
 
 static bool
-bfin_handle_option (struct gcc_options *opts, struct gcc_options *opts_set,
+bfin_handle_option (struct gcc_options *opts,
+		    struct gcc_options *opts_set ATTRIBUTE_UNUSED,
 		    const struct cl_decoded_option *decoded,
-		    location_t loc ATTRIBUTE_UNUSED)
+		    location_t loc)
 {
   size_t code = decoded->opt_index;
   const char *arg = decoded->arg;
   int value = decoded->value;
 
-  gcc_assert (opts == &global_options);
-  gcc_assert (opts_set == &global_options_set);
-
   switch (code)
     {
     case OPT_mshared_library_id_:
       if (value > MAX_LIBRARY_ID)
-	error ("-mshared-library-id=%s is not between 0 and %d",
-	       arg, MAX_LIBRARY_ID);
-      bfin_lib_id_given = 1;
+	error_at (loc, "-mshared-library-id=%s is not between 0 and %d",
+		  arg, MAX_LIBRARY_ID);
       return true;
 
     case OPT_mcpu_:
@@ -2594,27 +2577,27 @@  bfin_handle_option (struct gcc_options *
 
 	if (p == NULL)
 	  {
-	    error ("-mcpu=%s is not valid", arg);
+	    error_at (loc, "-mcpu=%s is not valid", arg);
 	    return false;
 	  }
 
-	bfin_cpu_type = bfin_cpus[i].type;
+	opts->x_bfin_cpu_type = bfin_cpus[i].type;
 
 	q = arg + strlen (p);
 
 	if (*q == '\0')
 	  {
-	    bfin_si_revision = bfin_cpus[i].si_revision;
-	    bfin_workarounds |= bfin_cpus[i].workarounds;
+	    opts->x_bfin_si_revision = bfin_cpus[i].si_revision;
+	    opts->x_bfin_workarounds |= bfin_cpus[i].workarounds;
 	  }
 	else if (strcmp (q, "-none") == 0)
-	  bfin_si_revision = -1;
+	  opts->x_bfin_si_revision = -1;
       	else if (strcmp (q, "-any") == 0)
 	  {
-	    bfin_si_revision = 0xffff;
-	    while (bfin_cpus[i].type == bfin_cpu_type)
+	    opts->x_bfin_si_revision = 0xffff;
+	    while (bfin_cpus[i].type == opts->x_bfin_cpu_type)
 	      {
-		bfin_workarounds |= bfin_cpus[i].workarounds;
+		opts->x_bfin_workarounds |= bfin_cpus[i].workarounds;
 		i++;
 	      }
 	  }
@@ -2630,20 +2613,20 @@  bfin_handle_option (struct gcc_options *
 		|| si_major > 0xff || si_minor > 0xff)
 	      {
 	      invalid_silicon_revision:
-		error ("-mcpu=%s has invalid silicon revision", arg);
+		error_at (loc, "-mcpu=%s has invalid silicon revision", arg);
 		return false;
 	      }
 
-	    bfin_si_revision = (si_major << 8) | si_minor;
+	    opts->x_bfin_si_revision = (si_major << 8) | si_minor;
 
-	    while (bfin_cpus[i].type == bfin_cpu_type
-		   && bfin_cpus[i].si_revision != bfin_si_revision)
+	    while (bfin_cpus[i].type == opts->x_bfin_cpu_type
+		   && bfin_cpus[i].si_revision != opts->x_bfin_si_revision)
 	      i++;
 
-	    if (bfin_cpus[i].type != bfin_cpu_type)
+	    if (bfin_cpus[i].type != opts->x_bfin_cpu_type)
 	      goto invalid_silicon_revision;
 
-	    bfin_workarounds |= bfin_cpus[i].workarounds;
+	    opts->x_bfin_workarounds |= bfin_cpus[i].workarounds;
 	  }
 
 	return true;
@@ -2690,7 +2673,7 @@  bfin_option_override (void)
     flag_omit_frame_pointer = 1;
 
   /* Library identification */
-  if (bfin_lib_id_given && ! TARGET_ID_SHARED_LIBRARY)
+  if (global_options_set.x_bfin_library_id && ! TARGET_ID_SHARED_LIBRARY)
     error ("-mshared-library-id= specified without -mid-shared-library");
 
   if (stack_limit_rtx && TARGET_STACK_CHECK_L1)
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/bfin/bfin.h gcc-mainline/gcc/config/bfin/bfin.h
--- gcc-mainline-1/gcc/config/bfin/bfin.h	2011-01-26 16:28:20.000000000 -0800
+++ gcc-mainline/gcc/config/bfin/bfin.h	2011-03-01 17:38:43.000000000 -0800
@@ -22,54 +22,15 @@ 
 #ifndef _BFIN_CONFIG
 #define _BFIN_CONFIG
 
+#ifndef BFIN_OPTS_H
+#include "config/bfin/bfin-opts.h"
+#endif
+
 #define OBJECT_FORMAT_ELF
 
 #define BRT 1
 #define BRF 0
 
-/* CPU type.  */
-typedef enum bfin_cpu_type
-{
-  BFIN_CPU_UNKNOWN,
-  BFIN_CPU_BF512,
-  BFIN_CPU_BF514,
-  BFIN_CPU_BF516,
-  BFIN_CPU_BF518,
-  BFIN_CPU_BF522,
-  BFIN_CPU_BF523,
-  BFIN_CPU_BF524,
-  BFIN_CPU_BF525,
-  BFIN_CPU_BF526,
-  BFIN_CPU_BF527,
-  BFIN_CPU_BF531,
-  BFIN_CPU_BF532,
-  BFIN_CPU_BF533,
-  BFIN_CPU_BF534,
-  BFIN_CPU_BF536,
-  BFIN_CPU_BF537,
-  BFIN_CPU_BF538,
-  BFIN_CPU_BF539,
-  BFIN_CPU_BF542,
-  BFIN_CPU_BF542M,
-  BFIN_CPU_BF544,
-  BFIN_CPU_BF544M,
-  BFIN_CPU_BF547,
-  BFIN_CPU_BF547M,
-  BFIN_CPU_BF548,
-  BFIN_CPU_BF548M,
-  BFIN_CPU_BF549,
-  BFIN_CPU_BF549M,
-  BFIN_CPU_BF561
-} bfin_cpu_t;
-
-/* Value of -mcpu= */
-extern bfin_cpu_t bfin_cpu_type;
-
-/* Value of -msi-revision= */
-extern int bfin_si_revision;
-
-extern unsigned int bfin_workarounds;
-
 /* Print subsidiary information on the compiler version in use.  */
 #define TARGET_VERSION fprintf (stderr, " (BlackFin bfin)")
 
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/bfin/bfin.opt gcc-mainline/gcc/config/bfin/bfin.opt
--- gcc-mainline-1/gcc/config/bfin/bfin.opt	2009-03-28 00:38:54.000000000 -0700
+++ gcc-mainline/gcc/config/bfin/bfin.opt	2011-03-01 17:39:27.000000000 -0800
@@ -1,6 +1,6 @@ 
 ; Options for the Blackfin port of the compiler
 ;
-; Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
+; Copyright (C) 2005, 2007, 2008, 2011 Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
 ;
@@ -18,6 +18,23 @@ 
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
 
+HeaderInclude
+config/bfin/bfin-opts.h
+
+; Value of -mcpu=.
+Variable
+bfin_cpu_t bfin_cpu_type = BFIN_CPU_UNKNOWN
+
+; -msi-revision support. There are three special values:
+; -1      -msi-revision=none.
+; 0xffff  -msi-revision=any.
+Variable
+int bfin_si_revision
+
+; The workarounds enabled.
+Variable
+unsigned int bfin_workarounds = 0
+
 msim
 Target RejectNegative
 Use simulator runtime