[Patch, fortran] PR25746 - elemental subroutine dependency checking

THOMAS Paul Richard 169137 paul.richard.thomas@cea.fr
Fri Apr 21 11:34:00 GMT 2006


:ADDPATCH fortran :

I am going to take a risk that the leading brand mailer will come out right....for once!

If this is screwed up, I will resubmit tonight.

This patch fixes PR25746 by adding dependency checking to the translation of elemental subroutine calls.  Quite aside from the immediate need of the PR to ensure that user defined assignments work correctly, the standard requires that elemental subroutines produce the same result, independent of the loop order and this mandates the dependency checking.

The checking is accomplished by calling a new function gfc_conv_elemental_dependencies before starting the scalarizing body and calling the elemental subroutine itself.  This has the advantage that the loopinfo and the ss's for each actual argument are available and the information that they contain is used as much as possible.

The new function proceeds as follows:

It loops over the actual arguments and, if the INTENT is OUT or INOUT, it checks for dependency with each of the arguments that are not INTENT(OUT).  I have modified dependency.c(gfc_check_fncall_dependency) to prevent the argument expression from being checked against itself.

If there is a dependency, a temporary loopinfo is made, ready for the call to gfc_trans_create_temp_array.  This is done to prevent this function from resetting the loop and thereby necessitating the renormalisation of the ss->data.info's for each of the arguments.  Once the temporary is obtained, the descriptor is obtained afresh, so that the result can be correctly unpacked after the subroutine call.

In the case of an INTENT(INOUT) argument, the original data has to be packed and copied to the temporary.  I have signalled a TODO here; the potential creation of two temporaries could be eliminated and this is something that I intend to contribute after I have fixed the array TRANSFER intrinsic.  This will require a new library routine that can be employed here.  In the mean time, this patch works correctly (I hope!), even if it is a bit inefficient in a small number of cases.

As well as copying the packed data to the temporary used for the subroutine call, this part of the code frees the temporary potentially produced by internal_pack.

Following this, the scalarizer is satisfied by adding the offset for the temporary to the ss->data.info, using the loop index ranges.  Finally, the result is copied to the destination array and the temporary freed.

As well as testing the fix for the original PR, the testcase checks various kinds of assignment, including >1D arrays, and tests that INTENT(INOUT) arguments are correctly handled.

Regtested on FC5/Athlon.  OK for trunk and 4.1?

Paul

2006-04-21  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/25746
	dependency.c (gfc_check_fncall_dependency): Don't check other
	against itself.
	trans-stmt.c (gfc_conv_elemental_dependencies): New function.
	(gfc_trans_call): Call it.

2006-04-21  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/25746
	elemental_subroutine_3.f90: New test.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: depends04.diff
Type: application/octet-stream
Size: 9675 bytes
Desc: depends04.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20060421/737b8b9b/attachment.obj>


More information about the Gcc-patches mailing list