1 ! Test lowering of transformational intrinsic to HLFIR what matters here
2 ! is not to test each transformational, but to check how their
3 ! lowering interfaces with the rest of lowering.
4 ! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
6 subroutine test_transformational_implemented_with_runtime_allocation(x
)
8 ! MINLOC result is allocated inside the runtime and returned in
9 ! a descriptor that was passed by reference to the runtime.
10 ! Lowering does the following:
11 ! - declares the temp created by the runtime as an hlfir variable.
12 ! - "moves" this variable to an hlfir.expr
13 ! - associate the expression to takes_array_arg dummy argument
14 ! - destroys the expression after the call.
16 ! After bufferization, this will allow the buffer created by the
17 ! runtime to be passed to takes_array_arg without creating any
18 ! other temporaries and to be deallocated after the call.
19 call takes_array_arg(minloc(x
))
21 ! CHECK-LABEL: func.func @_QPtest_transformational_implemented_with_runtime_allocation(
22 ! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<10x10xf32>> {fir.bindc_name = "x"}) {
23 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?xi32>>>
24 ! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.ref<!fir.box<none>>
25 ! CHECK: %[[VAL_22:.*]] = fir.call @_FortranAMinlocReal4(%[[VAL_17]], {{.*}}
26 ! CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
27 ! CHECK: %[[VAL_26:.*]] = fir.box_addr %[[VAL_23]] : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
28 ! CHECK: %[[VAL_28:.*]]:2 = hlfir.declare %[[VAL_26]](%{{.*}}) {uniq_name = ".tmp.intrinsic_result"} : (!fir.heap<!fir.array<?xi32>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
29 ! CHECK: %[[VAL_29:.*]] = arith.constant true
30 ! CHECK: %[[VAL_30:.*]] = hlfir.as_expr %[[VAL_28]]#0 move %[[VAL_29]] : (!fir.box<!fir.array<?xi32>>, i1) -> !hlfir.expr<?xi32>
31 ! CHECK: %[[VAL_32:.*]]:3 = hlfir.associate %[[VAL_30]](%{{.*}}) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
32 ! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_32]]#1 : (!fir.ref<!fir.array<?xi32>>) -> !fir.ref<!fir.array<2xi32>>
33 ! CHECK: fir.call @_QPtakes_array_arg(%[[VAL_33]])
34 ! CHECK: hlfir.end_associate %[[VAL_32]]#1, %[[VAL_32]]#2 : !fir.ref<!fir.array<?xi32>>, i1
35 ! CHECK: hlfir.destroy %[[VAL_30]] : !hlfir.expr<?xi32>