From patchwork Thu Mar 3 02:47:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 85215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 99423B70DB for ; Thu, 3 Mar 2011 13:47:17 +1100 (EST) Received: (qmail 2177 invoked by alias); 3 Mar 2011 02:47:15 -0000 Received: (qmail 2169 invoked by uid 22791); 3 Mar 2011 02:47:14 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, TW_XG, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 03 Mar 2011 02:47:09 +0000 Received: (qmail 5905 invoked from network); 3 Mar 2011 02:47:07 -0000 Received: from unknown (HELO digraph.polyomino.org.uk) (joseph@127.0.0.2) by mail.codesourcery.com with ESMTPA; 3 Mar 2011 02:47:07 -0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.72) (envelope-from ) id 1PuyZG-00074d-GO; Thu, 03 Mar 2011 02:47:06 +0000 Date: Thu, 3 Mar 2011 02:47:06 +0000 (UTC) From: "Joseph S. Myers" To: gcc-patches@gcc.gnu.org cc: wilson@tuliptree.org, sje@cup.hp.com Subject: [4.7] Avoid global state in ia64_handle_option Message-ID: MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch, for 4.7 and relative to a tree with applied, stops the IA64 handle_option hook from using global state. One option, -mtune=, is converted to using the Enum machinery, while another, -mfixed-range=, needs to be deferred to ia64_option_override (when that hook gets changes to avoid global state, it will be split up into a first part that avoids global state and is shared with the driver, and a second part using global state and not shared). In the course of preparing this patch I noticed that the 4.5 removal of Itanium 1 tuning did not remove all relevant code, although the code is now dead; the value PROCESSOR_ITANIUM is still there, although ia64_tune can never have that value, and there is a conditional on ia64_tune for which only one branch is reachable. IA64 maintainers might wish to clean these things up. Tested building cc1 and xgcc for cross to ia64-elf. Will commit to trunk for 4.7 in the absence of target maintainer objections. 2011-03-02 Joseph Myers * config/ia64/ia64-opts.h: New. * config/ia64/ia64.c (ia64_tune): Remove. (ia64_handle_option): Don't handle OPT_mfixed_range_ or OPT_mtune_ here. Use error_at. (ia64_option_override): Handle deferred OPT_mfixed_range_. * config/ia64/ia64.h (enum processor_type, ia64_tune): Remove. * config/ia64/ia64.opt (config/ia64/ia64-opts.h): New HeaderInclude entry. (ia64_tune): New Variable entry. (mfixed-range=): Use Defer and Var. (mtune=): Use Enum and Var. (ia64_tune): New Enum and EnumValue entries. diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/ia64/ia64-opts.h gcc-mainline/gcc/config/ia64/ia64-opts.h --- gcc-mainline-1/gcc/config/ia64/ia64-opts.h 1969-12-31 16:00:00.000000000 -0800 +++ gcc-mainline/gcc/config/ia64/ia64-opts.h 2011-03-02 14:15:27.000000000 -0800 @@ -0,0 +1,35 @@ +/* Definitions for option handling for IA-64. + Copyright (C) 1999, 2000, 2001, 2002, 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 +. */ + +#ifndef IA64_OPTS_H +#define IA64_OPTS_H + +/* Which processor to schedule for. The cpu attribute defines a list + that mirrors this list, so changes to ia64.md must be made at the + same time. */ + +enum processor_type +{ + PROCESSOR_ITANIUM, /* Original Itanium. */ + PROCESSOR_ITANIUM2, + PROCESSOR_max +}; + +#endif diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/ia64/ia64.c gcc-mainline/gcc/config/ia64/ia64.c --- gcc-mainline-1/gcc/config/ia64/ia64.c 2011-02-23 15:17:54.000000000 -0800 +++ gcc-mainline/gcc/config/ia64/ia64.c 2011-03-02 14:32:53.000000000 -0800 @@ -103,9 +103,6 @@ static const char * const ia64_local_reg static const char * const ia64_output_reg_names[8] = { "out0", "out1", "out2", "out3", "out4", "out5", "out6", "out7" }; -/* Which cpu are we scheduling for. */ -enum processor_type ia64_tune = PROCESSOR_ITANIUM2; - /* Determines whether we run our final scheduling pass or not. We always avoid the normal second scheduling pass. */ static int ia64_flag_schedule_insns2; @@ -5654,54 +5651,22 @@ fix_range (const char *const_str) /* Implement TARGET_HANDLE_OPTION. */ static bool -ia64_handle_option (struct gcc_options *opts, struct gcc_options *opts_set, +ia64_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, + 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_mfixed_range_: - fix_range (arg); - return true; - case OPT_mtls_size_: if (value != 14 && value != 22 && value != 64) - error ("bad value %<%s%> for -mtls-size= switch", arg); + error_at (loc, "bad value %<%s%> for -mtls-size= switch", arg); return true; - case OPT_mtune_: - { - static struct pta - { - const char *name; /* processor name or nickname. */ - enum processor_type processor; - } - const processor_alias_table[] = - { - {"itanium2", PROCESSOR_ITANIUM2}, - {"mckinley", PROCESSOR_ITANIUM2}, - }; - int const pta_size = ARRAY_SIZE (processor_alias_table); - int i; - - for (i = 0; i < pta_size; i++) - if (!strcmp (arg, processor_alias_table[i].name)) - { - ia64_tune = processor_alias_table[i].processor; - break; - } - if (i == pta_size) - error ("bad value %<%s%> for -mtune= switch", arg); - return true; - } - default: return true; } @@ -5712,6 +5677,24 @@ ia64_handle_option (struct gcc_options * static void ia64_option_override (void) { + unsigned int i; + cl_deferred_option *opt; + VEC(cl_deferred_option,heap) *vec + = (VEC(cl_deferred_option,heap) *) ia64_deferred_options; + + FOR_EACH_VEC_ELT (cl_deferred_option, vec, i, opt) + { + switch (opt->opt_index) + { + case OPT_mfixed_range_: + fix_range (opt->arg); + break; + + default: + gcc_unreachable (); + } + } + if (TARGET_AUTO_PIC) target_flags |= MASK_CONST_GP; diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/ia64/ia64.h gcc-mainline/gcc/config/ia64/ia64.h --- gcc-mainline-1/gcc/config/ia64/ia64.h 2010-12-30 04:02:12.000000000 -0800 +++ gcc-mainline/gcc/config/ia64/ia64.h 2011-03-02 14:15:36.000000000 -0800 @@ -1,6 +1,6 @@ /* Definitions of target machine GNU compiler. IA-64 version. Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - 2009, 2010 Free Software Foundation, Inc. + 2009, 2010, 2011 Free Software Foundation, Inc. Contributed by James E. Wilson and David Mosberger . @@ -102,19 +102,6 @@ enum ia64_inline_type #ifndef TARGET_CPU_DEFAULT #define TARGET_CPU_DEFAULT 0 #endif - -/* Which processor to schedule for. The cpu attribute defines a list - that mirrors this list, so changes to ia64.md must be made at the - same time. */ - -enum processor_type -{ - PROCESSOR_ITANIUM, /* Original Itanium. */ - PROCESSOR_ITANIUM2, - PROCESSOR_max -}; - -extern enum processor_type ia64_tune; /* Driver configuration */ diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/ia64/ia64.opt gcc-mainline/gcc/config/ia64/ia64.opt --- gcc-mainline-1/gcc/config/ia64/ia64.opt 2010-11-15 17:01:15.000000000 -0800 +++ gcc-mainline/gcc/config/ia64/ia64.opt 2011-03-02 14:29:56.000000000 -0800 @@ -1,4 +1,5 @@ -; Copyright (C) 2005, 2006, 2008, 2009, 2010 Free Software Foundation, Inc. +; Copyright (C) 2005, 2006, 2008, 2009, 2010, 2011 +; Free Software Foundation, Inc. ; ; This file is part of GCC. ; @@ -16,6 +17,13 @@ ; along with GCC; see the file COPYING3. If not see ; . +HeaderInclude +config/ia64/ia64-opts.h + +; Which cpu are we scheduling for. +Variable +enum processor_type ia64_tune = PROCESSOR_ITANIUM2 + mbig-endian Target Report RejectNegative Mask(BIG_ENDIAN) Generate big endian code @@ -103,7 +111,7 @@ Target Report Mask(EARLY_STOP_BITS) Enable earlier placing stop bits for better scheduling mfixed-range= -Target RejectNegative Joined +Target RejectNegative Joined Var(ia64_deferred_options) Defer Specify range of registers to make fixed mtls-size= @@ -111,9 +119,19 @@ Target RejectNegative Joined UInteger Va Specify bit size of immediate TLS offsets mtune= -Target RejectNegative Joined +Target RejectNegative Joined Enum(ia64_tune) Var(ia64_tune) Schedule code for given CPU +Enum +Name(ia64_tune) Type(enum processor_type) +Known Itanium CPUs (for use with the -mtune= option): + +EnumValue +Enum(ia64_tune) String(itanium2) Value(PROCESSOR_ITANIUM2) + +EnumValue +Enum(ia64_tune) String(mckinley) Value(PROCESSOR_ITANIUM2) + msched-br-data-spec Target Report Var(mflag_sched_br_data_spec) Init(0) Use data speculation before reload