From 2837fd7e5ad521d977fbca85a639ce7afbacdc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Fri, 11 Apr 2025 14:01:03 -0700 Subject: [PATCH] [flang][openacc] Allow if_present multiple times on host_data and update (#135422) 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. --- flang/test/Lower/OpenACC/acc-host-data.f90 | 5 +++++ flang/test/Lower/OpenACC/acc-update.f90 | 3 +++ .../test/Semantics/OpenACC/acc-host-data.f90 | 2 +- .../Semantics/OpenACC/acc-update-validity.f90 | 2 +- llvm/include/llvm/Frontend/OpenACC/ACC.td | 20 +++++++------------ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/flang/test/Lower/OpenACC/acc-host-data.f90 b/flang/test/Lower/OpenACC/acc-host-data.f90 index 7e06ebbc0ea0..871eabd256ca 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.ref> {name = "a"} ! CHECK: acc.host_data dataOperands(%[[DA]] : !fir.ref>) { +! CHECK: } attributes {ifPresent} + + !$acc host_data use_device(a) if_present if_present + !$acc end host_data +! CHECK: acc.host_data dataOperands(%{{.*}} : !fir.ref>) { ! 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 1ae06a8c1d0e..f96b105ed93b 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>) attributes {ifPresent}{{$}} ! CHECK: acc.update_host accPtr(%[[DEVPTR_A]] : !fir.ref>) to varPtr(%[[DECLA]]#0 : !fir.ref>) {name = "a", structured = false} + !$acc update host(a) if_present if_present +! CHECK: acc.update dataOperands(%{{.*}} : !fir.ref>) attributes {ifPresent}{{$}} + !$acc update self(a) ! CHECK: %[[DEVPTR_A:.*]] = acc.getdeviceptr varPtr(%[[DECLA]]#0 : !fir.ref>) -> !fir.ref> {dataClause = #acc, name = "a", structured = false} ! CHECK: acc.update dataOperands(%[[DEVPTR_A]] : !fir.ref>){{$}} diff --git a/flang/test/Semantics/OpenACC/acc-host-data.f90 b/flang/test/Semantics/OpenACC/acc-host-data.f90 index 4e9167722a22..f5aa4d7f320f 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 1e75742e63e9..8add56e81cf9 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 cee0d53458a0..2acee9bcc719 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, - VersionedClause - ]; - let allowedOnceClauses = [ - VersionedClause, - VersionedClause, - VersionedClause - ]; + let allowedClauses = [VersionedClause, + VersionedClause, + VersionedClause]; + let allowedOnceClauses = [VersionedClause, + VersionedClause]; let requiredClauses = [ VersionedClause, VersionedClause, @@ -550,10 +546,8 @@ def ACC_ExitData : Directive<"exit data"> { // 2.8 def ACC_HostData : Directive<"host_data"> { - let allowedOnceClauses = [ - VersionedClause, - VersionedClause - ]; + let allowedClauses = [VersionedClause]; + let allowedOnceClauses = [VersionedClause]; let requiredClauses = [ VersionedClause ];