[flang-commits] [flang] 29851f4 - [flang][openacc] Add lowering support for create clause on OpenACC declare

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue Aug 1 14:13:06 PDT 2023


Author: Valentin Clement
Date: 2023-08-01T14:12:40-07:00
New Revision: 29851f48fa29996eb2839741d41131ccb785d5c6

URL: https://github.com/llvm/llvm-project/commit/29851f48fa29996eb2839741d41131ccb785d5c6
DIFF: https://github.com/llvm/llvm-project/commit/29851f48fa29996eb2839741d41131ccb785d5c6.diff

LOG: [flang][openacc] Add lowering support for create clause on OpenACC declare

Lower the create clause on the OpenACC declare construct in
function/subroutine.

Depends on D156568

Reviewed By: razvanlupusoru

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

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 fd8bf143a70d6f..937815c8f947ba 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2400,20 +2400,33 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
                      Fortran::lower::StatementContext &fctCtx,
                      mlir::Location loc,
                      const Fortran::parser::AccClauseList &accClauseList) {
-  llvm::SmallVector<mlir::Value> dataClauseOperands, copyEntryOperands;
+  llvm::SmallVector<mlir::Value> dataClauseOperands, copyEntryOperands,
+      createEntryOperands;
   Fortran::lower::StatementContext stmtCtx;
   fir::FirOpBuilder &builder = converter.getFirOpBuilder();
   for (const Fortran::parser::AccClause &clause : accClauseList.v) {
     if (const auto *copyClause =
             std::get_if<Fortran::parser::AccClause::Copy>(&clause.u)) {
       auto crtDataStart = dataClauseOperands.size();
-
       genDataOperandOperations<mlir::acc::CopyinOp>(
           copyClause->v, converter, semanticsContext, stmtCtx,
           dataClauseOperands, mlir::acc::DataClause::acc_copy,
           /*structured=*/true, /*setDeclareAttr=*/true);
       copyEntryOperands.append(dataClauseOperands.begin() + crtDataStart,
                                dataClauseOperands.end());
+    } else if (const auto *createClause =
+                   std::get_if<Fortran::parser::AccClause::Create>(&clause.u)) {
+      const Fortran::parser::AccObjectListWithModifier &listWithModifier =
+          createClause->v;
+      const auto &accObjectList =
+          std::get<Fortran::parser::AccObjectList>(listWithModifier.t);
+      auto crtDataStart = dataClauseOperands.size();
+      genDataOperandOperations<mlir::acc::CreateOp>(
+          accObjectList, converter, semanticsContext, stmtCtx,
+          dataClauseOperands, mlir::acc::DataClause::acc_create,
+          /*structured=*/true, /*setDeclareAttr=*/true);
+      createEntryOperands.append(dataClauseOperands.begin() + crtDataStart,
+                                 dataClauseOperands.end());
     } else {
       mlir::Location clauseLocation = converter.genLocation(clause.source);
       TODO(clauseLocation, "clause on declare directive");
@@ -2422,10 +2435,13 @@ genDeclareInFunction(Fortran::lower::AbstractConverter &converter,
   builder.create<mlir::acc::DeclareEnterOp>(loc, dataClauseOperands);
 
   // Attach declare exit operation generation to function context.
-  fctCtx.attachCleanup([&builder, loc, copyEntryOperands]() {
-    builder.create<mlir::acc::DeclareExitOp>(loc, copyEntryOperands);
-    genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(
-        builder, copyEntryOperands, /*structured=*/true, /*implicit=*/false);
+  fctCtx.attachCleanup([&builder, loc, dataClauseOperands, createEntryOperands,
+                        copyEntryOperands]() {
+    builder.create<mlir::acc::DeclareExitOp>(loc, dataClauseOperands);
+    genDataExitOperations<mlir::acc::CreateOp, mlir::acc::DeleteOp>(
+        builder, createEntryOperands, /*structured=*/true, /*implicit=*/false);
+    genDataExitOperations<mlir::acc::CopyinOp, mlir::acc::CopyoutOp>(builder,
+        copyEntryOperands, /*structured=*/true, /*implicit=*/false);
   });
 }
 

diff  --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index c0ad91581e7e24..294f495fb36e05 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -95,4 +95,28 @@ subroutine acc_declare_copy()
 
 ! CHECK: return
 
+  subroutine acc_declare_create()
+    integer :: a(100), i
+    !$acc declare create(a)
+
+    do i = 1, 100
+      a(i) = i
+    end do
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMacc_declarePacc_declare_create() {
+    
+! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xi32> {acc.declare = #acc.declare<dataClause =  acc_create>, bindc_name = "a", uniq_name = "_QMacc_declareFacc_declare_createEa"}
+! CHECK: %[[BOUND:.*]] = acc.bounds   lowerbound(%{{.*}} : index) upperbound(%{{.*}} : index) extent(%{{.*}} : index) stride(%c1 : index) startIdx(%c1 : index)
+! CHECK: %[[CREATE:.*]] = acc.create varPtr(%[[ALLOCA]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xi32>> {name = "a"}
+! CHECK: acc.declare_enter dataOperands(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>)
+
+! CHECK: %{{.*}}:2 = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%{{.*}} = %{{.*}}) -> (index, i32) {
+! CHECK: }
+
+! CHECK: acc.declare_exit dataOperands(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>)
+! CHECK: acc.delete accPtr(%[[CREATE]] : !fir.ref<!fir.array<100xi32>>) bounds(%[[BOUND]]) {dataClause = #acc<data_clause acc_create>, name = "a"}
+! CHECK: return
+
+
 end module


        


More information about the flang-commits mailing list