http://gcc.gnu.org/ml/fortran/2007-02/msg00167.html
> > > From what I've seen, one of the main problems with Fortran and
> > > aliasing is the pass-by-reference rule in Fortran.  This often tricks 
> > > alias analysis into overstating the amount of call-clobbered variables.
> > Can we do something in the frontend to overcome the pass-by-reference
> > rule? Can some of the analysis be done where we have the information
> > and the variables be marked up ins some way?
> We need middle-end support to annotate function parameters as read-only
> and/or non-escaping.

Fortran allows to specify that certain arguments of procedures (functions and
subroutines) have "intent(in)", i.e. are not modified by the procedure, or to
be "intent(out)", i.e. their value on entry might be undefined.

Additionally, there exist PURE functions, which may not modify any of the
passed arguments nor global variables. This is actually also true for many
functions provided by the Fortran library, e.g. matrix products ("matmul()") or
dot_product()s; while for simple cases they are inlined, for more complicated
ones (e.g. several dimensions with strides) they are not but a call to the
Fortran library is generated.

Even if a temporary variable is created, one can do optimizations:
{
  real D.14354;
  D.14354 = foo; // Not needed for intent(out)
  bar(&D.14354);
  foo = D.14354; // Not needed for intent(in)
}

(In Fortran code: "call bar(foo)" where bar is defined, e.g., as:
"subroutine bar(a); real, intent(in) :: a")


-- 
           Summary: Support annotating function parameters as read-only
                    and/or non-escaping
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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

Reply via email to