diff options
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 89 |
1 files changed, 84 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index f5937df17d82..fa55f925d117 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -4013,6 +4013,9 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { case OMPD_tile: case OMPD_unroll: break; + case OMPD_loop: + // TODO: 'loop' may require additional parameters depending on the binding. + // Treat similar to OMPD_simd/OMPD_for for now. case OMPD_simd: case OMPD_for: case OMPD_for_simd: @@ -4788,6 +4791,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, // A masked region may not be closely nested inside a worksharing, loop, // atomic, task, or taskloop region. NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || + isOpenMPGenericLoopDirective(ParentRegion) || isOpenMPTaskingDirective(ParentRegion); } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { // OpenMP [2.16, Nesting of Regions] @@ -4821,6 +4825,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, // task, taskloop, critical, ordered, atomic, or masked region. NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || + isOpenMPGenericLoopDirective(ParentRegion) || isOpenMPTaskingDirective(ParentRegion) || ParentRegion == OMPD_master || ParentRegion == OMPD_masked || ParentRegion == OMPD_parallel_master || @@ -4834,6 +4839,7 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, // critical, ordered, atomic, or masked region. NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || + isOpenMPGenericLoopDirective(ParentRegion) || isOpenMPTaskingDirective(ParentRegion) || ParentRegion == OMPD_master || ParentRegion == OMPD_masked || ParentRegion == OMPD_parallel_master || @@ -4879,12 +4885,16 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, !isOpenMPTargetExecutionDirective(CurrentRegion) && !isOpenMPTargetDataManagementDirective(CurrentRegion) && (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { - // OpenMP [2.16, Nesting of Regions] - // distribute, parallel, parallel sections, parallel workshare, and the - // parallel loop and parallel loop SIMD constructs are the only OpenMP - // constructs that can be closely nested in the teams region. + // OpenMP [5.1, 2.22, Nesting of Regions] + // distribute, distribute simd, distribute parallel worksharing-loop, + // distribute parallel worksharing-loop SIMD, loop, parallel regions, + // including any parallel regions arising from combined constructs, + // omp_get_num_teams() regions, and omp_get_team_num() regions are the + // only OpenMP regions that may be strictly nested inside the teams + // region. NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && - !isOpenMPDistributeDirective(CurrentRegion); + !isOpenMPDistributeDirective(CurrentRegion) && + CurrentRegion != OMPD_loop; Recommend = ShouldBeInParallelRegion; } if (!NestingProhibited && @@ -6231,6 +6241,10 @@ StmtResult Sema::ActOnOpenMPExecutableDirective( Res = ActOnOpenMPDispatchDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); break; + case OMPD_loop: + Res = ActOnOpenMPGenericLoopDirective(ClausesWithImplicit, AStmt, StartLoc, + EndLoc, VarsWithInheritedDSA); + break; case OMPD_declare_target: case OMPD_end_declare_target: case OMPD_threadprivate: @@ -8817,6 +8831,7 @@ static bool checkOpenMPIterationSpace( ResultIterSpaces[CurrentNestedLoopCount].NumIterations = ISC.buildNumIterations(DSA.getCurScope(), ResultIterSpaces, (isOpenMPWorksharingDirective(DKind) || + isOpenMPGenericLoopDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind) || isOpenMPLoopTransformationDirective(DKind)), @@ -9300,6 +9315,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind) || + isOpenMPGenericLoopDirective(DKind) || isOpenMPLoopTransformationDirective(DKind)) { // Lower bound variable, initialized with zero. VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); @@ -9399,6 +9415,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); Expr *RHS = (isOpenMPWorksharingDirective(DKind) || + isOpenMPGenericLoopDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind) || isOpenMPLoopTransformationDirective(DKind)) @@ -9410,6 +9427,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, if (isOpenMPLoopBoundSharingDirective(DKind)) { Expr *CombRHS = (isOpenMPWorksharingDirective(DKind) || + isOpenMPGenericLoopDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) ? CombLB.get() @@ -9441,6 +9459,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, } ExprResult Cond = (isOpenMPWorksharingDirective(DKind) || + isOpenMPGenericLoopDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind) || isOpenMPLoopTransformationDirective(DKind)) ? SemaRef.BuildBinOp(CurScope, CondLoc, @@ -9490,6 +9509,7 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, // base variables for the update ExprResult NextLB, NextUB, CombNextLB, CombNextUB; if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || + isOpenMPGenericLoopDirective(DKind) || isOpenMPDistributeDirective(DKind) || isOpenMPLoopTransformationDirective(DKind)) { // LB + ST @@ -10044,6 +10064,57 @@ StmtResult Sema::ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses, TargetCallLoc); } +StmtResult Sema::ActOnOpenMPGenericLoopDirective( + ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { + if (!AStmt) + return StmtError(); + + // OpenMP 5.1 [2.11.7, loop construct] + // A list item may not appear in a lastprivate clause unless it is the + // loop iteration variable of a loop that is associated with the construct. + for (OMPClause *C : Clauses) { + if (auto *LPC = dyn_cast<OMPLastprivateClause>(C)) { + for (Expr *RefExpr : LPC->varlists()) { + SourceLocation ELoc; + SourceRange ERange; + Expr *SimpleRefExpr = RefExpr; + auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); + if (ValueDecl *D = Res.first) { + auto &&Info = DSAStack->isLoopControlVariable(D); + if (!Info.first) { + Diag(ELoc, diag::err_omp_lastprivate_loop_var_non_loop_iteration); + return StmtError(); + } + } + } + } + } + + auto *CS = cast<CapturedStmt>(AStmt); + // 1.2.2 OpenMP Language Terminology + // Structured block - An executable statement with a single entry at the + // top and a single exit at the bottom. + // The point of exit cannot be a branch out of the structured block. + // longjmp() and throw() must not violate the entry/exit criteria. + CS->getCapturedDecl()->setNothrow(); + + OMPLoopDirective::HelperExprs B; + // In presence of clause 'collapse', it will define the nested loops number. + unsigned NestedLoopCount = checkOpenMPLoop( + OMPD_loop, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), + AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); + if (NestedLoopCount == 0) + return StmtError(); + + assert((CurContext->isDependentContext() || B.builtAll()) && + "omp loop exprs were not built"); + + setFunctionHasBranchProtectedScope(); + return OMPGenericLoopDirective::Create(Context, StartLoc, EndLoc, + NestedLoopCount, Clauses, AStmt, B); +} + StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, @@ -13529,6 +13600,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_teams: case OMPD_tile: case OMPD_unroll: @@ -13608,6 +13680,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_teams: case OMPD_simd: case OMPD_tile: @@ -13692,6 +13765,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_simd: case OMPD_tile: case OMPD_unroll: @@ -13773,6 +13847,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_simd: case OMPD_tile: case OMPD_unroll: @@ -13855,6 +13930,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_simd: case OMPD_tile: case OMPD_unroll: @@ -13936,6 +14012,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_simd: case OMPD_tile: case OMPD_unroll: @@ -14018,6 +14095,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_simd: case OMPD_tile: case OMPD_unroll: @@ -14101,6 +14179,7 @@ static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( case OMPD_end_declare_variant: case OMPD_declare_target: case OMPD_end_declare_target: + case OMPD_loop: case OMPD_simd: case OMPD_tile: case OMPD_unroll: |