219 lines · plain
1!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s2!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE3!RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s4!RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=50 -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE5 6! CHECK-LABEL: func.func @_QPimplicitly_captured7! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}8function implicitly_captured(toggle) result(k)9 integer :: i, j, k10 logical :: toggle11 i = 1012 j = 513 if (toggle) then14 k = i15 else16 k = j17 end if18end function implicitly_captured19 20 21! CHECK-LABEL: func.func @_QPtarget_function22! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}23function target_function(toggle) result(i)24!$omp declare target25 integer :: i26 logical :: toggle27 i = implicitly_captured(toggle)28end function target_function29 30!! -----31 32! CHECK-LABEL: func.func @_QPimplicitly_captured_twice33! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}34function implicitly_captured_twice() result(k)35 integer :: i36 i = 1037 k = i38end function implicitly_captured_twice39 40! CHECK-LABEL: func.func @_QPtarget_function_twice_host41! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to), automap = false>{{.*}}}42function target_function_twice_host() result(i)43!$omp declare target to(target_function_twice_host) device_type(host)44 integer :: i45 i = implicitly_captured_twice()46end function target_function_twice_host47 48! DEVICE-LABEL: func.func @_QPtarget_function_twice_device49! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}50function target_function_twice_device() result(i)51!$omp declare target to(target_function_twice_device) device_type(nohost)52 integer :: i53 i = implicitly_captured_twice()54end function target_function_twice_device55 56!! -----57 58! DEVICE-LABEL: func.func @_QPimplicitly_captured_nest59! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}60function implicitly_captured_nest() result(k)61 integer :: i62 i = 1063 k = i64end function implicitly_captured_nest65 66! DEVICE-LABEL: func.func @_QPimplicitly_captured_one67! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to){{.*}}}68function implicitly_captured_one() result(k)69 k = implicitly_captured_nest()70end function implicitly_captured_one71 72! DEVICE-LABEL: func.func @_QPimplicitly_captured_two73! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}74function implicitly_captured_two() result(k)75 integer :: i76 i = 1077 k = i78end function implicitly_captured_two79 80! DEVICE-LABEL: func.func @_QPtarget_function_test81! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}82function target_function_test() result(j)83!$omp declare target to(target_function_test) device_type(nohost)84 integer :: i, j85 i = implicitly_captured_one()86 j = implicitly_captured_two() + i87end function target_function_test88 89!! -----90 91! CHECK-LABEL: func.func @_QPimplicitly_captured_nest_twice92! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}93function implicitly_captured_nest_twice() result(k)94 integer :: i95 i = 1096 k = i97end function implicitly_captured_nest_twice98 99! CHECK-LABEL: func.func @_QPimplicitly_captured_one_twice100! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}101function implicitly_captured_one_twice() result(k)102 k = implicitly_captured_nest_twice()103end function implicitly_captured_one_twice104 105! CHECK-LABEL: func.func @_QPimplicitly_captured_two_twice106! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}107function implicitly_captured_two_twice() result(k)108 integer :: i109 i = 10110 k = i111end function implicitly_captured_two_twice112 113! DEVICE-LABEL: func.func @_QPtarget_function_test_device114! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}115function target_function_test_device() result(j)116 !$omp declare target to(target_function_test_device) device_type(nohost)117 integer :: i, j118 i = implicitly_captured_one_twice()119 j = implicitly_captured_two_twice() + i120end function target_function_test_device121 122! CHECK-LABEL: func.func @_QPtarget_function_test_host123! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to), automap = false>{{.*}}}124function target_function_test_host() result(j)125 !$omp declare target to(target_function_test_host) device_type(host)126 integer :: i, j127 i = implicitly_captured_one_twice()128 j = implicitly_captured_two_twice() + i129end function target_function_test_host130 131!! -----132 133! DEVICE-LABEL: func.func @_QPimplicitly_captured_with_dev_type_recursive134! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}135recursive function implicitly_captured_with_dev_type_recursive(increment) result(k)136!$omp declare target to(implicitly_captured_with_dev_type_recursive) device_type(host)137 integer :: increment, k138 if (increment == 10) then139 k = increment140 else141 k = implicitly_captured_with_dev_type_recursive(increment + 1)142 end if143end function implicitly_captured_with_dev_type_recursive144 145! DEVICE-LABEL: func.func @_QPtarget_function_with_dev_type_recurse146! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}147function target_function_with_dev_type_recurse() result(i)148!$omp declare target to(target_function_with_dev_type_recurse) device_type(nohost)149 integer :: i150 i = implicitly_captured_with_dev_type_recursive(0)151end function target_function_with_dev_type_recurse152 153!! -----154 155module test_module156contains157! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_nest_twice158! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}159 function implicitly_captured_nest_twice() result(i)160 integer :: i161 i = 10162 end function implicitly_captured_nest_twice163 164! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_one_twice165! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to), automap = false>{{.*}}}166 function implicitly_captured_one_twice() result(k)167 !$omp declare target to(implicitly_captured_one_twice) device_type(host)168 k = implicitly_captured_nest_twice()169 end function implicitly_captured_one_twice170 171! DEVICE-LABEL: func.func @_QMtest_modulePimplicitly_captured_two_twice172! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}173 function implicitly_captured_two_twice() result(y)174 integer :: y175 y = 5176 end function implicitly_captured_two_twice177 178! DEVICE-LABEL: func.func @_QMtest_modulePtarget_function_test_device179! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}180 function target_function_test_device() result(j)181 !$omp declare target to(target_function_test_device) device_type(nohost)182 integer :: i, j183 i = implicitly_captured_one_twice()184 j = implicitly_captured_two_twice() + i185 end function target_function_test_device186end module test_module187 188!! -----189 190program mb191 interface192 subroutine caller_recursive193 !$omp declare target to(caller_recursive) device_type(nohost)194 end subroutine195 196 recursive subroutine implicitly_captured_recursive(increment)197 integer :: increment198 end subroutine199 end interface200end program201 202! DEVICE-LABEL: func.func @_QPimplicitly_captured_recursive203! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}204recursive subroutine implicitly_captured_recursive(increment)205 integer :: increment206 if (increment == 10) then207 return208 else209 call implicitly_captured_recursive(increment + 1)210 end if211end subroutine212 213! DEVICE-LABEL: func.func @_QPcaller_recursive214! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to), automap = false>{{.*}}}215subroutine caller_recursive216!$omp declare target to(caller_recursive) device_type(nohost)217 call implicitly_captured_recursive(0)218end subroutine219