Author: erichkeane Date: 2024-12-12T12:16:20-08:00 New Revision: afcb7d4a2eab51977497e43ce6539d2b0ca01071
URL: https://github.com/llvm/llvm-project/commit/afcb7d4a2eab51977497e43ce6539d2b0ca01071 DIFF: https://github.com/llvm/llvm-project/commit/afcb7d4a2eab51977497e43ce6539d2b0ca01071.diff LOG: [OpenACC] Implement 'wait' sema for data constructs This is once again simply enabling this for 'data', 'enter data', and 'exit data' (and ensuring we error for 'host_data'). Implementation is very simply to enable it rather than emit the not-implemented diagnostic. Added: clang/test/SemaOpenACC/data-construct-wait-ast.cpp clang/test/SemaOpenACC/data-construct-wait-clause.c Modified: clang/lib/Sema/SemaOpenACC.cpp clang/test/AST/ast-print-openacc-data-construct.cpp clang/test/ParserOpenACC/parse-clauses.c clang/test/SemaOpenACC/data-construct-device_type-clause.c clang/test/SemaOpenACC/data-construct.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp index f438ec193bf0ba..655d3b4ad6347d 100644 --- a/clang/lib/Sema/SemaOpenACC.cpp +++ b/clang/lib/Sema/SemaOpenACC.cpp @@ -1070,11 +1070,13 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDevicePtrClause( OpenACCClause *SemaOpenACCClauseVisitor::VisitWaitClause( SemaOpenACC::OpenACCParsedClause &Clause) { - // Restrictions only properly implemented on 'compute'/'combined' constructs, - // and 'compute'/'combined' constructs are the only construct that can do - // anything with this yet, so skip/treat as unimplemented in this case. + // Restrictions only properly implemented on 'compute'/'combined'/'data' + // constructs, and 'compute'/'combined'/'data' constructs are the only + // construct that can do anything with this yet, so skip/treat as + // unimplemented in this case. if (!isOpenACCComputeDirectiveKind(Clause.getDirectiveKind()) && - !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind())) + !isOpenACCCombinedDirectiveKind(Clause.getDirectiveKind()) && + !isOpenACCDataDirectiveKind(Clause.getDirectiveKind())) return isNotImplemented(); return OpenACCWaitClause::Create( diff --git a/clang/test/AST/ast-print-openacc-data-construct.cpp b/clang/test/AST/ast-print-openacc-data-construct.cpp index 508dc816b0fa70..8e1d3efbf3c4d5 100644 --- a/clang/test/AST/ast-print-openacc-data-construct.cpp +++ b/clang/test/AST/ast-print-openacc-data-construct.cpp @@ -29,6 +29,7 @@ void foo() { ; int i; + int *iPtr; int array[5]; // CHECK: #pragma acc data if(i == array[1]) @@ -51,4 +52,24 @@ void foo() { #pragma acc enter data copyin(i) async(i) // CHECK: #pragma acc exit data async #pragma acc exit data copyout(i) async + +// CHECK: #pragma acc data wait +#pragma acc data default(none) wait() + ; + +// CHECK: #pragma acc enter data wait() +#pragma acc enter data copyin(Var) wait() + +// CHECK: #pragma acc exit data wait(*iPtr, i) +#pragma acc exit data copyout(Var) wait(*iPtr, i) + +// CHECK: #pragma acc data wait(queues: *iPtr, i) +#pragma acc data default(none) wait(queues:*iPtr, i) + ; + +// CHECK: #pragma acc enter data wait(devnum: i : *iPtr, i) +#pragma acc enter data copyin(Var) wait(devnum:i:*iPtr, i) + +// CHECK: #pragma acc exit data wait(devnum: i : queues: *iPtr, i) +#pragma acc exit data copyout(Var) wait(devnum:i:queues:*iPtr, i) } diff --git a/clang/test/ParserOpenACC/parse-clauses.c b/clang/test/ParserOpenACC/parse-clauses.c index bb8c76200e8d00..558e61d666fd2f 100644 --- a/clang/test/ParserOpenACC/parse-clauses.c +++ b/clang/test/ParserOpenACC/parse-clauses.c @@ -19,7 +19,6 @@ void func() { // expected-error@+1{{invalid OpenACC clause 'invalid'}} #pragma acc enter data finalize invalid invalid finalize - // expected-warning@+2{{OpenACC clause 'wait' not yet implemented, clause ignored}} // expected-warning@+1{{OpenACC clause 'finalize' not yet implemented, clause ignored}} #pragma acc enter data wait finalize diff --git a/clang/test/SemaOpenACC/data-construct-device_type-clause.c b/clang/test/SemaOpenACC/data-construct-device_type-clause.c index 65513056f66bfb..f675c2fa6a8800 100644 --- a/clang/test/SemaOpenACC/data-construct-device_type-clause.c +++ b/clang/test/SemaOpenACC/data-construct-device_type-clause.c @@ -4,7 +4,6 @@ void uses() { int Var; #pragma acc data device_type(foo) async ; - // expected-warning@+1{{OpenACC clause 'wait' not yet implemented}} #pragma acc data device_type(foo) wait ; #pragma acc data device_type(foo) dtype(false) diff --git a/clang/test/SemaOpenACC/data-construct-wait-ast.cpp b/clang/test/SemaOpenACC/data-construct-wait-ast.cpp new file mode 100644 index 00000000000000..40409099d80588 --- /dev/null +++ b/clang/test/SemaOpenACC/data-construct-wait-ast.cpp @@ -0,0 +1,230 @@ +// 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 + +int some_int(); +long some_long(); + +void NormalUses() { + // CHECK: FunctionDecl{{.*}}NormalUses + // CHECK-NEXT: CompoundStmt + + int I; + // CHECK-NEXT: DeclStmt + // CHECK-NEXT: VarDecl + +#pragma acc data copyin(I) wait + ; + // CHECK-NEXT: OpenACCDataConstruct{{.*}}data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: NullStmt +#pragma acc enter data copyin(I) wait() + // CHECK: OpenACCEnterDataConstruct{{.*}}enter data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> +#pragma acc exit data copyout(I) wait(some_int(), some_long()) + // CHECK: OpenACCExitDataConstruct{{.*}}exit data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'long' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'long (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'long ()' lvalue Function{{.*}} 'some_long' 'long ()' +#pragma acc data copyin(I) wait(queues:some_int(), some_long()) + ; + // CHECK: OpenACCDataConstruct{{.*}}data + // CHECK-NEXT: wait clause has queues tag + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'long' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'long (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'long ()' lvalue Function{{.*}} 'some_long' 'long ()' + // CHECK-NEXT: NullStmt +#pragma acc enter data copyin(I) wait(devnum: some_int() :some_int(), some_long()) + // CHECK: OpenACCEnterDataConstruct{{.*}}enter data + // CHECK-NEXT: wait clause has devnum + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'long' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'long (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'long ()' lvalue Function{{.*}} 'some_long' 'long ()' +#pragma acc exit data copyout(I) wait(devnum: some_int() : queues :some_int(), some_long()) wait(devnum: some_int() : queues :some_int(), some_long()) + // CHECK: OpenACCExitDataConstruct{{.*}}exit data + // CHECK-NEXT: wait clause has devnum has queues tag + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'long' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'long (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'long ()' lvalue Function{{.*}} 'some_long' 'long ()' + // CHECK-NEXT: wait clause has devnum has queues tag + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'int' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'int (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'int ()' lvalue Function{{.*}} 'some_int' 'int ()' + // CHECK-NEXT: CallExpr{{.*}}'long' + // CHECK-NEXT: ImplicitCastExpr{{.*}}'long (*)()' <FunctionToPointerDecay> + // CHECK-NEXT: DeclRefExpr{{.*}}'long ()' lvalue Function{{.*}} 'some_long' 'long ()' +} + +template<typename U> +void TemplUses(U u) { + // CHECK: FunctionTemplateDecl + // CHECK-NEXT: TemplateTypeParmDecl{{.*}}typename depth 0 index 0 U + // CHECK-NEXT: FunctionDecl{{.*}} TemplUses 'void (U)' + // CHECK-NEXT: ParmVarDecl{{.*}} referenced u 'U' + // CHECK-NEXT: CompoundStmt + + U I; + // CHECK-NEXT: DeclStmt + // CHECK-NEXT: VarDecl + +#pragma acc data copyin(I) wait + ; + // CHECK: OpenACCDataConstruct{{.*}}data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: NullStmt + +#pragma acc enter data copyin(I) wait() + // CHECK: OpenACCEnterDataConstruct{{.*}}enter data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + +#pragma acc exit data copyout(I) wait(U::value, u) + // CHECK: OpenACCExitDataConstruct{{.*}}exit data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>' lvalue + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'U' + // CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U' + +#pragma acc data copyin(I) wait(queues: U::value, u) + ; + // CHECK: OpenACCDataConstruct{{.*}}data + // CHECK-NEXT: wait clause has queues tag + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>' lvalue + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'U' + // CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U' + // CHECK-NEXT: NullStmt + +#pragma acc enter data copyin(I) wait(devnum:u:queues: U::value, u) + // CHECK: OpenACCEnterDataConstruct{{.*}}data + // CHECK-NEXT: wait clause has devnum has queues tag + // CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U' + // CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>' lvalue + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'U' + // CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U' + +#pragma acc exit data copyout(I) wait(devnum:u: U::value, u) + // CHECK: OpenACCExitDataConstruct{{.*}}exit data + // CHECK-NEXT: wait clause has devnum + // CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U' + // CHECK-NEXT: DependentScopeDeclRefExpr{{.*}} '<dependent type>' lvalue + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'U' + // CHECK-NEXT: DeclRefExpr{{.*}} 'U' lvalue ParmVar{{.*}} 'u' 'U' + + // Check the instantiated versions of the above. + // CHECK: FunctionDecl{{.*}} used TemplUses 'void (HasInt)' implicit_instantiation + // CHECK-NEXT: TemplateArgument type 'HasInt' + // CHECK-NEXT: RecordType{{.*}} 'HasInt' + // CHECK-NEXT: CXXRecord{{.*}} 'HasInt' + // CHECK-NEXT: ParmVarDecl{{.*}} used u 'HasInt' + // CHECK-NEXT: CompoundStmt + + // CHECK-NEXT: DeclStmt + // CHECK-NEXT: VarDecl + + // CHECK: OpenACCDataConstruct{{.*}}data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: NullStmt + + // CHECK: OpenACCEnterDataConstruct{{.*}}enter data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + + // CHECK: OpenACCExitDataConstruct{{.*}}exit data + // CHECK-NEXT: wait clause + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue> + // CHECK-NEXT: DeclRefExpr{{.*}} 'const int' lvalue Var{{.*}} 'value' 'const int' + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'HasInt' + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion> + // CHECK-NEXT: CXXMemberCallExpr{{.*}}'char' + // CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char + // CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar + + // CHECK: OpenACCDataConstruct{{.*}}data + // CHECK-NEXT: wait clause has queues tag + // CHECK-NEXT: <<<NULL>>> + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue> + // CHECK-NEXT: DeclRefExpr{{.*}} 'const int' lvalue Var{{.*}} 'value' 'const int' + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'HasInt' + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion> + // CHECK-NEXT: CXXMemberCallExpr{{.*}}'char' + // CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char + // CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar + // CHECK-NEXT: NullStmt + + // CHECK: OpenACCEnterDataConstruct{{.*}}enter data + // CHECK-NEXT: wait clause has devnum has queues tag + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion> + // CHECK-NEXT: CXXMemberCallExpr{{.*}}'char' + // CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char + // CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue> + // CHECK-NEXT: DeclRefExpr{{.*}} 'const int' lvalue Var{{.*}} 'value' 'const int' + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'HasInt' + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion> + // CHECK-NEXT: CXXMemberCallExpr{{.*}}'char' + // CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char + // CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar + + // CHECK: OpenACCExitDataConstruct{{.*}}exit data + // CHECK-NEXT: wait clause has devnum + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion> + // CHECK-NEXT: CXXMemberCallExpr{{.*}}'char' + // CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char + // CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'int' <LValueToRValue> + // CHECK-NEXT: DeclRefExpr{{.*}} 'const int' lvalue Var{{.*}} 'value' 'const int' + // CHECK-NEXT: NestedNameSpecifier TypeSpec 'HasInt' + // CHECK-NEXT: ImplicitCastExpr{{.*}} 'char' <UserDefinedConversion> + // CHECK-NEXT: CXXMemberCallExpr{{.*}}'char' + // CHECK-NEXT: MemberExpr{{.*}} '<bound member function type>' .operator char + // CHECK-NEXT: DeclRefExpr{{.*}} 'HasInt' lvalue ParmVar +} + +struct HasInt { + using IntTy = int; + using ShortTy = short; + static constexpr int value = 1; + + operator char(); +}; + +void Inst() { + TemplUses<HasInt>({}); +} +#endif diff --git a/clang/test/SemaOpenACC/data-construct-wait-clause.c b/clang/test/SemaOpenACC/data-construct-wait-clause.c new file mode 100644 index 00000000000000..50a29df8b03bf0 --- /dev/null +++ b/clang/test/SemaOpenACC/data-construct-wait-clause.c @@ -0,0 +1,50 @@ +// RUN: %clang_cc1 %s -fopenacc -verify + +struct NotConvertible{} NC; +short getS(); +int getI(); + +void uses() { + int arr[5]; + + // expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}} +#pragma acc data copyin(arr[0]) wait + ; + + // expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}} +#pragma acc enter data copyin(arr[0]) wait() + + // expected-warning@+1{{OpenACC clause 'copyout' not yet implemented}} +#pragma acc exit data copyout(arr[0]) wait(getS(), getI()) + + // expected-warning@+2{{OpenACC clause 'use_device' not yet implemented}} + // expected-error@+1{{OpenACC 'wait' clause is not valid on 'host_data' directive}} +#pragma acc host_data use_device(arr[0]) wait(getS(), getI()) + ; + + // expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}} +#pragma acc data copyin(arr[0]) wait(devnum:getS(): getI()) + ; + + // expected-warning@+1{{OpenACC clause 'copyin' not yet implemented}} +#pragma acc enter data copyin(arr[0]) wait(devnum:getS(): queues: getI()) wait(devnum:getI(): queues: getS(), getI(), 5) + + // expected-warning@+2{{OpenACC clause 'copyout' not yet implemented}} + // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}} +#pragma acc exit data copyout(arr[0]) wait(devnum:NC : 5) + + // expected-warning@+2{{OpenACC clause 'copyin' not yet implemented}} + // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}} +#pragma acc data copyin(arr[0]) wait(devnum:5 : NC) + ; + + // expected-warning@+4{{OpenACC clause 'copyin' not yet implemented}} + // expected-error@+3{{OpenACC clause 'wait' requires expression of integer type ('int[5]' invalid)}} + // expected-error@+2{{OpenACC clause 'wait' requires expression of integer type ('int[5]' invalid)}} + // expected-error@+1{{OpenACC clause 'wait' requires expression of integer type ('struct NotConvertible' invalid)}} +#pragma acc enter data copyin(arr[0]) wait(devnum:arr : queues: arr, NC, 5) + + // expected-error@+1{{OpenACC 'wait' clause is not valid on 'loop' directive}} +#pragma acc loop wait + for(int i = 5; i < 10;++i); +} diff --git a/clang/test/SemaOpenACC/data-construct.cpp b/clang/test/SemaOpenACC/data-construct.cpp index b79899cc97a182..1e145c197834b0 100644 --- a/clang/test/SemaOpenACC/data-construct.cpp +++ b/clang/test/SemaOpenACC/data-construct.cpp @@ -58,7 +58,6 @@ void AtLeastOneOf() { #pragma acc data async ; - // expected-warning@+1{{OpenACC clause 'wait' not yet implemented}} #pragma acc data wait ; @@ -80,7 +79,6 @@ void AtLeastOneOf() { #pragma acc enter data if(Var) #pragma acc enter data async - // expected-warning@+1{{OpenACC clause 'wait' not yet implemented}} #pragma acc enter data wait #pragma acc enter data @@ -97,7 +95,6 @@ void AtLeastOneOf() { #pragma acc exit data if(Var) #pragma acc exit data async - // expected-warning@+1{{OpenACC clause 'wait' not yet implemented}} #pragma acc exit data wait // expected-warning@+1{{OpenACC clause 'finalize' not yet implemented}} #pragma acc exit data finalize @@ -166,7 +163,6 @@ void DataRules() { ; #pragma acc data device_type(*) async ; - // expected-warning@+1{{OpenACC clause 'wait' not yet implemented}} #pragma acc data device_type(*) wait ; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits