Hi Jakub,
Jakub Jelinek wrote:
On Tue, Sep 10, 2024 at 12:19:33PM +0200, Tobias Burnus wrote:
Background: OpenMP states that for 'map(var)', all allocatable components
of 'var' will automatically also be mapped ('deep mapping').
Not a review, just a comment. This kind of recursive mapping is also
what needs to happen for declare mapper, so wonder if that shouldn't be
solved together; and some way to merge mappings of one field after another
with the same way if consecutive fields (with possibly some padding bits
in between) are mapped the same way.
In case mapping Fortran allocatable components, I do not see the padding
part. For 'map(var)' all of var is mapped, including all array
descriptors. We then need to map the allocated memory (fully, if an
array: all array elements) + do a pointer attach. And we need to handle
unallocated components.
That's different to 'mapper', which is more flexible on one hand - but
also really explicit. There is no hidden 'only if allocated do',
possibly except for zero-sized array sections or iterator steps.
The Fortran part also handles polymorphic variables, where it is only
known at runtime which components exist – which means that the whole
tree of mappings to do is unknown at compile time. For 'mapper' that
part is known.
[Granted, TR13 now explicitly does not permit mapping of polymorphic
variables as there are too many corner cases. But for 6.x it is planned
to re-add it.]
In any case, the Fortran allocatable-component mapping also needs to be
applied to the mapper (+ iterator) generated code — and it needs to come
last after all implicit mappings and remove-mapping optimizations. It
could be also be done as part of the mapper expansion.
* * *
Having said this, there might be well a useful common approach that
covers Fortran deep mapping, 'mapper' and 'iterator'.
But the current approaches don't use them. Namely, we have:
* The current Fortran deep mapper (as just posted) was ready in March
2022, https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591075.html
* The mapper patch (latest version) is at
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/629363.html –
albeit first bits date back to
https://gcc.gnu.org/pipermail/gcc-patches/2022-March/591983.html
* There is also an 'iterator' patch at
https://gcc.gnu.org/pipermail/gcc-patches/2024-September/662138.html –
albeit it lacks the 'mapper' part, which is WIP and needs for main the
patch 'mapper' of the previous bullet.
* * *
If we have a clear plan to to implement things, I am somewhat willing to
revise patches, if it makes sense.
But for that, a clear design is needed.
And, in any case, it would be good, if we could get all of the features
above into GCC 15: Fortran deep mapping, 'mapper' (+ target_update with
strides), 'iterator' [and some other backlog].
Tobias