[flang-commits] [flang] f85a845 - [OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_ADDR clause on OMP TARGET DATA directive.

Raghu Maddhipatla via flang-commits flang-commits at lists.llvm.org
Wed May 10 17:17:53 PDT 2023


Author: Raghu Maddhipatla
Date: 2023-05-10T19:17:47-05:00
New Revision: f85a8456f114d071fb5985ef2c4cd922ba8f29cf

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

LOG: [OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_ADDR clause on OMP TARGET DATA directive.

Reviewed By: kiranchandramohan

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

Added: 
    flang/test/Semantics/OpenMP/use_device_addr.f90

Modified: 
    flang/docs/OpenMP-semantics.md
    flang/include/flang/Semantics/symbol.h
    flang/lib/Parser/openmp-parsers.cpp
    flang/lib/Semantics/check-omp-structure.cpp
    flang/lib/Semantics/resolve-directives.cpp
    llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 
    


################################################################################
diff  --git a/flang/docs/OpenMP-semantics.md b/flang/docs/OpenMP-semantics.md
index 579c40692ba4b..6f42b44726e93 100644
--- a/flang/docs/OpenMP-semantics.md
+++ b/flang/docs/OpenMP-semantics.md
@@ -418,6 +418,16 @@ More details are listed in the following table:
    <td>OmpUseDevicePtr
    </td>
   </tr>
+  <tr>
+   <td>use_device_addr
+   </td>
+   <td>Yes
+   </td>
+   <td>New Symbol
+   </td>
+   <td>OmpUseDeviceAddr
+   </td>
+  </tr>
 </table>
 
 To determine the right data-sharing attribute,
@@ -535,6 +545,11 @@ 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.
+If a list item that appears in a use_device_addr clause has corresponding
+storage in the device data environment, references to the list item in the
+associated structured block are converted into references to the corresponding
+list item so following the same i.e. represent them with a new Symbol and
+`OmpUseDeviceAddr` flag.
 
 The basic steps to determine the data-mapping attribute are:
 

diff  --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 41a03a2b6a949..3e029c98fc2e1 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -560,7 +560,7 @@ class Symbol {
       OmpShared, OmpPrivate, OmpLinear, OmpFirstPrivate, OmpLastPrivate,
       // OpenMP data-mapping attribute
       OmpMapTo, OmpMapFrom, OmpMapAlloc, OmpMapRelease, OmpMapDelete,
-      OmpUseDevicePtr,
+      OmpUseDevicePtr, OmpUseDeviceAddr,
       // 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
index 13ebb7f7efdc2..6a5815236768c 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -336,6 +336,9 @@ TYPE_PARSER(
                 parenthesized(Parser<OmpObjectList>{}))) ||
     "USE_DEVICE_PTR" >> construct<OmpClause>(construct<OmpClause::UseDevicePtr>(
                             parenthesized(Parser<OmpObjectList>{}))) ||
+    "USE_DEVICE_ADDR" >>
+        construct<OmpClause>(construct<OmpClause::UseDeviceAddr>(
+            parenthesized(Parser<OmpObjectList>{}))) ||
     "UNIFIED_ADDRESS" >>
         construct<OmpClause>(construct<OmpClause::UnifiedAddress>()) ||
     "UNIFIED_SHARED_MEMORY" >>

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index cd30441d5ad1e..eb8de20a6b8ba 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -2806,12 +2806,12 @@ const parser::OmpObjectList *OmpStructureChecker::GetOmpObjectList(
     const parser::OmpClause &clause) {
 
   // Clauses with OmpObjectList as its data member
-  using MemberObjectListClauses =
-      std::tuple<parser::OmpClause::Copyprivate, parser::OmpClause::Copyin,
-          parser::OmpClause::Firstprivate, parser::OmpClause::From,
-          parser::OmpClause::Lastprivate, parser::OmpClause::Link,
-          parser::OmpClause::Private, parser::OmpClause::Shared,
-          parser::OmpClause::To, parser::OmpClause::UseDevicePtr>;
+  using MemberObjectListClauses = std::tuple<parser::OmpClause::Copyprivate,
+      parser::OmpClause::Copyin, parser::OmpClause::Firstprivate,
+      parser::OmpClause::From, parser::OmpClause::Lastprivate,
+      parser::OmpClause::Link, parser::OmpClause::Private,
+      parser::OmpClause::Shared, parser::OmpClause::To,
+      parser::OmpClause::UseDevicePtr, parser::OmpClause::UseDeviceAddr>;
 
   // Clauses with OmpObjectList in the tuple
   using TupleObjectListClauses = std::tuple<parser::OmpClause::Allocate,

diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 1052c459632e6..c6cef99042a11 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -441,6 +441,11 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
     return false;
   }
 
+  bool Pre(const parser::OmpClause::UseDeviceAddr &x) {
+    ResolveOmpObjectList(x.v, Symbol::Flag::OmpUseDeviceAddr);
+    return false;
+  }
+
   void Post(const parser::Name &);
 
   // Keep track of labels in the statements that causes jumps to target labels
@@ -511,7 +516,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
       Symbol::Flag::OmpPrivate, Symbol::Flag::OmpLinear,
       Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
       Symbol::Flag::OmpReduction, Symbol::Flag::OmpCriticalLock,
-      Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpUseDevicePtr};
+      Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpUseDevicePtr,
+      Symbol::Flag::OmpUseDeviceAddr};
 
   static constexpr Symbol::Flags ompFlagsRequireMark{
       Symbol::Flag::OmpThreadprivate};

diff  --git a/flang/test/Semantics/OpenMP/use_device_addr.f90 b/flang/test/Semantics/OpenMP/use_device_addr.f90
new file mode 100644
index 0000000000000..67b274929647c
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/use_device_addr.f90
@@ -0,0 +1,17 @@
+! RUN: %flang -fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
+! OpenMP Version 5.1
+! 2.14.2 use_device_addr clause
+! List item that appears in a use_device_addr clause has corresponding storage
+! in the device data environment, references to the list item in the associated
+! structured block are converted into references to the corresponding list item.
+
+subroutine omp_target_data
+   integer :: a(1024)
+   !CHECK: b, TARGET size=4096 offset=4096: ObjectEntity type: INTEGER(4) shape: 1_8:1024_8
+   integer, target :: b(1024)
+   a = 1
+   !$omp target data map(tofrom: a) use_device_addr(b)
+   !CHECK: b (OmpUseDeviceAddr): HostAssoc
+      b = a
+   !$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
index 6e94302fab31c..0f8a9d58acc43 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -395,6 +395,7 @@ def OMPC_Affinity : Clause<"affinity"> {
 }
 def OMPC_UseDeviceAddr : Clause<"use_device_addr"> {
   let clangClass = "OMPUseDeviceAddrClause";
+  let flangClass = "OmpObjectList";
 }
 def OMPC_Uniform : Clause<"uniform"> {
   let flangClass = "Name";


        


More information about the flang-commits mailing list