Debian Codegraph @

flang/test/Fir/declare.fir

raw
1 // Test fir.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 = fir.declare %arg0 {uniq_name = "x"} : (!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:.*]] = fir.declare %[[VAL_0]] {uniq_name = "x"} : (!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 = fir.declare %0#0 typeparams %0#1 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>, index) -> !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:.*]] = fir.declare %[[VAL_1]]#0 typeparams %[[VAL_1]]#1 {uniq_name = "c"} : (!fir.ref<!fir.char<1,?>>, index) -> !fir.ref<!fir.char<1,?>>
23
24
25 func.func @derived_declare(%arg0: !fir.ref<!fir.type<t{field:i32}>>) {
26 %0 = fir.declare %arg0 {uniq_name = "x"} : (!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:.*]] = fir.declare %[[VAL_0]] {uniq_name = "x"} : (!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 = fir.declare %arg0 typeparams %c1 {uniq_name = "x"} : (!fir.ref<!fir.type<pdt(param:i32){field:i32}>>, index) -> !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:.*]] = fir.declare %[[VAL_0]] typeparams %[[VAL_1]] {uniq_name = "x"} : (!fir.ref<!fir.type<pdt(param:i32){field:i32}>>, index) -> !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 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !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:.*]] = fir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !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 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !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:.*]] = fir.declare %[[VAL_0]](%[[VAL_5]]) {uniq_name = "x"} : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.ref<!fir.array<?x?xf32>>
77
78
79 func.func @array_declare_box(%arg0: !fir.box<!fir.array<?x?xf32>>) {
80 %c1 = arith.constant 1 : index
81 %c2 = arith.constant 2 : index
82 %shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
83 %0 = fir.declare %arg0(%shape) {uniq_name = "x"} : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
84 return
85 }
86 // CHECK-LABEL: func.func @array_declare_box(
87 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>>) {
88 // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index
89 // CHECK: %[[VAL_2:.*]] = arith.constant 2 : index
90 // CHECK: %[[VAL_3:.*]] = fir.shift %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shift<2>
91 // CHECK: %[[VAL_4:.*]] = fir.declare %[[VAL_0]](%[[VAL_3]]) {uniq_name = "x"} : (!fir.box<!fir.array<?x?xf32>>, !fir.shift<2>) -> !fir.box<!fir.array<?x?xf32>>
92
93
94 func.func @array_declare_char_box(%arg0: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) {
95 %0 = fir.declare %arg0 {uniq_name = "x"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>) -> !fir.box<!fir.array<?x?x!fir.char<1,?>>>
96 return
97 }
98 // CHECK-LABEL: func.func @array_declare_char_box(
99 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) {
100 // CHECK: %[[VAL_1:.*]] = fir.declare %[[VAL_0]] {uniq_name = "x"} : (!fir.box<!fir.array<?x?x!fir.char<1,?>>>) -> !fir.box<!fir.array<?x?x!fir.char<1,?>>>
101
102
103 func.func @array_declare_char_box_2(%arg0: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) {
104 %c1 = arith.constant 1 : index
105 %c2 = arith.constant 2 : index
106 %c3 = arith.constant 3 : index
107 %shape = fir.shift %c1, %c2 : (index, index) -> !fir.shift<2>
108 %0 = fir.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,?>>>
109 return
110 }
111 // CHECK-LABEL: func.func @array_declare_char_box_2(
112 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?x!fir.char<1,?>>>) {
113 // CHECK: %[[VAL_1:.*]] = arith.constant 1 : index
114 // CHECK: %[[VAL_2:.*]] = arith.constant 2 : index
115 // CHECK: %[[VAL_3:.*]] = arith.constant 3 : index
116 // CHECK: %[[VAL_4:.*]] = fir.shift %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shift<2>
117 // CHECK: %[[VAL_5:.*]] = fir.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,?>>>
118
119
120 func.func @array_declare_char_boxaddr(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) {
121 %0 = fir.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,?>>>>>
122 return
123 }
124 // CHECK-LABEL: func.func @array_declare_char_boxaddr(
125 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) {
126 // CHECK: %[[VAL_1:.*]] = fir.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,?>>>>>
127
128
129 func.func @array_declare_char_boxaddr_2(%arg0: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) {
130 %c3 = arith.constant 3 : index
131 %0 = fir.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,?>>>>>
132 return
133 }
134 // CHECK-LABEL: func.func @array_declare_char_boxaddr_2(
135 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.char<1,?>>>>>) {
136 // CHECK: %[[VAL_1:.*]] = arith.constant 3 : index
137 // CHECK: %[[VAL_2:.*]] = fir.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,?>>>>>
138
139 func.func @array_declare_unlimited_polymorphic_boxaddr(%arg0: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) {
140 %0 = fir.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>>>>
141 return
142 }
143 // CHECK-LABEL: func.func @array_declare_unlimited_polymorphic_boxaddr(
144 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x?xnone>>>>) {
145 // CHECK: %[[VAL_1:.*]] = fir.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>>>>