diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2014-02-27 08:29:12 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2014-02-27 08:29:12 +0000 |
commit | 1b59ab568333264eadb4beb81ef9c40446744736 (patch) | |
tree | b7c942713595cd71aa04071fc9c133d9cb2cf2b3 /clang/lib | |
parent | 6edfad4811795789706216bf47b39ff7a4672286 (diff) | |
download | bcm5719-llvm-1b59ab568333264eadb4beb81ef9c40446744736.tar.gz bcm5719-llvm-1b59ab568333264eadb4beb81ef9c40446744736.zip |
[OPENMP] First changes for Parsing and Sema for 'omp simd' directive support
llvm-svn: 202360
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/Stmt.cpp | 35 | ||||
-rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 26 | ||||
-rw-r--r-- | clang/lib/AST/StmtProfile.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Basic/OpenMPKinds.cpp | 9 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 27 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 53 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 27 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriterStmt.cpp | 12 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 |
11 files changed, 167 insertions, 38 deletions
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index f4d90eaded2..9118751a4b9 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -1217,10 +1217,39 @@ OMPParallelDirective *OMPParallelDirective::Create( } OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, - unsigned N, + unsigned NumClauses, EmptyShell) { unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), llvm::alignOf<OMPClause *>()); - void *Mem = C.Allocate(Size + sizeof(OMPClause *) * N + sizeof(Stmt *)); - return new (Mem) OMPParallelDirective(N); + void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + + sizeof(Stmt *)); + return new (Mem) OMPParallelDirective(NumClauses); +} + +OMPSimdDirective *OMPSimdDirective::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc, + ArrayRef<OMPClause *> Clauses, + Stmt *AssociatedStmt) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), + llvm::alignOf<OMPClause *>()); + void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + + sizeof(Stmt *)); + OMPSimdDirective *Dir = new (Mem) OMPSimdDirective(StartLoc, EndLoc, + 1, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + return Dir; +} + +OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + unsigned CollapsedNum, + EmptyShell) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), + llvm::alignOf<OMPClause *>()); + void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + + sizeof(Stmt *)); + return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); } + diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index a9f49990ee5..eb983b2db01 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -70,6 +70,7 @@ namespace { void PrintCallArgs(CallExpr *E); void PrintRawSEHExceptHandler(SEHExceptStmt *S); void PrintRawSEHFinallyStmt(SEHFinallyStmt *S); + void PrintOMPExecutableDirective(OMPExecutableDirective *S); void PrintExpr(Expr *E) { if (E) @@ -89,7 +90,7 @@ namespace { return; else StmtVisitor<StmtPrinter>::Visit(S); } - + void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED { Indent() << "<<unknown stmt type>>\n"; } @@ -656,11 +657,9 @@ void OMPClausePrinter::VisitOMPSharedClause(OMPSharedClause *Node) { // OpenMP directives printing methods //===----------------------------------------------------------------------===// -void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) { - Indent() << "#pragma omp parallel "; - +void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S) { OMPClausePrinter Printer(OS, Policy); - ArrayRef<OMPClause *> Clauses = Node->clauses(); + ArrayRef<OMPClause *> Clauses = S->clauses(); for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); I != E; ++I) if (*I && !(*I)->isImplicit()) { @@ -668,13 +667,24 @@ void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) { OS << ' '; } OS << "\n"; - if (Node->getAssociatedStmt()) { - assert(isa<CapturedStmt>(Node->getAssociatedStmt()) && + if (S->getAssociatedStmt()) { + assert(isa<CapturedStmt>(S->getAssociatedStmt()) && "Expected captured statement!"); - Stmt *CS = cast<CapturedStmt>(Node->getAssociatedStmt())->getCapturedStmt(); + Stmt *CS = cast<CapturedStmt>(S->getAssociatedStmt())->getCapturedStmt(); PrintStmt(CS); } } + +void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) { + Indent() << "#pragma omp parallel "; + PrintOMPExecutableDirective(Node); +} + +void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) { + Indent() << "#pragma omp simd "; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index ae3b3600786..e9b1da49dd4 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -293,7 +293,7 @@ void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) { } void -StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { +StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { VisitStmt(S); OMPClauseProfiler P(this); ArrayRef<OMPClause *> Clauses = S->clauses(); @@ -303,6 +303,14 @@ StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { P.Visit(*I); } +void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { + VisitOMPExecutableDirective(S); +} + +void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { + VisitOMPExecutableDirective(S); +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index 4e0ab1298b4..99c2fd2ebdd 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -125,6 +125,15 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, break; } break; + case OMPD_simd: + switch (CKind) { +#define OPENMP_SIMD_CLAUSE(Name) \ + case OMPC_##Name: return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; case OMPD_unknown: case OMPD_threadprivate: case OMPD_task: diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 918103fcbd5..a13828e85ed 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -77,6 +77,7 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::SEHFinallyStmtClass: case Stmt::MSDependentExistsStmtClass: case Stmt::OMPParallelDirectiveClass: + case Stmt::OMPSimdDirectiveClass: llvm_unreachable("invalid statement class to emit generically"); case Stmt::NullStmtClass: case Stmt::CompoundStmtClass: diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index b3c7cb597e4..3a8f2ee8809 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -60,6 +60,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { Diag(Tok, diag::err_omp_unknown_directive); break; case OMPD_parallel: + case OMPD_simd: case OMPD_task: case NUM_OPENMP_DIRECTIVES: Diag(Tok, diag::err_omp_unexpected_directive) @@ -114,7 +115,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { } SkipUntil(tok::annot_pragma_openmp_end); break; - case OMPD_parallel: { + case OMPD_parallel: + case OMPD_simd: { ConsumeToken(); Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope()); diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index fee9b1d2ce4..63b64801fe3 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -699,6 +699,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); break; + case OMPD_simd: + Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, + StartLoc, EndLoc); + break; case OMPD_threadprivate: case OMPD_task: llvm_unreachable("OpenMP Directive is not allowed"); @@ -721,6 +725,29 @@ StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, Clauses, AStmt)); } +StmtResult Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, + Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + Stmt *CStmt = AStmt; + while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(CStmt)) + CStmt = CS->getCapturedStmt(); + while (AttributedStmt *AS = dyn_cast_or_null<AttributedStmt>(CStmt)) + CStmt = AS->getSubStmt(); + ForStmt *For = dyn_cast<ForStmt>(CStmt); + if (!For) { + Diag(CStmt->getLocStart(), diag::err_omp_not_for) + << getOpenMPDirectiveName(OMPD_simd); + return StmtError(); + } + + // FIXME: Checking loop canonical form, collapsing etc. + + getCurFunction()->setHasBranchProtectedScope(); + return Owned(OMPSimdDirective::Create(Context, StartLoc, EndLoc, + Clauses, AStmt)); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index d9ed6f5f027..5d2124f7ce6 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -607,6 +607,7 @@ public: ExprResult TransformAddressOfOperand(Expr *E); ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand); + StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous // amount of stack usage with clang. @@ -1286,16 +1287,17 @@ public: return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); } - /// \brief Build a new OpenMP parallel directive. + /// \brief Build a new OpenMP executable directive. /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - StmtResult RebuildOMPParallelDirective(ArrayRef<OMPClause *> Clauses, - Stmt *AStmt, - SourceLocation StartLoc, - SourceLocation EndLoc) { - return getSema().ActOnOpenMPParallelDirective(Clauses, AStmt, - StartLoc, EndLoc); + StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, + ArrayRef<OMPClause *> Clauses, + Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + return getSema().ActOnOpenMPExecutableDirective(Kind, Clauses, AStmt, + StartLoc, EndLoc); } /// \brief Build a new OpenMP 'if' clause. @@ -6248,9 +6250,8 @@ StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { template<typename Derived> StmtResult -TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { - DeclarationNameInfo DirName; - getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0); +TreeTransform<Derived>::TransformOMPExecutableDirective( + OMPExecutableDirective *D) { // Transform the clauses llvm::SmallVector<OMPClause *, 16> TClauses; @@ -6261,7 +6262,6 @@ TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { if (*I) { OMPClause *Clause = getDerived().TransformOMPClause(*I); if (!Clause) { - getSema().EndOpenMPDSABlock(0); return StmtError(); } TClauses.push_back(Clause); @@ -6271,21 +6271,38 @@ TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { } } if (!D->getAssociatedStmt()) { - getSema().EndOpenMPDSABlock(0); return StmtError(); } StmtResult AssociatedStmt = getDerived().TransformStmt(D->getAssociatedStmt()); if (AssociatedStmt.isInvalid()) { - getSema().EndOpenMPDSABlock(0); return StmtError(); } - StmtResult Res = getDerived().RebuildOMPParallelDirective(TClauses, - AssociatedStmt.take(), - D->getLocStart(), - D->getLocEnd()); - getSema().EndOpenMPDSABlock(Res.get()); + return getDerived().RebuildOMPExecutableDirective(D->getDirectiveKind(), + TClauses, + AssociatedStmt.take(), + D->getLocStart(), + D->getLocEnd()); +} + +template<typename Derived> +StmtResult +TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { + DeclarationNameInfo DirName; + getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, 0); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + +template<typename Derived> +StmtResult +TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { + DeclarationNameInfo DirName; + getSema().StartOpenMPDSABlock(OMPD_simd, DirName, 0); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); return Res; } diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index e1ca51fcc19..3f83beb0a03 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1742,8 +1742,6 @@ void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) { // OpenMP Directives. //===----------------------------------------------------------------------===// void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { - VisitStmt(E); - ++Idx; E->setLocStart(ReadSourceLocation(Record, Idx)); E->setLocEnd(ReadSourceLocation(Record, Idx)); OMPClauseReader ClauseReader(this, Reader.getContext(), Record, Idx); @@ -1755,6 +1753,16 @@ void ASTStmtReader::VisitOMPExecutableDirective(OMPExecutableDirective *E) { } void ASTStmtReader::VisitOMPParallelDirective(OMPParallelDirective *D) { + VisitStmt(D); + // The NumClauses field was read in ReadStmtFromStream. + ++Idx; + VisitOMPExecutableDirective(D); +} + +void ASTStmtReader::VisitOMPSimdDirective(OMPSimdDirective *D) { + VisitStmt(D); + // Two fields (NumClauses and CollapsedNum) were read in ReadStmtFromStream. + Idx += 2; VisitOMPExecutableDirective(D); } @@ -2230,13 +2238,22 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { DeclarationNameInfo(), 0); break; + case STMT_OMP_PARALLEL_DIRECTIVE: S = OMPParallelDirective::CreateEmpty(Context, Record[ASTStmtReader::NumStmtFields], Empty); break; - + + case STMT_OMP_SIMD_DIRECTIVE: { + unsigned NumClauses = Record[ASTStmtReader::NumStmtFields]; + unsigned CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + S = OMPSimdDirective::CreateEmpty(Context, NumClauses, + CollapsedNum, Empty); + break; + } + case EXPR_CXX_OPERATOR_CALL: S = new (Context) CXXOperatorCallExpr(Context, Empty); break; @@ -2244,11 +2261,11 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { case EXPR_CXX_MEMBER_CALL: S = new (Context) CXXMemberCallExpr(Context, Empty); break; - + case EXPR_CXX_CONSTRUCT: S = new (Context) CXXConstructExpr(Empty); break; - + case EXPR_CXX_TEMPORARY_OBJECT: S = new (Context) CXXTemporaryObjectExpr(Empty); break; diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 428881bb69a..08228d07544 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1721,8 +1721,6 @@ void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) { // OpenMP Directives. //===----------------------------------------------------------------------===// void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { - VisitStmt(E); - Record.push_back(E->getNumClauses()); Writer.AddSourceLocation(E->getLocStart(), Record); Writer.AddSourceLocation(E->getLocEnd(), Record); OMPClauseWriter ClauseWriter(this, Record); @@ -1733,10 +1731,20 @@ void ASTStmtWriter::VisitOMPExecutableDirective(OMPExecutableDirective *E) { } void ASTStmtWriter::VisitOMPParallelDirective(OMPParallelDirective *D) { + VisitStmt(D); + Record.push_back(D->getNumClauses()); VisitOMPExecutableDirective(D); Code = serialization::STMT_OMP_PARALLEL_DIRECTIVE; } +void ASTStmtWriter::VisitOMPSimdDirective(OMPSimdDirective *D) { + VisitStmt(D); + Record.push_back(D->getNumClauses()); + Record.push_back(D->getCollapsedNumber()); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_SIMD_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 94274c39cac..fbcd2630829 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -731,6 +731,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Expr::MSDependentExistsStmtClass: case Stmt::CapturedStmtClass: case Stmt::OMPParallelDirectiveClass: + case Stmt::OMPSimdDirectiveClass: llvm_unreachable("Stmt should not be in analyzer evaluation loop"); case Stmt::ObjCSubscriptRefExprClass: |