This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: [Fortran] Another array reference dependency improvement


On Sat, 4 Mar 2006, Paul Thomas wrote:
> The above breaks down for:
>
> forall (i=k:n)
> forall (j=1:5-i)
> a(i,j,:) = a(j,i,:)
> end forall
> end forall
>
> Take the case i = 1/ j= 2 - this puts a(2,1,:) into a(1:2,:). A bit
> later when i=2 and j=1, this is put back again. There is, therefore,
> a dependency for two constant indices.

Its been keeping me awake last night.  The problem is that fortran95's
array syntax is context sensitive, and therefore gfc_dependency needs
some form of state.

The statement

   a(i,j,:) = a(j,i,:)

has no dependencies outside of a FORALL context, or even inside a
FORALL nest that doesn't use i or j as iterating variables.
However, we need to some how inform gfc_check_element_vs_element
of which variables have been used in nested_forall_info, if we
want to take advantage of this potential optimization.

I can see two possible strategies.  (1). we build some data-structure
(or expose forall_info) and pass one in every call to dependency.c's
gfc_check_dependency, and pass it down through its recursive calls
and helper functions so that gfc_check_element_vs_element can do
something like

	if (i == -2)
	  return (contains_forall_index (r_start)
		  || constains_forall_index (lstart))
		 ? GFC_DEP_OVERLAP : GFC_DEP_EQUAL;

or (2) slightly cleaner but more intrusive, is that we provide
a bit in EXPR_VARIABLE, and annotate references to index variables
in the gstmt/gexpr parse tree.   This effectively treats FORALL
like a "scoping" statement, such that when we lookup the symbol
"i" or "j" inside a forall nest, the gfc_expr that we return
indicates whether it is truly a scalar variable or effectively
a subrange.

This latter approach avoids the need to pass down a linked list
of variables through gfc_dependency's call stack, and then scan
this list everytime we encounter a variable at a leaf.

Perhaps the gfortran maintainers could indicate which approach
they think is most appropriate.

Roger
--


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