From: Alexey Bataev Date: Tue, 8 Dec 2015 12:06:20 +0000 (+0000) Subject: [OPENMP 4.5] Parsing/sema for 'num_tasks' clause. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3e5ee986e78d47c8cbc2d92a5eaed03fc12419d;p=clang [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255008 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/OpenMPClause.h b/include/clang/AST/OpenMPClause.h index 869492a4d9..22f6a47213 100644 --- a/include/clang/AST/OpenMPClause.h +++ b/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(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/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index d29c8cfef6..3eeeca2576 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2765,6 +2765,13 @@ bool RecursiveASTVisitor::VisitOMPGrainsizeClause( return true; } +template +bool RecursiveASTVisitor::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/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index c4fe9792a3..230f361698 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/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/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index a0ca88e7fe..befaf7a787 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/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/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index f79f444c8c..e2f29e4d3e 100644 --- a/include/clang/Sema/Sema.h +++ b/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/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 2c5ec09add..a06fc0cf6e 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/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 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 ca008cecc1..c7fadafba5 100644 --- a/lib/AST/StmtProfile.cpp +++ b/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/lib/Basic/OpenMPKinds.cpp b/lib/Basic/OpenMPKinds.cpp index 7e3156ec2c..bfd257abe6 100644 --- a/lib/Basic/OpenMPKinds.cpp +++ b/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/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index c338285959..356b1de03a 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/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/lib/Parse/ParseOpenMP.cpp b/lib/Parse/ParseOpenMP.cpp index 76f2e975d4..c3d810da34 100644 --- a/lib/Parse/ParseOpenMP.cpp +++ b/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/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 20c3c73c94..c589d0afff 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -5367,6 +5367,30 @@ StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef Clauses, CancelRegion); } +static bool checkGrainsizeNumTasksClauses(Sema &S, + ArrayRef 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 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/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index d38073dc2c..39f955b4c1 100644 --- a/lib/Sema/TreeTransform.h +++ b/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::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); } +template +OMPClause * +TreeTransform::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/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 02cd25ba99..9a9ae9bd71 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/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/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index 288febaf0e..6383fb7b3d 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/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/test/OpenMP/taskloop_ast_print.cpp b/test/OpenMP/taskloop_ast_print.cpp index 9f4d6ed0c6..06164ab168 100644 --- a/test/OpenMP/taskloop_ast_print.cpp +++ b/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/test/OpenMP/taskloop_grainsize_messages.cpp b/test/OpenMP/taskloop_grainsize_messages.cpp index aaa1074054..047f925b82 100644 --- a/test/OpenMP/taskloop_grainsize_messages.cpp +++ b/test/OpenMP/taskloop_grainsize_messages.cpp @@ -42,6 +42,9 @@ int tmain(T argc, S **argv) { for (int i = 0; i < 10; ++i) foo(); #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(); @@ -86,6 +89,9 @@ int main(int argc, char **argv) { for (int i = 0; i < 10; ++i) foo(); #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(); diff --git a/test/OpenMP/taskloop_num_tasks_messages.cpp b/test/OpenMP/taskloop_num_tasks_messages.cpp new file mode 100644 index 0000000000..94d74eb41e --- /dev/null +++ b/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 // 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/test/OpenMP/taskloop_simd_ast_print.cpp b/test/OpenMP/taskloop_simd_ast_print.cpp index ff4d708737..3e3b7e4bec 100644 --- a/test/OpenMP/taskloop_simd_ast_print.cpp +++ b/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/test/OpenMP/taskloop_simd_grainsize_messages.cpp b/test/OpenMP/taskloop_simd_grainsize_messages.cpp index a0df9e91d3..45ccb31824 100644 --- a/test/OpenMP/taskloop_simd_grainsize_messages.cpp +++ b/test/OpenMP/taskloop_simd_grainsize_messages.cpp @@ -42,6 +42,9 @@ int tmain(T argc, S **argv) { for (int i = 0; i < 10; ++i) foo(); #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(); @@ -86,6 +89,9 @@ int main(int argc, char **argv) { for (int i = 0; i < 10; ++i) foo(); #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(); diff --git a/test/OpenMP/taskloop_simd_num_tasks_messages.cpp b/test/OpenMP/taskloop_simd_num_tasks_messages.cpp new file mode 100644 index 0000000000..f26ee79a87 --- /dev/null +++ b/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 // 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/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 61caa6a8dc..6bd92c434f 100644 --- a/tools/libclang/CIndex.cpp +++ b/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 void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { for (const auto *I : Node->varlists()) {