[flang-commits] [flang] c9bfca5 - [flang][openacc] Lower the default clause on compute constructs

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Jun 30 10:24:52 PDT 2023


Author: Valentin Clement
Date: 2023-06-30T10:24:46-07:00
New Revision: c9bfca542958ccb6ed4d4345768d439ba690d95e

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

LOG: [flang][openacc] Lower the default clause on compute constructs

Lower default clause to the correct attribute for compute
operation.

Reviewed By: razvanlupusoru

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

Added: 
    

Modified: 
    flang/lib/Lower/OpenACC.cpp
    flang/test/Lower/OpenACC/acc-kernels.f90
    flang/test/Lower/OpenACC/acc-parallel.f90
    flang/test/Lower/OpenACC/acc-serial.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 4313413065be34..648e7e243e3e87 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1129,6 +1129,9 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
   bool addWaitAttr = false;
   bool addSelfAttr = false;
 
+  bool hasDefaultNone = false;
+  bool hasDefaultPresent = false;
+
   fir::FirOpBuilder &builder = converter.getFirOpBuilder();
 
   // Lower clauses values mapped to operands.
@@ -1282,6 +1285,14 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
                        &clause.u)) {
       genReductions(reductionClause->v, converter, semanticsContext, stmtCtx,
                     reductionOperands, reductionRecipes);
+    } else if (const auto *defaultClause =
+                   std::get_if<Fortran::parser::AccClause::Default>(
+                       &clause.u)) {
+      if ((defaultClause->v).v == llvm::acc::DefaultValue::ACC_Default_none)
+        hasDefaultNone = true;
+      else if ((defaultClause->v).v ==
+               llvm::acc::DefaultValue::ACC_Default_present)
+        hasDefaultPresent = true;
     }
   }
 
@@ -1319,6 +1330,11 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
   if (addSelfAttr)
     computeOp.setSelfAttrAttr(builder.getUnitAttr());
 
+  if (hasDefaultNone)
+    computeOp.setDefaultAttr(mlir::acc::ClauseDefaultValue::None);
+  if (hasDefaultPresent)
+    computeOp.setDefaultAttr(mlir::acc::ClauseDefaultValue::Present);
+
   if constexpr (!std::is_same_v<Op, mlir::acc::KernelsOp>) {
     if (!privatizations.empty())
       computeOp.setPrivatizationsAttr(

diff  --git a/flang/test/Lower/OpenACC/acc-kernels.f90 b/flang/test/Lower/OpenACC/acc-kernels.f90
index 70a4cca6e094fc..b2eb85a3977dd5 100644
--- a/flang/test/Lower/OpenACC/acc-kernels.f90
+++ b/flang/test/Lower/OpenACC/acc-kernels.f90
@@ -277,4 +277,16 @@ subroutine acc_kernels
 ! CHECK:        acc.terminator
 ! CHECK-NEXT: }{{$}}
 
+!$acc kernels default(none)
+!$acc end kernels
+
+! CHECK: acc.kernels {
+! CHECK: } attributes {defaultAttr = #acc<defaultvalue none>}
+
+!$acc kernels default(present)
+!$acc end kernels
+
+! CHECK: acc.kernels {
+! CHECK: } attributes {defaultAttr = #acc<defaultvalue present>}
+
 end subroutine acc_kernels

diff  --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90
index 23afbe6a165fba..dbc6e6ccc46b02 100644
--- a/flang/test/Lower/OpenACC/acc-parallel.f90
+++ b/flang/test/Lower/OpenACC/acc-parallel.f90
@@ -329,4 +329,16 @@ subroutine acc_parallel
 ! CHECK:        acc.yield
 ! CHECK-NEXT: }{{$}}
 
+!$acc parallel default(none)
+!$acc end parallel
+
+! CHECK: acc.parallel {
+! CHECK: } attributes {defaultAttr = #acc<defaultvalue none>}
+
+!$acc parallel default(present)
+!$acc end parallel
+
+! CHECK: acc.parallel {
+! CHECK: } attributes {defaultAttr = #acc<defaultvalue present>}
+
 end subroutine acc_parallel

diff  --git a/flang/test/Lower/OpenACC/acc-serial.f90 b/flang/test/Lower/OpenACC/acc-serial.f90
index 2e760f44c54ecd..cea0a54406724b 100644
--- a/flang/test/Lower/OpenACC/acc-serial.f90
+++ b/flang/test/Lower/OpenACC/acc-serial.f90
@@ -265,4 +265,16 @@ subroutine acc_serial
 ! CHECK:        acc.yield
 ! CHECK-NEXT: }{{$}}
 
+!$acc serial default(none)
+!$acc end serial
+
+! CHECK: acc.serial {
+! CHECK: } attributes {defaultAttr = #acc<defaultvalue none>}
+
+!$acc serial default(present)
+!$acc end serial
+
+! CHECK: acc.serial {
+! CHECK: } attributes {defaultAttr = #acc<defaultvalue present>}
+
 end subroutine


        


More information about the flang-commits mailing list