Skip to content

Commit 1cd981a

Browse files
committed
[OpenACC] Implement private/firstprivate for combined constructs
This is another pair of clauses where the work is already done from previous constructs, so this just has to allow them and include tests for them. This patch adds testing, does a few little cleanup bits on the clause checking, and enables these.
1 parent 2e9f869 commit 1cd981a

10 files changed

+688
-34
lines changed

clang/lib/Sema/SemaOpenACC.cpp

+7-14
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultClause(
598598

599599
OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
600600
SemaOpenACC::OpenACCParsedClause &Clause) {
601+
// TODO OpenACC: Remove this when we get combined construct impl for this.
601602
if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
602603
return isNotImplemented();
603604

@@ -699,6 +700,8 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitNumGangsClause(
699700
// Restrictions only properly implemented on 'compute' constructs, and
700701
// 'compute' constructs are the only construct that can do anything with
701702
// this yet, so skip/treat as unimplemented in this case.
703+
// TODO OpenACC: Remove this check when we have combined constructs for this
704+
// clause.
702705
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()))
703706
return isNotImplemented();
704707

@@ -754,6 +757,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitNumWorkersClause(
754757
// Restrictions only properly implemented on 'compute' constructs, and
755758
// 'compute' constructs are the only construct that can do anything with
756759
// this yet, so skip/treat as unimplemented in this case.
760+
// TODO: OpenACC: Remove when we get combined constructs.
757761
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()))
758762
return isNotImplemented();
759763

@@ -775,6 +779,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
775779
// Restrictions only properly implemented on 'compute' constructs, and
776780
// 'compute' constructs are the only construct that can do anything with
777781
// this yet, so skip/treat as unimplemented in this case.
782+
// TODO: OpenACC: Remove when we get combined constructs.
778783
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()))
779784
return isNotImplemented();
780785

@@ -815,14 +820,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitAsyncClause(
815820

816821
OpenACCClause *SemaOpenACCClauseVisitor::VisitPrivateClause(
817822
SemaOpenACC::OpenACCParsedClause &Clause) {
818-
// Restrictions only properly implemented on 'compute' and 'loop'
819-
// constructs, and 'compute'/'loop' constructs are the only construct that
820-
// can do anything with this yet, so skip/treat as unimplemented in this
821-
// case.
822-
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
823-
Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
824-
return isNotImplemented();
825-
826823
// ActOnVar ensured that everything is a valid variable reference, so there
827824
// really isn't anything to do here. GCC does some duplicate-finding, though
828825
// it isn't apparent in the standard where this is justified.
@@ -834,12 +831,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitPrivateClause(
834831

835832
OpenACCClause *SemaOpenACCClauseVisitor::VisitFirstPrivateClause(
836833
SemaOpenACC::OpenACCParsedClause &Clause) {
837-
// Restrictions only properly implemented on 'compute' constructs, and
838-
// 'compute' constructs are the only construct that can do anything with
839-
// this yet, so skip/treat as unimplemented in this case.
840-
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()))
841-
return isNotImplemented();
842-
843834
// ActOnVar ensured that everything is a valid variable reference, so there
844835
// really isn't anything to do here. GCC does some duplicate-finding, though
845836
// it isn't apparent in the standard where this is justified.
@@ -1412,6 +1403,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
14121403
// Restrictions only properly implemented on 'compute' constructs, and
14131404
// 'compute' constructs are the only construct that can do anything with
14141405
// this yet, so skip/treat as unimplemented in this case.
1406+
// TODO: OpenACC: Remove check once we get combined constructs for this clause.
14151407
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
14161408
Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
14171409
return isNotImplemented();
@@ -1502,6 +1494,7 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitReductionClause(
15021494

15031495
OpenACCClause *SemaOpenACCClauseVisitor::VisitCollapseClause(
15041496
SemaOpenACC::OpenACCParsedClause &Clause) {
1497+
// TODO: Remove this check once we implement this for combined constructs.
15051498
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
15061499
Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
15071500
return isNotImplemented();

clang/test/AST/ast-print-openacc-combined-construct.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,13 @@ void foo() {
9696
// CHECK-NEXT: ;
9797
#pragma acc serial loop default(present)
9898
for(int i = 0;i<5;++i);
99+
100+
// CHECK: #pragma acc parallel loop private(i, array[1], array, array[1:2])
101+
#pragma acc parallel loop private(i, array[1], array, array[1:2])
102+
for(int i = 0;i<5;++i);
103+
104+
// CHECK: #pragma acc serial loop firstprivate(i, array[1], array, array[1:2])
105+
#pragma acc serial loop firstprivate(i, array[1], array, array[1:2])
106+
for(int i = 0;i<5;++i);
107+
99108
}

clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c

-18
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ void uses() {
9999
// expected-warning@+1{{OpenACC clause 'device_resident' not yet implemented}}
100100
#pragma acc parallel loop auto device_resident(VarPtr)
101101
for(unsigned i = 0; i < 5; ++i);
102-
// TODOexpected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'parallel loop' directive}}
103-
// expected-warning@+1{{OpenACC clause 'firstprivate' not yet implemented}}
104102
#pragma acc parallel loop auto firstprivate(Var)
105103
for(unsigned i = 0; i < 5; ++i);
106104
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
@@ -117,7 +115,6 @@ void uses() {
117115
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
118116
#pragma acc parallel loop auto present(Var)
119117
for(unsigned i = 0; i < 5; ++i);
120-
// expected-warning@+1{{OpenACC clause 'private' not yet implemented}}
121118
#pragma acc parallel loop auto private(Var)
122119
for(unsigned i = 0; i < 5; ++i);
123120
// TODOexpected-error@+1{{OpenACC 'copyout' clause is not valid on 'parallel loop' directive}}
@@ -267,8 +264,6 @@ void uses() {
267264
// expected-warning@+1{{OpenACC clause 'device_resident' not yet implemented}}
268265
#pragma acc parallel loop device_resident(VarPtr) auto
269266
for(unsigned i = 0; i < 5; ++i);
270-
// TODOexpected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'parallel loop' directive}}
271-
// expected-warning@+1{{OpenACC clause 'firstprivate' not yet implemented}}
272267
#pragma acc parallel loop firstprivate(Var) auto
273268
for(unsigned i = 0; i < 5; ++i);
274269
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
@@ -285,7 +280,6 @@ void uses() {
285280
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
286281
#pragma acc parallel loop present(Var) auto
287282
for(unsigned i = 0; i < 5; ++i);
288-
// expected-warning@+1{{OpenACC clause 'private' not yet implemented}}
289283
#pragma acc parallel loop private(Var) auto
290284
for(unsigned i = 0; i < 5; ++i);
291285
// TODOexpected-error@+1{{OpenACC 'copyout' clause is not valid on 'parallel loop' directive}}
@@ -436,8 +430,6 @@ void uses() {
436430
// expected-warning@+1{{OpenACC clause 'device_resident' not yet implemented}}
437431
#pragma acc parallel loop independent device_resident(VarPtr)
438432
for(unsigned i = 0; i < 5; ++i);
439-
// TODOexpected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'parallel loop' directive}}
440-
// expected-warning@+1{{OpenACC clause 'firstprivate' not yet implemented}}
441433
#pragma acc parallel loop independent firstprivate(Var)
442434
for(unsigned i = 0; i < 5; ++i);
443435
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
@@ -454,7 +446,6 @@ void uses() {
454446
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
455447
#pragma acc parallel loop independent present(Var)
456448
for(unsigned i = 0; i < 5; ++i);
457-
// expected-warning@+1{{OpenACC clause 'private' not yet implemented}}
458449
#pragma acc parallel loop independent private(Var)
459450
for(unsigned i = 0; i < 5; ++i);
460451
// TODOexpected-error@+1{{OpenACC 'copyout' clause is not valid on 'parallel loop' directive}}
@@ -604,8 +595,6 @@ void uses() {
604595
// expected-warning@+1{{OpenACC clause 'device_resident' not yet implemented}}
605596
#pragma acc parallel loop device_resident(VarPtr) independent
606597
for(unsigned i = 0; i < 5; ++i);
607-
// TODOexpected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'parallel loop' directive}}
608-
// expected-warning@+1{{OpenACC clause 'firstprivate' not yet implemented}}
609598
#pragma acc parallel loop firstprivate(Var) independent
610599
for(unsigned i = 0; i < 5; ++i);
611600
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
@@ -622,7 +611,6 @@ void uses() {
622611
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
623612
#pragma acc parallel loop present(Var) independent
624613
for(unsigned i = 0; i < 5; ++i);
625-
// expected-warning@+1{{OpenACC clause 'private' not yet implemented}}
626614
#pragma acc parallel loop private(Var) independent
627615
for(unsigned i = 0; i < 5; ++i);
628616
// TODOexpected-error@+1{{OpenACC 'copyout' clause is not valid on 'parallel loop' directive}}
@@ -779,8 +767,6 @@ void uses() {
779767
// expected-warning@+1{{OpenACC clause 'device_resident' not yet implemented}}
780768
#pragma acc parallel loop seq device_resident(VarPtr)
781769
for(unsigned i = 0; i < 5; ++i);
782-
// TODOexpected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'parallel loop' directive}}
783-
// expected-warning@+1{{OpenACC clause 'firstprivate' not yet implemented}}
784770
#pragma acc parallel loop seq firstprivate(Var)
785771
for(unsigned i = 0; i < 5; ++i);
786772
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
@@ -797,7 +783,6 @@ void uses() {
797783
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
798784
#pragma acc parallel loop seq present(Var)
799785
for(unsigned i = 0; i < 5; ++i);
800-
// expected-warning@+1{{OpenACC clause 'private' not yet implemented}}
801786
#pragma acc parallel loop seq private(Var)
802787
for(unsigned i = 0; i < 5; ++i);
803788
// TODOexpected-error@+1{{OpenACC 'copyout' clause is not valid on 'parallel loop' directive}}
@@ -953,8 +938,6 @@ void uses() {
953938
// expected-warning@+1{{OpenACC clause 'device_resident' not yet implemented}}
954939
#pragma acc parallel loop device_resident(VarPtr) seq
955940
for(unsigned i = 0; i < 5; ++i);
956-
// TODOexpected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'parallel loop' directive}}
957-
// expected-warning@+1{{OpenACC clause 'firstprivate' not yet implemented}}
958941
#pragma acc parallel loop firstprivate(Var) seq
959942
for(unsigned i = 0; i < 5; ++i);
960943
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
@@ -971,7 +954,6 @@ void uses() {
971954
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
972955
#pragma acc parallel loop present(Var) seq
973956
for(unsigned i = 0; i < 5; ++i);
974-
// expected-warning@+1{{OpenACC clause 'private' not yet implemented}}
975957
#pragma acc parallel loop private(Var) seq
976958
for(unsigned i = 0; i < 5; ++i);
977959
// TODOexpected-error@+1{{OpenACC 'copyout' clause is not valid on 'parallel loop' directive}}

clang/test/SemaOpenACC/combined-construct-default-clause.c

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ void SingleOnly() {
1818
#pragma acc kernels loop self default(present) present(i) default(none) copy(i)
1919
for(int i = 5; i < 10;++i);
2020

21-
// expected-warning@+4{{OpenACC clause 'private' not yet implemented}}
2221
// expected-warning@+3{{OpenACC clause 'copy' not yet implemented}}
2322
// expected-error@+2{{OpenACC 'default' clause cannot appear more than once on a 'parallel loop' directive}}
2423
// expected-note@+1{{previous clause is here}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
typedef struct IsComplete {
4+
struct S { int A; } CompositeMember;
5+
int ScalarMember;
6+
float ArrayMember[5];
7+
void *PointerMember;
8+
} Complete;
9+
void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete CompositeParam) {
10+
int LocalInt;
11+
short *LocalPointer;
12+
float LocalArray[5];
13+
Complete LocalComposite;
14+
// Check Appertainment:
15+
#pragma acc parallel loop firstprivate(LocalInt)
16+
for (int i = 5; i < 10; ++i);
17+
#pragma acc serial loop firstprivate(LocalInt)
18+
for (int i = 5; i < 10; ++i);
19+
// expected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'kernels loop' directive}}
20+
#pragma acc kernels loop firstprivate(LocalInt)
21+
for (int i = 5; i < 10; ++i);
22+
23+
// Valid cases:
24+
#pragma acc parallel loop firstprivate(LocalInt, LocalPointer, LocalArray)
25+
for (int i = 5; i < 10; ++i);
26+
#pragma acc serial loop firstprivate(LocalArray[2:1])
27+
for (int i = 5; i < 10; ++i);
28+
29+
#pragma acc parallel loop firstprivate(LocalComposite.ScalarMember, LocalComposite.ScalarMember)
30+
for (int i = 5; i < 10; ++i);
31+
32+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
33+
#pragma acc serial loop firstprivate(1 + IntParam)
34+
for (int i = 5; i < 10; ++i);
35+
36+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
37+
#pragma acc serial loop firstprivate(+IntParam)
38+
for (int i = 5; i < 10; ++i);
39+
40+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
41+
#pragma acc parallel loop firstprivate(PointerParam[2:])
42+
for (int i = 5; i < 10; ++i);
43+
44+
// expected-error@+1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
45+
#pragma acc serial loop firstprivate(ArrayParam[2:5])
46+
for (int i = 5; i < 10; ++i);
47+
48+
// expected-error@+2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
49+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
50+
#pragma acc parallel loop firstprivate((float*)ArrayParam[2:5])
51+
for (int i = 5; i < 10; ++i);
52+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
53+
#pragma acc serial loop firstprivate((float)ArrayParam[2])
54+
for (int i = 5; i < 10; ++i);
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
enum SomeE{};
4+
typedef struct IsComplete {
5+
struct S { int A; } CompositeMember;
6+
int ScalarMember;
7+
float ArrayMember[5];
8+
SomeE EnumMember;
9+
char *PointerMember;
10+
} Complete;
11+
12+
void uses(int IntParam, char *PointerParam, float ArrayParam[5], Complete CompositeParam, int &IntParamRef) {
13+
int LocalInt;
14+
char *LocalPointer;
15+
float LocalArray[5];
16+
// Check Appertainment:
17+
#pragma acc parallel loop firstprivate(LocalInt)
18+
for (int i = 5; i < 10; ++i);
19+
#pragma acc serial loop firstprivate(LocalInt)
20+
for (int i = 5; i < 10; ++i);
21+
// expected-error@+1{{OpenACC 'firstprivate' clause is not valid on 'kernels loop' directive}}
22+
#pragma acc kernels loop firstprivate(LocalInt)
23+
for (int i = 5; i < 10; ++i);
24+
25+
// Valid cases:
26+
#pragma acc parallel loop firstprivate(LocalInt, LocalPointer, LocalArray)
27+
for (int i = 5; i < 10; ++i);
28+
#pragma acc serial loop firstprivate(LocalArray[2:1])
29+
for (int i = 5; i < 10; ++i);
30+
31+
Complete LocalComposite2;
32+
#pragma acc parallel loop firstprivate(LocalComposite2.ScalarMember, LocalComposite2.ScalarMember)
33+
for (int i = 5; i < 10; ++i);
34+
35+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
36+
#pragma acc parallel loop firstprivate(1 + IntParam)
37+
for (int i = 5; i < 10; ++i);
38+
39+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
40+
#pragma acc serial loop firstprivate(+IntParam)
41+
for (int i = 5; i < 10; ++i);
42+
43+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
44+
#pragma acc parallel loop firstprivate(PointerParam[2:])
45+
for (int i = 5; i < 10; ++i);
46+
47+
// expected-error@+1{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
48+
#pragma acc parallel loop firstprivate(ArrayParam[2:5])
49+
for (int i = 5; i < 10; ++i);
50+
51+
// expected-error@+2{{OpenACC sub-array specified range [2:5] would be out of the range of the subscripted array size of 5}}
52+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
53+
#pragma acc serial loop firstprivate((float*)ArrayParam[2:5])
54+
for (int i = 5; i < 10; ++i);
55+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
56+
#pragma acc parallel loop firstprivate((float)ArrayParam[2])
57+
for (int i = 5; i < 10; ++i);
58+
}
59+
60+
template<typename T, unsigned I, typename V>
61+
void TemplUses(T t, T (&arrayT)[I], V TemplComp) {
62+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
63+
#pragma acc parallel loop firstprivate(+t)
64+
for (int i = 5; i < 10; ++i);
65+
66+
// NTTP's are only valid if it is a reference to something.
67+
// expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
68+
// expected-note@#TEMPL_USES_INST{{in instantiation of}}
69+
#pragma acc parallel loop firstprivate(I)
70+
for (int i = 5; i < 10; ++i);
71+
72+
// expected-error@+1{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
73+
#pragma acc serial loop firstprivate(t, I)
74+
for (int i = 5; i < 10; ++i);
75+
76+
#pragma acc parallel loop firstprivate(arrayT)
77+
for (int i = 5; i < 10; ++i);
78+
79+
#pragma acc parallel loop firstprivate(TemplComp)
80+
for (int i = 5; i < 10; ++i);
81+
82+
#pragma acc parallel loop firstprivate(TemplComp.PointerMember[5])
83+
for (int i = 5; i < 10; ++i);
84+
int *Pointer;
85+
#pragma acc serial loop firstprivate(Pointer[:I])
86+
for (int i = 5; i < 10; ++i);
87+
#pragma acc parallel loop firstprivate(Pointer[:t])
88+
for (int i = 5; i < 10; ++i);
89+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
90+
#pragma acc parallel loop firstprivate(Pointer[1:])
91+
for (int i = 5; i < 10; ++i);
92+
}
93+
94+
template<unsigned I, auto &NTTP_REF>
95+
void NTTP() {
96+
// NTTP's are only valid if it is a reference to something.
97+
// expected-error@+2{{OpenACC variable is not a valid variable name, sub-array, array element, member of a composite variable, or composite variable member}}
98+
// expected-note@#NTTP_INST{{in instantiation of}}
99+
#pragma acc parallel loop firstprivate(I)
100+
for (int i = 5; i < 10; ++i);
101+
102+
#pragma acc serial loop firstprivate(NTTP_REF)
103+
for (int i = 5; i < 10; ++i);
104+
}
105+
106+
void Inst() {
107+
static constexpr int NTTP_REFed = 1;
108+
int i;
109+
int Arr[5];
110+
Complete C;
111+
TemplUses(i, Arr, C); // #TEMPL_USES_INST
112+
NTTP<5, NTTP_REFed>(); // #NTTP_INST
113+
}

0 commit comments

Comments
 (0)