handling array reshapes during array section analysis

Dave Lloyd <dave@occl-cam.demon.co.uk>
Wed, 28 Jun 1995 19:23:48 GMT

          From comp.compilers

Related articles
handling array reshapes during array section analysis mcintosh@rice.edu (1995-06-27)
handling array reshapes during array section analysis dave@occl-cam.demon.co.uk (Dave Lloyd) (1995-06-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Dave Lloyd <dave@occl-cam.demon.co.uk>
Keywords: Fortran, optimize
Organization: Compilers Central
References: 95-06-087
Date: Wed, 28 Jun 1995 19:23:48 GMT

Reshapes turn up a lot in practice if you try to design a high-level
Fortran 90 compiler rather than extending a traditional F77 compiler
- primarily all calls with assumed-size and explicit-shape dummy
arguments need a reshape on both sides of the interface. For much
the same reason, equivalence'd and common arrays all go through a
reshape.The only other typical usage of reshape is on array
constructors (which for some dumb reason only give you 1d arrays).

We do ALL array manipulations with descriptors a la APL (although we
are coming from an Algol 68 background - indeed the F90 compiler is
written in Algol 68 and shares a common backend with our A68
compiler!). As a descriptor operation, reshape is cheap for arrays
with more than a few elements but does generate additional baggage
around calls and procedure entry which is bulkier than the
traditional dont-care approach to arrays but makes little difference
to the run-time.

Rule: Avoid doing an elemental operation, particularly a copy!

However once everything is reduced to simple descriptor algebra, it
is not too hard to do some interprocedural static analysis and
determine useful properties such as contiguity of array sections,
storage scope, disjoint storage between arguments, etc. We have only
recently started to explore this class of optimisation and few
traditional codes get much advantage as procedures with array
arguments usually do a lot of internal processing before returning -
due I suspect to the large granularity imposed by Fortran procedures.
On the other hand new codes, particularly using user-defined
operators to create a more mathematical syntax for array operations
tend to do less work within a procedure - but here the codes tend to
use the new, clean and shape-preserving assumed-shape array dummy
arguments and pass either whole arrays or simple slices (a transpose
is quite common).

Dave Lloyd Email: Dave@occl-cam.demon.co.uk
Oxford and Cambridge Compilers Ltd Phone: (44) 1223 572074
55 Brampton Rd, Cambridge CB1 3HJ, UK

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.