[flang-commits] [flang] b6b8d34 - [flang] Add lowering stubs for OpenMP/OpenACC declarative constructs
via flang-commits
flang-commits at lists.llvm.org
Wed Apr 27 18:46:10 PDT 2022
Author: Peixin-Qiao
Date: 2022-04-28T09:40:30+08:00
New Revision: b6b8d34554a4d85ec064463b54a27e073c42beeb
URL: https://github.com/llvm/llvm-project/commit/b6b8d34554a4d85ec064463b54a27e073c42beeb
DIFF: https://github.com/llvm/llvm-project/commit/b6b8d34554a4d85ec064463b54a27e073c42beeb.diff
LOG: [flang] Add lowering stubs for OpenMP/OpenACC declarative constructs
This patch provides the basic infrastructure for lowering declarative
constructs for OpenMP and OpenACC.
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, shraiysh, clementval
Differential Revision: https://reviews.llvm.org/D124225
Added:
flang/test/Lower/OpenACC/Todo/acc-declare.f90
flang/test/Lower/OpenACC/Todo/acc-routine.f90
flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90
flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90
flang/test/Lower/OpenMP/Todo/omp-declare-target.f90
flang/test/Lower/OpenMP/Todo/omp-threadprivate.f90
Modified:
flang/include/flang/Lower/OpenACC.h
flang/include/flang/Lower/OpenMP.h
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/OpenACC.cpp
flang/lib/Lower/OpenMP.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h
index a3e6f177f91d..b3cd70b8e03c 100644
--- a/flang/include/flang/Lower/OpenACC.h
+++ b/flang/include/flang/Lower/OpenACC.h
@@ -16,6 +16,7 @@
namespace Fortran {
namespace parser {
struct OpenACCConstruct;
+struct OpenACCDeclarativeConstruct;
} // namespace parser
namespace lower {
@@ -28,6 +29,9 @@ struct Evaluation;
void genOpenACCConstruct(AbstractConverter &, pft::Evaluation &,
const parser::OpenACCConstruct &);
+void genOpenACCDeclarativeConstruct(
+ AbstractConverter &, pft::Evaluation &,
+ const parser::OpenACCDeclarativeConstruct &);
} // namespace lower
} // namespace Fortran
diff --git a/flang/include/flang/Lower/OpenMP.h b/flang/include/flang/Lower/OpenMP.h
index a056443aeda3..df44c6752acc 100644
--- a/flang/include/flang/Lower/OpenMP.h
+++ b/flang/include/flang/Lower/OpenMP.h
@@ -16,6 +16,7 @@
namespace Fortran {
namespace parser {
struct OpenMPConstruct;
+struct OpenMPDeclarativeConstruct;
} // namespace parser
namespace lower {
@@ -28,6 +29,8 @@ struct Evaluation;
void genOpenMPConstruct(AbstractConverter &, pft::Evaluation &,
const parser::OpenMPConstruct &);
+void genOpenMPDeclarativeConstruct(AbstractConverter &, pft::Evaluation &,
+ const parser::OpenMPDeclarativeConstruct &);
} // namespace lower
} // namespace Fortran
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index df89b8c73565..340da6865369 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -1186,8 +1186,12 @@ class FirConverter : public Fortran::lower::AbstractConverter {
builder->restoreInsertionPoint(insertPt);
}
- void genFIR(const Fortran::parser::OpenACCDeclarativeConstruct &) {
- TODO(toLocation(), "OpenACCDeclarativeConstruct lowering");
+ void genFIR(const Fortran::parser::OpenACCDeclarativeConstruct &accDecl) {
+ mlir::OpBuilder::InsertPoint insertPt = builder->saveInsertionPoint();
+ genOpenACCDeclarativeConstruct(*this, getEval(), accDecl);
+ for (Fortran::lower::pft::Evaluation &e : getEval().getNestedEvaluations())
+ genFIR(e);
+ builder->restoreInsertionPoint(insertPt);
}
void genFIR(const Fortran::parser::OpenMPConstruct &omp) {
@@ -1202,7 +1206,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
}
void genFIR(const Fortran::parser::OpenMPDeclarativeConstruct &ompDecl) {
- TODO(toLocation(), "OpenMPDeclarativeConstruct lowering");
+ mlir::OpBuilder::InsertPoint insertPt = builder->saveInsertionPoint();
+ genOpenMPDeclarativeConstruct(*this, getEval(), ompDecl);
+ for (Fortran::lower::pft::Evaluation &e : getEval().getNestedEvaluations())
+ genFIR(e);
+ builder->restoreInsertionPoint(insertPt);
}
/// Generate FIR for a SELECT CASE statement.
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 4562b738d80f..23f999ae73a4 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -979,11 +979,6 @@ void Fortran::lower::genOpenACCConstruct(
&standaloneConstruct) {
genACC(converter, eval, standaloneConstruct);
},
- [&](const Fortran::parser::OpenACCRoutineConstruct
- &routineConstruct) {
- TODO(converter.getCurrentLocation(),
- "OpenACC Routine construct not lowered yet!");
- },
[&](const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
TODO(converter.getCurrentLocation(),
"OpenACC Cache construct not lowered yet!");
@@ -998,3 +993,24 @@ void Fortran::lower::genOpenACCConstruct(
},
accConstruct.u);
}
+
+void Fortran::lower::genOpenACCDeclarativeConstruct(
+ Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ const Fortran::parser::OpenACCDeclarativeConstruct &accDeclConstruct) {
+
+ std::visit(
+ common::visitors{
+ [&](const Fortran::parser::OpenACCStandaloneDeclarativeConstruct
+ &standaloneDeclarativeConstruct) {
+ TODO(converter.getCurrentLocation(),
+ "OpenACC Standalone Declarative construct not lowered yet!");
+ },
+ [&](const Fortran::parser::OpenACCRoutineConstruct
+ &routineConstruct) {
+ TODO(converter.getCurrentLocation(),
+ "OpenACC Routine construct not lowered yet!");
+ },
+ },
+ accDeclConstruct.u);
+}
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index 212b269305d7..93cb936e1e86 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -633,3 +633,35 @@ void Fortran::lower::genOpenMPConstruct(
},
ompConstruct.u);
}
+
+void Fortran::lower::genOpenMPDeclarativeConstruct(
+ Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ const Fortran::parser::OpenMPDeclarativeConstruct &ompDeclConstruct) {
+
+ std::visit(
+ common::visitors{
+ [&](const Fortran::parser::OpenMPDeclarativeAllocate
+ &declarativeAllocate) {
+ TODO(converter.getCurrentLocation(), "OpenMPDeclarativeAllocate");
+ },
+ [&](const Fortran::parser::OpenMPDeclareReductionConstruct
+ &declareReductionConstruct) {
+ TODO(converter.getCurrentLocation(),
+ "OpenMPDeclareReductionConstruct");
+ },
+ [&](const Fortran::parser::OpenMPDeclareSimdConstruct
+ &declareSimdConstruct) {
+ TODO(converter.getCurrentLocation(), "OpenMPDeclareSimdConstruct");
+ },
+ [&](const Fortran::parser::OpenMPDeclareTargetConstruct
+ &declareTargetConstruct) {
+ TODO(converter.getCurrentLocation(),
+ "OpenMPDeclareTargetConstruct");
+ },
+ [&](const Fortran::parser::OpenMPThreadprivate &threadprivate) {
+ TODO(converter.getCurrentLocation(), "OpenMPThreadprivate");
+ },
+ },
+ ompDeclConstruct.u);
+}
diff --git a/flang/test/Lower/OpenACC/Todo/acc-declare.f90 b/flang/test/Lower/OpenACC/Todo/acc-declare.f90
new file mode 100644
index 000000000000..d40394793e33
--- /dev/null
+++ b/flang/test/Lower/OpenACC/Todo/acc-declare.f90
@@ -0,0 +1,10 @@
+! This test checks lowering of OpenACC declare Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenacc %s 2>&1 | FileCheck %s
+
+program main
+ real, dimension(10) :: aa, bb
+
+ // CHECK: not yet implemented: OpenACC Standalone Declarative construct
+ !$acc declare present(aa, bb)
+end
diff --git a/flang/test/Lower/OpenACC/Todo/acc-routine.f90 b/flang/test/Lower/OpenACC/Todo/acc-routine.f90
new file mode 100644
index 000000000000..62e39759d762
--- /dev/null
+++ b/flang/test/Lower/OpenACC/Todo/acc-routine.f90
@@ -0,0 +1,12 @@
+! This test checks lowering of OpenACC routine Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenacc %s 2>&1 | FileCheck %s
+
+program main
+ // CHECK: not yet implemented: OpenACC Routine construct not lowered yet!
+ !$acc routine(sub) seq
+contains
+ subroutine sub(a)
+ real :: a(:)
+ end
+end
diff --git a/flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90 b/flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
new file mode 100644
index 000000000000..f02884e5e92f
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
@@ -0,0 +1,10 @@
+! This test checks lowering of OpenMP allocate Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+
+program main
+ integer :: x, y
+
+ // CHECK: not yet implemented: OpenMPDeclarativeAllocate
+ !$omp allocate(x, y)
+end
diff --git a/flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90 b/flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90
new file mode 100644
index 000000000000..3be61a1700ce
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/omp-declare-reduction.f90
@@ -0,0 +1,10 @@
+! This test checks lowering of OpenMP declare reduction Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+
+subroutine declare_red()
+ integer :: my_var
+ // CHECK: not yet implemented: OpenMPDeclareReductionConstruct
+ !$omp declare reduction (my_red : integer : omp_out = omp_in) initializer (omp_priv = 0)
+ my_var = 0
+end subroutine declare_red
diff --git a/flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90 b/flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90
new file mode 100644
index 000000000000..c6a0a8f2cd0d
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/omp-declare-simd.f90
@@ -0,0 +1,11 @@
+! This test checks lowering of OpenMP declare simd Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+
+subroutine sub(x, y)
+ real, intent(inout) :: x, y
+
+ // CHECK: not yet implemented: OpenMPDeclareSimdConstruct
+ !$omp declare simd(sub) aligned(x)
+ x = 3.14 + y
+end
diff --git a/flang/test/Lower/OpenMP/Todo/omp-declare-target.f90 b/flang/test/Lower/OpenMP/Todo/omp-declare-target.f90
new file mode 100644
index 000000000000..4f904475cd49
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/omp-declare-target.f90
@@ -0,0 +1,12 @@
+! This test checks lowering of OpenMP declare target Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+
+module mod1
+contains
+ subroutine sub()
+ integer :: x, y
+ // CHECK: not yet implemented: OpenMPDeclareTargetConstruct
+ !$omp declare target
+ end
+end module
diff --git a/flang/test/Lower/OpenMP/Todo/omp-threadprivate.f90 b/flang/test/Lower/OpenMP/Todo/omp-threadprivate.f90
new file mode 100644
index 000000000000..da1981a299b7
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/omp-threadprivate.f90
@@ -0,0 +1,10 @@
+! This test checks lowering of OpenMP threadprivate Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+
+program main
+ integer, save :: x, y
+
+// CHECK: not yet implemented: OpenMPThreadprivate
+ !$omp threadprivate(x, y)
+end
More information about the flang-commits
mailing list