diff options
author | Kelvin Li <kkwli0@gmail.com> | 2016-08-05 14:37:37 +0000 |
---|---|---|
committer | Kelvin Li <kkwli0@gmail.com> | 2016-08-05 14:37:37 +0000 |
commit | 02532876334c3323c26b236761bca6b4cead3c27 (patch) | |
tree | 5324cdc4a4a6726796691a75ebd274772c66b66f /clang/lib | |
parent | 24dc1e7a90ee85b33ac103f976bf6ad14097f9bf (diff) | |
download | bcm5719-llvm-02532876334c3323c26b236761bca6b4cead3c27.tar.gz bcm5719-llvm-02532876334c3323c26b236761bca6b4cead3c27.zip |
[OpenMP] Sema and parsing for 'teams distribute' pragma
This patch is to implement sema and parsing for 'teams distribute' pragma.
Differential Revision: https://reviews.llvm.org/D23189
llvm-svn: 277818
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/StmtOpenMP.cpp | 51 | ||||
-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 | 26 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmt.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGStmtOpenMP.cpp | 12 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 1 | ||||
-rw-r--r-- | clang/lib/Parse/ParseOpenMP.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 123 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 11 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReaderStmt.cpp | 13 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriterStmt.cpp | 6 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 1 |
13 files changed, 257 insertions, 11 deletions
diff --git a/clang/lib/AST/StmtOpenMP.cpp b/clang/lib/AST/StmtOpenMP.cpp index 504efdf9af5..7197586e39d 100644 --- a/clang/lib/AST/StmtOpenMP.cpp +++ b/clang/lib/AST/StmtOpenMP.cpp @@ -1311,3 +1311,54 @@ OMPTargetSimdDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, numLoopChildren(CollapsedNum, OMPD_target_simd)); return new (Mem) OMPTargetSimdDirective(CollapsedNum, NumClauses); } + +OMPTeamsDistributeDirective *OMPTeamsDistributeDirective::Create( + const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, + unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, + const HelperExprs &Exprs) { + unsigned Size = llvm::alignTo(sizeof(OMPTeamsDistributeDirective), + llvm::alignOf<OMPClause *>()); + void *Mem = C.Allocate( + Size + sizeof(OMPClause *) * Clauses.size() + + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute)); + OMPTeamsDistributeDirective *Dir = new (Mem) OMPTeamsDistributeDirective( + StartLoc, EndLoc, CollapsedNum, Clauses.size()); + Dir->setClauses(Clauses); + Dir->setAssociatedStmt(AssociatedStmt); + Dir->setIterationVariable(Exprs.IterationVarRef); + Dir->setLastIteration(Exprs.LastIteration); + Dir->setCalcLastIteration(Exprs.CalcLastIteration); + Dir->setPreCond(Exprs.PreCond); + Dir->setCond(Exprs.Cond); + Dir->setInit(Exprs.Init); + Dir->setInc(Exprs.Inc); + Dir->setIsLastIterVariable(Exprs.IL); + Dir->setLowerBoundVariable(Exprs.LB); + Dir->setUpperBoundVariable(Exprs.UB); + Dir->setStrideVariable(Exprs.ST); + Dir->setEnsureUpperBound(Exprs.EUB); + Dir->setNextLowerBound(Exprs.NLB); + Dir->setNextUpperBound(Exprs.NUB); + Dir->setNumIterations(Exprs.NumIterations); + Dir->setPrevLowerBoundVariable(Exprs.PrevLB); + Dir->setPrevUpperBoundVariable(Exprs.PrevUB); + Dir->setCounters(Exprs.Counters); + Dir->setPrivateCounters(Exprs.PrivateCounters); + Dir->setInits(Exprs.Inits); + Dir->setUpdates(Exprs.Updates); + Dir->setFinals(Exprs.Finals); + Dir->setPreInits(Exprs.PreInits); + return Dir; +} + +OMPTeamsDistributeDirective * +OMPTeamsDistributeDirective::CreateEmpty(const ASTContext &C, + unsigned NumClauses, + unsigned CollapsedNum, EmptyShell) { + unsigned Size = llvm::alignTo(sizeof(OMPTeamsDistributeDirective), + llvm::alignOf<OMPClause *>()); + void *Mem = C.Allocate( + Size + sizeof(OMPClause *) * NumClauses + + sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_teams_distribute)); + return new (Mem) OMPTeamsDistributeDirective(CollapsedNum, NumClauses); +} diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index 8033ea263db..0b103f96a5c 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -1203,6 +1203,12 @@ void StmtPrinter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *Node) { PrintOMPExecutableDirective(Node); } +void StmtPrinter::VisitOMPTeamsDistributeDirective( + OMPTeamsDistributeDirective *Node) { + Indent() << "#pragma omp teams distribute "; + PrintOMPExecutableDirective(Node); +} + //===----------------------------------------------------------------------===// // Expr printing methods. //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp index 776a672c7f6..cff836959d0 100644 --- a/clang/lib/AST/StmtProfile.cpp +++ b/clang/lib/AST/StmtProfile.cpp @@ -732,6 +732,11 @@ void StmtProfiler::VisitOMPTargetSimdDirective( VisitOMPLoopDirective(S); } +void StmtProfiler::VisitOMPTeamsDistributeDirective( + const OMPTeamsDistributeDirective *S) { + VisitOMPLoopDirective(S); +} + void StmtProfiler::VisitExpr(const Expr *S) { VisitStmt(S); } diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp index ac89983d0ce..4b41ab186d4 100644 --- a/clang/lib/Basic/OpenMPKinds.cpp +++ b/clang/lib/Basic/OpenMPKinds.cpp @@ -620,6 +620,16 @@ bool clang::isAllowedClauseForDirective(OpenMPDirectiveKind DKind, break; } break; + case OMPD_teams_distribute: + switch (CKind) { +#define OPENMP_TEAMS_DISTRIBUTE_CLAUSE(Name) \ + case OMPC_##Name: \ + return true; +#include "clang/Basic/OpenMPKinds.def" + default: + break; + } + break; case OMPD_declare_target: case OMPD_end_declare_target: case OMPD_unknown: @@ -645,7 +655,8 @@ bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) { DKind == OMPD_distribute_parallel_for || DKind == OMPD_distribute_parallel_for_simd || DKind == OMPD_distribute_simd || - DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd; + DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd || + DKind == OMPD_teams_distribute; // TODO add next directives. } @@ -688,7 +699,8 @@ bool clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) { } bool clang::isOpenMPTeamsDirective(OpenMPDirectiveKind DKind) { - return DKind == OMPD_teams; // TODO add next directives. + return DKind == OMPD_teams || DKind == OMPD_teams_distribute; + // TODO add next directives. } bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) { @@ -699,13 +711,19 @@ bool clang::isOpenMPSimdDirective(OpenMPDirectiveKind DKind) { // TODO add next directives. } -bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) { +bool clang::isOpenMPNestingDistributeDirective(OpenMPDirectiveKind Kind) { return Kind == OMPD_distribute || Kind == OMPD_distribute_parallel_for || Kind == OMPD_distribute_parallel_for_simd || Kind == OMPD_distribute_simd; // TODO add next directives. } +bool clang::isOpenMPDistributeDirective(OpenMPDirectiveKind Kind) { + return isOpenMPNestingDistributeDirective(Kind) || + Kind == OMPD_teams_distribute; + // TODO add next directives. +} + bool clang::isOpenMPPrivate(OpenMPClauseKind Kind) { return Kind == OMPC_private || Kind == OMPC_firstprivate || Kind == OMPC_lastprivate || Kind == OMPC_linear || @@ -723,5 +741,5 @@ bool clang::isOpenMPTaskingDirective(OpenMPDirectiveKind Kind) { bool clang::isOpenMPLoopBoundSharingDirective(OpenMPDirectiveKind Kind) { return Kind == OMPD_distribute_parallel_for || Kind == OMPD_distribute_parallel_for_simd || - Kind == OMPD_distribute_simd; + Kind == OMPD_distribute_simd || Kind == OMPD_teams_distribute; } diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 2adb1770ea4..aa457ad5f3f 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -298,6 +298,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { case Stmt::OMPTargetSimdDirectiveClass: EmitOMPTargetSimdDirective(cast<OMPTargetSimdDirective>(*S)); break; + case Stmt::OMPTeamsDistributeDirectiveClass: + EmitOMPTeamsDistributeDirective(cast<OMPTeamsDistributeDirective>(*S)); + break; } } diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index 954721e16a9..f2b99428588 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -1934,6 +1934,18 @@ void CodeGenFunction::EmitOMPTargetSimdDirective( }); } +void CodeGenFunction::EmitOMPTeamsDistributeDirective( + const OMPTeamsDistributeDirective &S) { + OMPLexicalScope Scope(*this, S, /*AsInlined=*/true); + CGM.getOpenMPRuntime().emitInlinedDirective( + *this, OMPD_teams_distribute, + [&S](CodeGenFunction &CGF, PrePostActionTy &) { + OMPLoopScope PreInitScope(CGF, S); + CGF.EmitStmt( + cast<CapturedStmt>(S.getAssociatedStmt())->getCapturedStmt()); + }); +} + /// \brief Emit a helper variable and return corresponding lvalue. static LValue EmitOMPHelperVar(CodeGenFunction &CGF, const DeclRefExpr *Helper) { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 24ead4c3095..bb0437157e5 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2512,6 +2512,7 @@ public: void EmitOMPTargetParallelForSimdDirective( const OMPTargetParallelForSimdDirective &S); void EmitOMPTargetSimdDirective(const OMPTargetSimdDirective &S); + void EmitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective &S); /// Emit outlined function for the target directive. static std::pair<llvm::Function * /*OutlinedFn*/, diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index d5d2f08d998..d4cdc8e8596 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -108,7 +108,8 @@ static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { { OMPD_target, OMPD_parallel, OMPD_target_parallel }, { OMPD_target, OMPD_simd, OMPD_target_simd }, { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for }, - { OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd } + { OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd }, + { OMPD_teams, OMPD_distribute, OMPD_teams_distribute } }; enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 }; auto Tok = P.getCurToken(); @@ -742,6 +743,7 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( case OMPD_distribute_simd: case OMPD_target_parallel_for_simd: case OMPD_target_simd: + case OMPD_teams_distribute: Diag(Tok, diag::err_omp_unexpected_directive) << getOpenMPDirectiveName(DKind); break; @@ -775,7 +777,8 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( /// 'target parallel' | 'target parallel for' | /// 'target update' | 'distribute parallel for' | /// 'distribute paralle for simd' | 'distribute simd' | -/// 'target parallel for simd' | 'target simd' {clause} +/// 'target parallel for simd' | 'target simd' | +/// 'teams distribute' {clause} /// annot_pragma_openmp_end /// StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( @@ -884,7 +887,8 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( case OMPD_distribute_parallel_for_simd: case OMPD_distribute_simd: case OMPD_target_parallel_for_simd: - case OMPD_target_simd: { + case OMPD_target_simd: + case OMPD_teams_distribute: { ConsumeToken(); // Parse directive name of the 'critical' directive if any. if (DKind == OMPD_critical) { diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 79c4d1c4aab..8194e161eae 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -1694,7 +1694,8 @@ void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { } case OMPD_distribute_parallel_for_simd: case OMPD_distribute_simd: - case OMPD_distribute_parallel_for: { + case OMPD_distribute_parallel_for: + case OMPD_teams_distribute: { QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); @@ -1922,6 +1923,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | |parallel for simd| | // | parallel | distribute simd | + | // | parallel | target simd | * | + // | parallel | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | for | parallel | * | // | for | for | + | @@ -1966,6 +1968,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for | target parallel | + | // | | for simd | | // | for | target simd | * | + // | for | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | master | parallel | * | // | master | for | + | @@ -2010,6 +2013,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | master | target parallel | + | // | | for simd | | // | master | target simd | * | + // | master | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | critical | parallel | * | // | critical | for | + | @@ -2053,6 +2057,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | critical | target parallel | + | // | | for simd | | // | critical | target simd | * | + // | critical | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | simd | parallel | | // | simd | for | | @@ -2097,6 +2102,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | simd | target parallel | | // | | for simd | | // | simd | target simd | | + // | simd | teams distribute| | // +------------------+-----------------+------------------------------------+ // | for simd | parallel | | // | for simd | for | | @@ -2141,6 +2147,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for simd | target parallel | | // | | for simd | | // | for simd | target simd | | + // | for simd | teams distribute| | // +------------------+-----------------+------------------------------------+ // | parallel for simd| parallel | | // | parallel for simd| for | | @@ -2184,6 +2191,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for simd| distribute simd | | // | | for simd | | // | parallel for simd| target simd | | + // | parallel for simd| teams distribute| | // +------------------+-----------------+------------------------------------+ // | sections | parallel | * | // | sections | for | + | @@ -2272,6 +2280,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | section | target parallel | + | // | | for simd | | // | section | target simd | * | + // | section | teams distrubte | + | // +------------------+-----------------+------------------------------------+ // | single | parallel | * | // | single | for | + | @@ -2316,6 +2325,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | single | target parallel | + | // | | for simd | | // | single | target simd | * | + // | single | teams distrubte | + | // +------------------+-----------------+------------------------------------+ // | parallel for | parallel | * | // | parallel for | for | + | @@ -2360,6 +2370,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for | target parallel | + | // | | for simd | | // | parallel for | target simd | * | + // | parallel for | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | parallel sections| parallel | * | // | parallel sections| for | + | @@ -2404,6 +2415,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel sections| target parallel | + | // | | for simd | | // | parallel sections| target simd | * | + // | parallel sections| teams distribute| + | // +------------------+-----------------+------------------------------------+ // | task | parallel | * | // | task | for | + | @@ -2448,6 +2460,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | task | target parallel | + | // | | for simd | | // | task | target simd | * | + // | task | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | ordered | parallel | * | // | ordered | for | + | @@ -2492,6 +2505,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | ordered | target parallel | + | // | | for simd | | // | ordered | target simd | * | + // | ordered | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | atomic | parallel | | // | atomic | for | | @@ -2536,6 +2550,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | atomic | target parallel | | // | | for simd | | // | atomic | target simd | | + // | atomic | teams distribute| | // +------------------+-----------------+------------------------------------+ // | target | parallel | * | // | target | for | * | @@ -2580,6 +2595,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | target | target parallel | | // | | for simd | | // | target | target simd | | + // | target | teams distribute| | // +------------------+-----------------+------------------------------------+ // | target parallel | parallel | * | // | target parallel | for | * | @@ -2624,6 +2640,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | target parallel | target parallel | | // | | for simd | | // | target parallel | target simd | | + // | target parallel | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | target parallel | parallel | * | // | for | | | @@ -2697,6 +2714,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for | for simd | | // | target parallel | target simd | | // | for | | | + // | target parallel | teams distribute| | + // | for | | | // +------------------+-----------------+------------------------------------+ // | teams | parallel | * | // | teams | for | + | @@ -2741,6 +2760,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | teams | target parallel | + | // | | for simd | | // | teams | target simd | + | + // | teams | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | taskloop | parallel | * | // | taskloop | for | + | @@ -2784,6 +2804,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | taskloop | target parallel | * | // | | for simd | | // | taskloop | target simd | * | + // | taskloop | teams distribute| + | // +------------------+-----------------+------------------------------------+ // | taskloop simd | parallel | | // | taskloop simd | for | | @@ -2828,6 +2849,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | taskloop simd | target parallel | | // | | for simd | | // | taskloop simd | target simd | | + // | taskloop simd | teams distribute| | // +------------------+-----------------+------------------------------------+ // | distribute | parallel | * | // | distribute | for | * | @@ -2872,6 +2894,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | distribute | target parallel | | // | | for simd | | // | distribute | target simd | | + // | distribute | teams distribute| | // +------------------+-----------------+------------------------------------+ // | distribute | parallel | * | // | parallel for | | | @@ -2946,6 +2969,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for | for simd | | // | distribute | target simd | | // | parallel for | | | + // | distribute | teams distribute| | + // | parallel for | | | // +------------------+-----------------+------------------------------------+ // | distribute | parallel | * | // | parallel for simd| | | @@ -3019,6 +3044,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | parallel for simd| for simd | | // | distribute | target simd | | // | parallel for simd| | | + // | distribute | teams distribute| | + // | parallel for simd| | | // +------------------+-----------------+------------------------------------+ // | distribute simd | parallel | * | // | distribute simd | for | * | @@ -3063,6 +3090,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | distribute simd | target parallel | * | // | | for simd | | // | distribute simd | target simd | * | + // | distribute simd | teams distribute| * | // +------------------+-----------------+------------------------------------+ // | target parallel | parallel | * | // | for simd | | | @@ -3136,6 +3164,8 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | for simd | for simd | | // | target parallel | target simd | * | // | for simd | | | + // | target parallel | teams distribute| * | + // | for simd | | | // +------------------+-----------------+------------------------------------+ // | target simd | parallel | | // | target simd | for | | @@ -3180,6 +3210,51 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, // | target simd | target parallel | | // | | for simd | | // | target simd | target simd | | + // | target simd | teams distribute| | + // +------------------+-----------------+------------------------------------+ + // | teams distribute | parallel | | + // | teams distribute | for | | + // | teams distribute | for simd | | + // | teams distribute | master | | + // | teams distribute | critical | | + // | teams distribute | simd | | + // | teams distribute | sections | | + // | teams distribute | section | | + // | teams distribute | single | | + // | teams distribute | parallel for | | + // | teams distribute |parallel for simd| | + // | teams distribute |parallel sections| | + // | teams distribute | task | | + // | teams distribute | taskyield | | + // | teams distribute | barrier | | + // | teams distribute | taskwait | | + // | teams distribute | taskgroup | | + // | teams distribute | flush | | + // | teams distribute | ordered | + (with simd clause) | + // | teams distribute | atomic | | + // | teams distribute | target | | + // | teams distribute | target parallel | | + // | teams distribute | target parallel | | + // | | for | | + // | teams distribute | target enter | | + // | | data | | + // | teams distribute | target exit | | + // | | data | | + // | teams distribute | teams | | + // | teams distribute | cancellation | | + // | | point | | + // | teams distribute | cancel | | + // | teams distribute | taskloop | | + // | teams distribute | taskloop simd | | + // | teams distribute | distribute | | + // | teams distribute | distribute | | + // | | parallel for | | + // | teams distribute | distribute | | + // | |parallel for simd| | + // | teams distribute | distribute simd | | + // | teams distribute | target parallel | | + // | | for simd | | + // | teams distribute | teams distribute| | // +------------------+-----------------+------------------------------------+ if (Stack->getCurScope()) { auto ParentRegion = Stack->getParentDirective(); @@ -3335,7 +3410,7 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, Recommend = ShouldBeInTargetRegion; Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); } - if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { + if (!NestingProhibited && ParentRegion == OMPD_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 @@ -3344,11 +3419,12 @@ static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, !isOpenMPDistributeDirective(CurrentRegion); Recommend = ShouldBeInParallelRegion; } - if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { + if (!NestingProhibited && + isOpenMPNestingDistributeDirective(CurrentRegion)) { // OpenMP 4.5 [2.17 Nesting of Regions] // The region associated with the distribute construct must be strictly // nested inside a teams region - NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); + NestingProhibited = ParentRegion != OMPD_teams; Recommend = ShouldBeInTeamsRegion; } if (!NestingProhibited && @@ -3698,6 +3774,11 @@ StmtResult Sema::ActOnOpenMPExecutableDirective( EndLoc, VarsWithInheritedDSA); AllowedNameModifiers.push_back(OMPD_target); break; + case OMPD_teams_distribute: + Res = ActOnOpenMPTeamsDistributeDirective(ClausesWithImplicit, AStmt, + StartLoc, EndLoc, + VarsWithInheritedDSA); + break; case OMPD_declare_target: case OMPD_end_declare_target: case OMPD_threadprivate: @@ -7350,6 +7431,40 @@ StmtResult Sema::ActOnOpenMPTargetSimdDirective( NestedLoopCount, Clauses, AStmt, B); } +StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( + ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, + SourceLocation EndLoc, + llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { + if (!AStmt) + return StmtError(); + + CapturedStmt *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' with number of loops, it will + // define the nested loops number. + unsigned NestedLoopCount = + CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), + nullptr /*ordered not a clause on distribute*/, AStmt, + *this, *DSAStack, VarsWithImplicitDSA, B); + if (NestedLoopCount == 0) + return StmtError(); + + assert((CurContext->isDependentContext() || B.builtAll()) && + "omp teams distribute loop exprs were not built"); + + getCurFunction()->setHasBranchProtectedScope(); + return OMPTeamsDistributeDirective::Create(Context, StartLoc, EndLoc, + NestedLoopCount, Clauses, AStmt, + B); +} + 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 9c55478ca8d..f68cdcaee87 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -7637,6 +7637,17 @@ StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( return Res; } +template <typename Derived> +StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( + OMPTeamsDistributeDirective *D) { + DeclarationNameInfo DirName; + getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, + nullptr, D->getLocStart()); + 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 f437ed1ef38..331932e0155 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -2864,6 +2864,11 @@ void ASTStmtReader::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) { VisitOMPLoopDirective(D); } +void ASTStmtReader::VisitOMPTeamsDistributeDirective( + OMPTeamsDistributeDirective *D) { + VisitOMPLoopDirective(D); +} + //===----------------------------------------------------------------------===// // ASTReader Implementation //===----------------------------------------------------------------------===// @@ -3583,6 +3588,14 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; } + case STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE: { + auto NumClauses = Record[ASTStmtReader::NumStmtFields]; + auto CollapsedNum = Record[ASTStmtReader::NumStmtFields + 1]; + S = OMPTeamsDistributeDirective::CreateEmpty(Context, NumClauses, + CollapsedNum, 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 9cc867a518b..19b1e20d369 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -2512,6 +2512,12 @@ void ASTStmtWriter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *D) { Code = serialization::STMT_OMP_TARGET_SIMD_DIRECTIVE; } +void ASTStmtWriter::VisitOMPTeamsDistributeDirective( + OMPTeamsDistributeDirective *D) { + VisitOMPLoopDirective(D); + Code = serialization::STMT_OMP_TEAMS_DISTRIBUTE_DIRECTIVE; +} + //===----------------------------------------------------------------------===// // ASTWriter Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index a3c5fc40fdf..6ca24c78a12 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -847,6 +847,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred, case Stmt::OMPDistributeSimdDirectiveClass: case Stmt::OMPTargetParallelForSimdDirectiveClass: case Stmt::OMPTargetSimdDirectiveClass: + case Stmt::OMPTeamsDistributeDirectiveClass: llvm_unreachable("Stmt should not be in analyzer evaluation loop"); case Stmt::ObjCSubscriptRefExprClass: |