Skip to content

Commit 82ef3d3

Browse files
PeixinQiaojeanPerier
authored andcommitted
[OpenMP] Lowering parse-tree to MLIR of ordered threads directive
This patch supports lowering parse-tree to MLIR of ordered threads directive following Section 2.19.9 of the OpenMP 5.1 standard.
1 parent 4e96f05 commit 82ef3d3

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@ genOMP(Fortran::lower::AbstractConverter &converter,
411411
mlir::Location currentLocation = converter.getCurrentLocation();
412412
auto masterOp = firOpBuilder.create<mlir::omp::MasterOp>(currentLocation);
413413
createBodyOfOp<omp::MasterOp>(masterOp, converter, currentLocation, eval);
414+
} else if (blockDirective.v == llvm::omp::OMPD_ordered) {
415+
auto &firOpBuilder = converter.getFirOpBuilder();
416+
auto currentLocation = converter.getCurrentLocation();
417+
mlir::Attribute simdClauseOperand;
418+
auto orderedOp = firOpBuilder.create<mlir::omp::OrderedRegionOp>(
419+
currentLocation, simdClauseOperand.dyn_cast_or_null<UnitAttr>());
420+
const auto &clauseList =
421+
std::get<Fortran::parser::OmpClauseList>(beginBlockDirective.t);
422+
for (const auto &clause : clauseList.v) {
423+
if (std::get_if<Fortran::parser::OmpClause::Simd>(&clause.u)) {
424+
TODO(currentLocation, "OpenMP ORDERED SIMD");
425+
}
426+
}
427+
createBodyOfOp<omp::OrderedRegionOp>(orderedOp, converter, currentLocation,
428+
eval);
414429
}
415430
}
416431

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
! This test checks lowering of OpenMP ordered directive with threads Clause.
2+
! Without clause in ordered direcitve, it behaves as if threads clause is
3+
! specified.
4+
5+
! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s --check-prefix=FIRDialect
6+
! RUN: bbc -fopenmp -emit-fir %s -o - | \
7+
! RUN: tco --disable-llvm --print-ir-after=fir-to-llvm-ir 2>&1 | \
8+
! RUN: FileCheck %s --check-prefix=LLVMIRDialect
9+
! RUN: bbc -fopenmp -emit-fir %s -o - | tco | FileCheck %s --check-prefix=LLVMIR
10+
11+
program ordered
12+
integer :: i
13+
integer :: a(20)
14+
15+
!FIRDialect: omp.ordered_region {
16+
!LLVMIRDialect: omp.ordered_region {
17+
!LLVMIR: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB0:[0-9]+]]), !dbg !{{.*}}
18+
!LLVMIR-NEXT: call void @__kmpc_ordered(%struct.ident_t* @[[GLOB0]], i32 [[TMP0]]), !dbg !{{.*}}
19+
!$OMP ORDERED
20+
a(i) = a(i-1) + 1
21+
!FIRDialect: omp.terminator
22+
!FIRDialect-NEXT: }
23+
!LLVMIRDialect: omp.terminator
24+
!LLVMIRDialect-NEXT: }
25+
!LLVMIR: call void @__kmpc_end_ordered(%struct.ident_t* @[[GLOB0]], i32 [[TMP0]]), !dbg !{{.*}}
26+
!$OMP END ORDERED
27+
28+
!FIRDialect: omp.ordered_region {
29+
!LLVMIRDialect: omp.ordered_region {
30+
!LLVMIR: [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]), !dbg !{{.*}}
31+
!LLVMIR-NEXT: call void @__kmpc_ordered(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]]), !dbg !{{.*}}
32+
!$OMP ORDERED THREADS
33+
a(i) = a(i-1) + 1
34+
!FIRDialect: omp.terminator
35+
!FIRDialect-NEXT: }
36+
!LLVMIRDialect: omp.terminator
37+
!LLVMIRDialect-NEXT: }
38+
!LLVMIR: call void @__kmpc_end_ordered(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]]), !dbg !{{.*}}
39+
!LLVMIR-NEXT: ret void, !dbg !{{.*}}
40+
!$OMP END ORDERED
41+
42+
end

0 commit comments

Comments
 (0)