Skip to content

Commit 666eee0

Browse files
committed
[OpenACC] enable 'device_type' for the 'update' construct
This has a similar restriction to 'set' in that only 'async' and 'wait' are disallowed, so this implements that restriction and enables 'device_type'.
1 parent ac604b2 commit 666eee0

File tree

4 files changed

+53
-38
lines changed

4 files changed

+53
-38
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,9 @@ bool checkAlreadyHasClauseOfKind(
498498
bool checkValidAfterDeviceType(
499499
SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
500500
const SemaOpenACC::OpenACCParsedClause &NewClause) {
501-
// This is only a requirement on compute, combined, data and loop constructs
502-
// so far, so this is fine otherwise.
503-
if (!isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind()) &&
504-
!isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind()) &&
505-
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
506-
NewClause.getDirectiveKind() != OpenACCDirectiveKind::Data)
501+
// This is implemented for everything but 'routine', so treat as 'fine' for
502+
// that.
503+
if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Routine)
507504
return false;
508505

509506
// OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
@@ -578,6 +575,21 @@ bool checkValidAfterDeviceType(
578575
default:
579576
break;
580577
}
578+
} else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Set ||
579+
NewClause.getDirectiveKind() == OpenACCDirectiveKind::Init ||
580+
NewClause.getDirectiveKind() == OpenACCDirectiveKind::Shutdown) {
581+
// There are no restrictions on 'set', 'init', or 'shutdown'.
582+
return false;
583+
} else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
584+
// OpenACC3.3 section 2.14.4: Only the async and wait clauses may follow a
585+
// device_type clause.
586+
switch (NewClause.getClauseKind()) {
587+
case OpenACCClauseKind::Async:
588+
case OpenACCClauseKind::Wait:
589+
return false;
590+
default:
591+
break;
592+
}
581593
}
582594
S.Diag(NewClause.getBeginLoc(), diag::err_acc_clause_after_device_type)
583595
<< NewClause.getClauseKind() << DeviceTypeClause.getClauseKind()
@@ -1178,11 +1190,8 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
11781190

11791191
OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
11801192
SemaOpenACC::OpenACCParsedClause &Clause) {
1181-
// Restrictions only properly implemented on 'compute', 'combined', 'data' and
1182-
// 'loop' constructs, and 'compute'/'combined'/'data'/'loop' constructs are
1183-
// the only construct that can do anything with this yet, so skip/treat as
1184-
// unimplemented in this case.
1185-
if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1193+
// Restrictions implemented properly on everything except 'routine'.
1194+
if (Clause.getDirectiveKind() == OpenACCDirectiveKind::Routine)
11861195
return isNotImplemented();
11871196

11881197
// OpenACC 3.3 2.14.3: Two instances of the same clause may not appear on the

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ void uses(bool cond) {
2929

3030
// CHECK: #pragma acc update wait(devnum: I : queues: *iPtr, I) if(I == array[I]) async(I)
3131
#pragma acc update wait(devnum:I:queues:*iPtr, I) if(I == array[I]) async(I)
32+
33+
// CHECK: #pragma acc update device_type(I) dtype(H)
34+
#pragma acc update device_type(I) dtype(H)
35+
36+
// CHECK: #pragma acc update device_type(J) dtype(K)
37+
#pragma acc update device_type(J) dtype(K)
3238
}

clang/test/SemaOpenACC/update-construct-ast.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ void NormalFunc() {
2727
// CHECK-NEXT: ImplicitCastExpr
2828
// CHECK-NEXT: DeclRefExpr{{.*}}'some_long' 'long ()'
2929

30-
#pragma acc update wait async
30+
#pragma acc update wait async device_type(A) dtype(B)
3131
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
3232
// CHECK-NEXT: wait clause
3333
// CHECK-NEXT: <<<NULL>>>
3434
// CHECK-NEXT: async clause
35+
// CHECK-NEXT: device_type(A)
36+
// CHECK-NEXT: dtype(B)
3537
#pragma acc update wait(some_int(), some_long()) async(some_int())
3638
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
3739
// CHECK-NEXT: wait clause
@@ -87,11 +89,13 @@ void TemplFunc(T t) {
8789
// CHECK-NEXT: NestedNameSpecifier TypeSpec 'T'
8890
// CHECK-NEXT: DeclRefExpr{{.*}}'t' 'T'
8991

90-
#pragma acc update wait async
92+
#pragma acc update wait async device_type(T) dtype(U)
9193
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
9294
// CHECK-NEXT: wait clause
9395
// CHECK-NEXT: <<<NULL>>>
9496
// CHECK-NEXT: async clause
97+
// CHECK-NEXT: device_type(T)
98+
// CHECK-NEXT: dtype(U)
9599
#pragma acc update wait(T::value, t) async(T::value)
96100
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
97101
// CHECK-NEXT: wait clause
@@ -144,6 +148,8 @@ void TemplFunc(T t) {
144148
// CHECK-NEXT: wait clause
145149
// CHECK-NEXT: <<<NULL>>>
146150
// CHECK-NEXT: async clause
151+
// CHECK-NEXT: device_type(T)
152+
// CHECK-NEXT: dtype(U)
147153

148154
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
149155
// CHECK-NEXT: wait clause

clang/test/SemaOpenACC/update-construct.cpp

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ void uses() {
88
#pragma acc update async self(Var)
99
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
1010
#pragma acc update wait self(Var)
11-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
12-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
11+
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
1312
#pragma acc update self(Var) device_type(I)
1413
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
1514
#pragma acc update if(true) self(Var)
@@ -22,46 +21,41 @@ void uses() {
2221
// expected-warning@+1{{OpenACC clause 'device' not yet implemented}}
2322
#pragma acc update device(Var)
2423

25-
// TODO: OpenACC: These all should diagnose as they aren't allowed after
26-
// device_type.
27-
// expected-warning@+3{{OpenACC clause 'self' not yet implemented}}
28-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
29-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
30-
#pragma acc update self(Var) device_type(I) device_type(I)
31-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
32-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
24+
// expected-warning@+3{{OpenACC clause 'self' not yet implemented}}
25+
// expected-error@+2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'update' construct}}
26+
// expected-note@+1{{previous clause is here}}
3327
#pragma acc update self(Var) device_type(I) if(true)
34-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
35-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
28+
// expected-warning@+3{{OpenACC clause 'self' not yet implemented}}
29+
// expected-error@+2{{OpenACC clause 'if_present' may not follow a 'device_type' clause in a 'update' construct}}
30+
// expected-note@+1{{previous clause is here}}
3631
#pragma acc update self(Var) device_type(I) if_present
37-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
38-
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
32+
// expected-error@+2{{OpenACC clause 'self' may not follow a 'device_type' clause in a 'update' construct}}
33+
// expected-note@+1{{previous clause is here}}
3934
#pragma acc update device_type(I) self(Var)
40-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
41-
// expected-warning@+1{{OpenACC clause 'host' not yet implemented}}
35+
// expected-error@+2{{OpenACC clause 'host' may not follow a 'device_type' clause in a 'update' construct}}
36+
// expected-note@+1{{previous clause is here}}
4237
#pragma acc update device_type(I) host(Var)
43-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
44-
// expected-warning@+1{{OpenACC clause 'device' not yet implemented}}
38+
// expected-error@+2{{OpenACC clause 'device' may not follow a 'device_type' clause in a 'update' construct}}
39+
// expected-note@+1{{previous clause is here}}
4540
#pragma acc update device_type(I) device(Var)
4641
// These 2 are OK.
47-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
48-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
42+
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
4943
#pragma acc update self(Var) device_type(I) async
50-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
51-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
44+
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
5245
#pragma acc update self(Var) device_type(I) wait
46+
// Unless otherwise specified, we assume 'device_type' can happen after itself.
47+
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
48+
#pragma acc update self(Var) device_type(I) device_type(I)
5349

5450
// TODO: OpenACC: These should diagnose because there isn't at least 1 of
5551
// 'self', 'host', or 'device'.
5652
#pragma acc update async
5753
#pragma acc update wait
58-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
5954
#pragma acc update device_type(I)
6055
#pragma acc update if(true)
6156
#pragma acc update if_present
6257

63-
// expected-error@+2{{value of type 'struct NotConvertible' is not contextually convertible to 'bool'}}
64-
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
58+
// expected-error@+1{{value of type 'struct NotConvertible' is not contextually convertible to 'bool'}}
6559
#pragma acc update if (NC) device_type(I)
6660

6761
// expected-error@+2{{OpenACC 'if' clause cannot appear more than once on a 'update' directive}}

0 commit comments

Comments
 (0)