summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2015-12-08 12:06:20 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2015-12-08 12:06:20 +0000
commit382967a2e4be30089b1b2b0f640181a5d48fe53e (patch)
tree1163da83aeb140343990cd97aa94d1fd62a4d1ef /clang
parenta520e9b30cd9b2cdd2d68145c597d037fe004ea5 (diff)
downloadbcm5719-llvm-382967a2e4be30089b1b2b0f640181a5d48fe53e.tar.gz
bcm5719-llvm-382967a2e4be30089b1b2b0f640181a5d48fe53e.zip
[OPENMP 4.5] Parsing/sema for 'num_tasks' clause.
OpenMP 4.5 adds directives 'taskloop' and 'taskloop simd'. These directives support clause 'num_tasks'. Patch adds parsing/semantic analysis for this clause. llvm-svn: 255008
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/OpenMPClause.h52
-rw-r--r--clang/include/clang/AST/RecursiveASTVisitor.h7
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--clang/include/clang/Basic/OpenMPKinds.def5
-rw-r--r--clang/include/clang/Sema/Sema.h4
-rw-r--r--clang/lib/AST/StmtPrinter.cpp6
-rw-r--r--clang/lib/AST/StmtProfile.cpp3
-rw-r--r--clang/lib/Basic/OpenMPKinds.cpp2
-rw-r--r--clang/lib/CodeGen/CGStmtOpenMP.cpp1
-rw-r--r--clang/lib/Parse/ParseOpenMP.cpp10
-rw-r--r--clang/lib/Sema/SemaOpenMP.cpp60
-rw-r--r--clang/lib/Sema/TreeTransform.h21
-rw-r--r--clang/lib/Serialization/ASTReaderStmt.cpp8
-rw-r--r--clang/lib/Serialization/ASTWriterStmt.cpp5
-rw-r--r--clang/test/OpenMP/taskloop_ast_print.cpp8
-rw-r--r--clang/test/OpenMP/taskloop_grainsize_messages.cpp6
-rw-r--r--clang/test/OpenMP/taskloop_num_tasks_messages.cpp99
-rw-r--r--clang/test/OpenMP/taskloop_simd_ast_print.cpp8
-rw-r--r--clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp6
-rw-r--r--clang/test/OpenMP/taskloop_simd_num_tasks_messages.cpp99
-rw-r--r--clang/tools/libclang/CIndex.cpp4
21 files changed, 406 insertions, 12 deletions
diff --git a/clang/include/clang/AST/OpenMPClause.h b/clang/include/clang/AST/OpenMPClause.h
index 869492a4d90..22f6a472138 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2976,6 +2976,58 @@ public:
}
};
+/// \brief This represents 'num_tasks' clause in the '#pragma omp ...'
+/// directive.
+///
+/// \code
+/// #pragma omp taskloop num_tasks(4)
+/// \endcode
+/// In this example directive '#pragma omp taskloop' has clause 'num_tasks'
+/// with single expression '4'.
+///
+class OMPNumTasksClause : public OMPClause {
+ friend class OMPClauseReader;
+ /// \brief Location of '('.
+ SourceLocation LParenLoc;
+ /// \brief Safe iteration space distance.
+ Stmt *NumTasks;
+
+ /// \brief Set safelen.
+ void setNumTasks(Expr *Size) { NumTasks = Size; }
+
+public:
+ /// \brief Build 'num_tasks' clause.
+ ///
+ /// \param Size Expression associated with this clause.
+ /// \param StartLoc Starting location of the clause.
+ /// \param EndLoc Ending location of the clause.
+ ///
+ OMPNumTasksClause(Expr *Size, SourceLocation StartLoc,
+ SourceLocation LParenLoc, SourceLocation EndLoc)
+ : OMPClause(OMPC_num_tasks, StartLoc, EndLoc), LParenLoc(LParenLoc),
+ NumTasks(Size) {}
+
+ /// \brief Build an empty clause.
+ ///
+ explicit OMPNumTasksClause()
+ : OMPClause(OMPC_num_tasks, SourceLocation(), SourceLocation()),
+ LParenLoc(SourceLocation()), NumTasks(nullptr) {}
+
+ /// \brief Sets the location of '('.
+ void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+ /// \brief Returns the location of '('.
+ SourceLocation getLParenLoc() const { return LParenLoc; }
+
+ /// \brief Return safe iteration space distance.
+ Expr *getNumTasks() const { return cast_or_null<Expr>(NumTasks); }
+
+ static bool classof(const OMPClause *T) {
+ return T->getClauseKind() == OMPC_num_tasks;
+ }
+
+ child_range children() { return child_range(&NumTasks, &NumTasks + 1); }
+};
+
} // end namespace clang
#endif // LLVM_CLANG_AST_OPENMPCLAUSE_H
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index d29c8cfef6f..3eeeca2576a 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2765,6 +2765,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPGrainsizeClause(
return true;
}
+template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPNumTasksClause(
+ OMPNumTasksClause *C) {
+ TRY_TO(TraverseStmt(C->getNumTasks()));
+ return true;
+}
+
// FIXME: look at the following tricky-seeming exprs to see if we
// need to recurse on anything. These are ones that have methods
// returning decls or qualtypes or nestednamespecifier -- though I'm
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c4fe9792a32..230f361698e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7927,6 +7927,10 @@ def err_omp_firstprivate_and_lastprivate_in_distribute : Error<
"lastprivate variable cannot be firstprivate in '#pragma omp distribute'">;
def err_omp_firstprivate_distribute_in_teams_reduction : Error<
"reduction variable in '#pragma omp teams' cannot be firstprivate in '#pragma omp distribute'">;
+def err_omp_grainsize_num_tasks_mutually_exclusive : Error<
+ "'%0' and '%1' clause are mutually exclusive and may not appear on the same directive">;
+def note_omp_previous_grainsize_num_tasks : Note<
+ "'%0' clause is specified here">;
} // end of OpenMP category
let CategoryName = "Related Result Type Issue" in {
diff --git a/clang/include/clang/Basic/OpenMPKinds.def b/clang/include/clang/Basic/OpenMPKinds.def
index a0ca88e7fe7..befaf7a7870 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -167,6 +167,7 @@ OPENMP_CLAUSE(thread_limit, OMPThreadLimitClause)
OPENMP_CLAUSE(priority, OMPPriorityClause)
OPENMP_CLAUSE(grainsize, OMPGrainsizeClause)
OPENMP_CLAUSE(nogroup, OMPNogroupClause)
+OPENMP_CLAUSE(num_tasks, OMPNumTasksClause)
// Clauses allowed for OpenMP directive 'parallel'.
OPENMP_PARALLEL_CLAUSE(if)
@@ -357,7 +358,6 @@ OPENMP_MAP_KIND(release)
OPENMP_MAP_KIND(always)
// Clauses allowed for OpenMP directive 'taskloop'.
-// TODO: add next clauses
OPENMP_TASKLOOP_CLAUSE(if)
OPENMP_TASKLOOP_CLAUSE(shared)
OPENMP_TASKLOOP_CLAUSE(private)
@@ -371,9 +371,9 @@ OPENMP_TASKLOOP_CLAUSE(mergeable)
OPENMP_TASKLOOP_CLAUSE(priority)
OPENMP_TASKLOOP_CLAUSE(grainsize)
OPENMP_TASKLOOP_CLAUSE(nogroup)
+OPENMP_TASKLOOP_CLAUSE(num_tasks)
// Clauses allowed for OpenMP directive 'taskloop simd'.
-// TODO: add next clauses
OPENMP_TASKLOOP_SIMD_CLAUSE(if)
OPENMP_TASKLOOP_SIMD_CLAUSE(shared)
OPENMP_TASKLOOP_SIMD_CLAUSE(private)
@@ -391,6 +391,7 @@ OPENMP_TASKLOOP_SIMD_CLAUSE(safelen)
OPENMP_TASKLOOP_SIMD_CLAUSE(simdlen)
OPENMP_TASKLOOP_SIMD_CLAUSE(grainsize)
OPENMP_TASKLOOP_SIMD_CLAUSE(nogroup)
+OPENMP_TASKLOOP_SIMD_CLAUSE(num_tasks)
// Clauses allowed for OpenMP directive 'distribute'
OPENMP_DISTRIBUTE_CLAUSE(private)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f79f444c8cd..e2f29e4d3e5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8012,6 +8012,10 @@ public:
OMPClause *ActOnOpenMPGrainsizeClause(Expr *Size, SourceLocation StartLoc,
SourceLocation LParenLoc,
SourceLocation EndLoc);
+ /// \brief Called on well-formed 'num_tasks' clause.
+ OMPClause *ActOnOpenMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc);
OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
unsigned Argument,
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 2c5ec09addb..a06fc0cf6ee 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -737,6 +737,12 @@ void OMPClausePrinter::VisitOMPGrainsizeClause(OMPGrainsizeClause *Node) {
OS << ")";
}
+void OMPClausePrinter::VisitOMPNumTasksClause(OMPNumTasksClause *Node) {
+ OS << "num_tasks(";
+ Node->getNumTasks()->printPretty(OS, nullptr, Policy, 0);
+ OS << ")";
+}
+
template<typename T>
void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
for (typename T::varlist_iterator I = Node->varlist_begin(),
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index ca008cecc15..c7fadafba57 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -468,6 +468,9 @@ void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Profiler->VisitStmt(C->getGrainsize());
}
+void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
+ Profiler->VisitStmt(C->getNumTasks());
+}
}
void
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 7e3156ec2c2..bfd257abe69 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -140,6 +140,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
case OMPC_priority:
case OMPC_grainsize:
case OMPC_nogroup:
+ case OMPC_num_tasks:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -243,6 +244,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
case OMPC_priority:
case OMPC_grainsize:
case OMPC_nogroup:
+ case OMPC_num_tasks:
break;
}
llvm_unreachable("Invalid OpenMP simple clause kind");
diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index c3382859593..356b1de03ac 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -2488,6 +2488,7 @@ static void EmitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
case OMPC_priority:
case OMPC_grainsize:
case OMPC_nogroup:
+ case OMPC_num_tasks:
llvm_unreachable("Clause is not allowed in 'omp atomic'.");
}
}
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 76f2e975d47..c3d810da349 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -404,7 +404,7 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
/// update-clause | capture-clause | seq_cst-clause | device-clause |
/// simdlen-clause | threads-clause | simd-clause | num_teams-clause |
/// thread_limit-clause | priority-clause | grainsize-clause |
-/// nogroup-clause
+/// nogroup-clause | num_tasks-clause
///
OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind, bool FirstClause) {
@@ -429,6 +429,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
case OMPC_thread_limit:
case OMPC_priority:
case OMPC_grainsize:
+ case OMPC_num_tasks:
// OpenMP [2.5, Restrictions]
// At most one num_threads clause can appear on the directive.
// OpenMP [2.8.1, simd construct, Restrictions]
@@ -447,6 +448,8 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
// At most one priority clause can appear on the directive.
// OpenMP [2.9.2, taskloop Construct, Restrictions]
// At most one grainsize clause can appear on the directive.
+ // OpenMP [2.9.2, taskloop Construct, Restrictions]
+ // At most one num_tasks clause can appear on the directive.
if (!FirstClause) {
Diag(Tok, diag::err_omp_more_one_clause)
<< getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0;
@@ -538,7 +541,7 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
/// \brief Parsing of OpenMP clauses with single expressions like 'final',
/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams',
-/// 'thread_limit', 'simdlen', 'priority' or 'grainsize'.
+/// 'thread_limit', 'simdlen', 'priority', 'grainsize' or 'num_tasks'.
///
/// final-clause:
/// 'final' '(' expression ')'
@@ -561,6 +564,9 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
/// grainsize-clause:
/// 'grainsize' '(' expression ')'
///
+/// num_tasks-clause:
+/// 'num_tasks' '(' expression ')'
+///
OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
SourceLocation Loc = ConsumeToken();
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 20c3c73c94a..c589d0afff2 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5367,6 +5367,30 @@ StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses,
CancelRegion);
}
+static bool checkGrainsizeNumTasksClauses(Sema &S,
+ ArrayRef<OMPClause *> Clauses) {
+ OMPClause *PrevClause = nullptr;
+ bool ErrorFound = false;
+ for (auto *C : Clauses) {
+ if (C->getClauseKind() == OMPC_grainsize ||
+ C->getClauseKind() == OMPC_num_tasks) {
+ if (!PrevClause)
+ PrevClause = C;
+ else if (PrevClause->getClauseKind() != C->getClauseKind()) {
+ S.Diag(C->getLocStart(),
+ diag::err_omp_grainsize_num_tasks_mutually_exclusive)
+ << getOpenMPClauseName(C->getClauseKind())
+ << getOpenMPClauseName(PrevClause->getClauseKind());
+ S.Diag(PrevClause->getLocStart(),
+ diag::note_omp_previous_grainsize_num_tasks)
+ << getOpenMPClauseName(PrevClause->getClauseKind());
+ ErrorFound = true;
+ }
+ }
+ }
+ return ErrorFound;
+}
+
StmtResult Sema::ActOnOpenMPTaskLoopDirective(
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
SourceLocation EndLoc,
@@ -5388,6 +5412,12 @@ StmtResult Sema::ActOnOpenMPTaskLoopDirective(
assert((CurContext->isDependentContext() || B.builtAll()) &&
"omp for loop exprs were not built");
+ // OpenMP, [2.9.2 taskloop Construct, Restrictions]
+ // The grainsize clause and num_tasks clause are mutually exclusive and may
+ // not appear on the same taskloop directive.
+ if (checkGrainsizeNumTasksClauses(*this, Clauses))
+ return StmtError();
+
getCurFunction()->setHasBranchProtectedScope();
return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc,
NestedLoopCount, Clauses, AStmt, B);
@@ -5414,6 +5444,12 @@ StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective(
assert((CurContext->isDependentContext() || B.builtAll()) &&
"omp for loop exprs were not built");
+ // OpenMP, [2.9.2 taskloop Construct, Restrictions]
+ // The grainsize clause and num_tasks clause are mutually exclusive and may
+ // not appear on the same taskloop directive.
+ if (checkGrainsizeNumTasksClauses(*this, Clauses))
+ return StmtError();
+
getCurFunction()->setHasBranchProtectedScope();
return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc,
NestedLoopCount, Clauses, AStmt, B);
@@ -5484,6 +5520,9 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
case OMPC_grainsize:
Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc);
break;
+ case OMPC_num_tasks:
+ Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc);
+ break;
case OMPC_if:
case OMPC_default:
case OMPC_proc_bind:
@@ -5790,6 +5829,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
case OMPC_priority:
case OMPC_grainsize:
case OMPC_nogroup:
+ case OMPC_num_tasks:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
@@ -5925,6 +5965,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
case OMPC_priority:
case OMPC_grainsize:
case OMPC_nogroup:
+ case OMPC_num_tasks:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
@@ -6064,6 +6105,7 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
case OMPC_thread_limit:
case OMPC_priority:
case OMPC_grainsize:
+ case OMPC_num_tasks:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
@@ -6203,6 +6245,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
case OMPC_priority:
case OMPC_grainsize:
case OMPC_nogroup:
+ case OMPC_num_tasks:
case OMPC_unknown:
llvm_unreachable("Clause is not allowed.");
}
@@ -8184,3 +8227,20 @@ OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize,
return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc);
}
+
+OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks,
+ SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc) {
+ Expr *ValExpr = NumTasks;
+
+ // OpenMP [2.9.2, taskloop Constrcut]
+ // The parameter of the num_tasks clause must be a positive integer
+ // expression.
+ if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks,
+ /*StrictlyPositive=*/true))
+ return nullptr;
+
+ return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc);
+}
+
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index d38073dc2cb..39f955b4c1e 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -1711,6 +1711,17 @@ public:
EndLoc);
}
+ /// \brief Build a new OpenMP 'num_tasks' clause.
+ ///
+ /// By default, performs semantic analysis to build the new statement.
+ /// Subclasses may override this routine to provide different behavior.
+ OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
+ SourceLocation LParenLoc,
+ SourceLocation EndLoc) {
+ return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
+ EndLoc);
+ }
+
/// \brief Rebuild the operand to an Objective-C \@synchronized statement.
///
/// By default, performs semantic analysis to build the new statement.
@@ -7822,6 +7833,16 @@ TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
}
+template <typename Derived>
+OMPClause *
+TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
+ ExprResult E = getDerived().TransformExpr(C->getNumTasks());
+ if (E.isInvalid())
+ return nullptr;
+ return getDerived().RebuildOMPNumTasksClause(
+ E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
+}
+
//===----------------------------------------------------------------------===//
// Expression transformation
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index 02cd25ba99e..9a9ae9bd717 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1865,6 +1865,9 @@ OMPClause *OMPClauseReader::readClause() {
case OMPC_grainsize:
C = new (Context) OMPGrainsizeClause();
break;
+ case OMPC_num_tasks:
+ C = new (Context) OMPNumTasksClause();
+ break;
}
Visit(C);
C->setLocStart(Reader->ReadSourceLocation(Record, Idx));
@@ -2211,6 +2214,11 @@ void OMPClauseReader::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
}
+void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
+ C->setNumTasks(Reader->Reader.ReadSubExpr());
+ C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
+}
+
//===----------------------------------------------------------------------===//
// OpenMP Directives.
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 288febaf0e8..6383fb7b3dd 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -2023,6 +2023,11 @@ void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) {
Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
}
+void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) {
+ Writer->Writer.AddStmt(C->getNumTasks());
+ Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
+}
+
//===----------------------------------------------------------------------===//
// OpenMP Directives.
//===----------------------------------------------------------------------===//
diff --git a/clang/test/OpenMP/taskloop_ast_print.cpp b/clang/test/OpenMP/taskloop_ast_print.cpp
index 9f4d6ed0c68..06164ab168d 100644
--- a/clang/test/OpenMP/taskloop_ast_print.cpp
+++ b/clang/test/OpenMP/taskloop_ast_print.cpp
@@ -20,7 +20,7 @@ T tmain(T argc) {
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: a = 2;
#pragma omp parallel
-#pragma omp taskloop private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) nogroup
+#pragma omp taskloop private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) nogroup num_tasks(N)
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
@@ -33,7 +33,7 @@ T tmain(T argc) {
for (int j = 0; j < 2; ++j)
foo();
// CHECK-NEXT: #pragma omp parallel
- // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) nogroup
+ // CHECK-NEXT: #pragma omp taskloop private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) nogroup num_tasks(N)
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
@@ -52,8 +52,8 @@ int main(int argc, char **argv) {
int b = argc, c, d, e, f, g;
static int a;
// CHECK: static int a;
-#pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup
- // CHECK-NEXT: #pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup
+#pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup num_tasks(argc)
+ // CHECK-NEXT: #pragma omp taskloop if(taskloop: a) default(none) shared(a) final(b) priority(5) nogroup num_tasks(argc)
for (int i = 0; i < 2; ++i)
a = 2;
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
diff --git a/clang/test/OpenMP/taskloop_grainsize_messages.cpp b/clang/test/OpenMP/taskloop_grainsize_messages.cpp
index aaa10740540..047f925b825 100644
--- a/clang/test/OpenMP/taskloop_grainsize_messages.cpp
+++ b/clang/test/OpenMP/taskloop_grainsize_messages.cpp
@@ -44,6 +44,9 @@ int tmain(T argc, S **argv) {
#pragma omp taskloop grainsize(-1) // expected-error {{argument to 'grainsize' clause must be a strictly positive integer value}}
for (int i = 0; i < 10; ++i)
foo();
+ #pragma omp taskloop grainsize(argc) num_tasks(argc) // expected-error {{'num_tasks' and 'grainsize' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'grainsize' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
return 0;
}
@@ -88,6 +91,9 @@ int main(int argc, char **argv) {
#pragma omp taskloop grainsize(-1) // expected-error {{argument to 'grainsize' clause must be a strictly positive integer value}}
for (int i = 0; i < 10; ++i)
foo();
+ #pragma omp taskloop grainsize(argc) num_tasks(argc) // expected-error {{'num_tasks' and 'grainsize' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'grainsize' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
return tmain(argc, argv);
}
diff --git a/clang/test/OpenMP/taskloop_num_tasks_messages.cpp b/clang/test/OpenMP/taskloop_num_tasks_messages.cpp
new file mode 100644
index 00000000000..94d74eb41eb
--- /dev/null
+++ b/clang/test/OpenMP/taskloop_num_tasks_messages.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+ return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+
+template <class T, class S> // expected-note {{declared here}}
+int tmain(T argc, S **argv) {
+ #pragma omp taskloop num_tasks // expected-error {{expected '(' after 'num_tasks'}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks () // expected-error {{expected expression}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc)) // expected-warning {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc > 0 ? argv[1][0] : argv[2][argc])
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (foobool(argc)), num_tasks (true) // expected-error {{directive '#pragma omp taskloop' cannot contain more than one 'num_tasks' clause}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (S) // expected-error {{'S' does not refer to a value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(0) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(-1) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(argc) grainsize(argc) // expected-error {{'grainsize' and 'num_tasks' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'num_tasks' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ #pragma omp taskloop num_tasks // expected-error {{expected '(' after 'num_tasks'}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks () // expected-error {{expected expression}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc)) // expected-warning {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc > 0 ? argv[1][0] : argv[2][argc])
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (foobool(argc)), num_tasks (true) // expected-error {{directive '#pragma omp taskloop' cannot contain more than one 'num_tasks' clause}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (S1) // expected-error {{'S1' does not refer to a value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(0) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(-1) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop num_tasks(argc) grainsize(argc) // expected-error {{'grainsize' and 'num_tasks' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'num_tasks' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+
+ return tmain(argc, argv);
+}
diff --git a/clang/test/OpenMP/taskloop_simd_ast_print.cpp b/clang/test/OpenMP/taskloop_simd_ast_print.cpp
index ff4d7087377..3e3b7e4bec2 100644
--- a/clang/test/OpenMP/taskloop_simd_ast_print.cpp
+++ b/clang/test/OpenMP/taskloop_simd_ast_print.cpp
@@ -21,7 +21,7 @@ T tmain(T argc) {
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: a = 2;
#pragma omp parallel
-#pragma omp taskloop simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) simdlen(N) nogroup
+#pragma omp taskloop simd private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) shared(g) if (c) final(d) mergeable priority(f) simdlen(N) nogroup num_tasks(N)
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int j = 0; j < 2; ++j)
@@ -34,7 +34,7 @@ T tmain(T argc) {
for (int j = 0; j < 2; ++j)
foo();
// CHECK-NEXT: #pragma omp parallel
- // CHECK-NEXT: #pragma omp taskloop simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) simdlen(N) nogroup
+ // CHECK-NEXT: #pragma omp taskloop simd private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) shared(g) if(c) final(d) mergeable priority(f) simdlen(N) nogroup num_tasks(N)
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
// CHECK-NEXT: for (int j = 0; j < 2; ++j)
@@ -53,8 +53,8 @@ int main(int argc, char **argv) {
int b = argc, c, d, e, f, g;
static int a;
// CHECK: static int a;
-#pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b), aligned(argv) nogroup
- // CHECK-NEXT: #pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b) aligned(argv) nogroup
+#pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b), aligned(argv) nogroup num_tasks(argc)
+ // CHECK-NEXT: #pragma omp taskloop simd if(taskloop: a) default(none) shared(a) final(b) priority(5) safelen(8) linear(b) aligned(argv) nogroup num_tasks(argc)
for (int i = 0; i < 2; ++i)
a = 2;
// CHECK-NEXT: for (int i = 0; i < 2; ++i)
diff --git a/clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp b/clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp
index a0df9e91d32..45ccb31824f 100644
--- a/clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp
+++ b/clang/test/OpenMP/taskloop_simd_grainsize_messages.cpp
@@ -44,6 +44,9 @@ int tmain(T argc, S **argv) {
#pragma omp taskloop simd grainsize(-1) // expected-error {{argument to 'grainsize' clause must be a strictly positive integer value}}
for (int i = 0; i < 10; ++i)
foo();
+ #pragma omp taskloop simd grainsize(argc) num_tasks(argc) // expected-error {{'num_tasks' and 'grainsize' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'grainsize' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
return 0;
}
@@ -88,6 +91,9 @@ int main(int argc, char **argv) {
#pragma omp taskloop simd grainsize(-1) // expected-error {{argument to 'grainsize' clause must be a strictly positive integer value}}
for (int i = 0; i < 10; ++i)
foo();
+ #pragma omp taskloop simd grainsize(argc) num_tasks(argc) // expected-error {{'num_tasks' and 'grainsize' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'grainsize' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
return tmain(argc, argv);
}
diff --git a/clang/test/OpenMP/taskloop_simd_num_tasks_messages.cpp b/clang/test/OpenMP/taskloop_simd_num_tasks_messages.cpp
new file mode 100644
index 00000000000..f26ee79a874
--- /dev/null
+++ b/clang/test/OpenMP/taskloop_simd_num_tasks_messages.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
+
+void foo() {
+}
+
+bool foobool(int argc) {
+ return argc;
+}
+
+struct S1; // expected-note {{declared here}}
+
+template <class T, class S> // expected-note {{declared here}}
+int tmain(T argc, S **argv) {
+ #pragma omp taskloop simd num_tasks // expected-error {{expected '(' after 'num_tasks'}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks () // expected-error {{expected expression}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc)) // expected-warning {{extra tokens at the end of '#pragma omp taskloop simd' are ignored}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc > 0 ? argv[1][0] : argv[2][argc])
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (foobool(argc)), num_tasks (true) // expected-error {{directive '#pragma omp taskloop simd' cannot contain more than one 'num_tasks' clause}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (S) // expected-error {{'S' does not refer to a value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(0) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(-1) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(argc) grainsize(argc) // expected-error {{'grainsize' and 'num_tasks' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'num_tasks' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ #pragma omp taskloop simd num_tasks // expected-error {{expected '(' after 'num_tasks'}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks () // expected-error {{expected expression}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc)) // expected-warning {{extra tokens at the end of '#pragma omp taskloop simd' are ignored}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc > 0 ? argv[1][0] : argv[2][argc])
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (foobool(argc)), num_tasks (true) // expected-error {{directive '#pragma omp taskloop simd' cannot contain more than one 'num_tasks' clause}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (S1) // expected-error {{'S1' does not refer to a value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(0) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(-1) // expected-error {{argument to 'num_tasks' clause must be a strictly positive integer value}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+ #pragma omp taskloop simd num_tasks(argc) grainsize(argc) // expected-error {{'grainsize' and 'num_tasks' clause are mutually exclusive and may not appear on the same directive}} expected-note {{'num_tasks' clause is specified here}}
+ for (int i = 0; i < 10; ++i)
+ foo();
+
+ return tmain(argc, argv);
+}
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 61caa6a8dce..6bd92c434f2 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2096,6 +2096,10 @@ void OMPClauseEnqueue::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Visitor->AddStmt(C->getGrainsize());
}
+void OMPClauseEnqueue::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
+ Visitor->AddStmt(C->getNumTasks());
+}
+
template<typename T>
void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
for (const auto *I : Node->varlists()) {
OpenPOWER on IntegriCloud