Index: flang/include/flang/Lower/OpenACC.h =================================================================== --- flang/include/flang/Lower/OpenACC.h +++ 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 @@ void genOpenACCConstruct(AbstractConverter &, pft::Evaluation &, const parser::OpenACCConstruct &); +void genOpenACCDeclarativeConstruct( + AbstractConverter &, pft::Evaluation &, + const parser::OpenACCDeclarativeConstruct &); } // namespace lower } // namespace Fortran Index: flang/include/flang/Lower/OpenMP.h =================================================================== --- flang/include/flang/Lower/OpenMP.h +++ 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 @@ void genOpenMPConstruct(AbstractConverter &, pft::Evaluation &, const parser::OpenMPConstruct &); +void genOpenMPDeclarativeConstruct(AbstractConverter &, pft::Evaluation &, + const parser::OpenMPDeclarativeConstruct &); } // namespace lower } // namespace Fortran Index: flang/lib/Lower/Bridge.cpp =================================================================== --- flang/lib/Lower/Bridge.cpp +++ flang/lib/Lower/Bridge.cpp @@ -1186,8 +1186,12 @@ 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 @@ } 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. Index: flang/lib/Lower/OpenACC.cpp =================================================================== --- flang/lib/Lower/OpenACC.cpp +++ flang/lib/Lower/OpenACC.cpp @@ -977,11 +977,6 @@ &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!"); @@ -996,3 +991,24 @@ }, 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); +} Index: flang/lib/Lower/OpenMP.cpp =================================================================== --- flang/lib/Lower/OpenMP.cpp +++ flang/lib/Lower/OpenMP.cpp @@ -633,3 +633,35 @@ }, 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); +} Index: flang/test/Lower/OpenACC/acc-declare.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenACC/acc-declare.f90 @@ -0,0 +1,9 @@ +! This test checks lowering of OpenACC declare Directive. +! XFAIL: * +! RUN: %bbc -fopenacc -emit-fir %s -o - | FileCheck %s + +program main + real, dimension(10) :: aa, bb + + !$acc declare present(aa, bb) +end Index: flang/test/Lower/OpenACC/acc-routine.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenACC/acc-routine.f90 @@ -0,0 +1,11 @@ +! This test checks lowering of OpenACC routine Directive. +! XFAIL: * +! RUN: %bbc -fopenacc -emit-fir %s -o - | FileCheck %s + +program main + !$acc routine(sub) seq +contains + subroutine sub(a) + real :: a(:) + end +end Index: flang/test/Lower/OpenMP/omp-declarative-allocate.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenMP/omp-declarative-allocate.f90 @@ -0,0 +1,10 @@ +! This test checks lowering of OpenMP allocate Directive. +! XFAIL: * +! RUN: %bbc -fopenmp -emit-fir %s -o - | \ +! RUN: FileCheck %s --check-prefix=FIRDialect + +program main + integer :: x, y + + !$omp allocate(x, y) +end Index: flang/test/Lower/OpenMP/omp-declare-reduction.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenMP/omp-declare-reduction.f90 @@ -0,0 +1,10 @@ +! This test checks lowering of OpenMP declare reduction Directive. +! XFAIL: * +! RUN: %bbc -fopenmp -emit-fir %s -o - | \ +! RUN: FileCheck %s --check-prefix=FIRDialect + +subroutine declare_red() + integer :: my_var + !$omp declare reduction (my_red : integer : omp_out = omp_in) initializer (omp_priv = 0) + my_var = 0 +end subroutine declare_red Index: flang/test/Lower/OpenMP/omp-declare-simd.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenMP/omp-declare-simd.f90 @@ -0,0 +1,11 @@ +! This test checks lowering of OpenMP declare simd Directive. +! XFAIL: * +! RUN: %bbc -fopenmp -emit-fir %s -o - | \ +! RUN: FileCheck %s --check-prefix=FIRDialect + +subroutine sub(x, y) + real, intent(inout) :: x, y + + !$omp declare simd(sub) aligned(x) + x = 3.14 + y +end Index: flang/test/Lower/OpenMP/omp-declare-target.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenMP/omp-declare-target.f90 @@ -0,0 +1,12 @@ +! This test checks lowering of OpenMP declare target Directive. +! XFAIL: * +! RUN: %bbc -fopenmp -emit-fir %s -o - | \ +! RUN: FileCheck %s --check-prefix=FIRDialect + +module mod1 +contains + subroutine sub() + integer :: x, y + !$omp declare target + end +end module Index: flang/test/Lower/OpenMP/omp-threadprivate.f90 =================================================================== --- /dev/null +++ flang/test/Lower/OpenMP/omp-threadprivate.f90 @@ -0,0 +1,10 @@ +! This test checks lowering of OpenMP threadprivate Directive. +! XFAIL: * +! RUN: %bbc -fopenmp -emit-fir %s -o - | \ +! RUN: FileCheck %s --check-prefix=FIRDialect + +program main + integer, save :: x, y + + !$omp threadprivate(x, y) +end