Hi.

This is similar transformation for IPA passes. This time,
one needs to use opt_for_fn in order to get the right
parameter values.

@Martin, Honza:
There are last few remaining parameters which should use
opt_for_fn:

param_ipa_max_agg_items
param_ipa_cp_unit_growth
param_ipa_sra_max_replacements
param_max_speculative_devirt_maydefs

Can you please help me with these as it's in your code?

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2020-01-03  Martin Liska  <mli...@suse.cz>

        * auto-profile.c (auto_profile): Use opt_for_fn
        for a parameter.
        * ipa-cp.c (ipcp_lattice::add_value): Likewise.
        (propagate_vals_across_arith_jfunc): Likewise.
        (hint_time_bonus): Likewise.
        (incorporate_penalties): Likewise.
        (good_cloning_opportunity_p): Likewise.
        (perform_estimation_of_a_value): Likewise.
        (estimate_local_effects): Likewise.
        (ipcp_propagate_stage): Likewise.
        * ipa-fnsummary.c (decompose_param_expr): Likewise.
        (set_switch_stmt_execution_predicate): Likewise.
        (analyze_function_body): Likewise.
        * ipa-inline-analysis.c (offline_size): Likewise.
        * ipa-inline.c (early_inliner): Likewise.
        * ipa-prop.c (ipa_analyze_node): Likewise.
        (ipcp_transform_function): Likewise.
        * ipa-sra.c (process_scan_results): Likewise.
        (ipa_sra_summarize_function): Likewise.
        * params.opt: Rename ipcp-unit-growth to
        ipa-cp-unit-growth.  Add Optimization for various
        IPA-related parameters.
---
 gcc/auto-profile.c        |  3 ++-
 gcc/ipa-cp.c              | 44 +++++++++++++++++++++++----------------
 gcc/ipa-fnsummary.c       |  7 ++++---
 gcc/ipa-inline-analysis.c |  7 ++++---
 gcc/ipa-inline.c          |  6 ++++--
 gcc/ipa-prop.c            |  4 ++--
 gcc/ipa-sra.c             |  6 ++++--
 gcc/params.opt            | 34 +++++++++++++++---------------
 8 files changed, 63 insertions(+), 48 deletions(-)


diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index 6aca2f29022..c5e9f1336a7 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -1628,7 +1628,8 @@ auto_profile (void)
        function before annotation, so the profile inside bar@loc_foo2
        will be useful.  */
     autofdo::stmt_set promoted_stmts;
-    for (int i = 0; i < param_early_inliner_max_iterations; i++)
+    for (int i = 0; i < opt_for_fn (node->decl,
+				    param_early_inliner_max_iterations); i++)
       {
         if (!flag_value_profile_transformations
             || !autofdo::afdo_vpt_for_early_inline (&promoted_stmts))
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index 43c0d5a6706..def89471abb 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -1859,7 +1859,8 @@ ipcp_lattice<valtype>::add_value (valtype newval, cgraph_edge *cs,
 	return false;
       }
 
-  if (!unlimited && values_count == param_ipa_cp_value_list_size)
+  if (!unlimited && values_count == opt_for_fn (cs->caller->decl,
+						param_ipa_cp_value_list_size))
     {
       /* We can only free sources, not the values themselves, because sources
 	 of other values in this SCC might point to them.   */
@@ -1986,12 +1987,15 @@ propagate_vals_across_arith_jfunc (cgraph_edge *cs,
     {
       int i;
 
-      if (src_lat != dest_lat || param_ipa_cp_max_recursive_depth < 1)
+      int max_recursive_depth = opt_for_fn(cs->caller->decl,
+					   param_ipa_cp_max_recursive_depth);
+      if (src_lat != dest_lat || max_recursive_depth < 1)
 	return dest_lat->set_contains_variable ();
 
       /* No benefit if recursive execution is in low probability.  */
       if (cs->sreal_frequency () * 100
-	  <= ((sreal) 1) * param_ipa_cp_min_recursive_probability)
+	  <= ((sreal) 1) * opt_for_fn (cs->caller->decl,
+				       param_ipa_cp_min_recursive_probability))
 	return dest_lat->set_contains_variable ();
 
       auto_vec<ipcp_value<tree> *, 8> val_seeds;
@@ -2019,7 +2023,7 @@ propagate_vals_across_arith_jfunc (cgraph_edge *cs,
       /* Recursively generate lattice values with a limited count.  */
       FOR_EACH_VEC_ELT (val_seeds, i, src_val)
 	{
-	  for (int j = 1; j < param_ipa_cp_max_recursive_depth; j++)
+	  for (int j = 1; j < max_recursive_depth; j++)
 	    {
 	      tree cstval = get_val_across_arith_op (opcode, opnd1_type, opnd2,
 						     src_val, res_type);
@@ -3155,11 +3159,11 @@ devirtualization_time_bonus (struct cgraph_node *node,
 /* Return time bonus incurred because of HINTS.  */
 
 static int
-hint_time_bonus (ipa_hints hints)
+hint_time_bonus (cgraph_node *node, ipa_hints hints)
 {
   int result = 0;
   if (hints & (INLINE_HINT_loop_iterations | INLINE_HINT_loop_stride))
-    result += param_ipa_cp_loop_hint_bonus;
+    result += opt_for_fn (node->decl, param_ipa_cp_loop_hint_bonus);
   return result;
 }
 
@@ -3167,15 +3171,18 @@ hint_time_bonus (ipa_hints hints)
    cloning goodness evaluation, do so.  */
 
 static inline int64_t
-incorporate_penalties (ipa_node_params *info, int64_t evaluation)
+incorporate_penalties (cgraph_node *node, ipa_node_params *info,
+		       int64_t evaluation)
 {
   if (info->node_within_scc && !info->node_is_self_scc)
     evaluation = (evaluation
-		  * (100 - param_ipa_cp_recursion_penalty)) / 100;
+		  * (100 - opt_for_fn (node->decl,
+				       param_ipa_cp_recursion_penalty))) / 100;
 
   if (info->node_calling_single_call)
     evaluation = (evaluation
-		  * (100 - param_ipa_cp_single_call_penalty))
+		  * (100 - opt_for_fn (node->decl,
+				       param_ipa_cp_single_call_penalty)))
       / 100;
 
   return evaluation;
@@ -3197,6 +3204,7 @@ good_cloning_opportunity_p (struct cgraph_node *node, int time_benefit,
   gcc_assert (size_cost > 0);
 
   class ipa_node_params *info = IPA_NODE_REF (node);
+  int eval_threshold = opt_for_fn (node->decl, param_ipa_cp_eval_threshold);
   if (max_count > profile_count::zero ())
     {
       int factor = RDIV (count_sum.probability_in
@@ -3204,7 +3212,7 @@ good_cloning_opportunity_p (struct cgraph_node *node, int time_benefit,
 		         * 1000, REG_BR_PROB_BASE);
       int64_t evaluation = (((int64_t) time_benefit * factor)
 				    / size_cost);
-      evaluation = incorporate_penalties (info, evaluation);
+      evaluation = incorporate_penalties (node, info, evaluation);
 
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
@@ -3216,16 +3224,16 @@ good_cloning_opportunity_p (struct cgraph_node *node, int time_benefit,
 		 info->node_within_scc
 		   ? (info->node_is_self_scc ? ", self_scc" : ", scc") : "",
 		 info->node_calling_single_call ? ", single_call" : "",
-		 evaluation, param_ipa_cp_eval_threshold);
+		 evaluation, eval_threshold);
 	}
 
-      return evaluation >= param_ipa_cp_eval_threshold;
+      return evaluation >= eval_threshold;
     }
   else
     {
       int64_t evaluation = (((int64_t) time_benefit * freq_sum)
 				    / size_cost);
-      evaluation = incorporate_penalties (info, evaluation);
+      evaluation = incorporate_penalties (node, info, evaluation);
 
       if (dump_file && (dump_flags & TDF_DETAILS))
 	fprintf (dump_file, "     good_cloning_opportunity_p (time: %i, "
@@ -3235,9 +3243,9 @@ good_cloning_opportunity_p (struct cgraph_node *node, int time_benefit,
 		 info->node_within_scc
 		   ? (info->node_is_self_scc ? ", self_scc" : ", scc") : "",
 		 info->node_calling_single_call ? ", single_call" : "",
-		 evaluation, param_ipa_cp_eval_threshold);
+		 evaluation, eval_threshold);
 
-      return evaluation >= param_ipa_cp_eval_threshold;
+      return evaluation >= eval_threshold;
     }
 }
 
@@ -3375,7 +3383,7 @@ perform_estimation_of_a_value (cgraph_node *node, vec<tree> known_csts,
     time_benefit = base_time.to_int ()
       + devirtualization_time_bonus (node, known_csts, known_contexts,
 				     known_aggs)
-      + hint_time_bonus (hints)
+      + hint_time_bonus (node, hints)
       + removable_params_cost + est_move_cost;
 
   gcc_checking_assert (size >=0);
@@ -3430,7 +3438,7 @@ estimate_local_effects (struct cgraph_node *node)
 					 known_aggs, &size, &time,
 					 &base_time, &hints);
       time -= devirt_bonus;
-      time -= hint_time_bonus (hints);
+      time -= hint_time_bonus (node, hints);
       time -= removable_params_cost;
       size -= stats.n_calls * removable_params_cost;
 
@@ -3858,7 +3866,7 @@ ipcp_propagate_stage (class ipa_topo_info *topo)
   max_new_size = overall_size;
   if (max_new_size < param_large_unit_insns)
     max_new_size = param_large_unit_insns;
-  max_new_size += max_new_size * param_ipcp_unit_growth / 100 + 1;
+  max_new_size += max_new_size * param_ipa_cp_unit_growth / 100 + 1;
 
   if (dump_file)
     fprintf (dump_file, "\noverall_size: %li, max_new_size: %li\n",
diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c
index fa01cb6c083..7364f823efd 100644
--- a/gcc/ipa-fnsummary.c
+++ b/gcc/ipa-fnsummary.c
@@ -1324,7 +1324,7 @@ decompose_param_expr (struct ipa_func_body_info *fbi,
 		      struct agg_position_info *aggpos,
 		      expr_eval_ops *param_ops_p = NULL)
 {
-  int op_limit = param_ipa_max_param_expr_ops;
+  int op_limit = opt_for_fn (fbi->node->decl, param_ipa_max_param_expr_ops);
   int op_count = 0;
 
   if (param_ops_p)
@@ -1555,7 +1555,8 @@ set_switch_stmt_execution_predicate (struct ipa_func_body_info *fbi,
 
   auto_vec<std::pair<tree, tree> > ranges;
   tree type = TREE_TYPE (op);
-  int bound_limit = param_ipa_max_switch_predicate_bounds;
+  int bound_limit = opt_for_fn (fbi->node->decl,
+				param_ipa_max_switch_predicate_bounds);
   int bound_count = 0;
   wide_int vr_wmin, vr_wmax;
   value_range_kind vr_type = get_range_info (op, &vr_wmin, &vr_wmax);
@@ -2451,7 +2452,7 @@ analyze_function_body (struct cgraph_node *node, bool early)
 	  fbi.bb_infos = vNULL;
 	  fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun));
 	  fbi.param_count = count_formal_params (node->decl);
-	  fbi.aa_walk_budget = param_ipa_max_aa_steps;
+	  fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
 
 	  nonconstant_names.safe_grow_cleared
 	    (SSANAMES (my_function)->length ());
diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index eb42caeb7ae..39be56c8f76 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -455,9 +455,10 @@ offline_size (struct cgraph_node *node, ipa_size_summary *info)
          Take this into account.  */
       else if (DECL_COMDAT (node->decl)
 	       && node->can_remove_if_no_direct_calls_p ())
-	return (info->size
-		* (100 - param_comdat_sharing_probability)
-		+ 50) / 100;
+	{
+	  int prob = opt_for_fn (node->decl, param_comdat_sharing_probability);
+	  return info->size * (100 - prob + 50) / 100;
+	}
     }
   return 0;
 }
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 3b68fc47d01..96ce67d71a5 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -2967,7 +2967,8 @@ early_inliner (function *fun)
 	}
       /* We iterate incremental inlining to get trivial cases of indirect
 	 inlining.  */
-      while (iterations < param_early_inliner_max_iterations
+      while (iterations < opt_for_fn (node->decl,
+				      param_early_inliner_max_iterations)
 	     && early_inline_small_functions (node))
 	{
 	  timevar_push (TV_INTEGRATION);
@@ -2986,7 +2987,8 @@ early_inliner (function *fun)
 	      es->call_stmt_time
 		= estimate_num_insns (edge->call_stmt, &eni_time_weights);
 	    }
-	  if (iterations < param_early_inliner_max_iterations - 1)
+	  if (iterations < opt_for_fn (node->decl,
+				       param_early_inliner_max_iterations) - 1)
 	    ipa_update_overall_fn_summary (node);
 	  timevar_pop (TV_INTEGRATION);
 	  iterations++;
diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 035730d180d..9f80dd1f6a8 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -2876,7 +2876,7 @@ ipa_analyze_node (struct cgraph_node *node)
   fbi.bb_infos = vNULL;
   fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun));
   fbi.param_count = ipa_get_param_count (info);
-  fbi.aa_walk_budget = param_ipa_max_aa_steps;
+  fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
 
   for (struct cgraph_edge *cs = node->callees; cs; cs = cs->next_callee)
     {
@@ -5756,7 +5756,7 @@ ipcp_transform_function (struct cgraph_node *node)
   fbi.bb_infos = vNULL;
   fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun));
   fbi.param_count = param_count;
-  fbi.aa_walk_budget = param_ipa_max_aa_steps;
+  fbi.aa_walk_budget = opt_for_fn (node->decl, param_ipa_max_aa_steps);
 
   vec_safe_grow_cleared (descriptors, param_count);
   ipa_populate_param_decls (node, *descriptors);
diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c
index a051a9f2154..79b543fa934 100644
--- a/gcc/ipa-sra.c
+++ b/gcc/ipa-sra.c
@@ -2279,7 +2279,9 @@ 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_ipa_sra_ptr_growth_factor * cur_param_size;
+	  param_size_limit
+	    = opt_for_fn (node->decl,
+			  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))
 	{
@@ -2499,7 +2501,7 @@ ipa_sra_summarize_function (cgraph_node *node)
 	  bb_dereferences = XCNEWVEC (HOST_WIDE_INT,
 				      by_ref_count
 				      * last_basic_block_for_fn (fun));
-	  aa_walking_limit = param_ipa_max_aa_steps;
+	  aa_walking_limit = opt_for_fn (node->decl, param_ipa_max_aa_steps);
 	  scan_function (node, fun);
 
 	  if (dump_file)
diff --git a/gcc/params.opt b/gcc/params.opt
index 5d39244761a..094e04aae5e 100644
--- a/gcc/params.opt
+++ b/gcc/params.opt
@@ -83,7 +83,7 @@ Common Joined UInteger Var(param_case_values_threshold) Param Optimization
 The smallest number of different values for which it is best to use a jump-table instead of a tree of conditional branches, if 0, use the default for the machine.
 
 -param=comdat-sharing-probability=
-Common Joined UInteger Var(param_comdat_sharing_probability) Init(20) Param
+Common Joined UInteger Var(param_comdat_sharing_probability) Init(20) Param Optimization
 Probability that COMDAT function will be shared with different compilation unit.
 
 -param=cxx-max-namespaces-for-diagnostic-help=
@@ -191,35 +191,39 @@ Common Joined UInteger Var(param_integer_share_limit) Init(251) IntegerRange(2,
 The upper bound for sharing integer constants.
 
 -param=ipa-cp-eval-threshold=
-Common Joined UInteger Var(param_ipa_cp_eval_threshold) Init(500) Param
+Common Joined UInteger Var(param_ipa_cp_eval_threshold) Init(500) Param Optimization
 Threshold ipa-cp opportunity evaluation that is still considered beneficial to clone.
 
 -param=ipa-cp-loop-hint-bonus=
-Common Joined UInteger Var(param_ipa_cp_loop_hint_bonus) Init(64) Param
+Common Joined UInteger Var(param_ipa_cp_loop_hint_bonus) Init(64) Param Optimization
 Compile-time bonus IPA-CP assigns to candidates which make loop bounds or strides known.
 
 -param=ipa-cp-max-recursive-depth=
-Common Joined UInteger Var(param_ipa_cp_max_recursive_depth) Init(8) Param
+Common Joined UInteger Var(param_ipa_cp_max_recursive_depth) Init(8) Param Optimization
 Maximum depth of recursive cloning for self-recursive function.
 
 -param=ipa-cp-min-recursive-probability=
-Common Joined UInteger Var(param_ipa_cp_min_recursive_probability) Init(2) Param
+Common Joined UInteger Var(param_ipa_cp_min_recursive_probability) Init(2) Param Optimization
 Recursive cloning only when the probability of call being executed exceeds the parameter.
 
 -param=ipa-cp-recursion-penalty=
-Common Joined UInteger Var(param_ipa_cp_recursion_penalty) Init(40) IntegerRange(0, 100) Param
+Common Joined UInteger Var(param_ipa_cp_recursion_penalty) Init(40) IntegerRange(0, 100) Param Optimization
 Percentage penalty the recursive functions will receive when they are evaluated for cloning.
 
 -param=ipa-cp-single-call-penalty=
-Common Joined UInteger Var(param_ipa_cp_single_call_penalty) Init(15) IntegerRange(0, 100) Param
+Common Joined UInteger Var(param_ipa_cp_single_call_penalty) Init(15) IntegerRange(0, 100) Param Optimization
 Percentage penalty functions containing a single call to another function will receive when they are evaluated for cloning.
 
+-param=ipa-cp-unit-growth=
+Common Joined UInteger Var(param_ipa_cp_unit_growth) Init(10) Param
+How much can given compilation unit grow because of the interprocedural constant propagation (in percent).
+
 -param=ipa-cp-value-list-size=
-Common Joined UInteger Var(param_ipa_cp_value_list_size) Init(8) Param
+Common Joined UInteger Var(param_ipa_cp_value_list_size) Init(8) Param Optimization
 Maximum size of a list of values associated with each parameter for interprocedural constant propagation.
 
 -param=ipa-max-aa-steps=
-Common Joined UInteger Var(param_ipa_max_aa_steps) Init(25000) Param
+Common Joined UInteger Var(param_ipa_max_aa_steps) Init(25000) Param Optimization
 Maximum number of statements that will be visited by IPA formal parameter analysis based on alias analysis in any given function.
 
 -param=ipa-max-agg-items=
@@ -227,11 +231,11 @@ Common Joined UInteger Var(param_ipa_max_agg_items) Init(16) Param
 Maximum number of aggregate content items for a parameter in jump functions and lattices.
 
 -param=ipa-max-param-expr-ops=
-Common Joined UInteger Var(param_ipa_max_param_expr_ops) Init(10) Param
+Common Joined UInteger Var(param_ipa_max_param_expr_ops) Init(10) Param Optimization
 Maximum number of operations in a parameter expression that can be handled by IPA analysis.
 
 -param=ipa-max-switch-predicate-bounds=
-Common Joined UInteger Var(param_ipa_max_switch_predicate_bounds) Init(5) Param
+Common Joined UInteger Var(param_ipa_max_switch_predicate_bounds) Init(5) Param Optimization
 Maximal number of boundary endpoints of case ranges of switch statement used during IPA functoin summary generation.
 
 -param=ipa-sra-max-replacements=
@@ -239,13 +243,9 @@ Common Joined UInteger Var(param_ipa_sra_max_replacements) Init(8) IntegerRange(
 Maximum pieces that IPA-SRA tracks per formal parameter, as a consequence, also the maximum number of replacements of a formal parameter.
 
 -param=ipa-sra-ptr-growth-factor=
-Common Joined UInteger Var(param_ipa_sra_ptr_growth_factor) Init(2) Param
+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.
 
--param=ipcp-unit-growth=
-Common Joined UInteger Var(param_ipcp_unit_growth) Init(10) Param
-How much can given compilation unit grow because of the interprocedural constant propagation (in percent).
-
 -param=ira-loop-reserved-regs=
 Common Joined UInteger Var(param_ira_loop_reserved_regs) Init(2) Param Optimization
 The number of registers in each class kept unused by loop invariant motion.
@@ -423,7 +423,7 @@ Common Joined UInteger Var(param_max_dse_active_local_stores) Init(5000) Param O
 Maximum number of active local stores in RTL dead store elimination.
 
 -param=max-early-inliner-iterations=
-Common Joined UInteger Var(param_early_inliner_max_iterations) Init(1) Param
+Common Joined UInteger Var(param_early_inliner_max_iterations) Init(1) Param Optimization
 The maximum number of nested indirect inlining performed by early inliner.
 
 -param=max-fields-for-field-sensitive=

Reply via email to