This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/44856] Usage of array PARAMETERs: Literal copy vs. global variable



------- Comment #1 from burnus at gcc dot gnu dot org  2010-07-07 14:47 -------
My idea is:

a) For scalar expressions, generate simply always the scalar variable.

b) For array accesses, generate a const variable at the beginning of the
current block (subroutine, function, BLOCK) - if the variable is smaller than
"-farray-parameter-inline-limit" or if from an intrinsic module.

The trick for (b) is to collect this information in the symbol attribute (i.e.
not needed if never access or when only scalars are accessed). Additionally,
one needs to make sure that then in the current block the copied parameter is
accessed. I think a reasonable value for the limit could be something like 10,
20.

(I am actually not sure whether the FE does mark the module global parameters
variable as "restricted" or as constant. If one and if possible, one should do
so.)


An example. The trick is to make sure that  (ModulePara(1))  does not simply
generate, e.g., "D.1558 = modulepara[0];" which is pointless.


module m
  integer, parameter :: ModulePara(2) = [ 1, 2 ]
end module m

program test
  use m
  implicit none

  integer :: aaaa(2),i
  i=1

  aaaa = ModulePara         ! access modulepara (1)
  print *, ModulePara       ! access modulepara (2)
  print *, ModulePara(i)    ! access modulepara (3)
  print *, ModulePara(i)+i  ! access modulepara (4)
  print *, ModulePara(i)+1  ! access modulepara (5)

  aaaa(1) = (ModulePara(1)) ! use literal
  aaaa(1) = ModulePara(1)   ! use literal
  print *, ModulePara(1)    ! use literal
end program test

Dump contains the (correct!) six accesses to modulepara (5 + "extern").


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44856


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]