diff mbox

[Patchv3] Control SRA and IPA-SRA by a param rather than MOVE_RATIO

Message ID 1415274813-4036-1-git-send-email-james.greenhalgh@arm.com
State New
Headers show

Commit Message

James Greenhalgh Nov. 6, 2014, 11:53 a.m. UTC
On Fri, Oct 31, 2014 at 10:46:12AM +0000, Richard Biener wrote:
> On Wed, Oct 29, 2014 at 3:39 PM, James Greenhalgh wrote:
> >> I suppose I could port any target with a definition of MOVE_RATIO to
> >> override the default parameter value in their option overriding code,
> >> but that makes this a very large patch set (many targets define
> >> MOVE_RATIO).
> >>
> >> Is this an avenue worth exploring? I agree the very special target
> >> hook is not ideal.
> >
> > Hi,
> >
> > Did you have any further thoughts on this? I'm still unable to come up
> > with a way to set these parameters which allows them to default to their
> > current (MOVE_RATIO derived) values.
> >
> > If the only way to make this work is to add code to
> > TARGET_OPTION_OVERRIDE for all targets that define MOVE_RATIO, then I
> > suppose I can do that, but I'd prefer a neater way to make it work, if
> > you can think of one.
>
> Maybe instead of putting the code in opts.c put it right before we call
> targetm.target_option.override () in toplev.c:process_options.  With
> a comment on why it cannot be in opts.c.

Ah, that makes sense. The (much simplified) patch then looks like
this...

Bootstrapped on x86_64, ARM and AArch64 with no issues.

OK?

Thanks,
James

---
gcc/

2014-11-06  James Greenhalgh  <james.greenhalgh@arm.com>

	* params.def (sra-max-scalarization-size-Ospeed): New.
	(sra-max-scalarization-size-Osize): Likewise.
	* doc/invoke.texi (sra-max-scalarization-size-Ospeed): Document.
	(sra-max-scalarization-size-Osize): Likewise.
	* toplev.c (process_options): Set default values for new
	parameters.
	* tree-sra.c (analyze_all_variable_accesses): Use new parameters.
	* targhooks.c (get_move_ratio): Remove static designator.
	* target.h (get_move_ratio): Declare.

Comments

Richard Biener Nov. 6, 2014, 2:10 p.m. UTC | #1
On Thu, Nov 6, 2014 at 12:53 PM, James Greenhalgh
<james.greenhalgh@arm.com> wrote:
>
> On Fri, Oct 31, 2014 at 10:46:12AM +0000, Richard Biener wrote:
>> On Wed, Oct 29, 2014 at 3:39 PM, James Greenhalgh wrote:
>> >> I suppose I could port any target with a definition of MOVE_RATIO to
>> >> override the default parameter value in their option overriding code,
>> >> but that makes this a very large patch set (many targets define
>> >> MOVE_RATIO).
>> >>
>> >> Is this an avenue worth exploring? I agree the very special target
>> >> hook is not ideal.
>> >
>> > Hi,
>> >
>> > Did you have any further thoughts on this? I'm still unable to come up
>> > with a way to set these parameters which allows them to default to their
>> > current (MOVE_RATIO derived) values.
>> >
>> > If the only way to make this work is to add code to
>> > TARGET_OPTION_OVERRIDE for all targets that define MOVE_RATIO, then I
>> > suppose I can do that, but I'd prefer a neater way to make it work, if
>> > you can think of one.
>>
>> Maybe instead of putting the code in opts.c put it right before we call
>> targetm.target_option.override () in toplev.c:process_options.  With
>> a comment on why it cannot be in opts.c.
>
> Ah, that makes sense. The (much simplified) patch then looks like
> this...
>
> Bootstrapped on x86_64, ARM and AArch64 with no issues.
>
> OK?

Ok.

Thanks,
Richard.

> Thanks,
> James
>
> ---
> gcc/
>
> 2014-11-06  James Greenhalgh  <james.greenhalgh@arm.com>
>
>         * params.def (sra-max-scalarization-size-Ospeed): New.
>         (sra-max-scalarization-size-Osize): Likewise.
>         * doc/invoke.texi (sra-max-scalarization-size-Ospeed): Document.
>         (sra-max-scalarization-size-Osize): Likewise.
>         * toplev.c (process_options): Set default values for new
>         parameters.
>         * tree-sra.c (analyze_all_variable_accesses): Use new parameters.
>         * targhooks.c (get_move_ratio): Remove static designator.
>         * target.h (get_move_ratio): Declare.
diff mbox

Patch

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 792f25b..fcc5c89 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -10403,6 +10403,16 @@  parameters only when their cumulative size is less or equal to
 @option{ipa-sra-ptr-growth-factor} times the size of the original
 pointer parameter.
 
+@item sra-max-scalarization-size-Ospeed
+@item sra-max-scalarization-size-Osize
+The two Scalar Reduction of Aggregates passes (SRA and IPA-SRA) aim to
+replace scalar parts of aggregates with uses of independent scalar
+variables.  These parameters control the maximum size, in storage units,
+of aggregate which will be considered for replacement when compiling for
+speed
+(@option{sra-max-scalarization-size-Ospeed}) or size
+(@option{sra-max-scalarization-size-Osize}) respectively.
+
 @item tm-max-aggregate-size
 When making copies of thread-local variables in a transaction, this
 parameter specifies the size in bytes after which variables are
diff --git a/gcc/params.def b/gcc/params.def
index beff7e6..7cba3b3 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -950,6 +950,18 @@  DEFPARAM (PARAM_TM_MAX_AGGREGATE_SIZE,
 	  "pairs",
 	  9, 0, 0)
 
+DEFPARAM (PARAM_SRA_MAX_SCALARIZATION_SIZE_SPEED,
+	  "sra-max-scalarization-size-Ospeed",
+	  "Maximum size, in storage units, of an aggregate which should be "
+	  "considered for scalarization when compiling for speed",
+	  0, 0, 0)
+
+DEFPARAM (PARAM_SRA_MAX_SCALARIZATION_SIZE_SIZE,
+	  "sra-max-scalarization-size-Osize",
+	  "Maximum size, in storage units, of an aggregate which should be "
+	  "considered for scalarization when compiling for size",
+	  0, 0, 0)
+
 DEFPARAM (PARAM_IPA_CP_VALUE_LIST_SIZE,
 	  "ipa-cp-value-list-size",
 	  "Maximum size of a list of values associated with each parameter for "
diff --git a/gcc/target.h b/gcc/target.h
index 40d7841..65250ed 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -102,6 +102,10 @@  extern int elf_record_gcc_switches (print_switch_type type, const char *);
    we disable such optimizations on such targets, using this function.  */
 extern bool target_default_pointer_address_modes_p (void);
 
+/* For hooks which use the MOVE_RATIO macro, this gives the legacy default
+   behaviour.  */
+extern unsigned int get_move_ratio (bool);
+
 struct stdarg_info;
 struct spec_info_def;
 struct hard_reg_set_container;
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index eef3d45..d798217 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1409,7 +1409,7 @@  default_register_move_cost (machine_mode mode ATTRIBUTE_UNUSED,
 /* For hooks which use the MOVE_RATIO macro, this gives the legacy default
    behaviour.  SPEED_P is true if we are compiling for speed.  */
 
-static unsigned int
+unsigned int
 get_move_ratio (bool speed_p ATTRIBUTE_UNUSED)
 {
   unsigned int move_ratio;
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 2c570d4..71589f2 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1265,6 +1265,20 @@  process_options (void)
      so we can correctly initialize debug output.  */
   no_backend = lang_hooks.post_options (&main_input_filename);
 
+  /* Set default values for parameters relation to the Scalar Reduction
+     of Aggregates passes (SRA and IP-SRA).  We must do this here, rather
+     than in opts.c:default_options_optimization as historically these
+     tuning heuristics have been based on MOVE_RATIO, which on some
+     targets requires other symbols from the backend.  */
+  maybe_set_param_value
+    (PARAM_SRA_MAX_SCALARIZATION_SIZE_SPEED,
+     get_move_ratio (true) * UNITS_PER_WORD,
+     global_options.x_param_values, global_options_set.x_param_values);
+  maybe_set_param_value
+    (PARAM_SRA_MAX_SCALARIZATION_SIZE_SIZE,
+     get_move_ratio (false) * UNITS_PER_WORD,
+     global_options.x_param_values, global_options_set.x_param_values);
+
   /* Some machines may reject certain combinations of options.  */
   targetm.target_option.override ();
 
diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c
index b723ca5..1e629bc 100644
--- a/gcc/tree-sra.c
+++ b/gcc/tree-sra.c
@@ -2511,10 +2511,12 @@  analyze_all_variable_accesses (void)
   int res = 0;
   bitmap tmp = BITMAP_ALLOC (NULL);
   bitmap_iterator bi;
-  unsigned i, max_total_scalarization_size;
-
-  max_total_scalarization_size = UNITS_PER_WORD * BITS_PER_UNIT
-    * MOVE_RATIO (optimize_function_for_speed_p (cfun));
+  unsigned i;
+  unsigned max_scalarization_size
+    = (optimize_function_for_size_p (cfun)
+	? PARAM_VALUE (PARAM_SRA_MAX_SCALARIZATION_SIZE_SIZE)
+	: PARAM_VALUE (PARAM_SRA_MAX_SCALARIZATION_SIZE_SPEED))
+      * BITS_PER_UNIT;
 
   EXECUTE_IF_SET_IN_BITMAP (candidate_bitmap, 0, i, bi)
     if (bitmap_bit_p (should_scalarize_away_bitmap, i)
@@ -2526,7 +2528,7 @@  analyze_all_variable_accesses (void)
 	    && type_consists_of_records_p (TREE_TYPE (var)))
 	  {
 	    if (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var)))
-		<= max_total_scalarization_size)
+		<= max_scalarization_size)
 	      {
 		completely_scalarize_var (var);
 		if (dump_file && (dump_flags & TDF_DETAILS))