From patchwork Mon Aug 10 05:43:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1342729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Bo5B0qs6; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BQ4dN6VjCz9sRN for ; Mon, 10 Aug 2020 15:43:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7058E3857C53; Mon, 10 Aug 2020 05:43:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7058E3857C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597038211; bh=wNo6mfVRtChD4drvB49XTXpnyDFPP7cclEx1tml8iAw=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Bo5B0qs6Y2lr3KpXn+i7qsNPy7sWrmpbUx0C+U1crG6kHhAEFoDu3FnPHrG/xHVDm 1ReJppFEELJWt4msRGpPwdGen1GoIisnLUrAtu8bvnd8GlJDGVec7bGAHbSE6fIcFd X3zvT/SzNkD+G2079ERmuJqwhMCLZ0y2rquVN70o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 3FA393857C4A for ; Mon, 10 Aug 2020 05:43:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3FA393857C4A Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07A5XDh1157658; Mon, 10 Aug 2020 01:43:23 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 32sr4qsh00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2020 01:43:23 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 07A5a7N7000547; Mon, 10 Aug 2020 05:43:21 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma04ams.nl.ibm.com with ESMTP id 32skp81w3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2020 05:43:21 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 07A5hJW38519970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Aug 2020 05:43:19 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15E9B4C040; Mon, 10 Aug 2020 05:43:19 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1764A4C046; Mon, 10 Aug 2020 05:43:16 +0000 (GMT) Received: from KewenLins-MacBook-Pro.local (unknown [9.200.49.182]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 10 Aug 2020 05:43:15 +0000 (GMT) Subject: [PATCH] options: Make --help= to emit values post-overrided To: Segher Boessenkool References: <9eb8a897-e4ee-a80a-4456-1e088ab8f301@linux.ibm.com> <20200806220449.GW6753@gate.crashing.org> <20200807144212.GZ6753@gate.crashing.org> Message-ID: <43e70605-d708-373c-c069-f8bbd3f9a8b0@linux.ibm.com> Date: Mon, 10 Aug 2020 13:43:14 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200807144212.GZ6753@gate.crashing.org> Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-08-10_02:2020-08-06, 2020-08-10 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 impostorscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008100039 X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, MIME_CHARSET_FARAWAY, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Cc: Bill Schmidt , GCC Patches , Joseph Myers Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi Segher, on 2020/8/7 下午10:42, Segher Boessenkool wrote: > Hi! > > On Fri, Aug 07, 2020 at 10:44:10AM +0800, Kewen.Lin wrote: >>> I think this makes a lot of sense. >>> >>>> btw, not sure whether it's a good idea to move target_option_override_hook >>>> call into print_specific_help and use one function local static >>>> variable to control it's called once for all kinds of help dumping >>>> (possible combination), then can remove the calls in function >>>> common_handle_option. >>> >>> I cannot easily imagine what that will look like... it could easily be >>> worse than what you have here (callbacks aren't so nice, but there are >>> worse things). >>> >> >> I attached opts_alt2.diff to be more specific for this, both alt1 and alt2 >> follow the existing callback scheme, alt2 aims to avoid possible multiple >> times target_option_override_hook calls when we have several --help= or >> similar, but I guess alt1 is also fine since the hook should be allowed to >> be called more than once. > > It could take quadratic time in alt1... Mostly a theoretical problem I > think, but still. > > All options look fine to me, but you need someone else to approve this ;-) Yeah, CC Joseph. Thanks! > > One thing: > >> @@ -1664,6 +1665,14 @@ print_specific_help (unsigned int include_flags, >> } >> } >> >> + static bool call_override_once_p = false; >> + if (!call_override_once_p) >> + { >> + gcc_assert (target_option_override_hook); >> + target_option_override_hook (); >> + call_override_once_p = true; >> + } > > That assert is pretty random, nothing else using the hook assert it > isn't zero; it immediately and always calls the hook right away, so you > will get a nice ICE with backtrace if it is zero *anyway*. > Good point! Removed it. Bootstrapped/regtested on powerpc64le-linux-gnu P8. BR, Kewen *opts_alt1.diff* gcc/ChangeLog: * opts-global.c (decode_options): Adjust call to print_help. * opts.c (print_help): Add one function point argument target_option_override_hook and call it before print_specific_help. * opts.h (print_help): Add one more argument to function declare. *opts_alt2.diff* gcc/ChangeLog: * opts-global.c (decode_options): Adjust call to print_help. * opts.c (print_specific_help): Add one function point argument target_option_override_hook and call it once. (print_help): Add one function point argument target_option_override_hook and pass it in print_specific_help call. (common_handle_option): Adjust calls to print_specific_help, refactor calls to target_option_override_hook. * opts.h (print_help): Add one more argument to function declare. diff --git a/gcc/opts-global.c b/gcc/opts-global.c index b1a8429dc3c..ec960c87c9a 100644 --- a/gcc/opts-global.c +++ b/gcc/opts-global.c @@ -328,7 +328,7 @@ decode_options (struct gcc_options *opts, struct gcc_options *opts_set, const char *arg; FOR_EACH_VEC_ELT (help_option_arguments, i, arg) - print_help (opts, lang_mask, arg); + print_help (opts, lang_mask, arg, target_option_override_hook); } /* Hold command-line options associated with stack limitation. */ diff --git a/gcc/opts.c b/gcc/opts.c index 499eb900643..c61e7b7d519 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1579,7 +1579,8 @@ print_specific_help (unsigned int include_flags, unsigned int exclude_flags, unsigned int any_flags, struct gcc_options *opts, - unsigned int lang_mask) + unsigned int lang_mask, + void (*target_option_override_hook) (void)) { unsigned int all_langs_mask = (1U << cl_lang_count) - 1; const char * description = NULL; @@ -1664,6 +1665,13 @@ print_specific_help (unsigned int include_flags, } } + static bool call_override_once_p = false; + if (!call_override_once_p) + { + target_option_override_hook (); + call_override_once_p = true; + } + printf ("%s%s:\n", description, descrip_extra); print_filtered_help (include_flags, exclude_flags, any_flags, opts->x_help_columns, opts, lang_mask); @@ -2017,7 +2025,8 @@ check_alignment_argument (location_t loc, const char *flag, const char *name) void print_help (struct gcc_options *opts, unsigned int lang_mask, - const char *help_option_argument) + const char *help_option_argument, + void (*target_option_override_hook) (void)) { const char *a = help_option_argument; unsigned int include_flags = 0; @@ -2146,8 +2155,8 @@ print_help (struct gcc_options *opts, unsigned int lang_mask, exclude_flags |= CL_PARAMS; if (include_flags) - print_specific_help (include_flags, exclude_flags, 0, opts, - lang_mask); + print_specific_help (include_flags, exclude_flags, 0, opts, lang_mask, + target_option_override_hook); } /* Handle target- and language-independent options. Return zero to @@ -2186,18 +2195,19 @@ common_handle_option (struct gcc_options *opts, undoc_mask = ((opts->x_verbose_flag | opts->x_extra_warnings) ? 0 : CL_UNDOCUMENTED); - target_option_override_hook (); /* First display any single language specific options. */ for (i = 0; i < cl_lang_count; i++) - print_specific_help - (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0, opts, - lang_mask); + print_specific_help (1U << i, + (all_langs_mask & (~(1U << i))) | undoc_mask, 0, + opts, lang_mask, target_option_override_hook); /* Next display any multi language specific options. */ - print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask); + print_specific_help (0, undoc_mask, all_langs_mask, opts, lang_mask, + target_option_override_hook); /* Then display any remaining, non-language options. */ for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1) if (i != CL_DRIVER) - print_specific_help (i, undoc_mask, 0, opts, lang_mask); + print_specific_help (i, undoc_mask, 0, opts, lang_mask, + target_option_override_hook); opts->x_exit_after_options = true; break; } @@ -2206,8 +2216,8 @@ common_handle_option (struct gcc_options *opts, if (lang_mask == CL_DRIVER) break; - target_option_override_hook (); - print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask); + print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0, opts, lang_mask, + target_option_override_hook); opts->x_exit_after_options = true; break; diff --git a/gcc/opts.h b/gcc/opts.h index 8f594b46e33..9a837305af1 100644 --- a/gcc/opts.h +++ b/gcc/opts.h @@ -419,8 +419,9 @@ extern bool target_handle_option (struct gcc_options *opts, extern void finish_options (struct gcc_options *opts, struct gcc_options *opts_set, location_t loc); -extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const - char *help_option_argument); +extern void print_help (struct gcc_options *opts, unsigned int lang_mask, + const char *help_option_argument, + void (*target_option_override_hook) (void)); extern void default_options_optimization (struct gcc_options *opts, struct gcc_options *opts_set, struct cl_decoded_option *decoded_options, diff --git a/gcc/opts-global.c b/gcc/opts-global.c index b1a8429dc3c..ec960c87c9a 100644 --- a/gcc/opts-global.c +++ b/gcc/opts-global.c @@ -328,7 +328,7 @@ decode_options (struct gcc_options *opts, struct gcc_options *opts_set, const char *arg; FOR_EACH_VEC_ELT (help_option_arguments, i, arg) - print_help (opts, lang_mask, arg); + print_help (opts, lang_mask, arg, target_option_override_hook); } /* Hold command-line options associated with stack limitation. */ diff --git a/gcc/opts.c b/gcc/opts.c index 499eb900643..a83b2f837dd 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -2017,7 +2017,8 @@ check_alignment_argument (location_t loc, const char *flag, const char *name) void print_help (struct gcc_options *opts, unsigned int lang_mask, - const char *help_option_argument) + const char *help_option_argument, + void (*target_option_override_hook) (void)) { const char *a = help_option_argument; unsigned int include_flags = 0; @@ -2146,8 +2147,10 @@ print_help (struct gcc_options *opts, unsigned int lang_mask, exclude_flags |= CL_PARAMS; if (include_flags) - print_specific_help (include_flags, exclude_flags, 0, opts, - lang_mask); + { + target_option_override_hook (); + print_specific_help (include_flags, exclude_flags, 0, opts, lang_mask); + } } /* Handle target- and language-independent options. Return zero to diff --git a/gcc/opts.h b/gcc/opts.h index 8f594b46e33..9a837305af1 100644 --- a/gcc/opts.h +++ b/gcc/opts.h @@ -419,8 +419,9 @@ extern bool target_handle_option (struct gcc_options *opts, extern void finish_options (struct gcc_options *opts, struct gcc_options *opts_set, location_t loc); -extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const - char *help_option_argument); +extern void print_help (struct gcc_options *opts, unsigned int lang_mask, + const char *help_option_argument, + void (*target_option_override_hook) (void)); extern void default_options_optimization (struct gcc_options *opts, struct gcc_options *opts_set, struct cl_decoded_option *decoded_options,