From patchwork Fri Sep 11 13:28:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 516811 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0EC81140271 for ; Fri, 11 Sep 2015 23:28:55 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=eIXLhqSn; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=bSoqNMPLJ1vAw/Nlg ScqyUrradhV4S/Hz6UOIomRAeeLicPStGduUOIolE4vck5ifE0XbC18VjPaVwnf6 rUGqRRK+QT09wRNaww0PhnQmhFyRrLnJN4bctIhXFbzY8x6jZunz5nV7tjOp7i90 92YtutPNYevUG35/CZdm0IeIpk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=n55wZr6CUx0FzETrnyiIejY kJ/c=; b=eIXLhqSn9IKOl4zZjPD02opigN8jrCU/jll6VW1vq6QDTMnL8y4tCQA 5VY39LXWyqU5mBkbrAh7WUSOrYT5j3Nxr+ZrBJQQ2CWOkOWH9vvF+M+YbFewm1zz 7/w4q62AsKC3/5lU87u/PvoBlMQiB6aSOvHyxNeTbu25u9nNETDk= Received: (qmail 78909 invoked by alias); 11 Sep 2015 13:28:46 -0000 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 Received: (qmail 78893 invoked by uid 89); 11 Sep 2015 13:28:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 11 Sep 2015 13:28:41 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43446) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZaONZ-0007hC-3t for gcc-patches@gnu.org; Fri, 11 Sep 2015 09:28:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZaONU-0007Uy-Ky for gcc-patches@gnu.org; Fri, 11 Sep 2015 09:28:36 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:44034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZaONU-0007R1-Ca for gcc-patches@gnu.org; Fri, 11 Sep 2015 09:28:32 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZaONR-0003WX-Um from Tom_deVries@mentor.com ; Fri, 11 Sep 2015 06:28:30 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Fri, 11 Sep 2015 14:28:28 +0100 Subject: Re: [PATCH][PR67476] Add param parloops-schedule To: Jakub Jelinek References: <55F2B304.7060604@mentor.com> <20150911105749.GC1847@tucnak.redhat.com> CC: Richard Biener , "gcc-patches@gnu.org" From: Tom de Vries Message-ID: <55F2D6E1.7030504@mentor.com> Date: Fri, 11 Sep 2015 15:28:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150911105749.GC1847@tucnak.redhat.com> X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 On 11/09/15 12:57, Jakub Jelinek wrote: > On Fri, Sep 11, 2015 at 12:55:00PM +0200, Tom de Vries wrote: >> >Hi, >> > >> >this patch adds a param parloops-schedule=<0-4>, which sets the omp schedule >> >for loops paralellized by parloops. >> > >> >The <0-4> maps onto . >> > >> >Bootstrapped and reg-tested on x86_64. >> > >> >OK for trunk? > I don't really like it, the mapping of the integers to the enum values > is non-obvious and hard to remember. > Perhaps add support for enumeration params if you want this instead? > This patch adds handling of a DEFPARAMENUM macro, which is similar to the DEFPARAM macro, but allows the values to be named. So the definition of param parloop-schedule becomes: ... DEFPARAMENUM PARAM_PARLOOPS_SCHEDULE, "parloops-schedule", "Schedule type of omp schedule for loops parallelized by " "parloops (static, dynamic, guided, auto, runtime)", 0, 0, 4, "static", "dynamic", "guided", "auto", "runtime") ... [ I'll repost the original patch containing this update. ] OK for trunk if x86_64 bootstrap and reg-test succeeds? Thanks, - Tom Support DEFPARAMENUM in params.def 2015-09-11 Tom de Vries * opts.c (handle_param): Handle case that param arg is a string. * params-list.h: Handle DEFPARAMENUM in params.def. * params.c (find_param): New function, factored out of ... (set_param_value): ... here. (get_param_string_value): New function. * params.h (struct param_info): Add values field. (get_param_string_value): Declare. --- gcc/opts.c | 12 ++++--- gcc/params-list.h | 3 ++ gcc/params.c | 93 +++++++++++++++++++++++++++++++++++++++++-------------- gcc/params.h | 5 +++ 4 files changed, 85 insertions(+), 28 deletions(-) diff --git a/gcc/opts.c b/gcc/opts.c index f1a9acd..47b8b86 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2116,15 +2116,17 @@ handle_param (struct gcc_options *opts, struct gcc_options *opts_set, arg); else { + *equal = '\0'; + value = integral_argument (equal + 1); if (value == -1) + value = get_param_string_value (arg, equal + 1); + + if (value == -1) error_at (loc, "invalid --param value %qs", equal + 1); else - { - *equal = '\0'; - set_param_value (arg, value, - opts->x_param_values, opts_set->x_param_values); - } + set_param_value (arg, value, + opts->x_param_values, opts_set->x_param_values); } free (arg); diff --git a/gcc/params-list.h b/gcc/params-list.h index ee33ef5..8a19919 100644 --- a/gcc/params-list.h +++ b/gcc/params-list.h @@ -19,5 +19,8 @@ along with GCC; see the file COPYING3. If not see #define DEFPARAM(enumerator, option, nocmsgid, default, min, max) \ enumerator, +#define DEFPARAMENUM(enumerator, option, nocmsgid, default, min, max, ...) \ + enumerator, #include "params.def" #undef DEFPARAM +#undef DEFPARAMENUM diff --git a/gcc/params.c b/gcc/params.c index b0bc80b..7eedab8 100644 --- a/gcc/params.c +++ b/gcc/params.c @@ -37,12 +37,22 @@ static size_t num_compiler_params; default values determined. */ static bool params_finished; +#define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) +#define DEFPARAMENUM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX, ...) \ + static const char *values_ ## ENUM [] = { __VA_ARGS__ }; +#include "params.def" +#undef DEFPARAMENUM +#undef DEFPARAM + static const param_info lang_independent_params[] = { #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \ - { OPTION, DEFAULT, MIN, MAX, HELP }, + { OPTION, DEFAULT, MIN, MAX, HELP, NULL }, +#define DEFPARAMENUM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX, ...) \ + { OPTION, DEFAULT, MIN, MAX, HELP, values_ ## ENUM }, #include "params.def" #undef DEFPARAM - { NULL, 0, 0, 0, NULL } +#undef DEFPARAMENUM + { NULL, 0, 0, 0, NULL, NULL } }; /* Add the N PARAMS to the current list of compiler parameters. */ @@ -114,6 +124,45 @@ set_param_value_internal (compiler_param num, int value, params_set[i] = true; } +/* Return true if it can find the matching entry for NAME in the parameter + table, and assign the entry index to INDEX. Return false otherwise. */ + +bool +find_param (const char *name, size_t *index) +{ + for (size_t i = 0; i < num_compiler_params; ++i) + if (strcmp (compiler_params[i].option, name) == 0) + { + *index = i; + return true; + } + + return false; +} + +/* Return the param value for param name VALUE_NAME belonging to param NAME. + Return -1 if there no corresponding param value. */ + +int +get_param_string_value (const char *name, const char *value_name) +{ + size_t index; + if (!find_param (name, &index)) + return -1; + + param_info *entry = &compiler_params[index]; + if (entry->value_names == NULL) + return -1; + + int n = entry->max_value - entry->min_value + 1; + int value = entry->min_value; + for (int i = 0; i < n ; ++i, ++value) + if (strcmp (entry->value_names[i], value_name) == 0) + return value; + + return -1; +} + /* Set the VALUE associated with the parameter given by NAME in PARAMS and PARAMS_SET. */ @@ -126,27 +175,25 @@ set_param_value (const char *name, int value, /* Make sure nobody tries to set a parameter to an invalid value. */ gcc_assert (value != INVALID_PARAM_VAL); - /* Scan the parameter table to find a matching entry. */ - for (i = 0; i < num_compiler_params; ++i) - if (strcmp (compiler_params[i].option, name) == 0) - { - if (value < compiler_params[i].min_value) - error ("minimum value of parameter %qs is %u", - compiler_params[i].option, - compiler_params[i].min_value); - else if (compiler_params[i].max_value > compiler_params[i].min_value - && value > compiler_params[i].max_value) - error ("maximum value of parameter %qs is %u", - compiler_params[i].option, - compiler_params[i].max_value); - else - set_param_value_internal ((compiler_param) i, value, - params, params_set, true); - return; - } - - /* If we didn't find this parameter, issue an error message. */ - error ("invalid parameter %qs", name); + if (!find_param (name, &i)) + { + /* If we didn't find this parameter, issue an error message. */ + error ("invalid parameter %qs", name); + return; + } + + if (value < compiler_params[i].min_value) + error ("minimum value of parameter %qs is %u", + compiler_params[i].option, + compiler_params[i].min_value); + else if (compiler_params[i].max_value > compiler_params[i].min_value + && value > compiler_params[i].max_value) + error ("maximum value of parameter %qs is %u", + compiler_params[i].option, + compiler_params[i].max_value); + else + set_param_value_internal ((compiler_param) i, value, + params, params_set, true); } /* Set the value of the parameter given by NUM to VALUE in PARAMS and diff --git a/gcc/params.h b/gcc/params.h index 9f7618a..cec6131 100644 --- a/gcc/params.h +++ b/gcc/params.h @@ -55,6 +55,9 @@ struct param_info /* A short description of the option. */ const char *const help; + + /* The optional names corresponding to the values. */ + const char **value_names; }; /* An array containing the compiler parameters and their current @@ -69,6 +72,8 @@ extern size_t get_num_compiler_params (void); extern void add_params (const param_info params[], size_t n); +extern int get_param_string_value (const char *, const char*); + /* Set the VALUE associated with the parameter given by NAME in the table PARAMS using PARAMS_SET to indicate which have been explicitly set. */ -- 1.9.1