r211347 - [OPENMP] Initial support for 'ordered' clause.
Alexey Bataev
a.bataev at hotmail.com
Fri Jun 20 02:44:06 PDT 2014
Author: abataev
Date: Fri Jun 20 04:44:06 2014
New Revision: 211347
URL: http://llvm.org/viewvc/llvm-project?rev=211347&view=rev
Log:
[OPENMP] Initial support for 'ordered' clause.
Modified:
cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/OpenMP/for_ast_print.cpp
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h Fri Jun 20 04:44:06 2014
@@ -2351,6 +2351,12 @@ RecursiveASTVisitor<Derived>::VisitOMPSc
}
template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
+ return true;
+}
+
+template <typename Derived>
template <typename T>
void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
for (auto *I : Node->varlists())
Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Fri Jun 20 04:44:06 2014
@@ -600,6 +600,35 @@ public:
StmtRange children() { return StmtRange(&ChunkSize, &ChunkSize + 1); }
};
+/// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp for ordered
+/// \endcode
+/// In this example directive '#pragma omp for' has 'ordered' clause.
+///
+class OMPOrderedClause : public OMPClause {
+public:
+ /// \brief Build 'ordered' clause.
+ ///
+ /// \param StartLoc Starting location of the clause.
+ /// \param EndLoc Ending location of the clause.
+ ///
+ OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
+ : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
+
+ /// \brief Build an empty clause.
+ ///
+ OMPOrderedClause()
+ : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
+
+ static bool classof(const OMPClause *T) {
+ return T->getClauseKind() == OMPC_ordered;
+ }
+
+ StmtRange children() { return StmtRange(); }
+};
+
/// \brief This represents clause 'private' in the '#pragma omp ...' directives.
///
/// \code
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Fri Jun 20 04:44:06 2014
@@ -2372,6 +2372,12 @@ RecursiveASTVisitor<Derived>::VisitOMPSc
}
template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
+ return true;
+}
+
+template <typename Derived>
template <typename T>
void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
for (auto *I : Node->varlists())
Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Fri Jun 20 04:44:06 2014
@@ -60,6 +60,7 @@ OPENMP_CLAUSE(aligned, OMPAlignedClause)
OPENMP_CLAUSE(copyin, OMPCopyinClause)
OPENMP_CLAUSE(proc_bind, OMPProcBindClause)
OPENMP_CLAUSE(schedule, OMPScheduleClause)
+OPENMP_CLAUSE(ordered, OMPOrderedClause)
// Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if)
@@ -87,6 +88,7 @@ OPENMP_FOR_CLAUSE(firstprivate)
OPENMP_FOR_CLAUSE(reduction)
OPENMP_FOR_CLAUSE(collapse)
OPENMP_FOR_CLAUSE(schedule)
+OPENMP_FOR_CLAUSE(ordered)
// Static attributes for 'default' clause.
OPENMP_DEFAULT_KIND(none)
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Jun 20 04:44:06 2014
@@ -2351,6 +2351,11 @@ private:
/// \param Kind Kind of current clause.
///
OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind);
+ /// \brief Parses clause without any additional arguments.
+ ///
+ /// \param Kind Kind of current clause.
+ ///
+ OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind);
/// \brief Parses clause with the list of variables of a kind \a Kind.
///
/// \param Kind Kind of current clause.
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Jun 20 04:44:06 2014
@@ -7381,6 +7381,12 @@ public:
SourceLocation CommaLoc,
SourceLocation EndLoc);
+ OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
+ SourceLocation EndLoc);
+ /// \brief Called on well-formed 'ordered' clause.
+ OMPClause *ActOnOpenMPOrderedClause(SourceLocation StartLoc,
+ SourceLocation EndLoc);
+
OMPClause *
ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
Expr *TailExpr, SourceLocation StartLoc,
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Jun 20 04:44:06 2014
@@ -638,6 +638,10 @@ void OMPClausePrinter::VisitOMPScheduleC
OS << ")";
}
+void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *) {
+ OS << "ordered";
+}
+
template<typename T>
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
for (typename T::varlist_iterator I = Node->varlist_begin(),
Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Fri Jun 20 04:44:06 2014
@@ -293,6 +293,8 @@ void OMPClauseProfiler::VisitOMPSchedule
Profiler->VisitStmt(C->getChunkSize());
}
+void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
+
template<typename T>
void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
for (auto *I : Node->varlists())
Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Fri Jun 20 04:44:06 2014
@@ -95,6 +95,7 @@ unsigned clang::getOpenMPSimpleClauseTyp
case OMPC_linear:
case OMPC_aligned:
case OMPC_copyin:
+ case OMPC_ordered:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -147,6 +148,7 @@ const char *clang::getOpenMPSimpleClause
case OMPC_linear:
case OMPC_aligned:
case OMPC_copyin:
+ case OMPC_ordered:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Fri Jun 20 04:44:06 2014
@@ -317,6 +317,16 @@ OMPClause *Parser::ParseOpenMPClause(Ope
Clause = ParseOpenMPSingleExprWithArgClause(CKind);
break;
+ case OMPC_ordered:
+ // OpenMP [2.7.1, Restrictions, p. 9]
+ // Only one ordered clause can appear on a loop directive.
+ if (!FirstClause) {
+ Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
+ << getOpenMPClauseName(CKind);
+ }
+
+ Clause = ParseOpenMPClause(CKind);
+ break;
case OMPC_private:
case OMPC_firstprivate:
case OMPC_lastprivate:
@@ -409,6 +419,19 @@ OMPClause *Parser::ParseOpenMPSimpleClau
Tok.getLocation());
}
+/// \brief Parsing of OpenMP clauses like 'ordered'.
+///
+/// ordered-clause:
+/// 'ordered'
+///
+OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
+ SourceLocation Loc = Tok.getLocation();
+ ConsumeAnyToken();
+
+ return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
+}
+
+
/// \brief Parsing of OpenMP clauses with single expressions and some additional
/// argument like 'schedule' or 'dist_schedule'.
///
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Jun 20 04:44:06 2014
@@ -1522,6 +1522,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprCl
case OMPC_linear:
case OMPC_aligned:
case OMPC_copyin:
+ case OMPC_ordered:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
@@ -1699,6 +1700,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause
case OMPC_linear:
case OMPC_aligned:
case OMPC_copyin:
+ case OMPC_ordered:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
@@ -1807,6 +1809,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWi
case OMPC_linear:
case OMPC_aligned:
case OMPC_copyin:
+ case OMPC_ordered:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
@@ -1870,6 +1873,41 @@ OMPClause *Sema::ActOnOpenMPScheduleClau
EndLoc, Kind, ValExpr);
}
+OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
+ SourceLocation StartLoc,
+ SourceLocation EndLoc) {
+ OMPClause *Res = nullptr;
+ switch (Kind) {
+ case OMPC_ordered:
+ Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc);
+ break;
+ case OMPC_if:
+ case OMPC_num_threads:
+ case OMPC_safelen:
+ case OMPC_collapse:
+ case OMPC_schedule:
+ case OMPC_private:
+ case OMPC_firstprivate:
+ case OMPC_lastprivate:
+ case OMPC_shared:
+ case OMPC_reduction:
+ case OMPC_linear:
+ case OMPC_aligned:
+ case OMPC_copyin:
+ case OMPC_default:
+ case OMPC_proc_bind:
+ case OMPC_threadprivate:
+ case OMPC_unknown:
+ llvm_unreachable("Clause is not allowed.");
+ }
+ return Res;
+}
+
+OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc,
+ SourceLocation EndLoc) {
+ return new (Context) OMPOrderedClause(StartLoc, EndLoc);
+}
+
OMPClause *Sema::ActOnOpenMPVarListClause(
OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
@@ -1911,6 +1949,7 @@ OMPClause *Sema::ActOnOpenMPVarListClaus
case OMPC_default:
case OMPC_proc_bind:
case OMPC_schedule:
+ case OMPC_ordered:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Jun 20 04:44:06 2014
@@ -6500,6 +6500,13 @@ TreeTransform<Derived>::TransformOMPSche
template <typename Derived>
OMPClause *
+TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *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());
Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Fri Jun 20 04:44:06 2014
@@ -1694,6 +1694,9 @@ OMPClause *OMPClauseReader::readClause()
case OMPC_schedule:
C = new (Context) OMPScheduleClause();
break;
+ case OMPC_ordered:
+ C = new (Context) OMPOrderedClause();
+ break;
case OMPC_private:
C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
break;
@@ -1769,6 +1772,8 @@ void OMPClauseReader::VisitOMPScheduleCl
C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx));
}
+void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {}
+
void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
unsigned NumVars = C->varlist_size();
Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Fri Jun 20 04:44:06 2014
@@ -1715,6 +1715,8 @@ void OMPClauseWriter::VisitOMPScheduleCl
Writer->Writer.AddSourceLocation(C->getCommaLoc(), Record);
}
+void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *) {}
+
void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
Record.push_back(C->varlist_size());
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
Modified: cfe/trunk/test/OpenMP/for_ast_print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_ast_print.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/for_ast_print.cpp Fri Jun 20 04:44:06 2014
@@ -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)
+#pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered
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)
+ // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered
// 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)
+#pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered
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)
+ // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered
// CHECK-NEXT: for (int i = 0; i < 10; ++i)
// CHECK-NEXT: for (int j = 0; j < 10; ++j)
// CHECK-NEXT: foo();
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=211347&r1=211346&r2=211347&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Jun 20 04:44:06 2014
@@ -1949,6 +1949,8 @@ void OMPClauseEnqueue::VisitOMPScheduleC
Visitor->AddStmt(C->getChunkSize());
}
+void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *) {}
+
template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
for (const auto *I : Node->varlists())
More information about the cfe-commits
mailing list