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);
}