[patch, fortran] Function call optimization

Thomas Koenig tkoenig@netcologne.de
Sun Mar 20 17:10:00 GMT 2011


Hi Mikael,


> - Array elementals: here it's hard to tell which one is faster; save function
> calls to a temporary and use the temporary or do multiple function calls every
> time (but without temporary).

I have removed elementals for now. It would probably be best to create
a scalar temporary variable during scalarzation.

> - Transpose optimization: here the transpose call is changed into a direct
> array access, so your patch will definitely make things worse. Even if
> transpose calls are used multiple times as actual argument for example, better
> create multiple descriptors than copy the whole lot to a temp. The common
> function elimination should be disabled (IMO) in this case.

Removed for transpose.


> Please use more descriptive names.
> There are 3 cfe* functions and only one has a comment explaining what cfe
> means.

Changed.


> Is it expected that you allow allocatables with -faggressive-function-
> elimination?

No, changed.

>> +
>> +         if (!(*e)->value.function.esym->attr.pure
>> +&&  !(*e)->value.function.esym->attr.implicit_pure)
>> +           return 0;
>> +       }
>> +    }
>> +
>> +  if ((*e)->value.function.isym)
>> +    {
>> +      if ((*e)->value.function.isym->id == GFC_ISYM_CONVERSION)
>> +       return 0;
>> +
>> +      if (! (*e)->value.function.isym->pure
>> +&&  !(*e)->value.function.isym->elemental)
> Tobias' comment also applies here, even if there is no intrinsic impure
> elemental: the following code in intrinsic.c makes the elemental check
> redundant.
>        next_sym->pure = (cl != CLASS_IMPURE);
>        next_sym->elemental = (cl == CLASS_ELEMENTAL);

Changed.


>> +  for (i=expr_count-1; i>=1; i--)
>> +    {
> Tiny optimization here ;-):
> /* Don't bother if the expression has been factored already.  */

Applied.

> if ((*(expr_array[i]))->expr_type == EXPR_VARIABLE)
>    continue;
>> +      newvar = NULL;
>



 >> +
 > Small comment here, or better, more descriptive name
>> +static int
>> +cfe_code (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
>> +         void *data ATTRIBUTE_UNUSED)
>> +{

Better comment added.

I have also factored out the code with gfc_dep_compare_expression
into its own function.

Here is the new version of the patch.  Regression-tested.  OK for trunk?

	Thomas

2010-03-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/22572
	* gfortran.h (gfc_option_t) : Add
	flag_aggressive_function_elimination.
	(gfc_dep_compare_functions):  Add prototype.
	* lang.opt: Add faggressive-function-elimination.
	* invoke.texi: Document -faggressive-function-elimination.
	* frontend_passes (expr_array):  New static variable.
	(expr_size):  Likewise.
	(expr_count):  Likewise.
	(current_code):  Likewise.
	(current_ns):  Likewise.
	(gfc_run_passes):  Allocate and free space for expressions.
	(cfe_register_funcs):  New function.
	(create_var):  New function.
	(cfc_expr_0):  New function.
	(cfe_code):  New function.
	(optimize_namespace):  Invoke gfc_code_walker with cfe_code
	and cfe_expr_0.
	* dependency.c (gfc_dep_compare_functions):  New function.
	(gfc_dep_compare_expr):  Use it.
	* options.c (gfc_init_options):  Handle
	flag_aggressive_function_elimination.
	(gfc_handle_option):  Likewise.

2010-03-20  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/22572
	* gfortran.dg/function_optimize_1.f90:  New test.
	* gfortran.dg/function_optimize_2.f90:  New test.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: function_optimize_1.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20110320/e01045f6/attachment.f90>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: function_optimize_2.f90
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20110320/e01045f6/attachment-0001.f90>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p12.diff
Type: text/x-patch
Size: 13415 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20110320/e01045f6/attachment.bin>


More information about the Fortran mailing list