xref: /llvm-project/flang/test/Lower/HLFIR/transformational.f90 (revision 1710c8cf0f8def4984893e9dd646579de5528d95)
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-hlfir -o - %s | FileCheck %s
5
6subroutine test_transformational_implemented_with_runtime_allocation(x)
7  real :: x(10, 10)
8  ! MINLOC result is allocated inside the runtime and returned in
9  ! a descriptor that was passed by reference to the runtime.
10  ! Lowering goes via a hlfir.minloc intrinsic.
11
12  ! After bufferization, this will allow the buffer created by the
13  ! runtime to be passed to takes_array_arg without creating any
14  ! other temporaries and to be deallocated after the call.
15  call takes_array_arg(minloc(x))
16end subroutine
17! CHECK-LABEL: func.func @_QPtest_transformational_implemented_with_runtime_allocation(
18! CHECK-SAME:                                                                          %[[ARG0:.*]]: !fir.ref<!fir.array<10x10xf32>> {fir.bindc_name = "x"}) {
19! CHECK:  %[[VAL_1:.*]]:2 = hlfir.declare %[[ARG0]](%{{.*}}) dummy_scope %{{[0-9]+}} {uniq_name = "_QFtest_transformational_implemented_with_runtime_allocationEx"}
20! CHECK:  %[[VAL_2:.*]] = hlfir.minloc %[[VAL_1]]#0
21! CHECK:  %[[VAL_3:.*]] = hlfir.shape_of %[[VAL_2]]
22! CHECK:  %[[VAL_4:.*]]:3 = hlfir.associate %[[VAL_2]](%[[VAL_3]]) {adapt.valuebyref}
23! CHECK:  fir.call @_QPtakes_array_arg(%[[VAL_4]]#1)
24! CHECK:  hlfir.end_associate %[[VAL_4]]#1, %[[VAL_4]]#2 : !fir.ref<!fir.array<2xi32>>, i1
25! CHECK:  hlfir.destroy %[[VAL_2]] : !hlfir.expr<2xi32>
26