On 10/31/19 2:16 PM, Martin Liška wrote:
> On 10/31/19 2:01 PM, Martin Liška wrote:
>> Hi.
>>
>> Based on the discussion with Honza and Richard I'm sending a proposal
>> for conversion of param machinery into the existing option machinery.
>> Our motivation for the change is to provide per function param values,
>> similarly what 'Optimization' keyword does for options.
>>
>> Right now, we support the following format:
>> gcc --param=lto-partitions=4 /tmp/main.c -c
>>
>> And so that I decided to name newly the params like:
>>
>> -param=ipa-sra-ptr-growth-factor=
>> Common Joined UInteger Var(param_ipa_sra_ptr_growth_factor) Init(2) Param 
>> Optimization
>> Maximum allowed growth of number and total size of new parameters
>> that ipa-sra replaces a pointer to an aggregate with.
>>
>> And I learnt decoder to parse '--param' 'name=value' as 
>> '--param=name=value'. Doing that
>> the transformation works. Help provides reasonable output as well:
>>
>> $ ./xgcc -B. --param predictable-branch-outcome=5  /tmp/main.c -c -Q 
>> --help=param
>> The --param option recognizes the following as parameters:
>>   --param=ipa-sra-ptr-growth-factor=         2
>>   --param=predictable-branch-outcome=<0,50>  5
>>
>> Thoughts?
>> Thanks,
>> Martin
>>
>> ---
>>  gcc/common.opt        | 18 +++++++++++-------
>>  gcc/ipa-sra.c         |  3 +--
>>  gcc/opt-functions.awk |  3 ++-
>>  gcc/opts-common.c     |  9 +++++++++
>>  gcc/opts.c            | 36 ------------------------------------
>>  gcc/params.def        | 10 ----------
>>  gcc/predict.c         |  4 ++--
>>  7 files changed, 25 insertions(+), 58 deletions(-)
>>
>>
> 
> I forgot to add gcc-patches to To.
> 
> Martin
> 

+ the patch.

Martin
>From 508ee931152b8b7895424f0b6b2d86c2ab758ae0 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Thu, 31 Oct 2019 13:53:54 +0100
Subject: [PATCH] Param to options conversion (demo).

---
 gcc/common.opt        | 18 +++++++++++-------
 gcc/ipa-sra.c         |  3 +--
 gcc/opt-functions.awk |  3 ++-
 gcc/opts-common.c     |  9 +++++++++
 gcc/opts.c            | 36 ------------------------------------
 gcc/params.def        | 10 ----------
 gcc/predict.c         |  4 ++--
 7 files changed, 25 insertions(+), 58 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index cc279f411d7..b8782d6c35b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -437,13 +437,6 @@ Common Driver Alias(-target-help)
 fversion
 Common Driver Alias(-version)
 
--param
-Common Separate
---param <param>=<value>	Set parameter <param> to value.  See below for a complete list of parameters.
-
--param=
-Common Joined Alias(-param)
-
 -sysroot
 Driver Separate Alias(-sysroot=)
 
@@ -3344,4 +3337,15 @@ fipa-ra
 Common Report Var(flag_ipa_ra) Optimization
 Use caller save register across calls if possible.
 
+; PARAMS start here
+
+-param=predictable-branch-outcome=
+Common Joined UInteger Var(param_predictable_branch_outcome) Init(2) IntegerRange(0, 50) Param
+Maximal estimated outcome of branch considered predictable.
+
+-param=ipa-sra-ptr-growth-factor=
+Common Joined UInteger Var(param_ipa_sra_ptr_growth_factor) Init(2) Param Optimization
+Maximum allowed growth of number and total size of new parameters
+that ipa-sra replaces a pointer to an aggregate with.
+
 ; This comment is to ensure we retain the blank line above.
diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c
index 8f028438556..09744a3b251 100644
--- a/gcc/ipa-sra.c
+++ b/gcc/ipa-sra.c
@@ -2279,8 +2279,7 @@ process_scan_results (cgraph_node *node, struct function *fun,
       if (!desc->by_ref || optimize_function_for_size_p (fun))
 	param_size_limit = cur_param_size;
       else
-	param_size_limit = (PARAM_VALUE (PARAM_IPA_SRA_PTR_GROWTH_FACTOR)
-			   * cur_param_size);
+	param_size_limit = param_ipa_sra_ptr_growth_factor * cur_param_size;
       if (nonarg_acc_size > param_size_limit
 	  || (!desc->by_ref && nonarg_acc_size == param_size_limit))
 	{
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index c1da80c648c..4f02b74e97c 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -105,7 +105,8 @@ function switch_flags (flags)
 	  test_flag("Undocumented", flags,  " | CL_UNDOCUMENTED") \
 	  test_flag("NoDWARFRecord", flags,  " | CL_NO_DWARF_RECORD") \
 	  test_flag("Warning", flags,  " | CL_WARNING") \
-	  test_flag("(Optimization|PerFunction)", flags,  " | CL_OPTIMIZATION")
+	  test_flag("(Optimization|PerFunction)", flags,  " | CL_OPTIMIZATION") \
+	  test_flag("Param", flags,  " | CL_PARAMS")
 	sub( "^0 \\| ", "", result )
 	return result
 }
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index b4ec1bd25ac..d55dc93e165 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -961,6 +961,15 @@ decode_cmdline_options_to_array (unsigned int argc, const char **argv,
 	  continue;
 	}
 
+      /* Interpret "--param" "key=name" as "--param=key=name".  */
+      const char *needle = "--param";
+      if (i + 1 < argc && strcmp (opt, needle) == 0)
+	{
+	  const char *replacement
+	    = opts_concat (needle, "=", argv[i + 1], NULL);
+	  argv[++i] = replacement;
+	}
+
       n = decode_cmdline_option (argv + i, lang_mask,
 				 &opt_array[num_decoded_options]);
       num_decoded_options++;
diff --git a/gcc/opts.c b/gcc/opts.c
index 10b9f108f8d..aa4e15a1a38 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -1278,38 +1278,6 @@ print_filtered_help (unsigned int include_flags,
   bool displayed = false;
   char new_help[256];
 
-  if (include_flags == CL_PARAMS)
-    {
-      for (i = 0; i < LAST_PARAM; i++)
-	{
-	  const char *param = compiler_params[i].option;
-
-	  help = compiler_params[i].help;
-	  if (help == NULL || *help == '\0')
-	    {
-	      if (exclude_flags & CL_UNDOCUMENTED)
-		continue;
-	      help = undocumented_msg;
-	    }
-
-	  /* Get the translation.  */
-	  help = _(help);
-
-	  if (!opts->x_quiet_flag)
-	    {
-	      snprintf (new_help, sizeof (new_help),
-			_("default %d minimum %d maximum %d"),
-			compiler_params[i].default_value,
-			compiler_params[i].min_value,
-			compiler_params[i].max_value);
-	      help = new_help;
-	    }
-	  wrap_help (help, param, strlen (param), columns);
-	}
-      putchar ('\n');
-      return;
-    }
-
   if (!opts->x_help_printed)
     opts->x_help_printed = XCNEWVAR (char, cl_options_count);
 
@@ -2241,10 +2209,6 @@ common_handle_option (struct gcc_options *opts,
 
   switch (code)
     {
-    case OPT__param:
-      handle_param (opts, opts_set, loc, arg);
-      break;
-
     case OPT__help:
       {
 	unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
diff --git a/gcc/params.def b/gcc/params.def
index 7928f6f071e..5a21f4d6f3f 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -44,10 +44,6 @@ along with GCC; see the file COPYING3.  If not see
 
 /* When branch is predicted to be taken with probability lower than this
    threshold (in percent), then it is considered well predictable. */
-DEFPARAM (PARAM_PREDICTABLE_BRANCH_OUTCOME,
-	  "predictable-branch-outcome",
-	  "Maximal estimated outcome of branch considered predictable.",
-	  2, 0, 50)
 
 DEFPARAM (PARAM_INLINE_MIN_SPEEDUP,
 	  "inline-min-speedup",
@@ -1085,12 +1081,6 @@ DEFPARAM (PARAM_MIN_NONDEBUG_INSN_UID,
 	  "The minimum UID to be used for a nondebug insn.",
 	  0, 0, 0)
 
-DEFPARAM (PARAM_IPA_SRA_PTR_GROWTH_FACTOR,
-	  "ipa-sra-ptr-growth-factor",
-	  "Maximum allowed growth of number and total size of new parameters "
-	  "that ipa-sra replaces a pointer to an aggregate with.",
-	  2, 0, 0)
-
 DEFPARAM (PARAM_IPA_SRA_MAX_REPLACEMENTS,
 	  "ipa-sra-max-replacements",
 	  "Maximum pieces that IPA-SRA tracks per formal parameter, as "
diff --git a/gcc/predict.c b/gcc/predict.c
index 915f0806b11..edb6920cfd5 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -412,9 +412,9 @@ predictable_edge_p (edge e)
   if (!e->probability.initialized_p ())
     return false;
   if ((e->probability.to_reg_br_prob_base ()
-       <= PARAM_VALUE (PARAM_PREDICTABLE_BRANCH_OUTCOME) * REG_BR_PROB_BASE / 100)
+       <= param_predictable_branch_outcome * REG_BR_PROB_BASE / 100)
       || (REG_BR_PROB_BASE - e->probability.to_reg_br_prob_base ()
-          <= PARAM_VALUE (PARAM_PREDICTABLE_BRANCH_OUTCOME) * REG_BR_PROB_BASE / 100))
+	  <= param_predictable_branch_outcome * REG_BR_PROB_BASE / 100))
     return true;
   return false;
 }
-- 
2.23.0

Reply via email to