[flang-commits] [flang] f2031ac - [flang][openacc] Lower if_present clause correctly on acc update

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue May 9 08:59:56 PDT 2023


Author: Valentin Clement
Date: 2023-05-09T08:59:50-07:00
New Revision: f2031ac90e2790f741d1a5e0a0c7f779cd5a859d

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

LOG: [flang][openacc] Lower if_present clause correctly on acc update

The `if_present` clause is modeled as an attribute on the
acc.update operation. The lowering was not adding correctly the attribute
when the clause was present. This patch update the lowering to add
the attribute when needed.

Reviewed By: razvanlupusoru

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index d46c0c54ee460..a0d10847ea50b 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1481,6 +1481,8 @@ genACCUpdateOp(Fortran::lower::AbstractConverter &converter,
       genDataOperandOperations<mlir::acc::UpdateDeviceOp>(
           deviceClause->v, converter, semanticsContext, stmtCtx,
           dataClauseOperands, mlir::acc::DataClause::acc_update_device, false);
+    } else if (std::get_if<Fortran::parser::AccClause::IfPresent>(&clause.u)) {
+      addIfPresentAttr = true;
     }
   }
 

diff  --git a/flang/test/Lower/OpenACC/acc-update.f90 b/flang/test/Lower/OpenACC/acc-update.f90
index ee02371e2d4f6..ac25cb12a1ffe 100644
--- a/flang/test/Lower/OpenACC/acc-update.f90
+++ b/flang/test/Lower/OpenACC/acc-update.f90
@@ -14,6 +14,11 @@ subroutine acc_update
   !$acc update host(a)
 ! CHECK: %[[DEVPTR_A:.*]] = acc.getdeviceptr varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%{{.*}}, %{{.*}}) -> !fir.ref<!fir.array<10x10xf32>> {dataClause = 17 : i64, name = "a", structured = false}
 ! CHECK: acc.update dataOperands(%[[DEVPTR_A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
+! CHECK: acc.update_host accPtr(%[[DEVPTR_A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%{{.*}}, %{{.*}}) to varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) {name = "a", structured = false}
+
+  !$acc update host(a) if_present
+! CHECK: %[[DEVPTR_A:.*]] = acc.getdeviceptr varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%{{.*}}, %{{.*}}) -> !fir.ref<!fir.array<10x10xf32>> {dataClause = 17 : i64, name = "a", structured = false}
+! CHECK: acc.update dataOperands(%[[DEVPTR_A]] : !fir.ref<!fir.array<10x10xf32>>) attributes {ifPresent}{{$}}
 ! CHECK: acc.update_host accPtr(%[[DEVPTR_A]] : !fir.ref<!fir.array<10x10xf32>>) bounds(%{{.*}}, %{{.*}}) to varPtr(%[[A]] : !fir.ref<!fir.array<10x10xf32>>) {name = "a", structured = false}
 
   !$acc update host(a) if(.true.)


        


More information about the flang-commits mailing list