r213262 - [OPENMP] Initial parsing and sema analysis of 'mergeable' clause.
Alexey Bataev
a.bataev at hotmail.com
Thu Jul 17 05:47:03 PDT 2014
Author: abataev
Date: Thu Jul 17 07:47:03 2014
New Revision: 213262
URL: http://llvm.org/viewvc/llvm-project?rev=213262&view=rev
Log:
[OPENMP] Initial parsing and sema analysis of 'mergeable' 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/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/task_ast_print.cpp
cfe/trunk/test/OpenMP/task_messages.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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/DataRecursiveASTVisitor.h Thu Jul 17 07:47:03 2014
@@ -2392,6 +2392,12 @@ bool RecursiveASTVisitor<Derived>::Visit
}
template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
+ return true;
+}
+
+template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
for (auto *E : 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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Thu Jul 17 07:47:03 2014
@@ -740,6 +740,36 @@ public:
StmtRange children() { return StmtRange(); }
};
+/// \brief This represents 'mergeable' clause in the '#pragma omp ...'
+/// directive.
+///
+/// \code
+/// #pragma omp task mergeable
+/// \endcode
+/// In this example directive '#pragma omp task' has 'mergeable' clause.
+///
+class OMPMergeableClause : public OMPClause {
+public:
+ /// \brief Build 'mergeable' clause.
+ ///
+ /// \param StartLoc Starting location of the clause.
+ /// \param EndLoc Ending location of the clause.
+ ///
+ OMPMergeableClause(SourceLocation StartLoc, SourceLocation EndLoc)
+ : OMPClause(OMPC_mergeable, StartLoc, EndLoc) {}
+
+ /// \brief Build an empty clause.
+ ///
+ OMPMergeableClause()
+ : OMPClause(OMPC_mergeable, SourceLocation(), SourceLocation()) {}
+
+ static bool classof(const OMPClause *T) {
+ return T->getClauseKind() == OMPC_mergeable;
+ }
+
+ 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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Thu Jul 17 07:47:03 2014
@@ -2414,6 +2414,12 @@ bool RecursiveASTVisitor<Derived>::Visit
}
template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPMergeableClause(OMPMergeableClause *) {
+ return true;
+}
+
+template <typename Derived>
template <typename T>
bool RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
for (auto *E : 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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original)
+++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Thu Jul 17 07:47:03 2014
@@ -89,6 +89,7 @@ OPENMP_CLAUSE(schedule, OMPScheduleClaus
OPENMP_CLAUSE(ordered, OMPOrderedClause)
OPENMP_CLAUSE(nowait, OMPNowaitClause)
OPENMP_CLAUSE(untied, OMPUntiedClause)
+OPENMP_CLAUSE(mergeable, OMPMergeableClause)
// Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if)
@@ -176,7 +177,7 @@ OPENMP_PARALLEL_SECTIONS_CLAUSE(reductio
OPENMP_PARALLEL_SECTIONS_CLAUSE(copyin)
OPENMP_PARALLEL_SECTIONS_CLAUSE(lastprivate)
-// TODO more clauses allowed for OpenMP directive 'task'.
+// Clauses allowed for OpenMP directive 'task'.
OPENMP_TASK_CLAUSE(if)
OPENMP_TASK_CLAUSE(final)
OPENMP_TASK_CLAUSE(default)
@@ -184,6 +185,7 @@ OPENMP_TASK_CLAUSE(private)
OPENMP_TASK_CLAUSE(firstprivate)
OPENMP_TASK_CLAUSE(shared)
OPENMP_TASK_CLAUSE(untied)
+OPENMP_TASK_CLAUSE(mergeable)
#undef OPENMP_SCHEDULE_KIND
#undef OPENMP_PROC_BIND_KIND
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jul 17 07:47:03 2014
@@ -7443,6 +7443,9 @@ public:
/// \brief Called on well-formed 'untied' clause.
OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc,
SourceLocation EndLoc);
+ /// \brief Called on well-formed 'mergeable' clause.
+ OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc,
+ SourceLocation EndLoc);
OMPClause *
ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Thu Jul 17 07:47:03 2014
@@ -661,6 +661,10 @@ void OMPClausePrinter::VisitOMPUntiedCla
OS << "untied";
}
+void OMPClausePrinter::VisitOMPMergeableClause(OMPMergeableClause *) {
+ OS << "mergeable";
+}
+
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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Thu Jul 17 07:47:03 2014
@@ -308,6 +308,8 @@ void OMPClauseProfiler::VisitOMPNowaitCl
void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
+void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
+
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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Thu Jul 17 07:47:03 2014
@@ -104,6 +104,7 @@ unsigned clang::getOpenMPSimpleClauseTyp
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -161,6 +162,7 @@ const char *clang::getOpenMPSimpleClause
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Thu Jul 17 07:47:03 2014
@@ -292,7 +292,8 @@ bool Parser::ParseOpenMPSimpleVarList(Op
/// default-clause | private-clause | firstprivate-clause | shared-clause
/// | linear-clause | aligned-clause | collapse-clause |
/// lastprivate-clause | reduction-clause | proc_bind-clause |
-/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause
+/// schedule-clause | copyin-clause | copyprivate-clause | untied-clause |
+/// mergeable-clause
///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) {
@@ -354,6 +355,7 @@ OMPClause *Parser::ParseOpenMPClause(Ope
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
// 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]
@@ -472,6 +474,9 @@ OMPClause *Parser::ParseOpenMPSimpleClau
/// untied-clause:
/// 'untied'
///
+/// mergeable-clause:
+/// 'mergeable'
+///
OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
SourceLocation Loc = Tok.getLocation();
ConsumeAnyToken();
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Jul 17 07:47:03 2014
@@ -2069,6 +2069,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprCl
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
@@ -2270,6 +2271,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
@@ -2383,6 +2385,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWi
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
case OMPC_threadprivate:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
@@ -2460,6 +2463,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenM
case OMPC_untied:
Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc);
break;
+ case OMPC_mergeable:
+ Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc);
+ break;
case OMPC_if:
case OMPC_final:
case OMPC_num_threads:
@@ -2499,6 +2505,11 @@ OMPClause *Sema::ActOnOpenMPUntiedClause
return new (Context) OMPUntiedClause(StartLoc, EndLoc);
}
+OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc,
+ SourceLocation EndLoc) {
+ return new (Context) OMPMergeableClause(StartLoc, EndLoc);
+}
+
OMPClause *Sema::ActOnOpenMPVarListClause(
OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
@@ -2547,6 +2558,7 @@ OMPClause *Sema::ActOnOpenMPVarListClaus
case OMPC_ordered:
case OMPC_nowait:
case OMPC_untied:
+ case OMPC_mergeable:
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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jul 17 07:47:03 2014
@@ -6653,6 +6653,13 @@ TreeTransform<Derived>::TransformOMPUnti
template <typename Derived>
OMPClause *
+TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Thu Jul 17 07:47:03 2014
@@ -1712,6 +1712,9 @@ OMPClause *OMPClauseReader::readClause()
case OMPC_untied:
C = new (Context) OMPUntiedClause();
break;
+ case OMPC_mergeable:
+ C = new (Context) OMPMergeableClause();
+ break;
case OMPC_private:
C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
break;
@@ -1801,6 +1804,8 @@ void OMPClauseReader::VisitOMPNowaitClau
void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {}
+void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {}
+
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=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Thu Jul 17 07:47:03 2014
@@ -1733,6 +1733,8 @@ void OMPClauseWriter::VisitOMPNowaitClau
void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {}
+void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {}
+
void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
Record.push_back(C->varlist_size());
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
Modified: cfe/trunk/test/OpenMP/task_ast_print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/task_ast_print.cpp?rev=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/task_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/task_ast_print.cpp Thu Jul 17 07:47:03 2014
@@ -37,7 +37,7 @@ T tmain(T argc, T *argv) {
a = 2;
#pragma omp task default(none), private(argc, b) firstprivate(argv) shared(d) if (argc > 0) final(S<T>::TS > 0)
foo();
-#pragma omp task if (C)
+#pragma omp task if (C) mergeable
foo();
return 0;
}
@@ -50,7 +50,7 @@ T tmain(T argc, T *argv) {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<int>::TS > 0)
// CHECK-NEXT: foo()
-// CHECK-NEXT: #pragma omp task if(5)
+// CHECK-NEXT: #pragma omp task if(5) mergeable
// CHECK-NEXT: foo()
// CHECK: template <typename T = long, int C = 1> long tmain(long argc, long *argv) {
// CHECK-NEXT: long b = argc, c, d, e, f, g;
@@ -60,7 +60,7 @@ T tmain(T argc, T *argv) {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<long>::TS > 0)
// CHECK-NEXT: foo()
-// CHECK-NEXT: #pragma omp task if(1)
+// CHECK-NEXT: #pragma omp task if(1) mergeable
// CHECK-NEXT: foo()
// CHECK: template <typename T, int C> T tmain(T argc, T *argv) {
// CHECK-NEXT: T b = argc, c, d, e, f, g;
@@ -70,7 +70,7 @@ T tmain(T argc, T *argv) {
// CHECK-NEXT: a = 2;
// CHECK-NEXT: #pragma omp task default(none) private(argc,b) firstprivate(argv) shared(d) if(argc > 0) final(S<T>::TS > 0)
// CHECK-NEXT: foo()
-// CHECK-NEXT: #pragma omp task if(C)
+// CHECK-NEXT: #pragma omp task if(C) mergeable
// CHECK-NEXT: foo()
enum Enum {};
@@ -82,8 +82,8 @@ int main(int argc, char **argv) {
#pragma omp threadprivate(a)
Enum ee;
// CHECK: Enum ee;
-#pragma omp task untied
- // CHECK-NEXT: #pragma omp task untied
+#pragma omp task untied mergeable
+ // CHECK-NEXT: #pragma omp task untied mergeable
a = 2;
// CHECK-NEXT: a = 2;
#pragma omp task default(none), private(argc, b) firstprivate(argv) if (argc > 0) final(a > 0)
Modified: cfe/trunk/test/OpenMP/task_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/task_messages.cpp?rev=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/task_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/task_messages.cpp Thu Jul 17 07:47:03 2014
@@ -100,6 +100,9 @@ int foo() {
// expected-error at +1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
#pragma omp task untied untied
++r;
+// expected-error at +1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
+#pragma omp task mergeable mergeable
+ ++r;
return a + b;
}
@@ -262,6 +265,9 @@ L2:
// expected-error at +1 {{directive '#pragma omp task' cannot contain more than one 'untied' clause}}
#pragma omp task untied untied
++r;
+// expected-error at +1 {{directive '#pragma omp task' cannot contain more than one 'mergeable' clause}}
+#pragma omp task mergeable mergeable
+ ++r;
// expected-note at +2 {{in instantiation of function template specialization 'foo<int>' requested here}}
// expected-note at +1 {{in instantiation of function template specialization 'foo<S>' requested here}}
return foo<int>() + foo<S>();
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=213262&r1=213261&r2=213262&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Jul 17 07:47:03 2014
@@ -1970,6 +1970,8 @@ void OMPClauseEnqueue::VisitOMPNowaitCla
void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {}
+void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {}
+
template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
for (const auto *I : Node->varlists())
More information about the cfe-commits
mailing list