Commit 03ced4ab by Tamar Christina Committed by Tamar Christina

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
parent c98f502f
2018-10-01 Tamar Christina <tamar.christina@arm.com> 2018-10-01 Tamar Christina <tamar.christina@arm.com>
* 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 <tamar.christina@arm.com>
PR target/86486 PR target/86486
* config/aarch64/aarch64.c (aarch64_override_options_internal): * config/aarch64/aarch64.c (aarch64_override_options_internal):
Add validation for stack-clash parameters and set defaults. Add validation for stack-clash parameters and set defaults.
...@@ -56,6 +56,13 @@ DEFHOOK ...@@ -56,6 +56,13 @@ DEFHOOK
void, (void), void, (void),
hook_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. */ /* The initial value of target_flags. */
DEFHOOKPOD DEFHOOKPOD
(default_target_flags, (default_target_flags,
......
...@@ -86,6 +86,15 @@ default_get_valid_option_values (int, const char *) ...@@ -86,6 +86,15 @@ default_get_valid_option_values (int, const char *)
return vec<const char *> (); return vec<const char *> ();
} }
/* 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[] = const struct default_options empty_optimization_table[] =
{ {
{ OPT_LEVELS_NONE, 0, NULL, 0 } { OPT_LEVELS_NONE, 0, NULL, 0 }
......
...@@ -30,6 +30,8 @@ extern bool default_target_handle_option (struct gcc_options *, ...@@ -30,6 +30,8 @@ extern bool default_target_handle_option (struct gcc_options *,
location_t); location_t);
extern vec<const char *> default_get_valid_option_values (int, const char *); extern vec<const char *> 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[]; extern const struct default_options empty_optimization_table[];
#endif #endif
...@@ -753,6 +753,10 @@ Set target-dependent initial values of fields in @var{opts}. ...@@ -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}. Set target-dependent default values for @option{--param} settings, using calls to @code{set_default_param_value}.
@end deftypefn @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 @defmac SWITCHABLE_TARGET
Some targets need to switch between substantially different subtargets Some targets need to switch between substantially different subtargets
during compilation. For example, the MIPS target has one subtarget for during compilation. For example, the MIPS target has one subtarget for
......
...@@ -729,6 +729,8 @@ options are changed via @code{#pragma GCC optimize} or by using the ...@@ -729,6 +729,8 @@ options are changed via @code{#pragma GCC optimize} or by using the
@hook TARGET_OPTION_DEFAULT_PARAMS @hook TARGET_OPTION_DEFAULT_PARAMS
@hook TARGET_OPTION_VALIDATE_PARAM
@defmac SWITCHABLE_TARGET @defmac SWITCHABLE_TARGET
Some targets need to switch between substantially different subtargets Some targets need to switch between substantially different subtargets
during compilation. For example, the MIPS target has one subtarget for during compilation. For example, the MIPS target has one subtarget for
......
...@@ -209,7 +209,7 @@ set_param_value (const char *name, int value, ...@@ -209,7 +209,7 @@ set_param_value (const char *name, int value,
error ("maximum value of parameter %qs is %u", error ("maximum value of parameter %qs is %u",
compiler_params[i].option, compiler_params[i].option,
compiler_params[i].max_value); compiler_params[i].max_value);
else else if (targetm_common.option_validate_param (value, (int)i))
set_param_value_internal ((compiler_param) i, value, set_param_value_internal ((compiler_param) i, value,
params, params_set, true); params, params_set, true);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment