From 26a89ad7bd378b1f9872ed63e9d0de208335b70d Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Fri, 2 Jul 2021 19:55:38 -0700 Subject: [PATCH] Fixed LFTR bugs LFTR now applicable to all strength reduction candidates with 2 variable operands. If LFTR forms an expression that has already been processed by EPRE, it will not be processed again. Implemented FindScalarVersion() to determine the correct SSA version to use when LFTR causes a var to appear at the compare. The isRebuild parameter for BuildWorkListExpr is now split into sRebuild and insertSorted for its 2 different purposes. --- src/mapleall/maple_me/include/me_ssa_lpre.h | 2 +- src/mapleall/maple_me/include/occur.h | 6 +- src/mapleall/maple_me/include/orig_symbol.h | 7 ++ src/mapleall/maple_me/include/ssa_epre.h | 3 +- src/mapleall/maple_me/include/ssa_pre.h | 4 +- src/mapleall/maple_me/src/irmap.cpp | 2 + src/mapleall/maple_me/src/me_ssa_lpre.cpp | 8 +-- src/mapleall/maple_me/src/ssa_epre.cpp | 24 ++++--- .../maple_me/src/ssa_epre_for_lftr.cpp | 67 +++++++++++++++++-- src/mapleall/maple_me/src/ssa_pre.cpp | 46 +++++++------ 10 files changed, 122 insertions(+), 47 deletions(-) diff --git a/src/mapleall/maple_me/include/me_ssa_lpre.h b/src/mapleall/maple_me/include/me_ssa_lpre.h index 7dfd8f0e6f..3c8c92b152 100644 --- a/src/mapleall/maple_me/include/me_ssa_lpre.h +++ b/src/mapleall/maple_me/include/me_ssa_lpre.h @@ -59,7 +59,7 @@ class MeSSALPre : public SSAPre { void BuildEntryLHSOcc4Formals() const override; void BuildWorkListLHSOcc(MeStmt &meStmt, int32 seqStmt) override; void CreateMembarOccAtCatch(BB &bb) override; - void BuildWorkListExpr(MeStmt&, int32, MeExpr&, bool, MeExpr*, bool isRootExpr) override; + void BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool isRebuild, MeExpr *tmpVar, bool isRootExpr, bool insertSorted) override; void BuildWorkList() override; BB *GetBB(BBId id) const override { return func->GetCfg()->GetBBFromID(id); diff --git a/src/mapleall/maple_me/include/occur.h b/src/mapleall/maple_me/include/occur.h index 2b095c8146..18d1c69191 100644 --- a/src/mapleall/maple_me/include/occur.h +++ b/src/mapleall/maple_me/include/occur.h @@ -504,7 +504,8 @@ class PreWorkCand { redo2HandleCritEdges(false), needLocalRefVar(false), isSRCand(false), - onlyInvariantOpnds(false) { + onlyInvariantOpnds(false), + deletedFromWorkList(false) { ASSERT(pIdx != 0, "PreWorkCand: initial puIdx cannot be 0"); } @@ -632,10 +633,11 @@ class PreWorkCand { // puIdx cannot be 0 if hasLocalOpnd is true bool redo2HandleCritEdges : 1; // redo to make critical edges affect canbevail bool needLocalRefVar : 1; // for the candidate, if necessary to introduce + // localrefvar in addition to the temp register to for saving the value public: bool isSRCand : 1; // is a strength reduction candidate bool onlyInvariantOpnds : 1; // all operands have only 1 SSA version - // localrefvar in addition to the temp register to for saving the value + bool deletedFromWorkList : 1; // processed by SSAPRE already }; class PreStmtWorkCand : public PreWorkCand { diff --git a/src/mapleall/maple_me/include/orig_symbol.h b/src/mapleall/maple_me/include/orig_symbol.h index 47cc5cc802..d1b21ee348 100644 --- a/src/mapleall/maple_me/include/orig_symbol.h +++ b/src/mapleall/maple_me/include/orig_symbol.h @@ -249,6 +249,13 @@ class OriginalSt { nextLevOsts.push_back(nextLevelOst); } + uint32 NumSSAVersions() { + if (zeroVersionIndex == 0 || !IsPregOst()) { + return versionsIndices.size(); + } + return versionsIndices.size() - 1; // preg's zero version not counted + } + private: enum OSTType { kUnkonwnOst, diff --git a/src/mapleall/maple_me/include/ssa_epre.h b/src/mapleall/maple_me/include/ssa_epre.h index bb73bfe238..40eb1d1b35 100644 --- a/src/mapleall/maple_me/include/ssa_epre.h +++ b/src/mapleall/maple_me/include/ssa_epre.h @@ -34,7 +34,7 @@ class SSAEPre : public SSAPre { MeExpr *PhiOpndFromRes(MeRealOcc &realZ, size_t j) const override; void ComputeVarAndDfPhis() override; void BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr&, bool isReBuild, - MeExpr *tempVar, bool isRootExpr) override; + MeExpr *tempVar, bool isRootExpr, bool insertSorted) override; void BuildWorkListIvarLHSOcc(MeStmt &meStmt, int32 seqStmt, bool isReBuild, MeExpr *tempVar) override; void CollectVarForMeExpr(MeExpr &meExpr, std::vector &varVec) const override; void CollectVarForCand(MeRealOcc &realOcc, std::vector &varVec) const override; @@ -77,6 +77,7 @@ class SSAEPre : public SSAPre { bool epreIncludeRef; bool enableLHSIvar; // here starts methods related to linear function test replacement + ScalarMeExpr *FindScalarVersion(ScalarMeExpr *scalar, MeStmt *stmt); OpMeExpr *FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) override; void CreateCompOcc(MeStmt *meStmt, int seqStmt, OpMeExpr *comapre, bool isRebuilt) override; }; diff --git a/src/mapleall/maple_me/include/ssa_pre.h b/src/mapleall/maple_me/include/ssa_pre.h index d6f8f2abdf..807b1e20e1 100644 --- a/src/mapleall/maple_me/include/ssa_pre.h +++ b/src/mapleall/maple_me/include/ssa_pre.h @@ -181,7 +181,7 @@ class SSAPre { virtual void BuildWorkListIvarLHSOcc(MeStmt&, int32, bool, MeExpr*) {} virtual void BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool isRebuilt, MeExpr *tempVar, - bool isRootExpr) = 0; + bool isRootExpr, bool insertSorted) = 0; virtual void BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeExpr *tempVar = nullptr); virtual void BuildWorkListBB(BB *bb); virtual void ConstructUseOccurMap() {} @@ -200,7 +200,7 @@ class SSAPre { } bool CheckIfAnyLocalOpnd(const MeExpr &meExpr) const; - MeRealOcc *CreateRealOcc(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool isRebuilt, bool isLHS = false); + void CreateRealOcc(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool insertSorted, bool isLHS = false); virtual bool ScreenPhiBB(BBId bbId) const = 0; virtual bool EpreLocalRefVar() const { return false; diff --git a/src/mapleall/maple_me/src/irmap.cpp b/src/mapleall/maple_me/src/irmap.cpp index 16dbc24020..f145efe119 100644 --- a/src/mapleall/maple_me/src/irmap.cpp +++ b/src/mapleall/maple_me/src/irmap.cpp @@ -22,6 +22,7 @@ namespace maple { VarMeExpr *IRMap::CreateVarMeExprVersion(OriginalSt *ost) { VarMeExpr *varMeExpr = New(exprID++, ost, verst2MeExprTable.size(), GlobalTables::GetTypeTable().GetTypeFromTyIdx(ost->GetTyIdx())->GetPrimType()); + ost->PushbackVersionsIndices(verst2MeExprTable.size()); verst2MeExprTable.push_back(varMeExpr); return varMeExpr; } @@ -103,6 +104,7 @@ RegMeExpr *IRMap::CreateRegMeExprVersion(OriginalSt &pregOSt) { RegMeExpr *regReadExpr = New(exprID++, &pregOSt, verst2MeExprTable.size(), kMeOpReg, OP_regread, pregOSt.GetMIRPreg()->GetPrimType()); + pregOSt.PushbackVersionsIndices(verst2MeExprTable.size()); verst2MeExprTable.push_back(regReadExpr); return regReadExpr; } diff --git a/src/mapleall/maple_me/src/me_ssa_lpre.cpp b/src/mapleall/maple_me/src/me_ssa_lpre.cpp index 78c6990164..fb732350d9 100644 --- a/src/mapleall/maple_me/src/me_ssa_lpre.cpp +++ b/src/mapleall/maple_me/src/me_ssa_lpre.cpp @@ -292,7 +292,7 @@ void MeSSALPre::CreateMembarOccAtCatch(BB &bb) { // only handle the leaf of load, because all other expressions has been done by // previous SSAPre -void MeSSALPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool, MeExpr*, bool) { +void MeSSALPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool isRebuild, MeExpr *tmpVar, bool isRootExpr, bool insertSorted) { MeExprOp meOp = meExpr.GetMeOp(); switch (meOp) { case kMeOpVar: { @@ -341,7 +341,7 @@ void MeSSALPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, for (size_t i = 0; i < kOperandNumTernary; ++i) { MeExpr *opnd = meOpExpr->GetOpnd(i); if (opnd != nullptr) { - BuildWorkListExpr(meStmt, seqStmt, *opnd, false, nullptr, false); + BuildWorkListExpr(meStmt, seqStmt, *opnd, false, nullptr, false, false); } } break; @@ -351,13 +351,13 @@ void MeSSALPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, MapleVector &opnds = naryMeExpr->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { MeExpr *opnd = *it; - BuildWorkListExpr(meStmt, seqStmt, *opnd, false, nullptr, false); + BuildWorkListExpr(meStmt, seqStmt, *opnd, false, nullptr, false, false); } break; } case kMeOpIvar: { auto *ivarMeExpr = static_cast(&meExpr); - BuildWorkListExpr(meStmt, seqStmt, *ivarMeExpr->GetBase(), false, nullptr, false); + BuildWorkListExpr(meStmt, seqStmt, *ivarMeExpr->GetBase(), false, nullptr, false, false); break; } case kMeOpAddroflabel: diff --git a/src/mapleall/maple_me/src/ssa_epre.cpp b/src/mapleall/maple_me/src/ssa_epre.cpp index b06ce7fee8..4afc32be76 100644 --- a/src/mapleall/maple_me/src/ssa_epre.cpp +++ b/src/mapleall/maple_me/src/ssa_epre.cpp @@ -316,11 +316,13 @@ void SSAEPre::ComputeVarAndDfPhis() { } // build worklist for each expression; -// isRebuild means the expression is built from second time, in which case, +// isRebuild means the expression is not built in step 0, in which case, // tempVar is not nullptr, and it matches only expressions with tempVar as one of -// its operands; isRebuild is true only when called from the code motion phase +// its operands; isRebuild is true only when called from the code motion phase. +// insertSorted is for passing to CreateRealOcc. Most of the time, isRebuild implies insertSorted, +// except when invoked from LFTR. void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, bool isRebuild, MeExpr *tempVar, - bool isRootExpr) { + bool isRootExpr, bool insertSorted) { if (meExpr.GetTreeID() == (curTreeId + 1)) { return; // already visited twice in the same tree } @@ -333,7 +335,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b for (uint32 i = 0; i < meOpExpr->GetNumOpnds(); i++) { MeExpr *opnd = meOpExpr->GetOpnd(i); if (!opnd->IsLeaf()) { - BuildWorkListExpr(meStmt, seqStmt, *opnd, isRebuild, tempVar, false); + BuildWorkListExpr(meStmt, seqStmt, *opnd, isRebuild, tempVar, false, insertSorted); isFirstOrder = false; } else if (LeafIsVolatile(opnd)) { isFirstOrder = false; @@ -362,7 +364,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b if (isRebuild && !hasTempVarAs1Opnd) { break; } - (void)CreateRealOcc(meStmt, seqStmt, meExpr, isRebuild); + (void)CreateRealOcc(meStmt, seqStmt, meExpr, insertSorted); break; } case kMeOpNary: { @@ -373,7 +375,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b for (auto it = opnds.begin(); it != opnds.end(); ++it) { MeExpr *opnd = *it; if (!opnd->IsLeaf()) { - BuildWorkListExpr(meStmt, seqStmt, *opnd, isRebuild, tempVar, false); + BuildWorkListExpr(meStmt, seqStmt, *opnd, isRebuild, tempVar, false, insertSorted); isFirstOrder = false; } else if (LeafIsVolatile(opnd)) { isFirstOrder = false; @@ -396,11 +398,11 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b auto *ptrMIRType = static_cast(mirType); MIRJarrayType *arryType = safe_cast(ptrMIRType->GetPointedType()); if (arryType == nullptr) { - (void)CreateRealOcc(meStmt, seqStmt, meExpr, isRebuild); + (void)CreateRealOcc(meStmt, seqStmt, meExpr, insertSorted); } else { int dim = arryType->GetDim(); // to compute the dim field if (dim <= 1) { - (void)CreateRealOcc(meStmt, seqStmt, meExpr, isRebuild); + (void)CreateRealOcc(meStmt, seqStmt, meExpr, insertSorted); } else { if (GetSSAPreDebug()) { mirModule->GetOut() << "----- real occ suppressed for jarray with dim " << dim << '\n'; @@ -419,7 +421,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b } } if (!intrinDesc->IsLoadMem()) { - (void)CreateRealOcc(meStmt, seqStmt, meExpr, isRebuild); + (void)CreateRealOcc(meStmt, seqStmt, meExpr, insertSorted); } } } @@ -432,7 +434,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b break; } if (!base->IsLeaf()) { - BuildWorkListExpr(meStmt, seqStmt, *ivarMeExpr->GetBase(), isRebuild, tempVar, false); + BuildWorkListExpr(meStmt, seqStmt, *ivarMeExpr->GetBase(), isRebuild, tempVar, false, insertSorted); } else if (ivarMeExpr->IsVolatile()) { break; } else if (IsThreadObjField(*ivarMeExpr)) { @@ -442,7 +444,7 @@ void SSAEPre::BuildWorkListExpr(MeStmt &meStmt, int32 seqStmt, MeExpr &meExpr, b } else if (!epreIncludeRef && ivarMeExpr->GetPrimType() == PTY_ref) { break; } else if (!isRebuild || base->IsUseSameSymbol(*tempVar)) { - (void)CreateRealOcc(meStmt, seqStmt, meExpr, isRebuild); + (void)CreateRealOcc(meStmt, seqStmt, meExpr, insertSorted); } break; } diff --git a/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp b/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp index d56782d80a..167e53a8a9 100644 --- a/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp +++ b/src/mapleall/maple_me/src/ssa_epre_for_lftr.cpp @@ -17,6 +17,51 @@ namespace maple { +// Find the SSA version of scalar at stmt by search backward for its def. +// When reaching the beginning of BB, continue with parent BB in the dominator +// tree. It is assumed that scalarOst has no alias, so chi lists are skipped. +ScalarMeExpr *SSAEPre::FindScalarVersion(ScalarMeExpr *scalar, MeStmt *stmt) { + if (scalar->GetOst()->NumSSAVersions() == 1) { + return scalar; + } + BB *bb = stmt->GetBB(); + stmt = stmt->GetPrev(); + ScalarMeExpr *lhs = nullptr; + do { + // go thru the statements in reverse order + while (stmt != nullptr) { + AssignMeStmt *asStmt = dynamic_cast(stmt); + if (asStmt != nullptr) { + lhs = asStmt->GetLHS(); + if (lhs->GetOst() == scalar->GetOst()) { + return lhs; + } + } else { + CallMeStmt *callStmt = dynamic_cast(stmt); + if (callStmt != nullptr) { + lhs = callStmt->GetAssignedLHS(); + if (lhs != nullptr && lhs->GetOst() == scalar->GetOst()) { + return lhs; + } + } + } + stmt = stmt->GetPrev(); + } + // check if there is phi + MapleMap &mePhiList = bb->GetMePhiList(); + MapleMap::iterator it = mePhiList.find(scalar->GetOst()->GetIndex()); + if (it != mePhiList.end()) { + return it->second->GetLHS(); + } + // set bb to its parent in dominator tree + bb = dom->GetDom(bb->GetBBId()); + // make stmt point to last statement in bb + stmt = to_ptr(bb->GetMeStmts().rbegin()); + } while (true); + CHECK_FATAL(false, "FindScalarVersion: fail to find SSA version for scalar"); + return nullptr; +} + // one side of compare is an operand x in workCand->GetTheMeExpr() with current // occurrence occExpr; replace that side of the compare by regorvar; replace the // other side of compare by the expression formed by substituting x in occExpr @@ -31,6 +76,9 @@ namespace maple { // EXAMPLE 3: INPUT: workCand is (i + &A), compare is (i < 100) // RETURN: regorvar < 100 + &A // 100 + &A is folded to an OP_addrof node +// EXAMPLE 4: INPUT: workCand is (i + p), compare is (i < 100) +// RETURN: regorvar < 100 + p (need to find p's SSA version there) +// 100 + p is added to EPRE work list OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { MeExpr *compare = compOcc->GetMeExpr(); // determine the ith operand of workCand that is the jth operand of compare @@ -62,10 +110,19 @@ OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { newSide.SetOpndType(x->GetOpndType()); break; } - case OP_mul: + case OP_mul: { + newSide.SetOpnd(1-i, x->GetOpnd(1-i)); + break; + } case OP_add: case OP_sub: { - newSide.SetOpnd(1-i, x->GetOpnd(1-i)); + ScalarMeExpr *scalarOpnd = dynamic_cast(x->GetOpnd(1-i)); + if (scalarOpnd == nullptr) { + newSide.SetOpnd(1-i, x->GetOpnd(1-i)); + } else { + scalarOpnd = FindScalarVersion(scalarOpnd, compOcc->GetMeStmt()); + newSide.SetOpnd(1-i, scalarOpnd); + } break; } default: { @@ -80,7 +137,7 @@ OpMeExpr *SSAEPre::FormLFTRCompare(MeRealOcc *compOcc, MeExpr *regorvar) { hashedSide = simplifyExpr; } else { hashedSide = irMap->HashMeExpr(newSide); - BuildWorkListExpr(*compOcc->GetMeStmt(), compOcc->GetSequence(), *hashedSide, true, nullptr, true); + BuildWorkListExpr(*compOcc->GetMeStmt(), compOcc->GetSequence(), *hashedSide, false, nullptr, true, true); } OpMeExpr newcompare(-1, compare->GetOp(), compare->GetPrimType(), 2); newcompare.SetOpndType(regorvar->GetPrimType()); @@ -139,8 +196,8 @@ void SSAEPre::CreateCompOcc(MeStmt *meStmt, int seqStmt, OpMeExpr *compare, bool (compareRHS && iv->GetOst() == compareRHS->GetOst())) { numRelevantOpnds++; } else { - // disqualify as compocc if x has a scalar which is not used in the comparison and has multiple SSA versions - if (iv->GetOst()->GetVersionsIndices().size() > 1) { + // disqualify as compocc if x has a scalar which is not used in the comparison and has multiple SSA versions and is not preg + if (iv->GetOst()->NumSSAVersions() > 1 && !iv->GetOst()->IsPregOst()) { isRelevant = false; break; } diff --git a/src/mapleall/maple_me/src/ssa_pre.cpp b/src/mapleall/maple_me/src/ssa_pre.cpp index a6324f9eb7..5c3efbc7ee 100644 --- a/src/mapleall/maple_me/src/ssa_pre.cpp +++ b/src/mapleall/maple_me/src/ssa_pre.cpp @@ -1384,7 +1384,7 @@ bool SSAPre::CheckIfAnyLocalOpnd(const MeExpr &meExpr) const { } // create a new realOcc based on the meStmt and meExpr -MeRealOcc *SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bool isRebuilt, bool isLHS) { +void SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bool insertSOrted, bool isLHS) { uint32 hashIdx = PreWorkCandHashTable::ComputeWorkCandHashIndex(meExpr); PreWorkCand *wkCand = preWorkCandHashTable.GetWorkcandFromIndex(hashIdx); while (wkCand != nullptr) { @@ -1398,13 +1398,16 @@ MeRealOcc *SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bo MeRealOcc *newOcc = ssaPreMemPool->New(&meStmt, seqStmt, &meExpr); newOcc->SetIsLHS(isLHS); if (wkCand != nullptr) { - if (isRebuilt) { + if (wkCand->deletedFromWorkList) { + return; // processed earlier; skip doing it again + } + if (insertSOrted) { // insert to realOccs in dt_preorder of the BBs and seq in each BB wkCand->AddRealOccSorted(*dom, *newOcc, GetPUIdx()); } else { wkCand->AddRealOccAsLast(*newOcc, GetPUIdx()); } - return newOcc; + return; } // workcand not yet created; create a new one and add to worklist wkCand = ssaPreMemPool->New(ssaPreAllocator, &meExpr, GetPUIdx()); @@ -1427,7 +1430,7 @@ MeRealOcc *SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bo wkCand->onlyInvariantOpnds = true; for (int i = 0; i < meExpr.GetNumOpnds(); i++) { ScalarMeExpr *scalarOpnd = dynamic_cast(meExpr.GetOpnd(i)); - if (scalarOpnd != nullptr && scalarOpnd->GetOst()->GetVersionsIndices().size() > 1) { + if (scalarOpnd != nullptr && scalarOpnd->GetOst()->NumSSAVersions() > 1) { wkCand->onlyInvariantOpnds = false; break; } @@ -1441,7 +1444,7 @@ MeRealOcc *SSAPre::CreateRealOcc(MeStmt &meStmt, int seqStmt, MeExpr &meExpr, bo // add to bucket at workcandHashTable[hashIdx] wkCand->SetNext(*preWorkCandHashTable.GetWorkcandFromIndex(hashIdx)); preWorkCandHashTable.SetWorkCandAt(hashIdx, *wkCand); - return newOcc; + return; } void SSAPre::CreateMembarOcc(MeStmt &meStmt, int seqStmt) { @@ -1511,27 +1514,27 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE break; case OP_throw: { auto *thrMeStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *thrMeStmt->GetOpnd(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *thrMeStmt->GetOpnd(), isRebuilt, tempVar, true, isRebuilt); break; } case OP_iassign: case OP_iassignoff: { auto *ivarStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *ivarStmt->GetRHS(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *ivarStmt->GetRHS(), isRebuilt, tempVar, true, isRebuilt); BuildWorkListExpr(*meStmt, static_cast(seqStmt), - *ivarStmt->GetLHSVal()->GetBase(), isRebuilt, tempVar, true); + *ivarStmt->GetLHSVal()->GetBase(), isRebuilt, tempVar, true, isRebuilt); BuildWorkListIvarLHSOcc(*meStmt, static_cast(seqStmt), isRebuilt, tempVar); break; } case OP_brtrue: case OP_brfalse: { auto *condGotoStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *condGotoStmt->GetOpnd(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *condGotoStmt->GetOpnd(), isRebuilt, tempVar, true, isRebuilt); break; } case OP_switch: { auto *switchStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *switchStmt->GetOpnd(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *switchStmt->GetOpnd(), isRebuilt, tempVar, true, isRebuilt); break; } case OP_dassign: { @@ -1543,7 +1546,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE dassMeStmt->GetLHS()->GetOst() == static_cast(dassMeStmt->GetRHS())->GetOst()) { break; // identity assignment converted from phi } - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *dassMeStmt->GetRHS(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *dassMeStmt->GetRHS(), isRebuilt, tempVar, true, isRebuilt); BuildWorkListLHSOcc(*meStmt, static_cast(seqStmt)); break; } @@ -1552,12 +1555,12 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE if (rassMeStmt->isIncDecStmt && preKind == kExprPre) { break; } - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *rassMeStmt->GetRHS(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *rassMeStmt->GetRHS(), isRebuilt, tempVar, true, isRebuilt); break; } case OP_maydassign: { auto *dassMeStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *dassMeStmt->GetRHS(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *dassMeStmt->GetRHS(), isRebuilt, tempVar, true, isRebuilt); BuildWorkListLHSOcc(*meStmt, static_cast(seqStmt)); break; } @@ -1567,7 +1570,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE // affects LPRE only; will cause CI failure if this is allowed break; } - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *unaryStmt->GetOpnd(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *unaryStmt->GetOpnd(), isRebuilt, tempVar, true, isRebuilt); break; } case OP_incref: @@ -1577,7 +1580,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE case OP_assertnonnull: case OP_free: { auto *unaryStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *unaryStmt->GetOpnd(), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *unaryStmt->GetOpnd(), isRebuilt, tempVar, true, isRebuilt); break; } case OP_syncenter: @@ -1585,7 +1588,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE auto *syncMeStmt = static_cast(meStmt); const MapleVector &opnds = syncMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { - BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true, isRebuilt); } break; } @@ -1608,7 +1611,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE } } } - BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true, isRebuilt); } break; } @@ -1633,7 +1636,7 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE auto *naryMeStmt = static_cast(meStmt); const MapleVector &opnds = naryMeStmt->GetOpnds(); for (auto it = opnds.begin(); it != opnds.end(); ++it) { - BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true, isRebuilt); } break; } @@ -1665,15 +1668,15 @@ void SSAPre::BuildWorkListStmt(MeStmt &stmt, uint32 seqStmt, bool isRebuilt, MeE continue; } } - BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), **it, isRebuilt, tempVar, true, isRebuilt); } break; } case OP_assertlt: case OP_assertge: { auto *assMeStmt = static_cast(meStmt); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *assMeStmt->GetOpnd(0), isRebuilt, tempVar, true); - BuildWorkListExpr(*meStmt, static_cast(seqStmt), *assMeStmt->GetOpnd(1), isRebuilt, tempVar, true); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *assMeStmt->GetOpnd(0), isRebuilt, tempVar, true, isRebuilt); + BuildWorkListExpr(*meStmt, static_cast(seqStmt), *assMeStmt->GetOpnd(1), isRebuilt, tempVar, true, isRebuilt); break; } default: @@ -1734,6 +1737,7 @@ void SSAPre::ApplySSAPRE() { workCand = workList.front(); workCand->SetIndex(static_cast(cnt)); workList.pop_front(); + workCand->deletedFromWorkList = true; if (workCand->GetRealOccs().empty()) { continue; } -- Gitee