[flang-commits] [flang] eeba037 - [flang][openacc] Resolve symbol in device, host and self clause

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Jun 28 09:08:47 PDT 2023


Author: Valentin Clement
Date: 2023-06-28T09:08:42-07:00
New Revision: eeba037e0bb6bf0686eca73f4b4cf5eaf573499b

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

LOG: [flang][openacc] Resolve symbol in device, host and self clause

Some symbols were not resolved in the device, host and self clause
resulting in an `Internal: no symbol found` error.

This patch adds symbol resolution for these clauses.

Reviewed By: razvanlupusoru

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

Added: 
    flang/test/Semantics/OpenACC/acc-resolve04.f90

Modified: 
    flang/include/flang/Semantics/symbol.h
    flang/lib/Semantics/resolve-directives.cpp
    flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90
    flang/test/Semantics/OpenACC/acc-update-validity.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 379f3f21826c02..2fb45942baf6ff 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -595,6 +595,8 @@ class Symbol {
       AccPrivate, AccFirstPrivate, AccShared,
       // OpenACC data-mapping attribute
       AccCopyIn, AccCopyOut, AccCreate, AccDelete, AccPresent,
+      // OpenACC data-movement attribute
+      AccDevice, AccHost, AccSelf,
       // OpenACC miscellaneous flags
       AccCommonBlock, AccThreadPrivate, AccReduction, AccNone, AccPreDetermined,
       // OpenMP data-sharing attribute

diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 64ebb6c98df9a3..169e7099aae9b9 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -192,6 +192,27 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
     return false;
   }
 
+  bool Pre(const parser::AccClause::Device &x) {
+    ResolveAccObjectList(x.v, Symbol::Flag::AccDevice);
+    return false;
+  }
+
+  bool Pre(const parser::AccClause::Host &x) {
+    ResolveAccObjectList(x.v, Symbol::Flag::AccHost);
+    return false;
+  }
+
+  bool Pre(const parser::AccClause::Self &x) {
+    const std::optional<parser::AccSelfClause> &accSelfClause = x.v;
+    if (accSelfClause &&
+        std::holds_alternative<parser::AccObjectList>((*accSelfClause).u)) {
+      const auto &accObjectList =
+          std::get<parser::AccObjectList>((*accSelfClause).u);
+      ResolveAccObjectList(accObjectList, Symbol::Flag::AccSelf);
+    }
+    return false;
+  }
+
   void Post(const parser::Name &);
 
 private:
@@ -210,6 +231,9 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
       Symbol::Flag::AccPrivate, Symbol::Flag::AccFirstPrivate,
       Symbol::Flag::AccReduction};
 
+  static constexpr Symbol::Flags accDataMvtFlags{
+      Symbol::Flag::AccDevice, Symbol::Flag::AccHost, Symbol::Flag::AccSelf};
+
   static constexpr Symbol::Flags accFlagsRequireMark{};
 
   void PrivatizeAssociatedLoopIndex(const parser::OpenACCLoopConstruct &);

diff  --git a/flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90 b/flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90
index 9f231851c44109..b0be7d31e4426d 100644
--- a/flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90
@@ -45,7 +45,7 @@ program openacc_parallel_loop_validity
   end do
 
   !ERROR: SELF clause on the PARALLEL LOOP directive only accepts optional scalar logical expression
-  !$acc parallel loop self(bb, cc(:))
+  !$acc parallel loop self(bb, cc(:,:))
   do i = 1, N
     a(i) = 3.14
   end do

diff  --git a/flang/test/Semantics/OpenACC/acc-resolve04.f90 b/flang/test/Semantics/OpenACC/acc-resolve04.f90
new file mode 100644
index 00000000000000..d02b19e3bede6d
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-resolve04.f90
@@ -0,0 +1,16 @@
+! RUN: %flang_fc1 -fopenacc %s
+
+! Check that symbol are correctly resolved in device, host and self clause.
+
+program test_resolve04
+  real :: a(10), b(10)
+  common /foo/ b, c
+
+!$acc data create(/foo/)
+!$acc update device(/foo/)
+!$acc update host(/foo/)
+!$acc update self(/foo/)
+!$acc end data
+
+end
+

diff  --git a/flang/test/Semantics/OpenACC/acc-update-validity.f90 b/flang/test/Semantics/OpenACC/acc-update-validity.f90
index 6563ef9e0912ab..a409ba5ea549f8 100644
--- a/flang/test/Semantics/OpenACC/acc-update-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-update-validity.f90
@@ -38,7 +38,7 @@ program openacc_update_validity
   !ERROR: At most one ASYNC clause can appear on the UPDATE directive
   !$acc update host(aa, bb) async(1) async(2)
 
-  !$acc update self(bb, cc(:)) wait(1)
+  !$acc update self(bb, cc(:,:)) wait(1)
 
   !ERROR: SELF clause on the UPDATE directive must have a var-list
   !$acc update self


        


More information about the flang-commits mailing list