1 // Test the FIR operations
3 // RUN: fir-opt %s | fir-opt | FileCheck %s
5 // CHECK-LABEL: func private @it1() -> !fir.int<4>
6 // CHECK: func private @box1() -> !fir.boxchar<2>
7 // CHECK: func private @box2() -> !fir.boxproc<(i32, i32) -> i64>
8 // CHECK: func private @box3() -> !fir.box<!fir.type<derived3{f:f32}>>
9 func.func private @it1() -> !fir.int<4>
10 func.func private @box1() -> !fir.boxchar<2>
11 func.func private @box2() -> !fir.boxproc<(i32, i32) -> i64>
12 func.func private @box3() -> !fir.box<!fir.type<derived3{f:f32}>>
14 // Fortran SUBROUTINE and FUNCTION
15 // CHECK-LABEL: func private @print_index3(index, index, index)
16 // CHECK: func private @user_i64(i64)
17 // CHECK: func private @user_tdesc(!fir.tdesc<!fir.type<x>>)
18 func.func private @print_index3(index, index, index)
19 func.func private @user_i64(i64)
20 func.func private @user_tdesc(!fir.tdesc<!fir.type<x>>)
22 // expect the void return to be omitted
23 // CHECK-LABEL: func private @store_tuple(tuple<!fir.type<qq1{f1:i32}>>)
24 // CHECK: func private @get_method_box() -> !fir.box<!fir.type<derived3{f:f32}>>
25 // CHECK: func private @method_impl(!fir.box<!fir.type<derived3{f:f32}>>)
26 func.func private @store_tuple(tuple<!fir.type<qq1{f1:i32}>>) -> ()
27 func.func private @get_method_box() -> !fir.box<!fir.type<derived3{f:f32}>>
28 func.func private @method_impl(!fir.box<!fir.type<derived3{f:f32}>>)
30 // CHECK-LABEL: func private @nop()
31 // CHECK-LABEL: func private @get_func() -> (() -> ())
32 func.func private @nop()
33 func.func private @get_func() -> (() -> ())
35 // CHECK-LABEL: func @instructions() {
36 func.func @instructions() {
37 // CHECK: [[VAL_0:%.*]] = fir.alloca !fir.array<10xi32>
38 // CHECK: [[VAL_1:%.*]] = fir.load [[VAL_0]] : !fir.ref<!fir.array<10xi32>>
39 // CHECK: [[VAL_2:%.*]] = fir.alloca i32
40 // CHECK: [[VAL_3:%.*]] = arith.constant 22 : i32
41 %0 = fir.alloca !fir.array<10xi32>
42 %1 = fir.load %0 : !fir.ref<!fir.array<10xi32>>
44 %3 = arith.constant 22 : i32
46 // CHECK: fir.store [[VAL_3]] to [[VAL_2]] : !fir.ref<i32>
47 // CHECK: [[VAL_4:%.*]] = fir.undefined i32
48 // CHECK: [[VAL_5:%.*]] = fir.allocmem !fir.array<100xf32>
49 // CHECK: [[VAL_6:%.*]] = fir.embox [[VAL_5]] : (!fir.heap<!fir.array<100xf32>>) -> !fir.box<!fir.array<100xf32>>
50 fir.store %3 to %2 : !fir.ref<i32>
51 %4 = fir.undefined i32
52 %5 = fir.allocmem !fir.array<100xf32>
53 %6 = fir.embox %5 : (!fir.heap<!fir.array<100xf32>>) -> !fir.box<!fir.array<100xf32>>
55 // CHECK: [[VAL_7:%.*]] = fir.box_addr [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> !fir.ref<!fir.array<100xf32>>
56 %7 = fir.box_addr %6 : (!fir.box<!fir.array<100xf32>>) -> !fir.ref<!fir.array<100xf32>>
57 // CHECK: %[[WAL_2:.*]] = fir.undefined !fir.boxproc<() -> ()>
58 %ba1 = fir.undefined !fir.boxproc<() -> ()>
59 // CHECK: %{{.*}} = fir.box_addr %[[WAL_2]] : (!fir.boxproc<() -> ()>) -> (() -> ())
60 %ba2 = fir.box_addr %ba1 : (!fir.boxproc<() -> ()>) -> (() -> ())
61 %ba3 = fir.undefined !fir.boxchar<1>
62 // CHECK: %{{.*}} = fir.box_addr %{{.*}} : (!fir.boxchar<1>) -> !fir.ref<!fir.char<1>>
63 %ba4 = fir.box_addr %ba3 : (!fir.boxchar<1>) -> !fir.ref<!fir.char<1>>
64 %c0 = arith.constant 0 : index
65 %d1:3 = fir.box_dims %6, %c0 : (!fir.box<!fir.array<100xf32>>, index) -> (index, index, index)
66 // CHECK: [[VAL_8:%.*]] = arith.constant 0 : index
67 // CHECK: [[VAL_9:%.*]]:3 = fir.box_dims [[VAL_6]], [[VAL_8]] : (!fir.box<!fir.array<100xf32>>, index) -> (index, index, index)
68 // CHECK: fir.call @print_index3([[VAL_9]]#0, [[VAL_9]]#1, [[VAL_9]]#2) : (index, index, index) -> ()
69 // CHECK: [[VAL_10:%.*]] = fir.call @it1() : () -> !fir.int<4>
70 fir.call @print_index3(%d1#0, %d1#1, %d1#2) : (index, index, index) -> ()
71 %8 = fir.call @it1() : () -> !fir.int<4>
73 // CHECK: [[VAL_11:%.*]] = fir.box_elesize [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i64
74 // CHECK: [[VAL_12:%.*]] = fir.box_isalloc [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
75 // CHECK: [[VAL_13:%.*]] = fir.box_isarray [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
76 // CHECK: [[VAL_14:%.*]] = fir.box_isptr [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i1
77 // CHECK: [[VAL_15:%.*]] = fir.box_rank [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> i64
78 %9 = fir.box_elesize %6 : (!fir.box<!fir.array<100xf32>>) -> i64
79 %10 = fir.box_isalloc %6 : (!fir.box<!fir.array<100xf32>>) -> i1
80 %11 = fir.box_isarray %6 : (!fir.box<!fir.array<100xf32>>) -> i1
81 %12 = fir.box_isptr %6 : (!fir.box<!fir.array<100xf32>>) -> i1
82 %13 = fir.box_rank %6 : (!fir.box<!fir.array<100xf32>>) -> i64
84 // CHECK: [[VAL_16:%.*]] = fir.box_tdesc [[VAL_6]] : (!fir.box<!fir.array<100xf32>>) -> !fir.tdesc<!fir.array<100xf32>>
85 // CHECK: [[VAL_17:%.*]] = fir.call @box1() : () -> !fir.boxchar<2>
86 // CHECK: [[VAL_18:%.*]] = fir.boxchar_len [[VAL_17]] : (!fir.boxchar<2>) -> i32
87 // CHECK: [[VAL_19:%.*]] = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
88 // CHECK: [[VAL_20:%.*]] = fir.boxproc_host [[VAL_19]] : (!fir.boxproc<(i32, i32) -> i64>) -> !fir.ref<i32>
89 %14 = fir.box_tdesc %6 : (!fir.box<!fir.array<100xf32>>) -> !fir.tdesc<!fir.array<100xf32>>
90 %15 = fir.call @box1() : () -> !fir.boxchar<2>
91 %16 = fir.boxchar_len %15 : (!fir.boxchar<2>) -> i32
92 %17 = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
93 %18 = fir.boxproc_host %17 : (!fir.boxproc<(i32, i32) -> i64>) -> !fir.ref<i32>
95 // CHECK: [[VAL_21:%.*]] = arith.constant 10 : i32
96 // CHECK: [[VAL_22:%.*]] = fir.coordinate_of [[VAL_5]], [[VAL_21]] : (!fir.heap<!fir.array<100xf32>>, i32) -> !fir.ref<f32>
97 // CHECK: [[VAL_23:%.*]] = fir.field_index f, !fir.type<derived{f:f32}>
98 // CHECK: [[VAL_24:%.*]] = fir.undefined !fir.type<derived{f:f32}>
99 // CHECK: [[VAL_25:%.*]] = fir.extract_value [[VAL_24]], ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>) -> f32
100 %19 = arith.constant 10 : i32
101 %20 = fir.coordinate_of %5, %19 : (!fir.heap<!fir.array<100xf32>>, i32) -> !fir.ref<f32>
102 %21 = fir.field_index f, !fir.type<derived{f:f32}>
103 %22 = fir.undefined !fir.type<derived{f:f32}>
104 %23 = fir.extract_value %22, ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>) -> f32
106 // CHECK: [[VAL_26:%.*]] = arith.constant 1 : i32
107 // CHECK: [[VAL_27:%.*]] = fir.shape [[VAL_21]] : (i32) -> !fir.shape<1>
108 // CHECK: [[VAL_28:%.*]] = arith.constant 1.0
109 // CHECK: [[VAL_29:%.*]] = fir.insert_value [[VAL_24]], [[VAL_28]], ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>, f32) -> !fir.type<derived{f:f32}>
110 // CHECK: [[VAL_30:%.*]] = fir.len_param_index f, !fir.type<derived3{f:f32}>
111 %c1 = arith.constant 1 : i32
112 %24 = fir.shape %19 : (i32) -> !fir.shape<1>
113 %cf1 = arith.constant 1.0 : f32
114 %25 = fir.insert_value %22, %cf1, ["f", !fir.type<derived{f:f32}>] : (!fir.type<derived{f:f32}>, f32) -> !fir.type<derived{f:f32}>
115 %26 = fir.len_param_index f, !fir.type<derived3{f:f32}>
117 // CHECK: [[VAL_31:%.*]] = fir.call @box3() : () -> !fir.class<!fir.type<derived3{f:f32}>>
118 // CHECK: [[VAL_32:%.*]] = fir.dispatch "method"([[VAL_31]] : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
119 // CHECK: [[VAL_33:%.*]] = fir.convert [[VAL_32]] : (i32) -> i64
120 // CHECK: [[VAL_34:%.*]] = fir.type_desc !fir.type<x>
121 // CHECK: fir.call @user_tdesc([[VAL_34]]) : (!fir.tdesc<!fir.type<x>>) -> ()
122 // CHECK: [[VAL_35:%.*]] = fir.no_reassoc [[VAL_33]] : i64
123 %27 = fir.call @box3() : () -> !fir.class<!fir.type<derived3{f:f32}>>
124 %28 = fir.dispatch "method"(%27 : !fir.class<!fir.type<derived3{f:f32}>>) -> i32
125 %29 = fir.convert %28 : (i32) -> i64
126 %30 = fir.type_desc !fir.type<x>
127 fir.call @user_tdesc(%30) : (!fir.tdesc<!fir.type<x>>) -> ()
128 %31 = fir.no_reassoc %29 : i64
130 // CHECK: fir.call @user_i64([[VAL_35]]) : (i64) -> ()
131 // CHECK: fir.freemem [[VAL_5]] : !fir.heap<!fir.array<100xf32>>
132 // CHECK: [[VAL_36:%.*]] = fir.call @get_func() : () -> (() -> ())
133 // CHECK: fir.call [[VAL_36]]() : () -> ()
134 // CHECK: [[VAL_37:%.*]] = fir.address_of(@it1) : !fir.ref<() -> !fir.int<4>>
137 fir.call @user_i64(%31) : (i64) -> ()
138 fir.freemem %5 : !fir.heap<!fir.array<100xf32>>
139 %32 = fir.call @get_func() : () -> (() -> ())
140 fir.call %32() : () -> ()
141 %33 = fir.address_of (@it1) : !fir.ref<() -> !fir.int<4>>
145 // CHECK-LABEL: func @boxing_match() {
146 func.func @boxing_match() {
147 // CHECK: [[VAL_38:%.*]] = fir.alloca i32
148 // CHECK: [[VAL_39:%.*]] = fir.alloca !fir.type<qq2{f1:i32,f2:f64}>
149 // CHECK: [[VAL_40:%.*]] = fir.alloca !fir.char<1>
150 // CHECK: [[VAL_41:%.*]] = fir.alloca tuple<i32, f64>
151 // CHECK: [[VAL_42:%.*]] = fir.embox [[VAL_38]] : (!fir.ref<i32>) -> !fir.box<i32>
152 // CHECK: [[VAL_44:%.*]] = arith.constant 8 : i32
153 // CHECK: [[VAL_45:%.*]] = fir.undefined !fir.char<1>
154 // CHECK: [[VAL_46:%.*]] = fir.emboxchar [[VAL_40]], [[VAL_44]] : (!fir.ref<!fir.char<1>>, i32) -> !fir.boxchar<1>
155 // CHECK: [[VAL_47:%.*]]:2 = fir.unboxchar [[VAL_46]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i32)
156 // CHECK: [[VAL_48:%.*]] = fir.undefined !fir.type<qq2{f1:i32,f2:f64}>
157 // CHECK: [[VAL_49:%.*]] = arith.constant 0 : i32
158 // CHECK: [[VAL_50:%.*]] = arith.constant 12 : i32
159 // CHECK: [[VAL_51:%.*]] = fir.insert_value [[VAL_48]], [[VAL_50]], [0 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
160 // CHECK: [[VAL_52:%.*]] = arith.constant 1 : i32
161 // CHECK: [[VAL_53:%.*]] = arith.constant 4.213000e+01 : f64
162 // CHECK: [[VAL_54:%.*]] = fir.insert_value [[VAL_48]], [[VAL_53]], [1 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, f64) -> !fir.type<qq2{f1:i32,f2:f64}>
163 // CHECK: fir.store [[VAL_54]] to [[VAL_39]] : !fir.ref<!fir.type<qq2{f1:i32,f2:f64}>>
164 // CHECK: %[[WAL_1:.*]] = fir.address_of(@method_impl)
165 // CHECK: [[VAL_55:%.*]] = fir.emboxproc %[[WAL_1]], [[VAL_41]] : ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<i32, f64>>) -> !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>
166 // CHECK: [[VAL_56:%.*]], [[VAL_57:%.*]] = fir.unboxproc [[VAL_55]] : (!fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>) -> ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<!fir.type<qq2{f1:i32,f2:f64}>>>)
167 // CHECK: [[VAL_58:%.*]] = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
168 // CHECK: [[VAL_59:%.*]], [[VAL_60:%.*]] = fir.unboxproc [[VAL_58]] : (!fir.boxproc<(i32, i32) -> i64>) -> ((i32, i32) -> i64, !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>)
169 // CHECK: [[VAL_61:%.*]] = fir.load [[VAL_60]] : !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>
170 // CHECK: fir.call @store_tuple([[VAL_61]]) : (tuple<!fir.type<qq1{f1:i32}>>) -> ()
174 %d6 = fir.alloca !fir.type<qq2{f1:i32,f2:f64}>
175 %d3 = fir.alloca !fir.char<1>
176 %e6 = fir.alloca tuple<i32,f64>
177 %1 = fir.embox %0 : (!fir.ref<i32>) -> !fir.box<i32>
178 %c8 = arith.constant 8 : i32
179 %3 = fir.undefined !fir.char<1>
180 %4 = fir.emboxchar %d3, %c8 : (!fir.ref<!fir.char<1>>, i32) -> !fir.boxchar<1>
181 %5:2 = fir.unboxchar %4 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i32)
182 %6 = fir.undefined !fir.type<qq2{f1:i32,f2:f64}>
183 %z = arith.constant 0 : i32
184 %c12 = arith.constant 12 : i32
185 %a2 = fir.insert_value %6, %c12, [0 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, i32) -> !fir.type<qq2{f1:i32,f2:f64}>
186 %z1 = arith.constant 1 : i32
187 %c42 = arith.constant 42.13 : f64
188 %a3 = fir.insert_value %6, %c42, [1 : i32] : (!fir.type<qq2{f1:i32,f2:f64}>, f64) -> !fir.type<qq2{f1:i32,f2:f64}>
189 fir.store %a3 to %d6 : !fir.ref<!fir.type<qq2{f1:i32,f2:f64}>>
190 %mi = fir.address_of(@method_impl) : (!fir.box<!fir.type<derived3{f:f32}>>) -> ()
191 %7 = fir.emboxproc %mi, %e6 : ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<i32,f64>>) -> !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>
192 %8:2 = fir.unboxproc %7 : (!fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>) -> ((!fir.box<!fir.type<derived3{f:f32}>>) -> (), !fir.ref<tuple<!fir.type<qq2{f1:i32,f2:f64}>>>)
193 %9 = fir.call @box2() : () -> !fir.boxproc<(i32, i32) -> i64>
194 %10:2 = fir.unboxproc %9 : (!fir.boxproc<(i32, i32) -> i64>) -> ((i32, i32) -> i64, !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>)
195 %11 = fir.load %10#1 : !fir.ref<tuple<!fir.type<qq1{f1:i32}>>>
196 fir.call @store_tuple(%11) : (tuple<!fir.type<qq1{f1:i32}>>) -> ()
200 // CHECK-LABEL: func @loop() {
202 // CHECK: [[VAL_62:%.*]] = arith.constant 1 : index
203 // CHECK: [[VAL_63:%.*]] = arith.constant 10 : index
204 // CHECK: [[VAL_64:%.*]] = arith.constant true
205 %c1 = arith.constant 1 : index
206 %c10 = arith.constant 10 : index
207 %ct = arith.constant true
209 // CHECK: fir.do_loop [[VAL_65:%.*]] = [[VAL_62]] to [[VAL_63]] step [[VAL_62]] {
210 // CHECK: fir.if [[VAL_64]] {
211 // CHECK: fir.call @nop() : () -> ()
213 // CHECK: fir.call @nop() : () -> ()
216 // CHECK: fir.unreachable
218 fir.do_loop %i = %c1 to %c10 step %c1 {
220 fir.call @nop() : () -> ()
222 fir.call @nop() : () -> ()
228 // CHECK: func @bar_select([[VAL_66:%.*]]: i32, [[VAL_67:%.*]]: i32) -> i32 {
229 func.func @bar_select(%arg : i32, %arg2 : i32) -> i32 {
230 // CHECK: [[VAL_68:%.*]] = arith.constant 1 : i32
231 // CHECK: [[VAL_69:%.*]] = arith.constant 2 : i32
232 // CHECK: [[VAL_70:%.*]] = arith.constant 3 : i32
233 // CHECK: [[VAL_71:%.*]] = arith.constant 4 : i32
234 %0 = arith.constant 1 : i32
235 %1 = arith.constant 2 : i32
236 %2 = arith.constant 3 : i32
237 %3 = arith.constant 4 : i32
239 // CHECK: fir.select [[VAL_66]] : i32 [1, ^bb1([[VAL_68]] : i32), 2, ^bb2([[VAL_70]], [[VAL_66]], [[VAL_67]] : i32, i32, i32), -3, ^bb3([[VAL_67]], [[VAL_70]] : i32, i32), 4, ^bb4([[VAL_69]] : i32), unit, ^bb5]
240 // CHECK: ^bb1([[VAL_72:%.*]]: i32):
241 // CHECK: return [[VAL_72]] : i32
242 // CHECK: ^bb2([[VAL_73:%.*]]: i32, [[VAL_74:%.*]]: i32, [[VAL_75:%.*]]: i32):
243 // CHECK: [[VAL_76:%.*]] = arith.addi [[VAL_73]], [[VAL_74]] : i32
244 // CHECK: [[VAL_77:%.*]] = arith.addi [[VAL_76]], [[VAL_75]] : i32
245 // CHECK: return [[VAL_77]] : i32
246 // CHECK: ^bb3([[VAL_78:%.*]]: i32, [[VAL_79:%.*]]: i32):
247 // CHECK: [[VAL_80:%.*]] = arith.addi [[VAL_78]], [[VAL_79]] : i32
248 // CHECK: return [[VAL_80]] : i32
249 // CHECK: ^bb4([[VAL_81:%.*]]: i32):
250 // CHECK: return [[VAL_81]] : i32
252 // CHECK: [[VAL_82:%.*]] = arith.constant 0 : i32
253 // CHECK: return [[VAL_82]] : i32
255 fir.select %arg:i32 [ 1,^bb1(%0:i32), 2,^bb2(%2,%arg,%arg2:i32,i32,i32), -3,^bb3(%arg2,%2:i32,i32), 4,^bb4(%1:i32), unit,^bb5 ]
258 ^bb2(%b : i32, %b2 : i32, %b3:i32) :
259 %4 = arith.addi %b, %b2 : i32
260 %5 = arith.addi %4, %b3 : i32
262 ^bb3(%c:i32, %c2:i32) :
263 %6 = arith.addi %c, %c2 : i32
268 %zero = arith.constant 0 : i32
272 // CHECK-LABEL: func @bar_select_rank(
273 // CHECK-SAME: [[VAL_83:%.*]]: i32, [[VAL_84:%.*]]: i32) -> i32 {
274 func.func @bar_select_rank(%arg : i32, %arg2 : i32) -> i32 {
275 // CHECK: [[VAL_85:%.*]] = arith.constant 1 : i32
276 // CHECK: [[VAL_86:%.*]] = arith.constant 2 : i32
277 // CHECK: [[VAL_87:%.*]] = arith.constant 3 : i32
278 // CHECK: [[VAL_88:%.*]] = arith.constant 4 : i32
279 %0 = arith.constant 1 : i32
280 %1 = arith.constant 2 : i32
281 %2 = arith.constant 3 : i32
282 %3 = arith.constant 4 : i32
284 // CHECK: fir.select_rank [[VAL_83]] : i32 [1, ^bb1([[VAL_85]] : i32), 2, ^bb2([[VAL_87]], [[VAL_83]], [[VAL_84]] : i32, i32, i32), 3, ^bb3([[VAL_84]], [[VAL_87]] : i32, i32), -1, ^bb4([[VAL_86]] : i32), unit, ^bb5]
285 // CHECK: ^bb1([[VAL_89:%.*]]: i32):
286 // CHECK: return [[VAL_89]] : i32
287 // CHECK: ^bb2([[VAL_90:%.*]]: i32, [[VAL_91:%.*]]: i32, [[VAL_92:%.*]]: i32):
288 // CHECK: [[VAL_93:%.*]] = arith.addi [[VAL_90]], [[VAL_91]] : i32
289 // CHECK: [[VAL_94:%.*]] = arith.addi [[VAL_93]], [[VAL_92]] : i32
290 // CHECK: return [[VAL_94]] : i32
291 fir.select_rank %arg:i32 [ 1,^bb1(%0:i32), 2,^bb2(%2,%arg,%arg2:i32,i32,i32), 3,^bb3(%arg2,%2:i32,i32), -1,^bb4(%1:i32), unit,^bb5 ]
294 ^bb2(%b : i32, %b2 : i32, %b3:i32) :
295 %4 = arith.addi %b, %b2 : i32
296 %5 = arith.addi %4, %b3 : i32
299 // CHECK: ^bb3([[VAL_95:%.*]]: i32, [[VAL_96:%.*]]: i32):
300 // CHECK: [[VAL_97:%.*]] = arith.addi [[VAL_95]], [[VAL_96]] : i32
301 // CHECK: return [[VAL_97]] : i32
302 // CHECK: ^bb4([[VAL_98:%.*]]: i32):
303 // CHECK: return [[VAL_98]] : i32
304 ^bb3(%c:i32, %c2:i32) :
305 %6 = arith.addi %c, %c2 : i32
311 // CHECK: [[VAL_99:%.*]] = arith.constant 0 : i32
312 // CHECK: [[VAL_100:%.*]] = fir.call @get_method_box() : () -> !fir.class<!fir.type<derived3{f:f32}>>
313 // CHECK: fir.dispatch "method"([[VAL_100]] : !fir.class<!fir.type<derived3{f:f32}>>)
315 %zero = arith.constant 0 : i32
316 %7 = fir.call @get_method_box() : () -> !fir.class<!fir.type<derived3{f:f32}>>
317 fir.dispatch "method"(%7 : !fir.class<!fir.type<derived3{f:f32}>>)
319 // CHECK: return [[VAL_99]] : i32
324 // CHECK-LABEL: func @bar_select_type(
325 // CHECK-SAME: [[VAL_101:%.*]]: !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>>) -> i32 {
326 func.func @bar_select_type(%arg : !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>>) -> i32 {
328 // CHECK: [[VAL_102:%.*]] = arith.constant 1 : i32
329 // CHECK: [[VAL_103:%.*]] = arith.constant 2 : i32
330 // CHECK: [[VAL_104:%.*]] = arith.constant 3 : i32
331 // CHECK: [[VAL_105:%.*]] = arith.constant 4 : i32
332 %0 = arith.constant 1 : i32
333 %1 = arith.constant 2 : i32
334 %2 = arith.constant 3 : i32
335 %3 = arith.constant 4 : i32
337 // CHECK: fir.select_type [[VAL_101]] : !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>> [#fir.type_is<!fir.int<4>>, ^bb1([[VAL_102]] : i32), #fir.type_is<!fir.int<8>>, ^bb2([[VAL_104]] : i32), #fir.class_is<!fir.int<2>>, ^bb3([[VAL_104]] : i32), #fir.type_is<!fir.int<1>>, ^bb4([[VAL_103]] : i32), unit, ^bb5]
338 fir.select_type %arg : !fir.class<!fir.type<name(param1:i32){fld:!fir.char<1>}>> [ #fir.type_is<!fir.int<4>>,^bb1(%0:i32), #fir.type_is<!fir.int<8>>,^bb2(%2:i32), #fir.class_is<!fir.int<2>>,^bb3(%2:i32), #fir.type_is<!fir.int<1>>,^bb4(%1:i32), unit,^bb5 ]
340 // CHECK: ^bb1([[VAL_106:%.*]]: i32):
341 // CHECK: return [[VAL_106]] : i32
342 // CHECK: ^bb2([[VAL_107:%.*]]: i32):
343 // CHECK: return [[VAL_107]] : i32
344 // CHECK: ^bb3([[VAL_108:%.*]]: i32):
345 // CHECK: return [[VAL_108]] : i32
346 // CHECK: ^bb4([[VAL_109:%.*]]: i32):
347 // CHECK: return [[VAL_109]] : i32
358 // CHECK: [[VAL_110:%.*]] = arith.constant 0 : i32
359 // CHECK: return [[VAL_110]] : i32
362 %zero = arith.constant 0 : i32
366 // CHECK-LABEL: func @bar_select_case(
367 // CHECK-SAME: [[VAL_111:%.*]]: i32, [[VAL_112:%.*]]: i32) -> i32 {
368 // CHECK: [[VAL_113:%.*]] = arith.constant 1 : i32
369 // CHECK: [[VAL_114:%.*]] = arith.constant 2 : i32
370 // CHECK: [[VAL_115:%.*]] = arith.constant 3 : i32
371 // CHECK: [[VAL_116:%.*]] = arith.constant 4 : i32
372 func.func @bar_select_case(%arg : i32, %arg2 : i32) -> i32 {
373 %0 = arith.constant 1 : i32
374 %1 = arith.constant 2 : i32
375 %2 = arith.constant 3 : i32
376 %3 = arith.constant 4 : i32
378 // CHECK: fir.select_case [[VAL_111]] : i32 [#fir.point, [[VAL_113]], ^bb1([[VAL_113]] : i32), #fir.lower, [[VAL_114]], ^bb2([[VAL_115]], [[VAL_111]], [[VAL_112]], [[VAL_114]] : i32, i32, i32, i32), #fir.interval, [[VAL_115]], [[VAL_116]], ^bb3([[VAL_115]], [[VAL_112]] : i32, i32), #fir.upper, [[VAL_111]], ^bb4([[VAL_114]] : i32), unit, ^bb5]
379 fir.select_case %arg : i32 [#fir.point, %0, ^bb1(%0:i32), #fir.lower, %1, ^bb2(%2,%arg,%arg2,%1:i32,i32,i32,i32), #fir.interval, %2, %3, ^bb3(%2,%arg2:i32,i32), #fir.upper, %arg, ^bb4(%1:i32), unit, ^bb5]
381 // CHECK: ^bb1([[VAL_117:%.*]]: i32):
382 // CHECK: return [[VAL_117]] : i32
383 // CHECK: ^bb2([[VAL_118:%.*]]: i32, [[VAL_119:%.*]]: i32, [[VAL_120:%.*]]: i32, [[VAL_121:%.*]]: i32):
384 // CHECK: [[VAL_122:%.*]] = arith.addi [[VAL_118]], [[VAL_119]] : i32
385 // CHECK: [[VAL_123:%.*]] = arith.muli [[VAL_122]], [[VAL_120]] : i32
386 // CHECK: [[VAL_124:%.*]] = arith.addi [[VAL_123]], [[VAL_121]] : i32
387 // CHECK: return [[VAL_124]] : i32
388 // CHECK: ^bb3([[VAL_125:%.*]]: i32, [[VAL_126:%.*]]: i32):
389 // CHECK: [[VAL_127:%.*]] = arith.addi [[VAL_125]], [[VAL_126]] : i32
390 // CHECK: return [[VAL_127]] : i32
391 // CHECK: ^bb4([[VAL_128:%.*]]: i32):
392 // CHECK: return [[VAL_128]] : i32
395 ^bb2(%b : i32, %b2:i32, %b3:i32, %b4:i32) :
396 %4 = arith.addi %b, %b2 : i32
397 %5 = arith.muli %4, %b3 : i32
398 %6 = arith.addi %5, %b4 : i32
400 ^bb3(%c : i32, %c2 : i32) :
401 %7 = arith.addi %c, %c2 : i32
407 // CHECK: [[VAL_129:%.*]] = arith.constant 0 : i32
408 // CHECK: return [[VAL_129]] : i32
411 %zero = arith.constant 0 : i32
415 // CHECK-LABEL: fir.global @global_var : i32 {
416 // CHECK: [[VAL_130:%.*]] = arith.constant 1 : i32
417 // CHECK: fir.has_value [[VAL_130]] : i32
419 fir.global @global_var : i32 {
420 %0 = arith.constant 1 : i32
421 fir.has_value %0 : i32
424 // CHECK-LABEL: fir.global @global_constant constant : i32 {
425 // CHECK: [[VAL_131:%.*]] = arith.constant 934 : i32
426 // CHECK: fir.has_value [[VAL_131]] : i32
428 fir.global @global_constant constant : i32 {
429 %0 = arith.constant 934 : i32
430 fir.has_value %0 : i32
433 // CHECK-LABEL: fir.global @global_derived : !fir.type<minez(f:i32)> {
434 // CHECK: fir.global_len "f", 1 : i32
435 // CHECK: [[VAL_132:%.*]] = fir.undefined !fir.type<minez(f:i32)>
436 // CHECK: fir.has_value [[VAL_132]] : !fir.type<minez(f:i32)>
438 fir.global @global_derived : !fir.type<minez(f:i32)> {
439 fir.global_len f, 1 : i32
440 %0 = fir.undefined !fir.type<minez>
441 fir.has_value %0 : !fir.type<minez>
444 // CHECK-LABEL: fir.global linkonce_odr @global_linkonce_odr : i32 {
445 // CHECK: [[VAL_130:%.*]] = arith.constant 1 : i32
446 // CHECK: fir.has_value [[VAL_130]] : i32
448 fir.global linkonce_odr @global_linkonce_odr : i32 {
449 %0 = arith.constant 1 : i32
450 fir.has_value %0 : i32
453 // CHECK-LABEL: fir.type_info @dispatch_tbl : !fir.type<dispatch_tbl{i:i32}> dispatch_table {
454 // CHECK: fir.dt_entry "method", @method_impl
456 fir.type_info @dispatch_tbl : !fir.type<dispatch_tbl{i:i32}> dispatch_table {
457 fir.dt_entry "method", @method_impl
460 // CHECK-LABEL: fir.type_info @test_type_info noinit nodestroy nofinal extends !fir.type<parent{i:i32}> : !fir.type<test_type_info{i:i32,j:f32}>
461 fir.type_info @test_type_info noinit nodestroy nofinal extends !fir.type<parent{i:i32}> : !fir.type<test_type_info{i:i32,j:f32}>
463 // CHECK-LABEL: fir.type_info @cpinfo : !fir.type<cpinfo{comp_i:!fir.array<10x20xi32>}> component_info {
464 // CHECK: fir.dt_component "component_info" lbs [2, 3]
466 fir.type_info @cpinfo : !fir.type<cpinfo{comp_i:!fir.array<10x20xi32>}> component_info {
467 fir.dt_component "component_info" lbs [2, 3]
470 // CHECK-LABEL: func @compare_complex(
471 // CHECK-SAME: [[VAL_151:%.*]]: complex<f128>, [[VAL_152:%.*]]: complex<f128>) {
472 func.func @compare_complex(%a : complex<f128>, %b : complex<f128>) {
474 // CHECK: [[VAL_153:%.*]] = fir.cmpc "false", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
475 // CHECK: [[VAL_154:%.*]] = fir.cmpc "oeq", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
476 // CHECK: [[VAL_155:%.*]] = fir.cmpc "ogt", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
477 // CHECK: [[VAL_156:%.*]] = fir.cmpc "oge", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
478 %d0 = fir.cmpc "false", %a, %b : complex<f128>
479 %d1 = fir.cmpc "oeq", %a, %b : complex<f128>
480 %d2 = fir.cmpc "ogt", %a, %b : complex<f128>
481 %d3 = fir.cmpc "oge", %a, %b : complex<f128>
483 // CHECK: [[VAL_157:%.*]] = fir.cmpc "olt", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
484 // CHECK: [[VAL_158:%.*]] = fir.cmpc "ole", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
485 // CHECK: [[VAL_159:%.*]] = fir.cmpc "one", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
486 // CHECK: [[VAL_160:%.*]] = fir.cmpc "ord", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
487 %a0 = fir.cmpc "olt", %a, %b : complex<f128>
488 %a1 = fir.cmpc "ole", %a, %b : complex<f128>
489 %a2 = fir.cmpc "one", %a, %b : complex<f128>
490 %a3 = fir.cmpc "ord", %a, %b : complex<f128>
492 // CHECK: [[VAL_161:%.*]] = fir.cmpc "ueq", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
493 // CHECK: [[VAL_162:%.*]] = fir.cmpc "ugt", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
494 // CHECK: [[VAL_163:%.*]] = fir.cmpc "uge", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
495 // CHECK: [[VAL_164:%.*]] = fir.cmpc "ult", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
496 %b0 = fir.cmpc "ueq", %a, %b : complex<f128>
497 %b1 = fir.cmpc "ugt", %a, %b : complex<f128>
498 %b2 = fir.cmpc "uge", %a, %b : complex<f128>
499 %b3 = fir.cmpc "ult", %a, %b : complex<f128>
501 // CHECK: [[VAL_165:%.*]] = fir.cmpc "ule", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
502 // CHECK: [[VAL_166:%.*]] = fir.cmpc "une", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
503 // CHECK: [[VAL_167:%.*]] = fir.cmpc "uno", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
504 // CHECK: [[VAL_168:%.*]] = fir.cmpc "true", [[VAL_151]], [[VAL_152]] {fastmath = {{.*}}} : complex<f128>
505 %c0 = fir.cmpc "ule", %a, %b : complex<f128>
506 %c1 = fir.cmpc "une", %a, %b : complex<f128>
507 %c2 = fir.cmpc "uno", %a, %b : complex<f128>
508 %c3 = fir.cmpc "true", %a, %b : complex<f128>
514 // CHECK-LABEL: func @arith_real(
515 // CHECK-SAME: [[VAL_169:%.*]]: f128, [[VAL_170:%.*]]: f128) -> f128 {
516 func.func @arith_real(%a : f128, %b : f128) -> f128 {
518 // CHECK: [[VAL_171:%.*]] = arith.constant 1.0
519 // CHECK: [[VAL_172:%.*]] = fir.convert [[VAL_171]] : (f32) -> f128
520 // CHECK: [[VAL_173:%.*]] = arith.negf [[VAL_169]] : f128
521 // CHECK: [[VAL_174:%.*]] = arith.addf [[VAL_172]], [[VAL_173]] : f128
522 // CHECK: [[VAL_175:%.*]] = arith.subf [[VAL_174]], [[VAL_170]] : f128
523 // CHECK: [[VAL_176:%.*]] = arith.mulf [[VAL_173]], [[VAL_175]] : f128
524 // CHECK: [[VAL_177:%.*]] = arith.divf [[VAL_176]], [[VAL_169]] : f128
525 %c1 = arith.constant 1.0 : f32
526 %0 = fir.convert %c1 : (f32) -> f128
527 %1 = arith.negf %a : f128
528 %2 = arith.addf %0, %1 : f128
529 %3 = arith.subf %2, %b : f128
530 %4 = arith.mulf %1, %3 : f128
531 %5 = arith.divf %4, %a : f128
532 // CHECK: return [[VAL_177]] : f128
537 // CHECK-LABEL: func @arith_complex(
538 // CHECK-SAME: [[VAL_179:%.*]]: complex<f128>, [[VAL_180:%.*]]: complex<f128>) -> complex<f128> {
539 func.func @arith_complex(%a : complex<f128>, %b : complex<f128>) -> complex<f128> {
540 // CHECK: [[VAL_181:%.*]] = fir.negc [[VAL_179]] : complex<f128>
541 // CHECK: [[VAL_182:%.*]] = fir.addc [[VAL_180]], [[VAL_181]] : complex<f128>
542 // CHECK: [[VAL_183:%.*]] = fir.subc [[VAL_182]], [[VAL_180]] : complex<f128>
543 // CHECK: [[VAL_184:%.*]] = fir.mulc [[VAL_181]], [[VAL_183]] : complex<f128>
544 // CHECK: [[VAL_185:%.*]] = fir.divc [[VAL_184]], [[VAL_179]] : complex<f128>
545 %1 = fir.negc %a : complex<f128>
546 %2 = fir.addc %b, %1 : complex<f128>
547 %3 = fir.subc %2, %b : complex<f128>
548 %4 = fir.mulc %1, %3 : complex<f128>
549 %5 = fir.divc %4, %a : complex<f128>
550 // CHECK: return [[VAL_185]] : complex<f128>
552 return %5 : complex<f128>
555 // CHECK-LABEL: func @character_literal() -> !fir.char<1,13> {
556 func.func @character_literal() -> !fir.char<1,13> {
557 // CHECK: [[VAL_186:%.*]] = fir.string_lit "Hello, World!"(13) : !fir.char<1,13>
558 %0 = fir.string_lit "Hello, World!"(13) : !fir.char<1,13>
559 // CHECK: return [[VAL_186]] : !fir.char<1,13>
560 return %0 : !fir.char<1,13>
564 // CHECK-LABEL: func private @earlyexit2(i32) -> i1
565 func.func private @earlyexit2(%a : i32) -> i1
567 // CHECK-LABEL: func @early_exit(
568 // CHECK-SAME: [[VAL_187:%.*]]: i1, [[VAL_188:%.*]]: i32) -> i1 {
569 func.func @early_exit(%ok : i1, %k : i32) -> i1 {
570 // CHECK: [[VAL_189:%.*]] = arith.constant 1 : index
571 // CHECK: [[VAL_190:%.*]] = arith.constant 100 : index
572 %c1 = arith.constant 1 : index
573 %c100 = arith.constant 100 : index
575 // CHECK: %[[VAL_191:.*]]:2 = fir.iterate_while ([[VAL_192:%.*]] = [[VAL_189]] to [[VAL_190]] step [[VAL_189]]) and ([[VAL_193:%.*]] = [[VAL_187]]) iter_args([[VAL_194:%.*]] = [[VAL_188]]) -> (i32) {
576 // CHECK: [[VAL_195:%.*]] = func.call @earlyexit2([[VAL_194]]) : (i32) -> i1
577 // CHECK: fir.result [[VAL_195]], [[VAL_194]] : i1, i32
579 %newOk:2 = fir.iterate_while (%i = %c1 to %c100 step %c1) and (%ok_ = %ok) iter_args(%v = %k) -> (i32) {
580 %stop = func.call @earlyexit2(%v) : (i32) -> i1
581 fir.result %stop, %v : i1, i32
583 // CHECK: return %[[VAL_191]]#0 : i1
588 // CHECK-LABEL: @array_access
589 func.func @array_access(%arr : !fir.ref<!fir.array<?x?xf32>>) {
590 // CHECK-DAG: %[[c1:.*]] = arith.constant 100
591 // CHECK-DAG: %[[c2:.*]] = arith.constant 50
592 %c100 = arith.constant 100 : index
593 %c50 = arith.constant 50 : index
594 // CHECK: %[[sh:.*]] = fir.shape %[[c1]], %[[c2]] : {{.*}} -> !fir.shape<2>
595 %shape = fir.shape %c100, %c50 : (index, index) -> !fir.shape<2>
596 %c47 = arith.constant 47 : index
597 %c78 = arith.constant 78 : index
598 %c3 = arith.constant 3 : index
599 %c18 = arith.constant 18 : index
600 %c36 = arith.constant 36 : index
601 %c4 = arith.constant 4 : index
602 // CHECK: %[[sl:.*]] = fir.slice {{.*}} -> !fir.slice<2>
603 %slice = fir.slice %c47, %c78, %c3, %c18, %c36, %c4 : (index,index,index,index,index,index) -> !fir.slice<2>
604 %c0 = arith.constant 0 : index
605 %c99 = arith.constant 99 : index
606 %c1 = arith.constant 1 : index
607 fir.do_loop %i = %c0 to %c99 step %c1 {
608 %c49 = arith.constant 49 : index
609 fir.do_loop %j = %c0 to %c49 step %c1 {
610 // CHECK: fir.array_coor %{{.*}}(%[[sh]]) [%[[sl]]] %{{.*}}, %{{.*}} :
611 %p = fir.array_coor %arr(%shape)[%slice] %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>, !fir.slice<2>, index, index) -> !fir.ref<f32>
612 %x = arith.constant 42.0 : f32
613 fir.store %x to %p : !fir.ref<f32>
619 // CHECK-LABEL: @test_is_present
620 func.func @test_is_present(%arg0: !fir.box<!fir.array<?xf32>>) -> i1 {
621 // CHECK: fir.is_present %{{.*}} : (!fir.box<!fir.array<?xf32>>) -> i1
622 %0 = fir.is_present %arg0 : (!fir.box<!fir.array<?xf32>>) -> i1
625 // CHECK-LABEL: @test_absent
626 func.func @test_absent() -> i1 {
627 // CHECK: fir.absent !fir.box<!fir.array<?xf32>>
628 %0 = fir.absent !fir.box<!fir.array<?xf32>>
629 %1 = fir.call @_QPfoo(%0) : (!fir.box<!fir.array<?xf32>>) -> i1
633 // CHECK-LABEL: @test_misc_ops(
634 // CHECK-SAME: [[ARR1:%.*]]: !fir.ref<!fir.array<?x?xf32>>, [[INDXM:%.*]]: index, [[INDXN:%.*]]: index, [[INDXO:%.*]]: index, [[INDXP:%.*]]: index)
635 func.func @test_misc_ops(%arr1 : !fir.ref<!fir.array<?x?xf32>>, %m : index, %n : index, %o : index, %p : index) {
636 // CHECK: [[I10:%.*]] = arith.constant 10 : index
637 // CHECK: [[J20:%.*]] = arith.constant 20 : index
638 // CHECK: [[C2:%.*]] = arith.constant 2 : index
639 // CHECK: [[C9:%.*]] = arith.constant 9 : index
640 // CHECK: [[C1_I32:%.*]] = arith.constant 9 : i32
641 %i10 = arith.constant 10 : index
642 %j20 = arith.constant 20 : index
643 %c2 = arith.constant 2 : index
644 %c9 = arith.constant 9 : index
645 %c1_i32 = arith.constant 9 : i32
647 // CHECK: [[ARR2:%.*]] = fir.zero_bits !fir.array<10xi32>
648 // CHECK: [[ARR3:%.*]] = fir.insert_on_range [[ARR2]], [[C1_I32]] from (2) to (9) : (!fir.array<10xi32>, i32) -> !fir.array<10xi32>
649 // CHECK: fir.call @noret1([[ARR3]]) : (!fir.array<10xi32>) -> ()
650 %arr2 = fir.zero_bits !fir.array<10xi32>
651 %arr3 = fir.insert_on_range %arr2, %c1_i32 from (2) to (9) : (!fir.array<10xi32>, i32) -> !fir.array<10xi32>
652 fir.call @noret1(%arr3) : (!fir.array<10xi32>) -> ()
654 // CHECK: [[SHAPE:%.*]] = fir.shape_shift [[INDXM:%.*]], [[INDXN:%.*]], [[INDXO:%.*]], [[INDXP:%.*]] : (index, index, index, index) -> !fir.shapeshift<2>
655 // CHECK: [[AV1:%.*]] = fir.array_load [[ARR1]]([[SHAPE]]) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
656 // CHECK: [[FVAL:%.*]] = fir.array_fetch [[AV1]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, index, index) -> f32
657 // CHECK: [[AV2:%.*]] = fir.array_update [[AV1]], [[FVAL]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
658 // CHECK: fir.array_merge_store [[AV1]], [[AV2]] to [[ARR1]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
659 %s = fir.shape_shift %m, %n, %o, %p : (index, index, index, index) -> !fir.shapeshift<2>
660 %av1 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
661 %f = fir.array_fetch %av1, %i10, %j20 : (!fir.array<?x?xf32>, index, index) -> f32
662 %av2 = fir.array_update %av1, %f, %i10, %j20 : (!fir.array<?x?xf32>, f32, index, index) -> !fir.array<?x?xf32>
663 fir.array_merge_store %av1, %av2 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
665 // CHECK: [[AV3:%.*]] = fir.array_load [[ARR1]]([[SHAPE]]) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
666 // CHECK: [[FVAL2:%.*]] = fir.array_fetch [[AV3]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, index, index) -> f32
667 // CHECK: [[AV4:%.*]]:2 = fir.array_modify [[AV3]], [[I10]], [[J20]] : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
668 // CHECK: fir.store [[FVAL2]] to [[AV4]]#0 : !fir.ref<f32>
669 // CHECK: fir.array_merge_store [[AV3]], [[AV4]]#1 to [[ARR1]] : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
670 %av3 = fir.array_load %arr1(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>) -> !fir.array<?x?xf32>
671 %f2 = fir.array_fetch %av3, %i10, %j20 : (!fir.array<?x?xf32>, index, index) -> f32
672 %addr, %av4 = fir.array_modify %av3, %i10, %j20 : (!fir.array<?x?xf32>, index, index) -> (!fir.ref<f32>, !fir.array<?x?xf32>)
673 fir.store %f2 to %addr : !fir.ref<f32>
674 fir.array_merge_store %av3, %av4 to %arr1 : !fir.array<?x?xf32>, !fir.array<?x?xf32>, !fir.ref<!fir.array<?x?xf32>>
678 // CHECK-LABEL: @insert_on_range_multi_dim
679 // CHECK-SAME: %[[ARR:.*]]: !fir.array<10x20xi32>, %[[CST:.*]]: i32
680 func.func @insert_on_range_multi_dim(%arr : !fir.array<10x20xi32>, %cst : i32) {
681 // CHECK: fir.insert_on_range %[[ARR]], %[[CST]] from (2, 3) to (5, 6) : (!fir.array<10x20xi32>, i32) -> !fir.array<10x20xi32>
682 %arr3 = fir.insert_on_range %arr, %cst from (2, 3) to (5, 6) : (!fir.array<10x20xi32>, i32) -> !fir.array<10x20xi32>
686 // CHECK-LABEL: @test_shift
687 func.func @test_shift(%arg0: !fir.box<!fir.array<?xf32>>) -> !fir.ref<f32> {
688 %c4 = arith.constant 4 : index
689 %c100 = arith.constant 100 : index
690 // CHECK: fir.shift %{{.*}} : (index) -> !fir.shift<1>
691 %0 = fir.shift %c4 : (index) -> !fir.shift<1>
692 %1 = fir.array_coor %arg0(%0) %c100 : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, index) -> !fir.ref<f32>
693 return %1 : !fir.ref<f32>
696 func.func private @bar_rebox_test(!fir.box<!fir.array<?x?xf32>>)
697 // CHECK-LABEL: @test_rebox(
698 func.func @test_rebox(%arg0: !fir.box<!fir.array<?xf32>>) {
699 %c0 = arith.constant 0 : index
700 %c1 = arith.constant 1 : index
701 %c2 = arith.constant 2 : index
702 %c3 = arith.constant 3 : index
703 %c4 = arith.constant 4 : index
704 %c10 = arith.constant 10 : index
705 %c33 = arith.constant 33 : index
706 %0 = fir.slice %c10, %c33, %c2 : (index, index, index) -> !fir.slice<1>
707 %1 = fir.shift %c0 : (index) -> !fir.shift<1>
708 // CHECK: fir.rebox %{{.*}}(%{{.*}}) [%{{.*}}] : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
709 %2 = fir.rebox %arg0(%1) [%0] : (!fir.box<!fir.array<?xf32>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
710 %3 = fir.shape %c3, %c4 : (index, index) -> !fir.shape<2>
711 // CHECK: fir.rebox %{{.*}}(%{{.*}}) : (!fir.box<!fir.array<?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
712 %4 = fir.rebox %2(%3) : (!fir.box<!fir.array<?xf32>>, !fir.shape<2>) -> !fir.box<!fir.array<?x?xf32>>
713 fir.call @bar_rebox_test(%4) : (!fir.box<!fir.array<?x?xf32>>) -> ()
717 func.func private @bar_rebox_test_char(!fir.box<!fir.array<?x!fir.char<1,?>>>)
718 // CHECK-LABEL: @test_rebox_char(
719 func.func @test_rebox_char(%arg0: !fir.box<!fir.array<?x!fir.char<1,20>>>) {
720 %c7_i64 = arith.constant 7 : i64
721 %c1_i64 = arith.constant 1 : i64
722 %c0 = arith.constant 0 : index
723 %c1 = arith.constant 1 : index
724 %0:3 = fir.box_dims %arg0, %c0 : (!fir.box<!fir.array<?x!fir.char<1,20>>>, index) -> (index, index, index)
725 %1 = fir.slice %c1, %0#1, %c1_i64 substr %c1_i64, %c7_i64 : (index, index, i64, i64, i64) -> !fir.slice<1>
726 // CHECK: fir.rebox %{{.*}} [%{{.*}}] : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
727 %2 = fir.rebox %arg0 [%1] : (!fir.box<!fir.array<?x!fir.char<1,20>>>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.char<1,?>>>
728 fir.call @bar_rebox_test_char(%2) : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> ()
733 func.func private @array_func() -> !fir.array<?x!fir.char<1,?>>
734 // CHECK-LABEL: @test_save_result(
735 func.func @test_save_result(%buffer: !fir.ref<!fir.array<?x!fir.char<1,?>>>) {
736 %c100 = arith.constant 100 : index
737 %c50 = arith.constant 50 : index
738 %shape = fir.shape %c100 : (index) -> !fir.shape<1>
739 %res = fir.call @array_func() : () -> !fir.array<?x!fir.char<1,?>>
740 // CHECK: fir.save_result %{{.*}} to %{{.*}}(%{{.*}}) typeparams %{{.*}} : !fir.array<?x!fir.char<1,?>>, !fir.ref<!fir.array<?x!fir.char<1,?>>>, !fir.shape<1>, index
741 fir.save_result %res to %buffer(%shape) typeparams %c50 : !fir.array<?x!fir.char<1,?>>, !fir.ref<!fir.array<?x!fir.char<1,?>>>, !fir.shape<1>, index
745 func.func @char_convert() {
746 %1 = fir.undefined i32
747 %2 = fir.undefined !fir.ref<!fir.char<1>>
748 %3 = fir.undefined !fir.ref<!fir.array<?x!fir.char<2,?>>>
749 // CHECK: fir.char_convert %{{.*}} for %{{.*}} to %{{.*}} : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
750 fir.char_convert %2 for %1 to %3 : !fir.ref<!fir.char<1>>, i32, !fir.ref<!fir.array<?x!fir.char<2,?>>>
754 func.func @slice_substr() {
755 %lb = arith.constant 0 : index
756 %ub = arith.constant 42 : index
757 %c1 = arith.constant 1 : index
758 %offset = arith.constant 10 : index
759 %0 = fir.slice %lb, %ub, %c1 substr %offset, %c1 : (index, index, index, index, index) -> !fir.slice<1>
760 // CHECK: fir.slice %{{.*}}, %{{.*}}, %{{.*}} substr %{{.*}}, %{{.*}} : (index, index, index, index, index) -> !fir.slice<1>
764 // Test load, store, coordinate_of with llvmptr type
765 // CHECK-LABEL: llvm_ptr_load_store_coordinate
766 // CHECK-SAME: (%[[ARG0:.*]]: !fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.ptr<f32>>>)
767 func.func @llvm_ptr_load_store_coordinate(%arg0: !fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, %arg1: !fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>> {
768 // CHECK-NEXT: %[[C0:.*]] = arith.constant 0 : i32
769 %c0_i32 = arith.constant 0 : i32
770 // CHECK-NEXT: %[[LLVMPTR:.*]] = fir.coordinate_of %[[ARG0]], %[[C0]] : (!fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, i32) -> !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
771 %0 = fir.coordinate_of %arg0, %c0_i32 : (!fir.ref<tuple<!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>>>, i32) -> !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
772 // CHECK-NEXT: fir.store %[[ARG1]] to %[[LLVMPTR]] : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
773 fir.store %arg1 to %0 : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
774 // CHECK-NEXT: fir.load %[[LLVMPTR]] : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
775 %1 = fir.load %0 : !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<f32>>>>
776 return %1 : !fir.ref<!fir.box<!fir.ptr<f32>>>
779 func.func @array_access_ops(%a : !fir.ref<!fir.array<?x?xf32>>) {
780 %c1 = arith.constant 1 : index
781 %n = arith.constant 0 : index
782 %m = arith.constant 50 : index
783 %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
784 %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
785 %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
786 // CHECK: %{{.*}} = fir.array_access %{{.*}}, %{{.*}}, %{{.*}} : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
790 func.func @array_amend_ops(%a : !fir.ref<!fir.array<?x?xf32>>) {
791 %c1 = arith.constant 1 : index
792 %n = arith.constant 0 : index
793 %m = arith.constant 50 : index
794 %s = fir.shape %n, %m : (index, index) -> !fir.shape<2>
795 %v = fir.array_load %a(%s) : (!fir.ref<!fir.array<?x?xf32>>, !fir.shape<2>) -> !fir.array<?x?xf32>
796 %p = fir.array_access %v, %c1, %c1 : (!fir.array<?x?xf32>, index, index) -> !fir.ref<f32>
797 %res = fir.array_amend %v, %p : (!fir.array<?x?xf32>, !fir.ref<f32>) -> !fir.array<?x?xf32>
798 // CHECK: %{{.*}} = fir.array_amend %{{.*}}, %{{.*}} : (!fir.array<?x?xf32>, !fir.ref<f32>) -> !fir.array<?x?xf32>
802 func.func private @dispatch(%arg0: !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, %arg1: i32) -> () {
803 // CHECK-LABEL: func.func private @dispatch(
804 // CHECK-SAME: %[[CLASS:.*]]: !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>, %[[INTARG:.*]]: i32)
805 fir.dispatch "proc1"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32}
806 // CHECK: fir.dispatch "proc1"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32}
808 fir.dispatch "proc2"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) proc_attrs<pure>
809 // CHECK: fir.dispatch "proc2"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) proc_attrs <pure>
811 fir.dispatch "proc3"(%arg0 : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%arg1, %arg0 : i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
812 // CHECK: fir.dispatch "proc3"(%[[CLASS]] : !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) (%[[INTARG]], %[[CLASS]] : i32, !fir.class<!fir.type<dispatch_derived1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32}
817 // CHECK-LABEL: func.func @embox_tdesc(
818 // CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>
819 func.func @embox_tdesc(%arg0: !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>) {
821 %c1_i32 = arith.constant 1 : i32
822 %1 = fir.convert %c1_i32 : (i32) -> index
823 %c10_i32 = arith.constant 10 : i32
824 %2 = fir.convert %c10_i32 : (i32) -> index
825 %c1 = arith.constant 1 : index
826 %3 = fir.convert %1 : (index) -> i32
827 %4:2 = fir.do_loop %arg2 = %1 to %2 step %c1 iter_args(%arg3 = %3) -> (index, i32) {
828 fir.store %arg3 to %0 : !fir.ref<i32>
829 %9 = fir.load %0 : !fir.ref<i32>
830 %10 = fir.convert %9 : (i32) -> i64
831 %c1_i64 = arith.constant 1 : i64
832 %11 = arith.subi %10, %c1_i64 : i64
833 %12 = fir.coordinate_of %arg0, %11 : (!fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>, i64) -> !fir.ref<!fir.type<derived_poly{a:i32,b:i32}>>
834 %13 = fir.embox %12 source_box %arg0 : (!fir.ref<!fir.type<derived_poly{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>) -> !fir.class<!fir.type<derived_poly{a:i32,b:i32}>>
835 // CHECK: %{{.*}} = fir.embox %{{.*}} source_box %[[ARG0]] : (!fir.ref<!fir.type<derived_poly{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<derived_poly{a:i32,b:i32}>>>) -> !fir.class<!fir.type<derived_poly{a:i32,b:i32}>>
836 %14 = arith.addi %arg2, %c1 : index
837 %15 = fir.convert %c1 : (index) -> i32
838 %16 = fir.load %0 : !fir.ref<i32>
839 %17 = arith.addi %16, %15 : i32
840 fir.result %14, %17 : index, i32
842 fir.store %4#1 to %0 : !fir.ref<i32>
846 func.func @test_fortran_var_attrs() {
847 %0 = fir.alloca !fir.heap<f32> {fortran_attrs = #fir.var_attrs<allocatable>}
848 %1 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<asynchronous>}
849 %2 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<bind_c>}
850 %3 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<contiguous>}
851 %4 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_in>}
852 %5 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_inout>}
853 %6 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_out>}
854 %7 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<optional>}
855 %8 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<parameter>}
856 %9 = fir.alloca !fir.ptr<f32> {fortran_attrs = #fir.var_attrs<pointer>}
857 %10 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<target>}
858 %11 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<value>}
859 %12 = fir.alloca f32 {fortran_attrs = #fir.var_attrs<volatile>}
860 %13 = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {fortran_attrs = #fir.var_attrs<pointer, contiguous, volatile>}
862 // CHECK: fir.alloca !fir.heap<f32> {fortran_attrs = #fir.var_attrs<allocatable>}
863 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<asynchronous>}
864 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<bind_c>}
865 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<contiguous>}
866 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_in>}
867 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_inout>}
868 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<intent_out>}
869 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<optional>}
870 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<parameter>}
871 // CHECK: fir.alloca !fir.ptr<f32> {fortran_attrs = #fir.var_attrs<pointer>}
872 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<target>}
873 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<value>}
874 // CHECK: fir.alloca f32 {fortran_attrs = #fir.var_attrs<volatile>}
875 // CHECK: fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {fortran_attrs = #fir.var_attrs<contiguous, pointer, volatile>}
878 func.func @test_box_typecode(%a: !fir.class<none>) {
879 %0 = fir.box_typecode %a : (!fir.class<none>) -> i32
883 // CHECK-LABEL: func.func @test_box_typecode(
884 // CHECK-SAME: %[[A:.*]]: !fir.class<none>)
885 // CHECK: %{{.*}} = fir.box_typecode %[[A]] : (!fir.class<none>) -> i32
887 fir.global @t1 {keep_my_attr = "data"} : i32 {
888 %1 = arith.constant 0 : i32
889 fir.has_value %1 : i32
892 // CHECK-LABEL: fir.global @t1 {keep_my_attr = "data"} : i32
894 func.func @test_rebox_assumed_rank(%arg0: !fir.box<!fir.array<*:f32>> ) {
895 %1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
896 %2 = fir.rebox_assumed_rank %arg0 lbs zeroes : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
897 %3 = fir.rebox_assumed_rank %arg0 lbs preserve : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
900 // CHECK-LABEL: func.func @test_rebox_assumed_rank(
901 // CHECK-SAME: %[[A:.*]]: !fir.box<!fir.array<*:f32>>)
902 // CHECK: fir.rebox_assumed_rank %[[A]] lbs ones : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
903 // CHECK: fir.rebox_assumed_rank %[[A]] lbs zeroes : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
904 // CHECK: fir.rebox_assumed_rank %[[A]] lbs preserve : (!fir.box<!fir.array<*:f32>>) -> !fir.box<!fir.array<*:f32>>
906 func.func @test_is_assumed_size(%arg0: !fir.class<!fir.array<*:none>>, %arg1 : !fir.box<!fir.array<?xf32>>) {
907 %1 = fir.is_assumed_size %arg0 : (!fir.class<!fir.array<*:none>>) -> i1
908 %2 = fir.is_assumed_size %arg1 : (!fir.box<!fir.array<?xf32>>) -> i1
911 // CHECK-LABEL: func.func @test_is_assumed_size(
912 // CHECK-SAME: %[[A:.*]]: !fir.class<!fir.array<*:none>>,
913 // CHECK-SAME: %[[B:.*]]: !fir.box<!fir.array<?xf32>>)
914 // CHECK: fir.is_assumed_size %[[A]] : (!fir.class<!fir.array<*:none>>) -> i1
915 // CHECK: fir.is_assumed_size %[[B]] : (!fir.box<!fir.array<?xf32>>) -> i1