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

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 05:49:14 PDT 2021


clementval created this revision.
clementval added reviewers: jeanPerier, svedanayagam, sscalpone, kiranchandramohan, jdoerfert, schweitz, pmccormick, rovka, AlexisPerry, PeteSteinfeld.
Herald added subscribers: Chia-hungDuan, mehdi_amini, rriddle.
Herald added a project: Flang.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer.
Herald added a project: LLVM.

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>

It is only possible to use `array_access` on an `array_load` result value.

This patch is part of the upstreaming effort from fir-dev branch.

Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112445

Files:
  flang/include/flang/Optimizer/Dialect/FIROps.td
  flang/lib/Optimizer/Dialect/FIROps.cpp
  flang/test/Fir/fir-ops.fir
  flang/test/Fir/invalid.fir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112445.381955.patch
Type: text/x-patch
Size: 5409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211025/eeccd754/attachment.bin>


More information about the llvm-commits mailing list