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

15 files changed:
include/clang/AST/DataRecursiveASTVisitor.h
include/clang/AST/OpenMPClause.h
include/clang/AST/RecursiveASTVisitor.h
include/clang/Basic/OpenMPKinds.def
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 c0d07f03e8e7b46fe4c082f2c3562158f3d8d056..9b902267ce3dcd9506421d0aafc075bd24dd2588 100644 (file)
@@ -2356,6 +2356,11 @@ RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
   return true;
 }
 
+template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
+  return true;
+}
+
 template <typename Derived>
 template <typename T>
 void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
index 59c0e2b409992f729eb5cdec6cdf0cded5560f44..46fc4207c9e266a7bdcfb8c875d00f60d639098c 100644 (file)
@@ -629,6 +629,35 @@ public:
   StmtRange children() { return StmtRange(); }
 };
 
+/// \brief This represents 'nowait' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp for nowait
+/// \endcode
+/// In this example directive '#pragma omp for' has 'nowait' clause.
+///
+class OMPNowaitClause : public OMPClause {
+public:
+  /// \brief Build 'nowait' clause.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param EndLoc Ending location of the clause.
+  ///
+  OMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc)
+      : OMPClause(OMPC_nowait, StartLoc, EndLoc) {}
+
+  /// \brief Build an empty clause.
+  ///
+  OMPNowaitClause()
+      : OMPClause(OMPC_nowait, SourceLocation(), SourceLocation()) {}
+
+  static bool classof(const OMPClause *T) {
+    return T->getClauseKind() == OMPC_nowait;
+  }
+
+  StmtRange children() { return StmtRange(); }
+};
+
 /// \brief This represents clause 'private' in the '#pragma omp ...' directives.
 ///
 /// \code
index c914d378aeae58120605c8fdd341d9b799a3b27d..dcc5caf9bad749e70c0da9113a78c7ecb7e2cbd0 100644 (file)
@@ -2377,6 +2377,11 @@ RecursiveASTVisitor<Derived>::VisitOMPOrderedClause(OMPOrderedClause *) {
   return true;
 }
 
+template <typename Derived>
+bool RecursiveASTVisitor<Derived>::VisitOMPNowaitClause(OMPNowaitClause *) {
+  return true;
+}
+
 template <typename Derived>
 template <typename T>
 void RecursiveASTVisitor<Derived>::VisitOMPClauseList(T *Node) {
index 5deff117395b28c830428e3b4048dd6b92310a47..f6c213b7591ec13fe425f6c8b839d872d37ab14d 100644 (file)
@@ -61,6 +61,7 @@ OPENMP_CLAUSE(copyin,  OMPCopyinClause)
 OPENMP_CLAUSE(proc_bind, OMPProcBindClause)
 OPENMP_CLAUSE(schedule, OMPScheduleClause)
 OPENMP_CLAUSE(ordered, OMPOrderedClause)
+OPENMP_CLAUSE(nowait, OMPNowaitClause)
 
 // Clauses allowed for OpenMP directive 'parallel'.
 OPENMP_PARALLEL_CLAUSE(if)
@@ -89,6 +90,7 @@ OPENMP_FOR_CLAUSE(reduction)
 OPENMP_FOR_CLAUSE(collapse)
 OPENMP_FOR_CLAUSE(schedule)
 OPENMP_FOR_CLAUSE(ordered)
+OPENMP_FOR_CLAUSE(nowait)
 
 // Static attributes for 'default' clause.
 OPENMP_DEFAULT_KIND(none)
index 0795789c43ee28d321b020daadb2ff6a03381602..b8d31c32a449505362bdefb189ce7c98d466bd85 100644 (file)
@@ -7386,6 +7386,9 @@ public:
   /// \brief Called on well-formed 'ordered' clause.
   OMPClause *ActOnOpenMPOrderedClause(SourceLocation StartLoc,
                                       SourceLocation EndLoc);
+  /// \brief Called on well-formed 'nowait' clause.
+  OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
+                                     SourceLocation EndLoc);
 
   OMPClause *
   ActOnOpenMPVarListClause(OpenMPClauseKind Kind, ArrayRef<Expr *> Vars,
index b5c122c1f65035de9c380527c470742a03496e59..db70cbe72de1928f3629fbf452fb0d87506df14b 100644 (file)
@@ -642,6 +642,10 @@ void OMPClausePrinter::VisitOMPOrderedClause(OMPOrderedClause *) {
   OS << "ordered";
 }
 
+void OMPClausePrinter::VisitOMPNowaitClause(OMPNowaitClause *) {
+  OS << "nowait";
+}
+
 template<typename T>
 void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) {
   for (typename T::varlist_iterator I = Node->varlist_begin(),
index 534d6bb772988e7af32709c661e44ba3e0afe105..cf7c6fcfa0fe32b9e18175e8205591cd86eb3000 100644 (file)
@@ -295,6 +295,8 @@ void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
 
 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
 
+void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
+
 template<typename T>
 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
   for (auto *I : Node->varlists())
index ec5198e06ebed95703bb171983c2f1937ee9e86b..de01f8afdfbfc7fbf6648f9f3e22a231c08efe3f 100644 (file)
@@ -96,6 +96,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind,
   case OMPC_aligned:
   case OMPC_copyin:
   case OMPC_ordered:
+  case OMPC_nowait:
     break;
   }
   llvm_unreachable("Invalid OpenMP simple clause kind");
@@ -149,6 +150,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
   case OMPC_aligned:
   case OMPC_copyin:
   case OMPC_ordered:
+  case OMPC_nowait:
     break;
   }
   llvm_unreachable("Invalid OpenMP simple clause kind");
index 599dda42124f7fcb3b95ba301e222e63bb70aa26..5a5e15a5e45e37c0835c53b3dc8b7e8771eba22f 100644 (file)
@@ -318,8 +318,11 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
     Clause = ParseOpenMPSingleExprWithArgClause(CKind);
     break;
   case OMPC_ordered:
+  case OMPC_nowait:
     // OpenMP [2.7.1, Restrictions, p. 9]
     //  Only one ordered clause can appear on a loop directive.
+    // OpenMP [2.7.1, Restrictions, C/C++, p. 4]
+    //  Only one nowait clause can appear on a for directive.
     if (!FirstClause) {
       Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind)
                                                << getOpenMPClauseName(CKind);
@@ -424,6 +427,9 @@ OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
 ///    ordered-clause:
 ///         'ordered'
 ///
+///    nowait-clause:
+///         'nowait'
+///
 OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) {
   SourceLocation Loc = Tok.getLocation();
   ConsumeAnyToken();
index 23c003815a71a686d11569e42fdef1aaf6743ce0..53f4b861346a9ab64ab426e6098861685f5b76bf 100644 (file)
@@ -1523,6 +1523,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
   case OMPC_aligned:
   case OMPC_copyin:
   case OMPC_ordered:
+  case OMPC_nowait:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
@@ -1701,6 +1702,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(
   case OMPC_aligned:
   case OMPC_copyin:
   case OMPC_ordered:
+  case OMPC_nowait:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
@@ -1810,6 +1812,7 @@ OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
   case OMPC_aligned:
   case OMPC_copyin:
   case OMPC_ordered:
+  case OMPC_nowait:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
@@ -1881,6 +1884,9 @@ OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
   case OMPC_ordered:
     Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc);
     break;
+  case OMPC_nowait:
+    Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc);
+    break;
   case OMPC_if:
   case OMPC_num_threads:
   case OMPC_safelen:
@@ -1908,6 +1914,11 @@ OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc,
   return new (Context) OMPOrderedClause(StartLoc, EndLoc);
 }
 
+OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc,
+                                         SourceLocation EndLoc) {
+  return new (Context) OMPNowaitClause(StartLoc, EndLoc);
+}
+
 OMPClause *Sema::ActOnOpenMPVarListClause(
     OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
     SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
@@ -1950,6 +1961,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(
   case OMPC_proc_bind:
   case OMPC_schedule:
   case OMPC_ordered:
+  case OMPC_nowait:
   case OMPC_threadprivate:
   case OMPC_unknown:
     llvm_unreachable("Clause is not allowed.");
index 27b134c801a4171ddfd7b52c991d5e2939437464..7fa0889c9a5c397d527944fc22997feca8753640 100644 (file)
@@ -6505,6 +6505,13 @@ TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
   return C;
 }
 
+template <typename Derived>
+OMPClause *
+TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
+  // No need to rebuild this clause, no template-dependent parameters.
+  return C;
+}
+
 template <typename Derived>
 OMPClause *
 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
index 65f86707fcb45c9ebd8bf3fe7f2c6230814d7112..dece91e6eac8d60a2c97d28e0a35e866a28bdb99 100644 (file)
@@ -1697,6 +1697,9 @@ OMPClause *OMPClauseReader::readClause() {
   case OMPC_ordered:
     C = new (Context) OMPOrderedClause();
     break;
+  case OMPC_nowait:
+    C = new (Context) OMPNowaitClause();
+    break;
   case OMPC_private:
     C = OMPPrivateClause::CreateEmpty(Context, Record[Idx++]);
     break;
@@ -1774,6 +1777,8 @@ void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) {
 
 void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *) {}
 
+void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {}
+
 void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) {
   C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx));
   unsigned NumVars = C->varlist_size();
index 3904192aa91717ad8ec9107601ecced99b01c0dd..5decf98cbf41a60a4878449248cf9063575020c4 100644 (file)
@@ -1717,6 +1717,8 @@ void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) {
 
 void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *) {}
 
+void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {}
+
 void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) {
   Record.push_back(C->varlist_size());
   Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record);
index 96c7fb12c917e18d50411426ec559df18f2ebac8..838eb4e923a4758ba7ced9de4b0931c471e8172a 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) ordered
+#pragma omp for private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered nowait
   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) ordered
+  // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered nowait
   // 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) ordered
+#pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(2) schedule(auto) ordered nowait
   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) ordered
+  // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(2) schedule(auto) ordered nowait
   // CHECK-NEXT: for (int i = 0; i < 10; ++i)
   // CHECK-NEXT: for (int j = 0; j < 10; ++j)
   // CHECK-NEXT: foo();
index 85b20f343a65c30b4f44e8592cb3d2a9cd285356..45e578609599ac6df7d98f62b9dce580887e0c06 100644 (file)
@@ -1951,6 +1951,8 @@ void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) {
 
 void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *) {}
 
+void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {}
+
 template<typename T>
 void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
   for (const auto *I : Node->varlists())