1 // Test hlfir.designate operation parse, verify (no errors), and unparse.
3 // RUN: fir-opt %s | fir-opt | FileCheck %s
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>
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>
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>>
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>>
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>>
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>>
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>>
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>>
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>
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>
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,?>>>
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,?>>>
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>>
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>>
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>
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>
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>>>
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>>>
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}>>
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}>>