diff options
| author | Alexey Bataev <a.bataev@hotmail.com> | 2015-07-02 11:25:17 +0000 |
|---|---|---|
| committer | Alexey Bataev <a.bataev@hotmail.com> | 2015-07-02 11:25:17 +0000 |
| commit | 80909878adc79d9f1277373af175041718f05953 (patch) | |
| tree | c673079a9bf2cc7e6d7635625bdb1691e162686b /clang/lib/Sema | |
| parent | 3937bc650cad69cbd607ca3ea64ea6623808fc19 (diff) | |
| download | bcm5719-llvm-80909878adc79d9f1277373af175041718f05953.tar.gz bcm5719-llvm-80909878adc79d9f1277373af175041718f05953.zip | |
[OPENMP 4.0] Initial support for 'omp cancel' construct.
Implemented parsing/sema analysis + (de)serialization.
llvm-svn: 241253
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 57 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 13 |
2 files changed, 67 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 8d6d01e6eb0..7286301fe6e 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -1325,6 +1325,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { case OMPD_barrier: case OMPD_taskwait: case OMPD_cancellation_point: + case OMPD_cancel: case OMPD_flush: llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: @@ -1395,6 +1396,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel | teams | + | // | parallel | cancellation | | // | | point | ! | + // | parallel | cancel | ! | // +------------------+-----------------+------------------------------------+ // | for | parallel | * | // | for | for | + | @@ -1420,6 +1422,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for | teams | + | // | for | cancellation | | // | | point | ! | + // | for | cancel | ! | // +------------------+-----------------+------------------------------------+ // | master | parallel | * | // | master | for | + | @@ -1445,6 +1448,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | master | teams | + | // | master | cancellation | | // | | point | | + // | master | cancel | | // +------------------+-----------------+------------------------------------+ // | critical | parallel | * | // | critical | for | + | @@ -1469,6 +1473,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | critical | teams | + | // | critical | cancellation | | // | | point | | + // | critical | cancel | | // +------------------+-----------------+------------------------------------+ // | simd | parallel | | // | simd | for | | @@ -1494,6 +1499,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | simd | teams | | // | simd | cancellation | | // | | point | | + // | simd | cancel | | // +------------------+-----------------+------------------------------------+ // | for simd | parallel | | // | for simd | for | | @@ -1519,6 +1525,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for simd | teams | | // | for simd | cancellation | | // | | point | | + // | for simd | cancel | | // +------------------+-----------------+------------------------------------+ // | parallel for simd| parallel | | // | parallel for simd| for | | @@ -1544,6 +1551,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for simd| teams | | // | parallel for simd| cancellation | | // | | point | | + // | parallel for simd| cancel | | // +------------------+-----------------+------------------------------------+ // | sections | parallel | * | // | sections | for | + | @@ -1569,6 +1577,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | sections | teams | + | // | sections | cancellation | | // | | point | ! | + // | sections | cancel | ! | // +------------------+-----------------+------------------------------------+ // | section | parallel | * | // | section | for | + | @@ -1594,6 +1603,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | section | teams | + | // | section | cancellation | | // | | point | ! | + // | section | cancel | ! | // +------------------+-----------------+------------------------------------+ // | single | parallel | * | // | single | for | + | @@ -1619,6 +1629,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | single | teams | + | // | single | cancellation | | // | | point | | + // | single | cancel | | // +------------------+-----------------+------------------------------------+ // | parallel for | parallel | * | // | parallel for | for | + | @@ -1644,6 +1655,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for | teams | + | // | parallel for | cancellation | | // | | point | ! | + // | parallel for | cancel | ! | // +------------------+-----------------+------------------------------------+ // | parallel sections| parallel | * | // | parallel sections| for | + | @@ -1669,6 +1681,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel sections| teams | + | // | parallel sections| cancellation | | // | | point | ! | + // | parallel sections| cancel | ! | // +------------------+-----------------+------------------------------------+ // | task | parallel | * | // | task | for | + | @@ -1693,7 +1706,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | task | target | * | // | task | teams | + | // | task | cancellation | | - // | | point | ! | + // | | point | ! | + // | task | cancel | ! | // +------------------+-----------------+------------------------------------+ // | ordered | parallel | * | // | ordered | for | + | @@ -1719,6 +1733,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | ordered | teams | + | // | ordered | cancellation | | // | | point | | + // | ordered | cancel | | // +------------------+-----------------+------------------------------------+ // | atomic | parallel | | // | atomic | for | | @@ -1744,6 +1759,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | atomic | teams | | // | atomic | cancellation | | // | | point | | + // | atomic | cancel | | // +------------------+-----------------+------------------------------------+ // | target | parallel | * | // | target | for | * | @@ -1769,6 +1785,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | target | teams | * | // | target | cancellation | | // | | point | | + // | target | cancel | | // +------------------+-----------------+------------------------------------+ // | teams | parallel | * | // | teams | for | + | @@ -1786,7 +1803,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | teams | taskyield | + | // | teams | barrier | + | // | teams | taskwait | + | - // | teams | taskgroup | + | + // | teams | taskgroup | + | // | teams | flush | + | // | teams | ordered | + | // | teams | atomic | + | @@ -1794,6 +1811,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | teams | teams | + | // | teams | cancellation | | // | | point | | + // | teams | cancel | | // +------------------+-----------------+------------------------------------+ if (Stack->getCurScope()) { auto ParentRegion = Stack->getParentDirective(); @@ -1835,13 +1853,19 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // called from OpenMP regions with the required preconditions). if (ParentRegion == OMPD_unknown) return false; - if (CurrentRegion == OMPD_cancellation_point) { + if (CurrentRegion == OMPD_cancellation_point || + CurrentRegion == OMPD_cancel) { // OpenMP [2.16, Nesting of Regions] // A cancellation point construct for which construct-type-clause is // taskgroup must be nested inside a task construct. A cancellation // point construct for which construct-type-clause is not taskgroup must // be closely nested inside an OpenMP construct that matches the type // specified in construct-type-clause. + // A cancel construct for which construct-type-clause is taskgroup must be + // nested inside a task construct. A cancel construct for which + // construct-type-clause is not taskgroup must be closely nested inside an + // OpenMP construct that matches the type specified in + // construct-type-clause. NestingProhibited = !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || (CancelRegion == OMPD_for && ParentRegion == OMPD_for) || @@ -2085,6 +2109,13 @@ StmtResult Sema::ActOnOpenMPExecutableDirective( "cancellation point' directive"); Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); break; + case OMPD_cancel: + assert(ClausesWithImplicit.empty() && + "No clauses are allowed for 'omp cancel' directive"); + assert(AStmt == nullptr && + "No associated statement allowed for 'omp cancel' directive"); + Res = ActOnOpenMPCancelDirective(StartLoc, EndLoc, CancelRegion); + break; case OMPD_threadprivate: llvm_unreachable("OpenMP Directive is not allowed"); case OMPD_unknown: @@ -4293,6 +4324,26 @@ Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, CancelRegion); } +StmtResult Sema::ActOnOpenMPCancelDirective(SourceLocation StartLoc, + SourceLocation EndLoc, + OpenMPDirectiveKind CancelRegion) { + if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && + CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { + Diag(StartLoc, diag::err_omp_wrong_cancel_region) + << getOpenMPDirectiveName(CancelRegion); + return StmtError(); + } + if (DSAStack->isParentNowaitRegion()) { + Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; + return StmtError(); + } + if (DSAStack->isParentOrderedRegion()) { + Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; + return StmtError(); + } + return OMPCancelDirective::Create(Context, StartLoc, EndLoc, CancelRegion); +} + 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 41ab5a2e9b0..80896be981d 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -6719,6 +6719,8 @@ StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( OpenMPDirectiveKind CancelRegion = OMPD_unknown; if (D->getDirectiveKind() == OMPD_cancellation_point) { CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); + } else if (D->getDirectiveKind() == OMPD_cancel) { + CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); } return getDerived().RebuildOMPExecutableDirective( @@ -6978,6 +6980,17 @@ StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( return Res; } +template <typename Derived> +StmtResult +TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, + D->getLocStart()); + StmtResult Res = getDerived().TransformOMPExecutableDirective(D); + getDerived().getSema().EndOpenMPDSABlock(Res.get()); + return Res; +} + //===----------------------------------------------------------------------===// // OpenMP clause transformation //===----------------------------------------------------------------------===// |

