[flang-commits] [flang] 5f2c585 - [flang][openacc] Lower acc declare copyin for module variable

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Jul 27 13:00:25 PDT 2023


Author: Valentin Clement
Date: 2023-07-27T13:00:20-07:00
New Revision: 5f2c585b10c7c497fb9cdda80fc2aab8638c0562

URL: https://github.com/llvm/llvm-project/commit/5f2c585b10c7c497fb9cdda80fc2aab8638c0562
DIFF: https://github.com/llvm/llvm-project/commit/5f2c585b10c7c497fb9cdda80fc2aab8638c0562.diff

LOG: [flang][openacc] Lower acc declare copyin for module variable

This patch adds support to lower the copyin clause on OpenACC
declare construct in module declaration.

Depends on D156353

Reviewed By: razvanlupusoru

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

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 3e27c491d6fc58..1acd0e294ce199 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2356,10 +2356,12 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
                 createDeclareGlobalOp<mlir::acc::GlobalConstructorOp, EntryOp,
                                       mlir::acc::DeclareEnterOp, ExitOp>(
                     modBuilder, builder, operandLocation, globalOp, clause);
-                createDeclareGlobalOp<mlir::acc::GlobalDestructorOp,
-                                      mlir::acc::GetDevicePtrOp,
-                                      mlir::acc::DeclareExitOp, ExitOp>(
-                    modBuilder, builder, operandLocation, globalOp, clause);
+                if constexpr (!std::is_same_v<EntryOp, ExitOp>) {
+                  createDeclareGlobalOp<mlir::acc::GlobalDestructorOp,
+                                        mlir::acc::GetDevicePtrOp,
+                                        mlir::acc::DeclareExitOp, ExitOp>(
+                      modBuilder, builder, operandLocation, globalOp, clause);
+                }
                 builder.restoreInsertionPoint(crtPos);
               }
             },
@@ -2423,6 +2425,15 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
               Fortran::parser::AccDataModifier::Modifier::Zero,
               mlir::acc::DataClause::acc_create,
               mlir::acc::DataClause::acc_create_zero);
+        } else if (const auto *copyinClause =
+                       std::get_if<Fortran::parser::AccClause::Copyin>(
+                           &clause.u)) {
+          genGlobalCtorsWithModifier<Fortran::parser::AccClause::Copyin,
+                                     mlir::acc::CopyinOp, mlir::acc::CopyinOp>(
+              converter, modBuilder, copyinClause,
+              Fortran::parser::AccDataModifier::Modifier::ReadOnly,
+              mlir::acc::DataClause::acc_copyin,
+              mlir::acc::DataClause::acc_copyin_readonly);
         } else {
           TODO(clauseLocation, "OpenACC declare clause");
         }

diff  --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index 08184d841e5d87..db6d5af7243721 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -41,3 +41,17 @@ module acc_declare_test
 ! CHECK:         acc.delete accPtr(%[[DEVICEPTR]] : !fir.ref<!fir.array<100000xf32>>) {dataClause = #acc<data_clause acc_create_zero>, name = "data2", structured = false}
 ! CHECK:         acc.terminator
 ! CHECK:       }
+
+module acc_declare_copyin_test
+ integer, parameter :: n = 100000
+ real, dimension(n) :: data1
+ !$acc declare copyin(data1)
+end module
+
+
+! CHECK-LABEL: acc.global_ctor @_QMacc_declare_copyin_testEdata1_acc_ctor {
+! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_copyin_testEdata1) {acc.declare = #acc.declare<dataClause =  acc_copyin>} : !fir.ref<!fir.array<100000xf32>>
+! CHECK:         %[[COPYIN:.*]] = acc.copyin varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.array<100000xf32>>) -> !fir.ref<!fir.array<100000xf32>> {name = "data1"}
+! CHECK:         acc.declare_enter dataOperands(%[[COPYIN]] : !fir.ref<!fir.array<100000xf32>>)
+! CHECK:         acc.terminator
+! CHECK:       }


        


More information about the flang-commits mailing list