Skip to content

Commit

Permalink
[flang] Add lowering stubs for OpenMP/OpenACC declarative constructs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PeixinQiao committed Apr 28, 2022
1 parent c9a16e8 commit b6b8d34
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 8 deletions.
4 changes: 4 additions & 0 deletions flang/include/flang/Lower/OpenACC.h
Expand Up @@ -16,6 +16,7 @@
namespace Fortran {
namespace parser {
struct OpenACCConstruct;
struct OpenACCDeclarativeConstruct;
} // namespace parser

namespace lower {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions flang/include/flang/Lower/OpenMP.h
Expand Up @@ -16,6 +16,7 @@
namespace Fortran {
namespace parser {
struct OpenMPConstruct;
struct OpenMPDeclarativeConstruct;
} // namespace parser

namespace lower {
Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions flang/lib/Lower/Bridge.cpp
Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
26 changes: 21 additions & 5 deletions flang/lib/Lower/OpenACC.cpp
Expand Up @@ -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!");
Expand All @@ -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);
}
32 changes: 32 additions & 0 deletions flang/lib/Lower/OpenMP.cpp
Expand Up @@ -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);
}
10 changes: 10 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions 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
10 changes: 10 additions & 0 deletions 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
10 changes: 10 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions 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
10 changes: 10 additions & 0 deletions 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

0 comments on commit b6b8d34

Please sign in to comment.