Skip to content

[flang][OpenMP] Added support for lowering OpenMP barrier construct #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flang/include/flang/Lower/OpenMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Fortran {
namespace parser {
struct OpenMPConstruct;
struct OpenMPStandaloneConstruct;
struct OpenMPSimpleStandaloneConstruct;
struct OmpEndLoopDirective;
} // namespace parser

Expand All @@ -26,6 +28,12 @@ struct Evaluation;
void genOpenMPConstruct(AbstractConverter &, pft::Evaluation &,
const parser::OpenMPConstruct &);

void genOMP(AbstractConverter &, pft::Evaluation &,
const parser::OpenMPStandaloneConstruct &);

void genOMP(AbstractConverter &, pft::Evaluation &,
const parser::OpenMPSimpleStandaloneConstruct &);

void genOpenMPEndLoop(AbstractConverter &, pft::Evaluation &,
const parser::OmpEndLoopDirective &);

Expand Down
1 change: 1 addition & 0 deletions flang/include/flang/Optimizer/Dialect/FIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ inline void registerFIR() {
mlir::registerDialect<mlir::StandardOpsDialect>();
mlir::registerDialect<mlir::vector::VectorDialect>();
mlir::registerDialect<FIROpsDialect>();
mlir::registerDialect<mlir::omp::OpenMPDialect>();
return true;
}();
}
Expand Down
81 changes: 78 additions & 3 deletions flang/lib/Lower/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,90 @@

#include "flang/Lower/OpenMP.h"
#include "flang/Lower/Bridge.h"
#include "flang/Lower/FIRBuilder.h"
#include "flang/Lower/PFTBuilder.h"
#include "flang/Parser/parse-tree.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"

#define TODO() llvm_unreachable("not yet implemented")

void Fortran::lower::genOMP(
Fortran::lower::AbstractConverter &absConv,
Fortran::lower::pft::Evaluation &eval,
const Fortran::parser::OpenMPSimpleStandaloneConstruct
&simpleStandaloneConstruct) {
const auto &directive =
std::get<Fortran::parser::OmpSimpleStandaloneDirective>(
simpleStandaloneConstruct.t);
switch (directive.v) {

case parser::OmpSimpleStandaloneDirective::Directive::Barrier:
absConv.getFirOpBuilder().create<mlir::omp::BarrierOp>(
absConv.getCurrentLocation());
break;
case parser::OmpSimpleStandaloneDirective::Directive::Taskwait:
TODO();
case parser::OmpSimpleStandaloneDirective::Directive::Taskyield:
TODO();
case parser::OmpSimpleStandaloneDirective::Directive::TargetEnterData:
TODO();
case parser::OmpSimpleStandaloneDirective::Directive::TargetExitData:
TODO();
case parser::OmpSimpleStandaloneDirective::Directive::TargetUpdate:
TODO();
case parser::OmpSimpleStandaloneDirective::Directive::Ordered:
TODO();
}
}

void Fortran::lower::genOMP(
Fortran::lower::AbstractConverter &absConv,
Fortran::lower::pft::Evaluation &eval,
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
std::visit(
common::visitors{
[&](const Fortran::parser::OpenMPSimpleStandaloneConstruct
&simpleStandaloneConstruct) {
genOMP(absConv, eval, simpleStandaloneConstruct);
},
[&](const Fortran::parser::OpenMPFlushConstruct &flushConstruct) {
TODO();
},
[&](const Fortran::parser::OpenMPCancelConstruct &cancelConstruct) {
TODO();
},
[&](const Fortran::parser::OpenMPCancellationPointConstruct
&cancellationPointConstruct) { TODO(); },
},
standaloneConstruct.u);
}

void Fortran::lower::genOpenMPConstruct(
Fortran::lower::AbstractConverter &, Fortran::lower::pft::Evaluation &,
const Fortran::parser::OpenMPConstruct &) {
TODO();
Fortran::lower::AbstractConverter &absConv,
Fortran::lower::pft::Evaluation &eval,
const Fortran::parser::OpenMPConstruct &ompConstruct) {

std::visit(
common::visitors{
[&](const Fortran::parser::OpenMPStandaloneConstruct
&standaloneConstruct) {
genOMP(absConv, eval, standaloneConstruct);
},
[&](const Fortran::parser::OpenMPSectionsConstruct
&sectionsConstruct) { TODO(); },
[&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
TODO();
},
[&](const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
TODO();
},
[&](const Fortran::parser::OpenMPAtomicConstruct &atomicConstruct) {
TODO();
},
[&](const Fortran::parser::OpenMPCriticalConstruct
&criticalConstruct) { TODO(); },
},
ompConstruct.u);
}

void Fortran::lower::genOpenMPEndLoop(
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,7 @@ struct FIRToLLVMLoweringPass
mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern);
mlir::ConversionTarget target{*context};
target.addLegalDialect<mlir::LLVM::LLVMDialect>();
target.addLegalDialect<mlir::omp::OpenMPDialect>();

// required NOPs for applying a full conversion
target.addLegalOp<mlir::ModuleOp, mlir::ModuleTerminatorOp>();
Expand Down
24 changes: 24 additions & 0 deletions flang/test/Lower/omp-barrier.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
! This test checks lowering of OpenMP Barrier Directive.

! RUN: bbc -fopenmp -emit-fir %s -o - | \
! RUN: FileCheck %s --check-prefix=FIRDialect
! RUN: bbc -fopenmp -emit-llvm %s -o - | \
! RUN: FileCheck %s --check-prefix=LLVMIRDialect
! RUN: bbc -fopenmp -emit-fir %s -o - | \
! RUN: tco | FileCheck %s --check-prefix=LLVMIR

program barrier

integer :: a,b,c

!$OMP BARRIER
!FIRDialect: omp.barrier
!LLVMIRDialect: omp.barrier
!LLVMIR: call void @__kmpc_barrier(%struct.ident_t* @1, i32 %omp_global_thread_num)
c = a + b
!$OMP BARRIER
!FIRDialect: omp.barrier
!LLVMIRDialect: omp.barrier
!LLVMIR: call void @__kmpc_barrier(%struct.ident_t* @1, i32 %omp_global_thread_num1)

end program