[flang] [llvm] [Flang][OpenMP] Fix Fortran automap handling (PR #162501)

Abhinav Gaba via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 15 09:55:54 PDT 2025


abhinavgaba wrote:

I agree, please avoid the runtime changes. libomptarget should not need to internally detect descriptor shapes/sizes.

>Currently we map allocatables as a form of record type/C struct, where we have the descriptor as a parent, and the base address as a pointer map member that points to some data, like the below:
```
omptarget --> Entry 0: Base=0x00005e1e0039c0a0, Begin=0x00005e1e0039c0a0, Size=48, Type=0x0...
omptarget --> Entry 1: Base=0x00005e1e0039c0a0, Begin=0x00005e1e0039c0a0, Size=48, Type=0x1000000000001,...
omptarget --> Entry 2: Base=0x00005e1e0039c0a0, Begin=0x00005e1dfedc8c90, Size=8, Type=0x1000000000001, ...
omptarget --> Entry 3: Base=0x00005e1dfedc8c90, Begin=0x00005e1e0039c0a0, Size=40, Type=0x1000000000011, ...
```

Once Andrew's flang changes to use the ATTACH map-type in the codegen are upstreamed, then `automap(automap_array)` can just be translated into `map(alloc: automap_array(:))` on any `allocate` statement.

```
&pointee_of_automap_array, &pointee_of_automap_array, size_of_pointee, ALLOC
&descriptor_or_pointer_of_automap_array, &descriptor_or_pointer_of_automap_array, size_of_descriptor_or_pointer, ATTACH
```

Which would imply mapping the pointee data, and doing an attachment to a descriptor that's already present on the device using the ATTACH map-type bit. The ATTACH map-type already accepts the size of the descriptor as the size argument (the assumption it makes is that the pointee address is in the first field of the descriptor).


That way, the descriptor for the declare-target version of `automap_array` will get updated on device.

It is not correct to use `has_device_addr` to pass the value in, because `has_device_addr` only works for the lexical scope of the `target` construct. A `declare target` variable may be accessed in a `declare target` subroutine. So the device version of the descriptor has to be updated using the ATTACH map as shown above.

https://github.com/llvm/llvm-project/pull/162501


More information about the llvm-commits mailing list