From patchwork Wed Jul 11 11:24:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 942450 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481347-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Dl2m17ot"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="LQcYfmU1"; dkim-atps=neutral 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 41QcDZ1Lnkz9s01 for ; Wed, 11 Jul 2018 21:25:02 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=esWll9QcfnXrUinXtPVclCPOyaujI3OW0KKEh+yGrhfa90hgBS i7b6nVEVnYZ70Cu8djXt26LLzO//YX2DLAn14q/2YClqRjrnPexZuMRR/9rSyt+/ IFBNpTguCfeYRfI0v0mLxtE505xMVeWm7IB44queAM5ETAT4H+3hkg9vY= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=ci4NFnu8zrXOFbErBWRMRshUR08=; b=Dl2m17otb+UhA+Bm4IvO 2jkWIu1ztx0x2500jfwbwAkMM9hjudevDna1UBvABP49YSoxLYbARa296wxyolhs d8IZcq7TK8yyWdSVJWYmY1dVWdoCDOlC8GzDxvvSkfuHJF0/qAGRKs7jZonovBlC axcZri6s1o7CHWT0nAAGd/k= Received: (qmail 122712 invoked by alias); 11 Jul 2018 11:24:53 -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 88904 invoked by uid 89); 11 Jul 2018 11:24:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy= X-HELO: EUR03-DB5-obe.outbound.protection.outlook.com Received: from mail-eopbgr40078.outbound.protection.outlook.com (HELO EUR03-DB5-obe.outbound.protection.outlook.com) (40.107.4.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 11:24:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j942/aS7SQ+/5LRHqULihjccjugDV+PecuftNx+8lzg=; b=LQcYfmU15htMHkHL30q9sgVXmQ5/MW8GFvd6DzyiWXjy8nnzcvPzsAT367zyRX9CGd9sBl13Pau0m3LH1ehq1cRDQZw3IMn3ZJuRg0BxvYMLn5zfylkt4Sa2e2VMessEoXmxCOQIIkWGBH3PzPQUpqHJ9Lz5bDK8Y38ZwDJm6Uk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tamar.Christina@arm.com; Received: from arm.com (217.140.96.140) by HE1PR08MB0748.eurprd08.prod.outlook.com (2a01:111:e400:59b1::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.930.21; Wed, 11 Jul 2018 11:24:08 +0000 Date: Wed, 11 Jul 2018 12:24:04 +0100 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, law@redhat.com, joseph@codesourcery.com Subject: [PATCH][GCC][front-end][opt-framework] Allow back-ends to be able to do custom validations on params. [Patch (1/3)] Message-ID: <20180711112402.GA16008@arm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes Hi All, This patch adds the ability for backends to add custom constrains to the param values by defining a new hook option_validate_param. This hook is invoked on every set_param_value which allows the back-end to ensure that the parameters are always within it's desired state. Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu and no issues. Both targets were tested with stack clash on and off by default. Ok for trunk? Thanks, Tamar gcc/ 2018-07-11 Tamar Christina * params.c (set_param_value): Add index of parameter being validated. * common/common-target.def (option_validate_param): New. * common/common-targhooks.h (default_option_validate_param): New. * common/common-targhooks.c (default_option_validate_param): New. * doc/tm.texi.in (TARGET_OPTION_VALIDATE_PARAM): New. * doc/tm.texi: Regenerate. diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def index e0afbc6af29a37a908c32bcdbecd68c8cda003af..021b7e916471de97174ed17b143a03154165bb2d 100644 --- a/gcc/common/common-target.def +++ b/gcc/common/common-target.def @@ -56,6 +56,13 @@ DEFHOOK void, (void), hook_void_void) +DEFHOOK +(option_validate_param, +"Validate target-dependent value for @option{--param} settings, using\ + calls to @code{set_param_value}.", + bool, (int, int), + default_option_validate_param) + /* The initial value of target_flags. */ DEFHOOKPOD (default_target_flags, diff --git a/gcc/common/common-targhooks.h b/gcc/common/common-targhooks.h index d290d7f3e2110aa2c421c57e9285e97def4bf0be..ff1da6a78322a26a622c74a1ad7b841847487bf1 100644 --- a/gcc/common/common-targhooks.h +++ b/gcc/common/common-targhooks.h @@ -29,6 +29,8 @@ extern bool default_target_handle_option (struct gcc_options *, const struct cl_decoded_option *, location_t); +extern bool default_option_validate_param (const int, const int); + extern const struct default_options empty_optimization_table[]; #endif diff --git a/gcc/common/common-targhooks.c b/gcc/common/common-targhooks.c index b109019066422429280bfec58e10a0c0421ffae7..5cb8d27321a4bc5c858f349c29e90691baa9c144 100644 --- a/gcc/common/common-targhooks.c +++ b/gcc/common/common-targhooks.c @@ -77,6 +77,16 @@ default_target_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, return true; } +/* Default version of TARGET_OPTION_VALIDATE_PARAM. */ + +bool +default_option_validate_param (const int value ATTRIBUTE_UNUSED, + const int param ATTRIBUTE_UNUSED) +{ + return true; +} + + const struct default_options empty_optimization_table[] = { { OPT_LEVELS_NONE, 0, NULL, 0 } diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 138d905023b449a7a239fb32c07f5c8551d5380f..e61bee35b5379466563cb5ad03c12225c1bdfe04 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -753,6 +753,10 @@ Set target-dependent initial values of fields in @var{opts}. Set target-dependent default values for @option{--param} settings, using calls to @code{set_default_param_value}. @end deftypefn +@deftypefn {Common Target Hook} bool TARGET_OPTION_VALIDATE_PARAM (const @var{int}, const @var{int}) +Validate target-dependent value for @option{--param} settings, using calls to @code{set_param_value}. +@end deftypefn + @defmac SWITCHABLE_TARGET Some targets need to switch between substantially different subtargets during compilation. For example, the MIPS target has one subtarget for diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 8c62ae06b6be2fe338e3614917dc5f5b1f4fd4aa..37373a29ced2540e1070559e53b5c6cf952fdda4 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -729,6 +729,8 @@ options are changed via @code{#pragma GCC optimize} or by using the @hook TARGET_OPTION_DEFAULT_PARAMS +@hook TARGET_OPTION_VALIDATE_PARAM + @defmac SWITCHABLE_TARGET Some targets need to switch between substantially different subtargets during compilation. For example, the MIPS target has one subtarget for diff --git a/gcc/params.c b/gcc/params.c index 623296ce49b6c8cf98da7be08a3fb01bc2c21a93..eb663be880a91dc0adce2a84c6bad7e06b4c72c3 100644 --- a/gcc/params.c +++ b/gcc/params.c @@ -209,7 +209,7 @@ set_param_value (const char *name, int value, error ("maximum value of parameter %qs is %u", compiler_params[i].option, compiler_params[i].max_value); - else + else if (targetm_common.option_validate_param (value, (int)i)) set_param_value_internal ((compiler_param) i, value, params, params_set, true); }