1 // Test hlfir.elemental and hlfir.yield_element operation parse, verify
2 // (no errors), and unparse.
4 // RUN: fir-opt %s | fir-opt | FileCheck %s
6 func.func @numeric_type(%x: !fir.ref<!fir.array<10x20xi32>>, %y: !fir.ref<!fir.array<10x20xi32>>) {
7 %c10 = arith.constant 10 : index
8 %c20 = arith.constant 20 : index
9 %0 = fir.shape %c10, %c20 : (index, index) -> !fir.shape<2>
10 %3 = hlfir.elemental %0 : (!fir.shape<2>) -> !hlfir.expr<10x20xi32> {
11 ^bb0(%i: index, %j: index):
12 %4 = hlfir.designate %x (%i, %j) : (!fir.ref<!fir.array<10x20xi32>>, index, index) -> !fir.ref<i32>
13 %5 = hlfir.designate %y (%i, %j) : (!fir.ref<!fir.array<10x20xi32>>, index, index) -> !fir.ref<i32>
14 %6 = fir.load %4 : !fir.ref<i32>
15 %7 = fir.load %5 : !fir.ref<i32>
16 %8 = arith.addi %6, %7 : i32
17 hlfir.yield_element %8 : i32
21 // CHECK-LABEL: func.func @numeric_type(
22 // CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.ref<!fir.array<10x20xi32>>,
23 // CHECK-SAME: %[[VAL_1:[^:]*]]: !fir.ref<!fir.array<10x20xi32>>
24 // CHECK: %[[VAL_4:.*]] = fir.shape
25 // CHECK: %[[VAL_5:.*]] = hlfir.elemental %[[VAL_4]] : (!fir.shape<2>) -> !hlfir.expr<10x20xi32> {
26 // CHECK: ^bb0(%[[VAL_6:.*]]: index, %[[VAL_7:.*]]: index):
27 // CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_6]], %[[VAL_7]]) : (!fir.ref<!fir.array<10x20xi32>>, index, index) -> !fir.ref<i32>
28 // CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_1]] (%[[VAL_6]], %[[VAL_7]]) : (!fir.ref<!fir.array<10x20xi32>>, index, index) -> !fir.ref<i32>
29 // CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_8]] : !fir.ref<i32>
30 // CHECK: %[[VAL_11:.*]] = fir.load %[[VAL_9]] : !fir.ref<i32>
31 // CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_10]], %[[VAL_11]] : i32
32 // CHECK: hlfir.yield_element %[[VAL_12]] : i32
35 func.func @char_type(%x: !fir.box<!fir.array<?x!fir.char<1,?>>>, %n: index, %l : index, %l0 :index) {
36 %0 = fir.shape %n : (index) -> !fir.shape<1>
37 %3 = hlfir.elemental %0 typeparams %l : (!fir.shape<1>, index) -> !hlfir.expr<?x!fir.char<1,?>> {
39 %4 = hlfir.designate %x (%i) typeparams %l0 : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
40 %6 = hlfir.concat %4, %4 len %l : (!fir.boxchar<1>, !fir.boxchar<1>, index) -> !hlfir.expr<!fir.char<1,?>>
41 hlfir.yield_element %6 : !hlfir.expr<!fir.char<1,?>>
45 // CHECK-LABEL: func.func @char_type(
46 // CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.box<!fir.array<?x!fir.char<1,?>>>,
47 // CHECK-SAME: %[[VAL_1:[^:]*]]: index,
48 // CHECK-SAME: %[[VAL_2:[^:]*]]: index,
49 // CHECK-SAME: %[[VAL_3:[^:]*]]: index) {
50 // CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
51 // CHECK: %[[VAL_5:.*]] = hlfir.elemental %[[VAL_4]] typeparams %[[VAL_2]] : (!fir.shape<1>, index) -> !hlfir.expr<?x!fir.char<1,?>> {
52 // CHECK: ^bb0(%[[VAL_6:.*]]: index):
53 // CHECK: %[[VAL_7:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_6]]) typeparams %[[VAL_3]] : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
54 // CHECK: %[[VAL_8:.*]] = hlfir.concat %[[VAL_7]], %[[VAL_7]] len %[[VAL_2]] : (!fir.boxchar<1>, !fir.boxchar<1>, index) -> !hlfir.expr<!fir.char<1,?>>
55 // CHECK: hlfir.yield_element %[[VAL_8]] : !hlfir.expr<!fir.char<1,?>>
58 !pdt = !fir.type<pdt(param:i32){field:f32}>
59 func.func @parametrized_derived_transpose(%x: !fir.box<!fir.array<?x?x!pdt>>, %n: index, %m: index, %l: i32) {
60 %0 = fir.shape %m, %n : (index, index) -> !fir.shape<2>
61 %3 = hlfir.elemental %0 typeparams %l : (!fir.shape<2>, i32) -> !hlfir.expr<?x?x!pdt> {
62 ^bb0(%j: index, %i: index):
63 %4 = hlfir.designate %x (%j, %i) typeparams %l : (!fir.box<!fir.array<?x?x!pdt>>, index, index, i32) -> !fir.box<!pdt>
64 %5 = hlfir.as_expr %4 : (!fir.box<!pdt>) -> !hlfir.expr<!pdt>
65 hlfir.yield_element %5 : !hlfir.expr<!pdt>
69 // CHECK-LABEL: func.func @parametrized_derived_transpose(
70 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box
71 // CHECK-SAME: %[[VAL_3:[^:]*]]: i32
72 // CHECK: %[[VAL_4:.*]] = fir.shape
73 // CHECK: %[[VAL_5:.*]] = hlfir.elemental %[[VAL_4]] typeparams %[[VAL_3]] : (!fir.shape<2>, i32) -> !hlfir.expr<?x?x!fir.type<pdt(param:i32){field:f32}>> {
74 // CHECK: ^bb0(%[[VAL_6:.*]]: index, %[[VAL_7:.*]]: index):
75 // CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_6]], %[[VAL_7]]) typeparams %[[VAL_3]] : (!fir.box<!fir.array<?x?x!fir.type<pdt(param:i32){field:f32}>>>, index, index, i32) -> !fir.box<!fir.type<pdt(param:i32){field:f32}>>
76 // CHECK: %[[VAL_9:.*]] = hlfir.as_expr %[[VAL_8]] : (!fir.box<!fir.type<pdt(param:i32){field:f32}>>) -> !hlfir.expr<!fir.type<pdt(param:i32){field:f32}>>
77 // CHECK: hlfir.yield_element %[[VAL_9]] : !hlfir.expr<!fir.type<pdt(param:i32){field:f32}>>