This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[4.7] Avoid global state in v850_handle_option
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: nickc at redhat dot com
- Date: Tue, 8 Mar 2011 02:30:17 +0000 (UTC)
- Subject: [4.7] Avoid global state in v850_handle_option
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 V850 handle_option hook from using global state.
The main changes here relate to the small memory options. These were
previously handled as options -msda, -mtda, -mzda with joined
arguments and target-specific code looking for a '-' or '=' followed
by a number; that is changed to describing them as options -msda=
etc. with UInteger arguments, and aliases -msda- etc., so the .opt
machinery deals with parsing the arguments. (The canonical forms were
chosen on the basis that invoke.texi only mentions the '=' forms, with
the '-' forms being undocumented.) Previously an array small_memory
was used that combined both variable information from the command line
and constant information about the permitted range of arguments to the
options; these are separated so that the variable information ends up
in the gcc_options structure. The third structure element was the
option name; the full original option name with its original spelling
is now passed down to v850_handle_memory_option so that structure
element is no longer needed.
Tested building cc1 and xgcc for cross to v850-elf. Will commit to
trunk for 4.7 in the absence of target maintainer objections.
2011-03-07 Joseph Myers <joseph@codesourcery.com>
* config/v850/v850-opts.h: New.
* config/v850/v850.c (small_memory): Replace with
small_memory_physical_max array. Make that array static const.
(v850_handle_memory_option): Take integer value of argument. Take
gcc_options pointer, option text and location. Return void.
Update for changes to small memory structures.
(v850_handle_option): Access target_flags via opts pointer. Don't
assert that global structures are in use. Update calls to
v850_handle_memory_option.
(v850_encode_data_area): Update references to small memory
settings.
* config/v850/v850.h (struct small_memory_info, small_memory):
Remove.
(enum small_memory_type): Move to v850-opts.h.
* config/v850/v850.opt (config/v850/v850-opts.h): New
HeaderInclude entry.
(small_memory_max): New Variable entry.
(msda): Replace by pair of options msda= and msda-. Use UInteger.
(mtda, mzda): Likewise.
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/v850/v850-opts.h gcc-mainline/gcc/config/v850/v850-opts.h
--- gcc-mainline-1/gcc/config/v850/v850-opts.h 1969-12-31 16:00:00.000000000 -0800
+++ gcc-mainline/gcc/config/v850/v850-opts.h 2011-03-07 17:52:17.000000000 -0800
@@ -0,0 +1,34 @@
+/* Definitions for option handling for NEC V850 series.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 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 V850_OPTS_H
+#define V850_OPTS_H
+
+enum small_memory_type {
+ /* tiny data area, using EP as base register */
+ SMALL_MEMORY_TDA = 0,
+ /* small data area using dp as base register */
+ SMALL_MEMORY_SDA,
+ /* zero data area using r0 as base register */
+ SMALL_MEMORY_ZDA,
+ SMALL_MEMORY_max
+};
+
+#endif
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/v850/v850.c gcc-mainline/gcc/config/v850/v850.c
--- gcc-mainline-1/gcc/config/v850/v850.c 2011-02-24 13:45:15.000000000 -0800
+++ gcc-mainline/gcc/config/v850/v850.c 2011-03-07 18:07:45.000000000 -0800
@@ -51,12 +51,11 @@
static void v850_print_operand_address (FILE *, rtx);
/* Information about the various small memory areas. */
-struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
+static const int small_memory_physical_max[(int) SMALL_MEMORY_max] =
{
- /* Name Max Physical max. */
- { "tda", 0, 256 },
- { "sda", 0, 65536 },
- { "zda", 0, 32768 },
+ 256,
+ 65536,
+ 32768,
};
/* Names of the various data areas used on the v850. */
@@ -83,66 +82,62 @@ static GTY(()) section * zdata_section;
static GTY(()) section * zbss_section;
/* Set the maximum size of small memory area TYPE to the value given
- by VALUE. Return true if VALUE was syntactically correct. VALUE
- starts with the argument separator: either "-" or "=". */
+ by SIZE in structure OPTS (option text OPT passed at location LOC). */
-static bool
-v850_handle_memory_option (enum small_memory_type type, const char *value)
+static void
+v850_handle_memory_option (enum small_memory_type type,
+ struct gcc_options *opts, const char *opt,
+ int size, location_t loc)
{
- int i, size;
-
- if (*value != '-' && *value != '=')
- return false;
-
- value++;
- for (i = 0; value[i]; i++)
- if (!ISDIGIT (value[i]))
- return false;
-
- size = atoi (value);
- if (size > small_memory[type].physical_max)
- error ("value passed to %<-m%s%> is too large", small_memory[type].name);
+ if (size > small_memory_physical_max[type])
+ error_at (loc, "value passed in %qs is too large", opt);
else
- small_memory[type].max = size;
- return true;
+ opts->x_small_memory_max[type] = size;
}
/* Implement TARGET_HANDLE_OPTION. */
static bool
-v850_handle_option (struct gcc_options *opts, struct gcc_options *opts_set,
+v850_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;
-
- gcc_assert (opts == &global_options);
- gcc_assert (opts_set == &global_options_set);
+ int value = decoded->value;
switch (code)
{
case OPT_mspace:
- target_flags |= MASK_EP | MASK_PROLOG_FUNCTION;
+ opts->x_target_flags |= MASK_EP | MASK_PROLOG_FUNCTION;
return true;
case OPT_mv850:
- target_flags &= ~(MASK_CPU ^ MASK_V850);
+ opts->x_target_flags &= ~(MASK_CPU ^ MASK_V850);
return true;
case OPT_mv850e:
case OPT_mv850e1:
- target_flags &= ~(MASK_CPU ^ MASK_V850E);
+ opts->x_target_flags &= ~(MASK_CPU ^ MASK_V850E);
return true;
- case OPT_mtda:
- return v850_handle_memory_option (SMALL_MEMORY_TDA, arg);
+ case OPT_mtda_:
+ v850_handle_memory_option (SMALL_MEMORY_TDA, opts,
+ decoded->orig_option_with_args_text,
+ value, loc);
+ return true;
- case OPT_msda:
- return v850_handle_memory_option (SMALL_MEMORY_SDA, arg);
+ case OPT_msda_:
+ v850_handle_memory_option (SMALL_MEMORY_SDA, opts,
+ decoded->orig_option_with_args_text,
+ value, loc);
+ return true;
- case OPT_mzda:
- return v850_handle_memory_option (SMALL_MEMORY_ZDA, arg);
+ case OPT_mzda_:
+ v850_handle_memory_option (SMALL_MEMORY_ZDA, opts,
+ decoded->orig_option_with_args_text,
+ value, loc);
+ return true;
default:
return true;
@@ -2265,13 +2260,13 @@ v850_encode_data_area (tree decl, rtx sy
if (size <= 0)
;
- else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
+ else if (size <= small_memory_max [(int) SMALL_MEMORY_TDA])
v850_set_data_area (decl, DATA_AREA_TDA);
- else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
+ else if (size <= small_memory_max [(int) SMALL_MEMORY_SDA])
v850_set_data_area (decl, DATA_AREA_SDA);
- else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
+ else if (size <= small_memory_max [(int) SMALL_MEMORY_ZDA])
v850_set_data_area (decl, DATA_AREA_ZDA);
}
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/v850/v850.h gcc-mainline/gcc/config/v850/v850.h
--- gcc-mainline-1/gcc/config/v850/v850.h 2011-02-14 12:16:20.000000000 -0800
+++ gcc-mainline/gcc/config/v850/v850.h 2011-03-07 17:52:11.000000000 -0800
@@ -1,6 +1,6 @@
/* Definitions of target machine for GNU compiler. NEC V850 series
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
- 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+ 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
Contributed by Jeff Law (law@cygnus.com).
This file is part of GCC.
@@ -123,25 +123,6 @@ extern GTY(()) rtx v850_compare_op1;
} while(0)
#define MASK_CPU (MASK_V850 | MASK_V850E)
-
-/* Information about the various small memory areas. */
-struct small_memory_info {
- const char *name;
- long max;
- long physical_max;
-};
-
-enum small_memory_type {
- /* tiny data area, using EP as base register */
- SMALL_MEMORY_TDA = 0,
- /* small data area using dp as base register */
- SMALL_MEMORY_SDA,
- /* zero data area using r0 as base register */
- SMALL_MEMORY_ZDA,
- SMALL_MEMORY_max
-};
-
-extern struct small_memory_info small_memory[(int)SMALL_MEMORY_max];
/* Target machine storage layout */
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/v850/v850.opt gcc-mainline/gcc/config/v850/v850.opt
--- gcc-mainline-1/gcc/config/v850/v850.opt 2011-01-26 16:28:20.000000000 -0800
+++ gcc-mainline/gcc/config/v850/v850.opt 2011-03-07 18:02:10.000000000 -0800
@@ -1,6 +1,6 @@
; Options for the NEC V850 port of the compiler.
-; Copyright (C) 2005, 2007, 2010 Free Software Foundation, Inc.
+; Copyright (C) 2005, 2007, 2010, 2011 Free Software Foundation, Inc.
;
; This file is part of GCC.
;
@@ -18,6 +18,12 @@
; along with GCC; see the file COPYING3. If not see
; <http://www.gnu.org/licenses/>.
+HeaderInclude
+config/v850/v850-opts.h
+
+Variable
+int small_memory_max[(int)SMALL_MEMORY_max] = { 0, 0, 0 }
+
mapp-regs
Target Report Mask(APP_REGS)
Use registers r2 and r5
@@ -50,10 +56,13 @@ mprolog-function
Target Report Mask(PROLOG_FUNCTION)
Use stubs for function prologues
-msda
-Target RejectNegative Joined
+msda=
+Target RejectNegative Joined UInteger
Set the max size of data eligible for the SDA area
+msda-
+Target RejectNegative Joined Undocumented Alias(msda=)
+
msmall-sld
Target Report Mask(SMALL_SLD)
Enable the use of the short load instructions
@@ -62,10 +71,13 @@ mspace
Target RejectNegative
Same as: -mep -mprolog-function
-mtda
-Target RejectNegative Joined
+mtda=
+Target RejectNegative Joined UInteger
Set the max size of data eligible for the TDA area
+mtda-
+Target RejectNegative Joined Undocumented Alias(mtda=)
+
mno-strict-align
Target Report Mask(NO_STRICT_ALIGN)
Do not enforce strict alignment
@@ -101,6 +113,9 @@ mv850e2v3
Target Report RejectNegative Mask(V850E2V3)
Compile for the v850e2v3 processor
-mzda
-Target RejectNegative Joined
+mzda=
+Target RejectNegative Joined UInteger
Set the max size of data eligible for the ZDA area
+
+mzda-
+Target RejectNegative Joined Undocumented Alias(mzda=)
--
Joseph S. Myers
joseph@codesourcery.com