From f0a57f4453809e08ae1b4feaeec2c91c5257af48 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 26 Jun 2014 12:05:45 +0000 Subject: [OPENMP] Initial parsing and sema analysis for 'single' directive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211774 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang-c/Index.h | 6 ++- include/clang/AST/DataRecursiveASTVisitor.h | 5 +++ include/clang/AST/RecursiveASTVisitor.h | 5 +++ include/clang/AST/StmtOpenMP.h | 57 +++++++++++++++++++++++++++++ include/clang/Basic/OpenMPKinds.def | 10 +++++ include/clang/Basic/StmtNodes.td | 1 + include/clang/Sema/Sema.h | 5 +++ include/clang/Serialization/ASTBitCodes.h | 1 + 8 files changed, 89 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 909e2dbfe2..561bed9231 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -2151,7 +2151,11 @@ enum CXCursorKind { */ CXCursor_OMPSectionDirective = 236, - CXCursor_LastStmt = CXCursor_OMPSectionDirective, + /** \brief OpenMP single directive. + */ + CXCursor_OMPSingleDirective = 237, + + CXCursor_LastStmt = CXCursor_OMPSingleDirective, /** * \brief Cursor that represents the translation unit itself. diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h index 536d372ec4..86d6ca8667 100644 --- a/include/clang/AST/DataRecursiveASTVisitor.h +++ b/include/clang/AST/DataRecursiveASTVisitor.h @@ -2305,6 +2305,11 @@ DEF_TRAVERSE_STMT(OMPSectionDirective, { return false; }) +DEF_TRAVERSE_STMT(OMPSingleDirective, { + if (!TraverseOMPExecutableDirective(S)) + return false; +}) + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index eae370e0b8..14a957e1cf 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -2327,6 +2327,11 @@ DEF_TRAVERSE_STMT(OMPSectionDirective, { return false; }) +DEF_TRAVERSE_STMT(OMPSingleDirective, { + if (!TraverseOMPExecutableDirective(S)) + return false; +}) + // OpenMP clauses. template bool RecursiveASTVisitor::TraverseOMPClause(OMPClause *C) { diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h index 8b954f45e7..59f24facb3 100644 --- a/include/clang/AST/StmtOpenMP.h +++ b/include/clang/AST/StmtOpenMP.h @@ -470,6 +470,63 @@ public: } }; +/// \brief This represents '#pragma omp single' directive. +/// +/// \code +/// #pragma omp single private(a,b) copyprivate(c,d) +/// \endcode +/// In this example directive '#pragma omp single' has clauses 'private' with +/// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'. +/// +class OMPSingleDirective : public OMPExecutableDirective { + friend class ASTStmtReader; + /// \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 NumClauses Number of clauses. + /// + OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc, + unsigned NumClauses) + : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single, + StartLoc, EndLoc, NumClauses, 1) {} + + /// \brief Build an empty directive. + /// + /// \param NumClauses Number of clauses. + /// + explicit OMPSingleDirective(unsigned NumClauses) + : OMPExecutableDirective(this, OMPSingleDirectiveClass, OMPD_single, + SourceLocation(), SourceLocation(), NumClauses, + 1) {} + +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 Clauses List of clauses. + /// \param AssociatedStmt Statement, associated with the directive. + /// + static OMPSingleDirective * + Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + ArrayRef Clauses, Stmt *AssociatedStmt); + + /// \brief Creates an empty directive with the place for \a NumClauses + /// clauses. + /// + /// \param C AST context. + /// \param NumClauses Number of clauses. + /// + static OMPSingleDirective *CreateEmpty(const ASTContext &C, + unsigned NumClauses, EmptyShell); + + static bool classof(const Stmt *T) { + return T->getStmtClass() == OMPSingleDirectiveClass; + } +}; + } // end namespace clang #endif diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def index c47782b816..67ce712ed5 100644 --- a/include/clang/Basic/OpenMPKinds.def +++ b/include/clang/Basic/OpenMPKinds.def @@ -30,6 +30,9 @@ #ifndef OPENMP_SECTIONS_CLAUSE # define OPENMP_SECTIONS_CLAUSE(Name) #endif +#ifndef OPENMP_SINGLE_CLAUSE +# define OPENMP_SINGLE_CLAUSE(Name) +#endif #ifndef OPENMP_DEFAULT_KIND # define OPENMP_DEFAULT_KIND(Name) #endif @@ -48,6 +51,7 @@ OPENMP_DIRECTIVE(simd) OPENMP_DIRECTIVE(for) OPENMP_DIRECTIVE(sections) OPENMP_DIRECTIVE(section) +OPENMP_DIRECTIVE(single) // OpenMP clauses. OPENMP_CLAUSE(if, OMPIfClause) @@ -104,6 +108,11 @@ OPENMP_SECTIONS_CLAUSE(firstprivate) OPENMP_SECTIONS_CLAUSE(reduction) OPENMP_SECTIONS_CLAUSE(nowait) +// TODO more clauses allowed for directive 'omp single'. +OPENMP_SINGLE_CLAUSE(private) +OPENMP_SINGLE_CLAUSE(firstprivate) +OPENMP_SINGLE_CLAUSE(nowait) + // Static attributes for 'default' clause. OPENMP_DEFAULT_KIND(none) OPENMP_DEFAULT_KIND(shared) @@ -125,6 +134,7 @@ OPENMP_SCHEDULE_KIND(runtime) #undef OPENMP_DEFAULT_KIND #undef OPENMP_DIRECTIVE #undef OPENMP_CLAUSE +#undef OPENMP_SINGLE_CLAUSE #undef OPENMP_SECTIONS_CLAUSE #undef OPENMP_PARALLEL_CLAUSE #undef OPENMP_SIMD_CLAUSE diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td index 5236f46883..17a56adcf6 100644 --- a/include/clang/Basic/StmtNodes.td +++ b/include/clang/Basic/StmtNodes.td @@ -182,3 +182,4 @@ def OMPSimdDirective : DStmt; def OMPForDirective : DStmt; def OMPSectionsDirective : DStmt; def OMPSectionDirective : DStmt; +def OMPSingleDirective : DStmt; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 0a6cd33b8d..700bda08c6 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7331,6 +7331,11 @@ public: /// associated statement. StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); + /// \brief Called on well-formed '\#pragma omp single' after parsing of the + /// associated statement. + StmtResult ActOnOpenMPSingleDirective(ArrayRef Clauses, + Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc); OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index 55cf34fc73..fe91b15d99 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -1344,6 +1344,7 @@ namespace clang { STMT_OMP_FOR_DIRECTIVE, STMT_OMP_SECTIONS_DIRECTIVE, STMT_OMP_SECTION_DIRECTIVE, + STMT_OMP_SINGLE_DIRECTIVE, // ARC EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr -- cgit v1.2.3