[Patch, fortran] [31..53/66] inline sum and product: Update the scalarizer.

Mikael Morin mikael.morin@sfr.fr
Thu Oct 27 23:35:00 GMT 2011


This part of the serie takes care of updating the scalarizer code once its
core structures have changed.
There are basically two kinds of changes:
 - for functions working on loops mostly one needs to take care of more than
   one loop. This is done by attaching a list of nested loops to every
   gfc_loopinfo struct and calling these functions recursively on every element
   of the list. (See patches 31 and 47..52).
 - for functions working mostly on arrays, one needs to take care of arrays
   slices scattered in more than one gfc_ss struct. This is done by adding
   nested_ss and parent pointers to walk upwards (towards outer loops) or
   downwards (towards inner loops) in the chain. Then the function can walk
   the chain to have a view of the whole array. See below for the
   gfc_trans_create_temp_array case. (See patches 40..44).
 - Hybrid functions. Of course most functions are not trivial enough to work
   on loops without looking at the arrays, or conversely working on a single
   array without using the loop information. For those hybrid functions, a
   combination of the above is used. A loop field is added to the gfc_ss structs
   so that there is no ambiguity (it's easy to make mistakes) to which loop the
   array slice belongs.

The case of gfc_trans_create_temp_array deserves a comment of its own.
For the expression 
  some_func(sum(a(:,:), 1))
the temporary created needs to be of rank 2 (i.e. it should be of the same size
as `a(1,:)', while for the expression
  sum(some_other_func(), 1)
it should have the same size as the full result of `some_other_func()'.
This shows that in the first case we want the temporary to be of the size of the
outer loop only, while for the second it should be of the combined size of
the outer and the inner loop. Thus, we can't guess temporary size by walking
loops downwards (from the outer to the inner loop), we have to walk upwards
(this is patch 46, with preliminaries 33 and 45).
The same convention has been used in all the functions requiring the same kind
of walk: walk from inner to outer.

Another important thing in gfc_trans_create_temp_array is the handling of
dimensions. In every gfc_ss struct, we have with the DIM array a mapping from
loop dimension to array dimension, but as we are setting temporary bounds with
loop bounds, we need to reverse that information (get the loop bounds from the
array dimension). If one wants to handle multiple loops one has to consider
every corresponding DIM array.
See patch 45 for details.

Sorry, this part is a big mess.

Patch 31    : Split gfc_conv_loop_setup.
Patch 32    : Clear specloop in gfc_trans_create_temp_array.
Patch 33    : Move condition out of loop in gfc_trans_create_temp_array.
Patch 34    : gfc_ss_info reference counting.
Patch 35..39: New gfc_ss::loop field.
Patch 40..43: New gfc_ss::parent field.
Patch 44    : New gfc_ss::nested_ss field.
Patch 45    : Update get_array_ref_dim.
Patch 46    : Update gfc_trans_create_temp_array.
Patch 47..48: New gfc_loopinfo::nested_loop field.
Patch 49..51: New gfc_loopinfo::parent field.
Patch 52    : Add preliminary code in outermost loop.
Patch 53    : Update gfc_trans_preloop_setup.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr43829-31..53.diff
Type: text/x-diff
Size: 52124 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111027/db7dc472/attachment.bin>


More information about the Gcc-patches mailing list