[PATCH] D112445: [fir] Add fir.array_access op

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 3 16:19:54 PDT 2021


mehdi_amini added a comment.

> 3. `fir.array_access` provides a reference to a single element from an array. This is *not* a view in the immutable array, otherwise it couldn't be stored to. It can be thought of as a copy of the array element + the coordinate in the array. On its own this reference can be written to and modified without changing the array it comes from. Something unclear with this abstract model would be the lifetime of this new "object": but we could consider that this has the effect of an "alloca" and dies with the current scope.

To clarify how I see this, in pseudo C++ `%p = fir.array_access %v, %i, %j : (!fir.array<?x?xf32>, index) -> !fir.ref<f32>`

  struct 2d_float_array_access_ref {
    float value;
    int64_t coord[2]
  };
  #define ARRAY_ACCESS(array, i, j)  \
    2d_float_array_access_ref *p = (2d_float_array_access_ref)alloca(sizeof(2d_float_array_access_ref)); \
    p->value = array[i][j]; \
    p->coord[0] = i; \
    p->coord[1] = j; \
  
  #define STORE_REF(value, ref)  ref->value = value;
  #define LOAD_REF(value, ref)  ref->value;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112445/new/

https://reviews.llvm.org/D112445



More information about the llvm-commits mailing list