[flang-commits] [flang] ebf5f37 - [flang][openacc] Make sure the correct flags are set for symbol in acc declare

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Aug 4 13:08:53 PDT 2023


Author: Valentin Clement
Date: 2023-08-04T13:08:47-07:00
New Revision: ebf5f371304f29ef3568b82d10e6551e8b06dc1a

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

LOG: [flang][openacc] Make sure the correct flags are set for symbol in acc declare

Flags were not correctly set for symbols appearing in the OpenACC declare
directive in module declaration part.

Also some missing flags for OpenACC are added. This makes the Flags enum
> 64 and then the implementation switch to std::bitset as defined in
`flang/include/flang/Common/enum-set.h`. Therefore, `constexpr` cannot be
used for set of flags in `flang/lib/Semantics/resolve-directives.cpp`.

Reviewed By: razvanlupusoru

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

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

Modified: 
    flang/include/flang/Semantics/symbol.h
    flang/lib/Semantics/resolve-directives.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 1651e68879b56f..df1d9c2a58b83d 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -594,7 +594,10 @@ class Symbol {
       // OpenACC data-sharing attribute
       AccPrivate, AccFirstPrivate, AccShared,
       // OpenACC data-mapping attribute
-      AccCopy, AccCopyIn, AccCopyOut, AccCreate, AccDelete, AccPresent,
+      AccCopy, AccCopyIn, AccCopyOut, AccCreate, AccDelete, AccPresent, AccLink,
+      AccDeviceResident, AccDevicePtr,
+      // OpenACC declare
+      AccDeclare,
       // OpenACC data-movement attribute
       AccDevice, AccHost, AccSelf,
       // OpenACC miscellaneous flags

diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 25c398ce1e7036..f317b27f7b1eaa 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -195,6 +195,21 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
     return false;
   }
 
+  bool Pre(const parser::AccClause::DeviceResident &x) {
+    ResolveAccObjectList(x.v, Symbol::Flag::AccDeviceResident);
+    return false;
+  }
+
+  bool Pre(const parser::AccClause::Deviceptr &x) {
+    ResolveAccObjectList(x.v, Symbol::Flag::AccDevicePtr);
+    return false;
+  }
+
+  bool Pre(const parser::AccClause::Link &x) {
+    ResolveAccObjectList(x.v, Symbol::Flag::AccLink);
+    return false;
+  }
+
   bool Pre(const parser::AccClause::Host &x) {
     ResolveAccObjectList(x.v, Symbol::Flag::AccHost);
     return false;
@@ -216,23 +231,24 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
 private:
   std::int64_t GetAssociatedLoopLevelFromClauses(const parser::AccClauseList &);
 
-  static constexpr Symbol::Flags dataSharingAttributeFlags{
-      Symbol::Flag::AccShared, Symbol::Flag::AccPrivate,
-      Symbol::Flag::AccPresent, Symbol::Flag::AccFirstPrivate,
+  Symbol::Flags dataSharingAttributeFlags{Symbol::Flag::AccShared,
+      Symbol::Flag::AccPrivate, Symbol::Flag::AccFirstPrivate,
       Symbol::Flag::AccReduction};
 
-  static constexpr Symbol::Flags dataMappingAttributeFlags{
-      Symbol::Flag::AccCreate, Symbol::Flag::AccCopyIn,
-      Symbol::Flag::AccCopyOut, Symbol::Flag::AccDelete};
+  Symbol::Flags dataMappingAttributeFlags{Symbol::Flag::AccCreate,
+      Symbol::Flag::AccCopyIn, Symbol::Flag::AccCopyOut,
+      Symbol::Flag::AccDelete, Symbol::Flag::AccPresent};
 
-  static constexpr Symbol::Flags accFlagsRequireNewSymbol{
-      Symbol::Flag::AccPrivate, Symbol::Flag::AccFirstPrivate,
-      Symbol::Flag::AccReduction};
+  Symbol::Flags accFlagsRequireNewSymbol{Symbol::Flag::AccPrivate,
+      Symbol::Flag::AccFirstPrivate, Symbol::Flag::AccReduction};
 
-  static constexpr Symbol::Flags accDataMvtFlags{
+  Symbol::Flags accDataMvtFlags{
       Symbol::Flag::AccDevice, Symbol::Flag::AccHost, Symbol::Flag::AccSelf};
 
-  static constexpr Symbol::Flags accFlagsRequireMark{};
+  Symbol::Flags accFlagsRequireMark{Symbol::Flag::AccCreate,
+      Symbol::Flag::AccCopyIn, Symbol::Flag::AccCopy, Symbol::Flag::AccCopyOut,
+      Symbol::Flag::AccDevicePtr, Symbol::Flag::AccDeviceResident,
+      Symbol::Flag::AccLink, Symbol::Flag::AccPresent};
 
   void PrivatizeAssociatedLoopIndex(const parser::OpenACCLoopConstruct &);
   void ResolveAccObjectList(const parser::AccObjectList &, Symbol::Flag);
@@ -532,26 +548,24 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
 private:
   std::int64_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &);
 
-  static constexpr Symbol::Flags dataSharingAttributeFlags{
-      Symbol::Flag::OmpShared, Symbol::Flag::OmpPrivate,
-      Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
-      Symbol::Flag::OmpReduction, Symbol::Flag::OmpLinear};
-
-  static constexpr Symbol::Flags privateDataSharingAttributeFlags{
+  Symbol::Flags dataSharingAttributeFlags{Symbol::Flag::OmpShared,
       Symbol::Flag::OmpPrivate, Symbol::Flag::OmpFirstPrivate,
-      Symbol::Flag::OmpLastPrivate};
+      Symbol::Flag::OmpLastPrivate, Symbol::Flag::OmpReduction,
+      Symbol::Flag::OmpLinear};
+
+  Symbol::Flags privateDataSharingAttributeFlags{Symbol::Flag::OmpPrivate,
+      Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate};
 
-  static constexpr Symbol::Flags ompFlagsRequireNewSymbol{
-      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::OmpUseDeviceAddr};
+  Symbol::Flags ompFlagsRequireNewSymbol{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::OmpUseDeviceAddr};
 
-  static constexpr Symbol::Flags ompFlagsRequireMark{
+  Symbol::Flags ompFlagsRequireMark{
       Symbol::Flag::OmpThreadprivate, Symbol::Flag::OmpDeclareTarget};
 
-  static constexpr Symbol::Flags dataCopyingAttributeFlags{
+  Symbol::Flags dataCopyingAttributeFlags{
       Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpCopyPrivate};
 
   std::vector<const parser::Name *> allocateNames_; // on one directive
@@ -1171,7 +1185,10 @@ Symbol *AccAttributeVisitor::DeclareOrMarkOtherAccessEntity(
 Symbol *AccAttributeVisitor::DeclareOrMarkOtherAccessEntity(
     Symbol &object, Symbol::Flag accFlag) {
   if (accFlagsRequireMark.test(accFlag)) {
-    object.set(accFlag);
+    if (GetContext().directive == llvm::acc::ACCD_declare) {
+      object.set(Symbol::Flag::AccDeclare);
+      object.set(accFlag);
+    }
   }
   return &object;
 }

diff  --git a/flang/test/Semantics/OpenACC/acc-symbols02.f90 b/flang/test/Semantics/OpenACC/acc-symbols02.f90
new file mode 100644
index 00000000000000..0627af80b1563f
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-symbols02.f90
@@ -0,0 +1,21 @@
+! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenacc
+
+!DEF:/acc_declare_symbolsModule
+module acc_declare_symbols
+  !DEF: /acc_declare_symbols/a PUBLIC (AccCreate, AccDeclare) ObjectEntity REAL(4)
+  real a(100)
+  !$acc declare create(a)
+
+  !DEF:/acc_declare_symbols/b PUBLIC (AccCopyIn, AccDeclare) ObjectEntity REAL(4)
+  real b(20)
+  !$acc declare copyin(b)
+
+  !DEF:/acc_declare_symbols/c PUBLIC (AccDeviceResident, AccDeclare) ObjectEntity REAL(4)
+  real c(10)
+  !$acc declare device_resident(c)
+
+  !DEF:/acc_declare_symbols/d PUBLIC (AccLink, AccDeclare) ObjectEntity REAL(4)
+  real d(10)
+  !$acc declare link(d)
+
+end module


        


More information about the flang-commits mailing list