Jean Perier 9f867a3c46 [flang][hlfir] Add assignment mask operations
Add hlfir.forall_mask, hlfir.where, and hlfir.elsewhere operations that
are operations that holds (optionally for hlfir.elsewhere) the
evaluation of a logical mask that controls the evaluation of nested
operations.

They allow representing Fortran forall control mask, as well as where
and eslewhere statements/constructs.

They use the OrderedAssignmentTreeOpInterface since they can all be used
inside Forall and their masks should be fully evaluated for all the
index-value set induced by parent Forall before any of the nested
operations in their body is evaluated.

I initially tried making them into a single operation with some attributes
to make a difference, but I felt this made the verifier/parser/printer and
usages messier/tricky compared to making three distinct operations that
represent the three Fortran feature in a vanilla way.

Differential Revision: https://reviews.llvm.org/D149754
2023-05-04 10:00:36 +02:00

29 lines
1.2 KiB
Plaintext

// Test hlfir.where operation parse, verify (no errors), and unparse.
// RUN: fir-opt %s | fir-opt | FileCheck %s
func.func @test_where(%mask: !fir.ref<!fir.array<10x!fir.logical<4>>>, %x: !fir.ref<!fir.array<10xf32>>, %y: !fir.box<!fir.array<?xf32>>) {
hlfir.where {
hlfir.yield %mask : !fir.ref<!fir.array<10x!fir.logical<4>>>
} do {
hlfir.region_assign {
hlfir.yield %y : !fir.box<!fir.array<?xf32>>
} to {
hlfir.yield %x : !fir.ref<!fir.array<10xf32>>
}
}
return
}
// CHECK-LABEL: func.func @test_where(
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10x!fir.logical<4>>>,
// CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.array<10xf32>>,
// CHECK-SAME: %[[VAL_2:.*]]: !fir.box<!fir.array<?xf32>>) {
// CHECK: hlfir.where {
// CHECK: hlfir.yield %[[VAL_0]] : !fir.ref<!fir.array<10x!fir.logical<4>>>
// CHECK: } do {
// CHECK: hlfir.region_assign {
// CHECK: hlfir.yield %[[VAL_2]] : !fir.box<!fir.array<?xf32>>
// CHECK: } to {
// CHECK: hlfir.yield %[[VAL_1]] : !fir.ref<!fir.array<10xf32>>
// CHECK: }
// CHECK: }