Allow back-ends to be able to do custom validations on params.
authorTamar Christina <tamar.christina@arm.com>
Mon, 1 Oct 2018 13:06:53 +0000 (13:06 +0000)
committerTamar Christina <tnfchris@gcc.gnu.org>
Mon, 1 Oct 2018 13:06:53 +0000 (13:06 +0000)
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
gcc/common/common-target.def
gcc/common/common-targhooks.c
gcc/common/common-targhooks.h
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/params.c

index 0eafc63..7ae7b90 100644 (file)
@@ -1,5 +1,15 @@
 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
        * config/aarch64/aarch64.c (aarch64_override_options_internal):
        Add validation for stack-clash parameters and set defaults.
index 019b1e7..8a268b6 100644 (file)
@@ -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,
index 1b1a015..990c495 100644 (file)
@@ -86,6 +86,15 @@ default_get_valid_option_values (int, 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[] =
   {
     { OPT_LEVELS_NONE, 0, NULL, 0 }
index 4bdf8ef..b021ff0 100644 (file)
@@ -30,6 +30,8 @@ extern bool default_target_handle_option (struct gcc_options *,
                                          location_t);
 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[];
 
 #endif
index b00e4b6..83965b2 100644 (file)
@@ -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
index e2b6f94..e1966bd 100644 (file)
@@ -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
index 623296c..eb663be 100644 (file)
@@ -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);
 }