Skip to content

Commit f0f8434

Browse files
committed
[OpenACC] Implement sema for 'async' on 'data' constructs
This also is a clause that doesn't have any special rules, so this patch enables it and adds tests.
1 parent c047a5b commit f0f8434

File tree

7 files changed

+125
-19
lines changed

7 files changed

+125
-19
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitVectorLengthClause(
876876

877877
OpenACCClause *SemaOpenACCClauseVisitor::VisitAsyncClause(
878878
SemaOpenACC::OpenACCParsedClause &Clause) {
879-
// Restrictions only properly implemented on 'compute'/'combined' constructs,
880-
// and 'compute'/'combined' constructs are the only construct that can do
881-
// anything with this yet, so skip/treat as unimplemented in this case.
879+
// Restrictions only properly implemented on 'compute'/'combined'/'data'
880+
// constructs, and 'compute'/'combined'/'data' constructs are the only
881+
// construct that can do anything with this yet, so skip/treat as
882+
// unimplemented in this case.
882883
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
883-
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
884+
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()) &&
885+
!isOpenACCDataDirectiveKind(Clause.getDirectiveKind()))
884886
return isNotImplemented();
885887

886888
// There is no prose in the standard that says duplicates aren't allowed,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,12 @@ void foo() {
4343
// CHECK: #pragma acc host_data if(i == array[1])
4444
#pragma acc host_data use_device(Var) if(i == array[1])
4545
;
46+
47+
// CHECK: #pragma acc data async(i)
48+
#pragma acc data default(none) async(i)
49+
;
50+
// CHECK: #pragma acc enter data async(i)
51+
#pragma acc enter data copyin(i) async(i)
52+
// CHECK: #pragma acc exit data async
53+
#pragma acc exit data copyout(i) async
4654
}

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,25 +521,21 @@ void VarListClauses() {
521521
#pragma acc serial firstprivate(s.array[s.value : 5], s.value), self
522522
for(int i = 0; i < 5;++i) {}
523523

524-
// expected-error@+3{{expected ','}}
525-
// expected-warning@+2{{OpenACC clause 'delete' not yet implemented, clause ignored}}
526-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented, clause ignored}}
524+
// expected-error@+2{{expected ','}}
525+
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented, clause ignored}}
527526
#pragma acc exit data delete(s.array[s.value] s.array[s.value :5] ) async
528527
for(int i = 0; i < 5;++i) {}
529528

530-
// expected-warning@+2{{OpenACC clause 'delete' not yet implemented, clause ignored}}
531-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented, clause ignored}}
529+
// expected-warning@+1{{OpenACC clause 'delete' not yet implemented, clause ignored}}
532530
#pragma acc exit data delete(s.array[s.value : 5], s.value),async
533531
for(int i = 0; i < 5;++i) {}
534532

535-
// expected-error@+3{{expected ','}}
536-
// expected-warning@+2{{OpenACC clause 'use_device' not yet implemented, clause ignored}}
537-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented, clause ignored}}
533+
// expected-error@+2{{expected ','}}
534+
// expected-warning@+1{{OpenACC clause 'use_device' not yet implemented, clause ignored}}
538535
#pragma acc exit data use_device(s.array[s.value] s.array[s.value :5] ),async
539536
for(int i = 0; i < 5;++i) {}
540537

541-
// expected-warning@+2{{OpenACC clause 'use_device' not yet implemented, clause ignored}}
542-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented, clause ignored}}
538+
// expected-warning@+1{{OpenACC clause 'use_device' not yet implemented, clause ignored}}
543539
#pragma acc exit data use_device(s.array[s.value : 5], s.value), async
544540
for(int i = 0; i < 5;++i) {}
545541

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %clang_cc1 %s -fopenacc -ast-dump | FileCheck %s
2+
3+
// Test this with PCH.
4+
// RUN: %clang_cc1 %s -fopenacc -emit-pch -o %t %s
5+
// RUN: %clang_cc1 %s -fopenacc -include-pch %t -ast-dump-all | FileCheck %s
6+
#ifndef PCH_HELPER
7+
#define PCH_HELPER
8+
9+
int some_int();
10+
11+
template<typename T>
12+
void TemplUses() {
13+
// CHECK: FunctionTemplateDecl{{.*}}TemplUses
14+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}T
15+
// CHECK-NEXT: FunctionDecl{{.*}}TemplUses
16+
// CHECK-NEXT: CompoundStmt
17+
18+
#pragma acc data async(some_int())
19+
;
20+
// CHECK-NEXT: OpenACCDataConstruct{{.*}}data
21+
// CHECK-NEXT: async clause
22+
// CHECK-NEXT: CallExpr{{.*}}'int'
23+
// CHECK-NEXT: ImplicitCastExpr
24+
// CHECK-NEXT: DeclRefExpr{{.*}}'some_int' 'int ()'
25+
// CHECK-NEXT: NullStmt
26+
#pragma acc enter data async(T{})
27+
// CHECK-NEXT: OpenACCEnterDataConstruct{{.*}}enter data
28+
// CHECK-NEXT: async clause
29+
// CHECK-NEXT: CXXUnresolvedConstructExpr{{.*}} 'T' 'T' list
30+
// CHECK-NEXT: InitListExpr{{.*}}'void'
31+
#pragma acc exit data async
32+
// CHECK-NEXT: OpenACCExitDataConstruct{{.*}}exit data
33+
// CHECK-NEXT: async clause
34+
35+
// Instantiations
36+
// CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void ()' implicit_instantiation
37+
// CHECK-NEXT: TemplateArgument type 'int'
38+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
39+
// CHECK-NEXT: CompoundStmt
40+
41+
// CHECK-NEXT: OpenACCDataConstruct{{.*}}data
42+
// CHECK-NEXT: async clause
43+
// CHECK-NEXT: CallExpr{{.*}}'int'
44+
// CHECK-NEXT: ImplicitCastExpr
45+
// CHECK-NEXT: DeclRefExpr{{.*}}'some_int' 'int ()'
46+
// CHECK-NEXT: NullStmt
47+
48+
// CHECK-NEXT: OpenACCEnterDataConstruct{{.*}}enter data
49+
// CHECK-NEXT: async clause
50+
// CHECK-NEXT: CXXFunctionalCastExpr
51+
// CHECK-NEXT: InitListExpr{{.*}}'int'
52+
53+
// CHECK-NEXT: OpenACCExitDataConstruct{{.*}}exit data
54+
// CHECK-NEXT: async clause
55+
}
56+
void Inst() {
57+
TemplUses<int>();
58+
}
59+
60+
61+
#endif // PCH_HELPER
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
void Test() {
4+
int I;
5+
struct NotConvertible{} NC;
6+
// No special rules for this clause on the data constructs, so not much to
7+
// test that isn't covered by combined/compute.
8+
// expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}}
9+
#pragma acc data copyin(I) async(I)
10+
;
11+
// expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}}
12+
#pragma acc enter data copyin(I) async(I)
13+
// expected-warning@+1{{OpenACC clause 'copyout' not yet implemented}}
14+
#pragma acc exit data copyout(I) async(I)
15+
// expected-warning@+2{{OpenACC clause 'use_device' not yet implemented}}
16+
// expected-error@+1{{OpenACC 'async' clause is not valid on 'host_data' directive}}
17+
#pragma acc host_data use_device(I) async(I)
18+
;
19+
20+
// expected-warning@+2{{OpenACC clause 'copyin' not yet implemented}}
21+
// expected-error@+1{{OpenACC clause 'async' requires expression of integer type ('struct NotConvertible' invalid)}}
22+
#pragma acc data copyin(NC) async(NC)
23+
;
24+
// expected-warning@+2{{OpenACC clause 'copyin' not yet implemented}}
25+
// expected-error@+1{{OpenACC clause 'async' requires expression of integer type ('struct NotConvertible' invalid)}}
26+
#pragma acc enter data copyin(NC) async(NC)
27+
// expected-warning@+2{{OpenACC clause 'copyout' not yet implemented}}
28+
// expected-error@+1{{OpenACC clause 'async' requires expression of integer type ('struct NotConvertible' invalid)}}
29+
#pragma acc exit data copyout(NC) async(NC)
30+
// expected-warning@+2{{OpenACC clause 'use_device' not yet implemented}}
31+
// expected-error@+1{{OpenACC clause 'async' requires expression of integer type ('struct NotConvertible' invalid)}}
32+
#pragma acc host_data use_device(NC) async(NC)
33+
;
34+
35+
// expected-warning@+3{{OpenACC clause 'copyin' not yet implemented}}
36+
// expected-error@+2{{OpenACC 'async' clause cannot appear more than once on a 'data' directive}}
37+
// expected-note@+1{{previous clause is here}}
38+
#pragma acc data copyin(I) async(I) async(I)
39+
;
40+
// expected-warning@+3{{OpenACC clause 'copyin' not yet implemented}}
41+
// expected-error@+2{{expected ')'}}
42+
// expected-note@+1{{to match this '('}}
43+
#pragma acc enter data copyin(I) async(I, I)
44+
}

clang/test/SemaOpenACC/data-construct-device_type-clause.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
void uses() {
44
int Var;
5-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
65
#pragma acc data device_type(foo) async
76
;
87
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented}}

clang/test/SemaOpenACC/data-construct.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void AtLeastOneOf() {
5555
#pragma acc data if(Var)
5656
;
5757

58-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
5958
#pragma acc data async
6059
;
6160

@@ -80,7 +79,6 @@ void AtLeastOneOf() {
8079
// they don't have at least one of the above clauses.
8180

8281
#pragma acc enter data if(Var)
83-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
8482
#pragma acc enter data async
8583
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented}}
8684
#pragma acc enter data wait
@@ -98,7 +96,6 @@ void AtLeastOneOf() {
9896
// they don't have at least one of the above clauses.
9997

10098
#pragma acc exit data if(Var)
101-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
10299
#pragma acc exit data async
103100
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented}}
104101
#pragma acc exit data wait
@@ -167,7 +164,6 @@ void DataRules() {
167164
// expected-note@+1{{previous clause is here}}
168165
#pragma acc data device_type(*) if(Var)
169166
;
170-
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
171167
#pragma acc data device_type(*) async
172168
;
173169
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented}}

0 commit comments

Comments
 (0)