Skip to content

Commit 0226003

Browse files
committed
[flang] Update the description of !fir.coordinate_of
This change was suggested in one of the comments for https://reviews.llvm.org/D115333. Basically, the following usage is valid, but the current wording suggests otherwise: ``` %1 = fir.coordinate_of %a, %k : (!fir.ref<!fir.array<10 x 10 x i32>>, index) -> !fir.ref<!fir.array<10 x i32>> ``` A test is also added to better document this particular case. Differential revision: https://reviews.llvm.org/D115929
1 parent 7d19566 commit 0226003

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ def fir_CoordinateOp : fir_Op<"coordinate_of", [NoSideEffect]> {
16331633
Compute the internal coordinate address starting from a boxed value or
16341634
unboxed memory reference. Returns a memory reference. When computing the
16351635
coordinate of an array element, the rank of the array must be known and
1636-
the number of indexing expressions must equal the rank of the array.
1636+
the number of indexing expressions must not exceed the rank of the array.
16371637

16381638
This operation will apply the access map from a boxed value implicitly.
16391639

flang/test/Fir/convert-to-llvm.fir

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,11 +2471,11 @@ func @coordinate_array_known_size_1d(%arg0: !fir.ref<!fir.array<10 x i32>>, %arg
24712471

24722472
// -----
24732473

2474-
func @coordinate_array_known_size_2d(%arg0: !fir.ref<!fir.array<10 x 10 x i32>>, %arg1 : index, %arg2 : index) {
2474+
func @coordinate_array_known_size_2d_get_i32(%arg0: !fir.ref<!fir.array<10 x 10 x i32>>, %arg1 : index, %arg2 : index) {
24752475
%q = fir.coordinate_of %arg0, %arg1, %arg2 : (!fir.ref<!fir.array<10 x 10 x i32>>, index, index) -> !fir.ref<i32>
24762476
return
24772477
}
2478-
// CHECK-LABEL: llvm.func @coordinate_array_known_size_2d(
2478+
// CHECK-LABEL: llvm.func @coordinate_array_known_size_2d_get_i32(
24792479
// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr<array<10 x array<10 x i32>>>,
24802480
// CHECK-SAME: %[[VAL_1:.*]]: i64,
24812481
// CHECK-SAME: %[[VAL_2:.*]]: i64) {
@@ -2486,6 +2486,20 @@ func @coordinate_array_known_size_2d(%arg0: !fir.ref<!fir.array<10 x 10 x i32>>,
24862486

24872487
// -----
24882488

2489+
func @coordinate_array_known_size_2d_get_array(%arg0: !fir.ref<!fir.array<10 x 10 x i32>>, %arg1 : index) {
2490+
%q = fir.coordinate_of %arg0, %arg1 : (!fir.ref<!fir.array<10 x 10 x i32>>, index) -> !fir.ref<!fir.array<10 x i32>>
2491+
return
2492+
}
2493+
// CHECK-LABEL: llvm.func @coordinate_array_known_size_2d_get_array(
2494+
// CHECK-SAME: %[[VAL_0:.*]]: !llvm.ptr<array<10 x array<10 x i32>>>,
2495+
// CHECK-SAME: %[[VAL_1:.*]]: i64) {
2496+
// CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i64) : i64
2497+
// CHECK: %[[VAL_3:.*]] = llvm.getelementptr %[[VAL_0]][%[[VAL_2]], %[[VAL_1]]] : (!llvm.ptr<array<10 x array<10 x i32>>>, i64, i64) -> !llvm.ptr<array<10 x i32>>
2498+
// CHECK: llvm.return
2499+
// CHECK: }
2500+
2501+
// -----
2502+
24892503
// 5.2. `fir.derived`
24902504
func @coordinate_ref_derived(%arg0: !fir.ref<!fir.type<dervied_4{field_1:i32, field_2:i32}>>) {
24912505
%idx = fir.field_index field_2, !fir.type<dervied_4{field_1:i32, field_2:i32}>

0 commit comments

Comments
 (0)