[clang] 8eec301 - [OpenACC] Implement 'device_type' for 'data' construct
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 08:37:25 PST 2024
Author: erichkeane
Date: 2024-12-12T08:37:20-08:00
New Revision: 8eec301fe3ac5fdcb4de4757806661b99c9e6580
URL: https://github.com/llvm/llvm-project/commit/8eec301fe3ac5fdcb4de4757806661b99c9e6580
DIFF: https://github.com/llvm/llvm-project/commit/8eec301fe3ac5fdcb4de4757806661b99c9e6580.diff
LOG: [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.
Added:
clang/test/SemaOpenACC/data-construct-device_type-ast.cpp
clang/test/SemaOpenACC/data-construct-device_type-clause.c
Modified:
clang/lib/Sema/SemaOpenACC.cpp
clang/test/AST/ast-print-openacc-data-construct.cpp
clang/test/SemaOpenACC/data-construct.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 5575dd730e5596..981a98d024a281 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -435,11 +435,12 @@ bool checkAlreadyHasClauseOfKind(
bool checkValidAfterDeviceType(
SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
const SemaOpenACC::OpenACCParsedClause &NewClause) {
- // This is only a requirement on compute and loop constructs so far, so this
- // is fine otherwise.
+ // This is only a requirement on compute, combined, data and loop constructs
+ // so far, so this is fine otherwise.
if (!isOpenACCComputeDirectiveKind(NewClause.getDirectiveKind()) &&
!isOpenACCCombinedDirectiveKind(NewClause.getDirectiveKind()) &&
- NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
+ NewClause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
+ NewClause.getDirectiveKind() != OpenACCDirectiveKind::Data)
return false;
// OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
@@ -504,6 +505,16 @@ bool checkValidAfterDeviceType(
default:
break;
}
+ } else if (NewClause.getDirectiveKind() == OpenACCDirectiveKind::Data) {
+ // OpenACC3.3 section 2.6.5: Only the async and wait clauses may follow a
+ // device_type clause.
+ switch (NewClause.getClauseKind()) {
+ case OpenACCClauseKind::Async:
+ case OpenACCClauseKind::Wait:
+ return false;
+ default:
+ break;
+ }
}
S.Diag(NewClause.getBeginLoc(), diag::err_acc_clause_after_device_type)
<< NewClause.getClauseKind() << DeviceTypeClause.getClauseKind()
@@ -1067,12 +1078,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause(
OpenACCClause *SemaOpenACCClauseVisitor::VisitDeviceTypeClause(
SemaOpenACC::OpenACCParsedClause &Clause) {
- // Restrictions only properly implemented on 'compute', 'combined', and
- // 'loop' constructs, and 'compute'/'combined'/'loop' constructs are the only
- // construct that can do anything with this yet, so skip/treat as
+ // Restrictions only properly implemented on 'compute', 'combined', 'data' and
+ // 'loop' constructs, and 'compute'/'combined'/'data'/'loop' constructs are
+ // the only construct that can do anything with this yet, so skip/treat as
// unimplemented in this case.
if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) &&
Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop &&
+ Clause.getDirectiveKind() != OpenACCDirectiveKind::Data &&
!isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()))
return isNotImplemented();
diff --git a/clang/test/AST/ast-print-openacc-data-construct.cpp b/clang/test/AST/ast-print-openacc-data-construct.cpp
index fc15add15c6b89..c65121317c099d 100644
--- a/clang/test/AST/ast-print-openacc-data-construct.cpp
+++ b/clang/test/AST/ast-print-openacc-data-construct.cpp
@@ -10,6 +10,11 @@ void foo() {
// CHECK-NOT: default(none)
#pragma acc data default(none)
;
+
+// CHECK: #pragma acc data device_type(int)
+#pragma acc data device_type(int)
+ ;
+
// CHECK: #pragma acc enter data
// CHECK-NOT: copyin(Var)
#pragma acc enter data copyin(Var)
diff --git a/clang/test/SemaOpenACC/data-construct-device_type-ast.cpp b/clang/test/SemaOpenACC/data-construct-device_type-ast.cpp
new file mode 100644
index 00000000000000..23f00490f0674f
--- /dev/null
+++ b/clang/test/SemaOpenACC/data-construct-device_type-ast.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -fopenacc -ast-dump | FileCheck %s
+
+// Test this with PCH.
+// RUN: %clang_cc1 %s -fopenacc -emit-pch -o %t %s
+// RUN: %clang_cc1 %s -fopenacc -include-pch %t -ast-dump-all | FileCheck %s
+#ifndef PCH_HELPER
+#define PCH_HELPER
+
+template<typename T>
+void TemplUses() {
+ // CHECK: FunctionTemplateDecl{{.*}}TemplUses
+ // CHECK-NEXT: TemplateTypeParmDecl{{.*}}T
+ // CHECK-NEXT: FunctionDecl{{.*}}TemplUses
+ // CHECK-NEXT: CompoundStmt
+
+#pragma acc data device_type(T) dtype(T)
+ ;
+ // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+ // CHECK-NEXT: device_type(T)
+ // CHECK-NEXT: dtype(T)
+ // CHECK-NEXT: NullStmt
+
+ // Instantiations
+ // CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void ()' implicit_instantiation
+ // CHECK-NEXT: TemplateArgument type 'int'
+ // CHECK-NEXT: BuiltinType{{.*}} 'int'
+ // CHECK-NEXT: CompoundStmt
+
+ // Argument to 'device-type' is just an identifier, so we don't transform it.
+ // CHECK-NEXT: OpenACCDataConstruct{{.*}} data
+ // CHECK-NEXT: device_type(T)
+ // CHECK-NEXT: dtype(T)
+ // CHECK-NEXT: NullStmt
+}
+void Inst() {
+ TemplUses<int>();
+}
+
+#endif // PCH_HELPER
diff --git a/clang/test/SemaOpenACC/data-construct-device_type-clause.c b/clang/test/SemaOpenACC/data-construct-device_type-clause.c
new file mode 100644
index 00000000000000..80cb466555b991
--- /dev/null
+++ b/clang/test/SemaOpenACC/data-construct-device_type-clause.c
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 %s -fopenacc -verify
+
+void uses() {
+ int Var;
+ // expected-warning at +1{{OpenACC clause 'async' not yet implemented}}
+#pragma acc data device_type(foo) async
+ ;
+ // expected-warning at +1{{OpenACC clause 'wait' not yet implemented}}
+#pragma acc data device_type(foo) wait
+ ;
+#pragma acc data device_type(foo) dtype(false)
+ ;
+#pragma acc data dtype(foo) device_type(false)
+ ;
+
+ // expected-error at +2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) if(1)
+ ;
+ // expected-error at +2{{OpenACC clause 'copy' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) copy(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'copyin' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) copyin(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'copyout' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) copyout(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'create' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) create(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'no_create' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) no_create(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'present' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) present(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'deviceptr' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) deviceptr(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'attach' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) attach(Var)
+ ;
+ // expected-error at +2{{OpenACC clause 'default' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
+#pragma acc data device_type(foo) default(none)
+ ;
+}
diff --git a/clang/test/SemaOpenACC/data-construct.cpp b/clang/test/SemaOpenACC/data-construct.cpp
index 0c1959dc427248..2292065e781a2e 100644
--- a/clang/test/SemaOpenACC/data-construct.cpp
+++ b/clang/test/SemaOpenACC/data-construct.cpp
@@ -64,7 +64,6 @@ void AtLeastOneOf() {
#pragma acc data wait
;
- // expected-warning at +1{{OpenACC clause 'device_type' not yet implemented}}
#pragma acc data device_type(*)
;
#pragma acc data
@@ -132,51 +131,49 @@ void DataRules() {
// OpenACC TODO: Only 'async' and 'wait' are permitted after a device_type, so
// the rest of these should diagnose.
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'copy' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'copy' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) copy(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'copyin' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'copyin' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) copyin(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'copyout' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'copyout' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) copyout(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'create' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'create' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) create(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'no_create' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'no_create' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) no_create(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'present' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'present' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) present(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'deviceptr' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'deviceptr' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) deviceptr(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'attach' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'attach' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) attach(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'default' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'default' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) default(none)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
- // expected-warning at +1{{OpenACC clause 'if' not yet implemented}}
+ // expected-error at +2{{OpenACC clause 'if' may not follow a 'device_type' clause in a 'data' construct}}
+ // expected-note at +1{{previous clause is here}}
#pragma acc data device_type(*) if(Var)
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'async' not yet implemented}}
#pragma acc data device_type(*) async
;
- // expected-warning at +2{{OpenACC clause 'device_type' not yet implemented}}
// expected-warning at +1{{OpenACC clause 'wait' not yet implemented}}
#pragma acc data device_type(*) wait
;
More information about the cfe-commits
mailing list