[flang-commits] [flang] [llvm] [flang][openacc] Allow if_present multiple times on host_data and update (PR #135422)

via flang-commits flang-commits at lists.llvm.org
Fri Apr 11 11:43:28 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

<details>
<summary>Changes</summary>

Similar to #<!-- -->135415.

The spec has not strict restriction to allow a single `if_present` clause on the host_data and update directives. Allowing this clause multiple times does not change the semantic of it. This patch relax the rules in ACC.td since there is no restriction in the standard.

The OpenACC dialect represents the `if_present` clause with a `UnitAttr` so the attribute will be set if the is one or more `if_present` clause.



---
Full diff: https://github.com/llvm/llvm-project/pull/135422.diff


5 Files Affected:

- (modified) flang/test/Lower/OpenACC/acc-host-data.f90 (+5) 
- (modified) flang/test/Lower/OpenACC/acc-update.f90 (+3) 
- (modified) flang/test/Semantics/OpenACC/acc-host-data.f90 (+1-1) 
- (modified) flang/test/Semantics/OpenACC/acc-update-validity.f90 (+1-1) 
- (modified) llvm/include/llvm/Frontend/OpenACC/ACC.td (+7-13) 


``````````diff
diff --git a/flang/test/Lower/OpenACC/acc-host-data.f90 b/flang/test/Lower/OpenACC/acc-host-data.f90
index 7e06ebbc0ea04..871eabd256ca6 100644
--- a/flang/test/Lower/OpenACC/acc-host-data.f90
+++ b/flang/test/Lower/OpenACC/acc-host-data.f90
@@ -22,6 +22,11 @@ subroutine acc_host_data()
 
 ! CHECK: %[[DA:.*]] = acc.use_device varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {name = "a"}
 ! CHECK: acc.host_data dataOperands(%[[DA]] : !fir.ref<!fir.array<10xf32>>) {
+! CHECK: } attributes {ifPresent}
+
+  !$acc host_data use_device(a) if_present if_present
+  !$acc end host_data
+! CHECK: acc.host_data dataOperands(%{{.*}} : !fir.ref<!fir.array<10xf32>>) {
 ! CHECK: } attributes {ifPresent}
 
   !$acc host_data use_device(a) if(ifCondition)
diff --git a/flang/test/Lower/OpenACC/acc-update.f90 b/flang/test/Lower/OpenACC/acc-update.f90
index 1ae06a8c1d0e8..f96b105ed93bd 100644
--- a/flang/test/Lower/OpenACC/acc-update.f90
+++ b/flang/test/Lower/OpenACC/acc-update.f90
@@ -24,6 +24,9 @@ subroutine acc_update
 ! 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>>) to varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) {name = "a", structured = false}
 
+  !$acc update host(a) if_present if_present
+! CHECK: acc.update dataOperands(%{{.*}} : !fir.ref<!fir.array<10x10xf32>>) attributes {ifPresent}{{$}}
+
   !$acc update self(a)
 ! CHECK: %[[DEVPTR_A:.*]] = acc.getdeviceptr varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) -> !fir.ref<!fir.array<10x10xf32>> {dataClause = #acc<data_clause acc_update_self>, name = "a", structured = false}
 ! CHECK: acc.update dataOperands(%[[DEVPTR_A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
diff --git a/flang/test/Semantics/OpenACC/acc-host-data.f90 b/flang/test/Semantics/OpenACC/acc-host-data.f90
index 4e9167722a228..f5aa4d7f320ff 100644
--- a/flang/test/Semantics/OpenACC/acc-host-data.f90
+++ b/flang/test/Semantics/OpenACC/acc-host-data.f90
@@ -27,7 +27,7 @@ program openacc_host_data_validity
   !$acc host_data use_device(aa, bb) if_present
   !$acc end host_data
 
-  !ERROR: At most one IF_PRESENT clause can appear on the HOST_DATA directive
+  ! OK
   !$acc host_data use_device(aa, bb) if_present if_present
   !$acc end host_data
 
diff --git a/flang/test/Semantics/OpenACC/acc-update-validity.f90 b/flang/test/Semantics/OpenACC/acc-update-validity.f90
index 1e75742e63e97..8add56e81cf9e 100644
--- a/flang/test/Semantics/OpenACC/acc-update-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-update-validity.f90
@@ -58,7 +58,7 @@ program openacc_update_validity
   !ERROR: At most one IF clause can appear on the UPDATE directive
   !$acc update device(aa) if(.true.) if(ifCondition)
 
-  !ERROR: At most one IF_PRESENT clause can appear on the UPDATE directive
+  ! OK
   !$acc update device(bb) if_present if_present
 
   !ERROR: Clause IF is not allowed after clause DEVICE_TYPE on the UPDATE directive
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index 8729d4505205b..78cc02ae0b332 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -487,15 +487,11 @@ def ACC_Shutdown : Directive<"shutdown"> {
 
 // 2.14.4
 def ACC_Update : Directive<"update"> {
-  let allowedClauses = [
-    VersionedClause<ACCC_DeviceType>,
-    VersionedClause<ACCC_Wait>
-  ];
-  let allowedOnceClauses = [
-    VersionedClause<ACCC_Async>,
-    VersionedClause<ACCC_If>,
-    VersionedClause<ACCC_IfPresent>
-  ];
+  let allowedClauses = [VersionedClause<ACCC_DeviceType>,
+                        VersionedClause<ACCC_IfPresent>,
+                        VersionedClause<ACCC_Wait>];
+  let allowedOnceClauses = [VersionedClause<ACCC_Async>,
+                            VersionedClause<ACCC_If>];
   let requiredClauses = [
     VersionedClause<ACCC_Device>,
     VersionedClause<ACCC_Host>,
@@ -554,10 +550,8 @@ def ACC_ExitData : Directive<"exit data"> {
 
 // 2.8
 def ACC_HostData : Directive<"host_data"> {
-  let allowedOnceClauses = [
-    VersionedClause<ACCC_If>,
-    VersionedClause<ACCC_IfPresent>
-  ];
+  let allowedClauses = [VersionedClause<ACCC_IfPresent>];
+  let allowedOnceClauses = [VersionedClause<ACCC_If>];
   let requiredClauses = [
     VersionedClause<ACCC_UseDevice>
   ];

``````````

</details>


https://github.com/llvm/llvm-project/pull/135422


More information about the flang-commits mailing list