Skip to content

[Flang][OpenMP] : Add a temporary lowering for workshare directive #78268

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 1 commit into from
Mar 5, 2024

Conversation

kiranchandramohan
Copy link
Contributor

As a temporary solution, lower workshare to the single directive

@tblah
Copy link
Contributor

tblah commented Jan 30, 2024

This patch also needs to remove the TODO here

TODO(currentLocation, "Workshare construct");

As a temporary solution, lower workshare to the single directive.
@kiranchandramohan kiranchandramohan marked this pull request as ready for review February 27, 2024 18:57
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Feb 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2024

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-flang-openmp

Author: Kiran Chandramohan (kiranchandramohan)

Changes

As a temporary solution, lower workshare to the single directive


Full diff: https://github.com/llvm/llvm-project/pull/78268.diff

2 Files Affected:

  • (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+7-2)
  • (added) flang/test/Lower/OpenMP/workshare.f90 (+42)
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 7953bf83cba0fe..d9c3148d0e3d34 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1740,7 +1740,11 @@ genOMP(Fortran::lower::AbstractConverter &converter,
                /*outerCombined=*/false);
     break;
   case llvm::omp::Directive::OMPD_workshare:
-    TODO(currentLocation, "Workshare construct");
+    // FIXME: Workshare is not a commonly used OpenMP construct, an
+    // implementation for this feature will come later. For the codes
+    // that use this construct, add a single construct for now.
+    genSingleOp(converter, semaCtx, eval, /*genNested=*/true, currentLocation,
+                beginClauseList, endClauseList);
     break;
   default:
     singleDirective = false;
@@ -1775,7 +1779,8 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   }
   if ((llvm::omp::workShareSet & llvm::omp::blockConstructSet)
           .test(directive.v)) {
-    TODO(currentLocation, "Workshare construct");
+    genSingleOp(converter, semaCtx, eval, /*genNested=*/false, currentLocation,
+                beginClauseList, endClauseList);
     combinedDirective = true;
   }
   if (!combinedDirective)
diff --git a/flang/test/Lower/OpenMP/workshare.f90 b/flang/test/Lower/OpenMP/workshare.f90
new file mode 100644
index 00000000000000..1e11677a15e1f0
--- /dev/null
+++ b/flang/test/Lower/OpenMP/workshare.f90
@@ -0,0 +1,42 @@
+
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+
+!CHECK-LABEL: func @_QPsb1
+subroutine sb1(arr)
+  integer :: arr(:)
+!CHECK: omp.parallel  {
+  !$omp parallel
+!CHECK: omp.single  {
+  !$omp workshare
+    arr = 0
+  !$omp end workshare
+!CHECK: }
+  !$omp end parallel
+!CHECK: }
+end subroutine
+
+!CHECK-LABEL: func @_QPsb2
+subroutine sb2(arr)
+  integer :: arr(:)
+!CHECK: omp.parallel  {
+  !$omp parallel
+!CHECK: omp.single nowait {
+  !$omp workshare
+    arr = 0
+  !$omp end workshare nowait
+!CHECK: }
+  !$omp end parallel
+!CHECK: }
+end subroutine
+
+!CHECK-LABEL: func @_QPsb3
+subroutine sb3(arr)
+  integer :: arr(:)
+!CHECK: omp.parallel  {
+!CHECK: omp.single  {
+  !$omp parallel workshare
+    arr = 0
+  !$omp end parallel workshare
+!CHECK: }
+!CHECK: }
+end subroutine

@kiranchandramohan
Copy link
Contributor Author

Note: This is only a temporary lowering. There will be further discussions on the best way to implement this. Some of this is covered as part of Ivan's work for the coexecute construct on the target side (https://llvm.org/devmtg/2024-03/#talk8).

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this!

@kiranchandramohan kiranchandramohan merged commit b585c43 into llvm:main Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants