[flang-commits] [flang] a2b9201 - [flang][openacc] Lower acc declare link for module variable

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


Author: Valentin Clement
Date: 2023-07-27T13:04:00-07:00
New Revision: a2b92017d3f65327af7f9ec26994053886d0b6d0

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

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

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

Depends on D156463

Reviewed By: razvanlupusoru

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

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 7db109f8acbbb2..1374f25828ce41 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -2416,7 +2416,6 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
     } else if (moduleOp) {
       mlir::OpBuilder modBuilder(moduleOp.getBodyRegion());
       for (const Fortran::parser::AccClause &clause : accClauseList.v) {
-        mlir::Location clauseLocation = converter.genLocation(clause.source);
         if (const auto *createClause =
                 std::get_if<Fortran::parser::AccClause::Create>(&clause.u)) {
           genGlobalCtorsWithModifier<Fortran::parser::AccClause::Create,
@@ -2441,8 +2440,14 @@ static void genACC(Fortran::lower::AbstractConverter &converter,
                          mlir::acc::DeclareDeviceResidentOp>(
               converter, modBuilder, deviceResidentClause->v,
               mlir::acc::DataClause::acc_declare_device_resident);
+        } else if (const auto *linkClause =
+                       std::get_if<Fortran::parser::AccClause::Link>(
+                           &clause.u)) {
+          genGlobalCtors<mlir::acc::DeclareLinkOp, mlir::acc::DeclareLinkOp>(
+              converter, modBuilder, linkClause->v,
+              mlir::acc::DataClause::acc_declare_link);
         } else {
-          TODO(clauseLocation, "OpenACC declare clause");
+          llvm::report_fatal_error("unsupported clause on DECLARE directive");
         }
       }
     }

diff  --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index 0a234d262e84a6..ace164de2c80fc 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -70,3 +70,18 @@ module acc_declare_device_resident_test
 ! CHECK:         acc.declare_enter dataOperands(%[[DEVICERESIDENT]] : !fir.ref<!fir.array<5000xi32>>)
 ! CHECK:         acc.terminator
 ! CHECK:       }
+
+module acc_declare_device_link_test
+ integer, parameter :: n = 5000
+ integer, dimension(n) :: data1
+ !$acc declare link(data1)
+end module
+
+! CHECK-LABEL: fir.global @_QMacc_declare_device_link_testEdata1 {acc.declare = #acc.declare<dataClause =  acc_declare_link>} : !fir.array<5000xi32> {
+
+! CHECK-LABEL: acc.global_ctor @_QMacc_declare_device_link_testEdata1_acc_ctor {
+! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_device_link_testEdata1) {acc.declare = #acc.declare<dataClause =  acc_declare_link>} : !fir.ref<!fir.array<5000xi32>>
+! CHECK:         %[[LINK:.*]] = acc.declare_link varPtr(%[[GLOBAL_ADDR]] : !fir.ref<!fir.array<5000xi32>>) -> !fir.ref<!fir.array<5000xi32>> {name = "data1"}
+! CHECK:         acc.declare_enter dataOperands(%[[LINK]] : !fir.ref<!fir.array<5000xi32>>)
+! CHECK:         acc.terminator
+! CHECK:       }


        


More information about the flang-commits mailing list