[flang-commits] [flang] 8964a17 - [OpenMP] Lowering to MLIR of ordered threads directive
via flang-commits
flang-commits at lists.llvm.org
Wed Apr 13 07:32:51 PDT 2022
Author: PeixinQiao
Date: 2022-04-13T22:30:52+08:00
New Revision: 8964a17dad6a24d8126a7a4be469ba6487cdad43
URL: https://github.com/llvm/llvm-project/commit/8964a17dad6a24d8126a7a4be469ba6487cdad43
DIFF: https://github.com/llvm/llvm-project/commit/8964a17dad6a24d8126a7a4be469ba6487cdad43.diff
LOG: [OpenMP] Lowering 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.
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: shraiysh
Differential Revision: https://reviews.llvm.org/D123590
Added:
flang/test/Lower/OpenMP/omp-ordered-threads.f90
Modified:
flang/lib/Lower/OpenMP.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 5a80e733c6e18..66ed6b620ba1c 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -292,6 +292,9 @@ genOMP(Fortran::lower::AbstractConverter &converter,
&clause.u)) {
// Privatisation clauses are handled elsewhere.
continue;
+ } else if (std::get_if<Fortran::parser::OmpClause::Threads>(&clause.u)) {
+ // Nothing needs to be done for threads clause.
+ continue;
} else {
TODO(currentLocation, "OpenMP Block construct clauses");
}
@@ -319,6 +322,10 @@ genOMP(Fortran::lower::AbstractConverter &converter,
auto singleOp = firOpBuilder.create<mlir::omp::SingleOp>(
currentLocation, allocateOperands, allocatorOperands, nowaitAttr);
createBodyOfOp<omp::SingleOp>(singleOp, converter, currentLocation);
+ } else if (blockDirective.v == llvm::omp::OMPD_ordered) {
+ auto orderedOp = firOpBuilder.create<mlir::omp::OrderedRegionOp>(
+ currentLocation, /*simd=*/nullptr);
+ createBodyOfOp<omp::OrderedRegionOp>(orderedOp, converter, currentLocation);
} else {
TODO(converter.getCurrentLocation(), "Unhandled block directive");
}
diff --git a/flang/test/Lower/OpenMP/omp-ordered-threads.f90 b/flang/test/Lower/OpenMP/omp-ordered-threads.f90
new file mode 100644
index 0000000000000..352b40e67da60
--- /dev/null
+++ b/flang/test/Lower/OpenMP/omp-ordered-threads.f90
@@ -0,0 +1,40 @@
+! This test checks lowering of OpenMP ordered directive with threads Clause.
+! Without clause in ordered direcitve, it behaves as if threads clause is
+! specified.
+
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefix=FIRDialect
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefix=LLVMIRDialect
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --fir-to-llvm-ir | tco | FileCheck %s --check-prefix=LLVMIR
+
+subroutine ordered
+ integer :: i
+ integer :: a(20)
+
+!FIRDialect: omp.ordered_region {
+!LLVMIRDialect: omp.ordered_region {
+!LLVMIR: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB0:[0-9]+]]), !dbg !{{.*}}
+!LLVMIR-NEXT: call void @__kmpc_ordered(%struct.ident_t* @[[GLOB0]], i32 [[TMP0]]), !dbg !{{.*}}
+!$OMP ORDERED
+ a(i) = a(i-1) + 1
+!FIRDialect: omp.terminator
+!FIRDialect-NEXT: }
+!LLVMIRDialect: omp.terminator
+!LLVMIRDialect-NEXT: }
+!LLVMIR: call void @__kmpc_end_ordered(%struct.ident_t* @[[GLOB0]], i32 [[TMP0]]), !dbg !{{.*}}
+!$OMP END ORDERED
+
+!FIRDialect: omp.ordered_region {
+!LLVMIRDialect: omp.ordered_region {
+!LLVMIR: [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]]), !dbg !{{.*}}
+!LLVMIR-NEXT: call void @__kmpc_ordered(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]]), !dbg !{{.*}}
+!$OMP ORDERED THREADS
+ a(i) = a(i-1) + 1
+!FIRDialect: omp.terminator
+!FIRDialect-NEXT: }
+!LLVMIRDialect: omp.terminator
+!LLVMIRDialect-NEXT: }
+!LLVMIR: call void @__kmpc_end_ordered(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]]), !dbg !{{.*}}
+!LLVMIR-NEXT: ret void, !dbg !{{.*}}
+!$OMP END ORDERED
+
+end
More information about the flang-commits
mailing list