diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2014-06-20 11:19:47 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2014-06-20 11:19:47 +0000 |
commit | da3504c90ff68c32eb16b91924ca888d1a5af105 (patch) | |
tree | c5ff975529ea45275766146020c1495a3ecdd063 | |
parent | c3c8bb304c9bde743bc050c070518ea7d1616b57 (diff) | |
download | clang-da3504c90ff68c32eb16b91924ca888d1a5af105.tar.gz clang-da3504c90ff68c32eb16b91924ca888d1a5af105.tar.bz2 clang-da3504c90ff68c32eb16b91924ca888d1a5af105.tar.xz |
[OPENMP] Initial support for 'nowait' clause.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211352 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/DataRecursiveASTVisitor.h | 5 | ||||
-rw-r--r-- | include/clang/AST/OpenMPClause.h | 29 | ||||
-rw-r--r-- | include/clang/AST/RecursiveASTVisitor.h | 5 | ||||
-rw-r--r-- | include/clang/Basic/OpenMPKinds.def | 2 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 4 | ||||
-rw-r--r-- | lib/AST/StmtProfile.cpp | 2 | ||||
-rw-r--r-- | lib/Basic/OpenMPKinds.cpp | 2 | ||||
-rw-r--r-- | lib/Parse/ParseOpenMP.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaOpenMP.cpp | 12 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 7 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderStmt.cpp | 5 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterStmt.cpp | 2 | ||||
-rw-r--r-- | test/OpenMP/for_ast_print.cpp | 8 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 2 |
15 files changed, 90 insertions, 4 deletions
diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index c0d07f03e8..9b902267ce 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2357,6 +2357,11 @@ RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) { } template <typename Derived> +bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) { + return true; +} + +template <typename Derived> template <typename T> void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) { for (auto *I : Node->varlists()) diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index 59c0e2b409..46fc4207c9 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/include/clang/AST/OpenMPClause.h @@ -629,6 +629,35 @@ public: StmtRange children() { return StmtRange(); } }; +/// \brief This represents 'nowait' clause in the '#pragma omp ...' directive. +/// +/// \code +/// #pragma omp for nowait +/// \endcode +/// In this example directive '#pragma omp for' has 'nowait' clause. +/// +class OMPNowaitClause : public OMPClause { +public: + /// \brief Build 'nowait' clause. + /// + /// \param StartLoc Starting location of the clause. + /// \param EndLoc Ending location of the clause. + /// + OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc) + : OMPClause(OMPC_nowait, StartLoc, EndLoc) {} + + /// \brief Build an empty clause. + /// + OMPNowaitClause() + : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {} + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_nowait; + } + + StmtRange children() { return StmtRange(); } +}; + /// \brief This represents clause 'private' in the '#pragma omp ...' directives. /// /// \code diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index c914d378ae..dcc5caf9ba 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2378,6 +2378,11 @@ RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) { } template <typename Derived> +bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) { + return true; +} + +template <typename Derived> template <typename T> void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) { for (auto *I : Node->varlists()) diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index 5deff11739..f6c213b759 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -61,6 +61,7 @@ OPENMP_CLAUSE(copyin, OMPCopyinClause) OPENMP_CLAUSE(proc_bind, OMPProcBindClause) OPENMP_CLAUSE(schedule, OMPScheduleClause) OPENMP_CLAUSE(ordered, OMPOrderedClause) +OPENMP_CLAUSE(nowait, OMPNowaitClause) // Clauses allowed for OpenMP directive 'parallel'. OPENMP_PARALLEL_CLAUSE(if) @@ -89,6 +90,7 @@ OPENMP_FOR_CLAUSE(reduction) OPENMP_FOR_CLAUSE(collapse) OPENMP_FOR_CLAUSE(schedule) OPENMP_FOR_CLAUSE(ordered) +OPENMP_FOR_CLAUSE(nowait) // Static attributes for 'default' clause. OPENMP_DEFAULT_KIND(none) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 0795789c43..b8d31c32a4 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7386,6 +7386,9 @@ public: /// \brief Called on well-formed 'ordered' clause. OMPClause *ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc); + /// \brief Called on well-formed 'nowait' clause. + OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, + SourceLocation EndLoc); OMPClause * ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars, diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index b5c122c1f6..db70cbe72d 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -642,6 +642,10 @@ void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *) { OS << "ordered"; } +void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) { + OS << "nowait"; +} + template<typename T> void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { for (typename T::varlist_iterator I = Node->varlist_begin(), diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 534d6bb772..cf7c6fcfa0 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -295,6 +295,8 @@ void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) { void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {} +void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {} + template<typename T> void OMPClauseProfiler::VisitOMPClauseList(T *Node) { for (auto *I : Node->varlists()) diff --git a/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index ec5198e06e..de01f8afdf 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/lib/Basic/OpenMPKinds.cpp @@ -96,6 +96,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, case OMPC_aligned: case OMPC_copyin: case OMPC_ordered: + case OMPC_nowait: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); @@ -149,6 +150,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, case OMPC_aligned: case OMPC_copyin: case OMPC_ordered: + case OMPC_nowait: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); diff --git a/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 599dda4212..5a5e15a5e4 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/lib/Parse/ParseOpenMP.cpp @@ -318,8 +318,11 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, Clause = ParseOpenMPSingleExprWithArgClause(CKind); break; case OMPC_ordered: + case OMPC_nowait: // 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] + // Only one nowait clause can appear on a for directive. if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); @@ -424,6 +427,9 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { /// ordered-clause: /// 'ordered' /// +/// nowait-clause: +/// 'nowait' +/// OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { SourceLocation Loc = Tok.getLocation(); ConsumeAnyToken(); diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 23c003815a..53f4b86134 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -1523,6 +1523,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, case OMPC_aligned: case OMPC_copyin: case OMPC_ordered: + case OMPC_nowait: case OMPC_threadprivate: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); @@ -1701,6 +1702,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause( case OMPC_aligned: case OMPC_copyin: case OMPC_ordered: + case OMPC_nowait: case OMPC_threadprivate: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); @@ -1810,6 +1812,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( case OMPC_aligned: case OMPC_copyin: case OMPC_ordered: + case OMPC_nowait: case OMPC_threadprivate: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); @@ -1881,6 +1884,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, case OMPC_ordered: Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); break; + case OMPC_nowait: + Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); + break; case OMPC_if: case OMPC_num_threads: case OMPC_safelen: @@ -1908,6 +1914,11 @@ OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, return new (Context) OMPOrderedClause(StartLoc, EndLoc); } +OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, + SourceLocation EndLoc) { + return new (Context) OMPNowaitClause(StartLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPVarListClause( OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, @@ -1950,6 +1961,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause( case OMPC_proc_bind: case OMPC_schedule: case OMPC_ordered: + case OMPC_nowait: case OMPC_threadprivate: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 27b134c801..7fa0889c9a 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -6507,6 +6507,13 @@ TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { template <typename Derived> OMPClause * +TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { + // No need to rebuild this clause, no template-dependent parameters. + return C; +} + +template <typename Derived> +OMPClause * TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { llvm::SmallVector<Expr *, 16> Vars; Vars.reserve(C->varlist_size()); diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 65f86707fc..dece91e6ea 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -1697,6 +1697,9 @@ OMPClause *OMPClauseReader::readClause() { case OMPC_ordered: C = new (Context) OMPOrderedClause(); break; + case OMPC_nowait: + C = new (Context) OMPNowaitClause(); + break; case OMPC_private: C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]); break; @@ -1774,6 +1777,8 @@ void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) { void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {} +void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {} + void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); unsigned NumVars = C->varlist_size(); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 3904192aa9..5decf98cbf 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -1717,6 +1717,8 @@ void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) { void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *) {} +void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {} + void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { Record.push_back(C->varlist_size()); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); diff --git a/test/OpenMP/for_ast_print.cpp b/test/OpenMP/for_ast_print.cpp index 96c7fb12c9..838eb4e923 100644 --- a/test/OpenMP/for_ast_print.cpp +++ b/test/OpenMP/for_ast_print.cpp @@ -20,12 +20,12 @@ T tmain(T argc) { // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: a = 2; #pragma omp parallel -#pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered +#pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered nowait for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) foo(); // CHECK-NEXT: #pragma omp parallel - // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered + // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered nowait // CHECK-NEXT: for (int i = 0; i < 10; ++i) // CHECK-NEXT: for (int j = 0; j < 10; ++j) // CHECK-NEXT: foo(); @@ -43,12 +43,12 @@ int main(int argc, char **argv) { // CHECK-NEXT: for (int i = 0; i < 2; ++i) // CHECK-NEXT: a = 2; #pragma omp parallel -#pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered +#pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered nowait for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) foo(); // CHECK-NEXT: #pragma omp parallel - // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered + // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered nowait // CHECK-NEXT: for (int i = 0; i < 10; ++i) // CHECK-NEXT: for (int j = 0; j < 10; ++j) // CHECK-NEXT: foo(); diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 85b20f343a..45e5786095 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -1951,6 +1951,8 @@ void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) { void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *) {} +void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {} + template<typename T> void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { for (const auto *I : Node->varlists()) |