[Flang][OpenMP] Adjust Flang OpenMP lowering to handle zero sized arrays as mappings#2736
[Flang][OpenMP] Adjust Flang OpenMP lowering to handle zero sized arrays as mappings#2736agozillon wants to merge 1 commit into
Conversation
| llvm::Value *sizeCalc = builder.CreateMul( | ||
| elementCount, builder.getInt64(underlyingTypeSzInBits / 8), | ||
| "element_count"); |
There was a problem hiding this comment.
The multiplication does not seem needed. Whether it's a zero-length array can be determined by inspecting the number of elements; their type is not relevant.
There was a problem hiding this comment.
Whilst entirely true, I think you need to remember that this function isn't specifically for checking zero-length arrays, it's also for calculating every other types size, including regular arrays and allocatable/pointer arrays with an actual defined size, of N-dimensions, and it also needs to continue to function for C/C++ types in the future which do not come packaged with the nice (annoying) descriptor.
So, we could add more complicated logic (if bounds extent is appropriately set to look at the correct descriptor field, which I think it is, but it's been a while) but that would add more instructions to the LLVM-IR and complicate the logic inside of this function specifically for this one case which doesn't seem worth while :-)
Edit: Basically trying to keep the calculation generic and open to C/C++ (CIR) usage, but I think ideally in the future we might let the respective lowering's (CIR/FIR) dictate how the calculations are handled and we just grab an SSA at this level and use it.
…ays as mappings In this PR we are teaching the compiler to map the 1-byte that the runtime allocates for zero-sized arrays, so that the data is counted as resident for presence check purposes. This is OpenMP specification compliant. The 1-byte on device shouldn't matter for later reallocations as users to stay compliant with the speciifcation MUST deallocate mapped data via an exit before modifying it in any way, e.g. resizing it, pointing it elsewhere asn so on. Otherwise it's non conformant code. The Fortran specification also protects us somewhat from this scenario as to resize a zero sized array you have to deallocate and then reallocate it, and assignment resizing also likely goes through the reallocation process under the hood. We also add presence checking to the descriptor as well as the base address, so we verify if both are present on device now. This should also apply to all presence checking for ref_ptr/ptee/ref_ptr_ptee as well.
2a873a3 to
1ef5e59
Compare
In this PR we are teaching the compiler to map the 1-byte that the runtime allocates for zero-sized arrays, so that the data is counted as resident for presence check purposes. This is OpenMP specification compliant.
The 1-byte on device shouldn't matter for later reallocations as users to stay compliant with the speciifcation MUST deallocate mapped data via an exit before modifying it in any way, e.g. resizing it, pointing it elsewhere asn so on. Otherwise it's non conformant code. The Fortran specification also protects us somewhat from this scenario as to resize a zero sized array you have to deallocate and then reallocate it, and assignment resizing also likely goes through the reallocation process under the hood.
We also add presence checking to the descriptor as well as the base address, so we verify if both are present on device now. This should also apply to all presence checking for ref_ptr/ptee/ref_ptr_ptee as well.