The array_access provides a reference to a single element from an array
value. This is *not* a view in the immutable array, otherwise it couldn't
be stored to. It can be see as a logical copy of the element and its
position in the array. This reference can be written to and modified without
changing the original array.
The array_access operation is used to fetch the memory reference of an
element in an array value.
fortran real :: a(n,m) ... ... a ... ... a(r,s+1) ...
One can use fir.array_access to recover the implied memory reference to
the element a(i,j) in an array expression a as shown above. It can also
be used to recover the reference element a(r,s+1) in the second
expression.
mlir %s = fir.shape %n, %m : (index, index) -> !fir.shape<2> // load the entire array 'a' %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32> // fetch the value of one of the array value's elements %1 = fir.array_access %v, %i, %j : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
More information about array_access and other array operations can be
found in flang/docs/FIRArrayOperations.md.
This patch is part of the upstreaming effort from fir-dev branch.
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Can this be verified in the verifier? Or is it too costly due to the transitive look up?