Skip to content

Commit d1653c8

Browse files
[Flang][OpenMP] NFC: Versions of critical, master tests with HLFIR flow
The conversion to LLVM dialect test is moved and the translation to LLVM IR is removed from these tests. These are covered separately in convert-to-llvm-openmp-and-fir.fir (for critical, master is already tested in this file) and MLIR to LLVM IR tests.
1 parent d2b7a8e commit d1653c8

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

flang/test/Fir/convert-to-llvm-openmp-and-fir.fir

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,30 @@ func.func @sub_() {
864864
}
865865
return
866866
}
867+
868+
// -----
869+
870+
// CHECK: omp.critical.declare @help hint(contended)
871+
omp.critical.declare @help hint(contended)
872+
873+
// CHECK: llvm.func @omp_critical_() {
874+
func.func @omp_critical_() {
875+
// CHECK: %[[X_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "x", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_criticalEx"} : (i64) -> !llvm.ptr<i32>
876+
%0 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFomp_criticalEx"}
877+
// CHECK: %[[Y_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "y", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_criticalEy"} : (i64) -> !llvm.ptr<i32>
878+
%1 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFomp_criticalEy"}
879+
// CHECK: omp.critical(@help)
880+
omp.critical(@help) {
881+
// CHECK: %[[X_VAL:.*]] = llvm.load %[[X_REF]] : !llvm.ptr<i32>
882+
%2 = fir.load %0 : !fir.ref<i32>
883+
// CHECK: %[[Y_VAL:.*]] = llvm.load %[[Y_REF]] : !llvm.ptr<i32>
884+
%3 = fir.load %1 : !fir.ref<i32>
885+
// CHECK: %[[RESULT:.*]] = llvm.add %[[X_VAL]], %[[Y_VAL]] : i32
886+
%4 = arith.addi %2, %3 : i32
887+
// CHECK: llvm.store %[[RESULT]], %[[X_REF]] : !llvm.ptr<i32>
888+
fir.store %4 to %0 : !fir.ref<i32>
889+
// CHECK: omp.terminator
890+
omp.terminator
891+
}
892+
return
893+
}

flang/test/Lower/OpenMP/critical.f90

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2+
3+
!CHECK: omp.critical.declare @help2 hint(none)
4+
!CHECK: omp.critical.declare @help1 hint(contended)
5+
6+
subroutine omp_critical()
7+
use omp_lib
8+
integer :: x, y
9+
!CHECK: omp.critical(@help1)
10+
!$OMP CRITICAL(help1) HINT(omp_lock_hint_contended)
11+
x = x + y
12+
!CHECK: omp.terminator
13+
!$OMP END CRITICAL(help1)
14+
15+
! Test that the same name can be used again
16+
! Also test with the zero hint expression
17+
!CHECK: omp.critical(@help2)
18+
!$OMP CRITICAL(help2) HINT(omp_lock_hint_none)
19+
x = x - y
20+
!CHECK: omp.terminator
21+
!$OMP END CRITICAL(help2)
22+
23+
!CHECK: omp.critical
24+
!$OMP CRITICAL
25+
y = x + y
26+
!CHECK: omp.terminator
27+
!$OMP END CRITICAL
28+
end subroutine omp_critical

flang/test/Lower/OpenMP/master.f90

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2+
3+
!===============================================================================
4+
! parallel construct with function call which has master construct internally
5+
!===============================================================================
6+
!CHECK-LABEL: func @_QPomp_master
7+
subroutine omp_master()
8+
9+
!CHECK: omp.master {
10+
!$omp master
11+
12+
!CHECK: fir.call @_QPmaster() {{.*}}: () -> ()
13+
call master()
14+
15+
!CHECK: omp.terminator
16+
!$omp end master
17+
18+
end subroutine omp_master
19+
20+
!CHECK-LABEL: func @_QPparallel_function_master
21+
subroutine parallel_function_master()
22+
23+
!CHECK: omp.parallel {
24+
!$omp parallel
25+
26+
!CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
27+
call foo()
28+
29+
!CHECK: omp.terminator
30+
!$omp end parallel
31+
32+
end subroutine parallel_function_master
33+
34+
!===============================================================================
35+
! master construct nested inside parallel construct
36+
!===============================================================================
37+
38+
!CHECK-LABEL: func @_QPomp_parallel_master
39+
subroutine omp_parallel_master()
40+
41+
!CHECK: omp.parallel {
42+
!$omp parallel
43+
!CHECK: fir.call @_QPparallel() {{.*}}: () -> ()
44+
call parallel()
45+
46+
!CHECK: omp.master {
47+
!$omp master
48+
49+
!CHECK: fir.call @_QPparallel_master() {{.*}}: () -> ()
50+
call parallel_master()
51+
52+
!CHECK: omp.terminator
53+
!$omp end master
54+
55+
!CHECK: omp.terminator
56+
!$omp end parallel
57+
58+
end subroutine omp_parallel_master
59+
60+
!===============================================================================
61+
! master construct nested inside parallel construct with conditional flow
62+
!===============================================================================
63+
64+
!CHECK-LABEL: func @_QPomp_master_parallel
65+
subroutine omp_master_parallel()
66+
integer :: alpha, beta, gama
67+
alpha = 4
68+
beta = 5
69+
gama = 6
70+
71+
!CHECK: omp.master {
72+
!$omp master
73+
74+
!CHECK: %{{.*}} = fir.load %{{.*}}
75+
!CHECK: %{{.*}} = fir.load %{{.*}}
76+
!CHECK: %[[RESULT:.*]] = arith.cmpi sge, %{{.*}}, %{{.*}}
77+
!CHECK: fir.if %[[RESULT]] {
78+
if (alpha .ge. gama) then
79+
80+
!CHECK: omp.parallel {
81+
!$omp parallel
82+
!CHECK: fir.call @_QPinside_if_parallel() {{.*}}: () -> ()
83+
call inside_if_parallel()
84+
85+
!CHECK: omp.terminator
86+
!$omp end parallel
87+
88+
!CHECK: %{{.*}} = fir.load %{{.*}}
89+
!CHECK: %{{.*}} = fir.load %{{.*}}
90+
!CHECK: %{{.*}} = arith.addi %{{.*}}, %{{.*}}
91+
!CHECK: hlfir.assign %{{.*}} to %{{.*}}#0 : i32, !fir.ref<i32>
92+
beta = alpha + gama
93+
end if
94+
!CHECK: else
95+
96+
!CHECK: omp.terminator
97+
!$omp end master
98+
99+
end subroutine omp_master_parallel

0 commit comments

Comments
 (0)