[clang] b7f7e64 - [OpenACC] Implement 'default' clause for Combined Constructs

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 14 06:41:16 PST 2024


Author: erichkeane
Date: 2024-11-14T06:41:10-08:00
New Revision: b7f7e6454877846d2ee4be8cae821b2c32501b1e

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

LOG: [OpenACC] Implement 'default' clause for Combined Constructs

This clause takes one of two fixed values, and can apply to all three of
the combined constructs. Tests/etc are all exactly like the compute
constructs, so committing them all here.

Added: 
    clang/test/SemaOpenACC/combined-construct-default-ast.cpp
    clang/test/SemaOpenACC/combined-construct-default-clause.c
    clang/test/SemaOpenACC/combined-construct-default-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
    clang/test/SemaOpenACC/compute-construct-default-clause.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index dd6558d0afed70..70a0a122d82497 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -572,10 +572,12 @@ class SemaOpenACCClauseVisitor {
 
 OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultClause(
     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.
+  // Only 'data' is left.
+  if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
+      !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
     return isNotImplemented();
 
   // Don't add an invalid clause to the AST.

diff  --git a/clang/test/AST/ast-print-openacc-combined-construct.cpp b/clang/test/AST/ast-print-openacc-combined-construct.cpp
index 14b8d0bab40041..f80500e7852192 100644
--- a/clang/test/AST/ast-print-openacc-combined-construct.cpp
+++ b/clang/test/AST/ast-print-openacc-combined-construct.cpp
@@ -86,4 +86,14 @@ void foo() {
 #pragma acc kernels loop if(i == array[1])
   for(int i = 0;i<5;++i);
 
+// CHECK: #pragma acc parallel loop default(none)
+// CHECK-NEXT: for (int i = 0; i < 5; ++i)
+// CHECK-NEXT: ;
+#pragma acc parallel loop default(none)
+  for(int i = 0;i<5;++i);
+// CHECK: #pragma acc serial loop default(present)
+// CHECK-NEXT: for (int i = 0; i < 5; ++i)
+// CHECK-NEXT: ;
+#pragma acc serial loop default(present)
+  for(int i = 0;i<5;++i);
 }

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 8a062b6ac1d5d6..9dd0ed922ffc2c 100644
--- a/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
+++ b/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
@@ -56,8 +56,6 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented}}
 #pragma acc parallel loop auto nohost
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC clause 'default' not yet implemented, clause ignored}}
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
 #pragma acc parallel loop auto default(none)
   for(unsigned i = 0; i < 5; ++i);
 #pragma acc parallel loop auto if(1)
@@ -226,8 +224,6 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented}}
 #pragma acc parallel loop nohost auto
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'default' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
 #pragma acc parallel loop default(none) auto
   for(unsigned i = 0; i < 5; ++i);
 #pragma acc parallel loop if(1) auto
@@ -397,8 +393,6 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented}}
 #pragma acc parallel loop independent nohost
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'default' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
 #pragma acc parallel loop independent default(none)
   for(unsigned i = 0; i < 5; ++i);
 #pragma acc parallel loop independent if(1)
@@ -567,8 +561,6 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented}}
 #pragma acc parallel loop nohost independent
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'default' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
 #pragma acc parallel loop default(none) independent
   for(unsigned i = 0; i < 5; ++i);
 #pragma acc parallel loop if(1) independent
@@ -744,8 +736,6 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented}}
 #pragma acc parallel loop seq nohost
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'default' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
 #pragma acc parallel loop seq default(none)
   for(unsigned i = 0; i < 5; ++i);
 #pragma acc parallel loop seq if(1)
@@ -920,8 +910,6 @@ void uses() {
   // expected-warning at +1{{OpenACC clause 'nohost' not yet implemented}}
 #pragma acc parallel loop nohost seq
   for(unsigned i = 0; i < 5; ++i);
-  // TODOexpected-error at +1{{OpenACC 'default' clause is not valid on 'parallel loop' directive}}
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
 #pragma acc parallel loop default(none) seq
   for(unsigned i = 0; i < 5; ++i);
 #pragma acc parallel loop if(1) seq

diff  --git a/clang/test/SemaOpenACC/combined-construct-default-ast.cpp b/clang/test/SemaOpenACC/combined-construct-default-ast.cpp
new file mode 100644
index 00000000000000..2ff24b32afe7b9
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-default-ast.cpp
@@ -0,0 +1,76 @@
+
+// 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 NormalFunc() {
+  // CHECK-LABEL: NormalFunc
+  // CHECK-NEXT: CompoundStmt
+  // CHECK-NEXT: OpenACCCombinedConstruct {{.*}}parallel loop
+  // CHECK-NEXT: default(none)
+#pragma acc parallel loop default(none)
+  for (unsigned I = 0; I < 5; ++I) {
+#pragma acc kernels loop
+  for (unsigned J = 0; J < 5; ++J) {
+  }
+  // CHECK: OpenACCCombinedConstruct {{.*}}kernels loop
+  // CHECK: OpenACCCombinedConstruct {{.*}}serial loop
+  // CHECK-NEXT: default(present)
+#pragma acc serial loop default(present)
+  for (unsigned J = 0; J < 5; ++J) {
+  }
+  }
+}
+template<typename T>
+void TemplFunc() {
+#pragma acc parallel loop default(none)
+  for (unsigned i = 0; i < 5; ++i) {
+    typename T::type I;
+  }
+
+#pragma acc serial loop default(present)
+  for (unsigned i = 0; i < 5; ++i) {
+    typename T::type I;
+  }
+
+  // CHECK-LABEL: FunctionTemplateDecl {{.*}}TemplFunc
+  // CHECK-NEXT: TemplateTypeParmDecl
+
+  // Template Pattern:
+  // CHECK-NEXT: FunctionDecl
+  // CHECK-NEXT: CompoundStmt
+  // CHECK-NEXT: OpenACCCombinedConstruct {{.*}}parallel loop
+  // CHECK-NEXT: default(none)
+  // CHECK: VarDecl{{.*}} I 'typename T::type'
+
+  // CHECK-NEXT: OpenACCCombinedConstruct {{.*}}serial loop
+  // CHECK-NEXT: default(present)
+  // CHECK: VarDecl{{.*}} I 'typename T::type'
+
+  // Check instantiation.
+  // CHECK-LABEL: FunctionDecl{{.*}} used TemplFunc 'void ()' implicit_instantiation
+  // CHECK-NEXT: TemplateArgument type 'S'
+  // CHECK-NEXT: RecordType
+  // CHECK-NEXT: CXXRecord
+  // CHECK-NEXT: CompoundStmt
+  // CHECK-NEXT: OpenACCCombinedConstruct {{.*}}parallel loop
+  // CHECK-NEXT: default(none)
+  // CHECK: VarDecl{{.*}} I 'typename S::type':'int'
+  // CHECK-NEXT: OpenACCCombinedConstruct {{.*}}serial loop
+  // CHECK-NEXT: default(present)
+  // CHECK: VarDecl{{.*}} I 'typename S::type':'int'
+
+}
+struct S {
+  using type = int;
+};
+
+void use() {
+  TemplFunc<S>();
+}
+
+#endif

diff  --git a/clang/test/SemaOpenACC/combined-construct-default-clause.c b/clang/test/SemaOpenACC/combined-construct-default-clause.c
new file mode 100644
index 00000000000000..058a6066c5eacb
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-default-clause.c
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+void SingleOnly() {
+  #pragma acc parallel loop default(none)
+  for(int i = 5; i < 10;++i);
+
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'serial loop' directive}}
+  // expected-note at +1{{previous clause is here}}
+  #pragma acc serial loop default(present) self default(none)
+  for(int i = 5; i < 10;++i);
+
+  int i;
+
+  // expected-warning at +4{{OpenACC clause 'copy' not yet implemented}}
+  // expected-warning at +3{{OpenACC clause 'present' not yet implemented}}
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'kernels loop' directive}}
+  // expected-note at +1{{previous clause is here}}
+  #pragma acc kernels loop self default(present) present(i) default(none) copy(i)
+  for(int i = 5; i < 10;++i);
+
+  // expected-warning at +4{{OpenACC clause 'private' not yet implemented}}
+  // expected-warning at +3{{OpenACC clause 'copy' not yet implemented}}
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'parallel loop' directive}}
+  // expected-note at +1{{previous clause is here}}
+  #pragma acc parallel loop self default(present) private(i) default(none) copy(i)
+  for(int i = 0; i < 5; ++i);
+
+  // expected-error at +1{{expected '('}}
+  #pragma acc serial loop self default private(i) default(none) if(i)
+  for(int i = 0; i < 5; ++i);
+
+  #pragma acc kernels loop default(none)
+  for(int i = 0; i < 5; ++i);
+
+  // expected-warning at +2{{OpenACC construct 'data' not yet implemented}}
+  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
+  #pragma acc data default(none)
+  while(0);
+
+  // expected-error at +1{{OpenACC 'default' clause is not valid on 'loop' directive}}
+  #pragma acc loop default(none)
+  for(int i = 5; i < 10;++i);
+
+  // expected-warning at +2{{OpenACC construct 'wait' not yet implemented}}
+  // expected-error at +1{{OpenACC 'default' clause is not valid on 'wait' directive}}
+  #pragma acc wait default(none)
+  while(0);
+
+  // expected-error at +1{{OpenACC 'default' clause is not valid on 'loop' directive}}
+#pragma acc loop default(present)
+  for(int i = 5; i < 10;++i);
+}

diff  --git a/clang/test/SemaOpenACC/combined-construct-default-clause.cpp b/clang/test/SemaOpenACC/combined-construct-default-clause.cpp
new file mode 100644
index 00000000000000..a211b11b6d3ffb
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-default-clause.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+template<typename T>
+void SingleOnly() {
+  #pragma acc parallel loop default(none)
+  for (unsigned I = 0; I < 5; ++I);
+
+  int i;
+
+  // expected-warning at +3{{OpenACC clause 'async' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'parallel loop' directive}}
+  // expected-note at +1{{previous clause is here}}
+  #pragma acc parallel loop default(present) async default(none)
+  for (unsigned I = 0; I < 5; ++I);
+
+  // expected-warning at +4{{OpenACC clause 'copy' not yet implemented, clause ignored}}
+  // expected-warning at +3{{OpenACC clause 'async' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'serial loop' directive}}
+  // expected-note at +1{{previous clause is here}}
+  #pragma acc serial loop async default(present) copy(i) default(none) self
+  for (unsigned I = 0; I < 5; ++I);
+
+  // expected-warning at +4{{OpenACC clause 'copy' not yet implemented, clause ignored}}
+  // expected-warning at +3{{OpenACC clause 'async' not yet implemented, clause ignored}}
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'kernels loop' directive}}
+  // expected-note at +1{{previous clause is here}}
+  #pragma acc kernels loop async default(present) copy(i) default(none) self
+  for (unsigned I = 0; I < 5; ++I);
+
+  // expected-warning at +3{{OpenACC clause 'copy' not yet implemented, clause ignored}}
+  // expected-warning at +2{{OpenACC clause 'async' not yet implemented, clause ignored}}
+  // expected-error at +1{{expected '('}}
+  #pragma acc parallel loop async default(none) copy(i) default self
+  for (unsigned I = 0; I < 5; ++I);
+}
+
+void Instantiate() {
+  SingleOnly<int>();
+}

diff  --git a/clang/test/SemaOpenACC/compute-construct-default-clause.c b/clang/test/SemaOpenACC/compute-construct-default-clause.c
index 17f1b27a9b5838..15d6c512d6e654 100644
--- a/clang/test/SemaOpenACC/compute-construct-default-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-default-clause.c
@@ -16,10 +16,10 @@ void SingleOnly() {
   #pragma acc kernels self default(present) present(i) default(none) copy(i)
   while(0);
 
-  // expected-warning at +4{{OpenACC clause 'default' not yet implemented}}
-  // expected-warning at +3{{OpenACC clause 'private' not yet implemented}}
-  // expected-warning at +2{{OpenACC clause 'default' not yet implemented}}
-  // expected-warning at +1{{OpenACC clause 'copy' not yet implemented}}
+  // expected-warning at +4{{OpenACC clause 'private' not yet implemented}}
+  // expected-warning at +3{{OpenACC clause 'copy' not yet implemented}}
+  // expected-error at +2{{OpenACC 'default' clause cannot appear more than once on a 'parallel loop' directive}}
+  // expected-note at +1{{previous clause is here}}
   #pragma acc parallel loop self default(present) private(i) default(none) copy(i)
   for(int i = 0; i < 5; ++i);
 
@@ -27,7 +27,6 @@ void SingleOnly() {
   #pragma acc serial loop self default private(i) default(none) if(i)
   for(int i = 0; i < 5; ++i);
 
-  // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
   #pragma acc kernels loop default(none)
   for(int i = 0; i < 5; ++i);
 


        


More information about the cfe-commits mailing list