Index: include/clang-c/Index.h =================================================================== --- include/clang-c/Index.h +++ include/clang-c/Index.h @@ -2260,7 +2260,11 @@ */ CXCursor_OMPTaskLoopDirective = 258, - CXCursor_LastStmt = CXCursor_OMPTaskLoopDirective, + /** \brief OpenMP distribute directive. + */ + CXCursor_OMPDistributeDirective = 259, + + CXCursor_LastStmt = CXCursor_OMPDistributeDirective, /** * \brief Cursor that represents the translation unit itself. Index: include/clang/AST/OpenMPClause.h =================================================================== --- include/clang/AST/OpenMPClause.h +++ include/clang/AST/OpenMPClause.h @@ -664,7 +664,7 @@ SourceLocation LParenLoc; /// \brief A kind of the 'schedule' clause. OpenMPScheduleClauseKind Kind; - /// \brief Start location of the schedule ind in source code. + /// \brief Start location of the schedule kind in source code. SourceLocation KindLoc; /// \brief Location of ',' (if any). SourceLocation CommaLoc; @@ -705,8 +705,8 @@ void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; } public: - /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size - /// expression \a ChunkSize. + /// \brief Build 'dist_schedule' clause with schedule kind \a Kind and chunk + /// size expression \a ChunkSize. /// /// \param StartLoc Starting location of the clause. /// \param LParenLoc Location of '('. @@ -776,6 +776,136 @@ } }; +/// \brief This represents 'dist_schedule' clause in the '#pragma omp ...' +/// directive. +/// +/// \code +/// #pragma omp distribute dist_schedule(static, 3) +/// \endcode +/// In this example directive '#pragma omp distribute' has 'dist_schedule' +/// clause with arguments 'static' and '3'. +/// +class OMPDistScheduleClause : public OMPClause { + friend class OMPClauseReader; + /// \brief Location of '('. + SourceLocation LParenLoc; + /// \brief A kind of the 'schedule' clause. + OpenMPDistScheduleClauseKind Kind; + /// \brief Start location of the schedule kind in source code. + SourceLocation KindLoc; + /// \brief Location of ',' (if any). + SourceLocation CommaLoc; + /// \brief Chunk size and a reference to pseudo variable for combined + /// directives. + enum { CHUNK_SIZE, HELPER_CHUNK_SIZE, NUM_EXPRS }; + Stmt *ChunkSizes[NUM_EXPRS]; + + /// \brief Set schedule kind. + /// + /// \param K Schedule kind. + /// + void setDistScheduleKind(OpenMPDistScheduleClauseKind K) { Kind = K; } + /// \brief Sets the location of '('. + /// + /// \param Loc Location of '('. + /// + void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; } + /// \brief Set schedule kind start location. + /// + /// \param KLoc Schedule kind location. + /// + void setDistScheduleKindLoc(SourceLocation KLoc) { KindLoc = KLoc; } + /// \brief Set location of ','. + /// + /// \param Loc Location of ','. + /// + void setCommaLoc(SourceLocation Loc) { CommaLoc = Loc; } + /// \brief Set chunk size. + /// + /// \param E Chunk size. + /// + void setChunkSize(Expr *E) { ChunkSizes[CHUNK_SIZE] = E; } + /// \brief Set helper chunk size. + /// + /// \param E Helper chunk size. + /// + void setHelperChunkSize(Expr *E) { ChunkSizes[HELPER_CHUNK_SIZE] = E; } + +public: + /// \brief Build 'schedule' clause with schedule kind \a Kind and chunk size + /// expression \a ChunkSize. + /// + /// \param StartLoc Starting location of the clause. + /// \param LParenLoc Location of '('. + /// \param KLoc Starting location of the argument. + /// \param CommaLoc Location of ','. + /// \param EndLoc Ending location of the clause. + /// \param Kind DistSchedule kind. + /// \param ChunkSize Chunk size. + /// \param HelperChunkSize Helper chunk size for combined directives. + /// + OMPDistScheduleClause(SourceLocation StartLoc, SourceLocation LParenLoc, + SourceLocation KLoc, SourceLocation CommaLoc, + SourceLocation EndLoc, + OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, + Expr *HelperChunkSize) + : OMPClause(OMPC_dist_schedule, StartLoc, EndLoc), LParenLoc(LParenLoc), + Kind(Kind), KindLoc(KLoc), CommaLoc(CommaLoc) { + ChunkSizes[CHUNK_SIZE] = ChunkSize; + ChunkSizes[HELPER_CHUNK_SIZE] = HelperChunkSize; + } + + /// \brief Build an empty clause. + /// + explicit OMPDistScheduleClause() + : OMPClause(OMPC_dist_schedule, SourceLocation(), SourceLocation()), + Kind(OMPC_DIST_SCHEDULE_unknown) { + ChunkSizes[CHUNK_SIZE] = nullptr; + ChunkSizes[HELPER_CHUNK_SIZE] = nullptr; + } + + /// \brief Get kind of the clause. + /// + OpenMPDistScheduleClauseKind getDistScheduleKind() const { return Kind; } + /// \brief Get location of '('. + /// + SourceLocation getLParenLoc() { return LParenLoc; } + /// \brief Get kind location. + /// + SourceLocation getDistScheduleKindLoc() { return KindLoc; } + /// \brief Get location of ','. + /// + SourceLocation getCommaLoc() { return CommaLoc; } + /// \brief Get chunk size. + /// + Expr *getChunkSize() { + return dyn_cast_or_null(ChunkSizes[CHUNK_SIZE]); + } + /// \brief Get chunk size. + /// + Expr *getChunkSize() const { + return dyn_cast_or_null(ChunkSizes[CHUNK_SIZE]); + } + /// \brief Get helper chunk size. + /// + Expr *getHelperChunkSize() { + return dyn_cast_or_null(ChunkSizes[HELPER_CHUNK_SIZE]); + } + /// \brief Get helper chunk size. + /// + Expr *getHelperChunkSize() const { + return dyn_cast_or_null(ChunkSizes[HELPER_CHUNK_SIZE]); + } + + static bool classof(const OMPClause *T) { + return T->getClauseKind() == OMPC_dist_schedule; + } + + child_range children() { + return child_range(&ChunkSizes[CHUNK_SIZE], &ChunkSizes[CHUNK_SIZE] + 1); + } +}; + /// \brief This represents 'ordered' clause in the '#pragma omp ...' directive. /// /// \code Index: include/clang/AST/RecursiveASTVisitor.h =================================================================== --- include/clang/AST/RecursiveASTVisitor.h +++ include/clang/AST/RecursiveASTVisitor.h @@ -2434,6 +2434,10 @@ DEF_TRAVERSE_STMT(OMPTaskLoopDirective, { TRY_TO(TraverseOMPExecutableDirective(S)); }) +DEF_TRAVERSE_STMT(OMPDistributeDirective, + { TRY_TO(TraverseOMPExecutableDirective(S)); }) + + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { @@ -2725,6 +2729,14 @@ } template +bool RecursiveASTVisitor::VisitOMPDistScheduleClause( + OMPDistScheduleClause *C) { + TRY_TO(TraverseStmt(C->getChunkSize())); + TRY_TO(TraverseStmt(C->getHelperChunkSize())); + return true; +} + +template bool RecursiveASTVisitor::VisitOMPNumTeamsClause( OMPNumTeamsClause *C) { TRY_TO(TraverseStmt(C->getNumTeams())); Index: include/clang/AST/StmtOpenMP.h =================================================================== --- include/clang/AST/StmtOpenMP.h +++ include/clang/AST/StmtOpenMP.h @@ -2264,6 +2264,83 @@ } }; +/// \brief This represents '#pragma omp distribute' directive. +/// +/// \code +/// #pragma omp distribute private(a,b) +/// \endcode +/// In this example directive '#pragma omp distribute' has clauses 'private' +/// with the variables 'a' and 'b' +/// +class OMPDistributeDirective : public OMPLoopDirective { + friend class ASTStmtReader; + + /// \brief true if current directive has inner cancel directive. + bool HasCancel; + + /// \brief Build directive with the given start and end location. + /// + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending location of the directive. + /// \param CollapsedNum Number of collapsed nested loops. + /// \param NumClauses Number of clauses. + /// + OMPDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, unsigned NumClauses) + : OMPLoopDirective(this, OMPDistributeDirectiveClass, OMPD_distribute, + StartLoc, EndLoc, CollapsedNum, NumClauses), + HasCancel(false) {} + + /// \brief Build an empty directive. + /// + /// \param CollapsedNum Number of collapsed nested loops. + /// \param NumClauses Number of clauses. + /// + explicit OMPDistributeDirective(unsigned CollapsedNum, unsigned NumClauses) + : OMPLoopDirective(this, OMPDistributeDirectiveClass, OMPD_distribute, + SourceLocation(), SourceLocation(), CollapsedNum, + NumClauses), + HasCancel(false) {} + + /// \brief Set cancel state. + void setHasCancel(bool Has) { HasCancel = Has; } + +public: + /// \brief Creates directive with a list of \a Clauses. + /// + /// \param C AST context. + /// \param StartLoc Starting location of the directive kind. + /// \param EndLoc Ending Location of the directive. + /// \param CollapsedNum Number of collapsed loops. + /// \param Clauses List of clauses. + /// \param AssociatedStmt Statement, associated with the directive. + /// \param Exprs Helper expressions for CodeGen. + /// \param HasCancel true if current directive has inner cancel directive. + /// + static OMPDistributeDirective * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, ArrayRef Clauses, + Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel); + + /// \brief Creates an empty directive with the place + /// for \a NumClauses clauses. + /// + /// \param C AST context. + /// \param CollapsedNum Number of collapsed nested loops. + /// \param NumClauses Number of clauses. + /// + static OMPDistributeDirective *CreateEmpty(const ASTContext &C, + unsigned NumClauses, + unsigned CollapsedNum, EmptyShell); + + /// \brief Return true if current directive has inner cancel directive. + bool hasCancel() const { return HasCancel; } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPDistributeDirectiveClass; + } +}; + } // end namespace clang #endif Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -7909,6 +7909,14 @@ "the parameter of the 'ordered' clause must be greater than or equal to the parameter of the 'collapse' clause">; def note_collapse_loop_count : Note< "parameter of the 'collapse' clause">; +def err_omp_firstprivate_distribute_private_teams : Error< + "private variable in '#pragma omp teams' cannot be firstprivate in '#pragma omp distribute'">; +def err_omp_distribute_strictly_nested_in_teams : Error< + "'#pragma omp distribute' must be strictly nested in '#pragma omp teams'">; +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'">; } // end of OpenMP category let CategoryName = "Related Result Type Issue" in { Index: include/clang/Basic/OpenMPKinds.h =================================================================== --- include/clang/Basic/OpenMPKinds.h +++ include/clang/Basic/OpenMPKinds.h @@ -86,6 +86,13 @@ OMPC_MAP_unknown }; +/// \brief OpenMP attributes for 'dist_schedule' clause. +enum OpenMPDistScheduleClauseKind { +#define OPENMP_DIST_SCHEDULE_KIND(Name) OMPC_DIST_SCHEDULE_##Name, +#include "clang/Basic/OpenMPKinds.def" + OMPC_DIST_SCHEDULE_unknown +}; + OpenMPDirectiveKind getOpenMPDirectiveKind(llvm::StringRef Str); const char *getOpenMPDirectiveName(OpenMPDirectiveKind Kind); @@ -135,6 +142,13 @@ /// otherwise - false. bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind); +/// \brief Checks if the specified directive is a distribute directive. +/// \param DKind Specified directive. +/// \return true - the directive is a distribute-directive like 'omp +/// distribute', +/// otherwise - false. +bool isOpenMPDistributeDirective(OpenMPDirectiveKind DKind); + /// \brief Checks if the specified clause is one of private clauses like /// 'private', 'firstprivate', 'reduction' etc.. /// \param Kind Clause kind. Index: include/clang/Basic/OpenMPKinds.def =================================================================== --- include/clang/Basic/OpenMPKinds.def +++ include/clang/Basic/OpenMPKinds.def @@ -72,6 +72,9 @@ #ifndef OPENMP_TASKLOOP_CLAUSE # define OPENMP_TASKLOOP_CLAUSE(Name) #endif +#ifndef OPENMP_DISTRIBUTE_CLAUSE +#define OPENMP_DISTRIBUTE_CLAUSE(Name) +#endif #ifndef OPENMP_DEFAULT_KIND # define OPENMP_DEFAULT_KIND(Name) #endif @@ -90,6 +93,10 @@ #ifndef OPENMP_MAP_KIND #define OPENMP_MAP_KIND(Name) #endif +#ifndef OPENMP_DIST_SCHEDULE_KIND +#define OPENMP_DIST_SCHEDULE_KIND(Name) +#endif + // OpenMP directives. OPENMP_DIRECTIVE(threadprivate) @@ -112,6 +119,7 @@ OPENMP_DIRECTIVE(target) OPENMP_DIRECTIVE(teams) OPENMP_DIRECTIVE(cancel) +OPENMP_DIRECTIVE(distribute) OPENMP_DIRECTIVE_EXT(target_data, "target data") OPENMP_DIRECTIVE_EXT(parallel_for, "parallel for") OPENMP_DIRECTIVE_EXT(parallel_for_simd, "parallel for simd") @@ -154,6 +162,7 @@ OPENMP_CLAUSE(threads, OMPThreadsClause) OPENMP_CLAUSE(simd, OMPSIMDClause) OPENMP_CLAUSE(map, OMPMapClause) +OPENMP_CLAUSE(dist_schedule, OMPDistScheduleClause) OPENMP_CLAUSE(num_teams, OMPNumTeamsClause) OPENMP_CLAUSE(thread_limit, OMPThreadLimitClause) OPENMP_CLAUSE(priority, OMPPriorityClause) @@ -337,6 +346,16 @@ OPENMP_ORDERED_CLAUSE(threads) OPENMP_ORDERED_CLAUSE(simd) +// Clauses allowed for OpenMP directive 'distribute' +OPENMP_DISTRIBUTE_CLAUSE(private) +OPENMP_DISTRIBUTE_CLAUSE(firstprivate) +OPENMP_DISTRIBUTE_CLAUSE(lastprivate) +OPENMP_DISTRIBUTE_CLAUSE(collapse) +OPENMP_DISTRIBUTE_CLAUSE(dist_schedule) + +// Static attributes for 'dist_schedule' clause. +OPENMP_DIST_SCHEDULE_KIND(static) + // Map types and map type modifier for 'map' clause. OPENMP_MAP_KIND(alloc) OPENMP_MAP_KIND(to) @@ -385,4 +404,6 @@ #undef OPENMP_SIMD_CLAUSE #undef OPENMP_FOR_CLAUSE #undef OPENMP_FOR_SIMD_CLAUSE +#undef OPENMP_DISTRIBUTE_CLAUSE #undef OPENMP_MAP_KIND +#undef OPENMP_DIST_SCHEDULE_KIND Index: include/clang/Basic/StmtNodes.td =================================================================== --- include/clang/Basic/StmtNodes.td +++ include/clang/Basic/StmtNodes.td @@ -220,4 +220,5 @@ def OMPCancellationPointDirective : DStmt; def OMPCancelDirective : DStmt; def OMPTaskLoopDirective : DStmt; +def OMPDistributeDirective : DStmt; Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -7940,6 +7940,12 @@ ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc, llvm::DenseMap &VarsWithImplicitDSA); + /// \brief Called on well-formed '\#pragma omp distribute' after parsing + /// of the associated statement. + StmtResult ActOnOpenMPDistributeDirective( + ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc, + llvm::DenseMap &VarsWithImplicitDSA); OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, @@ -8016,6 +8022,12 @@ SourceLocation CommaLoc, SourceLocation EndLoc); + /// \brief Called on well-formed 'dist_schedule' clause. + OMPClause *ActOnOpenMPDistScheduleClause( + OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, + SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, + SourceLocation CommaLoc, SourceLocation EndLoc); + OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, SourceLocation EndLoc); /// \brief Called on well-formed 'nowait' clause. Index: include/clang/Serialization/ASTBitCodes.h =================================================================== --- include/clang/Serialization/ASTBitCodes.h +++ include/clang/Serialization/ASTBitCodes.h @@ -1448,6 +1448,7 @@ STMT_OMP_CANCELLATION_POINT_DIRECTIVE, STMT_OMP_CANCEL_DIRECTIVE, STMT_OMP_TASKLOOP_DIRECTIVE, + STMT_OMP_DISTRIBUTE_DIRECTIVE, EXPR_OMP_ARRAY_SECTION, // ARC Index: lib/AST/StmtOpenMP.cpp =================================================================== --- lib/AST/StmtOpenMP.cpp +++ lib/AST/StmtOpenMP.cpp @@ -786,3 +786,49 @@ return new (Mem) OMPTaskLoopDirective(CollapsedNum, NumClauses); } +OMPDistributeDirective *OMPDistributeDirective::Create( + const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, ArrayRef Clauses, Stmt *AssociatedStmt, + const HelperExprs &Exprs, bool HasCancel) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPDistributeDirective), + llvm::alignOf()); + void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + + sizeof(Stmt *) * + numLoopChildren(CollapsedNum, OMPD_distribute)); + OMPDistributeDirective *Dir = new (Mem) + OMPDistributeDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + Dir->setIterationVariable(Exprs.IterationVarRef); + Dir->setLastIteration(Exprs.LastIteration); + Dir->setCalcLastIteration(Exprs.CalcLastIteration); + Dir->setPreCond(Exprs.PreCond); + Dir->setCond(Exprs.Cond); + Dir->setInit(Exprs.Init); + Dir->setInc(Exprs.Inc); + Dir->setIsLastIterVariable(Exprs.IL); + Dir->setLowerBoundVariable(Exprs.LB); + Dir->setUpperBoundVariable(Exprs.UB); + Dir->setStrideVariable(Exprs.ST); + Dir->setEnsureUpperBound(Exprs.EUB); + Dir->setNextLowerBound(Exprs.NLB); + Dir->setNextUpperBound(Exprs.NUB); + Dir->setCounters(Exprs.Counters); + Dir->setPrivateCounters(Exprs.PrivateCounters); + Dir->setInits(Exprs.Inits); + Dir->setUpdates(Exprs.Updates); + Dir->setFinals(Exprs.Finals); + Dir->setHasCancel(HasCancel); + return Dir; +} + +OMPDistributeDirective * +OMPDistributeDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, + unsigned CollapsedNum, EmptyShell) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPDistributeDirective), + llvm::alignOf()); + void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + + sizeof(Stmt *) * + numLoopChildren(CollapsedNum, OMPD_distribute)); + return new (Mem) OMPDistributeDirective(CollapsedNum, NumClauses); +} Index: lib/AST/StmtPrinter.cpp =================================================================== --- lib/AST/StmtPrinter.cpp +++ lib/AST/StmtPrinter.cpp @@ -877,6 +877,16 @@ OS << ")"; } } + +void OMPClausePrinter::VisitOMPDistScheduleClause(OMPDistScheduleClause *Node) { + OS << "schedule(" << getOpenMPSimpleClauseTypeName( + OMPC_dist_schedule, Node->getDistScheduleKind()); + if (Node->getChunkSize()) { + OS << ", "; + Node->getChunkSize()->printPretty(OS, nullptr, Policy); + } + OS << ")"; +} } //===----------------------------------------------------------------------===// @@ -1041,6 +1051,11 @@ PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) { + Indent() << "#pragma omp distribute "; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// Index: lib/AST/StmtProfile.cpp =================================================================== --- lib/AST/StmtProfile.cpp +++ lib/AST/StmtProfile.cpp @@ -589,6 +589,21 @@ VisitOMPLoopDirective(S); } +void StmtProfiler::VisitOMPDistributeDirective( + const OMPDistributeDirective *S) { + VisitOMPLoopDirective(S); +} + +void OMPClauseProfiler::VisitOMPDistScheduleClause( + const OMPDistScheduleClause *C) { + if (C->getChunkSize()) { + Profiler->VisitStmt(C->getChunkSize()); + if (C->getHelperChunkSize()) { + Profiler->VisitStmt(C->getChunkSize()); + } + } +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } Index: lib/Basic/OpenMPKinds.cpp =================================================================== --- lib/Basic/OpenMPKinds.cpp +++ lib/Basic/OpenMPKinds.cpp @@ -106,6 +106,11 @@ #define OPENMP_MAP_KIND(Name) .Case(#Name, OMPC_MAP_##Name) #include "clang/Basic/OpenMPKinds.def" .Default(OMPC_MAP_unknown); + case OMPC_dist_schedule: + return llvm::StringSwitch(Str) +#define OPENMP_DIST_SCHEDULE_KIND(Name) .Case(#Name, OMPC_DIST_SCHEDULE_##Name) +#include "clang/Basic/OpenMPKinds.def" + .Default(OMPC_DIST_SCHEDULE_unknown); case OMPC_unknown: case OMPC_threadprivate: case OMPC_if: @@ -206,6 +211,15 @@ default: break; } + case OMPC_dist_schedule: + switch (Type) { + case OMPC_DIST_SCHEDULE_unknown: + return "unknown"; +#define OPENMP_DIST_SCHEDULE_KIND(Name) \ + case OMPC_DIST_SCHEDULE_##Name: \ + return #Name; +#include "clang/Basic/OpenMPKinds.def" + } llvm_unreachable("Invalid OpenMP 'map' clause type"); case OMPC_unknown: case OMPC_threadprivate: @@ -422,6 +436,16 @@ break; } break; + case OMPD_distribute: + switch (CKind) { +#define OPENMP_DISTRIBUTE_CLAUSE(Name) \ + case OMPC_##Name: \ + return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; case OMPD_unknown: case OMPD_threadprivate: case OMPD_section: @@ -440,15 +464,15 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd || DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd || - DKind == OMPD_taskloop; // TODO add next directives. + DKind == OMPD_distribute || DKind == OMPD_taskloop; // TODO add next directives. } bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) { return DKind == OMPD_for || DKind == OMPD_for_simd || DKind == OMPD_sections || DKind == OMPD_section || DKind == OMPD_single || DKind == OMPD_parallel_for || - DKind == OMPD_parallel_for_simd || - DKind == OMPD_parallel_sections; // TODO add next directives. + DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections || + DKind == OMPD_distribute; // TODO add next directives. } bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) { @@ -470,6 +494,10 @@ DKind == OMPD_parallel_for_simd; // TODO add next directives. } +bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) { + return Kind == OMPD_distribute; +} + bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) { return Kind == OMPC_private || Kind == OMPC_firstprivate || Kind == OMPC_lastprivate || Kind == OMPC_linear || Index: lib/CodeGen/CGStmt.cpp =================================================================== --- lib/CodeGen/CGStmt.cpp +++ lib/CodeGen/CGStmt.cpp @@ -259,6 +259,9 @@ case Stmt::OMPTaskLoopDirectiveClass: EmitOMPTaskLoopDirective(cast(*S)); break; +case Stmt::OMPDistributeDirectiveClass: + EmitOMPDistributeDirective(cast(*S)); + break; } } Index: lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- lib/CodeGen/CGStmtOpenMP.cpp +++ lib/CodeGen/CGStmtOpenMP.cpp @@ -2001,6 +2001,11 @@ }(), S.getLocStart()); } +void CodeGenFunction::EmitOMPDistributeDirective( + const OMPDistributeDirective &S) { + llvm_unreachable("CodeGen for 'omp distribute' is not supported yet."); +} + static llvm::Function *emitOutlinedOrderedFunction(CodeGenModule &CGM, const CapturedStmt *S) { CodeGenFunction CGF(CGM, /*suppressNewContext=*/true); @@ -2434,6 +2439,7 @@ case OMPC_threads: case OMPC_simd: case OMPC_map: + case OMPC_dist_schedule: case OMPC_num_teams: case OMPC_thread_limit: case OMPC_priority: Index: lib/CodeGen/CodeGenFunction.h =================================================================== --- lib/CodeGen/CodeGenFunction.h +++ lib/CodeGen/CodeGenFunction.h @@ -2335,6 +2335,7 @@ EmitOMPCancellationPointDirective(const OMPCancellationPointDirective &S); void EmitOMPCancelDirective(const OMPCancelDirective &S); void EmitOMPTaskLoopDirective(const OMPTaskLoopDirective &S); + void EmitOMPDistributeDirective(const OMPDistributeDirective &S); /// \brief Emit inner loop of the worksharing/simd construct. /// Index: lib/Parse/ParseOpenMP.cpp =================================================================== --- lib/Parse/ParseOpenMP.cpp +++ lib/Parse/ParseOpenMP.cpp @@ -138,6 +138,7 @@ case OMPD_cancel: case OMPD_target_data: case OMPD_taskloop: + case OMPD_distribute: Diag(Tok, diag::err_omp_unexpected_directive) << getOpenMPDirectiveName(DKind); break; @@ -158,7 +159,7 @@ /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | /// 'for simd' | 'parallel for simd' | 'target' | 'target data' | -/// 'taskgroup' | 'teams' {clause} +/// 'taskgroup' | 'teams' {clause} | 'distribute' /// annot_pragma_openmp_end /// StmtResult @@ -233,8 +234,9 @@ case OMPD_target: case OMPD_teams: case OMPD_taskgroup: - case OMPD_target_data: - case OMPD_taskloop: { + case OMPD_taskloop: + case OMPD_distribute: + case OMPD_target_data: { ConsumeToken(); // Parse directive name of the 'critical' directive if any. if (DKind == OMPD_critical) { @@ -397,7 +399,7 @@ /// mergeable-clause | flush-clause | read-clause | write-clause | /// update-clause | capture-clause | seq_cst-clause | device-clause | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | -/// thread_limit-clause | priority-clause +/// thread_limit-clause | priority-clause | dist_schedule-clause /// OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, bool FirstClause) { @@ -464,6 +466,7 @@ Clause = ParseOpenMPSimpleClause(CKind); break; case OMPC_schedule: + case OMPC_dist_schedule: // OpenMP [2.7.1, Restrictions, p. 3] // Only one schedule clause can appear on a loop directive. if (!FirstClause) { @@ -664,6 +667,15 @@ Arg == OMPC_SCHEDULE_guided) && Tok.is(tok::comma)) DelimLoc = ConsumeAnyToken(); + } else if (Kind == OMPC_dist_schedule) { + Arg = getOpenMPSimpleClauseType( + Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); + KLoc = Tok.getLocation(); + if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && + Tok.isNot(tok::annot_pragma_openmp_end)) + ConsumeAnyToken(); + if (Arg == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) + DelimLoc = ConsumeAnyToken(); } else { assert(Kind == OMPC_if); KLoc = Tok.getLocation(); @@ -678,8 +690,9 @@ } } - bool NeedAnExpression = - (Kind == OMPC_schedule && DelimLoc.isValid()) || Kind == OMPC_if; + bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || + (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || + Kind == OMPC_if; if (NeedAnExpression) { SourceLocation ELoc = Tok.getLocation(); ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -1455,7 +1455,15 @@ Params); break; } - case OMPD_taskloop: { + case OMPD_taskloop: { + Sema::CapturedParamNameType Params[] = { + std::make_pair(StringRef(), QualType()) // __context with shared vars + }; + ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, + Params); + break; + } + case OMPD_distribute: { Sema::CapturedParamNameType Params[] = { std::make_pair(StringRef(), QualType()) // __context with shared vars }; @@ -1519,6 +1527,7 @@ // Allowed nesting of constructs // +------------------+-----------------+------------------------------------+ // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| + // | | | Strictly (!!) | // +------------------+-----------------+------------------------------------+ // | parallel | parallel | * | // | parallel | for | * | @@ -1977,6 +1986,7 @@ // | | point | | // | teams | cancel | | // | teams | taskloop | + | + // | teams | distribute | !! | // +------------------+-----------------+------------------------------------+ // | taskloop | parallel | * | // | taskloop | for | + | @@ -2013,7 +2023,8 @@ NoRecommend, ShouldBeInParallelRegion, ShouldBeInOrderedRegion, - ShouldBeInTargetRegion + ShouldBeInTargetRegion, + ShouldBeInTeamsRegion } Recommend = NoRecommend; if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { // OpenMP [2.16, Nesting of Regions] @@ -2048,6 +2059,17 @@ // called from OpenMP regions with the required preconditions). if (ParentRegion == OMPD_unknown) return false; + if (isOpenMPDistributeDirective(CurrentRegion)) { + // OpenMP 4.5 [2.17 Nesting of Regions] + // The region associated with the distribute construct must be strictly + // nested inside a teams region + if (ParentRegion != OMPD_teams) { + SemaRef.Diag(StartLoc, + diag::err_omp_distribute_strictly_nested_in_teams); + return true; + } + return false; + } if (CurrentRegion == OMPD_cancellation_point || CurrentRegion == OMPD_cancel) { // OpenMP [2.16, Nesting of Regions] @@ -2153,8 +2175,8 @@ // distribute, parallel, parallel sections, parallel workshare, and the // parallel loop and parallel loop SIMD constructs are the only OpenMP // constructs that can be closely nested in the teams region. - // TODO: add distribute directive. - NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); + NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && + !isOpenMPDistributeDirective(CurrentRegion); Recommend = ShouldBeInParallelRegion; } if (NestingProhibited) { @@ -2419,6 +2441,10 @@ EndLoc, VarsWithInheritedDSA); AllowedNameModifiers.push_back(OMPD_taskloop); break; + case OMPD_distribute: + Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, + EndLoc, VarsWithInheritedDSA); + break; case OMPD_threadprivate: llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: @@ -5157,6 +5183,33 @@ NestedLoopCount, Clauses, AStmt, B); } +StmtResult Sema::ActOnOpenMPDistributeDirective( + ArrayRef Clauses, Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc, + llvm::DenseMap &VarsWithImplicitDSA) { + if (!AStmt) + return StmtError(); + + assert(isa(AStmt) && "Captured statement expected"); + OMPLoopDirective::HelperExprs B; + // In presence of clause 'collapse' with number of loops, it will + // define the nested loops number. + unsigned NestedLoopCount = + CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), + nullptr /*ordered not a clause on distribute*/, AStmt, + *this, *DSAStack, VarsWithImplicitDSA, B); + if (NestedLoopCount == 0) + return StmtError(); + + assert((CurContext->isDependentContext() || B.builtAll()) && + "omp for loop exprs were not built"); + + getCurFunction()->setHasBranchProtectedScope(); + return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, + NestedLoopCount, Clauses, AStmt, B, + DSAStack->isCancelRegion()); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, @@ -5220,6 +5273,7 @@ case OMPC_threads: case OMPC_simd: case OMPC_map: + case OMPC_dist_schedule: case OMPC_unknown: llvm_unreachable("Clause is not allowed."); } @@ -5493,6 +5547,7 @@ case OMPC_threads: case OMPC_simd: case OMPC_map: + case OMPC_dist_schedule: case OMPC_num_teams: case OMPC_thread_limit: case OMPC_priority: @@ -5594,6 +5649,12 @@ ActOnOpenMPIfClause(static_cast(Argument), Expr, StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); break; + case OMPC_dist_schedule: + Res = ActOnOpenMPDistScheduleClause( + static_cast(Argument), Expr, StartLoc, + LParenLoc, ArgumentLoc, DelimLoc, EndLoc); + break; + case OMPC_final: case OMPC_num_threads: case OMPC_safelen: @@ -5700,6 +5761,59 @@ EndLoc, Kind, ValExpr, HelperValExpr); } +OMPClause *Sema::ActOnOpenMPDistScheduleClause( + OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, + SourceLocation EndLoc) { + if (Kind == OMPC_DIST_SCHEDULE_unknown) { + std::string Values; + Values += "'"; + Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); + Values += "'"; + Diag(KindLoc, diag::err_omp_unexpected_clause_value) + << Values << getOpenMPClauseName(OMPC_dist_schedule); + return nullptr; + } + Expr *ValExpr = ChunkSize; + Expr *HelperValExpr = nullptr; + if (ChunkSize) { + if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && + !ChunkSize->isInstantiationDependent() && + !ChunkSize->containsUnexpandedParameterPack()) { + SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); + ExprResult Val = + PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); + if (Val.isInvalid()) + return nullptr; + + ValExpr = Val.get(); + + // OpenMP [2.7.1, Restrictions] + // chunk_size must be a loop invariant integer expression with a positive + // value. + llvm::APSInt Result; + if (ValExpr->isIntegerConstantExpr(Result, Context)) { + if (Result.isSigned() && !Result.isStrictlyPositive()) { + Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) + << "dist_schedule" << ChunkSize->getSourceRange(); + return nullptr; + } + } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { + auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), + ChunkSize->getType(), ".chunk."); + auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), + ChunkSize->getExprLoc(), + /*RefersToCapture=*/true); + HelperValExpr = ImpVarRef; + } + } + } + + return new (Context) + OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, + Kind, ValExpr, HelperValExpr); +} + OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, SourceLocation EndLoc) { @@ -5761,6 +5875,7 @@ case OMPC_depend: case OMPC_device: case OMPC_map: + case OMPC_dist_schedule: case OMPC_num_teams: case OMPC_thread_limit: case OMPC_priority: @@ -5893,6 +6008,7 @@ case OMPC_device: case OMPC_threads: case OMPC_simd: + case OMPC_dist_schedule: case OMPC_num_teams: case OMPC_thread_limit: case OMPC_priority: @@ -6174,6 +6290,49 @@ continue; } } + + // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] + // A list item that is private within a teams region must not appear in a + // firstprivate clause on a distribute construct if any of the distribute + // regions arising from the distribute construct ever bind to any of the + // teams regions arising from the teams construct. + // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] + // A list item that appears in a reduction clause of a teams construct + // must not appear in a firstprivate clause on a distribute construct if + // any of the distribute regions arising from the distribute construct + // ever bind to any of the teams regions arising from the teams construct. + // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] + // A list item may appear in a firstprivate or lastprivate clause but not + // both. + if (CurrDir == OMPD_distribute) { + DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), + [](OpenMPDirectiveKind K) -> bool { + return isOpenMPTeamsDirective(K); + }, + false); + if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { + Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); + ReportOriginalDSA(*this, DSAStack, VD, DVar); + continue; + } + DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), + [](OpenMPDirectiveKind K) -> bool { + return isOpenMPTeamsDirective(K); + }, + false); + if (DVar.CKind == OMPC_reduction && + isOpenMPTeamsDirective(DVar.DKind)) { + Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); + ReportOriginalDSA(*this, DSAStack, VD, DVar); + continue; + } + DVar = DSAStack->getTopDSA(VD, false); + if (DVar.CKind == OMPC_lastprivate) { + Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); + ReportOriginalDSA(*this, DSAStack, VD, DVar); + continue; + } + } } // Variably modified types are not supported for tasks. @@ -6370,6 +6529,18 @@ if (AssignmentOp.isInvalid()) continue; + // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] + // A list item may appear in a firstprivate or lastprivate clause but not + // both. + if (CurrDir == OMPD_distribute) { + DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); + if (DVar.CKind == OMPC_firstprivate) { + Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); + ReportOriginalDSA(*this, DSAStack, VD, DVar); + continue; + } + } + if (TopDVar.CKind != OMPC_firstprivate) DSAStack->addDSA(VD, DE, OMPC_lastprivate); Vars.push_back(DE); Index: lib/Sema/TreeTransform.h =================================================================== --- lib/Sema/TreeTransform.h +++ lib/Sema/TreeTransform.h @@ -1666,6 +1666,19 @@ LParenLoc, EndLoc); } + /// \brief Build a new OpenMP 'dist_schedule' clause. + /// + /// By default, performs semantic analysis to build the new OpenMP clause. + /// Subclasses may override this routine to provide different behavior. + OMPClause * + RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, + Expr *ChunkSize, SourceLocation StartLoc, + SourceLocation LParenLoc, SourceLocation KindLoc, + SourceLocation CommaLoc, SourceLocation EndLoc) { + return getSema().ActOnOpenMPDistScheduleClause( + Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); + } + /// \brief Build a new OpenMP 'num_teams' clause. /// /// By default, performs semantic analysis to build the new statement. @@ -7364,6 +7377,17 @@ return Res; } +template +StmtResult TreeTransform::TransformOMPDistributeDirective( + OMPDistributeDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, + D->getLocStart()); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + //===----------------------------------------------------------------------===// // OpenMP clause transformation //===----------------------------------------------------------------------===// @@ -7743,6 +7767,17 @@ } template +OMPClause *TreeTransform::TransformOMPDistScheduleClause( + OMPDistScheduleClause *C) { + ExprResult E = getDerived().TransformExpr(C->getChunkSize()); + if (E.isInvalid()) + return nullptr; + return getDerived().RebuildOMPDistScheduleClause( + C->getDistScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(), + C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd()); +} + +template OMPClause * TreeTransform::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { ExprResult E = getDerived().TransformExpr(C->getNumTeams()); Index: lib/Serialization/ASTReaderStmt.cpp =================================================================== --- lib/Serialization/ASTReaderStmt.cpp +++ lib/Serialization/ASTReaderStmt.cpp @@ -1850,6 +1850,9 @@ case OMPC_map: C = OMPMapClause::CreateEmpty(Context, Record[Idx++]); break; + case OMPC_dist_schedule: + C = new (Context) OMPDistScheduleClause(); + break; case OMPC_num_teams: C = new (Context) OMPNumTeamsClause(); break; @@ -2183,6 +2186,16 @@ C->setVarRefs(Vars); } +void OMPClauseReader::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { + C->setDistScheduleKind( + static_cast(Record[Idx++])); + C->setChunkSize(Reader->Reader.ReadSubExpr()); + C->setHelperChunkSize(Reader->Reader.ReadSubExpr()); + C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); + C->setDistScheduleKindLoc(Reader->ReadSourceLocation(Record, Idx)); + C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx)); +} + void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { C->setNumTeams(Reader->Reader.ReadSubExpr()); C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); @@ -2420,6 +2433,11 @@ D->setCancelRegion(static_cast(Record[Idx++])); } +void ASTStmtReader::VisitOMPDistributeDirective(OMPDistributeDirective *D) { + VisitOMPLoopDirective(D); + D->setHasCancel(Record[Idx++]); +} + void ASTStmtReader::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *D) { VisitOMPLoopDirective(D); } @@ -3054,6 +3072,14 @@ break; } + case STMT_OMP_DISTRIBUTE_DIRECTIVE: { + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + S = OMPDistributeDirective::CreateEmpty(Context, NumClauses, CollapsedNum, + Empty); + break; + } + case EXPR_CXX_OPERATOR_CALL: S = new (Context) CXXOperatorCallExpr(Context, Empty); break; Index: lib/Serialization/ASTWriterStmt.cpp =================================================================== --- lib/Serialization/ASTWriterStmt.cpp +++ lib/Serialization/ASTWriterStmt.cpp @@ -2001,6 +2001,15 @@ Writer->Writer.AddStmt(VE); } +void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { + Record.push_back(C->getDistScheduleKind()); + Writer->Writer.AddStmt(C->getChunkSize()); + Writer->Writer.AddStmt(C->getHelperChunkSize()); + Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); + Writer->Writer.AddSourceLocation(C->getDistScheduleKindLoc(), Record); + Writer->Writer.AddSourceLocation(C->getCommaLoc(), Record); +} + void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { Writer->Writer.AddStmt(C->getNumTeams()); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); @@ -2249,6 +2258,12 @@ Code = serialization::STMT_OMP_TASKLOOP_DIRECTIVE; } +void ASTStmtWriter::VisitOMPDistributeDirective(OMPDistributeDirective *D) { + VisitOMPLoopDirective(D); + Record.push_back(D->hasCancel() ? 1 : 0); + Code = serialization::STMT_OMP_DISTRIBUTE_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// Index: lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -830,6 +830,7 @@ case Stmt::OMPCancellationPointDirectiveClass: case Stmt::OMPCancelDirectiveClass: case Stmt::OMPTaskLoopDirectiveClass: + case Stmt::OMPDistributeDirectiveClass: llvm_unreachable("Stmt should not be in analyzer evaluation loop"); case Stmt::ObjCSubscriptRefExprClass: Index: test/OpenMP/distribute_ast_print.cpp =================================================================== --- /dev/null +++ test/OpenMP/distribute_ast_print.cpp @@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s +// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +void foo() {} + +template +T tmain(T argc) { + T b = argc, c, d, e, f, g; + static T a; +// CHECK: static T a; +#pragma omp distribute +// CHECK-NEXT: #pragma omp distribute + for (int i=0; i < 2; ++i)a=2; +// CHECK-NEXT: for (int i = 0; i < 2; ++i) +// CHECK-NEXT: a = 2; +#pragma omp target +#pragma omp teams +#pragma omp distribute private(argc, b), firstprivate(c, d), collapse(2) + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j)foo(); +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams +// CHECK-NEXT: #pragma omp distribute private(argc,b) firstprivate(c,d) collapse(2) +// CHECK-NEXT: for (int i = 0; i < 10; ++i) +// CHECK-NEXT: for (int j = 0; j < 10; ++j) +// CHECK-NEXT: foo(); + for (int i = 0; i < 10; ++i)foo(); +// CHECK-NEXT: for (int i = 0; i < 10; ++i) +// CHECK-NEXT: foo(); +#pragma omp distribute +// CHECK: #pragma omp distribute + for (int i = 0; i < 10; ++i)foo(); +// CHECK-NEXT: for (int i = 0; i < 10; ++i) +// CHECK-NEXT: foo(); + return T(); +} + +int main (int argc, char **argv) { + int b = argc, c, d, e, f, g; + static int a; +// CHECK: static int a; +#pragma omp distribute +// CHECK-NEXT: #pragma omp distribute + for (int i=0; i < 2; ++i)a=2; +// CHECK-NEXT: for (int i = 0; i < 2; ++i) +// CHECK-NEXT: a = 2; +#pragma omp target +#pragma omp teams +#pragma omp distribute private(argc,b),firstprivate(argv, c), collapse(2) + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j)foo(); +// CHECK-NEXT: #pragma omp target +// CHECK-NEXT: #pragma omp teams +// CHECK-NEXT: #pragma omp distribute private(argc,b) firstprivate(argv,c) collapse(2) +// CHECK-NEXT: for (int i = 0; i < 10; ++i) +// CHECK-NEXT: for (int j = 0; j < 10; ++j) +// CHECK-NEXT: foo(); + for (int i = 0; i < 10; ++i)foo(); +// CHECK-NEXT: for (int i = 0; i < 10; ++i) +// CHECK-NEXT: foo(); +#pragma omp distribute +// CHECK: #pragma omp distribute + for (int i = 0; i < 10; ++i)foo(); +// CHECK-NEXT: for (int i = 0; i < 10; ++i) +// CHECK-NEXT: foo(); + return (0); +} + +#endif Index: test/OpenMP/distribute_collapse_messages.cpp =================================================================== --- /dev/null +++ test/OpenMP/distribute_collapse_messages.cpp @@ -0,0 +1,83 @@ +// RUN: %clang_cc1 -verify -fopenmp %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} + +template // expected-note {{declared here}} +T tmain(T argc, S **argv) { //expected-note 2 {{declared here}} + #pragma omp distribute collapse // expected-error {{expected '(' after 'collapse'}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse () // expected-error {{expected expression}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + // expected-error@+3 {{expected ')'}} expected-note@+3 {{to match this '('}} + // expected-error@+2 2 {{expression is not an integral constant expression}} + // expected-note@+1 2 {{read of non-const variable 'argc' is not allowed in a constant expression}} + #pragma omp distribute collapse (argc + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + // expected-error@+1 2 {{argument to 'collapse' clause must be a strictly positive integer value}} + #pragma omp distribute collapse (ST // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse (1)) // expected-warning {{extra tokens at the end of '#pragma omp distribute' are ignored}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp distribute', but found only 1}} + // expected-error@+3 2 {{directive '#pragma omp distribute' cannot contain more than one 'collapse' clause}} + // expected-error@+2 2 {{argument to 'collapse' clause must be a strictly positive integer value}} + // expected-error@+1 2 {{expression is not an integral constant expression}} + #pragma omp distribute collapse (foobool(argc)), collapse (true), collapse (-5) + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse (S) // expected-error {{'S' does not refer to a value}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + // expected-error@+1 2 {{expression is not an integral constant expression}} + #pragma omp distribute collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse (1) + for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse (N) // expected-error {{argument to 'collapse' clause must be a strictly positive integer value}} + for (T i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; + #pragma omp distribute collapse (2) // expected-note {{as specified in 'collapse' clause}} + foo(); // expected-error {{expected 2 for loops after '#pragma omp distribute'}} + return argc; +} + +int main(int argc, char **argv) { + #pragma omp distribute collapse // expected-error {{expected '(' after 'collapse'}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp distribute collapse ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp distribute collapse () // expected-error {{expected expression}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp distribute collapse (4 // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-note {{as specified in 'collapse' clause}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; // expected-error {{expected 4 for loops after '#pragma omp distribute', but found only 1}} + #pragma omp distribute collapse (2+2)) // expected-warning {{extra tokens at the end of '#pragma omp distribute' are ignored}} expected-note {{as specified in 'collapse' clause}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; // expected-error {{expected 4 for loops after '#pragma omp distribute', but found only 1}} + #pragma omp distribute collapse (foobool(1) > 0 ? 1 : 2) // expected-error {{expression is not an integral constant expression}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + // expected-error@+3 {{expression is not an integral constant expression}} + // expected-error@+2 2 {{directive '#pragma omp distribute' cannot contain more than one 'collapse' clause}} + // expected-error@+1 2 {{argument to 'collapse' clause must be a strictly positive integer value}} + #pragma omp distribute collapse (foobool(argc)), collapse (true), collapse (-5) + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + #pragma omp distribute collapse (S1) // expected-error {{'S1' does not refer to a value}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + // expected-error@+1 {{expression is not an integral constant expression}} + #pragma omp distribute collapse (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4]; + // expected-error@+3 {{statement after '#pragma omp distribute' must be a for loop}} + // expected-note@+1 {{in instantiation of function template specialization 'tmain' requested here}} + #pragma omp distribute collapse(collapse(tmain(argc, argv) // expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}} + foo(); + #pragma omp distribute collapse (2) // expected-note {{as specified in 'collapse' clause}} + foo(); // expected-error {{expected 2 for loops after '#pragma omp distribute'}} + // expected-note@+1 {{in instantiation of function template specialization 'tmain' requested here}} + return tmain(argc, argv); +} + Index: test/OpenMP/distribute_dist_schedule_messages.cpp =================================================================== --- /dev/null +++ test/OpenMP/distribute_dist_schedule_messages.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 -o - %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} + +int main(int argc, char **argv) { + #pragma omp distribute dist_schedule // expected-error {{expected '(' after 'dist_schedule'}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule ( // expected-error {{expected 'static' in OpenMP clause 'dist_schedule'}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule () // expected-error {{expected 'static' in OpenMP clause 'dist_schedule'}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (static // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (static, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (argc)) // expected-error {{expected 'static' in OpenMP clause 'dist_schedule'}} expected-warning {{extra tokens at the end of '#pragma omp distribute' are ignored}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (static, argc > 0 ? argv[1] : argv[2]) // expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (static), dist_schedule (static, 1) // expected-error {{directive '#pragma omp distribute' cannot contain more than one 'dist_schedule' clause}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (static, S1) // expected-error {{'S1' does not refer to a value}} + for (int i = 0; i < 10; ++i) foo(); + #pragma omp distribute dist_schedule (static, argv[1]=2) // expected-error {{expression must have integral or unscoped enumeration type, not 'char *'}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int i = 0; i < 10; ++i) foo(); + + return 0; +} Index: test/OpenMP/distribute_firstprivate_messages.cpp =================================================================== --- /dev/null +++ test/OpenMP/distribute_firstprivate_messages.cpp @@ -0,0 +1,157 @@ +// RUN: %clang_cc1 -verify -fopenmp %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; + +public: + S2() : a(0) {} + S2(const S2 &s2) : a(s2.a) {} + static float S2s; + static const float S2sc; +}; +const float S2::S2sc = 0; +const S2 b; +const S2 ba[5]; +class S3 { + int a; + S3 &operator=(const S3 &s3); + +public: + S3() : a(0) {} // expected-note {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} + S3(S3 &s3) : a(s3.a) {} // expected-note {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}} +}; +const S3 c; +const S3 ca[5]; +extern const int f; +class S4 { + int a; + S4(); + S4(const S4 &s4); +public: + S4(int v):a(v) { } +}; +class S5 { + int a; + S5():a(0) {} + S5(const S5 &s5):a(s5.a) { } +public: + S5(int v):a(v) { } +}; +class S6 { + int a; +public: + S6() : a(0) { } +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}} + +int main(int argc, char **argv) { + const int d = 5; + const int da[5] = { 0 }; + S4 e(4); + S5 g(5); + S6 p; + int i; + int &j = i; + #pragma omp distribute firstprivate // expected-error {{expected '(' after 'firstprivate'}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp distribute firstprivate ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp distribute firstprivate () // expected-error {{expected expression}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (argc) + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (S1) // expected-error {{'S1' does not refer to a value}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate (argv[1]) // expected-error {{expected variable name}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(ba) + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(da) + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(S2::S2s) + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(S2::S2sc) + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute private(i), firstprivate(i) // expected-error {{private variable cannot be firstprivate}} expected-note{{defined as private}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams shared(i) + #pragma omp distribute firstprivate(i) + for (j = 0; j < argc; ++j) foo(); + #pragma omp target + #pragma omp teams shared(i) + #pragma omp distribute firstprivate(i) // expected-note {{defined as firstprivate}} + for (i = 0; i < argc; ++i) foo(); // expected-error {{loop iteration variable in the associated loop of 'omp distribute' directive may not be firstprivate, predetermined as private}} + #pragma omp target + #pragma omp teams private(argc) // expected-note {{defined as private}} + #pragma omp distribute firstprivate(argc) // expected-error {{private variable in '#pragma omp teams' cannot be firstprivate in '#pragma omp distribute'}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams reduction(+:argc) // expected-note {{defined as reduction}} + #pragma omp distribute firstprivate(argc) // expected-error {{reduction variable in '#pragma omp teams' cannot be firstprivate in '#pragma omp distribute'}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(j) + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams + #pragma omp distribute lastprivate(argc), firstprivate(argc) // expected-error {{lastprivate variable cannot be firstprivate in '#pragma omp distribute'}} expected-note{{defined as lastprivate}} + for (i = 0; i < argc; ++i) foo(); + #pragma omp target + #pragma omp teams +#pragma omp distribute firstprivate(argc), lastprivate(argc) // expected-error {{lastprivate variable cannot be firstprivate in '#pragma omp distribute'}} expected-note{{defined as firstprivate}} + for (i = 0; i < argc; ++i) foo(); + return 0; +} Index: test/OpenMP/distribute_private_messages.cpp =================================================================== --- /dev/null +++ test/OpenMP/distribute_private_messages.cpp @@ -0,0 +1,132 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -ferror-limit 100 %s + +void foo() { +} + +bool foobool(int argc) { + return argc; +} + +struct S1; // expected-note {{declared here}} expected-note {{forward declaration of 'S1'}} +extern S1 a; +class S2 { + mutable int a; +public: + S2():a(0) { } + static float S2s; // expected-note {{predetermined as shared}} +}; +const S2 b; +const S2 ba[5]; +class S3 { + int a; +public: + S3():a(0) { } +}; +const S3 c; // expected-note {{predetermined as shared}} +const S3 ca[5]; // expected-note {{predetermined as shared}} +extern const int f; // expected-note {{predetermined as shared}} +class S4 { + int a; + S4(); // expected-note {{implicitly declared private here}} +public: + S4(int v):a(v) { } +}; +class S5 { + int a; + S5():a(0) {} // expected-note {{implicitly declared private here}} +public: + S5(int v):a(v) { } +}; + +S3 h; +#pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}} + + +int main(int argc, char **argv) { + const int d = 5; // expected-note {{predetermined as shared}} + const int da[5] = { 0 }; // expected-note {{predetermined as shared}} + S4 e(4); + S5 g(5); + int i; + int &j = i; + #pragma omp distribute private // expected-error {{expected '(' after 'private'}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private () // expected-error {{expected expression}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (argc) + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (S1) // expected-error {{'S1' does not refer to a value}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (a, b, c, d, f) // expected-error {{private variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be private}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private (argv[1]) // expected-error {{expected variable name}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(ba) + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(ca) // expected-error {{shared variable cannot be private}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(da) // expected-error {{shared variable cannot be private}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(S2::S2s) // expected-error {{shared variable cannot be private}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(h) // expected-error {{threadprivate or thread local variable cannot be private}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp distribute'}} + for (int k = 0; k < argc; ++k) ++k; + #pragma omp target + #pragma omp teams + { + int i; // expected-note {{predetermined as private}} + #pragma omp distribute firstprivate(i), private(i) // expected-error {{private variable cannot be firstprivate}} + for (int k = 0; k < argc; ++k) ++k; + } + #pragma omp target + #pragma omp teams private(i) + #pragma omp distribute private(j) + for (int k = 0; k < argc; ++k) ++k; + #pragma omp parallel private(i) + #pragma omp target + #pragma omp teams firstprivate(i) + #pragma omp parallel private(i) + #pragma omp target + #pragma omp teams reduction(+:i) + #pragma omp distribute private(i) + for (int k = 0; k < argc; ++k) ++k; + #pragma omp distribute private(i) + for (int k = 0; k < 10; ++k) { + #pragma omp target + #pragma omp teams private(i) + #pragma omp distribute private(i) + for (int x = 0; x < 10; ++x) foo(); + } + #pragma omp target + #pragma omp teams + #pragma omp distribute firstprivate(i) + for (int k = 0; k < 10; ++k) { + #pragma omp target + #pragma omp teams firstprivate(i) + #pragma omp distribute private(i) + for (int x = 0; x < 10; ++x) foo(); + } + #pragma omp target + #pragma omp teams reduction(+:i) + #pragma omp distribute + for (int k = 0; k < 10; ++k) { + #pragma omp target + #pragma omp teams reduction(+:i) + #pragma omp distribute private(i) + for (int x = 0; x < 10; ++x) foo(); + } + + return 0; +} Index: test/OpenMP/nesting_of_regions.cpp =================================================================== --- test/OpenMP/nesting_of_regions.cpp +++ test/OpenMP/nesting_of_regions.cpp @@ -106,6 +106,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // SIMD DIRECTIVE #pragma omp simd @@ -239,6 +245,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int j = 0; j < 10; ++j) + ; + } // FOR DIRECTIVE #pragma omp for @@ -395,6 +407,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int j = 0; j < 10; ++j) + ; + } // FOR SIMD DIRECTIVE #pragma omp for simd @@ -528,6 +546,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp for simd + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int j = 0; j < 10; ++j) + ; + } // SECTIONS DIRECTIVE #pragma omp sections @@ -691,6 +715,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp sections + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -891,6 +921,13 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp sections + { +#pragma omp section +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // SINGLE DIRECTIVE #pragma omp single @@ -1037,6 +1074,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp single + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // MASTER DIRECTIVE #pragma omp master @@ -1183,6 +1226,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp master + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // CRITICAL DIRECTIVE #pragma omp critical @@ -1343,6 +1392,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp critical + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -1504,6 +1559,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int j = 0; j < 10; ++j) + ; + } // PARALLEL FOR SIMD DIRECTIVE #pragma omp parallel for simd @@ -1665,6 +1726,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int j = 0; j < 10; ++j) + ; + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -1817,6 +1884,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel sections + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // TASK DIRECTIVE #pragma omp task @@ -1915,6 +1988,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp task + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // ORDERED DIRECTIVE #pragma omp ordered @@ -2061,6 +2140,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp ordered + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // ATOMIC DIRECTIVE #pragma omp atomic @@ -2238,6 +2323,14 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp atomic + // expected-error@+2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + // expected-note@+1 {{expected an expression statement}} + { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + for (int i = 0; i < 10; ++i) + ; + } // TARGET DIRECTIVE #pragma omp target @@ -2349,6 +2442,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp target + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // TEAMS DIRECTIVE #pragma omp target @@ -2476,6 +2575,19 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) + ; +#pragma omp distribute + for (int j = 0; j < 10; ++j) + ; // TASKLOOP DIRECTIVE #pragma omp taskloop @@ -2627,6 +2739,204 @@ for (int i = 0; i < 10; ++i) ++a; } +// DISTRIBUTE DIRECTIVE +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp for // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a distribute region}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp master // expected-error {{region cannot be closely nested inside 'distribute' region}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp critical + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + { +#pragma omp single // OK + { + bar(); + } + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel sections + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp task + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp taskyield + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'distribute' region}} + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp flush + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp atomic + ++a; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp target + ++a; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } } void foo() { @@ -2732,6 +3042,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // SIMD DIRECTIVE #pragma omp simd @@ -2858,6 +3174,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp simd + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int j = 0; j < 10; ++j) + ; + } // FOR DIRECTIVE #pragma omp for @@ -3004,6 +3326,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp for + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int j = 0; j < 10; ++j) + ; + } // FOR SIMD DIRECTIVE #pragma omp for simd @@ -3130,6 +3458,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp for simd + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int j = 0; j < 10; ++j) + ; + } // SECTIONS DIRECTIVE #pragma omp sections @@ -3268,6 +3602,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp sections + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // SECTION DIRECTIVE #pragma omp section // expected-error {{orphaned 'omp section' directives are prohibited, it must be closely nested to a sections region}} @@ -3476,6 +3816,13 @@ ++a; } } +#pragma omp sections + { +#pragma omp section +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // SINGLE DIRECTIVE #pragma omp single @@ -3612,6 +3959,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp single + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // MASTER DIRECTIVE #pragma omp master @@ -3758,6 +4111,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp master + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // CRITICAL DIRECTIVE #pragma omp critical @@ -3923,6 +4282,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp critical + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // PARALLEL FOR DIRECTIVE #pragma omp parallel for @@ -4084,6 +4449,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel for + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int j = 0; j < 10; ++j) + ; + } // PARALLEL FOR SIMD DIRECTIVE #pragma omp parallel for simd @@ -4245,6 +4616,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside a simd region}} + for (int j = 0; j < 10; ++j) + ; + } // PARALLEL SECTIONS DIRECTIVE #pragma omp parallel sections @@ -4393,6 +4770,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp parallel sections + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // TASK DIRECTIVE #pragma omp task @@ -4490,6 +4873,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp task + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // ATOMIC DIRECTIVE #pragma omp atomic @@ -4667,6 +5056,14 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp atomic + // expected-error@+2 {{the statement for 'atomic' must be an expression statement of form '++x;', '--x;', 'x++;', 'x--;', 'x binop= expr;', 'x = x binop expr' or 'x = expr binop x', where x is an l-value expression with scalar type}} + // expected-note@+1 {{expected an expression statement}} + { +#pragma omp distribute // expected-error {{OpenMP constructs may not be nested inside an atomic region}} + for (int i = 0; i < 10; ++i) + ; + } // TARGET DIRECTIVE #pragma omp target @@ -4778,6 +5175,12 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp target + { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } // TEAMS DIRECTIVE #pragma omp target @@ -4905,6 +5308,19 @@ for (int i = 0; i < 10; ++i) ++a; } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) + ; +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) + ; +#pragma omp distribute + for (int j = 0; j < 10; ++j) + ; // TASKLOOP DIRECTIVE #pragma omp taskloop @@ -5056,6 +5472,205 @@ for (int i = 0; i < 10; ++i) ++a; } + +// DISTRIBUTE DIRECTIVE +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp distribute // expected-error {{'#pragma omp distribute' must be strictly nested in '#pragma omp teams'}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp for // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp for simd // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp for simd' directive into a parallel region?}} + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp sections // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp sections' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp section // expected-error {{'omp section' directive must be closely nested to a sections region, not a distribute region}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp single // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp single' directive into a parallel region?}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp master // expected-error {{region cannot be closely nested inside 'distribute' region}} + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp critical + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel + { +#pragma omp single // OK + { + bar(); + } + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute // OK + for (int i = 0; i < 10; ++i) + ; +#pragma omp sections // OK + { + bar(); + + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel for simd + for (int i = 0; i < 10; ++i) + ; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp parallel sections + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp task + { + bar(); + } + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp taskyield + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp barrier // expected-error {{region cannot be closely nested inside 'distribute' region}} + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp taskwait + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp flush + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp ordered // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}} + bar(); + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp atomic + ++a; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp target + ++a; + } +#pragma omp target +#pragma omp teams +#pragma omp distribute + for (int i = 0; i < 10; ++i) { +#pragma omp teams // expected-error {{region cannot be closely nested inside 'distribute' region; perhaps you forget to enclose 'omp teams' directive into a target region?}} + ++a; + } return foo(); } Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -1942,7 +1942,8 @@ void VisitOMPTargetDirective(const OMPTargetDirective *D); void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D); void VisitOMPTeamsDirective(const OMPTeamsDirective *D); - void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D); + void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D); + void VisitOMPDistributeDirective(const OMPDistributeDirective *D); private: void AddDeclarationNameInfo(const Stmt *S); @@ -2195,6 +2196,11 @@ VisitOMPClauseList(C); } } +void OMPClauseEnqueue::VisitOMPDistScheduleClause( + const OMPDistScheduleClause *C) { + Visitor->AddStmt(C->getChunkSize()); + Visitor->AddStmt(C->getHelperChunkSize()); +} void EnqueueVisitor::EnqueueChildren(const OMPClause *S) { unsigned size = WL.size(); @@ -2616,6 +2622,11 @@ VisitOMPLoopDirective(D); } +void EnqueueVisitor::VisitOMPDistributeDirective( + const OMPDistributeDirective *D) { + VisitOMPLoopDirective(D); +} + void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S); } @@ -4474,6 +4485,8 @@ return cxstring::createRef("OMPCancelDirective"); case CXCursor_OMPTaskLoopDirective: return cxstring::createRef("OMPTaskLoopDirective"); + case CXCursor_OMPDistributeDirective: + return cxstring::createRef("OMPForDirective"); case CXCursor_OverloadCandidate: return cxstring::createRef("OverloadCandidate"); case CXCursor_TypeAliasTemplateDecl: Index: tools/libclang/CXCursor.cpp =================================================================== --- tools/libclang/CXCursor.cpp +++ tools/libclang/CXCursor.cpp @@ -607,9 +607,12 @@ case Stmt::OMPCancelDirectiveClass: K = CXCursor_OMPCancelDirective; break; - case Stmt::OMPTaskLoopDirectiveClass: + case Stmt::OMPTaskLoopDirectiveClass: K = CXCursor_OMPTaskLoopDirective; break; + case Stmt::OMPDistributeDirectiveClass: + K = CXCursor_OMPDistributeDirective; + break; } CXCursor C = { K, 0, { Parent, S, TU } };