[flang-commits] [flang] 7b24612 - [flang][openacc] Always generate acc.declare_exit

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Aug 9 11:12:02 PDT 2023


Author: Valentin Clement
Date: 2023-08-09T11:11:45-07:00
New Revision: 7b24612c6fe4bd91d664264b452040fac4a93a0c

URL: https://github.com/llvm/llvm-project/commit/7b24612c6fe4bd91d664264b452040fac4a93a0c
DIFF: https://github.com/llvm/llvm-project/commit/7b24612c6fe4bd91d664264b452040fac4a93a0c.diff

LOG: [flang][openacc] Always generate acc.declare_exit

Always generate the acc.declare_exit operation so it
matches the acc.declare_enter operation. This is to ensure the
lifetime of data in the implicit region.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157524

Added: 
    

Modified: 
    flang/lib/Lower/OpenACC.cpp
    flang/test/Lower/OpenACC/acc-declare.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index de47e7e5f9dc17..f899590336a715 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2556,27 +2556,24 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
   }
   builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);
 
-  if (!createEntryOperands.empty() || !copyEntryOperands.empty() ||
-      !copyoutEntryOperands.empty() || !deviceResidentEntryOperands.empty()) {
-    // Attach declare exit operation generation to function context.
-    fctCtx.attachCleanup([&builder, loc, dataClauseOperands,
-                          createEntryOperands, copyEntryOperands,
-                          copyoutEntryOperands, deviceResidentEntryOperands]() {
-      builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
-      genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
-          builder, createEntryOperands, /*structured=*/true,
-          /*implicit=*/false);
-      genDataExitOperations<mlir::acc::DeclareDeviceResidentOp,
-                            mlir::acc::DeleteOp>(
-          builder, deviceResidentEntryOperands, /*structured=*/true,
-          /*implicit=*/false);
-      genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
-          builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
-      genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
-          builder, copyoutEntryOperands, /*structured=*/true,
-          /*implicit=*/false);
-    });
-  }
+  // Attach declare exit operation generation to function context.
+  fctCtx.attachCleanup([&builder, loc, dataClauseOperands, createEntryOperands,
+                        copyEntryOperands, copyoutEntryOperands,
+                        deviceResidentEntryOperands]() {
+    builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
+    genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
+        builder, createEntryOperands, /*structured=*/true,
+        /*implicit=*/false);
+    genDataExitOperations<mlir::acc::DeclareDeviceResidentOp,
+                          mlir::acc::DeleteOp>(
+        builder, deviceResidentEntryOperands, /*structured=*/true,
+        /*implicit=*/false);
+    genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
+        builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
+    genDataExitOperations<mlir::acc::CreateOp, mlir::acc::CopyoutOp>(
+        builder, copyoutEntryOperands, /*structured=*/true,
+        /*implicit=*/false);
+  });
 }
 
 static void

diff  --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index 227a9e677cf364..2d1a52bd01ab7f 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -133,7 +133,7 @@ subroutine acc_declare_present(a)
 ! CHECK: %[[PRESENT:.*]] = acc.present varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
 ! CHECK: acc.declare_enter dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
 ! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
-! CHECK-NOT: acc.declare_exit
+! CHECK: acc.declare_exit dataOperands(%[[PRESENT]] : !fir.ref<!fir.array<100xi32>>)
 
   subroutine acc_declare_copyin()
     integer :: a(100), b(10), i
@@ -153,7 +153,7 @@ subroutine acc_declare_copyin()
 ! CHECK: %[[COPYIN_B:.*]] = acc.copyin varPtr(%[[B]] : !fir.ref<!fir.array<10xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<10xi32>> {dataClause = #acc<data_clause acc_copyin_readonly>, name = "b"}
 ! CHECK: acc.declare_enter dataOperands(%[[COPYIN_A]], %[[COPYIN_B]] : !fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<10xi32>>)
 ! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
-! CHECK-NOT: acc.declare_exit
+! CHECK: acc.declare_exit dataOperands(%[[COPYIN_A]], %[[COPYIN_B]] : !fir.ref<!fir.array<100xi32>>, !fir.ref<!fir.array<10xi32>>)
 
   subroutine acc_declare_copyout()
     integer :: a(100), i
@@ -187,7 +187,7 @@ subroutine acc_declare_deviceptr(a)
 ! CHECK: %[[DEVICEPTR:.*]] = acc.deviceptr varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
 ! CHECK: acc.declare_enter dataOperands(%[[DEVICEPTR]] : !fir.ref<!fir.array<100xi32>>)
 ! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
-! CHECK-NOT: acc.declare_exit
+! CHECK: acc.declare_exit dataOperands(%[[DEVICEPTR]] : !fir.ref<!fir.array<100xi32>>)
 
   subroutine acc_declare_link(a)
     integer :: a(100), i
@@ -203,7 +203,7 @@ subroutine acc_declare_link(a)
 ! CHECK: %[[LINK:.*]] = acc.declare_link varPtr(%[[ARG0]] : !fir.ref<!fir.array<100xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
 ! CHECK: acc.declare_enter dataOperands(%[[LINK]] : !fir.ref<!fir.array<100xi32>>)
 ! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%arg{{.*}} = %{{.*}}) -> (index, i32)
-! CHECK-NOT: acc.declare_exit
+! CHECK: acc.declare_exit dataOperands(%[[LINK]] : !fir.ref<!fir.array<100xi32>>)
 
   subroutine acc_declare_device_resident(a)
     integer :: a(100), i


        


More information about the flang-commits mailing list