| 1 |
// Test hlfir.designate operation parse, verify (no errors), and unparse. |
| 2 |
|
| 3 |
// RUN: fir-opt %s | fir-opt | FileCheck %s |
| 4 |
|
| 5 |
// array(1) |
| 6 |
func.func @array_ref(%arg0 : !fir.ref<!fir.array<10xi32>>) { |
| 7 |
%c1 = arith.constant 1 : index |
| 8 |
%0 = hlfir.designate %arg0 (%c1) : (!fir.ref<!fir.array<10xi32>>, index) -> !fir.ref<i32> |
| 9 |
return |
| 10 |
} |
| 11 |
// CHECK-LABEL: func.func @array_ref( |
| 12 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10xi32>>) { |
| 13 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 14 |
// CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_1]]) : (!fir.ref<!fir.array<10xi32>>, index) -> !fir.ref<i32> |
| 15 |
|
| 16 |
// array(1, 2:3:4, 5) |
| 17 |
func.func @array_section(%arg0 : !fir.box<!fir.array<10x?x30xi32>>) { |
| 18 |
%c1 = arith.constant 1 : index |
| 19 |
%c2 = arith.constant 2 : index |
| 20 |
%c3 = arith.constant 3 : index |
| 21 |
%c4 = arith.constant 4 : index |
| 22 |
%c5 = arith.constant 5 : index |
| 23 |
%shape = fir.undefined !fir.shape<1> |
| 24 |
%0 = hlfir.designate %arg0 (%c1, %c2:%c3:%c4, %c5) shape %shape: (!fir.box<!fir.array<10x?x30xi32>>, index, index, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>> |
| 25 |
return |
| 26 |
} |
| 27 |
// CHECK-LABEL: func.func @array_section( |
| 28 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<10x?x30xi32>>) { |
| 29 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 30 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index |
| 31 |
// CHECK: %[[VAL_3:.*]] = arith.constant 3 : index |
| 32 |
// CHECK: %[[VAL_4:.*]] = arith.constant 4 : index |
| 33 |
// CHECK: %[[VAL_5:.*]] = arith.constant 5 : index |
| 34 |
// CHECK: %[[VAL_6:.*]] = fir.undefined !fir.shape<1> |
| 35 |
// CHECK: %[[VAL_7:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_1]], %[[VAL_2]]:%[[VAL_3]]:%[[VAL_4]], %[[VAL_5]]) shape %[[VAL_6]] : (!fir.box<!fir.array<10x?x30xi32>>, index, index, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xi32>> |
| 36 |
|
| 37 |
// array%comp |
| 38 |
func.func @component_ref(%arg0 : !fir.box<!fir.array<10x!fir.type<t{i:i32}>>>) { |
| 39 |
%shape = fir.undefined !fir.shape<1> |
| 40 |
%0 = hlfir.designate %arg0 {"i"} shape %shape: (!fir.box<!fir.array<10x!fir.type<t{i:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<10xi32>> |
| 41 |
return |
| 42 |
} |
| 43 |
// CHECK-LABEL: func.func @component_ref( |
| 44 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<10x!fir.type<t{i:i32}>>>) { |
| 45 |
// CHECK: %[[VAL_1:.*]] = fir.undefined !fir.shape<1> |
| 46 |
// CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_0]]{"i"} shape %[[VAL_1]] : (!fir.box<!fir.array<10x!fir.type<t{i:i32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<10xi32>> |
| 47 |
|
| 48 |
// array%array_comp(1) |
| 49 |
func.func @component_array_ref(%arg0 : !fir.box<!fir.array<10x!fir.type<t2{array_comp:!fir.array<100xi32>}>>>) { |
| 50 |
%c1 = arith.constant 1 : index |
| 51 |
%component_shape = fir.undefined !fir.shapeshift<1> |
| 52 |
%result_shape = fir.undefined !fir.shape<1> |
| 53 |
%0 = hlfir.designate %arg0 {"array_comp"}<%component_shape>(%c1) shape %result_shape : (!fir.box<!fir.array<10x!fir.type<t2{array_comp:!fir.array<100xi32>}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box<!fir.array<10xi32>> |
| 54 |
return |
| 55 |
} |
| 56 |
// CHECK-LABEL: func.func @component_array_ref( |
| 57 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<10x!fir.type<t2{array_comp:!fir.array<100xi32>}>>>) { |
| 58 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 59 |
// CHECK: %[[VAL_2:.*]] = fir.undefined !fir.shapeshift<1> |
| 60 |
// CHECK: %[[VAL_3:.*]] = fir.undefined !fir.shape<1> |
| 61 |
// CHECK: %[[VAL_4:.*]] = hlfir.designate %[[VAL_0]]{"array_comp"} <%[[VAL_2]]> (%[[VAL_1]]) shape %[[VAL_3]] : (!fir.box<!fir.array<10x!fir.type<t2{array_comp:!fir.array<100xi32>}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box<!fir.array<10xi32>> |
| 62 |
|
| 63 |
// char(3:4) |
| 64 |
func.func @substring(%arg0 : !fir.boxchar<1>) { |
| 65 |
%c2 = arith.constant 2 : index |
| 66 |
%c3 = arith.constant 3 : index |
| 67 |
%c4 = arith.constant 4 : index |
| 68 |
%0 = hlfir.designate %arg0 substr %c3, %c4 typeparams %c2: (!fir.boxchar<1>, index, index, index) -> !fir.boxchar<1> |
| 69 |
return |
| 70 |
} |
| 71 |
// CHECK-LABEL: func.func @substring( |
| 72 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>) { |
| 73 |
// CHECK: %[[VAL_1:.*]] = arith.constant 2 : index |
| 74 |
// CHECK: %[[VAL_2:.*]] = arith.constant 3 : index |
| 75 |
// CHECK: %[[VAL_3:.*]] = arith.constant 4 : index |
| 76 |
// CHECK: %[[VAL_4:.*]] = hlfir.designate %[[VAL_0]] substr %[[VAL_2]], %[[VAL_3]] typeparams %[[VAL_1]] : (!fir.boxchar<1>, index, index, index) -> !fir.boxchar<1> |
| 77 |
|
| 78 |
// char_array(3:4) |
| 79 |
func.func @array_substring(%arg0 : !fir.box<!fir.array<10x!fir.char<1,?>>>) { |
| 80 |
%c2 = arith.constant 2 : index |
| 81 |
%c3 = arith.constant 3 : index |
| 82 |
%c4 = arith.constant 4 : index |
| 83 |
%shape = fir.undefined !fir.shape<1> |
| 84 |
%0 = hlfir.designate %arg0 substr %c3, %c4 shape %shape typeparams %c2 : (!fir.box<!fir.array<10x!fir.char<1,?>>>, index, index, !fir.shape<1>, index) -> !fir.box<!fir.array<10x!fir.char<1,?>>> |
| 85 |
return |
| 86 |
} |
| 87 |
// CHECK-LABEL: func.func @array_substring( |
| 88 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<10x!fir.char<1,?>>>) { |
| 89 |
// CHECK: %[[VAL_1:.*]] = arith.constant 2 : index |
| 90 |
// CHECK: %[[VAL_2:.*]] = arith.constant 3 : index |
| 91 |
// CHECK: %[[VAL_3:.*]] = arith.constant 4 : index |
| 92 |
// CHECK: %[[VAL_4:.*]] = fir.undefined !fir.shape<1> |
| 93 |
// CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_0]] substr %[[VAL_2]], %[[VAL_3]] shape %[[VAL_4]] typeparams %[[VAL_1]] : (!fir.box<!fir.array<10x!fir.char<1,?>>>, index, index, !fir.shape<1>, index) -> !fir.box<!fir.array<10x!fir.char<1,?>>> |
| 94 |
|
| 95 |
func.func @real_part(%arg0 : !fir.ref<!fir.complex<4>>) { |
| 96 |
%0 = hlfir.designate %arg0 real : (!fir.ref<!fir.complex<4>>) -> !fir.ref<!fir.real<4>> |
| 97 |
return |
| 98 |
} |
| 99 |
// CHECK-LABEL: func.func @real_part( |
| 100 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.complex<4>>) { |
| 101 |
// CHECK: %[[VAL_1:.*]] = hlfir.designate %[[VAL_0]] real : (!fir.ref<!fir.complex<4>>) -> !fir.ref<!fir.real<4>> |
| 102 |
|
| 103 |
func.func @imag_part_mlir_complex(%arg0 : !fir.ref<complex<f32>>) { |
| 104 |
%0 = hlfir.designate %arg0 imag : (!fir.ref<complex<f32>>) -> !fir.ref<f32> |
| 105 |
return |
| 106 |
} |
| 107 |
// CHECK-LABEL: func.func @imag_part_mlir_complex( |
| 108 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<complex<f32>>) { |
| 109 |
// CHECK: %[[VAL_1:.*]] = hlfir.designate %[[VAL_0]] imag : (!fir.ref<complex<f32>>) -> !fir.ref<f32> |
| 110 |
|
| 111 |
// array%array_complex_comp(1)%im |
| 112 |
func.func @component_array_ref_cplx_part(%arg0 : !fir.box<!fir.array<10x!fir.type<t3{array_comp:!fir.array<100x!fir.complex<8>>}>>>) { |
| 113 |
%c1 = arith.constant 1 : index |
| 114 |
%component_shape = fir.undefined !fir.shapeshift<1> |
| 115 |
%result_shape = fir.undefined !fir.shape<1> |
| 116 |
%0 = hlfir.designate %arg0 {"array_comp"}<%component_shape>(%c1) imag shape %result_shape : (!fir.box<!fir.array<10x!fir.type<t3{array_comp:!fir.array<100x!fir.complex<8>>}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box<!fir.array<10x!fir.real<8>>> |
| 117 |
return |
| 118 |
} |
| 119 |
// CHECK-LABEL: func.func @component_array_ref_cplx_part( |
| 120 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<10x!fir.type<t3{array_comp:!fir.array<100x!fir.complex<8>>}>>>) { |
| 121 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 122 |
// CHECK: %[[VAL_2:.*]] = fir.undefined !fir.shapeshift<1> |
| 123 |
// CHECK: %[[VAL_3:.*]] = fir.undefined !fir.shape<1> |
| 124 |
// CHECK: %[[VAL_4:.*]] = hlfir.designate %[[VAL_0]]{"array_comp"} <%[[VAL_2]]> (%[[VAL_1]]) imag shape %[[VAL_3]] : (!fir.box<!fir.array<10x!fir.type<t3{array_comp:!fir.array<100x!fir.complex<8>>}>>>, !fir.shapeshift<1>, index, !fir.shape<1>) -> !fir.box<!fir.array<10x!fir.real<8>>> |
| 125 |
|
| 126 |
// pdt_array(1) |
| 127 |
func.func @pdt(%arg0 : !fir.box<!fir.array<?x!fir.type<pdt(param:i32){field:i32}>>>) { |
| 128 |
%c1 = arith.constant 1 : index |
| 129 |
%0 = hlfir.designate %arg0(%c1) typeparams %c1 : (!fir.box<!fir.array<?x!fir.type<pdt(param:i32){field:i32}>>>, index, index) -> !fir.box<!fir.type<pdt(param:i32){field:i32}>> |
| 130 |
return |
| 131 |
} |
| 132 |
// CHECK-LABEL: func.func @pdt( |
| 133 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.type<pdt(param:i32){field:i32}>>>) { |
| 134 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 135 |
// CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_1]]) typeparams %[[VAL_1]] : (!fir.box<!fir.array<?x!fir.type<pdt(param:i32){field:i32}>>>, index, index) -> !fir.box<!fir.type<pdt(param:i32){field:i32}>> |