| 1 |
// Test hlfir.declare operation parse, verify (no errors), and unparse. |
| 2 |
|
| 3 |
// RUN: fir-opt %s | fir-opt | FileCheck %s |
| 4 |
|
| 5 |
func.func @numeric_declare(%arg0: !fir.ref<f32>) { |
| 6 |
%0:2 = hlfir.declare %arg0 {uniq_name = "x"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 7 |
return |
| 8 |
} |
| 9 |
// CHECK-LABEL: func.func @numeric_declare( |
| 10 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32>) { |
| 11 |
// CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {uniq_name = "x"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>) |
| 12 |
|
| 13 |
|
| 14 |
func.func @char_declare(%arg0: !fir.boxchar<1> ) { |
| 15 |
%0:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index) |
| 16 |
%1:2 = hlfir.declare %0#0 typeparams %0#1 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>) |
| 17 |
return |
| 18 |
} |
| 19 |
// CHECK-LABEL: func.func @char_declare( |
| 20 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1>) { |
| 21 |
// CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index) |
| 22 |
// CHECK: %[[VAL_2:.*]] = hlfir.declare %[[VAL_1]]#0 typeparams %[[VAL_1]]#1 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>) |
| 23 |
|
| 24 |
|
| 25 |
func.func @derived_declare(%arg0: !fir.ref<!fir.type<t{field:i32}>>) { |
| 26 |
%0:2 = hlfir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.type<t{field:i32}>>) -> (!fir.ref<!fir.type<t{field:i32}>>, !fir.ref<!fir.type<t{field:i32}>>) |
| 27 |
return |
| 28 |
} |
| 29 |
// CHECK-LABEL: func.func @derived_declare( |
| 30 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t{field:i32}>>) { |
| 31 |
// CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {uniq_name = "x"} : (!fir.ref<!fir.type<t{field:i32}>>) -> (!fir.ref<!fir.type<t{field:i32}>>, !fir.ref<!fir.type<t{field:i32}>>) |
| 32 |
|
| 33 |
|
| 34 |
func.func @pdt_declare(%arg0: !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) { |
| 35 |
%c1 = arith.constant 1 : index |
| 36 |
%0:2 = hlfir.declare %arg0 typeparams %c1 {uniq_name = "x"} : (!fir.ref<!fir.type<pdt(param:i32){field:i32}>>, index) -> (!fir.box<!fir.type<pdt(param:i32){field:i32}>>, !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) |
| 37 |
return |
| 38 |
} |
| 39 |
// CHECK-LABEL: func.func @pdt_declare( |
| 40 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) { |
| 41 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 42 |
// CHECK: %[[VAL_2:.*]] = hlfir.declare %[[VAL_0]] typeparams %[[VAL_1]] {uniq_name = "x"} : (!fir.ref<!fir.type<pdt(param:i32){field:i32}>>, index) -> (!fir.box<!fir.type<pdt(param:i32){field:i32}>>, !fir.ref<!fir.type<pdt(param:i32){field:i32}>>) |
| 43 |
|
| 44 |
|
| 45 |
func.func @array_declare(%arg0: !fir.ref<!fir.array<?x?xf32>>) { |
| 46 |
%c1 = arith.constant 1 : index |
| 47 |
%c2 = arith.constant 2 : index |
| 48 |
%shape = fir.shape %c1, %c2 : (index, index) -> !fir.shape<2> |
| 49 |
%0:2 = hlfir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>) |
| 50 |
return |
| 51 |
} |
| 52 |
// CHECK-LABEL: func.func @array_declare( |
| 53 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<?x?xf32>>) { |
| 54 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 55 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index |
| 56 |
// CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shape<2> |
| 57 |
// CHECK: %[[VAL_4:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>) |
| 58 |
|
| 59 |
|
| 60 |
func.func @array_declare_2(%arg0: !fir.ref<!fir.array<?x?xf32>>) { |
| 61 |
%c1 = arith.constant 1 : index |
| 62 |
%c2 = arith.constant 2 : index |
| 63 |
%c3 = arith.constant 3 : index |
| 64 |
%c4 = arith.constant 4 : index |
| 65 |
%shape = fir.shape_shift %c1, %c2, %c3, %c4 : (index, index, index, index) -> !fir.shapeshift<2> |
| 66 |
%0:2 = hlfir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>) |
| 67 |
return |
| 68 |
} |
| 69 |
// CHECK-LABEL: func.func @array_declare_2( |
| 70 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<?x?xf32>>) { |
| 71 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 72 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index |
| 73 |
// CHECK: %[[VAL_3:.*]] = arith.constant 3 : index |
| 74 |
// CHECK: %[[VAL_4:.*]] = arith.constant 4 : index |
| 75 |
// CHECK: %[[VAL_5:.*]] = fir.shape_shift %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (index, index, index, index) -> !fir.shapeshift<2> |
| 76 |
// CHECK: %[[VAL_6:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_5]]) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.ref<!fir.array<?x?xf32>>) |
| 77 |
|
| 78 |
func.func @array_declare_constant_extents_with_lower_bounds(%arg0: !fir.ref<!fir.array<2x4xf32>>) { |
| 79 |
%c1 = arith.constant 1 : index |
| 80 |
%c2 = arith.constant 2 : index |
| 81 |
%c3 = arith.constant 3 : index |
| 82 |
%c4 = arith.constant 4 : index |
| 83 |
%shape = fir.shape_shift %c1, %c2, %c3, %c4 : (index, index, index, index) -> !fir.shapeshift<2> |
| 84 |
%0:2 = hlfir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<2x4xf32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<2x4xf32>>, !fir.ref<!fir.array<2x4xf32>>) |
| 85 |
return |
| 86 |
} |
| 87 |
// CHECK-LABEL: func.func @array_declare_constant_extents_with_lower_bounds( |
| 88 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<2x4xf32>>) { |
| 89 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 90 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index |
| 91 |
// CHECK: %[[VAL_3:.*]] = arith.constant 3 : index |
| 92 |
// CHECK: %[[VAL_4:.*]] = arith.constant 4 : index |
| 93 |
// CHECK: %[[VAL_5:.*]] = fir.shape_shift %[[VAL_1]], %[[VAL_2]], %[[VAL_3]], %[[VAL_4]] : (index, index, index, index) -> !fir.shapeshift<2> |
| 94 |
// CHECK: %[[VAL_6:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_5]]) {uniq_name = "x"} : (!fir.ref<!fir.array<2x4xf32>>, !fir.shapeshift<2>) -> (!fir.box<!fir.array<2x4xf32>>, !fir.ref<!fir.array<2x4xf32>>) |
| 95 |
|
| 96 |
|
| 97 |
func.func @array_declare_box(%arg0: !fir.box<!fir.array<?x?xf32>>) { |
| 98 |
%c1 = arith.constant 1 : index |
| 99 |
%c2 = arith.constant 2 : index |
| 100 |
%shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2> |
| 101 |
%0:2 = hlfir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>) |
| 102 |
return |
| 103 |
} |
| 104 |
// CHECK-LABEL: func.func @array_declare_box( |
| 105 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>>) { |
| 106 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 107 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index |
| 108 |
// CHECK: %[[VAL_3:.*]] = fir.shift %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shift<2> |
| 109 |
// CHECK: %[[VAL_4:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "x"} : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>) |
| 110 |
|
| 111 |
|
| 112 |
func.func @array_declare_char_box(%arg0: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) { |
| 113 |
%0:2 = hlfir.declare %arg0 {uniq_name = "x"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>) -> (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.box<!fir.array<?x?x!fir.char<1,?>>>) |
| 114 |
return |
| 115 |
} |
| 116 |
// CHECK-LABEL: func.func @array_declare_char_box( |
| 117 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) { |
| 118 |
// CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {uniq_name = "x"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>) -> (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.box<!fir.array<?x?x!fir.char<1,?>>>) |
| 119 |
|
| 120 |
|
| 121 |
func.func @array_declare_char_box_2(%arg0: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) { |
| 122 |
%c1 = arith.constant 1 : index |
| 123 |
%c2 = arith.constant 2 : index |
| 124 |
%c3 = arith.constant 3 : index |
| 125 |
%shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2> |
| 126 |
%0:2 = hlfir.declare %arg0(%shape) typeparams %c3 {uniq_name = "x"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.shift<2>, index) -> (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.box<!fir.array<?x?x!fir.char<1,?>>>) |
| 127 |
return |
| 128 |
} |
| 129 |
// CHECK-LABEL: func.func @array_declare_char_box_2( |
| 130 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) { |
| 131 |
// CHECK: %[[VAL_1:.*]] = arith.constant 1 : index |
| 132 |
// CHECK: %[[VAL_2:.*]] = arith.constant 2 : index |
| 133 |
// CHECK: %[[VAL_3:.*]] = arith.constant 3 : index |
| 134 |
// CHECK: %[[VAL_4:.*]] = fir.shift %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shift<2> |
| 135 |
// CHECK: %[[VAL_5:.*]] = hlfir.declare %[[VAL_0]](%[[VAL_4]]) typeparams %[[VAL_3]] {uniq_name = "x"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.shift<2>, index) -> (!fir.box<!fir.array<?x?x!fir.char<1,?>>>, !fir.box<!fir.array<?x?x!fir.char<1,?>>>) |
| 136 |
|
| 137 |
|
| 138 |
func.func @array_declare_char_boxaddr(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) { |
| 139 |
%0:2 = hlfir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) |
| 140 |
return |
| 141 |
} |
| 142 |
// CHECK-LABEL: func.func @array_declare_char_boxaddr( |
| 143 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) { |
| 144 |
// CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {uniq_name = "x"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) |
| 145 |
|
| 146 |
|
| 147 |
func.func @array_declare_char_boxaddr_2(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) { |
| 148 |
%c3 = arith.constant 3 : index |
| 149 |
%0:2 = hlfir.declare %arg0 typeparams %c3 {uniq_name = "x"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, index) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) |
| 150 |
return |
| 151 |
} |
| 152 |
// CHECK-LABEL: func.func @array_declare_char_boxaddr_2( |
| 153 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) { |
| 154 |
// CHECK: %[[VAL_1:.*]] = arith.constant 3 : index |
| 155 |
// CHECK: %[[VAL_2:.*]] = hlfir.declare %[[VAL_0]] typeparams %[[VAL_1]] {uniq_name = "x"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, index) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) |
| 156 |
|
| 157 |
func.func @array_declare_unlimited_polymorphic_boxaddr(%arg0: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) { |
| 158 |
%0:2 = hlfir.declare %arg0 {uniq_name = "x"} : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) -> (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) |
| 159 |
return |
| 160 |
} |
| 161 |
// CHECK-LABEL: func.func @array_declare_unlimited_polymorphic_boxaddr( |
| 162 |
// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) { |
| 163 |
// CHECK: %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {uniq_name = "x"} : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) -> (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) |