[flang-commits] [flang] 1fe4b96 - [flang][OpenMP] Added parallel sections translation
Shraiysh Vaishay via flang-commits
flang-commits at lists.llvm.org
Mon Mar 28 22:46:48 PDT 2022
Author: Shraiysh Vaishay
Date: 2022-03-29T11:16:38+05:30
New Revision: 1fe4b968c5fad5959ab9d371cc3324d9c7062eb3
URL: https://github.com/llvm/llvm-project/commit/1fe4b968c5fad5959ab9d371cc3324d9c7062eb3
DIFF: https://github.com/llvm/llvm-project/commit/1fe4b968c5fad5959ab9d371cc3324d9c7062eb3.diff
LOG: [flang][OpenMP] Added parallel sections translation
This patch adds translation for parallel sections from PFT to MLIR.
Reviewed By: kiranchandramohan, NimishMishra
Differential Revision: https://reviews.llvm.org/D122464
Added:
flang/test/Lower/OpenMP/parallel-sections.f90
Modified:
flang/lib/Lower/OpenMP.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index b3b8fc3211956..4ecbb7d37f914 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -320,8 +320,12 @@ genOMP(Fortran::lower::AbstractConverter &converter,
std::get<Fortran::parser::OmpBeginSectionsDirective>(sectionsConstruct.t)
.t);
for (const Fortran::parser::OmpClause &clause : sectionsClauseList.v) {
+
+ // Reduction Clause
if (std::get_if<Fortran::parser::OmpClause::Reduction>(&clause.u)) {
TODO(currentLocation, "OMPC_Reduction");
+
+ // Allocate clause
} else if (const auto &allocateClause =
std::get_if<Fortran::parser::OmpClause::Allocate>(
&clause.u)) {
@@ -334,16 +338,39 @@ genOMP(Fortran::lower::AbstractConverter &converter,
const auto &clauseList =
std::get<Fortran::parser::OmpClauseList>(endSectionsClauseList.t);
for (const auto &clause : clauseList.v) {
+ // Nowait clause
if (std::get_if<Fortran::parser::OmpClause::Nowait>(&clause.u)) {
noWaitClauseOperand = firOpBuilder.getUnitAttr();
}
}
- mlir::omp::SectionsOp sectionsOp = firOpBuilder.create<mlir::omp::SectionsOp>(
- currentLocation, reductionVars, /*reductions = */ nullptr,
- allocateOperands, allocatorOperands, noWaitClauseOperand);
+ llvm::omp::Directive dir =
+ std::get<Fortran::parser::OmpSectionsDirective>(
+ std::get<Fortran::parser::OmpBeginSectionsDirective>(
+ sectionsConstruct.t)
+ .t)
+ .v;
- createBodyOfOp<omp::SectionsOp>(sectionsOp, firOpBuilder, currentLocation);
+ // Parallel Sections Construct
+ if (dir == llvm::omp::Directive::OMPD_parallel_sections) {
+ auto parallelOp = firOpBuilder.create<mlir::omp::ParallelOp>(
+ currentLocation, /*if_expr_var*/ nullptr, /*num_threads_var*/ nullptr,
+ allocateOperands, allocatorOperands, /*reduction_vars=*/ValueRange(),
+ /*reductions=*/nullptr, /*proc_bind_val*/ nullptr);
+ createBodyOfOp(parallelOp, firOpBuilder, currentLocation);
+ auto sectionsOp = firOpBuilder.create<mlir::omp::SectionsOp>(
+ currentLocation, /*reduction_vars*/ ValueRange(),
+ /*reductions=*/nullptr, /*allocate_vars*/ ValueRange(),
+ /*allocators_vars*/ ValueRange(), /*nowait=*/nullptr);
+ createBodyOfOp(sectionsOp, firOpBuilder, currentLocation);
+
+ // Sections Construct
+ } else if (dir == llvm::omp::Directive::OMPD_sections) {
+ auto sectionsOp = firOpBuilder.create<mlir::omp::SectionsOp>(
+ currentLocation, reductionVars, /*reductions = */ nullptr,
+ allocateOperands, allocatorOperands, noWaitClauseOperand);
+ createBodyOfOp<omp::SectionsOp>(sectionsOp, firOpBuilder, currentLocation);
+ }
}
void Fortran::lower::genOpenMPConstruct(
diff --git a/flang/test/Lower/OpenMP/parallel-sections.f90 b/flang/test/Lower/OpenMP/parallel-sections.f90
new file mode 100644
index 0000000000000..c88d60cc8f88b
--- /dev/null
+++ b/flang/test/Lower/OpenMP/parallel-sections.f90
@@ -0,0 +1,57 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | fir-opt --cfg-conversion | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect,LLVMDialect"
+
+!===============================================================================
+! Parallel sections construct
+!===============================================================================
+
+!FIRDialect: func @_QPomp_parallel_sections
+subroutine omp_parallel_sections(x, y)
+ integer, intent(inout) :: x, y
+ !OMPDialect: omp.parallel {
+ !OMPDialect: omp.sections {
+ !$omp parallel sections
+ !OMPDialect: omp.section {
+ !$omp section
+ !FIRDialect: fir.load
+ !FIRDialect: arith.addi
+ !FIRDialect: fir.store
+ x = x + 12
+ !OMPDialect: omp.terminator
+ !OMPDialect: omp.section {
+ !$omp section
+ !FIRDialect: fir.load
+ !FIRDialect: arith.subi
+ !FIRDialect: fir.store
+ y = y - 5
+ !OMPDialect: omp.terminator
+ !OMPDialect: omp.terminator
+ !OMPDialect: omp.terminator
+ !$omp end parallel sections
+end subroutine omp_parallel_sections
+
+!===============================================================================
+! Parallel sections construct with allocate clause
+!===============================================================================
+
+!FIRDialect: func @_QPomp_parallel_sections
+subroutine omp_parallel_sections_allocate(x, y)
+ use omp_lib
+ integer, intent(inout) :: x, y
+ !FIRDialect: %[[allocator:.*]] = arith.constant 1 : i32
+ !LLVMDialect: %[[allocator:.*]] = llvm.mlir.constant(1 : i32) : i32
+ !OMPDialect: omp.parallel allocate(%[[allocator]] : i32 -> %{{.*}} : !fir.ref<i32>) {
+ !OMPDialect: omp.sections {
+ !$omp parallel sections allocate(omp_high_bw_mem_alloc: x)
+ !OMPDialect: omp.section {
+ !$omp section
+ x = x + 12
+ !OMPDialect: omp.terminator
+ !OMPDialect: omp.section {
+ !$omp section
+ y = y + 5
+ !OMPDialect: omp.terminator
+ !OMPDialect: omp.terminator
+ !OMPDialect: omp.terminator
+ !$omp end parallel sections
+end subroutine omp_parallel_sections_allocate
More information about the flang-commits
mailing list