Skip to content

Commit 5143366

Browse files
committed
[flang] Flush and master constructs
This patch adds tests for flush and master constructs This is part of the upstreaming effort from the fir-dev branch in [1]. [1] https://github.com/flang-compiler/f18-llvm-project Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D122250 Co-authored By: Sourabh Singh Tomar <[email protected]>
1 parent b244bba commit 5143366

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ genOMP(Fortran::lower::AbstractConverter &converter,
112112
std::get<std::optional<Fortran::parser::OmpObjectList>>(
113113
flushConstruct.t))
114114
genObjectList(*ompObjectList, converter, operandRange);
115-
if (std::get<std::optional<
116-
std::list<Fortran::parser::OmpMemoryOrderClause>>>(
117-
flushConstruct.t))
115+
const auto &memOrderClause = std::get<std::optional<
116+
std::list<Fortran::parser::OmpMemoryOrderClause>>>(
117+
flushConstruct.t);
118+
if (memOrderClause.has_value() && memOrderClause->size() > 0)
118119
TODO(converter.getCurrentLocation(),
119120
"Handle OmpMemoryOrderClause");
120121
converter.getFirOpBuilder().create<mlir::omp::FlushOp>(

flang/test/Lower/OpenMP/flush.f90

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
! This test checks lowering of OpenMP Flush Directive.
2+
3+
!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
4+
!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --cfg-conversion | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect"
5+
6+
subroutine flush_standalone(a, b, c)
7+
integer, intent(inout) :: a, b, c
8+
9+
!$omp flush(a,b,c)
10+
!$omp flush
11+
!OMPDialect: omp.flush(%{{.*}}, %{{.*}}, %{{.*}} : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
12+
!OMPDialect: omp.flush
13+
14+
end subroutine flush_standalone
15+
16+
subroutine flush_parallel(a, b, c)
17+
integer, intent(inout) :: a, b, c
18+
19+
!$omp parallel
20+
!OMPDialect: omp.parallel {
21+
22+
!OMPDialect: omp.flush(%{{.*}}, %{{.*}}, %{{.*}} : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
23+
!OMPDialect: omp.flush
24+
!$omp flush(a,b,c)
25+
!$omp flush
26+
27+
!FIRDialect: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>
28+
!FIRDialect: %{{.*}} = fir.load %{{.*}} : !fir.ref<i32>
29+
!FIRDialect: %{{.*}} = arith.addi %{{.*}}, %{{.*}} : i32
30+
!FIRDialect: fir.store %{{.*}} to %{{.*}} : !fir.ref<i32>
31+
32+
!LLVMIRDialect: %{{.*}} = llvm.load %{{.*}} : !llvm.ptr<i32>
33+
!LLVMIRDialect: %{{.*}} = llvm.load %{{.*}} : !llvm.ptr<i32>
34+
!LLVMIRDialect: %{{.*}} = llvm.add %{{.*}}, %{{.*}} : i32
35+
!LLVMIRDialect: llvm.store %{{.*}}, %{{.*}} : !llvm.ptr<i32>
36+
c = a + b
37+
38+
!OMPDialect: omp.terminator
39+
!$omp END parallel
40+
41+
end subroutine flush_parallel

flang/test/Lower/OpenMP/master.f90

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

0 commit comments

Comments
 (0)