[flang-commits] [flang] f305ac3 - [flang][OpenMP] Support lowering to MLIR for ordered clause
via flang-commits
flang-commits at lists.llvm.org
Tue May 17 00:08:34 PDT 2022
Author: Peixin-Qiao
Date: 2022-05-17T15:07:52+08:00
New Revision: f305ac3d5d0e02df68efbad42ab9c209f99d51a7
URL: https://github.com/llvm/llvm-project/commit/f305ac3d5d0e02df68efbad42ab9c209f99d51a7
DIFF: https://github.com/llvm/llvm-project/commit/f305ac3d5d0e02df68efbad42ab9c209f99d51a7.diff
LOG: [flang][OpenMP] Support lowering to MLIR for ordered clause
This supports the lowering parse-tree to MLIR for ordered clause in
worksharing-loop directive. Also add the test case for operation
conversion.
Part of this patch is from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.
Co-authored-by: Sourabh Singh Tomar <SourabhSingh.Tomar at amd.com>
Reviewed By: kiranchandramohan, NimishMishra
Differential Revision: https://reviews.llvm.org/D125456
Added:
flang/test/Lower/OpenMP/omp-wsloop-ordered.f90
Modified:
flang/lib/Lower/OpenMP.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 156aa89c1562e..06f546d453270 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -440,8 +440,20 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
// Handle attribute based clauses.
for (const Fortran::parser::OmpClause &clause : wsLoopOpClauseList.v) {
- if (const auto &scheduleClause =
- std::get_if<Fortran::parser::OmpClause::Schedule>(&clause.u)) {
+ if (const auto &orderedClause =
+ std::get_if<Fortran::parser::OmpClause::Ordered>(&clause.u)) {
+ if (orderedClause->v.has_value()) {
+ const auto *expr = Fortran::semantics::GetExpr(orderedClause->v);
+ const std::optional<std::int64_t> orderedClauseValue =
+ Fortran::evaluate::ToInt64(*expr);
+ wsLoopOp.ordered_valAttr(
+ firOpBuilder.getI64IntegerAttr(*orderedClauseValue));
+ } else {
+ wsLoopOp.ordered_valAttr(firOpBuilder.getI64IntegerAttr(0));
+ }
+ } else if (const auto &scheduleClause =
+ std::get_if<Fortran::parser::OmpClause::Schedule>(
+ &clause.u)) {
mlir::MLIRContext *context = firOpBuilder.getContext();
const auto &scheduleType = scheduleClause->v;
const auto &scheduleKind =
diff --git a/flang/test/Lower/OpenMP/omp-wsloop-ordered.f90 b/flang/test/Lower/OpenMP/omp-wsloop-ordered.f90
new file mode 100644
index 0000000000000..7548d7a597228
--- /dev/null
+++ b/flang/test/Lower/OpenMP/omp-wsloop-ordered.f90
@@ -0,0 +1,40 @@
+! This test checks lowering of worksharing-loop construct with ordered clause.
+
+! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
+
+! This checks lowering ordered clause specified without parameter
+subroutine wsloop_ordered_no_para()
+ integer :: a(10), i
+
+! CHECK: omp.wsloop ordered(0) for (%{{.*}}) : i32 = (%{{.*}}) to (%{{.*}}) inclusive step (%{{.*}}) {
+! CHECK: omp.yield
+! CHECK: }
+
+ !$omp do ordered
+ do i = 2, 10
+ !$omp ordered
+ a(i) = a(i-1) + 1
+ !$omp end ordered
+ end do
+ !$omp end do
+
+end
+
+! This checks lowering ordered clause specified with a parameter
+subroutine wsloop_ordered_with_para()
+ integer :: a(10), i
+
+! CHECK: func @_QPwsloop_ordered_with_para() {
+! CHECK: omp.wsloop ordered(1) for (%{{.*}}) : i32 = (%{{.*}}) to (%{{.*}}) inclusive step (%{{.*}}) {
+! CHECK: omp.yield
+! CHECK: }
+
+ !$omp do ordered(1)
+ do i = 2, 10
+ !!$omp ordered depend(sink: i-1)
+ a(i) = a(i-1) + 1
+ !!$omp ordered depend(source)
+ end do
+ !$omp end do
+
+end
More information about the flang-commits
mailing list