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
9 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
11 !CHECK: omp.terminator
13 end subroutine omp_task_simple
15 !===============================================================================
17 !===============================================================================
19 !CHECK-LABEL: func @_QPomp_task_if(%{{.+}}) {
20 subroutine omp_task_if(bar
)
21 logical, intent(inout
) :: bar
22 !CHECK: omp.task if(%{{.+}}) {
24 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
26 !CHECK: omp.terminator
28 end subroutine omp_task_if
30 !===============================================================================
32 !===============================================================================
34 !CHECK-LABEL: func @_QPomp_task_final(%{{.+}}) {
35 subroutine omp_task_final(bar
)
36 logical, intent(inout
) :: bar
37 !CHECK: omp.task final(%{{.+}}) {
39 !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
41 !CHECK: omp.terminator
43 end subroutine omp_task_final
45 !===============================================================================
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() {{.*}}: () -> ()
56 !CHECK: omp.terminator
58 end subroutine omp_task_priority
60 !===============================================================================
62 !===============================================================================
64 !CHECK-LABEL: func @_QPtask_allocate
65 subroutine task_allocate()
68 !CHECK: omp.task allocate(%{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>) {
69 !$omp task allocate(omp_high_bw_mem_alloc: x) private(x)
72 !CHECK: omp.terminator
74 end subroutine task_allocate
76 !===============================================================================
78 !===============================================================================
80 !CHECK-LABEL: func @_QPtask_depend
81 subroutine task_depend()
83 !CHECK: omp.task depend(taskdependin -> %{{.+}} : !fir.ref<i32>) {
84 !$omp task depend(in : x)
87 !CHECK: omp.terminator
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
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
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()
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)
109 !CHECK: omp.terminator
111 end subroutine task_depend_all_kinds_one_task
113 !CHECK-LABEL: func @_QPtask_depend_multi_var
114 subroutine task_depend_multi_var()
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)
122 !CHECK: omp.terminator
124 end subroutine task_depend_multi_var
126 !CHECK-LABEL: func @_QPtask_depend_multi_task
127 subroutine task_depend_multi_task()
129 !CHECK: omp.task depend(taskdependout -> %{{.+}} : !fir.ref<i32>)
130 !$omp task depend(out : x)
133 !CHECK: omp.terminator
135 !CHECK: omp.task depend(taskdependinout -> %{{.+}} : !fir.ref<i32>)
136 !$omp task depend(inout : x)
139 !CHECK: omp.terminator
141 !CHECK: omp.task depend(taskdependin -> %{{.+}} : !fir.ref<i32>)
142 !$omp task depend(in : x)
145 !CHECK: omp.terminator
147 end subroutine task_depend_multi_task
149 !===============================================================================
151 !===============================================================================
152 !CHECK-LABEL: func @_QPtask_private
153 subroutine task_private
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}>>)
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
176 end subroutine task_private
178 !===============================================================================
179 ! `firstprivate` clause
180 !===============================================================================
181 !CHECK-LABEL: func @_QPtask_firstprivate
182 subroutine task_firstprivate
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}>>)
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
204 end subroutine task_firstprivate
206 !===============================================================================
208 !===============================================================================
210 !CHECK-LABEL: func @_QPtask_multiple_clauses
211 subroutine task_multiple_clauses()
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>)
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>)
234 !CHECK: omp.terminator
236 end subroutine task_multiple_clauses
238 subroutine task_mergeable()
239 !CHECK: omp.task mergeable {
240 !CHECK: omp.terminator