How to express the fact that arguments don't escape?
Richard Guenther
richard.guenther@gmail.com
Sat Aug 15 10:12:00 GMT 2009
2009/8/15 Thomas Koenig <tkoenig@gcc.gnu.org>:
> On Sat, 2009-08-15 at 01:59 +0200, Tobias Schlüter wrote:
>> Hi,
>>
>> I reviewed some old discussions on argument passing, but I found nothing
>> which addressed a seemingly simple optimization for Fortran: what I
>> would like to see is a way to tell the compiler that a function argument
>> (which will be a pointer) will not have escaped after the function has
>> returned. I.e.
>> call f(i)
>> i = 1
>> call g(j) ! won't know about i
>> if (i != 1) then
>> can't happen
>> end if
>>
>> Is there a way to do this? Unless I'm mistaken, this assumption holds
>> for all non-POINTER arguments.
non-POINTER and non-TARGET arguments. TARGET arguments can
escape to global pointers or pointer return values.
> To stay within the current, C-centric framework of gcc, we'll need to do
> even more copying.
Yes, of course. With LTO IPA-SRA might do something about it. And yes,
being able to specify whether an argument escapes, whether it is read from
or written to would be useful - but tracking the information properly will cause
an overhead and thus it has to be carefully designed.
Richard.
> Compare
>
> $ cat g1.f90
> subroutine foo
> call f(i)
> i = 1
> call g(j)
> if (i /= 1) then
> call abort
> end if
> end subroutine foo
> $ gfortran -O2 -S -fdump-tree-optimized g1.f90
> $ cat g1.f90.133t.optimized
>
> ;; Function foo (foo_)
>
> foo ()
> {
> integer(kind=4) j;
> integer(kind=4) i;
> integer(kind=4) i.0;
>
> <bb 2>:
> f (&i);
> i = 1;
> g (&j);
> i.0_1 = i;
> if (i.0_1 != 1)
> goto <bb 3>;
> else
> goto <bb 4>;
>
> <bb 3>:
> _gfortran_abort ();
>
> <bb 4>:
> return;
>
> }
>
> with
>
> $ cat g2.f90
> subroutine foo
> call f(i_aux)
> i = i_aux
> i = 1
> call g(j)
> if (i /= 1) then
> call abort
> end if
> end subroutine foo
> $ gfortran -O2 -S -fdump-tree-optimized g2.f90
> $ cat g2.f90.133t.optimized
>
> ;; Function foo (foo_)
>
> foo ()
> {
> integer(kind=4) j;
> integer(kind=4) i_aux;
>
> <bb 2>:
> f (&i_aux);
> g (&j);
> return;
>
> }
>
>
>
More information about the Fortran
mailing list