]> granicus.if.org Git - clang/commitdiff
[OPENMP] Initial support for 'ordered' clause.
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 20 Jun 2014 09:44:06 +0000 (09:44 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 20 Jun 2014 09:44:06 +0000 (09:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211347 91177308-0d34-0410-b5e6-96231b3b80d8

16 files changed:
include/clang/AST/DataRecursiveASTVisitor.h
include/clang/AST/OpenMPClause.h
include/clang/AST/RecursiveASTVisitor.h
include/clang/Basic/OpenMPKinds.def
include/clang/Parse/Parser.h
include/clang/Sema/Sema.h
lib/AST/StmtPrinter.cpp
lib/AST/StmtProfile.cpp
lib/Basic/OpenMPKinds.cpp
lib/Parse/ParseOpenMP.cpp
lib/Sema/SemaOpenMP.cpp
lib/Sema/TreeTransform.h
lib/Serialization/ASTReaderStmt.cpp
lib/Serialization/ASTWriterStmt.cpp
test/OpenMP/for_ast_print.cpp
tools/libclang/CIndex.cpp

index e83d7269c46bb3600618900a78470464f8dbd475..c0d07f03e8e7b46fe4c082f2c3562158f3d8d056 100644 (file)
@@ -2350,6 +2350,12 @@ RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
   return true;
 }
 
+template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
+  return true;
+}
+
 template <typename Derived>
 template <typename T>
 void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
index 9df30a374ec8aaab1b0cb1918f9258246e4413d9..a46c44a6eafed6e4c135368ce53ce94ff6ec9e8d 100644 (file)
@@ -600,6 +600,35 @@ public:
   StmtRange children() { return StmtRange(&ChunkSize, &ChunkSize + 1); }
 };
 
+/// \brief This represents 'ordered' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp for ordered
+/// \endcode
+/// In this example directive '#pragma omp for' has 'ordered' clause.
+///
+class OMPOrderedClause : public OMPClause {
+public:
+  /// \brief Build 'ordered' clause.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param EndLoc Ending location of the clause.
+  ///
+  OMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc)
+      : OMPClause(OMPC_ordered, StartLoc, EndLoc) {}
+
+  /// \brief Build an empty clause.
+  ///
+  OMPOrderedClause()
+      : OMPClause(OMPC_ordered, SourceLocation(), SourceLocation()) {}
+
+  static bool classof(const OMPClause *T) {
+    return T->getClauseKind() == OMPC_ordered;
+  }
+
+  StmtRange children() { return StmtRange(); }
+};
+
 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
 ///
 /// \code
index 26841d3535e6acb46da4de15e852e641d8d03c1b..c914d378aeae58120605c8fdd341d9b799a3b27d 100644 (file)
@@ -2371,6 +2371,12 @@ RecursiveASTVisitor<Derived>::VisitOMPScheduleClause(OMPScheduleClause *C) {
   return true;
 }
 
+template <typename Derived>
+bool
+RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
+  return true;
+}
+
 template <typename Derived>
 template <typename T>
 void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
index f899570e6279d51527f7b207f8742d9b7e1eabb0..5deff117395b28c830428e3b4048dd6b92310a47 100644 (file)
@@ -60,6 +60,7 @@ OPENMP_CLAUSE(aligned, OMPAlignedClause)
 OPENMP_CLAUSE(copyin,  OMPCopyinClause)
 OPENMP_CLAUSE(proc_bind, OMPProcBindClause)
 OPENMP_CLAUSE(schedule, OMPScheduleClause)
+OPENMP_CLAUSE(ordered, OMPOrderedClause)
 
 // Clauses allowed for OpenMP directive 'parallel'.
 OPENMP_PARALLEL_CLAUSE(if)
@@ -87,6 +88,7 @@ OPENMP_FOR_CLAUSE(firstprivate)
 OPENMP_FOR_CLAUSE(reduction)
 OPENMP_FOR_CLAUSE(collapse)
 OPENMP_FOR_CLAUSE(schedule)
+OPENMP_FOR_CLAUSE(ordered)
 
 // Static attributes for 'default' clause.
 OPENMP_DEFAULT_KIND(none)
index ef09e7ac8226a55fb76fbfdffc133cda05af4784..586545eab8190700445d4efaf00ec0fb4e39a32f 100644 (file)
@@ -2351,6 +2351,11 @@ private:
   /// \param Kind Kind of current clause.
   ///
   OMPClause *ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind);
+  /// \brief Parses clause without any additional arguments.
+  ///
+  /// \param Kind Kind of current clause.
+  ///
+  OMPClause *ParseOpenMPClause(OpenMPClauseKind Kind);
   /// \brief Parses clause with the list of variables of a kind \a Kind.
   ///
   /// \param Kind Kind of current clause.
index 2f5cbef8658046d14436ce6bd2fd39323f93422e..0795789c43ee28d321b020daadb2ff6a03381602 100644 (file)
@@ -7381,6 +7381,12 @@ public:
                                        SourceLocation CommaLoc,
                                        SourceLocation EndLoc);
 
+  OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
+                               SourceLocation EndLoc);
+  /// \brief Called on well-formed 'ordered' clause.
+  OMPClause *ActOnOpenMPOrderedClause(SourceLocation StartLoc,
+                                      SourceLocation EndLoc);
+
   OMPClause *
   ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
                            Expr *TailExpr, SourceLocation StartLoc,
index ca18e708a0d4039a254006208eeaf4b37175ad8c..b5c122c1f65035de9c380527c470742a03496e59 100644 (file)
@@ -638,6 +638,10 @@ void OMPClausePrinter::VisitOMPScheduleClause(OMPScheduleClause *Node) {
   OS << ")";
 }
 
+void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *) {
+  OS << "ordered";
+}
+
 template<typename T>
 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
   for (typename T::varlist_iterator I = Node->varlist_begin(),
index bb41489597ee5823bdcf3dbefbe00789940c3fee..534d6bb772988e7af32709c661e44ba3e0afe105 100644 (file)
@@ -293,6 +293,8 @@ void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
     Profiler->VisitStmt(C->getChunkSize());
 }
 
+void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
+
 template<typename T>
 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
   for (auto *I : Node->varlists())
index 131d40a37549886c6033e724b800f18f0ab0b4ed..ec5198e06ebed95703bb171983c2f1937ee9e86b 100644 (file)
@@ -95,6 +95,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
   case OMPC_linear:
   case OMPC_aligned:
   case OMPC_copyin:
+  case OMPC_ordered:
     break;
   }
   llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -147,6 +148,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
   case OMPC_linear:
   case OMPC_aligned:
   case OMPC_copyin:
+  case OMPC_ordered:
     break;
   }
   llvm_unreachable("Invalid OpenMP simple clause kind");
index 9cd9d4d6340eb44c0c6136d7431e0b0f7fc34975..599dda42124f7fcb3b95ba301e222e63bb70aa26 100644 (file)
@@ -317,6 +317,16 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
 
     Clause = ParseOpenMPSingleExprWithArgClause(CKind);
     break;
+  case OMPC_ordered:
+    // OpenMP [2.7.1, Restrictions, p. 9]
+    //  Only one ordered clause can appear on a loop directive.
+    if (!FirstClause) {
+      Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
+                                               << getOpenMPClauseName(CKind);
+    }
+
+    Clause = ParseOpenMPClause(CKind);
+    break;
   case OMPC_private:
   case OMPC_firstprivate:
   case OMPC_lastprivate:
@@ -409,6 +419,19 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
                                          Tok.getLocation());
 }
 
+/// \brief Parsing of OpenMP clauses like 'ordered'.
+///
+///    ordered-clause:
+///         'ordered'
+///
+OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
+  SourceLocation Loc = Tok.getLocation();
+  ConsumeAnyToken();
+
+  return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation());
+}
+
+
 /// \brief Parsing of OpenMP clauses with single expressions and some additional
 /// argument like 'schedule' or 'dist_schedule'.
 ///
index 515bd5f8c488ebcecc39bc19813800667a408e6d..23c003815a71a686d11569e42fdef1aaf6743ce0 100644 (file)
@@ -1522,6 +1522,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
   case OMPC_linear:
   case OMPC_aligned:
   case OMPC_copyin:
+  case OMPC_ordered:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
@@ -1699,6 +1700,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
   case OMPC_linear:
   case OMPC_aligned:
   case OMPC_copyin:
+  case OMPC_ordered:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
@@ -1807,6 +1809,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
   case OMPC_linear:
   case OMPC_aligned:
   case OMPC_copyin:
+  case OMPC_ordered:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
@@ -1870,6 +1873,41 @@ OMPClause *Sema::ActOnOpenMPScheduleClause(
                                          EndLoc, Kind, ValExpr);
 }
 
+OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
+                                   SourceLocation StartLoc,
+                                   SourceLocation EndLoc) {
+  OMPClause *Res = nullptr;
+  switch (Kind) {
+  case OMPC_ordered:
+    Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc);
+    break;
+  case OMPC_if:
+  case OMPC_num_threads:
+  case OMPC_safelen:
+  case OMPC_collapse:
+  case OMPC_schedule:
+  case OMPC_private:
+  case OMPC_firstprivate:
+  case OMPC_lastprivate:
+  case OMPC_shared:
+  case OMPC_reduction:
+  case OMPC_linear:
+  case OMPC_aligned:
+  case OMPC_copyin:
+  case OMPC_default:
+  case OMPC_proc_bind:
+  case OMPC_threadprivate:
+  case OMPC_unknown:
+    llvm_unreachable("Clause is not allowed.");
+  }
+  return Res;
+}
+
+OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc,
+                                          SourceLocation EndLoc) {
+  return new (Context) OMPOrderedClause(StartLoc, EndLoc);
+}
+
 OMPClause *Sema::ActOnOpenMPVarListClause(
     OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
     SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
@@ -1911,6 +1949,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
   case OMPC_default:
   case OMPC_proc_bind:
   case OMPC_schedule:
+  case OMPC_ordered:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
index 69685a953943d2e232b75ddca0f209e2ed585db7..27b134c801a4171ddfd7b52c991d5e2939437464 100644 (file)
@@ -6498,6 +6498,13 @@ TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
       C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
 }
 
+template <typename Derived>
+OMPClause *
+TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
+  // No need to rebuild this clause, no template-dependent parameters.
+  return C;
+}
+
 template <typename Derived>
 OMPClause *
 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
index cda835597f186471b8a105a6c4b66e3cb8da1687..65f86707fcb45c9ebd8bf3fe7f2c6230814d7112 100644 (file)
@@ -1694,6 +1694,9 @@ OMPClause *OMPClauseReader::readClause() {
   case OMPC_schedule:
     C = new (Context) OMPScheduleClause();
     break;
+  case OMPC_ordered:
+    C = new (Context) OMPOrderedClause();
+    break;
   case OMPC_private:
     C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
     break;
@@ -1769,6 +1772,8 @@ void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
   C->setCommaLoc(Reader->ReadSourceLocation(Record, Idx));
 }
 
+void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {}
+
 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
   unsigned NumVars = C->varlist_size();
index 0de9221c73e13bab53f9c1de0e507c2be2eaa8c5..3904192aa91717ad8ec9107601ecced99b01c0dd 100644 (file)
@@ -1715,6 +1715,8 @@ void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
   Writer->Writer.AddSourceLocation(C->getCommaLoc(), Record);
 }
 
+void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *) {}
+
 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
   Record.push_back(C->varlist_size());
   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
index 665c0c55cfaf23741434c70bd88f99ef9de6191b..96c7fb12c917e18d50411426ec559df18f2ebac8 100644 (file)
@@ -20,12 +20,12 @@ T tmain(T argc) {
 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
 // CHECK-NEXT: a = 2;
 #pragma omp parallel
-#pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N)
+#pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered
   for (int i = 0; i < 10; ++i)
     for (int j = 0; j < 10; ++j)
       foo();
   // CHECK-NEXT: #pragma omp parallel
-  // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N)
+  // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered
   // CHECK-NEXT: for (int i = 0; i < 10; ++i)
   // CHECK-NEXT: for (int j = 0; j < 10; ++j)
   // CHECK-NEXT: foo();
@@ -43,12 +43,12 @@ int main(int argc, char **argv) {
 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
 // CHECK-NEXT: a = 2;
 #pragma omp parallel
-#pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto)
+#pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered
   for (int i = 0; i < 10; ++i)
     for (int j = 0; j < 10; ++j)
       foo();
   // CHECK-NEXT: #pragma omp parallel
-  // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto)
+  // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered
   // CHECK-NEXT: for (int i = 0; i < 10; ++i)
   // CHECK-NEXT: for (int j = 0; j < 10; ++j)
   // CHECK-NEXT: foo();
index 0958634a2845fcf4461bb5c04c1435015a6b6d88..85b20f343a65c30b4f44e8592cb3d2a9cd285356 100644 (file)
@@ -1949,6 +1949,8 @@ void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) {
   Visitor->AddStmt(C->getChunkSize());
 }
 
+void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *) {}
+
 template<typename T>
 void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
   for (const auto *I : Node->varlists())