From 3fe9e396f4d86e8c3e1144a1369f84874dbe8daf Mon Sep 17 00:00:00 2001 From: Patrick Lyster Date: Thu, 11 Oct 2018 14:41:10 +0000 Subject: [PATCH] Add support for 'dynamic_allocators' clause on 'requires' directive. Differential Revision: https://reviews.llvm.org/D53079 llvm-svn: 344249 --- clang/include/clang/AST/OpenMPClause.h | 32 ++++++++++++++++++++++ clang/include/clang/AST/RecursiveASTVisitor.h | 6 ++++ clang/include/clang/Basic/OpenMPKinds.def | 2 ++ clang/include/clang/Sema/Sema.h | 4 +++ clang/lib/AST/OpenMPClause.cpp | 2 ++ clang/lib/AST/StmtPrinter.cpp | 5 ++++ clang/lib/AST/StmtProfile.cpp | 3 ++ clang/lib/Basic/OpenMPKinds.cpp | 2 ++ clang/lib/CodeGen/CGStmtOpenMP.cpp | 1 + clang/lib/Parse/ParseOpenMP.cpp | 1 + clang/lib/Sema/SemaOpenMP.cpp | 13 +++++++++ clang/lib/Sema/TreeTransform.h | 7 +++++ clang/lib/Serialization/ASTReader.cpp | 7 +++++ clang/lib/Serialization/ASTWriter.cpp | 4 +++ .../OpenMP/requires_unified_address_ast_print.cpp | 3 ++ .../OpenMP/requires_unified_address_messages.cpp | 7 ++++- clang/tools/libclang/CIndex.cpp | 3 ++ 17 files changed, 101 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h index 98b1986..6a85cfb 100644 --- a/clang/include/clang/AST/OpenMPClause.h +++ b/clang/include/clang/AST/OpenMPClause.h @@ -827,6 +827,38 @@ public: } }; +/// This represents 'dynamic_allocators' clause in the '#pragma omp requires' +/// directive. +/// +/// \code +/// #pragma omp requires dynamic_allocators +/// \endcode +/// In this example directive '#pragma omp requires' has 'dynamic_allocators' +/// clause. +class OMPDynamicAllocatorsClause final : public OMPClause { +public: + friend class OMPClauseReader; + /// Build 'dynamic_allocators' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + OMPDynamicAllocatorsClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(OMPC_dynamic_allocators, StartLoc, EndLoc) {} + + /// Build an empty clause. + OMPDynamicAllocatorsClause() + : OMPClause(OMPC_dynamic_allocators, SourceLocation(), SourceLocation()) { + } + + child_range children() { + return child_range(child_iterator(), child_iterator()); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_dynamic_allocators; + } +}; + /// This represents 'schedule' clause in the '#pragma omp ...' directive. /// /// \code diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h index 5933c88..87f324e 100644 --- a/clang/include/clang/AST/RecursiveASTVisitor.h +++ b/clang/include/clang/AST/RecursiveASTVisitor.h @@ -2880,6 +2880,12 @@ bool RecursiveASTVisitor::VisitOMPReverseOffloadClause( } template +bool RecursiveASTVisitor::VisitOMPDynamicAllocatorsClause( + OMPDynamicAllocatorsClause *) { + return true; +} + +template bool RecursiveASTVisitor::VisitOMPScheduleClause(OMPScheduleClause *C) { TRY_TO(VisitOMPClauseWithPreInit(C)); diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def index 375eddf..ad40d3f8 100644 --- a/clang/include/clang/Basic/OpenMPKinds.def +++ b/clang/include/clang/Basic/OpenMPKinds.def @@ -282,6 +282,7 @@ OPENMP_CLAUSE(in_reduction, OMPInReductionClause) OPENMP_CLAUSE(unified_address, OMPUnifiedAddressClause) OPENMP_CLAUSE(unified_shared_memory, OMPUnifiedSharedMemoryClause) OPENMP_CLAUSE(reverse_offload, OMPReverseOffloadClause) +OPENMP_CLAUSE(dynamic_allocators, OMPDynamicAllocatorsClause) // Clauses allowed for OpenMP directive 'parallel'. OPENMP_PARALLEL_CLAUSE(if) @@ -467,6 +468,7 @@ OPENMP_TARGET_CLAUSE(reduction) OPENMP_REQUIRES_CLAUSE(unified_address) OPENMP_REQUIRES_CLAUSE(unified_shared_memory) OPENMP_REQUIRES_CLAUSE(reverse_offload) +OPENMP_REQUIRES_CLAUSE(dynamic_allocators) // Clauses allowed for OpenMP directive 'target data'. OPENMP_TARGET_DATA_CLAUSE(if) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 703c646..e1718e0 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9191,6 +9191,10 @@ public: OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, SourceLocation EndLoc); + /// Called on well-formed 'dynamic_allocators' clause. + OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, + SourceLocation EndLoc); + OMPClause *ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef Vars, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp index 5642294..a39f8b0 100644 --- a/clang/lib/AST/OpenMPClause.cpp +++ b/clang/lib/AST/OpenMPClause.cpp @@ -109,6 +109,7 @@ const OMPClauseWithPreInit *OMPClauseWithPreInit::get(const OMPClause *C) { case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } @@ -181,6 +182,7 @@ const OMPClauseWithPostUpdate *OMPClauseWithPostUpdate::get(const OMPClause *C) case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index fc12ce9..e9d351e 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -709,6 +709,11 @@ void OMPClausePrinter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) { OS << "reverse_offload"; } +void OMPClausePrinter::VisitOMPDynamicAllocatorsClause( + OMPDynamicAllocatorsClause *) { + OS << "dynamic_allocators"; +} + void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) { OS << "schedule("; if (Node->getFirstScheduleModifier() != OMPC_SCHEDULE_MODIFIER_unknown) { diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 10b10254..2ad9734 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -476,6 +476,9 @@ void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause( void OMPClauseProfiler::VisitOMPReverseOffloadClause( const OMPReverseOffloadClause *C) {} +void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause( + const OMPDynamicAllocatorsClause *C) {} + void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) { VistOMPClauseWithPreInit(C); if (auto *S = C->getChunkSize()) diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index fa3c3df..7693c42 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -171,6 +171,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); @@ -315,6 +316,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 7872a80..f410c59 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -3901,6 +3901,7 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind, case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed in 'omp atomic'."); } } diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 94eabf4..353bb80 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -1381,6 +1381,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: // OpenMP [2.7.1, Restrictions, p. 9] // Only one ordered clause can appear on a loop directive. // OpenMP [2.7.1, Restrictions, C/C++, p. 4] diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index de78a1a..d9f2973 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -8013,6 +8013,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; @@ -8537,6 +8538,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Unexpected OpenMP clause."); } return CaptureRegion; @@ -8857,6 +8859,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause( case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; @@ -9016,6 +9019,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; @@ -9180,6 +9184,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, case OMPC_reverse_offload: Res = ActOnOpenMPReverseOffloadClause(StartLoc, EndLoc); break; + case OMPC_dynamic_allocators: + Res = ActOnOpenMPDynamicAllocatorsClause(StartLoc, EndLoc); + break; case OMPC_if: case OMPC_final: case OMPC_num_threads: @@ -9295,6 +9302,11 @@ OMPClause *Sema::ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, return new (Context) OMPReverseOffloadClause(StartLoc, EndLoc); } +OMPClause *Sema::ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, + SourceLocation EndLoc) { + return new (Context) OMPDynamicAllocatorsClause(StartLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef VarList, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, @@ -9405,6 +9417,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause( case OMPC_unified_address: case OMPC_unified_shared_memory: case OMPC_reverse_offload: + case OMPC_dynamic_allocators: llvm_unreachable("Clause is not allowed."); } return Res; diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 5d600b7..73a522b 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -8450,6 +8450,13 @@ OMPClause *TreeTransform::TransformOMPReverseOffloadClause( } template +OMPClause *TreeTransform::TransformOMPDynamicAllocatorsClause( + OMPDynamicAllocatorsClause *C) { + llvm_unreachable( + "dynamic_allocators clause cannot appear in dependent context"); +} + +template OMPClause * TreeTransform::TransformOMPPrivateClause(OMPPrivateClause *C) { llvm::SmallVector Vars; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 7cf7817..5a29b2e 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -11729,6 +11729,9 @@ OMPClause *OMPClauseReader::readClause() { case OMPC_reverse_offload: C = new (Context) OMPReverseOffloadClause(); break; + case OMPC_dynamic_allocators: + C = new (Context) OMPDynamicAllocatorsClause(); + break; case OMPC_private: C = OMPPrivateClause::CreateEmpty(Context, Record.readInt()); break; @@ -11964,6 +11967,10 @@ void OMPClauseReader::VisitOMPUnifiedSharedMemoryClause( void OMPClauseReader::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} +void +OMPClauseReader::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { +} + void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { C->setLParenLoc(Record.readSourceLocation()); unsigned NumVars = C->varlist_size(); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 81ef885..06df715 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -6937,3 +6937,7 @@ void OMPClauseWriter::VisitOMPUnifiedSharedMemoryClause( OMPUnifiedSharedMemoryClause *) {} void OMPClauseWriter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} + +void +OMPClauseWriter::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { +} diff --git a/clang/test/OpenMP/requires_unified_address_ast_print.cpp b/clang/test/OpenMP/requires_unified_address_ast_print.cpp index 7a8a970..8c51ee0 100644 --- a/clang/test/OpenMP/requires_unified_address_ast_print.cpp +++ b/clang/test/OpenMP/requires_unified_address_ast_print.cpp @@ -19,4 +19,7 @@ #pragma omp requires reverse_offload // CHECK:#pragma omp requires reverse_offload +#pragma omp requires dynamic_allocators +// CHECK:#pragma omp requires dynamic_allocators + #endif diff --git a/clang/test/OpenMP/requires_unified_address_messages.cpp b/clang/test/OpenMP/requires_unified_address_messages.cpp index 916140f..8809ec4 100644 --- a/clang/test/OpenMP/requires_unified_address_messages.cpp +++ b/clang/test/OpenMP/requires_unified_address_messages.cpp @@ -14,6 +14,11 @@ #pragma omp requires reverse_offload, reverse_offload // expected-error {{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'reverse_offload' clause}} +#pragma omp requires dynamic_allocators // expected-note {{dynamic_allocators clause previously used here}} expected-note {{dynamic_allocators clause previously used here}} + +#pragma omp requires dynamic_allocators, dynamic_allocators // expected-error {{Only one dynamic_allocators clause can appear on a requires directive in a single translation unit}} expected-error {{directive '#pragma omp requires' cannot contain more than one 'dynamic_allocators' clause}} + + #pragma omp requires // expected-error {{expected at least one clause on '#pragma omp requires' directive}} #pragma omp requires invalid_clause // expected-warning {{extra tokens at the end of '#pragma omp requires' are ignored}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} @@ -24,7 +29,7 @@ #pragma omp requires invalid_clause unified_address // expected-warning {{extra tokens at the end of '#pragma omp requires' are ignored}} expected-error {{expected at least one clause on '#pragma omp requires' directive}} -#pragma omp requires unified_shared_memory, unified_address, reverse_offload // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error{{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error{{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} +#pragma omp requires unified_shared_memory, unified_address, reverse_offload, dynamic_allocators // expected-error {{Only one unified_shared_memory clause can appear on a requires directive in a single translation unit}} expected-error{{Only one unified_address clause can appear on a requires directive in a single translation unit}} expected-error{{Only one reverse_offload clause can appear on a requires directive in a single translation unit}} expected-error{{Only one dynamic_allocators clause can appear on a requires directive in a single translation unit}} namespace A { #pragma omp requires unified_address // expected-error {{Only one unified_address clause can appear on a requires directive in a single translation unit}} diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index ce653db..d104edd 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2216,6 +2216,9 @@ void OMPClauseEnqueue::VisitOMPUnifiedSharedMemoryClause( void OMPClauseEnqueue::VisitOMPReverseOffloadClause( const OMPReverseOffloadClause *) {} +void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause( + const OMPDynamicAllocatorsClause *) {} + void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) { Visitor->AddStmt(C->getDevice()); } -- 2.7.4