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 MEP handle_option hook from using global state. The variable option_mtiny_specified is replaced by the automatic setting of x_mep_tiny_cutoff in the opts_set structure. Setting of register properties and names for -mivc2 is deferred to mep_option_override. The other part of the effect of that option is setting various bits in target_flags (now opts->x_target_flags); as the part of the semantics described in the .opt file is now the deferral rather than setting a bit (both can't be described for the same option), the relevant mask is now defined by a Mask entry in mep.opt rather than by the Mask flag on the option entry for -mivc2. (The code to set this mask when the option is passed was already present in mep_handle_option, although before this patch it was redundant with the automatic setting.)
Tested building cc1 and xgcc for cross to mep-elf. Will commit to trunk for 4.7 in the absence of target maintainer objections. 2011-03-09 Joseph Myers <jos...@codesourcery.com> * config/mep/mep.c (option_mtiny_specified): Remove. (mep_option_override): Move register handling for -mivc2 from mep_handle_option. Use global_options_set.x_mep_tiny_cutoff instead of option_mtiny_specified. (mep_handle_option): Access target_flags via opts pointer. Don't assert that global structures are in use. Defer part of -mivc2 handling and move it to mep_option_override. * config/mep/mep.opt (IVC2): New Mask entry. (mivc2): Use Var and Defer instead of Mask. diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/mep/mep.c gcc-mainline/gcc/config/mep/mep.c --- gcc-mainline-1/gcc/config/mep/mep.c 2011-02-24 13:59:57.000000000 -0800 +++ gcc-mainline/gcc/config/mep/mep.c 2011-03-09 12:54:33.000000000 -0800 @@ -268,8 +268,6 @@ static const int mep_cmov_insns[] = { mep_cor3 }; -static int option_mtiny_specified = 0; - static void mep_set_leaf_registers (int enable) @@ -316,6 +314,58 @@ static const struct default_options mep_ static void mep_option_override (void) { + unsigned int i; + int j; + cl_deferred_option *opt; + VEC(cl_deferred_option,heap) *vec + = (VEC(cl_deferred_option,heap) *) mep_deferred_options; + + FOR_EACH_VEC_ELT (cl_deferred_option, vec, i, opt) + { + switch (opt->opt_index) + { + case OPT_mivc2: + for (j = 0; j < 32; j++) + fixed_regs[j + 48] = 0; + for (j = 0; j < 32; j++) + call_used_regs[j + 48] = 1; + for (j = 6; j < 8; j++) + call_used_regs[j + 48] = 0; + +#define RN(n,s) reg_names[FIRST_CCR_REGNO + n] = s + RN (0, "$csar0"); + RN (1, "$cc"); + RN (4, "$cofr0"); + RN (5, "$cofr1"); + RN (6, "$cofa0"); + RN (7, "$cofa1"); + RN (15, "$csar1"); + + RN (16, "$acc0_0"); + RN (17, "$acc0_1"); + RN (18, "$acc0_2"); + RN (19, "$acc0_3"); + RN (20, "$acc0_4"); + RN (21, "$acc0_5"); + RN (22, "$acc0_6"); + RN (23, "$acc0_7"); + + RN (24, "$acc1_0"); + RN (25, "$acc1_1"); + RN (26, "$acc1_2"); + RN (27, "$acc1_3"); + RN (28, "$acc1_4"); + RN (29, "$acc1_5"); + RN (30, "$acc1_6"); + RN (31, "$acc1_7"); +#undef RN + break; + + default: + gcc_unreachable (); + } + } + if (flag_pic == 1) warning (OPT_fpic, "-fpic is not supported"); if (flag_pic == 2) @@ -326,9 +376,9 @@ mep_option_override (void) error ("only one of -ms and -ml may be given"); if (TARGET_M && TARGET_L) error ("only one of -mm and -ml may be given"); - if (TARGET_S && option_mtiny_specified) + if (TARGET_S && global_options_set.x_mep_tiny_cutoff) error ("only one of -ms and -mtiny= may be given"); - if (TARGET_M && option_mtiny_specified) + if (TARGET_M && global_options_set.x_mep_tiny_cutoff) error ("only one of -mm and -mtiny= may be given"); if (TARGET_OPT_CLIP && ! TARGET_OPT_MINMAX) warning (0, "-mclip currently has no effect without -mminmax"); @@ -345,7 +395,7 @@ mep_option_override (void) mep_tiny_cutoff = 65536; if (TARGET_M) mep_tiny_cutoff = 0; - if (TARGET_L && ! option_mtiny_specified) + if (TARGET_L && ! global_options_set.x_mep_tiny_cutoff) mep_tiny_cutoff = 0; if (TARGET_64BIT_CR_REGS) @@ -7258,76 +7308,36 @@ mep_address_cost (rtx addr ATTRIBUTE_UNU } static bool -mep_handle_option (struct gcc_options *opts, struct gcc_options *opts_set, +mep_handle_option (struct gcc_options *opts, + struct gcc_options *opts_set ATTRIBUTE_UNUSED, const struct cl_decoded_option *decoded, location_t loc ATTRIBUTE_UNUSED) { - int i; size_t code = decoded->opt_index; - gcc_assert (opts == &global_options); - gcc_assert (opts_set == &global_options_set); - switch (code) { case OPT_mall_opts: - target_flags |= MEP_ALL_OPTS; + opts->x_target_flags |= MEP_ALL_OPTS; break; case OPT_mno_opts: - target_flags &= ~ MEP_ALL_OPTS; + opts->x_target_flags &= ~ MEP_ALL_OPTS; break; case OPT_mcop64: - target_flags |= MASK_COP; - target_flags |= MASK_64BIT_CR_REGS; + opts->x_target_flags |= MASK_COP; + opts->x_target_flags |= MASK_64BIT_CR_REGS; break; - case OPT_mtiny_: - option_mtiny_specified = 1; - case OPT_mivc2: - target_flags |= MASK_COP; - target_flags |= MASK_64BIT_CR_REGS; - target_flags |= MASK_VLIW; - target_flags |= MASK_OPT_VL64; - target_flags |= MASK_IVC2; - - for (i=0; i<32; i++) - fixed_regs[i+48] = 0; - for (i=0; i<32; i++) - call_used_regs[i+48] = 1; - for (i=6; i<8; i++) - call_used_regs[i+48] = 0; - -#define RN(n,s) reg_names[FIRST_CCR_REGNO + n] = s - RN (0, "$csar0"); - RN (1, "$cc"); - RN (4, "$cofr0"); - RN (5, "$cofr1"); - RN (6, "$cofa0"); - RN (7, "$cofa1"); - RN (15, "$csar1"); - - RN (16, "$acc0_0"); - RN (17, "$acc0_1"); - RN (18, "$acc0_2"); - RN (19, "$acc0_3"); - RN (20, "$acc0_4"); - RN (21, "$acc0_5"); - RN (22, "$acc0_6"); - RN (23, "$acc0_7"); - - RN (24, "$acc1_0"); - RN (25, "$acc1_1"); - RN (26, "$acc1_2"); - RN (27, "$acc1_3"); - RN (28, "$acc1_4"); - RN (29, "$acc1_5"); - RN (30, "$acc1_6"); - RN (31, "$acc1_7"); -#undef RN + opts->x_target_flags |= MASK_COP; + opts->x_target_flags |= MASK_64BIT_CR_REGS; + opts->x_target_flags |= MASK_VLIW; + opts->x_target_flags |= MASK_OPT_VL64; + opts->x_target_flags |= MASK_IVC2; + /* Remaining handling of this option deferred. */ break; default: diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/mep/mep.opt gcc-mainline/gcc/config/mep/mep.opt --- gcc-mainline-1/gcc/config/mep/mep.opt 2011-02-21 17:05:15.000000000 -0800 +++ gcc-mainline/gcc/config/mep/mep.opt 2011-03-09 12:13:54.000000000 -0800 @@ -1,5 +1,5 @@ ; Target specific command line options for the MEP port of the compiler. -; Copyright (C) 2005, 2007, 2009, 2010 Free Software Foundation, Inc. +; Copyright (C) 2005, 2007, 2009, 2010, 2011 Free Software Foundation, Inc. ; Contributed by Red Hat Inc. ; ; GCC is free software; you can redistribute it and/or modify it under @@ -16,6 +16,8 @@ ; along with GCC; see the file COPYING3. If not see ; <http://www.gnu.org/licenses/>. */ +Mask(IVC2) + mabsdiff Target Mask(OPT_ABSDIFF) Enable absolute difference instructions @@ -61,7 +63,7 @@ Target Mask(64BIT_CR_REGS) RejectNegativ Enable MeP Coprocessor with 64-bit registers mivc2 -Target Mask(IVC2) RejectNegative +Target RejectNegative Var(mep_deferred_options) Defer Enable IVC2 scheduling mdc -- Joseph S. Myers jos...@codesourcery.com