diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2014-06-26 08:21:58 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2014-06-26 08:21:58 +0000 |
| commit | 1e0498a92d6e09d01c791a7f32299de6c8e02cac (patch) | |
| tree | 80b5da2548f93a8a8f193b07da7851a496adb24d /clang/lib | |
| parent | 07910d6ab548e7a57717af7e28d994cd652fd75d (diff) | |
| download | bcm5719-llvm-1e0498a92d6e09d01c791a7f32299de6c8e02cac.tar.gz bcm5719-llvm-1e0498a92d6e09d01c791a7f32299de6c8e02cac.zip | |
[OPENMP] Initial parsing and sema analysis for 'section' directive.
llvm-svn: 211767
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/Stmt.cpp | 20 | ||||
| -rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/AST/StmtProfile.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Basic/OpenMPKinds.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 1 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 45 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 10 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTWriterStmt.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 |
13 files changed, 115 insertions, 6 deletions
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp index 48b3dc5baf4..b402f6edd25 100644 --- a/clang/lib/AST/Stmt.cpp +++ b/clang/lib/AST/Stmt.cpp @@ -1410,3 +1410,23 @@ OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, return new (Mem) OMPSectionsDirective(NumClauses); } +OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, + SourceLocation StartLoc, + SourceLocation EndLoc, + Stmt *AssociatedStmt) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), + llvm::alignOf<Stmt *>()); + void *Mem = C.Allocate(Size + sizeof(Stmt *)); + OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); + Dir->setAssociatedStmt(AssociatedStmt); + return Dir; +} + +OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, + EmptyShell) { + unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), + llvm::alignOf<Stmt *>()); + void *Mem = C.Allocate(Size + sizeof(Stmt *)); + return new (Mem) OMPSectionDirective(); +} + diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 46e9cbdc3d9..0ac683347f0 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -792,6 +792,11 @@ void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) { PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) { + Indent() << "#pragma omp section"; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 0a9a011b93a..804003fb678 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -364,6 +364,10 @@ void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { VisitOMPExecutableDirective(S); } +void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *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 07e2222f979..547eb32199b 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -204,6 +204,7 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, case OMPD_unknown: case OMPD_threadprivate: case OMPD_task: + case OMPD_section: break; } return false; @@ -214,8 +215,8 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { } bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) { - return DKind == OMPD_for || - DKind == OMPD_sections; // TODO add next directives. + return DKind == OMPD_for || DKind == OMPD_sections || + DKind == OMPD_section; // TODO add next directives. } bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) { diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 3e49733a9c7..c3ad8b369c2 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -185,6 +185,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::OMPSectionsDirectiveClass: EmitOMPSectionsDirective(cast<OMPSectionsDirective>(*S)); break; + case Stmt::OMPSectionDirectiveClass: + EmitOMPSectionDirective(cast<OMPSectionDirective>(*S)); + break; } } diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index f75111bce19..ae45aa4abbf 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -83,3 +83,7 @@ void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &) { llvm_unreachable("CodeGen for 'omp sections' is not supported yet."); } +void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &) { + llvm_unreachable("CodeGen for 'omp section' is not supported yet."); +} + diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 8a7ebdd5e9b..87453992b1d 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1904,6 +1904,7 @@ public: void EmitOMPSimdDirective(const OMPSimdDirective &S); void EmitOMPForDirective(const OMPForDirective &S); void EmitOMPSectionsDirective(const OMPSectionsDirective &S); + void EmitOMPSectionDirective(const OMPSectionDirective &S); //===--------------------------------------------------------------------===// // LValue Expression Emission diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 7a3c05e96be..11e888efb40 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -64,6 +64,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { case OMPD_task: case OMPD_for: case OMPD_sections: + case OMPD_section: Diag(Tok, diag::err_omp_unexpected_directive) << getOpenMPDirectiveName(DKind); break; @@ -79,8 +80,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { /// annot_pragma_openmp_end /// /// executable-directive: -/// annot_pragma_openmp 'parallel'|'simd'|'for'|'sections' {clause} -/// annot_pragma_openmp_end +/// annot_pragma_openmp 'parallel'|'simd'|'for'|'sections'|'section' +/// {clause} annot_pragma_openmp_end /// StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); @@ -119,7 +120,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { case OMPD_parallel: case OMPD_simd: case OMPD_for: - case OMPD_sections: { + case OMPD_sections: + case OMPD_section: { ConsumeToken(); if (isOpenMPLoopDirective(DKind)) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index db471b88adf..ba441a2b14e 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -917,6 +917,13 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, SourceLocation Loc, ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params); break; } + case OMPD_section: { + Sema::CapturedParamNameType Params[] = { + std::make_pair(StringRef(), QualType()) // __context with shared vars + }; + ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params); + break; + } case OMPD_threadprivate: case OMPD_task: llvm_unreachable("OpenMP Directive is not allowed"); @@ -939,6 +946,19 @@ bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); return true; } + if (CurrentRegion == OMPD_section) { + // OpenMP [2.7.2, sections Construct, Restrictions] + // Orphaned section directives are prohibited. That is, the section + // directives must appear within the sections construct and must not be + // encountered elsewhere in the sections region. + if (ParentRegion != OMPD_sections) { + SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) + << (ParentRegion != OMPD_unknown) + << getOpenMPDirectiveName(ParentRegion); + return true; + } + return false; + } if (isOpenMPWorksharingDirective(CurrentRegion) && !isOpenMPParallelDirective(CurrentRegion) && !isOpenMPSimdDirective(CurrentRegion)) { @@ -1008,6 +1028,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); break; + case OMPD_section: + assert(ClausesWithImplicit.empty() && + "No clauses is allowed for 'omp section' directive"); + Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); + break; case OMPD_threadprivate: case OMPD_task: llvm_unreachable("OpenMP Directive is not allowed"); @@ -1592,7 +1617,15 @@ StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, return StmtError(); // All associated statements must be '#pragma omp section' except for // the first one. - // TODO + for (++S; S; ++S) { + auto SectionStmt = *S; + if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { + if (SectionStmt) + Diag(SectionStmt->getLocStart(), + diag::err_omp_sections_substmt_not_section); + return StmtError(); + } + } } else { Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); return StmtError(); @@ -1604,6 +1637,16 @@ StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, AStmt); } +StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, + SourceLocation StartLoc, + SourceLocation EndLoc) { + assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); + + getCurFunction()->setHasBranchProtectedScope(); + + return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); +} + OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, SourceLocation StartLoc, SourceLocation LParenLoc, diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 2e595ea657a..59208737b75 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6439,6 +6439,16 @@ TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { return Res; } +template <typename Derived> +StmtResult +TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + //===----------------------------------------------------------------------===// // OpenMP clause transformation //===----------------------------------------------------------------------===// diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index ef057f870f7..6649b6f05e9 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1913,6 +1913,11 @@ void ASTStmtReader::VisitOMPSectionsDirective(OMPSectionsDirective *D) { VisitOMPExecutableDirective(D); } +void ASTStmtReader::VisitOMPSectionDirective(OMPSectionDirective *D) { + VisitStmt(D); + VisitOMPExecutableDirective(D); +} + //===----------------------------------------------------------------------===// // ASTReader Implementation //===----------------------------------------------------------------------===// @@ -2413,6 +2418,10 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { Context, Record[ASTStmtReader::NumStmtFields], Empty); break; + case STMT_OMP_SECTION_DIRECTIVE: + S = OMPSectionDirective::CreateEmpty(Context, Empty); + break; + case EXPR_CXX_OPERATOR_CALL: S = new (Context) CXXOperatorCallExpr(Context, Empty); break; diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index c0566679a51..10a55b28896 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1825,6 +1825,12 @@ void ASTStmtWriter::VisitOMPSectionsDirective(OMPSectionsDirective *D) { Code = serialization::STMT_OMP_SECTIONS_DIRECTIVE; } +void ASTStmtWriter::VisitOMPSectionDirective(OMPSectionDirective *D) { + VisitStmt(D); + VisitOMPExecutableDirective(D); + Code = serialization::STMT_OMP_SECTION_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 45250f32b98..244862d0de0 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -734,6 +734,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::OMPSimdDirectiveClass: case Stmt::OMPForDirectiveClass: case Stmt::OMPSectionsDirectiveClass: + case Stmt::OMPSectionDirectiveClass: llvm_unreachable("Stmt should not be in analyzer evaluation loop"); case Stmt::ObjCSubscriptRefExprClass: |

