From 03ced4ab9f729cc4d5854439f136d84d1343b32d Mon Sep 17 00:00:00 2001 From: Tamar Christina Date: Mon, 1 Oct 2018 13:06:53 +0000 Subject: [PATCH] Allow back-ends to be able to do custom validations on params. 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. gcc/ * 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. From-SVN: r264755 --- gcc/ChangeLog | 10 ++++++++++ gcc/common/common-target.def | 7 +++++++ gcc/common/common-targhooks.c | 9 +++++++++ gcc/common/common-targhooks.h | 2 ++ gcc/doc/tm.texi | 4 ++++ gcc/doc/tm.texi.in | 2 ++ gcc/params.c | 2 +- 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0eafc63fb69..7ae7b901b18 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2018-10-01 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. + 2018-10-01 Tamar Christina PR target/86486 diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def index 019b1e752a9..8a268b67222 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.c b/gcc/common/common-targhooks.c index 1b1a015381d..990c495fa75 100644 --- a/gcc/common/common-targhooks.c +++ b/gcc/common/common-targhooks.c @@ -86,6 +86,15 @@ default_get_valid_option_values (int, const char *) return vec (); } +/* 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/common/common-targhooks.h b/gcc/common/common-targhooks.h index 4bdf8efdbe6..b021ff05af0 100644 --- a/gcc/common/common-targhooks.h +++ b/gcc/common/common-targhooks.h @@ -30,6 +30,8 @@ extern bool default_target_handle_option (struct gcc_options *, location_t); extern vec default_get_valid_option_values (int, const char *); +extern bool default_option_validate_param (const int, const int); + extern const struct default_options empty_optimization_table[]; #endif diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index b00e4b60bc5..83965b2f3a8 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 (int, @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 e2b6f945d29..e1966bd12f9 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 623296ce49b..eb663be880a 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); } -- 2.30.2