[PATCH] D112448: [fir] Add fir.array_amend operation definition
Valentin Clement via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 25 06:23:36 PDT 2021
clementval created this revision.
clementval added reviewers: jeanPerier, svedanayagam, sscalpone, kiranchandramohan, jdoerfert, schweitz, pmccormick, rovka, AlexisPerry, PeteSteinfeld.
Herald added subscribers: Chia-hungDuan, rriddle.
Herald added a project: Flang.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer.
Herald added a project: LLVM.
This patch adds the fir.array_amend operation. this op
is used later in upstreaming patches for the F95 <https://reviews.llvm.org/F95> compliance.
Marks an array value as having been changed via a reference. The reference
into the array value is obtained via an fir.array_access op.
mlir
// fetch the value of one of the array value's elements
%1 = fir.array_access %v, %i, %j : (!fir.array<?x?xT>, index, index) -> !fir.ref<T>
// modify the element by storing data using %1 as a reference
%2 = ... %1 ...
// mark the array value
%new_v = fir.array_amend %v, %2 : (!fir.array<?x?xT>, !fir.ref<T>) -> !fir.array<?x?xT>
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/D112448
Files:
flang/include/flang/Optimizer/Dialect/FIROps.td
flang/test/Fir/fir-ops.fir
Index: flang/test/Fir/fir-ops.fir
===================================================================
--- flang/test/Fir/fir-ops.fir
+++ flang/test/Fir/fir-ops.fir
@@ -710,3 +710,15 @@
// CHECK: %{{.*}} = fir.array_access %{{.*}}, %{{.*}}, %{{.*}} : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
return
}
+
+func @array_amend_ops(%a : !fir.ref<!fir.array<?x?xf32>>) {
+ %c1 = arith.constant 1 : index
+ %n = arith.constant 0 : index
+ %m = arith.constant 50 : index
+ %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
+ %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
+ %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
+ %res = fir.array_amend %v, %p : (!fir.array<?x?xf32>, !fir.ref<f32>) -> !fir.array<?x?xf32>
+ // CHECK: %{{.*}} = fir.array_amend %{{.*}}, %{{.*}} : (!fir.array<?x?xf32>, !fir.ref<f32>) -> !fir.array<?x?xf32>
+ return
+}
Index: flang/include/flang/Optimizer/Dialect/FIROps.td
===================================================================
--- flang/include/flang/Optimizer/Dialect/FIROps.td
+++ flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -1593,6 +1593,36 @@
let verifier = "return ::verify(*this);";
}
+def fir_ArrayAmendOp : fir_Op<"array_amend", [NoSideEffect]> {
+ let summary = "Mark an array value as having been changed by reference.";
+
+ let description = [{
+ Marks an array value as having been changed via a reference. The reference
+ into the array value is obtained via an fir.array_access op.
+
+ ```mlir
+ // fetch the value of one of the array value's elements
+ %1 = fir.array_access %v, %i, %j : (!fir.array<?x?xT>, index, index) -> !fir.ref<T>
+ // modify the element by storing data using %1 as a reference
+ %2 = ... %1 ...
+ // mark the array value
+ %new_v = fir.array_amend %v, %2 : (!fir.array<?x?xT>, !fir.ref<T>) -> !fir.array<?x?xT>
+ ```
+ }];
+
+ let arguments = (ins
+ fir_SequenceType:$sequence,
+ fir_ReferenceType:$memref
+ );
+
+ let results = (outs fir_SequenceType);
+
+ let assemblyFormat = [{
+ $sequence `,` $memref attr-dict `:` functional-type(operands, results)
+ }];
+}
+
+
def fir_ArrayMergeStoreOp : fir_Op<"array_merge_store",
[AttrSizedOperandSegments]> {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112448.381967.patch
Type: text/x-patch
Size: 2332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211025/3553a25e/attachment.bin>
More information about the llvm-commits
mailing list