[flang-commits] [flang] [llvm] [flang][OpenMP] Add semantic check for target data (PR #71560)
via flang-commits
flang-commits at lists.llvm.org
Tue Nov 7 09:25:47 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Shraiysh (shraiysh)
<details>
<summary>Changes</summary>
This patch adds the following semantic check on target data
```
At least one map, use_device_addr or use_device_ptr clause must appear
on the target data directive.
```
---
Full diff: https://github.com/llvm/llvm-project/pull/71560.diff
4 Files Affected:
- (modified) flang/lib/Semantics/check-omp-structure.cpp (+16)
- (modified) flang/lib/Semantics/check-omp-structure.h (+1)
- (modified) flang/test/Semantics/OpenMP/device-constructs.f90 (+1-1)
- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+2-4)
``````````diff
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index d7a0681d1c3d476..1b6b38d0e972d0d 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -919,12 +919,28 @@ void OmpStructureChecker::ChecksOnOrderedAsBlock() {
}
}
+void OmpStructureChecker::CheckTargetData() {
+ const parser::OmpClause *mapClause = FindClause(llvm::omp::Clause::OMPC_map);
+ const parser::OmpClause *useDevicePtrClause =
+ FindClause(llvm::omp::Clause::OMPC_use_device_ptr);
+ const parser::OmpClause *useDeviceAddrClause =
+ FindClause(llvm::omp::OMPC_use_device_addr);
+ if (!mapClause && !useDevicePtrClause && !useDeviceAddrClause) {
+ context_.Say(GetContext().directiveSource,
+ "At least one MAP, USE_DEVICE_ADDR or USE_DEVICE_PTR clause must "
+ "appear on the TARGET DATA directive."_err_en_US);
+ }
+}
+
void OmpStructureChecker::Leave(const parser::OmpBeginBlockDirective &) {
switch (GetContext().directive) {
case llvm::omp::Directive::OMPD_ordered:
// [5.1] 2.19.9 Ordered Construct Restriction
ChecksOnOrderedAsBlock();
break;
+ case llvm::omp::Directive::OMPD_target_data:
+ CheckTargetData();
+ return;
default:
break;
}
diff --git a/flang/lib/Semantics/check-omp-structure.h b/flang/lib/Semantics/check-omp-structure.h
index d35602cca75d549..5c80c1ea8a2d23e 100644
--- a/flang/lib/Semantics/check-omp-structure.h
+++ b/flang/lib/Semantics/check-omp-structure.h
@@ -184,6 +184,7 @@ class OmpStructureChecker
void CheckSIMDNest(const parser::OpenMPConstruct &x);
void CheckTargetNest(const parser::OpenMPConstruct &x);
void CheckTargetUpdate();
+ void CheckTargetData();
void CheckCancellationNest(
const parser::CharBlock &source, const parser::OmpCancelType::Type &type);
std::int64_t GetOrdCollapseLevel(const parser::OpenMPLoopConstruct &x);
diff --git a/flang/test/Semantics/OpenMP/device-constructs.f90 b/flang/test/Semantics/OpenMP/device-constructs.f90
index 51f00700b6daf74..a18d99d7c368b64 100644
--- a/flang/test/Semantics/OpenMP/device-constructs.f90
+++ b/flang/test/Semantics/OpenMP/device-constructs.f90
@@ -135,7 +135,7 @@ program main
enddo
!$omp end target data
- !ERROR: At least one of MAP clause must appear on the TARGET DATA directive
+ !ERROR: At least one MAP, USE_DEVICE_ADDR or USE_DEVICE_PTR clause must appear on the TARGET DATA directive.
!$omp target data device(0)
do i = 1, N
a = 3.14
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index f8b3b0c7524979b..79211976c0270c1 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -705,15 +705,13 @@ def OMP_Nothing : Directive<"nothing"> {}
def OMP_TargetData : Directive<"target data"> {
let allowedClauses = [
VersionedClause<OMPC_UseDevicePtr>,
- VersionedClause<OMPC_UseDeviceAddr, 50>
+ VersionedClause<OMPC_UseDeviceAddr, 50>,
+ VersionedClause<OMPC_Map>
];
let allowedOnceClauses = [
VersionedClause<OMPC_Device>,
VersionedClause<OMPC_If>
];
- let requiredClauses = [
- VersionedClause<OMPC_Map>
- ];
}
def OMP_TargetEnterData : Directive<"target enter data"> {
let allowedClauses = [
``````````
</details>
https://github.com/llvm/llvm-project/pull/71560
More information about the flang-commits
mailing list