[RISCV] Rename a lambda to have plural nouns to reflect that it contains a loop. NFC
[llvm-project.git] / flang / test / Lower / OpenMP / task.f90
blob6e525a044b011eebb5918d2071bd67f06bccfb3c
1 ! REQUIRES: openmp_runtime
3 !RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s
5 !CHECK-LABEL: func @_QPomp_task_simple() {
6 subroutine omp_task_simple
7 !CHECK: omp.task {
8 !$omp task
9 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
10 call foo()
11 !CHECK: omp.terminator
12 !$omp end task
13 end subroutine omp_task_simple
15 !===============================================================================
16 ! `if` clause
17 !===============================================================================
19 !CHECK-LABEL: func @_QPomp_task_if(%{{.+}}) {
20 subroutine omp_task_if(bar)
21 logical, intent(inout) :: bar
22 !CHECK: omp.task if(%{{.+}}) {
23 !$omp task if(bar)
24 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
25 call foo()
26 !CHECK: omp.terminator
27 !$omp end task
28 end subroutine omp_task_if
30 !===============================================================================
31 ! `final` clause
32 !===============================================================================
34 !CHECK-LABEL: func @_QPomp_task_final(%{{.+}}) {
35 subroutine omp_task_final(bar)
36 logical, intent(inout) :: bar
37 !CHECK: omp.task final(%{{.+}}) {
38 !$omp task final(bar)
39 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
40 call foo()
41 !CHECK: omp.terminator
42 !$omp end task
43 end subroutine omp_task_final
45 !===============================================================================
46 ! `priority` clause
47 !===============================================================================
49 !CHECK-LABEL: func @_QPomp_task_priority(%{{.+}}) {
50 subroutine omp_task_priority(bar)
51 integer, intent(inout) :: bar
52 !CHECK: omp.task priority(%{{.+}}) {
53 !$omp task priority(bar)
54 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
55 call foo()
56 !CHECK: omp.terminator
57 !$omp end task
58 end subroutine omp_task_priority
60 !===============================================================================
61 ! `allocate` clause
62 !===============================================================================
64 !CHECK-LABEL: func @_QPtask_allocate
65 subroutine task_allocate()
66 use omp_lib
67 integer :: x
68 !CHECK: omp.task allocate(%{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>) {
69 !$omp task allocate(omp_high_bw_mem_alloc: x) private(x)
70 !CHECK: arith.addi
71 x = x + 12
72 !CHECK: omp.terminator
73 !$omp end task
74 end subroutine task_allocate
76 !===============================================================================
77 ! `depend` clause
78 !===============================================================================
80 !CHECK-LABEL: func @_QPtask_depend
81 subroutine task_depend()
82 integer :: x
83 !CHECK: omp.task depend(taskdependin -> %{{.+}} : !fir.ref<i32>) {
84 !$omp task depend(in : x)
85 !CHECK: arith.addi
86 x = x + 12
87 !CHECK: omp.terminator
88 !$omp end task
89 end subroutine task_depend
91 !CHECK-LABEL: func @_QPtask_depend_non_int
92 subroutine task_depend_non_int()
93 character(len = 15) :: x
94 integer, allocatable :: y
95 complex :: z
96 !CHECK: omp.task depend(taskdependin -> %{{.+}} : !fir.ref<!fir.char<1,15>>, taskdependin -> %{{.+}} : !fir.ref<!fir.box<!fir.heap<i32>>>, taskdependin -> %{{.+}} : !fir.ref<complex<f32>>) {
97 !$omp task depend(in : x, y, z)
98 !CHECK: omp.terminator
99 !$omp end task
100 end subroutine task_depend_non_int
102 !CHECK-LABEL: func @_QPtask_depend_all_kinds_one_task
103 subroutine task_depend_all_kinds_one_task()
104 integer :: x
105 !CHECK: omp.task depend(taskdependin -> %{{.+}} : !fir.ref<i32>, taskdependout -> %{{.+}} : !fir.ref<i32>, taskdependinout -> %{{.+}} : !fir.ref<i32>) {
106 !$omp task depend(in : x) depend(out : x) depend(inout : x)
107 !CHECK: arith.addi
108 x = x + 12
109 !CHECK: omp.terminator
110 !$omp end task
111 end subroutine task_depend_all_kinds_one_task
113 !CHECK-LABEL: func @_QPtask_depend_multi_var
114 subroutine task_depend_multi_var()
115 integer :: x
116 integer :: y
117 !CHECK: omp.task depend(taskdependin -> %{{.*}} : !fir.ref<i32>, taskdependin -> %{{.+}} : !fir.ref<i32>) private({{.*x_firstprivate.*}}, {{.*y_firstprivate.*}}) {
118 !$omp task depend(in :x,y)
119 !CHECK: arith.addi
120 x = x + 12
121 y = y + 12
122 !CHECK: omp.terminator
123 !$omp end task
124 end subroutine task_depend_multi_var
126 !CHECK-LABEL: func @_QPtask_depend_multi_task
127 subroutine task_depend_multi_task()
128 integer :: x
129 !CHECK: omp.task depend(taskdependout -> %{{.+}} : !fir.ref<i32>)
130 !$omp task depend(out : x)
131 !CHECK: arith.addi
132 x = x + 12
133 !CHECK: omp.terminator
134 !$omp end task
135 !CHECK: omp.task depend(taskdependinout -> %{{.+}} : !fir.ref<i32>)
136 !$omp task depend(inout : x)
137 !CHECK: arith.addi
138 x = x + 12
139 !CHECK: omp.terminator
140 !$omp end task
141 !CHECK: omp.task depend(taskdependin -> %{{.+}} : !fir.ref<i32>)
142 !$omp task depend(in : x)
143 !CHECK: arith.addi
144 x = x + 12
145 !CHECK: omp.terminator
146 !$omp end task
147 end subroutine task_depend_multi_task
149 !===============================================================================
150 ! `private` clause
151 !===============================================================================
152 !CHECK-LABEL: func @_QPtask_private
153 subroutine task_private
154 type mytype
155 integer :: x
156 end type mytype
158 !CHECK: %[[INT_ALLOCA:.*]] = fir.alloca i32 {bindc_name = "int_var", uniq_name = "_QFtask_privateEint_var"}
159 !CHECK: %[[INT_VAR:.+]]:2 = hlfir.declare %[[INT_ALLOCA]] {uniq_name = "_QFtask_privateEint_var"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
160 !CHECK: %[[MYTYPE_ALLOCA:.*]] = fir.alloca !fir.type<_QFtask_privateTmytype{x:i32}> {bindc_name = "mytype_var", uniq_name = "_QFtask_privateEmytype_var"}
161 !CHECK: %[[MYTYPE_VAR:.+]]:2 = hlfir.declare %[[MYTYPE_ALLOCA]] {uniq_name = "_QFtask_privateEmytype_var"} : (!fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>) -> (!fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>, !fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>)
162 integer :: int_var
163 type(mytype) :: mytype_var
165 !CHECK: fir.call @_QPbar(%[[INT_VAR]]#1, %[[MYTYPE_VAR]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>) -> ()
166 call bar(int_var, mytype_var)
168 !CHECK: omp.task private(@{{.*int_var_private.*}} %[[INT_VAR]]#0 -> %[[INT_VAR_ARG:.*]], @{{.*mytype_var_private.*}} %[[MYTYPE_VAR]]#0 -> %[[MYTYPE_VAR_ARG:.*]] : !fir.ref<i32>, !fir.ref<!fir.type<{{.*}}>) {
169 !$omp task private(int_var, mytype_var)
170 !CHECK: %[[INT_VAR_PRIVATE:.+]]:2 = hlfir.declare %[[INT_VAR_ARG]] {uniq_name = "_QFtask_privateEint_var"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
171 !CHECK: %[[MYTYPE_VAR_PRIVATE:.+]]:2 = hlfir.declare %[[MYTYPE_VAR_ARG]] {uniq_name = "_QFtask_privateEmytype_var"} : (!fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>) -> (!fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>, !fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>)
172 !CHECK: fir.call @_QPbar(%[[INT_VAR_PRIVATE]]#1, %[[MYTYPE_VAR_PRIVATE]]#1) fastmath<contract> : (!fir.ref<i32>, !fir.ref<!fir.type<_QFtask_privateTmytype{x:i32}>>) -> ()
173 call bar(int_var, mytype_var)
174 !CHECK: omp.terminator
175 !$omp end task
176 end subroutine task_private
178 !===============================================================================
179 ! `firstprivate` clause
180 !===============================================================================
181 !CHECK-LABEL: func @_QPtask_firstprivate
182 subroutine task_firstprivate
183 type mytype
184 integer :: x
185 end type mytype
187 !CHECK: %[[INT_ALLOCA:.+]] = fir.alloca i32 {bindc_name = "int_var", uniq_name = "_QFtask_firstprivateEint_var"}
188 !CHECK: %[[INT_VAR:.+]]:2 = hlfir.declare %[[INT_ALLOCA]] {uniq_name = "_QFtask_firstprivateEint_var"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
189 !CHECK: %[[MYTYPE_ALLOCA:.+]] = fir.alloca !fir.type<_QFtask_firstprivateTmytype{x:i32}> {bindc_name = "mytype_var", uniq_name = "_QFtask_firstprivateEmytype_var"}
190 !CHECK: %[[MYTYPE_VAR:.+]]:2 = hlfir.declare %[[MYTYPE_ALLOCA]] {uniq_name = "_QFtask_firstprivateEmytype_var"} : (!fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>) -> (!fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>, !fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>)
191 integer :: int_var
192 type(mytype) :: mytype_var
194 !CHECK: fir.call @_QPbaz(%[[INT_VAR]]#1, %[[MYTYPE_VAR]]#1) fastmath<contract> : (!fir.ref<i32>, !fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>) -> ()
195 call baz(int_var, mytype_var)
197 !CHECK: omp.task private(@{{.*int_var_firstprivate.*}} %[[INT_VAR]]#0 -> %[[INT_VAR_ARG:.*]], @{{.*mytype_var_firstprivate.*}} %[[MYTYPE_VAR]]#0 -> %[[MYTYPE_VAR_ARG:.*]] : !fir.ref<i32>, !fir.ref<{{.*}}) {
198 !$omp task firstprivate(int_var, mytype_var)
199 !CHECK: %[[INT_VAR_FIRSTPRIVATE:.+]]:2 = hlfir.declare %[[INT_VAR_ARG]] {uniq_name = "_QFtask_firstprivateEint_var"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
200 !CHECK: %[[MYTYPE_VAR_FIRSTPRIVATE:.+]]:2 = hlfir.declare %[[MYTYPE_VAR_ARG]] {uniq_name = "_QFtask_firstprivateEmytype_var"} : (!fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>) -> (!fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>, !fir.ref<!fir.type<_QFtask_firstprivateTmytype{x:i32}>>)
201 call baz(int_var, mytype_var)
202 !CHECK: omp.terminator
203 !$omp end task
204 end subroutine task_firstprivate
206 !===============================================================================
207 ! Multiple clauses
208 !===============================================================================
210 !CHECK-LABEL: func @_QPtask_multiple_clauses
211 subroutine task_multiple_clauses()
212 use omp_lib
214 !CHECK: %[[X_ALLOCA:.+]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtask_multiple_clausesEx"}
215 !CHECK: %[[X:.+]]:2 = hlfir.declare %[[X_ALLOCA]] {uniq_name = "_QFtask_multiple_clausesEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
216 !CHECK: %[[Y_ALLOCA:.+]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFtask_multiple_clausesEy"}
217 !CHECK: %[[Y:.+]]:2 = hlfir.declare %[[Y_ALLOCA]] {uniq_name = "_QFtask_multiple_clausesEy"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
218 !CHECK: %[[Z_ALLOCA:.+]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFtask_multiple_clausesEz"}
219 !CHECK: %[[Z:.+]]:2 = hlfir.declare %[[Z_ALLOCA]] {uniq_name = "_QFtask_multiple_clausesEz"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
220 integer :: x, y, z
221 logical :: buzz
223 !CHECK: omp.task allocate(%{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>) final(%{{.+}}) if(%{{.+}}) priority(%{{.+}}) private({{.*}}) {
224 !$omp task if(buzz) final(buzz) priority(z) allocate(omp_high_bw_mem_alloc: x) private(x) firstprivate(y)
226 !CHECK: %[[X_PRIV:.+]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFtask_multiple_clausesEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
227 !CHECK: %[[Y_PRIV:.+]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFtask_multiple_clausesEy"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
229 !CHECK: arith.addi
230 x = x + 12
231 !CHECK: arith.subi
232 y = y - 12
234 !CHECK: omp.terminator
235 !$omp end task
236 end subroutine task_multiple_clauses
238 subroutine task_mergeable()
239 !CHECK: omp.task mergeable {
240 !CHECK: omp.terminator
241 !CHECK: }
242 !$omp task mergeable
243 !$omp end task
244 end subroutine