| 1 |
! Tests that "loop-local values" are properly handled by localizing them to the |
| 2 |
! body of the loop nest. See `collectLoopLocalValues` and `localizeLoopLocalValue` |
| 3 |
! for a definition of "loop-local values" and how they are handled. |
| 4 |
|
| 5 |
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=host %s -o - \ |
| 6 |
! RUN: | FileCheck %s |
| 7 |
module struct_mod |
| 8 |
type test_struct |
| 9 |
integer, allocatable :: x_ |
| 10 |
end type |
| 11 |
|
| 12 |
interface test_struct |
| 13 |
pure module function construct_from_components(x) result(struct) |
| 14 |
implicit none |
| 15 |
integer, intent(in) :: x |
| 16 |
type(test_struct) struct |
| 17 |
end function |
| 18 |
end interface |
| 19 |
end module |
| 20 |
|
| 21 |
submodule(struct_mod) struct_sub |
| 22 |
implicit none |
| 23 |
|
| 24 |
contains |
| 25 |
module procedure construct_from_components |
| 26 |
struct%x_ = x |
| 27 |
end procedure |
| 28 |
end submodule struct_sub |
| 29 |
|
| 30 |
program main |
| 31 |
use struct_mod, only : test_struct |
| 32 |
|
| 33 |
implicit none |
| 34 |
type(test_struct), dimension(10) :: a |
| 35 |
integer :: i |
| 36 |
integer :: total |
| 37 |
|
| 38 |
do concurrent (i=1:10) |
| 39 |
a(i) = test_struct(i) |
| 40 |
end do |
| 41 |
|
| 42 |
do i=1,10 |
| 43 |
total = total + a(i)%x_ |
| 44 |
end do |
| 45 |
|
| 46 |
print *, "total =", total |
| 47 |
end program main |
| 48 |
|
| 49 |
! CHECK: omp.parallel { |
| 50 |
! CHECK: %[[LOCAL_TEMP:.*]] = fir.alloca !fir.type<_QMstruct_modTtest_struct{x_:!fir.box<!fir.heap<i32>>}> {bindc_name = ".result"} |
| 51 |
! CHECK: omp.wsloop { |
| 52 |
! CHECK: omp.loop_nest {{.*}} { |
| 53 |
! CHECK: %[[TEMP_VAL:.*]] = fir.call @_QMstruct_modPconstruct_from_components |
| 54 |
! CHECK: fir.save_result %[[TEMP_VAL]] to %[[LOCAL_TEMP]] |
| 55 |
! CHECK: %[[EMBOXED_LOCAL:.*]] = fir.embox %[[LOCAL_TEMP]] |
| 56 |
! CHECK: %[[CONVERTED_LOCAL:.*]] = fir.convert %[[EMBOXED_LOCAL]] |
| 57 |
! CHECK: fir.call @_FortranADestroy(%[[CONVERTED_LOCAL]]) |
| 58 |
! CHECK: omp.yield |
| 59 |
! CHECK: } |
| 60 |
! CHECK: } |
| 61 |
! CHECK: omp.terminator |
| 62 |
! CHECK: } |