[clang] bbbaeb5 - [OpenACC] Enable 'attach' clause for combined constructs

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 09:55:26 PST 2024


Author: erichkeane
Date: 2024-11-27T09:55:19-08:00
New Revision: bbbaeb5584b5f1ab38cc86a9e8ed64ec1dc926b6

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

LOG: [OpenACC] Enable 'attach' clause for combined constructs

Once again, this clause has the same implementation for compute
constructs as combined, so this adds the tests and enables it.

Added: 
    clang/test/SemaOpenACC/combined-construct-attach-ast.cpp
    clang/test/SemaOpenACC/combined-construct-attach-clause.c
    clang/test/SemaOpenACC/combined-construct-attach-clause.cpp

Modified: 
    clang/lib/Sema/SemaOpenACC.cpp
    clang/test/AST/ast-print-openacc-combined-construct.cpp
    clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 00514f4cf5b4ee..2b089bb330bb55 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -940,10 +940,11 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitCreateClause(
 
 OpenACCClause *SemaOpenACCClauseVisitor::VisitAttachClause(
     SemaOpenACC::OpenACCParsedClause &Clause) {
-  // Restrictions only properly implemented on 'compute' constructs, and
-  // 'compute' constructs are the only construct that can do anything with
-  // this yet, so skip/treat as unimplemented in this case.
-  if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()))
+  // Restrictions only properly implemented on 'compute'/'combined' constructs,
+  // and 'compute'/'combined' constructs are the only construct that can do
+  // anything with this yet, so skip/treat as unimplemented in this case.
+  if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
+      !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
     return isNotImplemented();
 
   // ActOnVar ensured that everything is a valid variable reference, but we

diff  --git a/clang/test/AST/ast-print-openacc-combined-construct.cpp b/clang/test/AST/ast-print-openacc-combined-construct.cpp
index 42c0d248c79fff..bade0dde14d5e3 100644
--- a/clang/test/AST/ast-print-openacc-combined-construct.cpp
+++ b/clang/test/AST/ast-print-openacc-combined-construct.cpp
@@ -158,4 +158,8 @@ void foo() {
 #pragma acc parallel loop wait(devnum:i:queues:*iPtr, i)
   for(int i = 0;i<5;++i);
 
+  // CHECK: #pragma acc serial loop attach(iPtr, arrayPtr[0])
+#pragma acc serial loop attach(iPtr, arrayPtr[0])
+  for(int i = 0;i<5;++i);
+
 }

diff  --git a/clang/test/SemaOpenACC/combined-construct-attach-ast.cpp b/clang/test/SemaOpenACC/combined-construct-attach-ast.cpp
new file mode 100644
index 00000000000000..c0b8d1b2eab522
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-attach-ast.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 %s -fopenacc -ast-dump | FileCheck %s
+
+// Test this with PCH.
+// RUN: %clang_cc1 %s -fopenacc -emit-pch -o %t %s
+// RUN: %clang_cc1 %s -fopenacc -include-pch %t -ast-dump-all | FileCheck %s
+
+#ifndef PCH_HELPER
+#define PCH_HELPER
+
+void NormalUses(float *PointerParam) {
+  // CHECK: FunctionDecl{{.*}}NormalUses
+  // CHECK: ParmVarDecl
+  // CHECK-NEXT: CompoundStmt
+
+#pragma acc parallel loop attach(PointerParam) deviceptr(PointerParam)
+  for (unsigned i = 0; i < 5; ++i);
+  // CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
+  // CHECK-NEXT: attach clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}} 'PointerParam' 'float *'
+  // CHECK-NEXT: deviceptr clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}} 'PointerParam' 'float *'
+  // CHECK-NEXT: ForStmt
+  // CHECK: NullStmt
+}
+
+template<typename T>
+void TemplUses(T *PointerParam) {
+  // CHECK-NEXT: FunctionTemplateDecl
+  // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 0 T
+  // CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T *)'
+  // CHECK-NEXT: ParmVarDecl{{.*}} referenced PointerParam 'T *'
+  // CHECK-NEXT: CompoundStmt
+
+#pragma acc parallel loop attach(PointerParam) deviceptr(PointerParam)
+  for (unsigned i = 0; i < 5; ++i);
+  // CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
+  // CHECK-NEXT: attach clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'T *' lvalue ParmVar{{.*}} 'PointerParam' 'T *'
+  // CHECK-NEXT: deviceptr clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'T *' lvalue ParmVar{{.*}} 'PointerParam' 'T *'
+  // CHECK-NEXT: ForStmt
+  // CHECK: NullStmt
+
+  // Check the instantiated versions of the above.
+  // CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int *)' implicit_instantiation
+  // CHECK-NEXT: TemplateArgument type 'int'
+  // CHECK-NEXT: BuiltinType{{.*}} 'int'
+  // CHECK-NEXT: ParmVarDecl{{.*}} used PointerParam 'int *'
+  // CHECK-NEXT: CompoundStmt
+
+//#pragma acc parallel loop attach(PointerParam) deviceptr(PointerParam)
+  // CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
+  // CHECK-NEXT: attach clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'PointerParam' 'int *'
+  // CHECK-NEXT: deviceptr clause
+  // CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'PointerParam' 'int *'
+  // CHECK-NEXT: ForStmt
+  // CHECK: NullStmt
+
+}
+
+void Inst() {
+  int i;
+  TemplUses(&i);
+}
+#endif

diff  --git a/clang/test/SemaOpenACC/combined-construct-attach-clause.c b/clang/test/SemaOpenACC/combined-construct-attach-clause.c
new file mode 100644
index 00000000000000..49a64a48196ba0
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-attach-clause.c
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+struct S {
+  int IntMem;
+  int *PtrMem;
+};
+
+void uses() {
+  int LocalInt;
+  int *LocalPtr;
+  int Array[5];
+  int *PtrArray[5];
+  struct S s;
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(LocalInt)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
+#pragma acc parallel loop attach(&LocalInt)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc serial loop attach(LocalPtr)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int[5]'}}
+#pragma acc kernels loop attach(Array)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(Array[0])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +2{{OpenACC sub-array is not allowed here}}
+  // expected-note at +1{{expected variable of pointer type}}
+#pragma acc parallel loop attach(Array[0:1])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int *[5]'}}
+#pragma acc parallel loop attach(PtrArray)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(PtrArray[0])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +2{{OpenACC sub-array is not allowed here}}
+  // expected-note at +1{{expected variable of pointer type}}
+#pragma acc parallel loop attach(PtrArray[0:1])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'struct S'}}
+#pragma acc parallel loop attach(s)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(s.IntMem)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(s.PtrMem)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{OpenACC 'attach' clause is not valid on 'loop' directive}}
+#pragma acc loop attach(LocalInt)
+  for(int i = 5; i < 10;++i);
+}

diff  --git a/clang/test/SemaOpenACC/combined-construct-attach-clause.cpp b/clang/test/SemaOpenACC/combined-construct-attach-clause.cpp
new file mode 100644
index 00000000000000..dfbd01f72eeee0
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-attach-clause.cpp
@@ -0,0 +1,120 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+struct S {
+  int IntMem;
+  int *PtrMem;
+  operator int*();
+};
+
+void uses() {
+  int LocalInt;
+  int *LocalPtr;
+  int Array[5];
+  int *PtrArray[5];
+  struct S s;
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(LocalInt)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(LocalPtr)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int[5]'}}
+#pragma acc parallel loop attach(Array)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(Array[0])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +2{{OpenACC sub-array is not allowed here}}
+  // expected-note at +1{{expected variable of pointer type}}
+#pragma acc parallel loop attach(Array[0:1])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int *[5]'}}
+#pragma acc parallel loop attach(PtrArray)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(PtrArray[0])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +2{{OpenACC sub-array is not allowed here}}
+  // expected-note at +1{{expected variable of pointer type}}
+#pragma acc parallel loop attach(PtrArray[0:1])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'struct S'}}
+#pragma acc parallel loop attach(s)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(s.IntMem)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(s.PtrMem)
+  for (unsigned i = 0; i < 5; ++i);
+}
+
+template<typename T, typename TPtr, typename TStruct, auto &R1>
+void Templ() {
+  T SomeInt;
+  TPtr SomePtr;
+  T SomeIntArray[5];
+  TPtr SomeIntPtrArray[5];
+  TStruct SomeStruct;
+
+  // expected-error at +2{{expected pointer in 'attach' clause, type is 'int'}}
+  // expected-note@#INST{{in instantiation of function template specialization}}
+#pragma acc parallel loop attach(SomeInt)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(SomePtr)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int[5]'}}
+#pragma acc parallel loop attach(SomeIntArray)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(SomeIntArray[0])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +2{{OpenACC sub-array is not allowed here}}
+  // expected-note at +1{{expected variable of pointer type}}
+#pragma acc parallel loop attach(SomeIntArray[0:1])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int *[5]'}}
+#pragma acc parallel loop attach(SomeIntPtrArray)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(SomeIntPtrArray[0])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +2{{OpenACC sub-array is not allowed here}}
+  // expected-note at +1{{expected variable of pointer type}}
+#pragma acc parallel loop attach(SomeIntPtrArray[0:1])
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'S'}}
+#pragma acc parallel loop attach(SomeStruct)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(SomeStruct.IntMem)
+  for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop attach(SomeStruct.PtrMem)
+  for (unsigned i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected pointer in 'attach' clause, type is 'int'}}
+#pragma acc parallel loop attach(R1)
+  for (unsigned i = 0; i < 5; ++i);
+}
+
+void inst() {
+  static constexpr int CEVar = 1;
+  Templ<int, int*, S, CEVar>(); // #INST
+}

diff  --git a/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c b/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
index e338177cf93afc..925f86118a26bf 100644
--- a/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
+++ b/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
@@ -1,4 +1,3 @@
-
 // RUN: %clang_cc1 %s -fopenacc -verify
 
 // TODO: OpenACC: A number of the 'not yet implemented' diagnostics interfere
@@ -79,9 +78,7 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented}}
 #pragma acc parallel loop auto use_device(Var)
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'attach' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
-#pragma acc parallel loop auto attach(Var)
+#pragma acc parallel loop auto attach(VarPtr)
   for(unsigned i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'delete' not yet implemented}}
 #pragma acc parallel loop auto delete(Var)
@@ -236,9 +233,7 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented}}
 #pragma acc parallel loop use_device(Var) auto
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'attach' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
-#pragma acc parallel loop attach(Var) auto
+#pragma acc parallel loop attach(VarPtr) auto
   for(unsigned i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'delete' not yet implemented}}
 #pragma acc parallel loop delete(Var) auto
@@ -394,9 +389,7 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented}}
 #pragma acc parallel loop independent use_device(Var)
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'attach' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
-#pragma acc parallel loop independent attach(Var)
+#pragma acc parallel loop independent attach(VarPtr)
   for(unsigned i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'delete' not yet implemented}}
 #pragma acc parallel loop independent delete(Var)
@@ -551,9 +544,7 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented}}
 #pragma acc parallel loop use_device(Var) independent
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'attach' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
-#pragma acc parallel loop attach(Var) independent
+#pragma acc parallel loop attach(VarPtr) independent
   for(unsigned i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'delete' not yet implemented}}
 #pragma acc parallel loop delete(Var) independent
@@ -715,9 +706,7 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented}}
 #pragma acc parallel loop seq use_device(Var)
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'attach' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
-#pragma acc parallel loop seq attach(Var)
+#pragma acc parallel loop seq attach(VarPtr)
   for(unsigned i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'delete' not yet implemented}}
 #pragma acc parallel loop seq delete(Var)
@@ -878,9 +867,7 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'use_device' not yet implemented}}
 #pragma acc parallel loop use_device(Var) seq
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'attach' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
-#pragma acc parallel loop attach(Var) seq
+#pragma acc parallel loop attach(VarPtr) seq
   for(unsigned i = 0; i < 5; ++i);
   // expected-warning at +1{{OpenACC clause 'delete' not yet implemented}}
 #pragma acc parallel loop delete(Var) seq


        


More information about the cfe-commits mailing list