1 // Test code generation to FIR of hlfir.designate operations
3 // RUN: fir-opt %s -convert-hlfir-to-fir | FileCheck %s
5 func.func @test_set_scalar(%arg0: !fir.ref<complex<f32>>, %arg1: !fir.ref<f32>) {
6 %0:2 = hlfir.declare %arg0 {uniq_name = "a"} : (!fir.ref<complex<f32>>) -> (!fir.ref<complex<f32>>, !fir.ref<complex<f32>>)
7 %1:2 = hlfir.declare %arg1 {uniq_name = "b"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
8 %2 = fir.load %1#0 : !fir.ref<f32>
9 %3 = hlfir.designate %0#0 imag : (!fir.ref<complex<f32>>) -> !fir.ref<f32>
10 hlfir.assign %2 to %3 : f32, !fir.ref<f32>
13 // CHECK-LABEL: func.func @test_set_scalar(
14 // CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<complex<f32>>, %[[VAL_1:.*]]: !fir.ref<f32>) {
15 // CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_0]] {uniq_name = "a"} : (!fir.ref<complex<f32>>) -> !fir.ref<complex<f32>>
16 // CHECK: %[[VAL_3:.*]] = fir.declare %[[VAL_1]] {uniq_name = "b"} : (!fir.ref<f32>) -> !fir.ref<f32>
17 // CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]] : !fir.ref<f32>
18 // CHECK: %[[VAL_5:.*]] = arith.constant 1 : index
19 // CHECK: %[[VAL_6:.*]] = fir.coordinate_of %[[VAL_2]], %[[VAL_5]] : (!fir.ref<complex<f32>>, index) -> !fir.ref<f32>
20 // CHECK: fir.store %[[VAL_4]] to %[[VAL_6]] : !fir.ref<f32>
22 func.func @test_scalar_at_index(%arg0: !fir.box<!fir.array<?xcomplex<f32>>>, %arg1: !fir.ref<i32>) {
23 %0:2 = hlfir.declare %arg0 {uniq_name = "a"} : (!fir.box<!fir.array<?xcomplex<f32>>>) -> (!fir.box<!fir.array<?xcomplex<f32>>>, !fir.box<!fir.array<?xcomplex<f32>>>)
24 %1:2 = hlfir.declare %arg1 {uniq_name = "b"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
25 %2 = fir.load %1#0 : !fir.ref<i32>
26 %3 = fir.convert %2 : (i32) -> i64
27 %4 = hlfir.designate %0#0 (%3) real : (!fir.box<!fir.array<?xcomplex<f32>>>, i64) -> !fir.ref<f32>
30 // CHECK-LABEL: func.func @test_scalar_at_index(
31 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xcomplex<f32>>>, %[[VAL_1:.*]]: !fir.ref<i32>) {
32 // CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_0]] {uniq_name = "a"} : (!fir.box<!fir.array<?xcomplex<f32>>>) -> !fir.box<!fir.array<?xcomplex<f32>>>
33 // CHECK: %[[VAL_3:.*]] = fir.rebox %[[VAL_2]] : (!fir.box<!fir.array<?xcomplex<f32>>>) -> !fir.box<!fir.array<?xcomplex<f32>>>
34 // CHECK: %[[VAL_4:.*]] = fir.declare %[[VAL_1]] {uniq_name = "b"} : (!fir.ref<i32>) -> !fir.ref<i32>
35 // CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]] : !fir.ref<i32>
36 // CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i32) -> i64
37 // CHECK: %[[VAL_7:.*]] = fir.array_coor %[[VAL_3]] %[[VAL_6]] : (!fir.box<!fir.array<?xcomplex<f32>>>, i64) -> !fir.ref<complex<f32>>
38 // CHECK: %[[VAL_8:.*]] = arith.constant 0 : index
39 // CHECK: %[[VAL_9:.*]] = fir.coordinate_of %[[VAL_7]], %[[VAL_8]] : (!fir.ref<complex<f32>>, index) -> !fir.ref<f32>
41 func.func @test_complete_slice(%arg0: !fir.box<!fir.array<?xcomplex<f32>>>) {
42 %c0 = arith.constant 0 : index
43 %0:2 = hlfir.declare %arg0 {uniq_name = "a"} : (!fir.box<!fir.array<?xcomplex<f32>>>) -> (!fir.box<!fir.array<?xcomplex<f32>>>, !fir.box<!fir.array<?xcomplex<f32>>>)
44 %1:3 = fir.box_dims %0#0, %c0 : (!fir.box<!fir.array<?xcomplex<f32>>>, index) -> (index, index, index)
45 %2 = fir.shape %1#1 : (index) -> !fir.shape<1>
46 %3 = hlfir.designate %0#0 imag shape %2 : (!fir.box<!fir.array<?xcomplex<f32>>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>>
49 // CHECK-LABEL: func.func @test_complete_slice(
50 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xcomplex<f32>>>) {
51 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : index
52 // CHECK: %[[VAL_2:.*]] = fir.declare %[[VAL_0]] {uniq_name = "a"} : (!fir.box<!fir.array<?xcomplex<f32>>>) -> !fir.box<!fir.array<?xcomplex<f32>>>
53 // CHECK: %[[VAL_3:.*]] = fir.rebox %[[VAL_2]] : (!fir.box<!fir.array<?xcomplex<f32>>>) -> !fir.box<!fir.array<?xcomplex<f32>>>
54 // CHECK: %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_3]], %[[VAL_1]] : (!fir.box<!fir.array<?xcomplex<f32>>>, index) -> (index, index, index)
55 // CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]]#1 : (index) -> !fir.shape<1>
56 // CHECK: %[[VAL_6:.*]] = arith.constant 1 : index
57 // CHECK: %[[VAL_7:.*]] = arith.constant 1 : index
58 // CHECK: %[[VAL_8:.*]] = arith.constant 0 : index
59 // CHECK: %[[VAL_9:.*]]:3 = fir.box_dims %[[VAL_3]], %[[VAL_8]] : (!fir.box<!fir.array<?xcomplex<f32>>>, index) -> (index, index, index)
60 // CHECK: %[[VAL_10:.*]] = arith.constant 1 : index
61 // CHECK: %[[VAL_11:.*]] = fir.slice %[[VAL_7]], %[[VAL_9]]#1, %[[VAL_6]] path %[[VAL_10]] : (index, index, index, index) -> !fir.slice<1>
62 // CHECK: %[[VAL_12:.*]] = fir.rebox %[[VAL_3]] [%[[VAL_11]]] : (!fir.box<!fir.array<?xcomplex<f32>>>, !fir.slice<1>) -> !fir.box<!fir.array<?xf32>>
64 func.func @test_slice_steps(%arg0: !fir.box<!fir.array<?xcomplex<f32>>>) {
65 %c3 = arith.constant 3 : index
66 %c12 = arith.constant 12 : index
67 %c4 = arith.constant 4 : index
68 %0:2 = hlfir.declare %arg0 {uniq_name = "a"} : (!fir.box<!fir.array<?xcomplex<f32>>>) -> (!fir.box<!fir.array<?xcomplex<f32>>>, !fir.box<!fir.array<?xcomplex<f32>>>)
69 %1 = fir.shape %c3 : (index) -> !fir.shape<1>
70 %2 = hlfir.designate %0#0 (%c4:%c12:%c3) real shape %1 : (!fir.box<!fir.array<?xcomplex<f32>>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<3xf32>>
73 // CHECK-LABEL: func.func @test_slice_steps(
74 // CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xcomplex<f32>>>) {
75 // CHECK: %[[VAL_1:.*]] = arith.constant 3 : index
76 // CHECK: %[[VAL_2:.*]] = arith.constant 12 : index
77 // CHECK: %[[VAL_3:.*]] = arith.constant 4 : index
78 // CHECK: %[[VAL_4:.*]] = fir.declare %[[VAL_0]] {uniq_name = "a"} : (!fir.box<!fir.array<?xcomplex<f32>>>) -> !fir.box<!fir.array<?xcomplex<f32>>>
79 // CHECK: %[[VAL_5:.*]] = fir.rebox %[[VAL_4]] : (!fir.box<!fir.array<?xcomplex<f32>>>) -> !fir.box<!fir.array<?xcomplex<f32>>>
80 // CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
81 // CHECK: %[[VAL_7:.*]] = arith.constant 0 : index
82 // CHECK: %[[VAL_8:.*]] = fir.slice %[[VAL_3]], %[[VAL_2]], %[[VAL_1]] path %[[VAL_7]] : (index, index, index, index) -> !fir.slice<1>
83 // CHECK: %[[VAL_9:.*]] = fir.rebox %[[VAL_5]] [%[[VAL_8]]] : (!fir.box<!fir.array<?xcomplex<f32>>>, !fir.slice<1>) -> !fir.box<!fir.array<3xf32>>