diff --git a/src/mapleall/maple_me/include/me_ssa_lpre.h b/src/mapleall/maple_me/include/me_ssa_lpre.h index 7dfd8f0e6f857e3bffd6a510a9539744e1088abe..3c8c92b15283c1aae34a99878e0d92cbebf888f0 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 2b095c814600ad6c826860c1c93d9202b358958b..18d1c691919d50929fb932d73f7a593e66bc5022 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 47cc5cc80230b0489957055f4a12efd6113fae87..d1b21ee34879f83b1a67125784c131de2feced96 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 bb73bfe238d96d19cf756facceb5989dbfe64a0e..40eb1d1b35f48e154cddaf3f963213385c69f5b9 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 d6f8f2abdf6a6fe6edb4e61e6fa04626c66db595..807b1e20e1bf176f84599ef607e80e2d8990552b 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 16dbc2402030d9a5f13d83cd1f774905d766016f..f145efe119026df84dc4b96de52631e4f5481122 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 78c69901649e281d059db695f915f11ca064330f..fb732350d9be1e017114110dd49adaa04cafa10b 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 b06ce7fee8eb5f81db7ce27e667132dd0bf7cf8a..4afc32be76b0b6610f82e3ec3c8bb88fd981403c 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 d56782d80a7dc3512903b8df76421127d2acdf58..167e53a8a9ddefadc8f5e289e9f02de3e35e2e6f 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 a6324f9eb7cbca725e634486098cd6090c58a96f..5c3efbc7ee638a6205bbfa1973651db5c81fa485 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; }