[Patch, fortran] PR25746 - elemental subroutine dependency checking - redux
Paul Thomas
paulthomas2@wanadoo.fr
Fri Apr 21 18:29:00 GMT 2006
Dear All,
I should explain that Outlook normally seems to emit non-mime characters
that gnu-central does not like. Changing to plain text drops all
references to wrap around. I thought that I had it fixed but apparently
not. Sorry about that.
If this is screwed up, I will resubmit tonight.... well, here it is again.
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. It has been corrected to
be conformant (thanks, Dominique).
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
* gfortran.dg/elemental_subroutine_3.f90: New test.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: depends04.diff
Type: text/x-patch
Size: 9596 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20060421/99049523/attachment.bin>
More information about the Fortran
mailing list