Skip to content

Commit c891eaa

Browse files
erichkeaneHoney Goyal
authored andcommitted
[OpenACC] Adjust rules of 'routine' required clauses (llvm#170667)
The interaction between various clauses on 'routine' was not implemented QUITE right, as I discovered when looking into the implementation of the ACC dialect. This patch fixes it up so that there can only be 1 of the special clauses per device_type VALUE (including nvidia == acc_device_nvidia). This patch also does a refactor/unification of this with the rules of other clauses, as we now know they are effectively the same.
1 parent ab72f53 commit c891eaa

14 files changed

+387
-374
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13537,21 +13537,19 @@ def err_acc_clause_after_device_type
1353713537
def err_acc_clause_cannot_combine
1353813538
: Error<"OpenACC clause '%0' may not appear on the same construct as a "
1353913539
"'%1' clause on a '%2' construct">;
13540-
def err_acc_clause_routine_cannot_combine_before_device_type
13541-
: Error<"OpenACC clause '%0' after 'device_type' clause on a 'routine' "
13542-
"conflicts with the '%1' clause before the first 'device_type'">;
13543-
def err_acc_clause_routine_cannot_combine_same_device_type
13544-
: Error<"OpenACC clause '%0' on a 'routine' directive conflicts with the "
13545-
"'%1' clause applying to the same 'device_type'">;
13540+
def err_acc_clause_cannot_combine_before_device_type
13541+
: Error<
13542+
"OpenACC clause '%1' after 'device_type' clause on a '%0' construct "
13543+
"conflicts with the '%2' clause before the first 'device_type'">;
13544+
def err_acc_clause_cannot_combine_same_device_type
13545+
: Error<"OpenACC clause '%1' cannot combine with previous '%2' clause"
13546+
"%select{| in the same 'device_type' region}3 on a '%0' directive">;
13547+
def err_acc_clause_conflicts_prev_dev_type
13548+
: Error<"OpenACC '%0' clause applies to 'device_type' '%1', which "
13549+
"conflicts with previous '%2' clause">;
1354613550
def err_acc_clause_routine_one_of_in_region
1354713551
: Error<"OpenACC 'routine' construct must have at least one 'gang', 'seq', "
1354813552
"'vector', or 'worker' clause that applies to each 'device_type'">;
13549-
def err_acc_clause_since_last_device_type
13550-
: Error<"OpenACC '%0' clause cannot appear more than once%select{| in a "
13551-
"'device_type' region}2 on a '%1' directive">;
13552-
def err_acc_clause_conflicts_prev_dev_type
13553-
: Error<"OpenACC '%0' clause applies to 'device_type' '%1', which "
13554-
"conflicts with previous '%0' clause">;
1355513553

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

clang/lib/Sema/SemaOpenACCClause.cpp

Lines changed: 157 additions & 189 deletions
Large diffs are not rendered by default.

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,16 +1315,16 @@ void Gang() {
13151315

13161316
}
13171317

1318-
// expected-error@+4{{OpenACC clause 'seq' may not appear on the same construct as a 'worker' clause on a 'routine' construct}}
1318+
// expected-error@+4{{OpenACC clause 'seq' cannot combine with previous 'worker' clause on a 'routine' directive}}
13191319
// expected-note@+3{{previous 'worker' clause is here}}
1320-
// expected-error@+2{{OpenACC clause 'vector' may not appear on the same construct as a 'worker' clause on a 'routine' construct}}
1320+
// expected-error@+2{{OpenACC clause 'vector' cannot combine with previous 'worker' clause on a 'routine' directive}}
13211321
// expected-note@+1{{previous 'worker' clause is here}}
13221322
#pragma acc routine worker, vector, seq, nohost
13231323
void bar();
13241324

1325-
// expected-error@+4{{OpenACC clause 'seq' may not appear on the same construct as a 'worker' clause on a 'routine' construct}}
1325+
// expected-error@+4{{OpenACC clause 'seq' cannot combine with previous 'worker' clause on a 'routine' directive}}
13261326
// expected-note@+3{{previous 'worker' clause is here}}
1327-
// expected-error@+2{{OpenACC clause 'vector' may not appear on the same construct as a 'worker' clause on a 'routine' construct}}
1327+
// expected-error@+2{{OpenACC clause 'vector' cannot combine with previous 'worker' clause on a 'routine' directive}}
13281328
// expected-note@+1{{previous 'worker' clause is here}}
13291329
#pragma acc routine(bar) worker, vector, seq, nohost
13301330

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ 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}}
16+
// expected-error@+2{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause on a 'kernels loop' directive}}
1717
// expected-note@+1{{previous 'num_gangs' clause is here}}
1818
#pragma acc kernels loop num_gangs(1) num_gangs(2)
1919
for(int i = 5; i < 10;++i);
2020

21-
// expected-error@+2{{OpenACC 'num_gangs' clause cannot appear more than once on a 'parallel loop' directive}}
21+
// expected-error@+2{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause on a 'parallel loop' directive}}
2222
// expected-note@+1{{previous 'num_gangs' clause is here}}
2323
#pragma acc parallel loop num_gangs(1) num_gangs(2)
2424
for(int i = 5; i < 10;++i);
2525

26-
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'kernels loop' directive}}
26+
// expected-error@+3{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause in the same 'device_type' region on a 'kernels loop' directive}}
2727
// expected-note@+2{{previous 'num_gangs' clause is here}}
2828
// expected-note@+1{{active 'device_type' clause here}}
2929
#pragma acc kernels loop num_gangs(1) device_type(*) num_gangs(1) num_gangs(2)
3030
for(int i = 5; i < 10;++i);
3131

32-
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'parallel loop' directive}}
32+
// expected-error@+3{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause in the same 'device_type' region on a 'parallel loop' directive}}
3333
// expected-note@+2{{previous 'num_gangs' clause is here}}
3434
// expected-note@+1{{active 'device_type' clause here}}
3535
#pragma acc parallel loop device_type(*) num_gangs(1) num_gangs(2)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ 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}}
16+
// expected-error@+2{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause on a 'kernels loop' directive}}
1717
// expected-note@+1{{previous 'num_workers' clause is here}}
1818
#pragma acc kernels loop num_workers(1) num_workers(2)
1919
for(int i = 5; i < 10;++i);
2020

21-
// expected-error@+2{{OpenACC 'num_workers' clause cannot appear more than once on a 'parallel loop' directive}}
21+
// expected-error@+2{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause on a 'parallel loop' directive}}
2222
// expected-note@+1{{previous 'num_workers' clause is here}}
2323
#pragma acc parallel loop num_workers(1) num_workers(2)
2424
for(int i = 5; i < 10;++i);
2525

26-
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'kernels loop' directive}}
26+
// expected-error@+3{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause in the same 'device_type' region on a 'kernels loop' directive}}
2727
// expected-note@+2{{previous 'num_workers' clause is here}}
2828
// expected-note@+1{{active 'device_type' clause here}}
2929
#pragma acc kernels loop num_workers(1) device_type(*) num_workers(1) num_workers(2)
3030
for(int i = 5; i < 10;++i);
3131

32-
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'parallel loop' directive}}
32+
// expected-error@+3{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause in the same 'device_type' region on a 'parallel loop' directive}}
3333
// expected-note@+2{{previous 'num_workers' clause is here}}
3434
// expected-note@+1{{active 'device_type' clause here}}
3535
#pragma acc parallel loop device_type(*) num_workers(1) num_workers(2)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ 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}}
16+
// expected-error@+2{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause on a 'kernels loop' directive}}
1717
// expected-note@+1{{previous 'vector_length' clause is here}}
1818
#pragma acc kernels loop vector_length(1) vector_length(2)
1919
for(int i = 5; i < 10;++i);
2020

21-
// expected-error@+2{{OpenACC 'vector_length' clause cannot appear more than once on a 'parallel loop' directive}}
21+
// expected-error@+2{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause on a 'parallel loop' directive}}
2222
// expected-note@+1{{previous 'vector_length' clause is here}}
2323
#pragma acc parallel loop vector_length(1) vector_length(2)
2424
for(int i = 5; i < 10;++i);
2525

26-
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'kernels loop' directive}}
26+
// expected-error@+3{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause in the same 'device_type' region on a 'kernels loop' directive}}
2727
// expected-note@+2{{previous 'vector_length' clause is here}}
2828
// expected-note@+1{{active 'device_type' clause here}}
2929
#pragma acc kernels loop vector_length(1) device_type(*) vector_length(1) vector_length(2)
3030
for(int i = 5; i < 10;++i);
3131

32-
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'parallel loop' directive}}
32+
// expected-error@+3{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause in the same 'device_type' region on a 'parallel loop' directive}}
3333
// expected-note@+2{{previous 'vector_length' clause is here}}
3434
// expected-note@+1{{active 'device_type' clause here}}
3535
#pragma acc parallel loop device_type(*) vector_length(1) vector_length(2)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,43 @@ void Test() {
2020
#pragma acc serial async(1, 2)
2121
while(1);
2222

23-
// expected-error@+2{{OpenACC 'async' clause cannot appear more than once on a 'kernels' directive}}
23+
// expected-error@+2{{OpenACC clause 'async' cannot combine with previous 'async' clause on a 'kernels' directive}}
2424
// expected-note@+1{{previous 'async' clause is here}}
2525
#pragma acc kernels async async
2626
while(1);
2727

28-
// expected-error@+2{{OpenACC 'async' clause cannot appear more than once on a 'kernels' directive}}
28+
// expected-error@+2{{OpenACC clause 'async' cannot combine with previous 'async' clause on a 'kernels' directive}}
2929
// expected-note@+1{{previous 'async' clause is here}}
3030
#pragma acc kernels async(1) async(2)
3131
while(1);
3232

33-
// expected-error@+2{{OpenACC 'async' clause cannot appear more than once on a 'parallel' directive}}
33+
// expected-error@+2{{OpenACC clause 'async' cannot combine with previous 'async' clause on a 'parallel' directive}}
3434
// expected-note@+1{{previous 'async' clause is here}}
3535
#pragma acc parallel async(1) async(2)
3636
while(1);
3737

38-
// expected-error@+2{{OpenACC 'async' clause cannot appear more than once on a 'serial' directive}}
38+
// expected-error@+2{{OpenACC clause 'async' cannot combine with previous 'async' clause on a 'serial' directive}}
3939
// expected-note@+1{{previous 'async' clause is here}}
4040
#pragma acc serial async(1) async(2)
4141
while(1);
4242

43-
// expected-error@+3{{OpenACC 'async' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
43+
// expected-error@+3{{OpenACC clause 'async' cannot combine with previous 'async' clause in the same 'device_type' region on a 'kernels' directive}}
4444
// expected-note@+2{{previous 'async' clause is here}}
4545
// expected-note@+1{{active 'device_type' clause here}}
4646
#pragma acc kernels async(1) device_type(*) async(1) async(2)
4747
while(1);
48-
// expected-error@+3{{OpenACC 'async' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
48+
// expected-error@+3{{OpenACC clause 'async' cannot combine with previous 'async' clause in the same 'device_type' region on a 'parallel' directive}}
4949
// expected-note@+2{{previous 'async' clause is here}}
5050
// expected-note@+1{{active 'device_type' clause here}}
5151
#pragma acc parallel async device_type(*) async async
5252
while(1);
53-
// expected-error@+3{{OpenACC 'async' clause cannot appear more than once in a 'device_type' region on a 'serial' directive}}
53+
// expected-error@+3{{OpenACC clause 'async' cannot combine with previous 'async' clause in the same 'device_type' region on a 'serial' directive}}
5454
// expected-note@+2{{previous 'async' clause is here}}
5555
// expected-note@+1{{active 'device_type' clause here}}
5656
#pragma acc serial async(1) device_type(*) async async(2)
5757
while(1);
5858

59-
// expected-error@+3{{OpenACC 'async' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
59+
// expected-error@+3{{OpenACC clause 'async' cannot combine with previous 'async' clause in the same 'device_type' region on a 'parallel' directive}}
6060
// expected-note@+2{{previous 'async' clause is here}}
6161
// expected-note@+1{{active 'device_type' clause here}}
6262
#pragma acc parallel device_type(*) async async

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ 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}}
15+
// expected-error@+2{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause on a 'kernels' directive}}
1616
// expected-note@+1{{previous 'num_gangs' clause is here}}
1717
#pragma acc kernels num_gangs(1) num_gangs(2)
1818
while(1);
1919

20-
// expected-error@+2{{OpenACC 'num_gangs' clause cannot appear more than once on a 'parallel' directive}}
20+
// expected-error@+2{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause on a 'parallel' directive}}
2121
// expected-note@+1{{previous 'num_gangs' clause is here}}
2222
#pragma acc parallel num_gangs(1) num_gangs(2)
2323
while(1);
2424

25-
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
25+
// expected-error@+3{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause in the same 'device_type' region on a 'kernels' directive}}
2626
// expected-note@+2{{previous 'num_gangs' clause is here}}
2727
// expected-note@+1{{active 'device_type' clause here}}
2828
#pragma acc kernels num_gangs(1) device_type(*) num_gangs(1) num_gangs(2)
2929
while(1);
3030

31-
// expected-error@+3{{OpenACC 'num_gangs' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
31+
// expected-error@+3{{OpenACC clause 'num_gangs' cannot combine with previous 'num_gangs' clause in the same 'device_type' region on a 'parallel' directive}}
3232
// expected-note@+2{{previous 'num_gangs' clause is here}}
3333
// expected-note@+1{{active 'device_type' clause here}}
3434
#pragma acc parallel device_type(*) num_gangs(1) num_gangs(2)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ 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}}
11+
// expected-error@+2{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause on a 'kernels' directive}}
1212
// expected-note@+1{{previous 'num_workers' clause is here}}
1313
#pragma acc kernels num_workers(1) num_workers(2)
1414
while(1);
1515

16-
// expected-error@+2{{OpenACC 'num_workers' clause cannot appear more than once on a 'parallel' directive}}
16+
// expected-error@+2{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause on a 'parallel' directive}}
1717
// expected-note@+1{{previous 'num_workers' clause is here}}
1818
#pragma acc parallel num_workers(1) num_workers(2)
1919
while(1);
2020

21-
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
21+
// expected-error@+3{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause in the same 'device_type' region on a 'kernels' directive}}
2222
// expected-note@+2{{previous 'num_workers' clause is here}}
2323
// expected-note@+1{{active 'device_type' clause here}}
2424
#pragma acc kernels num_workers(1) device_type(*) num_workers(1) num_workers(2)
2525
while(1);
2626

27-
// expected-error@+3{{OpenACC 'num_workers' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
27+
// expected-error@+3{{OpenACC clause 'num_workers' cannot combine with previous 'num_workers' clause in the same 'device_type' region on a 'parallel' directive}}
2828
// expected-note@+2{{previous 'num_workers' clause is here}}
2929
// expected-note@+1{{active 'device_type' clause here}}
3030
#pragma acc parallel device_type(*) num_workers(1) num_workers(2)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ 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}}
11+
// expected-error@+2{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause on a 'kernels' directive}}
1212
// expected-note@+1{{previous 'vector_length' clause is here}}
1313
#pragma acc kernels vector_length(1) vector_length(2)
1414
while(1);
1515

16-
// expected-error@+2{{OpenACC 'vector_length' clause cannot appear more than once on a 'parallel' directive}}
16+
// expected-error@+2{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause on a 'parallel' directive}}
1717
// expected-note@+1{{previous 'vector_length' clause is here}}
1818
#pragma acc parallel vector_length(1) vector_length(2)
1919
while(1);
2020

21-
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'kernels' directive}}
21+
// expected-error@+3{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause in the same 'device_type' region on a 'kernels' directive}}
2222
// expected-note@+2{{previous 'vector_length' clause is here}}
2323
// expected-note@+1{{active 'device_type' clause here}}
2424
#pragma acc kernels vector_length(1) device_type(*) vector_length(1) vector_length(2)
2525
while(1);
2626

27-
// expected-error@+3{{OpenACC 'vector_length' clause cannot appear more than once in a 'device_type' region on a 'parallel' directive}}
27+
// expected-error@+3{{OpenACC clause 'vector_length' cannot combine with previous 'vector_length' clause in the same 'device_type' region on a 'parallel' directive}}
2828
// expected-note@+2{{previous 'vector_length' clause is here}}
2929
// expected-note@+1{{active 'device_type' clause here}}
3030
#pragma acc parallel device_type(*) vector_length(1) vector_length(2)

0 commit comments

Comments
 (0)