Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / HLFIR / elemental-user-procedure-ref.f90
blob400bdb5c777362f892bae994031fadd251d81a66
1 ! Test lowering of user defined elemental procedure reference to HLFIR
2 ! RUN: bbc -emit-fir -hlfir -o - %s 2>&1 | FileCheck %s
4 subroutine by_addr(x, y)
5 integer :: x
6 real :: y(100)
7 interface
8 real elemental function elem(a, b)
9 integer, intent(in) :: a
10 real, intent(in) :: b
11 end function
12 end interface
13 call baz(elem(x, y))
14 end subroutine
15 ! CHECK-LABEL: func.func @_QPby_addr(
16 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0:.*]] {{.*}}x
17 ! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_1:.*]](%[[VAL_4:[^)]*]]) {{.*}}y
18 ! CHECK: %[[VAL_6:.*]] = hlfir.elemental %[[VAL_4]] : (!fir.shape<1>) -> !hlfir.expr<100xf32> {
19 ! CHECK: ^bb0(%[[VAL_7:.*]]: index):
20 ! CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_7]]) : (!fir.ref<!fir.array<100xf32>>, index) -> !fir.ref<f32>
21 ! CHECK: %[[VAL_9:.*]] = fir.call @_QPelem(%[[VAL_2]]#1, %[[VAL_8]]) fastmath<contract> : (!fir.ref<i32>, !fir.ref<f32>) -> f32
22 ! CHECK: hlfir.yield_element %[[VAL_9]] : f32
23 ! CHECK: }
24 ! CHECK: fir.call
25 ! CHECK: hlfir.destroy %[[VAL_6]]
27 subroutine by_value(x, y)
28 integer :: x
29 real :: y(10, 20)
30 interface
31 real elemental function elem_val(a, b)
32 integer, value :: a
33 real, value :: b
34 end function
35 end interface
36 call baz(elem_val(x, y))
37 end subroutine
38 ! CHECK-LABEL: func.func @_QPby_value(
39 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0:.*]] {{.*}}x
40 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1:.*]](%[[VAL_5:[^)]*]]) {{.*}}y
41 ! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i32>
42 ! CHECK: %[[VAL_8:.*]] = hlfir.elemental %[[VAL_5]] : (!fir.shape<2>) -> !hlfir.expr<10x20xf32> {
43 ! CHECK: ^bb0(%[[VAL_9:.*]]: index, %[[VAL_10:.*]]: index):
44 ! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_9]], %[[VAL_10]]) : (!fir.ref<!fir.array<10x20xf32>>, index, index) -> !fir.ref<f32>
45 ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref<f32>
46 ! CHECK: %[[VAL_13:.*]] = fir.call @_QPelem_val(%[[VAL_7]], %[[VAL_12]]) fastmath<contract> : (i32, f32) -> f32
47 ! CHECK: hlfir.yield_element %[[VAL_13]] : f32
48 ! CHECK: }
49 ! CHECK: fir.call
50 ! CHECK: hlfir.destroy %[[VAL_8]]
52 subroutine by_boxaddr(x, y)
53 character(*) :: x
54 character(*) :: y(100)
55 interface
56 real elemental function char_elem(a, b)
57 character(*), intent(in) :: a
58 character(*), intent(in) :: b
59 end function
60 end interface
61 call baz2(char_elem(x, y))
62 end subroutine
63 ! CHECK-LABEL: func.func @_QPby_boxaddr(
64 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2:.*]]#0 typeparams %[[VAL_2]]#1 {{.*}}x
65 ! CHECK: %[[VAL_6:.*]] = arith.constant 100 : index
66 ! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_5:.*]](%[[VAL_7:.*]]) typeparams %[[VAL_4:.*]]#1 {{.*}}y
67 ! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_7]] : (!fir.shape<1>) -> !hlfir.expr<100xf32> {
68 ! CHECK: ^bb0(%[[VAL_10:.*]]: index):
69 ! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_8]]#0 (%[[VAL_10]]) typeparams %[[VAL_4]]#1 : (!fir.box<!fir.array<100x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1>
70 ! CHECK: %[[VAL_12:.*]] = fir.call @_QPchar_elem(%[[VAL_3]]#0, %[[VAL_11]]) fastmath<contract> : (!fir.boxchar<1>, !fir.boxchar<1>) -> f32
71 ! CHECK: hlfir.yield_element %[[VAL_12]] : f32
72 ! CHECK: }
73 ! CHECK: fir.call
74 ! CHECK: hlfir.destroy %[[VAL_9]]
76 subroutine sub(x, y)
77 integer :: x
78 real :: y(10, 20)
79 interface
80 elemental subroutine elem_sub(a, b)
81 integer, intent(in) :: a
82 real, intent(in) :: b
83 end subroutine
84 end interface
85 call elem_sub(x, y)
86 end subroutine
87 ! CHECK-LABEL: func.func @_QPsub(
88 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0:.*]] {{.*}}x
89 ! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index
90 ! CHECK: %[[VAL_4:.*]] = arith.constant 20 : index
91 ! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_1:.*]](%[[VAL_5:[^)]*]]) {{.*}}y
92 ! CHECK: %[[VAL_7:.*]] = arith.constant 1 : index
93 ! CHECK: fir.do_loop %[[VAL_8:.*]] = %[[VAL_7]] to %[[VAL_4]] step %[[VAL_7]] {
94 ! CHECK: fir.do_loop %[[VAL_9:.*]] = %[[VAL_7]] to %[[VAL_3]] step %[[VAL_7]] {
95 ! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_6]]#0 (%[[VAL_9]], %[[VAL_8]]) : (!fir.ref<!fir.array<10x20xf32>>, index, index) -> !fir.ref<f32>
96 ! CHECK: fir.call @_QPelem_sub(%[[VAL_2]]#1, %[[VAL_10]]) fastmath<contract> : (!fir.ref<i32>, !fir.ref<f32>) -> ()
97 ! CHECK: }
98 ! CHECK: }