summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2014-06-18 04:14:57 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2014-06-18 04:14:57 +0000
commitb23263a1ac3e4c6080c2b1f56cc42d2f24faf856 (patch)
treef26d7c1d5fa22602e10da6c02436ce553ffc78fc /include
parent6356f564c351af8b22e7c2699d52e2062ae9e76e (diff)
downloadclang-b23263a1ac3e4c6080c2b1f56cc42d2f24faf856.tar.gz
clang-b23263a1ac3e4c6080c2b1f56cc42d2f24faf856.tar.bz2
clang-b23263a1ac3e4c6080c2b1f56cc42d2f24faf856.tar.xz
[OPENMP] Initial support for '#pragma omp for' (fixed incompatibility with MSVC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211140 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/clang-c/Index.h6
-rw-r--r--include/clang/AST/DataRecursiveASTVisitor.h5
-rw-r--r--include/clang/AST/RecursiveASTVisitor.h5
-rw-r--r--include/clang/AST/StmtOpenMP.h68
-rw-r--r--include/clang/Basic/OpenMPKinds.def12
-rw-r--r--include/clang/Basic/OpenMPKinds.h37
-rw-r--r--include/clang/Basic/StmtNodes.td1
-rw-r--r--include/clang/Sema/Sema.h5
-rw-r--r--include/clang/Serialization/ASTBitCodes.h1
9 files changed, 139 insertions, 1 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 49d2bc4047..4deb60b1a5 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -2139,7 +2139,11 @@ enum CXCursorKind {
*/
CXCursor_OMPSimdDirective = 233,
- CXCursor_LastStmt = CXCursor_OMPSimdDirective,
+ /** \brief OpenMP for directive.
+ */
+ CXCursor_OMPForDirective = 234,
+
+ CXCursor_LastStmt = CXCursor_OMPForDirective,
/**
* \brief Cursor that represents the translation unit itself.
diff --git a/include/clang/AST/DataRecursiveASTVisitor.h b/include/clang/AST/DataRecursiveASTVisitor.h
index a31965c48b..5679ba3b64 100644
--- a/include/clang/AST/DataRecursiveASTVisitor.h
+++ b/include/clang/AST/DataRecursiveASTVisitor.h
@@ -2285,6 +2285,11 @@ DEF_TRAVERSE_STMT(OMPSimdDirective, {
return false;
})
+DEF_TRAVERSE_STMT(OMPForDirective, {
+ if (!TraverseOMPExecutableDirective(S))
+ return false;
+})
+
// OpenMP clauses.
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h
index b0ba684e74..3b756ef384 100644
--- a/include/clang/AST/RecursiveASTVisitor.h
+++ b/include/clang/AST/RecursiveASTVisitor.h
@@ -2307,6 +2307,11 @@ DEF_TRAVERSE_STMT(OMPSimdDirective, {
return false;
})
+DEF_TRAVERSE_STMT(OMPForDirective, {
+ if (!TraverseOMPExecutableDirective(S))
+ return false;
+})
+
// OpenMP clauses.
template <typename Derived>
bool RecursiveASTVisitor<Derived>::TraverseOMPClause(OMPClause *C) {
diff --git a/include/clang/AST/StmtOpenMP.h b/include/clang/AST/StmtOpenMP.h
index 023720abe8..f8ba48ab05 100644
--- a/include/clang/AST/StmtOpenMP.h
+++ b/include/clang/AST/StmtOpenMP.h
@@ -255,6 +255,74 @@ public:
}
};
+/// \brief This represents '#pragma omp for' directive.
+///
+/// \code
+/// #pragma omp for private(a,b) reduction(+:c,d)
+/// \endcode
+/// In this example directive '#pragma omp for' has clauses 'private' with the
+/// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c'
+/// and 'd'.
+///
+class OMPForDirective : public OMPExecutableDirective {
+ friend class ASTStmtReader;
+ /// \brief Number of collapsed loops as specified by 'collapse' clause.
+ unsigned CollapsedNum;
+ /// \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.
+ ///
+ OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc,
+ unsigned CollapsedNum, unsigned NumClauses)
+ : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for, StartLoc,
+ EndLoc, NumClauses, 1),
+ CollapsedNum(CollapsedNum) {}
+
+ /// \brief Build an empty directive.
+ ///
+ /// \param CollapsedNum Number of collapsed nested loops.
+ /// \param NumClauses Number of clauses.
+ ///
+ explicit OMPForDirective(unsigned CollapsedNum, unsigned NumClauses)
+ : OMPExecutableDirective(this, OMPForDirectiveClass, OMPD_for,
+ SourceLocation(), SourceLocation(), NumClauses,
+ 1),
+ CollapsedNum(CollapsedNum) {}
+
+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 OMPForDirective *Create(const ASTContext &C, SourceLocation StartLoc,
+ SourceLocation EndLoc,
+ ArrayRef<OMPClause *> Clauses,
+ Stmt *AssociatedStmt);
+
+ /// \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 OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses,
+ unsigned CollapsedNum, EmptyShell);
+
+ unsigned getCollapsedNumber() const { return CollapsedNum; }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == OMPForDirectiveClass;
+ }
+};
+
} // end namespace clang
#endif
diff --git a/include/clang/Basic/OpenMPKinds.def b/include/clang/Basic/OpenMPKinds.def
index ecef38f7f1..a4bc961e29 100644
--- a/include/clang/Basic/OpenMPKinds.def
+++ b/include/clang/Basic/OpenMPKinds.def
@@ -24,6 +24,9 @@
#ifndef OPENMP_SIMD_CLAUSE
# define OPENMP_SIMD_CLAUSE(Name)
#endif
+#ifndef OPENMP_FOR_CLAUSE
+# define OPENMP_FOR_CLAUSE(Name)
+#endif
#ifndef OPENMP_DEFAULT_KIND
# define OPENMP_DEFAULT_KIND(Name)
#endif
@@ -36,6 +39,7 @@ OPENMP_DIRECTIVE(threadprivate)
OPENMP_DIRECTIVE(parallel)
OPENMP_DIRECTIVE(task)
OPENMP_DIRECTIVE(simd)
+OPENMP_DIRECTIVE(for)
// OpenMP clauses.
OPENMP_CLAUSE(if, OMPIfClause)
@@ -72,6 +76,13 @@ OPENMP_SIMD_CLAUSE(aligned)
OPENMP_SIMD_CLAUSE(safelen)
OPENMP_SIMD_CLAUSE(collapse)
+// TODO more clauses allowed for directive 'omp for'.
+OPENMP_FOR_CLAUSE(private)
+OPENMP_FOR_CLAUSE(lastprivate)
+OPENMP_FOR_CLAUSE(firstprivate)
+OPENMP_FOR_CLAUSE(reduction)
+OPENMP_FOR_CLAUSE(collapse)
+
// Static attributes for 'default' clause.
OPENMP_DEFAULT_KIND(none)
OPENMP_DEFAULT_KIND(shared)
@@ -87,4 +98,5 @@ OPENMP_PROC_BIND_KIND(spread)
#undef OPENMP_CLAUSE
#undef OPENMP_PARALLEL_CLAUSE
#undef OPENMP_SIMD_CLAUSE
+#undef OPENMP_FOR_CLAUSE
diff --git a/include/clang/Basic/OpenMPKinds.h b/include/clang/Basic/OpenMPKinds.h
index 2ee246ec96..57559074d3 100644
--- a/include/clang/Basic/OpenMPKinds.h
+++ b/include/clang/Basic/OpenMPKinds.h
@@ -64,6 +64,43 @@ const char *getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, unsigned Type);
bool isAllowedClauseForDirective(OpenMPDirectiveKind DKind,
OpenMPClauseKind CKind);
+/// \brief Checks if the specified directive is a directive with an associated
+/// loop construct.
+/// \param DKind Specified directive.
+/// \return true - the directive is a loop-associated directive like 'omp simd'
+/// or 'omp for' directive, otherwise - false.
+bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind);
+
+/// \brief Checks if the specified directive is a worksharing directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a worksharing directive like 'omp for',
+/// otherwise - false.
+bool isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind);
+
+/// \brief Checks if the specified directive is a parallel-kind directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a parallel-like directive like 'omp
+/// parallel', otherwise - false.
+bool isOpenMPParallelDirective(OpenMPDirectiveKind DKind);
+
+/// \brief Checks if the specified directive is a simd directive.
+/// \param DKind Specified directive.
+/// \return true - the directive is a simd directive like 'omp simd',
+/// otherwise - false.
+bool isOpenMPSimdDirective(OpenMPDirectiveKind DKind);
+
+/// \brief Checks if the specified clause is one of private clauses like
+/// 'private', 'firstprivate', 'reduction' etc..
+/// \param Kind Clause kind.
+/// \return true - the clause is a private clause, otherwise - false.
+bool isOpenMPPrivate(OpenMPClauseKind Kind);
+
+/// \brief Checks if the specified clause is one of threadprivate clauses like
+/// 'threadprivate', 'copyin' or 'copyprivate'.
+/// \param Kind Clause kind.
+/// \return true - the clause is a threadprivate clause, otherwise - false.
+bool isOpenMPThreadPrivate(OpenMPClauseKind Kind);
+
}
#endif
diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td
index 0f0f284476..d04ba597a6 100644
--- a/include/clang/Basic/StmtNodes.td
+++ b/include/clang/Basic/StmtNodes.td
@@ -179,3 +179,4 @@ def AsTypeExpr : DStmt<Expr>;
def OMPExecutableDirective : Stmt<1>;
def OMPParallelDirective : DStmt<OMPExecutableDirective>;
def OMPSimdDirective : DStmt<OMPExecutableDirective>;
+def OMPForDirective : DStmt<OMPExecutableDirective>;
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 4a21f361a7..085a482b13 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -7312,6 +7312,11 @@ public:
Stmt *AStmt,
SourceLocation StartLoc,
SourceLocation EndLoc);
+ /// \brief Called on well-formed '\#pragma omp for' after parsing
+ /// of the associated statement.
+ StmtResult ActOnOpenMPForDirective(ArrayRef<OMPClause *> 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 315c852016..cd579ce1df 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -1341,6 +1341,7 @@ namespace clang {
// OpenMP drectives
STMT_OMP_PARALLEL_DIRECTIVE,
STMT_OMP_SIMD_DIRECTIVE,
+ STMT_OMP_FOR_DIRECTIVE,
// ARC
EXPR_OBJC_BRIDGED_CAST, // ObjCBridgedCastExpr