diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2016-04-22 03:56:56 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2016-04-22 03:56:56 +0000 |
commit | 5dff95c04de0d096563462530160fd5fc221fd8f (patch) | |
tree | ef34759729b05ec62a742bfc096fe72fafbd2df1 /clang/lib/Sema/SemaOpenMP.cpp | |
parent | 59479e7208c4be3ea9317763dad05b208f0ea135 (diff) | |
download | bcm5719-llvm-5dff95c04de0d096563462530160fd5fc221fd8f.tar.gz bcm5719-llvm-5dff95c04de0d096563462530160fd5fc221fd8f.zip |
[OPENMP] Fix for LCV in simd directives in explicit clauses.
If loop control variable for simd-based directives is explicitly marked
as linear/lastprivate in clauses, codegen for such construct would
crash. Patch fixes this problem.
llvm-svn: 267101
Diffstat (limited to 'clang/lib/Sema/SemaOpenMP.cpp')
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 01474518a58..97647c3f99c 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -1033,9 +1033,9 @@ void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { PopExpressionEvaluationContext(); } -static bool -FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, - Expr *NumIterations, Sema &SemaRef, Scope *S); +static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, + Expr *NumIterations, Sema &SemaRef, + Scope *S, DSAStackTy *Stack); namespace { @@ -3523,8 +3523,8 @@ public: Expr *BuildPreCond(Scope *S, Expr *Cond, llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; /// \brief Build reference expression to the counter be used for codegen. - DeclRefExpr * - BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; + DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, + DSAStackTy &DSA) const; /// \brief Build reference expression to the private counter be used for /// codegen. Expr *BuildPrivateCounterVar() const; @@ -4063,13 +4063,17 @@ Expr *OpenMPIterationSpaceChecker::BuildPreCond( /// \brief Build reference expression to the counter be used for codegen. DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( - llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { + llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { auto *VD = dyn_cast<VarDecl>(LCDecl); if (!VD) { VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); auto *Ref = buildDeclRefExpr( SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); - Captures.insert(std::make_pair(LCRef, Ref)); + DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); + // If the loop control decl is explicitly marked as private, do not mark it + // as captured again. + if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) + Captures.insert(std::make_pair(LCRef, Ref)); return Ref; } return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), @@ -4283,7 +4287,7 @@ static bool CheckOpenMPIterationSpace( (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), Captures); - ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures); + ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); ResultIterSpace.CounterInit = ISC.BuildCounterInit(); ResultIterSpace.CounterStep = ISC.BuildCounterStep(); @@ -4787,10 +4791,10 @@ CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, } // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step - auto *CounterVar = buildDeclRefExpr( - SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), - IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), - /*RefersToCapture=*/true); + auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); + auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), + IS.CounterVar->getExprLoc(), + /*RefersToCapture=*/true); ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Captures); if (!Init.isUsable()) { @@ -4933,7 +4937,8 @@ StmtResult Sema::ActOnOpenMPSimdDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -4986,7 +4991,8 @@ StmtResult Sema::ActOnOpenMPForDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -5022,7 +5028,8 @@ StmtResult Sema::ActOnOpenMPForSimdDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -5238,7 +5245,8 @@ StmtResult Sema::ActOnOpenMPParallelForDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -5279,7 +5287,8 @@ StmtResult Sema::ActOnOpenMPParallelForSimdDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -6251,7 +6260,8 @@ StmtResult Sema::ActOnOpenMPTargetParallelForDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -6474,7 +6484,8 @@ StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( for (auto C : Clauses) { if (auto LC = dyn_cast<OMPLinearClause>(C)) if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), - B.NumIterations, *this, CurScope)) + B.NumIterations, *this, CurScope, + DSAStack)) return StmtError(); } } @@ -8964,9 +8975,9 @@ OMPClause *Sema::ActOnOpenMPLinearClause( buildPostUpdate(*this, ExprPostUpdates)); } -static bool -FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, - Expr *NumIterations, Sema &SemaRef, Scope *S) { +static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, + Expr *NumIterations, Sema &SemaRef, + Scope *S, DSAStackTy *Stack) { // Walk the vars and build update/final expressions for the CodeGen. SmallVector<Expr *, 8> Updates; SmallVector<Expr *, 8> Finals; @@ -8984,10 +8995,27 @@ FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, auto CurPrivate = Clause.privates().begin(); auto LinKind = Clause.getModifier(); for (auto &RefExpr : Clause.varlists()) { + SourceLocation ELoc; + SourceRange ERange; + Expr *SimpleRefExpr = RefExpr; + auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, + /*AllowArraySection=*/false); + ValueDecl *D = Res.first; + if (Res.second || !D) { + Updates.push_back(nullptr); + Finals.push_back(nullptr); + HasErrors = true; + continue; + } + if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { + D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) + ->getMemberDecl(); + } + auto &&Info = Stack->isLoopControlVariable(D); Expr *InitExpr = *CurInit; // Build privatized reference to the current linear var. - auto DE = cast<DeclRefExpr>(RefExpr); + auto DE = cast<DeclRefExpr>(SimpleRefExpr); Expr *CapturedRef; if (LinKind == OMPC_LINEAR_uval) CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); @@ -8998,18 +9026,27 @@ FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, /*RefersToCapture=*/true); // Build update: Var = InitExpr + IV * Step - ExprResult Update = - BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, - InitExpr, IV, Step, /* Subtract */ false); + ExprResult Update; + if (!Info.first) { + Update = + BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, + InitExpr, IV, Step, /* Subtract */ false); + } else + Update = *CurPrivate; Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), /*DiscardedValue=*/true); // Build final: Var = InitExpr + NumIterations * Step - ExprResult Final = - BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, - InitExpr, NumIterations, Step, /* Subtract */ false); + ExprResult Final; + if (!Info.first) { + Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, + InitExpr, NumIterations, Step, + /* Subtract */ false); + } else + Final = *CurPrivate; Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), /*DiscardedValue=*/true); + if (!Update.isUsable() || !Final.isUsable()) { Updates.push_back(nullptr); Finals.push_back(nullptr); |