Debian Codegraph @

flang/test/Lower/OpenMP/declare-target-implicit-func-and-subr-cap.f90

raw
1 !RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2 !RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE
3 !RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s
4 !RUN: bbc -emit-hlfir -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefix=DEVICE
5
6 ! CHECK-LABEL: func.func @_QPimplicitly_captured
7 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
8 function implicitly_captured(toggle) result(k)
9 integer :: i, j, k
10 logical :: toggle
11 i = 10
12 j = 5
13 if (toggle) then
14 k = i
15 else
16 k = j
17 end if
18 end function implicitly_captured
19
20
21 ! CHECK-LABEL: func.func @_QPtarget_function
22 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
23 function target_function(toggle) result(i)
24 !$omp declare target
25 integer :: i
26 logical :: toggle
27 i = implicitly_captured(toggle)
28 end function target_function
29
30 !! -----
31
32 ! CHECK-LABEL: func.func @_QPimplicitly_captured_twice
33 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
34 function implicitly_captured_twice() result(k)
35 integer :: i
36 i = 10
37 k = i
38 end function implicitly_captured_twice
39
40 ! CHECK-LABEL: func.func @_QPtarget_function_twice_host
41 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>{{.*}}}
42 function target_function_twice_host() result(i)
43 !$omp declare target to(target_function_twice_host) device_type(host)
44 integer :: i
45 i = implicitly_captured_twice()
46 end function target_function_twice_host
47
48 ! DEVICE-LABEL: func.func @_QPtarget_function_twice_device
49 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
50 function target_function_twice_device() result(i)
51 !$omp declare target to(target_function_twice_device) device_type(nohost)
52 integer :: i
53 i = implicitly_captured_twice()
54 end function target_function_twice_device
55
56 !! -----
57
58 ! DEVICE-LABEL: func.func @_QPimplicitly_captured_nest
59 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
60 function implicitly_captured_nest() result(k)
61 integer :: i
62 i = 10
63 k = i
64 end function implicitly_captured_nest
65
66 ! DEVICE-LABEL: func.func @_QPimplicitly_captured_one
67 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to){{.*}}}
68 function implicitly_captured_one() result(k)
69 k = implicitly_captured_nest()
70 end function implicitly_captured_one
71
72 ! DEVICE-LABEL: func.func @_QPimplicitly_captured_two
73 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
74 function implicitly_captured_two() result(k)
75 integer :: i
76 i = 10
77 k = i
78 end function implicitly_captured_two
79
80 ! DEVICE-LABEL: func.func @_QPtarget_function_test
81 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
82 function target_function_test() result(j)
83 !$omp declare target to(target_function_test) device_type(nohost)
84 integer :: i, j
85 i = implicitly_captured_one()
86 j = implicitly_captured_two() + i
87 end function target_function_test
88
89 !! -----
90
91 ! CHECK-LABEL: func.func @_QPimplicitly_captured_nest_twice
92 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
93 function implicitly_captured_nest_twice() result(k)
94 integer :: i
95 i = 10
96 k = i
97 end function implicitly_captured_nest_twice
98
99 ! CHECK-LABEL: func.func @_QPimplicitly_captured_one_twice
100 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
101 function implicitly_captured_one_twice() result(k)
102 k = implicitly_captured_nest_twice()
103 end function implicitly_captured_one_twice
104
105 ! CHECK-LABEL: func.func @_QPimplicitly_captured_two_twice
106 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
107 function implicitly_captured_two_twice() result(k)
108 integer :: i
109 i = 10
110 k = i
111 end function implicitly_captured_two_twice
112
113 ! DEVICE-LABEL: func.func @_QPtarget_function_test_device
114 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
115 function target_function_test_device() result(j)
116 !$omp declare target to(target_function_test_device) device_type(nohost)
117 integer :: i, j
118 i = implicitly_captured_one_twice()
119 j = implicitly_captured_two_twice() + i
120 end function target_function_test_device
121
122 ! CHECK-LABEL: func.func @_QPtarget_function_test_host
123 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>{{.*}}}
124 function target_function_test_host() result(j)
125 !$omp declare target to(target_function_test_host) device_type(host)
126 integer :: i, j
127 i = implicitly_captured_one_twice()
128 j = implicitly_captured_two_twice() + i
129 end function target_function_test_host
130
131 !! -----
132
133 ! DEVICE-LABEL: func.func @_QPimplicitly_captured_with_dev_type_recursive
134 ! DEVICE-SAME: {{.*}}attributes {fir.func_recursive, omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
135 recursive 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, k
138 if (increment == 10) then
139 k = increment
140 else
141 k = implicitly_captured_with_dev_type_recursive(increment + 1)
142 end if
143 end function implicitly_captured_with_dev_type_recursive
144
145 ! DEVICE-LABEL: func.func @_QPtarget_function_with_dev_type_recurse
146 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
147 function target_function_with_dev_type_recurse() result(i)
148 !$omp declare target to(target_function_with_dev_type_recurse) device_type(nohost)
149 integer :: i
150 i = implicitly_captured_with_dev_type_recursive(0)
151 end function target_function_with_dev_type_recurse
152
153 !! -----
154
155 module test_module
156 contains
157 ! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_nest_twice
158 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
159 function implicitly_captured_nest_twice() result(i)
160 integer :: i
161 i = 10
162 end function implicitly_captured_nest_twice
163
164 ! CHECK-LABEL: func.func @_QMtest_modulePimplicitly_captured_one_twice
165 ! CHECK-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
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_twice
170
171 ! DEVICE-LABEL: func.func @_QMtest_modulePimplicitly_captured_two_twice
172 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
173 function implicitly_captured_two_twice() result(y)
174 integer :: y
175 y = 5
176 end function implicitly_captured_two_twice
177
178 ! DEVICE-LABEL: func.func @_QMtest_modulePtarget_function_test_device
179 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
180 function target_function_test_device() result(j)
181 !$omp declare target to(target_function_test_device) device_type(nohost)
182 integer :: i, j
183 i = implicitly_captured_one_twice()
184 j = implicitly_captured_two_twice() + i
185 end function target_function_test_device
186 end module test_module
187
188 !! -----
189
190 program mb
191 interface
192 subroutine caller_recursive
193 !$omp declare target to(caller_recursive) device_type(nohost)
194 end subroutine
195
196 recursive subroutine implicitly_captured_recursive(increment)
197 integer :: increment
198 end subroutine
199 end interface
200 end program
201
202 ! DEVICE-LABEL: func.func @_QPimplicitly_captured_recursive
203 ! DEVICE-SAME: {{.*}}attributes {fir.func_recursive, omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
204 recursive subroutine implicitly_captured_recursive(increment)
205 integer :: increment
206 if (increment == 10) then
207 return
208 else
209 call implicitly_captured_recursive(increment + 1)
210 end if
211 end subroutine
212
213 ! DEVICE-LABEL: func.func @_QPcaller_recursive
214 ! DEVICE-SAME: {{.*}}attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>{{.*}}}
215 subroutine caller_recursive
216 !$omp declare target to(caller_recursive) device_type(nohost)
217 call implicitly_captured_recursive(0)
218 end subroutine