Skip to content

Commit 24dc800

Browse files
committed
Implement 'new' num_gangs/worker/vector_length rules around device_type, lots of test updates, fixed up the diagnostics-sema-kinds
1 parent 58aea76 commit 24dc800

11 files changed

+163
-15
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12971,8 +12971,8 @@ def err_acc_clause_routine_one_of_in_region
1297112971
: Error<"OpenACC 'routine' construct must have at least one 'gang', 'seq', "
1297212972
"'vector', or 'worker' clause that applies to each 'device_type'">;
1297312973
def err_acc_clause_since_last_device_type
12974-
: Error<"OpenACC '%0' clause cannot appear more than once on a '%1' "
12975-
"directive %select{|in a 'device_type' region}2}">;
12974+
: Error<"OpenACC '%0' clause cannot appear more than once%select{| in a "
12975+
"'device_type' region}2 on a '%1' directive">;
1297612976

1297712977
def err_acc_reduction_num_gangs_conflict
1297812978
: Error<"OpenACC '%1' clause %select{|with more than 1 argument }0may not "

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ class SemaOpenACCClauseVisitor {
334334
}
335335

336336
// For 'tile' and 'collapse', only allow 1 per 'device_type'.
337+
// Also applies to num_worker, num_gangs, and vector_length.
337338
template <typename TheClauseTy>
338339
bool DisallowSinceLastDeviceType(SemaOpenACC::OpenACCParsedClause &Clause) {
339340
auto LastDeviceTypeItr =
@@ -356,7 +357,6 @@ class SemaOpenACCClauseVisitor {
356357
SemaRef.Diag((*LastDeviceTypeItr)->getBeginLoc(),
357358
diag::note_acc_previous_clause_here);
358359

359-
// TODO: DIAG
360360
return true;
361361
}
362362

@@ -483,6 +483,9 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitSelfClause(
483483
OpenACCClause *SemaOpenACCClauseVisitor::VisitNumGangsClause(
484484
SemaOpenACC::OpenACCParsedClause &Clause) {
485485

486+
if (DisallowSinceLastDeviceType<OpenACCNumGangsClause>(Clause))
487+
return nullptr;
488+
486489
// num_gangs requires at least 1 int expr in all forms. Diagnose here, but
487490
// allow us to continue, an empty clause might be useful for future
488491
// diagnostics.
@@ -573,6 +576,9 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitNumGangsClause(
573576
OpenACCClause *SemaOpenACCClauseVisitor::VisitNumWorkersClause(
574577
SemaOpenACC::OpenACCParsedClause &Clause) {
575578

579+
if (DisallowSinceLastDeviceType<OpenACCNumWorkersClause>(Clause))
580+
return nullptr;
581+
576582
// OpenACC 3.3 Section 2.9.2:
577583
// An argument is allowed only when the 'num_workers' does not appear on the
578584
// kernels construct.
@@ -601,6 +607,10 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitNumWorkersClause(
601607

602608
OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
603609
SemaOpenACC::OpenACCParsedClause &Clause) {
610+
611+
if (DisallowSinceLastDeviceType<OpenACCVectorLengthClause>(Clause))
612+
return nullptr;
613+
604614
// OpenACC 3.3 Section 2.9.4:
605615
// An argument is allowed only when the 'vector_length' does not appear on the
606616
// 'kernels' construct.

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ void Test() {
1313
#pragma acc parallel loop num_gangs(1)
1414
for(int i = 5; i < 10;++i);
1515

16+
// expected-error@+2{{OpenACC 'num_gangs' clause cannot appear more than once on a 'kernels loop' directive}}
17+
// expected-note@+1{{previous clause is here}}
18+
#pragma acc kernels loop num_gangs(1) num_gangs(2)
19+
for(int i = 5; i < 10;++i);
20+
21+
// expected-error@+2{{OpenACC 'num_gangs' clause cannot appear more than once on a 'parallel loop' directive}}
22+
// expected-note@+1{{previous clause is here}}
23+
#pragma acc parallel loop num_gangs(1) num_gangs(2)
24+
for(int i = 5; i < 10;++i);
25+
26+
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'kernels loop' directive}}
27+
// expected-note@+2{{previous clause is here}}
28+
// expected-note@+1{{previous clause is here}}
29+
#pragma acc kernels loop num_gangs(1) device_type(*) num_gangs(1) num_gangs(2)
30+
for(int i = 5; i < 10;++i);
31+
32+
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'parallel loop' directive}}
33+
// expected-note@+2{{previous clause is here}}
34+
// expected-note@+1{{previous clause is here}}
35+
#pragma acc parallel loop device_type(*) num_gangs(1) num_gangs(2)
36+
for(int i = 5; i < 10;++i);
37+
38+
#pragma acc parallel loop num_gangs(1) device_type(*) num_gangs(2)
39+
for(int i = 5; i < 10;++i);
40+
1641
// expected-error@+1{{OpenACC clause 'num_gangs' requires expression of integer type}}
1742
#pragma acc parallel loop num_gangs(getF())
1843
for(int i = 5; i < 10;++i);
@@ -25,12 +50,6 @@ void Test() {
2550
#pragma acc parallel loop num_gangs()
2651
for(int i = 5; i < 10;++i);
2752

28-
#pragma acc kernels loop num_gangs(1) num_gangs(2)
29-
for(int i = 5; i < 10;++i);
30-
31-
#pragma acc parallel loop num_gangs(1) num_gangs(2)
32-
for(int i = 5; i < 10;++i);
33-
3453
// expected-error@+1{{too many integer expression arguments provided to OpenACC 'num_gangs' clause: 'kernels loop' directive expects maximum of 1, 2 were provided}}
3554
#pragma acc kernels loop num_gangs(1, getS())
3655
for(int i = 5; i < 10;++i);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ void Test() {
1313
#pragma acc parallel loop num_workers(1)
1414
for(int i = 5; i < 10;++i);
1515

16+
// expected-error@+2{{OpenACC 'num_workers' clause cannot appear more than once on a 'kernels loop' directive}}
17+
// expected-note@+1{{previous clause is here}}
18+
#pragma acc kernels loop num_workers(1) num_workers(2)
19+
for(int i = 5; i < 10;++i);
20+
21+
// expected-error@+2{{OpenACC 'num_workers' clause cannot appear more than once on a 'parallel loop' directive}}
22+
// expected-note@+1{{previous clause is here}}
23+
#pragma acc parallel loop num_workers(1) num_workers(2)
24+
for(int i = 5; i < 10;++i);
25+
26+
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'kernels loop' directive}}
27+
// expected-note@+2{{previous clause is here}}
28+
// expected-note@+1{{previous clause is here}}
29+
#pragma acc kernels loop num_workers(1) device_type(*) num_workers(1) num_workers(2)
30+
for(int i = 5; i < 10;++i);
31+
32+
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'parallel loop' directive}}
33+
// expected-note@+2{{previous clause is here}}
34+
// expected-note@+1{{previous clause is here}}
35+
#pragma acc parallel loop device_type(*) num_workers(1) num_workers(2)
36+
for(int i = 5; i < 10;++i);
37+
38+
#pragma acc parallel loop num_workers(1) device_type(*) num_workers(2)
39+
for(int i = 5; i < 10;++i);
40+
1641
// expected-error@+1{{OpenACC clause 'num_workers' requires expression of integer type}}
1742
#pragma acc parallel loop num_workers(getF())
1843
for(int i = 5; i < 10;++i);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ void Test() {
1313
#pragma acc parallel loop vector_length(1)
1414
for(int i = 5; i < 10;++i);
1515

16+
// expected-error@+2{{OpenACC 'vector_length' clause cannot appear more than once on a 'kernels loop' directive}}
17+
// expected-note@+1{{previous clause is here}}
18+
#pragma acc kernels loop vector_length(1) vector_length(2)
19+
for(int i = 5; i < 10;++i);
20+
21+
// expected-error@+2{{OpenACC 'vector_length' clause cannot appear more than once on a 'parallel loop' directive}}
22+
// expected-note@+1{{previous clause is here}}
23+
#pragma acc parallel loop vector_length(1) vector_length(2)
24+
for(int i = 5; i < 10;++i);
25+
26+
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'kernels loop' directive}}
27+
// expected-note@+2{{previous clause is here}}
28+
// expected-note@+1{{previous clause is here}}
29+
#pragma acc kernels loop vector_length(1) device_type(*) vector_length(1) vector_length(2)
30+
for(int i = 5; i < 10;++i);
31+
32+
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'parallel loop' directive}}
33+
// expected-note@+2{{previous clause is here}}
34+
// expected-note@+1{{previous clause is here}}
35+
#pragma acc parallel loop device_type(*) vector_length(1) vector_length(2)
36+
for(int i = 5; i < 10;++i);
37+
38+
#pragma acc parallel loop vector_length(1) device_type(*) vector_length(2)
39+
for(int i = 5; i < 10;++i);
40+
1641
// expected-error@+1{{OpenACC clause 'vector_length' requires expression of integer type}}
1742
#pragma acc parallel loop vector_length(getF())
1843
for(int i = 5; i < 10;++i);

clang/test/SemaOpenACC/compute-construct-num_gangs-clause.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,31 @@ void Test() {
1212
#pragma acc parallel num_gangs(1)
1313
while(1);
1414

15+
// expected-error@+2{{OpenACC 'num_gangs' clause cannot appear more than once on a 'kernels' directive}}
16+
// expected-note@+1{{previous clause is here}}
1517
#pragma acc kernels num_gangs(1) num_gangs(2)
1618
while(1);
1719

20+
// expected-error@+2{{OpenACC 'num_gangs' clause cannot appear more than once on a 'parallel' directive}}
21+
// expected-note@+1{{previous clause is here}}
1822
#pragma acc parallel num_gangs(1) num_gangs(2)
1923
while(1);
2024

25+
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
26+
// expected-note@+2{{previous clause is here}}
27+
// expected-note@+1{{previous clause is here}}
28+
#pragma acc kernels num_gangs(1) device_type(*) num_gangs(1) num_gangs(2)
29+
while(1);
30+
31+
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
32+
// expected-note@+2{{previous clause is here}}
33+
// expected-note@+1{{previous clause is here}}
34+
#pragma acc parallel device_type(*) num_gangs(1) num_gangs(2)
35+
while(1);
36+
37+
#pragma acc parallel num_gangs(1) device_type(*) num_gangs(2)
38+
while(1);
39+
2140
// expected-error@+1{{too many integer expression arguments provided to OpenACC 'num_gangs' clause: 'kernels' directive expects maximum of 1, 2 were provided}}
2241
#pragma acc kernels num_gangs(1, getS())
2342
while(1);

clang/test/SemaOpenACC/compute-construct-num_workers-clause.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ void Test() {
88
#pragma acc kernels num_workers(1)
99
while(1);
1010

11+
// expected-error@+2{{OpenACC 'num_workers' clause cannot appear more than once on a 'kernels' directive}}
12+
// expected-note@+1{{previous clause is here}}
13+
#pragma acc kernels num_workers(1) num_workers(2)
14+
while(1);
15+
16+
// expected-error@+2{{OpenACC 'num_workers' clause cannot appear more than once on a 'parallel' directive}}
17+
// expected-note@+1{{previous clause is here}}
18+
#pragma acc parallel num_workers(1) num_workers(2)
19+
while(1);
20+
21+
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
22+
// expected-note@+2{{previous clause is here}}
23+
// expected-note@+1{{previous clause is here}}
24+
#pragma acc kernels num_workers(1) device_type(*) num_workers(1) num_workers(2)
25+
while(1);
26+
27+
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
28+
// expected-note@+2{{previous clause is here}}
29+
// expected-note@+1{{previous clause is here}}
30+
#pragma acc parallel device_type(*) num_workers(1) num_workers(2)
31+
while(1);
32+
33+
#pragma acc parallel num_workers(1) device_type(*) num_workers(2)
34+
while(1);
35+
1136
// expected-error@+1{{OpenACC 'num_workers' clause is not valid on 'serial' directive}}
1237
#pragma acc serial num_workers(1)
1338
while(1);

clang/test/SemaOpenACC/compute-construct-vector_length-clause.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@ void Test() {
88
#pragma acc kernels vector_length(1)
99
while(1);
1010

11+
// expected-error@+2{{OpenACC 'vector_length' clause cannot appear more than once on a 'kernels' directive}}
12+
// expected-note@+1{{previous clause is here}}
13+
#pragma acc kernels vector_length(1) vector_length(2)
14+
while(1);
15+
16+
// expected-error@+2{{OpenACC 'vector_length' clause cannot appear more than once on a 'parallel' directive}}
17+
// expected-note@+1{{previous clause is here}}
18+
#pragma acc parallel vector_length(1) vector_length(2)
19+
while(1);
20+
21+
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
22+
// expected-note@+2{{previous clause is here}}
23+
// expected-note@+1{{previous clause is here}}
24+
#pragma acc kernels vector_length(1) device_type(*) vector_length(1) vector_length(2)
25+
while(1);
26+
27+
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
28+
// expected-note@+2{{previous clause is here}}
29+
// expected-note@+1{{previous clause is here}}
30+
#pragma acc parallel device_type(*) vector_length(1) vector_length(2)
31+
while(1);
32+
33+
#pragma acc parallel vector_length(1) device_type(*) vector_length(2)
34+
while(1);
35+
1136
// expected-error@+1{{OpenACC 'vector_length' clause is not valid on 'serial' directive}}
1237
#pragma acc serial vector_length(1)
1338
while(1);

clang/test/SemaOpenACC/loop-construct-collapse-clause.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ void allow_multiple_collapse() {
529529
}
530530

531531
void no_dupes_since_last_device_type() {
532-
// expected-error@+3{{OpenACC 'collapse' clause cannot appear more than once on a 'loop' directive in a 'device_type' region}}
532+
// expected-error@+3{{OpenACC 'collapse' clause cannot appear more than once in a 'device_type' region on a 'loop' directive}}
533533
// expected-note@+2{{previous clause is here}}
534534
// expected-note@+1{{previous clause is here}}
535535
#pragma acc loop collapse(1) device_type(*) collapse(1) collapse(2)

clang/test/SemaOpenACC/loop-construct-tile-clause.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ void collapse_tile_depth() {
409409
}
410410
}
411411
void no_dupes_since_last_device_type() {
412-
// expected-error@+3{{OpenACC 'tile' clause cannot appear more than once on a 'loop' directive in a 'device_type' region}}
412+
// expected-error@+3{{OpenACC 'tile' clause cannot appear more than once in a 'device_type' region on a 'loop' directive}}
413413
// expected-note@+2{{previous clause is here}}
414414
// expected-note@+1{{previous clause is here}}
415415
#pragma acc loop tile(1) device_type(*) tile(1) tile(2)

0 commit comments

Comments
 (0)