diff --git a/src/bin/maple b/src/bin/maple index 965b8e5b12574756056b11529e96cce7f1e72986..14ce6013ef67b85b5638a02a0948b3090757d6ef 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/maple_me/include/me_cfg.h b/src/maple_me/include/me_cfg.h index d5f7a2966d08d52e72ab69f3033449b0de397cf8..4fa0d590d527d79d36082751b1e37742bcdbe286 100644 --- a/src/maple_me/include/me_cfg.h +++ b/src/maple_me/include/me_cfg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -56,7 +56,8 @@ class MeCFG { void ConvertPhiList2IdentityAssigns(BB &meBB) const; void ConvertMevarPhiList2IdentityAssigns(BB &meBB) const; void ConvertMeregphiList2IdentityAssigns(BB &meBB) const; - + bool IsStartTryBB(BB &meBB) const; + void FixTryBB(BB &startBB, BB &nextBB); MeFunction &func; bool hasDoWhile = false; }; diff --git a/src/maple_me/src/me_bb_layout.cpp b/src/maple_me/src/me_bb_layout.cpp index 418083aa7be37f60291f7ccc732f274a3b5003b1..30d4118a9499189523536dcb4be4a28bd69130e1 100644 --- a/src/maple_me/src/me_bb_layout.cpp +++ b/src/maple_me/src/me_bb_layout.cpp @@ -400,6 +400,7 @@ void BBLayout::FixEndTryBB(BB &bb) { void BBLayout::FixTryBB(BB &startTryBB, BB &nextBB) { if (nextBB.GetBBLabel() != 0) { startTryBB.SetBBLabel(nextBB.GetBBLabel()); + func.SetLabelBBAt(nextBB.GetBBLabel(), &startTryBB); nextBB.SetBBLabel(0); } startTryBB.GetPred().clear(); diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp index 7acdcc3141db5a0cce1830305c3eb7853ee20081..1e317c353e814ced9ea97ebada61793903225fc3 100644 --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -439,6 +439,26 @@ void MeCFG::FixMirCFG() { } } +bool MeCFG::IsStartTryBB(maple::BB &meBB) const { + if (!meBB.GetAttributes(kBBAttrIsTry) || meBB.GetAttributes(kBBAttrIsTryEnd)) { + return false; + } + return (!meBB.GetStmtNodes().empty() && meBB.GetStmtNodes().front().GetOpCode() == OP_try); +} + +void MeCFG::FixTryBB(maple::BB &startBB, maple::BB &nextBB) { + if (nextBB.GetBBLabel() != 0) { + startBB.SetBBLabel(nextBB.GetBBLabel()); + func.SetLabelBBAt(nextBB.GetBBLabel(), &startBB); + nextBB.SetBBLabel(0); + } + startBB.GetPred().clear(); + for (size_t i = 0; i < nextBB.GetPred().size(); ++i) { + nextBB.GetPred(i)->ReplaceSucc(&nextBB, &startBB); + } + nextBB.GetPred().clear(); + startBB.ReplaceSucc(startBB.GetSucc(0), &nextBB); +} // analyse the CFG to find the BBs that are not reachable from function entries // and delete them @@ -454,6 +474,29 @@ void MeCFG::UnreachCodeAnalysis(bool updatePhi) { auto *bb = *bIt; BBId idx = bb->GetBBId(); if (!visitedBBs[idx] && !bb->GetAttributes(kBBAttrIsEntry)) { + // if bb is StartTryBB, relationship between endtry and try should be maintained + if (IsStartTryBB(*bb)) { + bool needFixTryBB = false; + size_t size = func.GetAllBBs().size(); + for (size_t nextIdx = idx + 1; nextIdx < size; ++nextIdx) { + auto nextBB = func.GetBBFromID(BBId(nextIdx)); + if (nextBB == nullptr) { + continue; + } + if (!visitedBBs[nextIdx] && nextBB->GetAttributes(kBBAttrIsTryEnd)) { + break; + } + if (visitedBBs[nextIdx]) { + needFixTryBB = true; + visitedBBs[idx] = true; + FixTryBB(*bb, *nextBB); + break; + } + } + if (needFixTryBB) { + continue; + } + } bb->SetAttributes(kBBAttrWontExit); // avoid redundant pred before adding to common_exit_bb's pred list size_t pi = 0; diff --git a/src/maple_me/src/me_ssa_update.cpp b/src/maple_me/src/me_ssa_update.cpp index 248502447d7fceed031486d99d6d8df65a4db1d0..8c479c6d04fbb4e7abf8dec523901354d95f3100 100644 --- a/src/maple_me/src/me_ssa_update.cpp +++ b/src/maple_me/src/me_ssa_update.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) [2019] Huawei Technologies Co.,Ltd.All rights reserved. + * Copyright (c) [2019-2020] Huawei Technologies Co.,Ltd.All rights reserved. * * OpenArkCompiler is licensed under the Mulan PSL v1. * You can use this software according to the terms and conditions of the Mulan PSL v1. @@ -104,13 +104,17 @@ MeExpr *MeSSAUpdate::RenameExpr(MeExpr &meExpr, bool &changed) { case kMeOpIvar: { auto &ivarMeExpr = static_cast(meExpr); IvarMeExpr newMeExpr(kInvalidExprID); + if (ivarMeExpr.GetMu() == nullptr) { + newMeExpr.SetMuVal(nullptr); + } else { + newMeExpr.SetMuVal(static_cast(RenameExpr(*ivarMeExpr.GetMu(), needRehash))); + } newMeExpr.SetBase(RenameExpr(*ivarMeExpr.GetBase(), needRehash)); if (needRehash) { changed = true; newMeExpr.SetFieldID(ivarMeExpr.GetFieldID()); newMeExpr.SetTyIdx(ivarMeExpr.GetTyIdx()); newMeExpr.InitBase(ivarMeExpr.GetOp(), ivarMeExpr.GetPrimType(), ivarMeExpr.GetNumOpnds()); - newMeExpr.SetMuVal(ivarMeExpr.GetMu()); return irMap.HashMeExpr(newMeExpr); } return &meExpr; @@ -158,17 +162,27 @@ MeExpr *MeSSAUpdate::RenameExpr(MeExpr &meExpr, bool &changed) { void MeSSAUpdate::RenameStmts(BB &bb) { for (auto &stmt : bb.GetMeStmts()) { + MapleMap *muList = stmt.GetMuList(); + if (muList != nullptr) { + for (auto &mu : *muList) { + auto it = renameStacks.find(mu.first); + if (it != renameStacks.end()) { + mu.second = static_cast(it->second->top()); + } + } + } // rename the expressions - bool changed = false; for (size_t i = 0; i < stmt.NumMeStmtOpnds(); ++i) { + bool changed = false; stmt.SetOpnd(i, RenameExpr(*stmt.GetOpnd(i), changed /* dummy */)); } // process mayDef MapleMap *chiList = stmt.GetChiList(); if (chiList != nullptr) { - for (const auto &chi : *chiList) { + for (auto &chi : *chiList) { auto it = renameStacks.find(chi.first); if (it != renameStacks.end() && chi.second != nullptr) { + chi.second->SetRHS(static_cast(it->second->top())); it->second->push(chi.second->GetLHS()); } } diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp index 3e87b86888fa49a0133833bac15d7f221f114c19..da5559d5e75546a1aadb6b58587352fe43505e58 100644 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -1425,8 +1425,6 @@ void SSAPre::BuildWorkListStmt(MeStmt *meStmt, uint32 seqStmt, bool isRebuilt, M case OP_throw: { auto *thrMeStmt = static_cast(meStmt); BuildWorkListExpr(meStmt, seqStmt, thrMeStmt->GetOpnd(), isRebuilt, tempVar, true); - // if (!isRebuilt) - // CreateExitOcc(bb); break; } case OP_iassign: {