[Clang][ASTMatcher] Add a matcher for the name of a DependentScopeDeclRefExpr (#121656)
[llvm-project.git] / flang / test / Lower / OpenMP / single.f90
blob9fd34344eb43be6a011e57c8eff6ca13350e3f78
1 ! REQUIRES: openmp_runtime
3 !RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s
4 !RUN: bbc -emit-hlfir %openmp_flags %s -o - | FileCheck %s
6 !===============================================================================
7 ! Single construct
8 !===============================================================================
10 !CHECK-LABEL: func @_QPomp_single
11 !CHECK-SAME: (%[[X:.*]]: !fir.ref<i32> {fir.bindc_name = "x"})
12 subroutine omp_single(x)
13 integer, intent(inout) :: x
14 !CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFomp_singleEx"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
15 !CHECK: omp.parallel
16 !$omp parallel
17 !CHECK: omp.single
18 !$omp single
19 !CHECK: %[[xval:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
20 !CHECK: %[[res:.*]] = arith.addi %[[xval]], %{{.*}} : i32
21 !CHECK: hlfir.assign %[[res]] to %[[X_DECL]]#0 : i32, !fir.ref<i32>
22 x = x + 12
23 !CHECK: omp.terminator
24 !$omp end single
25 !CHECK: omp.terminator
26 !$omp end parallel
27 end subroutine omp_single
29 !===============================================================================
30 ! Single construct with nowait
31 !===============================================================================
33 !CHECK-LABEL: func @_QPomp_single_nowait
34 !CHECK-SAME: (%[[X:.*]]: !fir.ref<i32> {fir.bindc_name = "x"})
35 subroutine omp_single_nowait(x)
36 integer, intent(inout) :: x
37 !CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFomp_single_nowaitEx"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>)
38 !CHECK: omp.parallel
39 !$omp parallel
40 !CHECK: omp.single nowait
41 !$omp single
42 !CHECK: %[[xval:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
43 !CHECK: %[[res:.*]] = arith.addi %[[xval]], %{{.*}} : i32
44 !CHECK: hlfir.assign %[[res]] to %[[X_DECL]]#0 : i32, !fir.ref<i32>
45 x = x + 12
46 !CHECK: omp.terminator
47 !$omp end single nowait
48 !CHECK: omp.terminator
49 !$omp end parallel
50 end subroutine omp_single_nowait
52 !===============================================================================
53 ! Single construct with allocate
54 !===============================================================================
56 !CHECK-LABEL: func @_QPsingle_allocate
57 subroutine single_allocate()
58 use omp_lib
59 integer :: x
60 !CHECK: omp.parallel {
61 !$omp parallel
62 !CHECK: omp.single allocate(%{{.+}} : i64 -> %{{.+}} : !fir.ref<i32>) {
63 !$omp single allocate(omp_high_bw_mem_alloc: x) private(x)
64 !CHECK: arith.addi
65 x = x + 12
66 !CHECK: omp.terminator
67 !$omp end single
68 !CHECK: omp.terminator
69 !$omp end parallel
70 end subroutine single_allocate
72 !===============================================================================
73 ! Single construct with private/firstprivate
74 !===============================================================================
76 ! CHECK-LABEL: func.func @_QPsingle_privatization(
77 ! CHECK-SAME: %[[X:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
78 ! CHECK-SAME: %[[Y:.*]]: !fir.ref<f64> {fir.bindc_name = "y"}) {
79 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFsingle_privatizationEx"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)
80 ! CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %[[Y]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFsingle_privatizationEy"} : (!fir.ref<f64>, !fir.dscope) -> (!fir.ref<f64>, !fir.ref<f64>)
81 ! CHECK: omp.single {
82 ! CHECK: %[[X_PVT:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatizationEx"}
83 ! CHECK: %[[X_PVT_DECL:.*]]:2 = hlfir.declare %[[X_PVT]] {uniq_name = "_QFsingle_privatizationEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
84 ! CHECK: %[[Y_PVT:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatizationEy"}
85 ! CHECK: %[[Y_PVT_DECL:.*]]:2 = hlfir.declare %[[Y_PVT]] {uniq_name = "_QFsingle_privatizationEy"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
86 ! CHECK: %[[Y_LOAD:.*]] = fir.load %[[Y_DECL]]#0 : !fir.ref<f64>
87 ! CHECK: hlfir.assign %[[Y_LOAD]] to %[[Y_PVT_DECL]]#0 : f64, !fir.ref<f64>
88 ! CHECK: fir.call @_QPbar(%[[X_PVT_DECL]]#1, %[[Y_PVT_DECL]]#1) fastmath<contract> : (!fir.ref<f32>, !fir.ref<f64>) -> ()
89 ! CHECK: omp.terminator
90 ! CHECK: }
91 ! CHECK: return
92 ! CHECK: }
94 subroutine single_privatization(x, y)
95 real :: x
96 real(8) :: y
98 !$omp single private(x) firstprivate(y)
99 call bar(x, y)
100 !$omp end single
101 end subroutine
103 ! CHECK-LABEL: func.func @_QPsingle_privatization2(
104 ! CHECK-SAME: %[[X:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
105 ! CHECK-SAME: %[[Y:.*]]: !fir.ref<f64> {fir.bindc_name = "y"}) {
106 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFsingle_privatization2Ex"} : (!fir.ref<f32>, !fir.dscope) -> (!fir.ref<f32>, !fir.ref<f32>)
107 ! CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %[[Y]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFsingle_privatization2Ey"} : (!fir.ref<f64>, !fir.dscope) -> (!fir.ref<f64>, !fir.ref<f64>)
108 ! CHECK: omp.parallel {
109 ! CHECK: omp.single {
110 ! CHECK: %[[X_PVT:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatization2Ex"}
111 ! CHECK: %[[X_PVT_DECL:.*]]:2 = hlfir.declare %[[X_PVT]] {uniq_name = "_QFsingle_privatization2Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
112 ! CHECK: %[[Y_PVT:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatization2Ey"}
113 ! CHECK: %[[Y_PVT_DECL:.*]]:2 = hlfir.declare %[[Y_PVT]] {uniq_name = "_QFsingle_privatization2Ey"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
114 ! CHECK: %[[Y_LOAD:.*]] = fir.load %[[Y_DECL]]#0 : !fir.ref<f64>
115 ! CHECK: hlfir.assign %[[Y_LOAD]] to %[[Y_PVT_DECL]]#0 : f64, !fir.ref<f64>
116 ! CHECK: fir.call @_QPbar(%[[X_PVT_DECL]]#1, %[[Y_PVT_DECL]]#1) fastmath<contract> : (!fir.ref<f32>, !fir.ref<f64>) -> ()
117 ! CHECK: omp.terminator
118 ! CHECK: }
119 ! CHECK: omp.terminator
120 ! CHECK: }
121 ! CHECK: return
122 ! CHECK: }
124 subroutine single_privatization2(x, y)
125 real :: x
126 real(8) :: y
128 !$omp parallel
129 !$omp single private(x) firstprivate(y)
130 call bar(x, y)
131 !$omp end single
132 !$omp end parallel
133 end subroutine