diff --git a/flang/docs/OpenMP-semantics.md b/flang/docs/OpenMP-semantics.md --- a/flang/docs/OpenMP-semantics.md +++ b/flang/docs/OpenMP-semantics.md @@ -318,6 +318,7 @@ For the following OpenMP regions: * `target` regions +* `target data` regions * `teams` regions * `parallel` regions * `simd` regions @@ -407,6 +408,16 @@ OmpLastPrivate + + use_device_ptr + + Yes + + New Symbol + + OmpUseDevicePtr + + To determine the right data-sharing attribute, @@ -519,6 +530,12 @@ of the variable. No `Symbol` or `Scope` will be created. +However, there are some exceptions for this, Pointers that appear in a +use_device_ptr clause are privatized and the device pointers to the +corresponding list items in the device data environment are assigned into the +private versions so it is best to follow the representation for privatised +variables i.e represent them with a new Symbol and `OmpUseDevicePtr` flag. + The basic steps to determine the data-mapping attribute are: 1. If _map_ clause is present, diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -560,6 +560,7 @@ OmpShared, OmpPrivate, OmpLinear, OmpFirstPrivate, OmpLastPrivate, // OpenMP data-mapping attribute OmpMapTo, OmpMapFrom, OmpMapAlloc, OmpMapRelease, OmpMapDelete, + OmpUseDevicePtr, // OpenMP data-copying attribute OmpCopyIn, OmpCopyPrivate, // OpenMP miscellaneous flags diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -309,7 +309,7 @@ "TO" >> construct(construct( parenthesized(Parser{}))) || "USE_DEVICE_PTR" >> construct(construct( - parenthesized(nonemptyList(name)))) || + parenthesized(Parser{}))) || "UNIFIED_ADDRESS" >> construct(construct()) || "UNIFIED_SHARED_MEMORY" >> diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp --- a/flang/lib/Semantics/check-omp-structure.cpp +++ b/flang/lib/Semantics/check-omp-structure.cpp @@ -2766,11 +2766,12 @@ const parser::OmpClause &clause) { // Clauses with OmpObjectList as its data member - using MemberObjectListClauses = std::tuple; + using MemberObjectListClauses = + std::tuple; // Clauses with OmpObjectList in the tuple using TupleObjectListClauses = std::tuple(x.t)}; const auto &beginDir{std::get(beginBlockDir.t)}; switch (beginDir.v) { - case llvm::omp::Directive::OMPD_target_data: case llvm::omp::Directive::OMPD_master: case llvm::omp::Directive::OMPD_ordered: case llvm::omp::Directive::OMPD_taskgroup: diff --git a/flang/test/Semantics/OpenMP/use_device_ptr.f90 b/flang/test/Semantics/OpenMP/use_device_ptr.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/OpenMP/use_device_ptr.f90 @@ -0,0 +1,21 @@ +! RUN: %flang -fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s +! OpenMP Version 5.0 +! 2.10.1 use_device_ptr clause +! List items that appear in a use_device_ptr clause are converted into device +! pointers to the corresponding list item in the device data environment. + +subroutine omp_target_data + use iso_c_binding + integer :: a(1024) + !CHECK: b size=8 offset=4096: ObjectEntity type: TYPE(c_ptr) + type(C_PTR) :: b + integer, pointer :: arrayB + a = 1 + !$omp target data map(tofrom: a, arrayB) use_device_ptr(b) + !CHECK: b (OmpUseDevicePtr) + allocate(arrayB) + call c_f_pointer(b, arrayB) + a = arrayB + !$omp end target data +end subroutine omp_target_data + diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -295,8 +295,7 @@ } def OMPC_UseDevicePtr : Clause<"use_device_ptr"> { let clangClass = "OMPUseDevicePtrClause"; - let flangClass = "Name"; - let isValueList = true; + let flangClass = "OmpObjectList"; } def OMPC_IsDevicePtr : Clause<"is_device_ptr"> { let clangClass = "OMPIsDevicePtrClause";