Skip to content
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

[flang][openacc] Use OpenACC terminator instead of fir.unreachable after Stop stmt #66325

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

clementval
Copy link
Contributor

This follow an update made on OpenMP https://reviews.llvm.org/D129969 and was not possible on OpenACC until the unstructured construct was supported.

…ter Stop stmt

This follow an update made on OpenMP https://reviews.llvm.org/D129969 and was not
possible on OpenACC until the unstructured construct was supported.
@clementval clementval requested a review from a team as a code owner September 14, 2023 04:18
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir openacc labels Sep 14, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2023

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

Changes This follow an update made on OpenMP https://reviews.llvm.org/D129969 and was not possible on OpenACC until the unstructured construct was supported. -- Full diff: https://github.com//pull/66325.diff

5 Files Affected:

  • (modified) flang/include/flang/Lower/OpenACC.h (+3)
  • (modified) flang/lib/Lower/OpenACC.cpp (+9)
  • (modified) flang/lib/Lower/Runtime.cpp (+5)
  • (modified) flang/test/Lower/OpenACC/acc-unstructured.f90 (+2-2)
  • (modified) flang/test/Lower/OpenACC/stop-stmt-in-region.f90 (+1-1)
diff --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h
index 429b548cc22bd47..b342e4a4704dab1 100644
--- a/flang/include/flang/Lower/OpenACC.h
+++ b/flang/include/flang/Lower/OpenACC.h
@@ -103,6 +103,9 @@ void attachDeclarePreDeallocAction(AbstractConverter &, fir::FirOpBuilder &,
 void attachDeclarePostDeallocAction(AbstractConverter &, fir::FirOpBuilder &,
                                     const Fortran::semantics::Symbol &);
 
+void genOpenACCTerminator(fir::FirOpBuilder &, mlir::Operation *,
+                          mlir::Location);
+
 } // namespace lower
 } // namespace Fortran
 
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 180c077d39c9ee2..04078d739ea78c4 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -3299,3 +3299,12 @@ void Fortran::lower::attachDeclarePostDeallocAction(
                  /*preAlloc=*/{}, /*postAlloc=*/{}, /*preDealloc=*/{},
                  /*postDealloc=*/builder.getSymbolRefAttr(fctName.str())));
 }
+
+void Fortran::lower::genOpenACCTerminator(fir::FirOpBuilder &builder,
+                                          mlir::Operation *op,
+                                          mlir::Location loc) {
+  if (mlir::isa<mlir::acc::ParallelOp, mlir::acc::LoopOp>(op))
+    builder.create<mlir::acc::YieldOp>(loc);
+  else
+    builder.create<mlir::acc::TerminatorOp>(loc);
+}
diff --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp
index 11cb56c72d75932..2cf1e522d330d4c 100644
--- a/flang/lib/Lower/Runtime.cpp
+++ b/flang/lib/Lower/Runtime.cpp
@@ -8,6 +8,7 @@
 
 #include "flang/Lower/Runtime.h"
 #include "flang/Lower/Bridge.h"
+#include "flang/Lower/OpenACC.h"
 #include "flang/Lower/OpenMP.h"
 #include "flang/Lower/StatementContext.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
@@ -21,6 +22,7 @@
 #include "flang/Runtime/stop.h"
 #include "flang/Runtime/time-intrinsic.h"
 #include "flang/Semantics/tools.h"
+#include "mlir/Dialect/OpenACC/OpenACC.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "llvm/Support/Debug.h"
 #include <optional>
@@ -37,6 +39,9 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) {
   if (parentOp->getDialect()->getNamespace() ==
       mlir::omp::OpenMPDialect::getDialectNamespace())
     Fortran::lower::genOpenMPTerminator(builder, parentOp, loc);
+  else if (parentOp->getDialect()->getNamespace() ==
+           mlir::acc::OpenACCDialect::getDialectNamespace())
+    Fortran::lower::genOpenACCTerminator(builder, parentOp, loc);
   else
     builder.create<fir::UnreachableOp>(loc);
   mlir::Block *newBlock = curBlock->splitBlock(builder.getInsertionPoint());
diff --git a/flang/test/Lower/OpenACC/acc-unstructured.f90 b/flang/test/Lower/OpenACC/acc-unstructured.f90
index bd9f3284d9fc25c..4ce474241a4bec7 100644
--- a/flang/test/Lower/OpenACC/acc-unstructured.f90
+++ b/flang/test/Lower/OpenACC/acc-unstructured.f90
@@ -57,7 +57,7 @@ subroutine test_unstructured2(a, b, c)
 ! CHECK: acc.parallel
 ! CHECK: acc.loop
 ! CHECK: fir.call @_FortranAStopStatementText
-! CHECK: fir.unreachable
+! CHECK: acc.yield
 ! CHECK: acc.yield
 ! CHECK: acc.yield
 
@@ -80,7 +80,7 @@ subroutine test_unstructured3(a, b, c)
 ! CHECK-LABEL: func.func @_QPtest_unstructured3
 ! CHECK: acc.parallel
 ! CHECK: fir.call @_FortranAStopStatementText
-! CHECK: fir.unreachable
+! CHECK: acc.yield
 ! CHECK: acc.yield
 
 end subroutine
diff --git a/flang/test/Lower/OpenACC/stop-stmt-in-region.f90 b/flang/test/Lower/OpenACC/stop-stmt-in-region.f90
index bec9d53b54c0f1d..4b3e5632650f1cf 100644
--- a/flang/test/Lower/OpenACC/stop-stmt-in-region.f90
+++ b/flang/test/Lower/OpenACC/stop-stmt-in-region.f90
@@ -29,7 +29,7 @@ subroutine test_stop_in_region1()
 ! CHECK:           %[[VAL_2:.*]] = arith.constant false
 ! CHECK:           %[[VAL_3:.*]] = arith.constant false
 ! CHECK:           %[[VAL_4:.*]] = fir.call @_FortranAStopStatement(%[[VAL_1]], %[[VAL_2]], %[[VAL_3]]) {{.*}} : (i32, i1, i1) -> none
-! CHECK:           fir.unreachable
+! CHECK:           acc.yield
 ! CHECK:         }
 ! CHECK:         return
 ! CHECK:       }

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

LGTM

@clementval clementval merged commit b171849 into llvm:main Sep 14, 2023
@clementval clementval deleted the acc_unreachable2 branch September 14, 2023 05:28
kstoimenov pushed a commit to kstoimenov/llvm-project that referenced this pull request Sep 14, 2023
…ter Stop stmt (llvm#66325)

This follow an update made on OpenMP https://reviews.llvm.org/D129969
and was not possible on OpenACC until the unstructured construct was
supported.
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
…ter Stop stmt (llvm#66325)

This follow an update made on OpenMP https://reviews.llvm.org/D129969
and was not possible on OpenACC until the unstructured construct was
supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category openacc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants