[clang] 8c1bd97 - [OpenACC] Expose 'no_create' clause in combined constructs
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 12:03:53 PST 2024
Author: erichkeane
Date: 2024-11-27T12:03:48-08:00
New Revision: 8c1bd9792be1d7d19eebce57be556d5cadeb2d15
URL: https://github.com/llvm/llvm-project/commit/8c1bd9792be1d7d19eebce57be556d5cadeb2d15
DIFF: https://github.com/llvm/llvm-project/commit/8c1bd9792be1d7d19eebce57be556d5cadeb2d15.diff
LOG: [OpenACC] Expose 'no_create' clause in combined constructs
Once again, not much work besides ensuring they are supposed to work the
same.
Added:
clang/test/SemaOpenACC/combined-construct-no_create-ast.cpp
clang/test/SemaOpenACC/combined-construct-no_create-clause.c
clang/test/SemaOpenACC/combined-construct-no_create-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 2b089bb330bb55..80226d0524783f 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -843,10 +843,11 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
OpenACCClause *SemaOpenACCClauseVisitor::VisitNoCreateClause(
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, so there
// really isn't anything to do here. GCC does some duplicate-finding, though
diff --git a/clang/test/AST/ast-print-openacc-combined-construct.cpp b/clang/test/AST/ast-print-openacc-combined-construct.cpp
index bade0dde14d5e3..16f0b3b49a7b74 100644
--- a/clang/test/AST/ast-print-openacc-combined-construct.cpp
+++ b/clang/test/AST/ast-print-openacc-combined-construct.cpp
@@ -162,4 +162,12 @@ void foo() {
#pragma acc serial loop attach(iPtr, arrayPtr[0])
for(int i = 0;i<5;++i);
+// CHECK: #pragma acc parallel loop no_create(i, array[1], array, array[1:2])
+#pragma acc parallel loop no_create(i, array[1], array, array[1:2])
+ for(int i = 0;i<5;++i);
+
+// CHECK: #pragma acc parallel loop no_create(i, array[1], array, array[1:2]) present(i, array[1], array, array[1:2])
+#pragma acc parallel loop no_create(i, array[1], array, array[1:2]) present(i, array[1], array, array[1:2])
+ 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 925f86118a26bf..cbd613b00c6ae9 100644
--- a/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
+++ b/clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c
@@ -102,8 +102,6 @@ void uses() {
// expected-warning at +1{{OpenACC clause 'link' not yet implemented}}
#pragma acc parallel loop auto link(Var)
for(unsigned i = 0; i < 5; ++i);
- // TODOexpected-error at +1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
#pragma acc parallel loop auto no_create(Var)
for(unsigned i = 0; i < 5; ++i);
#pragma acc parallel loop auto present(Var)
@@ -257,8 +255,6 @@ void uses() {
// expected-warning at +1{{OpenACC clause 'link' not yet implemented}}
#pragma acc parallel loop link(Var) auto
for(unsigned i = 0; i < 5; ++i);
- // TODOexpected-error at +1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
#pragma acc parallel loop no_create(Var) auto
for(unsigned i = 0; i < 5; ++i);
#pragma acc parallel loop present(Var) auto
@@ -413,8 +409,6 @@ void uses() {
// expected-warning at +1{{OpenACC clause 'link' not yet implemented}}
#pragma acc parallel loop independent link(Var)
for(unsigned i = 0; i < 5; ++i);
- // TODOexpected-error at +1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
#pragma acc parallel loop independent no_create(Var)
for(unsigned i = 0; i < 5; ++i);
#pragma acc parallel loop independent present(Var)
@@ -568,8 +562,6 @@ void uses() {
// expected-warning at +1{{OpenACC clause 'link' not yet implemented}}
#pragma acc parallel loop link(Var) independent
for(unsigned i = 0; i < 5; ++i);
- // TODOexpected-error at +1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
#pragma acc parallel loop no_create(Var) independent
for(unsigned i = 0; i < 5; ++i);
#pragma acc parallel loop present(Var) independent
@@ -730,8 +722,6 @@ void uses() {
// expected-warning at +1{{OpenACC clause 'link' not yet implemented}}
#pragma acc parallel loop seq link(Var)
for(unsigned i = 0; i < 5; ++i);
- // TODOexpected-error at +1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
#pragma acc parallel loop seq no_create(Var)
for(unsigned i = 0; i < 5; ++i);
#pragma acc parallel loop seq present(Var)
@@ -891,8 +881,6 @@ void uses() {
// expected-warning at +1{{OpenACC clause 'link' not yet implemented}}
#pragma acc parallel loop link(Var) seq
for(unsigned i = 0; i < 5; ++i);
- // TODOexpected-error at +1{{OpenACC 'no_create' clause is not valid on 'parallel loop' directive}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
#pragma acc parallel loop no_create(Var) seq
for(unsigned i = 0; i < 5; ++i);
#pragma acc parallel loop present(Var) seq
diff --git a/clang/test/SemaOpenACC/combined-construct-no_create-ast.cpp b/clang/test/SemaOpenACC/combined-construct-no_create-ast.cpp
new file mode 100644
index 00000000000000..193ec89fb48f1d
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-no_create-ast.cpp
@@ -0,0 +1,85 @@
+// 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
+
+int Global;
+short GlobalArray[5];
+void NormalUses(float *PointerParam) {
+ // CHECK: FunctionDecl{{.*}}NormalUses
+ // CHECK: ParmVarDecl
+ // CHECK-NEXT: CompoundStmt
+
+#pragma acc parallel loop no_create(GlobalArray, PointerParam[Global])
+ for (unsigned i = 0; i < 5; ++i);
+ // CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
+ // CHECK-NEXT: no_create clause
+ // CHECK-NEXT: DeclRefExpr{{.*}}'short[5]' lvalue Var{{.*}}'GlobalArray' 'short[5]'
+ // CHECK-NEXT: ArraySubscriptExpr{{.*}}'float' lvalue
+ // CHECK-NEXT: ImplicitCastExpr{{.*}} 'float *' <LValueToRValue>
+ // CHECK-NEXT: DeclRefExpr{{.*}}'float *' lvalue ParmVar{{.*}}'PointerParam' 'float *'
+ // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue>
+ // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue Var{{.*}}'Global' 'int'
+ // CHECK-NEXT: ForStmt
+ // CHECK: NullStmt
+}
+
+template<auto &NTTP, typename T, typename U>
+void TemplUses(T t, U u) {
+ // CHECK-NEXT: FunctionTemplateDecl
+ // CHECK-NEXT: NonTypeTemplateParmDecl {{.*}}referenced 'auto &' depth 0 index 0 NTTP
+ // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 1 T
+ // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 2 U
+ // CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (T, U)'
+ // CHECK-NEXT: ParmVarDecl{{.*}} referenced t 'T'
+ // CHECK-NEXT: ParmVarDecl{{.*}} referenced u 'U'
+ // CHECK-NEXT: CompoundStmt
+
+
+#pragma acc parallel loop no_create(t) present(NTTP, u)
+ for (unsigned i = 0; i < 5; ++i);
+ // CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
+ // CHECK-NEXT: no_create clause
+ // CHECK-NEXT: DeclRefExpr{{.*}}'T' lvalue ParmVar{{.*}} 't' 'T'
+ // CHECK-NEXT: present clause
+ // CHECK-NEXT: DeclRefExpr{{.*}}'auto' lvalue NonTypeTemplateParm{{.*}} 'NTTP' 'auto &'
+ // CHECK-NEXT: DeclRefExpr{{.*}}'U' lvalue ParmVar{{.*}} 'u' 'U'
+ // CHECK-NEXT: ForStmt
+ // CHECK: NullStmt
+
+ // Check the instantiated versions of the above.
+ // CHECK-NEXT: FunctionDecl{{.*}} used TemplUses 'void (int, int *)' implicit_instantiation
+ // CHECK-NEXT: TemplateArgument decl
+ // CHECK-NEXT: Var{{.*}} 'CEVar' 'const unsigned int'
+ // CHECK-NEXT: TemplateArgument type 'int'
+ // CHECK-NEXT: BuiltinType{{.*}} 'int'
+ // CHECK-NEXT: TemplateArgument type 'int *'
+ // CHECK-NEXT: PointerType{{.*}} 'int *'
+ // CHECK-NEXT: BuiltinType{{.*}} 'int'
+ // CHECK-NEXT: ParmVarDecl{{.*}} used t 'int'
+ // CHECK-NEXT: ParmVarDecl{{.*}} used u 'int *'
+ // CHECK-NEXT: CompoundStmt
+
+// #pragma acc parallel loop no_create(t) present(NTTP, u)
+ // CHECK-NEXT: OpenACCCombinedConstruct{{.*}} parallel loop
+ // CHECK-NEXT: no_create clause
+ // CHECK-NEXT: DeclRefExpr{{.*}}'int' lvalue ParmVar{{.*}} 't' 'int'
+ // CHECK-NEXT: present clause
+ // CHECK-NEXT: SubstNonTypeTemplateParmExpr{{.*}}'const unsigned int' lvalue
+ // CHECK-NEXT: NonTypeTemplateParmDecl{{.*}} referenced 'auto &' depth 0 index 0 NTTP
+ // CHECK-NEXT: DeclRefExpr{{.*}}'const unsigned int' lvalue Var{{.*}} 'CEVar' 'const unsigned int'
+ // CHECK-NEXT: DeclRefExpr{{.*}}'int *' lvalue ParmVar{{.*}} 'u' 'int *'
+ // CHECK-NEXT: ForStmt
+ // CHECK: NullStmt
+}
+
+void Inst() {
+ static constexpr unsigned CEVar = 1;
+ int i;
+ TemplUses<CEVar>(i, &i);
+}
+#endif
diff --git a/clang/test/SemaOpenACC/combined-construct-no_create-clause.c b/clang/test/SemaOpenACC/combined-construct-no_create-clause.c
new file mode 100644
index 00000000000000..b0caab2ab9efdb
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-no_create-clause.c
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+typedef struct IsComplete {
+ struct S { int A; } CompositeMember;
+ int ScalarMember;
+ float ArrayMember[5];
+ void *PointerMember;
+} Complete;
+void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete CompositeParam) {
+ int LocalInt;
+ short *LocalPointer;
+ float LocalArray[5];
+ Complete LocalComposite;
+ // Check Appertainment:
+#pragma acc parallel loop no_create(LocalInt)
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc serial loop no_create(LocalInt)
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc kernels loop no_create(LocalInt)
+ for (unsigned i = 0; i < 5; ++i);
+
+ // Valid cases:
+#pragma acc parallel loop no_create(LocalInt, LocalPointer, LocalArray)
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc parallel loop no_create(LocalArray[2:1])
+ for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop no_create(LocalComposite.ScalarMember, LocalComposite.ScalarMember)
+ 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 no_create(1 + IntParam)
+ 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 no_create(+IntParam)
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
+#pragma acc parallel loop no_create(PointerParam[2:])
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
+#pragma acc parallel loop no_create(ArrayParam[2:5])
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
+ // 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 no_create((float*)ArrayParam[2:5])
+ 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 no_create((float)ArrayParam[2])
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +1{{OpenACC 'no_create' clause is not valid on 'loop' directive}}
+#pragma acc loop no_create(LocalInt)
+ for(int i = 5; i < 10;++i);
+}
diff --git a/clang/test/SemaOpenACC/combined-construct-no_create-clause.cpp b/clang/test/SemaOpenACC/combined-construct-no_create-clause.cpp
new file mode 100644
index 00000000000000..f01c46e4877f77
--- /dev/null
+++ b/clang/test/SemaOpenACC/combined-construct-no_create-clause.cpp
@@ -0,0 +1,112 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+enum SomeE{};
+typedef struct IsComplete {
+ struct S { int A; } CompositeMember;
+ int ScalarMember;
+ float ArrayMember[5];
+ SomeE EnumMember;
+ char *PointerMember;
+} Complete;
+
+void uses(int IntParam, char *PointerParam, float ArrayParam[5], Complete CompositeParam, int &IntParamRef) {
+ int LocalInt;
+ char *LocalPointer;
+ float LocalArray[5];
+ // Check Appertainment:
+#pragma acc parallel loop no_create(LocalInt)
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc serial loop no_create(LocalInt)
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc kernels loop no_create(LocalInt)
+ for (unsigned i = 0; i < 5; ++i);
+
+ // Valid cases:
+#pragma acc parallel loop no_create(LocalInt, LocalPointer, LocalArray)
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc parallel loop no_create(LocalArray[2:1])
+ for (unsigned i = 0; i < 5; ++i);
+
+ Complete LocalComposite2;
+#pragma acc parallel loop no_create(LocalComposite2.ScalarMember, LocalComposite2.ScalarMember)
+ 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 no_create(1 + IntParam)
+ 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 no_create(+IntParam)
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
+#pragma acc parallel loop no_create(PointerParam[2:])
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
+#pragma acc parallel loop no_create(ArrayParam[2:5])
+ for (unsigned i = 0; i < 5; ++i);
+
+ // expected-error at +2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
+ // 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 no_create((float*)ArrayParam[2:5])
+ 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 no_create((float)ArrayParam[2])
+ for (unsigned i = 0; i < 5; ++i);
+}
+
+template<typename T, unsigned I, typename V>
+void TemplUses(T t, T (&arrayT)[I], V TemplComp) {
+ // 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 no_create(+t)
+ for (unsigned i = 0; i < 5; ++i);
+
+ // NTTP's are only valid if it is a reference to something.
+ // expected-error at +2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
+ // expected-note@#TEMPL_USES_INST{{in instantiation of}}
+#pragma acc parallel loop no_create(I)
+ 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 no_create(t, I)
+ for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop no_create(arrayT)
+ for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop no_create(TemplComp)
+ for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop no_create(TemplComp.PointerMember[5])
+ for (unsigned i = 0; i < 5; ++i);
+ int *Pointer;
+#pragma acc parallel loop no_create(Pointer[:I])
+ for (unsigned i = 0; i < 5; ++i);
+#pragma acc parallel loop no_create(Pointer[:t])
+ for (unsigned i = 0; i < 5; ++i);
+ // expected-error at +1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
+#pragma acc parallel loop no_create(Pointer[1:])
+ for (unsigned i = 0; i < 5; ++i);
+}
+
+template<unsigned I, auto &NTTP_REF>
+void NTTP() {
+ // NTTP's are only valid if it is a reference to something.
+ // expected-error at +2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
+ // expected-note@#NTTP_INST{{in instantiation of}}
+#pragma acc parallel loop no_create(I)
+ for (unsigned i = 0; i < 5; ++i);
+
+#pragma acc parallel loop no_create(NTTP_REF)
+ for (unsigned i = 0; i < 5; ++i);
+}
+
+void Inst() {
+ static constexpr int NTTP_REFed = 1;
+ int i;
+ int Arr[5];
+ Complete C;
+ TemplUses(i, Arr, C); // #TEMPL_USES_INST
+ NTTP<5, NTTP_REFed>(); // #NTTP_INST
+}
More information about the cfe-commits
mailing list