[flang][OpenMP] Don't emit implicit default mapper for flat allocatable derived types (#209645)
An allocatable or pointer capture of a derived type in a `target` region
triggers
synthesis of an implicit default declare mapper for the type. The gate
keyed only on
whether the captured *variable* was allocatable, not on whether the
*type* needs a
mapper:
```cpp
if (!isPointer && (hasDefaultMapper || isAllocatable)) {
```
For a flat type -- all components trivially mappable, no
allocatable/pointer/nested
record members -- the mapper is unnecessary. The object maps as a plain
bulk copy.
Emitting a mapper anyway lowers to a per-element, per-component mapper
walk in the
offload runtime (`targetDataBegin` -> `targetDataMapper` ->
`targetDataBegin`, and the
mirror walk in `targetDataEnd`), which is `O(num_elements *
num_components)` per kernel
invocation. On a large device-resident allocatable array this busy-loops
the host for
minutes with the GPU idle.
`Fortran::lower::omp::requiresImplicitDefaultDeclareMapper()` already
answers whether a
type requires a mapper (allocatable/pointer/nested-record components, or
ISO-C interop),
but the allocatable-capture path never consulted it. This gates on it:
```cpp
if (!isPointer &&
(hasDefaultMapper ||
(isAllocatable && requiresImplicitDefaultDeclareMapper(*typeSpec)))) {
```
Pointer captures and user/pre-existing declare mappers are unaffected. A
flat allocatable
now maps as descriptor + base-address + attach entries with no
`mapper()` attribute --
identical to the pointer path.
### Reproducing the runtime cost
Reported against the AMD ROCm flang runtime as ROCm/llvm-project#3385. A
flat derived type
(`ghost_point`-like) in a device-resident allocatable array, mapped
implicitly across many
kernel invocations, hangs for minutes. `perf` on the hang shows all time
in per-component
work: `DenseMap` insert into the mapping-state tables, `targetDataEnd`'s
mirror walk, and
`SourceInfo` construction -- each `O(1)`/`O(log M)` per entry, so the
total is linear in
`M = num_elements * num_components * kernel_invocations` with a large
constant. Suppressing
the mapper collapses `M` to one bulk entry.
### Tests
- `implicit-map-flat-allocatable-no-mapper.f90`: new; a flat allocatable
capture emits no
mapper.
- `implicit-map-pointer-no-default-mapper.f90`: the type now has an
allocatable component
so it still requires a mapper (keeps the pointer-vs-allocatable
distinction meaningful).
- `derived-type-map.f90`, `defaultmap.f90`: updated; these asserted a
mapper for a flat
allocatable capture, which is the behavior being removed.
### AI tool usage
Per the [LLVM AI Tool Use
Policy](https://llvm.org/docs/AIToolPolicy.html): this change was
developed with substantial assistance from Claude (Opus 4.8) and
reviewed by the author. The
root-cause analysis, the patch, the tests, and this description were
AI-assisted; the reproducer
and the offload-runtime `gdb`/`perf` profiling on an AMD Instinct MI250X
(HPC Fund) that confirmed
the runtime cost is linear (not a runtime bug) were part of that
workflow. Also noted as an
`Assisted-by:` trailer in the commit.