[clang] dd1e8aa - [OpenACC] Enable 'if' and 'if_present' for 'update' construct
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 7 08:20:32 PST 2025
Author: erichkeane
Date: 2025-01-07T08:20:20-08:00
New Revision: dd1e8aa09c0ab453a0566165b68e6a62fcd055e1
URL: https://github.com/llvm/llvm-project/commit/dd1e8aa09c0ab453a0566165b68e6a62fcd055e1
DIFF: https://github.com/llvm/llvm-project/commit/dd1e8aa09c0ab453a0566165b68e6a62fcd055e1.diff
LOG: [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.
Added:
Modified:
clang/lib/Sema/SemaOpenACC.cpp
clang/test/AST/ast-print-openacc-update-construct.cpp
clang/test/ParserOpenACC/parse-clauses.c
clang/test/SemaOpenACC/update-construct-ast.cpp
clang/test/SemaOpenACC/update-construct.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 1ab033cbbfc1a8..716749f08c5831 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -709,18 +709,11 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
OpenACCClause *SemaOpenACCClauseVisitor::VisitIfClause(
SemaOpenACC::OpenACCParsedClause &Clause) {
- // Restrictions only properly implemented on 'compute'/'combined'/'data'
- // constructs, and 'compute'/'combined'/'data' constructs are the only
- // constructs that can do anything with this yet, so skip/treat as
- // unimplemented in this case.
- if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
- return isNotImplemented();
-
// There is no prose in the standard that says duplicates aren't allowed,
// but this diagnostic is present in other compilers, as well as makes
// sense. Prose DOES exist for 'data' and 'host_data', 'set', 'enter data' and
// 'exit data' both don't, but other implmementations do this. OpenACC issue
- // 519 filed for the latter two.
+ // 519 filed for the latter two. Prose also exists for 'update'.
// GCC allows this on init/shutdown, presumably for good reason, so we do too.
if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Init &&
Clause.getDirectiveKind() != OpenACCDirectiveKind::Shutdown &&
@@ -1744,8 +1737,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitFinalizeClause(
OpenACCClause *SemaOpenACCClauseVisitor::VisitIfPresentClause(
SemaOpenACC::OpenACCParsedClause &Clause) {
- if (!isDirectiveKindImplemented(Clause.getDirectiveKind()))
- return isNotImplemented();
// There isn't anything to do here, this is only valid on one construct, and
// has no associated rules.
return OpenACCIfPresentClause::Create(Ctx, Clause.getBeginLoc(),
diff --git a/clang/test/AST/ast-print-openacc-update-construct.cpp b/clang/test/AST/ast-print-openacc-update-construct.cpp
index db9d1c0855c982..89210cc0124ca1 100644
--- a/clang/test/AST/ast-print-openacc-update-construct.cpp
+++ b/clang/test/AST/ast-print-openacc-update-construct.cpp
@@ -1,5 +1,10 @@
// RUN: %clang_cc1 -fopenacc -ast-print %s -o - | FileCheck %s
-void uses() {
+void uses(bool cond) {
// CHECK: #pragma acc update
#pragma acc update
+
+// CHECK: #pragma acc update if_present
+#pragma acc update if_present
+// CHECK: #pragma acc update if(cond)
+#pragma acc update if(cond)
}
diff --git a/clang/test/ParserOpenACC/parse-clauses.c b/clang/test/ParserOpenACC/parse-clauses.c
index 3da06c3af63f37..9b88c147d0faa2 100644
--- a/clang/test/ParserOpenACC/parse-clauses.c
+++ b/clang/test/ParserOpenACC/parse-clauses.c
@@ -347,16 +347,14 @@ void SelfUpdate() {
#pragma acc update self
for(int i = 0; i < 5;++i) {}
- // expected-error at +5{{use of undeclared identifier 'zero'}}
- // expected-error at +4{{expected ','}}
- // expected-error at +3{{expected expression}}
- // expected-warning at +2{{OpenACC clause 'self' not yet implemented, clause ignored}}
- // expected-warning at +1{{OpenACC clause 'if_present' not yet implemented, clause ignored}}
+ // expected-error at +4{{use of undeclared identifier 'zero'}}
+ // expected-error at +3{{expected ','}}
+ // expected-error at +2{{expected expression}}
+ // expected-warning at +1{{OpenACC clause 'self' not yet implemented, clause ignored}}
#pragma acc update self(zero : s.array[s.value : 5], s.value), if_present
for(int i = 0; i < 5;++i) {}
- // expected-warning at +2{{OpenACC clause 'self' not yet implemented, clause ignored}}
- // expected-warning at +1{{OpenACC clause 'if_present' not yet implemented, clause ignored}}
+ // expected-warning at +1{{OpenACC clause 'self' not yet implemented, clause ignored}}
#pragma acc update self(s.array[s.value : 5], s.value), if_present
for(int i = 0; i < 5;++i) {}
}
diff --git a/clang/test/SemaOpenACC/update-construct-ast.cpp b/clang/test/SemaOpenACC/update-construct-ast.cpp
index 0e793428ec9b82..097ca6fc97d405 100644
--- a/clang/test/SemaOpenACC/update-construct-ast.cpp
+++ b/clang/test/SemaOpenACC/update-construct-ast.cpp
@@ -6,12 +6,26 @@
#ifndef PCH_HELPER
#define PCH_HELPER
+
+int some_int();
+long some_long();
+
void NormalFunc() {
// CHECK-LABEL: NormalFunc
// CHECK-NEXT: CompoundStmt
-#pragma acc update
+#pragma acc update if_present if (some_int() < some_long())
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
+ // CHECK-NEXT: if_present clause
+ // CHECK-NEXT: if clause
+ // CHECK-NEXT: BinaryOperator{{.*}}'bool' '<'
+ // CHECK-NEXT: ImplicitCastExpr{{.*}}'long'
+ // CHECK-NEXT: CallExpr{{.*}}'int'
+ // CHECK-NEXT: ImplicitCastExpr
+ // CHECK-NEXT: DeclRefExpr{{.*}}'some_int' 'int ()'
+ // CHECK-NEXT: CallExpr{{.*}} 'long'
+ // CHECK-NEXT: ImplicitCastExpr
+ // CHECK-NEXT: DeclRefExpr{{.*}}'some_long' 'long ()'
}
template<typename T>
@@ -22,8 +36,14 @@ void TemplFunc(T t) {
// CHECK-NEXT: ParmVarDecl{{.*}} t 'T'
// CHECK-NEXT: CompoundStmt
-#pragma acc update
+#pragma acc update if_present if (T::value < t)
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
+ // CHECK-NEXT: if_present clause
+ // CHECK-NEXT: if clause
+ // CHECK-NEXT: BinaryOperator{{.*}}'<dependent type>' '<'
+ // CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>'
+ // CHECK-NEXT: NestedNameSpecifier TypeSpec 'T'
+ // CHECK-NEXT: DeclRefExpr{{.*}}'t' 'T'
// Instantiation:
// CHECK-NEXT: FunctionDecl{{.*}} TemplFunc 'void (SomeStruct)' implicit_instantiation
@@ -34,6 +54,16 @@ void TemplFunc(T t) {
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: OpenACCUpdateConstruct{{.*}}update
+ // CHECK-NEXT: if_present clause
+ // CHECK-NEXT: if clause
+ // CHECK-NEXT: BinaryOperator{{.*}}'bool' '<'
+ // CHECK-NEXT: ImplicitCastExpr {{.*}}'unsigned int'
+ // CHECK-NEXT: DeclRefExpr{{.*}}'value' 'const unsigned int'
+ // CHECK-NEXT: NestedNameSpecifier TypeSpec 'SomeStruct'
+ // CHECK-NEXT: ImplicitCastExpr {{.*}}'unsigned int'
+ // CHECK-NEXT: CXXMemberCallExpr{{.*}}'unsigned int'
+ // CHECK-NEXT: MemberExpr{{.*}}.operator unsigned int
+ // CHECk-NEXT: DeclRefExpr{{.*}}'t' 'SomeStruct'
}
struct SomeStruct{
diff --git a/clang/test/SemaOpenACC/update-construct.cpp b/clang/test/SemaOpenACC/update-construct.cpp
index 3bada827a7a3cd..c9998cdc5ff14d 100644
--- a/clang/test/SemaOpenACC/update-construct.cpp
+++ b/clang/test/SemaOpenACC/update-construct.cpp
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 %s -fopenacc -verify
+struct NotConvertible{} NC;
void uses() {
int Var;
// expected-warning at +2{{OpenACC clause 'async' not yet implemented}}
@@ -11,10 +12,8 @@ void uses() {
// expected-warning at +2{{OpenACC clause 'self' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
#pragma acc update self(Var) device_type(I)
- // expected-warning at +2{{OpenACC clause 'if' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'self' not yet implemented}}
#pragma acc update if(true) self(Var)
- // expected-warning at +2{{OpenACC clause 'if_present' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'self' not yet implemented}}
#pragma acc update if_present self(Var)
// expected-warning at +1{{OpenACC clause 'self' not yet implemented}}
@@ -30,13 +29,11 @@ void uses() {
// expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
#pragma acc update self(Var) device_type(I) device_type(I)
- // expected-warning at +3{{OpenACC clause 'self' not yet implemented}}
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'if' not yet implemented}}
+ // expected-warning at +2{{OpenACC clause 'self' not yet implemented}}
+ // expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
#pragma acc update self(Var) device_type(I) if(true)
- // expected-warning at +3{{OpenACC clause 'self' not yet implemented}}
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'if_present' not yet implemented}}
+ // expected-warning at +2{{OpenACC clause 'self' not yet implemented}}
+ // expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
#pragma acc update self(Var) device_type(I) if_present
// expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'self' not yet implemented}}
@@ -65,14 +62,15 @@ void uses() {
#pragma acc update wait
// expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
#pragma acc update device_type(I)
- // expected-warning at +1{{OpenACC clause 'if' not yet implemented}}
#pragma acc update if(true)
- // expected-warning at +1{{OpenACC clause 'if_present' not yet implemented}}
#pragma acc update if_present
- // TODO: OpenACC: There should only be a max of 1 'if'.
- // expected-warning at +2{{OpenACC clause 'if' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'if' not yet implemented}}
+ // expected-error at +2{{value of type 'struct NotConvertible' is not contextually convertible to 'bool'}}
+ // expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
+#pragma acc update if (NC) device_type(I)
+
+ // expected-error at +2{{OpenACC 'if' clause cannot appear more than once on a 'update' directive}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc update if(true) if (false)
// TODO: OpenACC: There is restrictions on the contents of a 'varlist', so
More information about the cfe-commits
mailing list