Author: abataev Date: Tue Dec 8 06:06:20 2015 New Revision: 255008 URL: http://llvm.org/viewvc/llvm-project?rev=255008&view=rev Log: [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.
Added: cfe/trunk/test/OpenMP/taskloop_num_tasks_messages.cpp cfe/trunk/test/OpenMP/taskloop_simd_num_tasks_messages.cpp Modified: cfe/trunk/include/clang/AST/OpenMPClause.h cfe/trunk/include/clang/AST/RecursiveASTVisitor.h cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td 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/CodeGen/CGStmtOpenMP.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/taskloop_ast_print.cpp cfe/trunk/test/OpenMP/taskloop_grainsize_messages.cpp cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp cfe/trunk/test/OpenMP/taskloop_simd_grainsize_messages.cpp cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/include/clang/AST/OpenMPClause.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/OpenMPClause.h (original) +++ cfe/trunk/include/clang/AST/OpenMPClause.h Tue Dec 8 06:06:20 2015 @@ -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 Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original) +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Dec 8 06:06:20 2015 @@ -2765,6 +2765,13 @@ bool RecursiveASTVisitor<Derived>::Visit 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 Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 8 06:06:20 2015 @@ -7927,6 +7927,10 @@ def err_omp_firstprivate_and_lastprivate "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 { Modified: cfe/trunk/include/clang/Basic/OpenMPKinds.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenMPKinds.def?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/OpenMPKinds.def (original) +++ cfe/trunk/include/clang/Basic/OpenMPKinds.def Tue Dec 8 06:06:20 2015 @@ -167,6 +167,7 @@ OPENMP_CLAUSE(thread_limit, OMPThreadLim 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) Modified: cfe/trunk/include/clang/Sema/Sema.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/include/clang/Sema/Sema.h (original) +++ cfe/trunk/include/clang/Sema/Sema.h Tue Dec 8 06:06:20 2015 @@ -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, Modified: cfe/trunk/lib/AST/StmtPrinter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/AST/StmtPrinter.cpp (original) +++ cfe/trunk/lib/AST/StmtPrinter.cpp Tue Dec 8 06:06:20 2015 @@ -737,6 +737,12 @@ void OMPClausePrinter::VisitOMPGrainsize 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(), Modified: cfe/trunk/lib/AST/StmtProfile.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/AST/StmtProfile.cpp (original) +++ cfe/trunk/lib/AST/StmtProfile.cpp Tue Dec 8 06:06:20 2015 @@ -468,6 +468,9 @@ void OMPClauseProfiler::VisitOMPPriority void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) { Profiler->VisitStmt(C->getGrainsize()); } +void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) { + Profiler->VisitStmt(C->getNumTasks()); +} } void Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original) +++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Tue Dec 8 06:06:20 2015 @@ -140,6 +140,7 @@ unsigned clang::getOpenMPSimpleClauseTyp 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::getOpenMPSimpleClause case OMPC_priority: case OMPC_grainsize: case OMPC_nogroup: + case OMPC_num_tasks: break; } llvm_unreachable("Invalid OpenMP simple clause kind"); Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original) +++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Tue Dec 8 06:06:20 2015 @@ -2488,6 +2488,7 @@ static void EmitOMPAtomicExpr(CodeGenFun case OMPC_priority: case OMPC_grainsize: case OMPC_nogroup: + case OMPC_num_tasks: llvm_unreachable("Clause is not allowed in 'omp atomic'."); } } Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original) +++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Tue Dec 8 06:06:20 2015 @@ -404,7 +404,7 @@ bool Parser::ParseOpenMPSimpleVarList(Op /// 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(Ope 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(Ope // 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(Ope /// \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(Ope /// grainsize-clause: /// 'grainsize' '(' expression ')' /// +/// num_tasks-clause: +/// 'num_tasks' '(' expression ')' +/// OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { SourceLocation Loc = ConsumeToken(); Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original) +++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Dec 8 06:06:20 2015 @@ -5367,6 +5367,30 @@ StmtResult Sema::ActOnOpenMPCancelDirect 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::ActOnOpenMPTaskLoopDire 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::ActOnOpenMPTaskLoopSimd 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::ActOnOpenMPSingleExprCl 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::ActOnOpenMPSingleExprWi 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(OpenM 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::ActOnOpenMPVarListClaus 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::ActOnOpenMPGrainsizeCla 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); +} + Modified: cfe/trunk/lib/Sema/TreeTransform.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/Sema/TreeTransform.h (original) +++ cfe/trunk/lib/Sema/TreeTransform.h Tue Dec 8 06:06:20 2015 @@ -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>::TransformOMPGrai 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 //===----------------------------------------------------------------------===// Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original) +++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Tue Dec 8 06:06:20 2015 @@ -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::VisitOMPGrainsizeC C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); } +void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) { + C->setNumTasks(Reader->Reader.ReadSubExpr()); + C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); +} + //===----------------------------------------------------------------------===// // OpenMP Directives. //===----------------------------------------------------------------------===// Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Tue Dec 8 06:06:20 2015 @@ -2023,6 +2023,11 @@ void OMPClauseWriter::VisitOMPGrainsizeC Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); } +void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) { + Writer->Writer.AddStmt(C->getNumTasks()); + Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); +} + //===----------------------------------------------------------------------===// // OpenMP Directives. //===----------------------------------------------------------------------===// Modified: cfe/trunk/test/OpenMP/taskloop_ast_print.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_ast_print.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/taskloop_ast_print.cpp (original) +++ cfe/trunk/test/OpenMP/taskloop_ast_print.cpp Tue Dec 8 06:06:20 2015 @@ -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) Modified: cfe/trunk/test/OpenMP/taskloop_grainsize_messages.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_grainsize_messages.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/taskloop_grainsize_messages.cpp (original) +++ cfe/trunk/test/OpenMP/taskloop_grainsize_messages.cpp Tue Dec 8 06:06:20 2015 @@ -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); } Added: cfe/trunk/test/OpenMP/taskloop_num_tasks_messages.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_num_tasks_messages.cpp?rev=255008&view=auto ============================================================================== --- cfe/trunk/test/OpenMP/taskloop_num_tasks_messages.cpp (added) +++ cfe/trunk/test/OpenMP/taskloop_num_tasks_messages.cpp Tue Dec 8 06:06:20 2015 @@ -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); +} Modified: cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp (original) +++ cfe/trunk/test/OpenMP/taskloop_simd_ast_print.cpp Tue Dec 8 06:06:20 2015 @@ -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) Modified: cfe/trunk/test/OpenMP/taskloop_simd_grainsize_messages.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_simd_grainsize_messages.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/taskloop_simd_grainsize_messages.cpp (original) +++ cfe/trunk/test/OpenMP/taskloop_simd_grainsize_messages.cpp Tue Dec 8 06:06:20 2015 @@ -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); } Added: cfe/trunk/test/OpenMP/taskloop_simd_num_tasks_messages.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_simd_num_tasks_messages.cpp?rev=255008&view=auto ============================================================================== --- cfe/trunk/test/OpenMP/taskloop_simd_num_tasks_messages.cpp (added) +++ cfe/trunk/test/OpenMP/taskloop_simd_num_tasks_messages.cpp Tue Dec 8 06:06:20 2015 @@ -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); +} Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=255008&r1=255007&r2=255008&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Tue Dec 8 06:06:20 2015 @@ -2096,6 +2096,10 @@ void OMPClauseEnqueue::VisitOMPGrainsize 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()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits