Skip to content

Commit dd1e8aa

Browse files
committed
[OpenACC] Enable 'if' and 'if_present' for 'update' construct
The only restriction on 'if' is that only 1 can appear on an update construct, so this enforces that. 'if_present' has no restrictions.
1 parent db81e8c commit dd1e8aa

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -709,18 +709,11 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
709709

710710
OpenACCClause *SemaOpenACCClauseVisitor::VisitIfClause(
711711
SemaOpenACC::OpenACCParsedClause &Clause) {
712-
// Restrictions only properly implemented on 'compute'/'combined'/'data'
713-
// constructs, and 'compute'/'combined'/'data' constructs are the only
714-
// constructs that can do anything with this yet, so skip/treat as
715-
// unimplemented in this case.
716-
if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
717-
return isNotImplemented();
718-
719712
// There is no prose in the standard that says duplicates aren't allowed,
720713
// but this diagnostic is present in other compilers, as well as makes
721714
// sense. Prose DOES exist for 'data' and 'host_data', 'set', 'enter data' and
722715
// 'exit data' both don't, but other implmementations do this. OpenACC issue
723-
// 519 filed for the latter two.
716+
// 519 filed for the latter two. Prose also exists for 'update'.
724717
// GCC allows this on init/shutdown, presumably for good reason, so we do too.
725718
if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Init &&
726719
Clause.getDirectiveKind() != OpenACCDirectiveKind::Shutdown &&
@@ -1744,8 +1737,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitFinalizeClause(
17441737

17451738
OpenACCClause *SemaOpenACCClauseVisitor::VisitIfPresentClause(
17461739
SemaOpenACC::OpenACCParsedClause &Clause) {
1747-
if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
1748-
return isNotImplemented();
17491740
// There isn't anything to do here, this is only valid on one construct, and
17501741
// has no associated rules.
17511742
return OpenACCIfPresentClause::Create(Ctx, Clause.getBeginLoc(),
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
// RUN: %clang_cc1 -fopenacc -ast-print %s -o - | FileCheck %s
2-
void uses() {
2+
void uses(bool cond) {
33
// CHECK: #pragma acc update
44
#pragma acc update
5+
6+
// CHECK: #pragma acc update if_present
7+
#pragma acc update if_present
8+
// CHECK: #pragma acc update if(cond)
9+
#pragma acc update if(cond)
510
}

clang/test/ParserOpenACC/parse-clauses.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,14 @@ void SelfUpdate() {
347347
#pragma acc update self
348348
for(int i = 0; i < 5;++i) {}
349349

350-
// expected-error@+5{{use of undeclared identifier 'zero'}}
351-
// expected-error@+4{{expected ','}}
352-
// expected-error@+3{{expected expression}}
353-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented, clause ignored}}
354-
// expected-warning@+1{{OpenACC clause 'if_present' not yet implemented, clause ignored}}
350+
// expected-error@+4{{use of undeclared identifier 'zero'}}
351+
// expected-error@+3{{expected ','}}
352+
// expected-error@+2{{expected expression}}
353+
// expected-warning@+1{{OpenACC clause 'self' not yet implemented, clause ignored}}
355354
#pragma acc update self(zero : s.array[s.value : 5], s.value), if_present
356355
for(int i = 0; i < 5;++i) {}
357356

358-
// expected-warning@+2{{OpenACC clause 'self' not yet implemented, clause ignored}}
359-
// expected-warning@+1{{OpenACC clause 'if_present' not yet implemented, clause ignored}}
357+
// expected-warning@+1{{OpenACC clause 'self' not yet implemented, clause ignored}}
360358
#pragma acc update self(s.array[s.value : 5], s.value), if_present
361359
for(int i = 0; i < 5;++i) {}
362360
}

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,26 @@
66

77
#ifndef PCH_HELPER
88
#define PCH_HELPER
9+
10+
int some_int();
11+
long some_long();
12+
913
void NormalFunc() {
1014
// CHECK-LABEL: NormalFunc
1115
// CHECK-NEXT: CompoundStmt
1216

13-
#pragma acc update
17+
#pragma acc update if_present if (some_int() < some_long())
1418
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
19+
// CHECK-NEXT: if_present clause
20+
// CHECK-NEXT: if clause
21+
// CHECK-NEXT: BinaryOperator{{.*}}'bool' '<'
22+
// CHECK-NEXT: ImplicitCastExpr{{.*}}'long'
23+
// CHECK-NEXT: CallExpr{{.*}}'int'
24+
// CHECK-NEXT: ImplicitCastExpr
25+
// CHECK-NEXT: DeclRefExpr{{.*}}'some_int' 'int ()'
26+
// CHECK-NEXT: CallExpr{{.*}} 'long'
27+
// CHECK-NEXT: ImplicitCastExpr
28+
// CHECK-NEXT: DeclRefExpr{{.*}}'some_long' 'long ()'
1529
}
1630

1731
template<typename T>
@@ -22,8 +36,14 @@ void TemplFunc(T t) {
2236
// CHECK-NEXT: ParmVarDecl{{.*}} t 'T'
2337
// CHECK-NEXT: CompoundStmt
2438

25-
#pragma acc update
39+
#pragma acc update if_present if (T::value < t)
2640
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
41+
// CHECK-NEXT: if_present clause
42+
// CHECK-NEXT: if clause
43+
// CHECK-NEXT: BinaryOperator{{.*}}'<dependent type>' '<'
44+
// CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>'
45+
// CHECK-NEXT: NestedNameSpecifier TypeSpec 'T'
46+
// CHECK-NEXT: DeclRefExpr{{.*}}'t' 'T'
2747

2848
// Instantiation:
2949
// CHECK-NEXT: FunctionDecl{{.*}} TemplFunc 'void (SomeStruct)' implicit_instantiation
@@ -34,6 +54,16 @@ void TemplFunc(T t) {
3454
// CHECK-NEXT: CompoundStmt
3555

3656
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
57+
// CHECK-NEXT: if_present clause
58+
// CHECK-NEXT: if clause
59+
// CHECK-NEXT: BinaryOperator{{.*}}'bool' '<'
60+
// CHECK-NEXT: ImplicitCastExpr {{.*}}'unsigned int'
61+
// CHECK-NEXT: DeclRefExpr{{.*}}'value' 'const unsigned int'
62+
// CHECK-NEXT: NestedNameSpecifier TypeSpec 'SomeStruct'
63+
// CHECK-NEXT: ImplicitCastExpr {{.*}}'unsigned int'
64+
// CHECK-NEXT: CXXMemberCallExpr{{.*}}'unsigned int'
65+
// CHECK-NEXT: MemberExpr{{.*}}.operator unsigned int
66+
// CHECk-NEXT: DeclRefExpr{{.*}}'t' 'SomeStruct'
3767
}
3868

3969
struct SomeStruct{

clang/test/SemaOpenACC/update-construct.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 %s -fopenacc -verify
22

3+
struct NotConvertible{} NC;
34
void uses() {
45
int Var;
56
// expected-warning@+2{{OpenACC clause 'async' not yet implemented}}
@@ -11,10 +12,8 @@ void uses() {
1112
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
1213
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
1314
#pragma acc update self(Var) device_type(I)
14-
// expected-warning@+2{{OpenACC clause 'if' not yet implemented}}
1515
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
1616
#pragma acc update if(true) self(Var)
17-
// expected-warning@+2{{OpenACC clause 'if_present' not yet implemented}}
1817
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
1918
#pragma acc update if_present self(Var)
2019
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
@@ -30,13 +29,11 @@ void uses() {
3029
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
3130
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
3231
#pragma acc update self(Var) device_type(I) device_type(I)
33-
// expected-warning@+3{{OpenACC clause 'self' not yet implemented}}
34-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
35-
// expected-warning@+1{{OpenACC clause 'if' not yet implemented}}
32+
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
33+
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
3634
#pragma acc update self(Var) device_type(I) if(true)
37-
// expected-warning@+3{{OpenACC clause 'self' not yet implemented}}
38-
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
39-
// expected-warning@+1{{OpenACC clause 'if_present' not yet implemented}}
35+
// expected-warning@+2{{OpenACC clause 'self' not yet implemented}}
36+
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
4037
#pragma acc update self(Var) device_type(I) if_present
4138
// expected-warning@+2{{OpenACC clause 'device_type' not yet implemented}}
4239
// expected-warning@+1{{OpenACC clause 'self' not yet implemented}}
@@ -65,14 +62,15 @@ void uses() {
6562
#pragma acc update wait
6663
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
6764
#pragma acc update device_type(I)
68-
// expected-warning@+1{{OpenACC clause 'if' not yet implemented}}
6965
#pragma acc update if(true)
70-
// expected-warning@+1{{OpenACC clause 'if_present' not yet implemented}}
7166
#pragma acc update if_present
7267

73-
// TODO: OpenACC: There should only be a max of 1 'if'.
74-
// expected-warning@+2{{OpenACC clause 'if' not yet implemented}}
75-
// expected-warning@+1{{OpenACC clause 'if' not yet implemented}}
68+
// expected-error@+2{{value of type 'struct NotConvertible' is not contextually convertible to 'bool'}}
69+
// expected-warning@+1{{OpenACC clause 'device_type' not yet implemented}}
70+
#pragma acc update if (NC) device_type(I)
71+
72+
// expected-error@+2{{OpenACC 'if' clause cannot appear more than once on a 'update' directive}}
73+
// expected-note@+1{{previous clause is here}}
7674
#pragma acc update if(true) if (false)
7775

7876
// TODO: OpenACC: There is restrictions on the contents of a 'varlist', so

0 commit comments

Comments
 (0)