diff options
| author | Alexander Musman <alexander.musman@gmail.com> | 2014-05-27 15:12:19 +0000 |
|---|---|---|
| committer | Alexander Musman <alexander.musman@gmail.com> | 2014-05-27 15:12:19 +0000 |
| commit | 8bd31e69a441bb7178134de57bc60c22be8e0f3c (patch) | |
| tree | 03c7c30a004a5d9aa29ba6ec4ad5ba26d832ef2a /clang/lib | |
| parent | b355e8f604d3b26f15990b478a126b254a0fd9b8 (diff) | |
| download | bcm5719-llvm-8bd31e69a441bb7178134de57bc60c22be8e0f3c.tar.gz bcm5719-llvm-8bd31e69a441bb7178134de57bc60c22be8e0f3c.zip | |
Parsing/Sema for OMPCollapseClause.
Actual usage in Sema for collapsing loops will in some future patch.
llvm-svn: 209660
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/AST/StmtProfile.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Basic/OpenMPKinds.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 19 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 21 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTWriterStmt.cpp | 5 |
8 files changed, 74 insertions, 2 deletions
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index e5f24dc5d5e..0804d4089bb 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -608,6 +608,12 @@ void OMPClausePrinter::VisitOMPSafelenClause(OMPSafelenClause *Node) { OS << ")"; } +void OMPClausePrinter::VisitOMPCollapseClause(OMPCollapseClause *Node) { + OS << "collapse("; + Node->getNumForLoops()->printPretty(OS, nullptr, Policy, 0); + OS << ")"; +} + void OMPClausePrinter::VisitOMPDefaultClause(OMPDefaultClause *Node) { OS << "default(" << getOpenMPSimpleClauseTypeName(OMPC_default, Node->getDefaultKind()) diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 5dbaa0e8327..9cff6d67437 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -279,6 +279,11 @@ void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) { Profiler->VisitStmt(C->getSafelen()); } +void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) { + if (C->getNumForLoops()) + Profiler->VisitStmt(C->getNumForLoops()); +} + void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { } void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { } diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index f67cac8d403..c0142410b49 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -83,6 +83,7 @@ unsigned clang::getOpenMPSimpleClauseType(OpenMPClauseKind Kind, case OMPC_if: case OMPC_num_threads: case OMPC_safelen: + case OMPC_collapse: case OMPC_private: case OMPC_firstprivate: case OMPC_shared: @@ -119,6 +120,7 @@ const char *clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind, case OMPC_if: case OMPC_num_threads: case OMPC_safelen: + case OMPC_collapse: case OMPC_private: case OMPC_firstprivate: case OMPC_shared: diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index dfd8ca7c2c9..5916098ab1c 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -257,7 +257,8 @@ bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, /// /// clause: /// if-clause | num_threads-clause | safelen-clause | default-clause | -/// private-clause | firstprivate-clause | shared-clause | linear-clause +/// private-clause | firstprivate-clause | shared-clause | linear-clause | +/// collapse-clause /// OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, bool FirstClause) { @@ -274,11 +275,13 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, case OMPC_if: case OMPC_num_threads: case OMPC_safelen: + case OMPC_collapse: // OpenMP [2.5, Restrictions] // At most one if clause can appear on the directive. // At most one num_threads clause can appear on the directive. // OpenMP [2.8.1, simd construct, Restrictions] - // Only one safelen clause can appear on a simd directive. + // Only one safelen clause can appear on a simd directive. + // Only one collapse clause can appear on a simd directive. if (!FirstClause) { Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind); @@ -334,6 +337,9 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, /// safelen-clause: /// 'safelen' '(' expression ')' /// +/// collapse-clause: +/// 'collapse' '(' expression ')' +/// OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { SourceLocation Loc = ConsumeToken(); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 18cfd43c804..39ec6327357 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -809,6 +809,9 @@ OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, case OMPC_safelen: Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); break; + case OMPC_collapse: + Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); + break; case OMPC_default: case OMPC_proc_bind: case OMPC_private: @@ -950,6 +953,20 @@ OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, OMPSafelenClause(Safelen.take(), StartLoc, LParenLoc, EndLoc); } +OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *Num, SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + // OpenMP [2.8.1, simd construct, Description] + // The parameter of the collapse clause must be a constant + // positive integer expression. + ExprResult NumForLoops = + VerifyPositiveIntegerConstantInClause(Num, OMPC_collapse); + if (NumForLoops.isInvalid()) + return nullptr; + return new (Context) + OMPCollapseClause(NumForLoops.take(), StartLoc, LParenLoc, EndLoc); +} + OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, @@ -971,6 +988,7 @@ OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, case OMPC_if: case OMPC_num_threads: case OMPC_safelen: + case OMPC_collapse: case OMPC_private: case OMPC_firstprivate: case OMPC_shared: @@ -1086,6 +1104,7 @@ OMPClause *Sema::ActOnOpenMPVarListClause(OpenMPClauseKind Kind, case OMPC_if: case OMPC_num_threads: case OMPC_safelen: + case OMPC_collapse: case OMPC_default: case OMPC_proc_bind: case OMPC_threadprivate: diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index ef82b821469..3386b5bceeb 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -1333,6 +1333,17 @@ public: return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); } + /// \brief Build a new OpenMP 'collapse' clause. + /// + /// By default, performs semantic analysis to build the new statement. + /// Subclasses may override this routine to provide different behavior. + OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, + SourceLocation LParenLoc, + SourceLocation EndLoc) { + return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, + EndLoc); + } + /// \brief Build a new OpenMP 'default' clause. /// /// By default, performs semantic analysis to build the new statement. @@ -6399,6 +6410,16 @@ TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); } +template <typename Derived> +OMPClause * +TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { + ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); + if (E.isInvalid()) + return 0; + return getDerived().RebuildOMPCollapseClause( + E.take(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd()); +} + template<typename Derived> OMPClause * TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index b51f097638d..89bc7fefa2f 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1682,6 +1682,9 @@ OMPClause *OMPClauseReader::readClause() { case OMPC_safelen: C = new (Context) OMPSafelenClause(); break; + case OMPC_collapse: + C = new (Context) OMPCollapseClause(); + break; case OMPC_default: C = new (Context) OMPDefaultClause(); break; @@ -1726,6 +1729,11 @@ void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) { C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); } +void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) { + C->setNumForLoops(Reader->Reader.ReadSubExpr()); + C->setLParenLoc(Reader->ReadSourceLocation(Record, Idx)); +} + void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) { C->setDefaultKind( static_cast<OpenMPDefaultClauseKind>(Record[Idx++])); diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index c827060d9d0..a79772a533e 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1690,6 +1690,11 @@ void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) { Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); } +void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) { + Writer->Writer.AddStmt(C->getNumForLoops()); + Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); +} + void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) { Record.push_back(C->getDefaultKind()); Writer->Writer.AddSourceLocation(C->getLParenLoc(), Record); |

