Skip to content

Commit 8eec301

Browse files
committed
[OpenACC] Implement 'device_type' for 'data' construct
Semantically this is identical to all other constructs with this tag, except in this case the 'wait' and 'async' are the only ones allowed after it. This patch implements that rule using the existing infrastructure.
1 parent c95af08 commit 8eec301

File tree

5 files changed

+138
-29
lines changed

5 files changed

+138
-29
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,12 @@ bool checkAlreadyHasClauseOfKind(
435435
bool checkValidAfterDeviceType(
436436
SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
437437
const SemaOpenACC::OpenACCParsedClause &NewClause) {
438-
// This is only a requirement on compute and loop constructs so far, so this
439-
// is fine otherwise.
438+
// This is only a requirement on compute, combined, data and loop constructs
439+
// so far, so this is fine otherwise.
440440
if (!isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind()) &&
441441
!isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind()) &&
442-
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
442+
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
443+
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Data)
443444
return false;
444445

445446
// OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
@@ -504,6 +505,16 @@ bool checkValidAfterDeviceType(
504505
default:
505506
break;
506507
}
508+
} else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Data) {
509+
// OpenACC3.3 section 2.6.5: Only the async and wait clauses may follow a
510+
// device_type clause.
511+
switch (NewClause.getClauseKind()) {
512+
case OpenACCClauseKind::Async:
513+
case OpenACCClauseKind::Wait:
514+
return false;
515+
default:
516+
break;
517+
}
507518
}
508519
S.Diag(NewClause.getBeginLoc(), diag::err_acc_clause_after_device_type)
509520
<< NewClause.getClauseKind() << DeviceTypeClause.getClauseKind()
@@ -1067,12 +1078,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
10671078

10681079
OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
10691080
SemaOpenACC::OpenACCParsedClause &Clause) {
1070-
// Restrictions only properly implemented on 'compute', 'combined', and
1071-
// 'loop' constructs, and 'compute'/'combined'/'loop' constructs are the only
1072-
// construct that can do anything with this yet, so skip/treat as
1081+
// Restrictions only properly implemented on 'compute', 'combined', 'data' and
1082+
// 'loop' constructs, and 'compute'/'combined'/'data'/'loop' constructs are
1083+
// the only construct that can do anything with this yet, so skip/treat as
10731084
// unimplemented in this case.
10741085
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
10751086
Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
1087+
Clause.getDirectiveKind() != OpenACCDirectiveKind::Data &&
10761088
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
10771089
return isNotImplemented();
10781090

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ void foo() {
1010
// CHECK-NOT: default(none)
1111
#pragma acc data default(none)
1212
;
13+
14+
// CHECK: #pragma acc data device_type(int)
15+
#pragma acc data device_type(int)
16+
;
17+
1318
// CHECK: #pragma acc enter data
1419
// CHECK-NOT: copyin(Var)
1520
#pragma acc enter data copyin(Var)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
template<typename T>
10+
void TemplUses() {
11+
// CHECK: FunctionTemplateDecl{{.*}}TemplUses
12+
// CHECK-NEXT: TemplateTypeParmDecl{{.*}}T
13+
// CHECK-NEXT: FunctionDecl{{.*}}TemplUses
14+
// CHECK-NEXT: CompoundStmt
15+
16+
#pragma acc data device_type(T) dtype(T)
17+
;
18+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
19+
// CHECK-NEXT: device_type(T)
20+
// CHECK-NEXT: dtype(T)
21+
// CHECK-NEXT: NullStmt
22+
23+
// Instantiations
24+
// CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void ()' implicit_instantiation
25+
// CHECK-NEXT: TemplateArgument type 'int'
26+
// CHECK-NEXT: BuiltinType{{.*}} 'int'
27+
// CHECK-NEXT: CompoundStmt
28+
29+
// Argument to 'device-type' is just an identifier, so we don't transform it.
30+
// CHECK-NEXT: OpenACCDataConstruct{{.*}} data
31+
// CHECK-NEXT: device_type(T)
32+
// CHECK-NEXT: dtype(T)
33+
// CHECK-NEXT: NullStmt
34+
}
35+
void Inst() {
36+
TemplUses<int>();
37+
}
38+
39+
#endif // PCH_HELPER
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %clang_cc1 %s -fopenacc -verify
2+
3+
void uses() {
4+
int Var;
5+
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
6+
#pragma acc data device_type(foo) async
7+
;
8+
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented}}
9+
#pragma acc data device_type(foo) wait
10+
;
11+
#pragma acc data device_type(foo) dtype(false)
12+
;
13+
#pragma acc data dtype(foo) device_type(false)
14+
;
15+
16+
// expected-error@+2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'data' construct}}
17+
// expected-note@+1{{previous clause is here}}
18+
#pragma acc data device_type(foo) if(1)
19+
;
20+
// expected-error@+2{{OpenACC clause 'copy' may not follow a 'device_type' clause in a 'data' construct}}
21+
// expected-note@+1{{previous clause is here}}
22+
#pragma acc data device_type(foo) copy(Var)
23+
;
24+
// expected-error@+2{{OpenACC clause 'copyin' may not follow a 'device_type' clause in a 'data' construct}}
25+
// expected-note@+1{{previous clause is here}}
26+
#pragma acc data device_type(foo) copyin(Var)
27+
;
28+
// expected-error@+2{{OpenACC clause 'copyout' may not follow a 'device_type' clause in a 'data' construct}}
29+
// expected-note@+1{{previous clause is here}}
30+
#pragma acc data device_type(foo) copyout(Var)
31+
;
32+
// expected-error@+2{{OpenACC clause 'create' may not follow a 'device_type' clause in a 'data' construct}}
33+
// expected-note@+1{{previous clause is here}}
34+
#pragma acc data device_type(foo) create(Var)
35+
;
36+
// expected-error@+2{{OpenACC clause 'no_create' may not follow a 'device_type' clause in a 'data' construct}}
37+
// expected-note@+1{{previous clause is here}}
38+
#pragma acc data device_type(foo) no_create(Var)
39+
;
40+
// expected-error@+2{{OpenACC clause 'present' may not follow a 'device_type' clause in a 'data' construct}}
41+
// expected-note@+1{{previous clause is here}}
42+
#pragma acc data device_type(foo) present(Var)
43+
;
44+
// expected-error@+2{{OpenACC clause 'deviceptr' may not follow a 'device_type' clause in a 'data' construct}}
45+
// expected-note@+1{{previous clause is here}}
46+
#pragma acc data device_type(foo) deviceptr(Var)
47+
;
48+
// expected-error@+2{{OpenACC clause 'attach' may not follow a 'device_type' clause in a 'data' construct}}
49+
// expected-note@+1{{previous clause is here}}
50+
#pragma acc data device_type(foo) attach(Var)
51+
;
52+
// expected-error@+2{{OpenACC clause 'default' may not follow a 'device_type' clause in a 'data' construct}}
53+
// expected-note@+1{{previous clause is here}}
54+
#pragma acc data device_type(foo) default(none)
55+
;
56+
}

clang/test/SemaOpenACC/data-construct.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void AtLeastOneOf() {
6464
#pragma acc data wait
6565
;
6666

67-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
6867
#pragma acc data device_type(*)
6968
;
7069
#pragma acc data
@@ -132,51 +131,49 @@ void DataRules() {
132131
// OpenACC TODO: Only 'async' and 'wait' are permitted after a device_type, so
133132
// the rest of these should diagnose.
134133

135-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
136-
// expected-warning@+1{{OpenACC clause 'copy' not yet implemented}}
134+
// expected-error@+2{{OpenACC clause 'copy' may not follow a 'device_type' clause in a 'data' construct}}
135+
// expected-note@+1{{previous clause is here}}
137136
#pragma acc data device_type(*) copy(Var)
138137
;
139-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
140-
// expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}}
138+
// expected-error@+2{{OpenACC clause 'copyin' may not follow a 'device_type' clause in a 'data' construct}}
139+
// expected-note@+1{{previous clause is here}}
141140
#pragma acc data device_type(*) copyin(Var)
142141
;
143-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
144-
// expected-warning@+1{{OpenACC clause 'copyout' not yet implemented}}
142+
// expected-error@+2{{OpenACC clause 'copyout' may not follow a 'device_type' clause in a 'data' construct}}
143+
// expected-note@+1{{previous clause is here}}
145144
#pragma acc data device_type(*) copyout(Var)
146145
;
147-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
148-
// expected-warning@+1{{OpenACC clause 'create' not yet implemented}}
146+
// expected-error@+2{{OpenACC clause 'create' may not follow a 'device_type' clause in a 'data' construct}}
147+
// expected-note@+1{{previous clause is here}}
149148
#pragma acc data device_type(*) create(Var)
150149
;
151-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
152-
// expected-warning@+1{{OpenACC clause 'no_create' not yet implemented}}
150+
// expected-error@+2{{OpenACC clause 'no_create' may not follow a 'device_type' clause in a 'data' construct}}
151+
// expected-note@+1{{previous clause is here}}
153152
#pragma acc data device_type(*) no_create(Var)
154153
;
155-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
156-
// expected-warning@+1{{OpenACC clause 'present' not yet implemented}}
154+
// expected-error@+2{{OpenACC clause 'present' may not follow a 'device_type' clause in a 'data' construct}}
155+
// expected-note@+1{{previous clause is here}}
157156
#pragma acc data device_type(*) present(Var)
158157
;
159-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
160-
// expected-warning@+1{{OpenACC clause 'deviceptr' not yet implemented}}
158+
// expected-error@+2{{OpenACC clause 'deviceptr' may not follow a 'device_type' clause in a 'data' construct}}
159+
// expected-note@+1{{previous clause is here}}
161160
#pragma acc data device_type(*) deviceptr(Var)
162161
;
163-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
164-
// expected-warning@+1{{OpenACC clause 'attach' not yet implemented}}
162+
// expected-error@+2{{OpenACC clause 'attach' may not follow a 'device_type' clause in a 'data' construct}}
163+
// expected-note@+1{{previous clause is here}}
165164
#pragma acc data device_type(*) attach(Var)
166165
;
167-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
168-
// expected-warning@+1{{OpenACC clause 'default' not yet implemented}}
166+
// expected-error@+2{{OpenACC clause 'default' may not follow a 'device_type' clause in a 'data' construct}}
167+
// expected-note@+1{{previous clause is here}}
169168
#pragma acc data device_type(*) default(none)
170169
;
171-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
172-
// expected-warning@+1{{OpenACC clause 'if' not yet implemented}}
170+
// expected-error@+2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'data' construct}}
171+
// expected-note@+1{{previous clause is here}}
173172
#pragma acc data device_type(*) if(Var)
174173
;
175-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
176174
// expected-warning@+1{{OpenACC clause 'async' not yet implemented}}
177175
#pragma acc data device_type(*) async
178176
;
179-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
180177
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented}}
181178
#pragma acc data device_type(*) wait
182179
;

0 commit comments

Comments
 (0)