Possible Front End optimization - remove entities USEd from module but not really used.
Toon Moene
toon@moene.org
Mon Jan 7 18:41:00 GMT 2013
Consider the following example:
$ cat loc-nomod.f
module noot
real :: x(10), y(5), z(16)
end module noot
program doit
use noot
common /aap/ a(2), b(10), c(16)
real :: f(6), g(3), h(10)
real, allocatable :: s(:), t(:), u(:)
locmod(r) = mod(loc(r),32)
allocate(s(3),t(10),u(13))
! print *,locmod(x(1)),locmod(y(1)),locmod(z(1))
print *,locmod(a(1)),locmod(b(1)),locmod(c(1))
print *,locmod(f(1)),locmod(g(1)),locmod(h(1))
print *,locmod(s(1)),locmod(t(1)),locmod(u(1))
end
which I originally used to study default aligned for arrays of various
origins (module, common, local variable, allocatable.
I commented out the arrays USEd from a module. However, both with and
without -ffrontend-optimize (using 4.7.2),
gfortran -Ofast -g -c -fdump-fortran-original loc-nomod.f
showed the following in the output:
symtree: 'x' || symbol: 'x'
type spec : (REAL 4)
attributes: (VARIABLE IMPLICIT-SAVE DIMENSION USE-ASSOC(noot))
Array spec:(1 [0] AS_EXPLICIT 1 10 )
symtree: 'y' || symbol: 'y'
type spec : (REAL 4)
attributes: (VARIABLE IMPLICIT-SAVE DIMENSION USE-ASSOC(noot))
Array spec:(1 [0] AS_EXPLICIT 1 5 )
symtree: 'z' || symbol: 'z'
type spec : (REAL 4)
attributes: (VARIABLE IMPLICIT-SAVE DIMENSION USE-ASSOC(noot))
Array spec:(1 [0] AS_EXPLICIT 1 16 )
Surely, those could be removed, speeding up the compilation process
(later on, middle end optimizations probably can't get rid of them), and
possibly helping optimization passes by removing clutter and extra
entities which count against the various *max*=<number> limits.
Such an optimization could also help to produce various useful warning
messages, like:
<x> is in module <m>, but not referenced in subprogram <y>
<x> is in module <m>, used as <xx>, but not referenced in subprogram <y>
or, in case only a few entities are referenced from a USEd module:
Few entities from module <m> are used, suggest USE <m>, ONLY: <x>, <y>, <z>
with a (default) cutoff of e.g., 10 entities.
Would that be useful ?
--
Toon Moene - e-mail: toon@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
Progress of GNU Fortran: http://gcc.gnu.org/wiki/GFortran#news
More information about the Fortran
mailing list