diff --git a/src/bin/maple b/src/bin/maple index 9d1e972d5de66cd13f16ec647917287b45977604..86eb9e91fdea0e4af51895e60864a0ba994b70b8 100755 Binary files a/src/bin/maple and b/src/bin/maple differ diff --git a/src/deplibs/libmempool.a b/src/deplibs/libmempool.a index 3cfd8646c9069be63e58585b3e3e0ff75054a41b..066f7a9dabcc000800d57886e713198b1b695ea5 100644 Binary files a/src/deplibs/libmempool.a and b/src/deplibs/libmempool.a differ diff --git a/src/deplibs/libmplutil.a b/src/deplibs/libmplutil.a index 4231e2da9201656c77bc6e535d63556b0ffce1cc..edece5d0ce158215d482cf9b5fea3ec72caeb5ba 100644 Binary files a/src/deplibs/libmplutil.a and b/src/deplibs/libmplutil.a differ diff --git a/src/maple_ipa/src/callgraph.cpp b/src/maple_ipa/src/callgraph.cpp index 83a05ee9d858e29fa9ef468c7c928505e7349304..340c9b2c1b68aedcdfea7354c0c32ab520bd737a 100644 --- a/src/maple_ipa/src/callgraph.cpp +++ b/src/maple_ipa/src/callgraph.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. @@ -614,7 +614,6 @@ static void ResetInferredType(std::vector &inferredSymbols, MIRSymbo break; } } - // ASSERT(i &inferredSymbols, MIRSymbol *s, TyIdx idx) { @@ -711,7 +710,6 @@ void IPODevirtulize::SearchDefInClinit(const Klass *klass) { if (node->GetOpCode() != OP_dread) { continue; } - // ASSERT(node->op == OP_dread, "Must be dread"); DreadNode *dreadNode = static_cast(node); MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(dreadNode->GetStIdx()); ResetInferredType(gcmallocSymbols, tmpSymbol); @@ -815,7 +813,6 @@ void IPODevirtulize::SearchDefInMemberMethods(const Klass *klass) { if (node->GetOpCode() != OP_dread) { continue; } - // ASSERT(node->op == OP_dread, "Must be dread"); DreadNode *dreadNode = static_cast(node); MIRSymbol *tmpSymbol = func->GetLocalOrGlobalSymbol(dreadNode->GetStIdx()); ResetInferredType(gcmallocSymbols, tmpSymbol); diff --git a/src/maple_me/include/me_abco.h b/src/maple_me/include/me_abco.h index 4b81b91f043872828dc6125c2ff7ec9656ce5a1e..12b998c3520c2252e401a48d66836a6418e4f53c 100644 --- a/src/maple_me/include/me_abco.h +++ b/src/maple_me/include/me_abco.h @@ -197,7 +197,7 @@ class DefPoint { class MeABC { public: - static bool kDebug; + static bool isDebug; MeABC(MeFunction &meFunction, Dominance &dom, MeIRMap &map, MemPool &pool) : meFunc(&meFunction), dom(&dom), @@ -208,7 +208,7 @@ class MeABC { prove(nullptr), forbidenPi(nullptr) {} ~MeABC() = default; - void executeABCO(); + void ExecuteABCO(); private: bool CollectABC(); diff --git a/src/maple_me/include/me_function.h b/src/maple_me/include/me_function.h index 492fd6fc1bb071a622248ed1327a42f8d7bc349a..334c7b118a68aa292bd11fdd47b51d8e0260b803 100644 --- a/src/maple_me/include/me_function.h +++ b/src/maple_me/include/me_function.h @@ -143,8 +143,6 @@ enum MeFuncHint { kRcLowered = 0x04, // method lowered by rclowering }; -// to suppress warning -// lint -sem(maple::MeFunction::PartialInit,initializer) class MeFunction : public FuncEmit { using BBPtrHolder = MapleVector; diff --git a/src/maple_me/include/me_inequality_graph.h b/src/maple_me/include/me_inequality_graph.h index 8ca41d3177d28666fc7ada86ccff40322048f504..ee8839c4d3618504f1dff043c36993d165199bb4 100644 --- a/src/maple_me/include/me_inequality_graph.h +++ b/src/maple_me/include/me_inequality_graph.h @@ -131,12 +131,12 @@ class InequalEdge { return pairEdge; } - bool leq(const InequalEdge &edge) const { + bool LessEqual(const InequalEdge &edge) const { ASSERT(edgeType == edge.GetEdgeType(), "two edges must have the same type: upper or lower"); return edgeType == kUpper ? value.constValue <= edge.GetConstValue() : value.constValue >= edge.GetConstValue(); } - bool geq(int32 val) const{ + bool GreaterEqual(int32 val) const{ return edgeType == kUpper ? value.constValue >= val : value.constValue <= val; } diff --git a/src/maple_me/include/preg_renamer.h b/src/maple_me/include/preg_renamer.h index 275530a826ea4aa4b4a084703771714d1f53f16e..a50de0a8addfc02d8d3352cf6e451594f9b0465e 100644 --- a/src/maple_me/include/preg_renamer.h +++ b/src/maple_me/include/preg_renamer.h @@ -16,6 +16,7 @@ #define MAPLE_ME_INCLUDE_PREGRENAMER_H #include "me_irmap.h" #include "ssa_pre.h" + namespace maple { class PregRenamer { public: diff --git a/src/maple_me/include/ssa_devirtual.h b/src/maple_me/include/ssa_devirtual.h index b69838368cb52863e676431a79b04c100b96a1c8..b07732e7b1a7ff7d18777b504116cd034531b324 100644 --- a/src/maple_me/include/ssa_devirtual.h +++ b/src/maple_me/include/ssa_devirtual.h @@ -20,6 +20,7 @@ #include "dominance.h" #include "class_hierarchy.h" #include "clone.h" + namespace maple { class SSADevirtual { public: @@ -41,7 +42,7 @@ class SSADevirtual { optedInterfaceCalls(0), nullCheckCount(0) {} - virtual ~SSADevirtual() {} + virtual ~SSADevirtual() = default; void Perform(BB *entryBB); diff --git a/src/maple_me/include/ssa_epre.h b/src/maple_me/include/ssa_epre.h index d128b460e2c740d0ebee84102656284b039c10b6..a5c5c0e7f26ba177168db5a4a6fb0e4272c2d644 100644 --- a/src/maple_me/include/ssa_epre.h +++ b/src/maple_me/include/ssa_epre.h @@ -15,6 +15,7 @@ #ifndef MAPLE_ME_INCLUDE_SSAEPRE_H #define MAPLE_ME_INCLUDE_SSAEPRE_H #include "ssa_pre.h" + namespace maple { class SSAEPre : public SSAPre { public: diff --git a/src/maple_me/include/ssa_pre.h b/src/maple_me/include/ssa_pre.h index b9c19bfabc1ee67552ac7e8584808d1a02840c11..4080cea4bbde3814f75c026fde90c7c080bf85e3 100644 --- a/src/maple_me/include/ssa_pre.h +++ b/src/maple_me/include/ssa_pre.h @@ -17,6 +17,7 @@ #include "irmap.h" #include "occur.h" #include "securec.h" + namespace maple { enum PreKind { kExprPre, @@ -63,6 +64,7 @@ class SSAPre { virtual MeStmt *CopyMeStmt(MeStmt &meStmt); virtual IassignMeStmt *CopyIassignMeStmt(const IassignMeStmt &iaStmt); void IncTreeid() { + // Incremented by 2 for each tree; purpose is to avoid processing a node the third time inside a tree curTreeId += 2; } @@ -161,8 +163,8 @@ class SSAPre { MeExpr *curTemp = nullptr; // the created temp for current workCand VarMeExpr *curLocalRefVar = nullptr; // the created localrefvar for ref-type iread MapleMap temp2LocalRefVarMap; - int32 reBuiltOccIndex = -1; // stores the size of worklist every time when try to add new worklist, update before each - // code motion + int32 reBuiltOccIndex = -1; // stores the size of worklist every time when try to add new worklist, update before + // each code motion uint32 strIdxCount = 0; // ssapre will create a lot of temp variables if using var to store redundances, start from 0 // step 6 codemotion methods MeExpr *CreateNewCurTemp(MeExpr *meExpr); diff --git a/src/maple_me/src/hdse.cpp b/src/maple_me/src/hdse.cpp index 7df4fa3b96782c6d8fc2b95dde3fe311dc2771f6..4d2feebcd3d3e6ad5d23b08afd533a25678c1dc2 100644 --- a/src/maple_me/src/hdse.cpp +++ b/src/maple_me/src/hdse.cpp @@ -226,7 +226,7 @@ bool HDSE::HasNonDeletableExpr(const MeStmt &meStmt) { case OP_dassign: { auto &dasgn = static_cast(meStmt); VarMeExpr *varMeExpr = dasgn.GetVarLHS(); - return (varMeExpr && varMeExpr->IsVolatile(ssaTab)) || ExprNonDeletable(*dasgn.GetRHS()) || + return (varMeExpr != nullptr && varMeExpr->IsVolatile(ssaTab)) || ExprNonDeletable(*dasgn.GetRHS()) || (hdseKeepRef && dasgn.Propagated()) || dasgn.GetWasMayDassign(); } case OP_regassign: { diff --git a/src/maple_me/src/me_abco.cpp b/src/maple_me/src/me_abco.cpp index 4bc60a130f0f269c784cfa566b3b668b5f5b7587..4c67fb1509aef12cafd68ab88c726da568ad11b9 100644 --- a/src/maple_me/src/me_abco.cpp +++ b/src/maple_me/src/me_abco.cpp @@ -18,7 +18,7 @@ // ABCD: Eliminating Array Bounds Checks on Demand. // Rastislav Bodik, Rajiv Gupta, Vivek Sarkar. namespace maple { -bool MeABC::kDebug = false; +bool MeABC::isDebug = false; constexpr int kNumOpnds = 2; constexpr int kPiStmtUpperBound = 2; constexpr int kPiListSize = 2; @@ -82,7 +82,8 @@ VarMeExpr *MeABC::CreateNewPiExpr(MeExpr &opnd) { CHECK_FATAL(opnd.GetMeOp() == kMeOpVar, "must be"); SSATab &ssaTab = irMap->GetSSATab(); OriginalSt *ost = ssaTab.GetOriginalStFromID(static_cast(&opnd)->GetOStIdx()); - CHECK_FATAL(ost != nullptr && !ost->IsVolatile(), "must be"); + CHECK_NULL_FATAL(ost); + CHECK_FATAL(!ost->IsVolatile(), "must be"); VarMeExpr *var = irMap->NewInPool(irMap->GetExprID(), ost->GetIndex(), irMap->GetVerst2MeExprTable().size()); irMap->SetExprID(irMap->GetExprID() + 1); @@ -155,16 +156,16 @@ void MeABC::InsertPiNodes() { } std::vector &arryChk = it->second; for (MeStmt *meStmt : arryChk) { - NaryMeExpr *nMeExpr = arrayChecks[meStmt]; - CHECK_FATAL(nMeExpr->GetOpnds().size() == kNumOpnds, "must be"); - MeExpr *opnd1 = nMeExpr->GetOpnd(0); - MeExpr *opnd2 = nMeExpr->GetOpnd(1); + NaryMeExpr *naryMeExpr = arrayChecks[meStmt]; + CHECK_FATAL(naryMeExpr->GetOpnds().size() == kNumOpnds, "must be"); + MeExpr *opnd1 = naryMeExpr->GetOpnd(0); + MeExpr *opnd2 = naryMeExpr->GetOpnd(1); // consider whether we should create pi if opnd2 is const CHECK_FATAL(opnd1->GetMeOp() == kMeOpVar, "must be"); CHECK_FATAL(opnd1->GetPrimType() == PTY_ref, "must be"); CHECK_FATAL(opnd2->GetMeOp() == kMeOpVar || opnd2->GetMeOp() == kMeOpConst, "must be"); - VarMeExpr *arracyCheckOpnd2 = CreateNewPiExpr(*opnd2); - CreateNewPiStmt(arracyCheckOpnd2, *opnd2, *meStmt); + VarMeExpr *arrayCheckOpnd2 = CreateNewPiExpr(*opnd2); + CreateNewPiStmt(arrayCheckOpnd2, *opnd2, *meStmt); } } } @@ -192,7 +193,8 @@ bool MeABC::ExistedPiNode(BB &bb, BB &parentBB, VarMeExpr &rhs) { return false; } std::vector &piStmts = it->second; - CHECK_FATAL(piStmts.size() >= 1 && piStmts.size() <= kPiStmtUpperBound, "must be"); + CHECK_FATAL(!piStmts.empty(), "should not be empty"); + CHECK_FATAL(piStmts.size() <= kPiStmtUpperBound, "must be"); PiassignMeStmt *pi1 = piStmts.at(0); if (pi1->GetLHS()->GetOStIdx() == rhs.GetOStIdx()) { return true; @@ -226,8 +228,10 @@ void MeABC::InsertPhiNodes() { VarMeExpr *rhs = newDefStmt->GetRHS(); if (newDefStmt->IsPiStmt()) { BB *genByBB = newDefStmt->GetGeneratedByBB(); - if (!dom->Dominate(*genByBB, *newDefBB) && !ExistedPhiNode(*newDefBB, *rhs)) { - CreatePhi(*rhs, *newDefBB); + if (!dom->Dominate(*genByBB, *newDefBB)) { + if (!ExistedPhiNode(*newDefBB, *rhs)) { + CreatePhi(*rhs, *newDefBB); + } continue; } } @@ -236,7 +240,8 @@ void MeABC::InsertPhiNodes() { oldDefBB = meFunc->GetCommonEntryBB(); CHECK_FATAL(rhs->IsZeroVersion(irMap->GetSSATab()), "must be"); } - CHECK_FATAL(newDefBB != nullptr && oldDefBB != nullptr, "must be"); + CHECK_NULL_FATAL(newDefBB); + CHECK_NULL_FATAL(oldDefBB); MapleSet &dfs = dom->GetDomFrontier(newDefBB->GetBBId()); for (auto bbID : dfs) { BB *dfBB = meFunc->GetBBFromID(bbID); @@ -320,7 +325,8 @@ void MeABC::ReplacePiPhiInSuccs(BB &bb, VarMeExpr &newVar) { if (it1 != piList.end()) { std::vector &piStmts = it1->second; // the size of pi statements must be 1 or 2 - CHECK_FATAL(piStmts.size() >= 1 && piStmts.size() <= 2, "must be"); + CHECK_FATAL(!piStmts.empty(), "should not be empty"); + CHECK_FATAL(piStmts.size() <= 2, "must be"); PiassignMeStmt *pi1 = piStmts.at(0); if (pi1->GetLHS()->GetOStIdx() == newVar.GetOStIdx()) { pi1->SetRHS(newVar); @@ -565,7 +571,7 @@ void MeABC::ReplaceBB(BB &bb, BB &parentBB, DefPoint &newDefPoint) { void MeABC::RemoveExtraNodes() { for (DefPoint *defP : newDefPoints) { - defP->RemoveFromBB(); + defP->RemoveFromBB(); } for (auto pair : modifiedStmt) { MeStmt *meStmt = pair.first.first; @@ -1038,17 +1044,16 @@ bool MeABC::BuildAssignInGraph(MeStmt &meStmt) { (void)inequalityGraph->AddEdge(*lhsNode, *arrLength, 0, EdgeType::kLower); return true; } else if (rhs->GetPrimType() == PTY_ref) { - if ((rhs->GetMeOp() == kMeOpVar || rhs->GetMeOp() == kMeOpIvar) && (lhs->GetPrimType() == PTY_ref)) { - ESSAVarNode *ivarNode = inequalityGraph->GetOrCreateVarNode(*rhs); - ESSAArrayNode *arrayNode = inequalityGraph->GetOrCreateArrayNode(*lhs); - InequalEdge *pairEdge1 = inequalityGraph->AddEdge(*ivarNode, *arrayNode, 0, EdgeType::kUpper); - InequalEdge *pairEdge2 = inequalityGraph->AddEdge(*arrayNode, *ivarNode, 0, EdgeType::kUpper); - pairEdge1->SetPairEdge(*pairEdge2); - pairEdge2->SetPairEdge(*pairEdge1); - return true; - } else { + if ((rhs->GetMeOp() != kMeOpVar && rhs->GetMeOp() != kMeOpIvar) || (lhs->GetPrimType() != PTY_ref)) { return false; } + ESSAVarNode *ivarNode = inequalityGraph->GetOrCreateVarNode(*rhs); + ESSAArrayNode *arrayNode = inequalityGraph->GetOrCreateArrayNode(*lhs); + InequalEdge *pairEdge1 = inequalityGraph->AddEdge(*ivarNode, *arrayNode, 0, EdgeType::kUpper); + InequalEdge *pairEdge2 = inequalityGraph->AddEdge(*arrayNode, *ivarNode, 0, EdgeType::kUpper); + pairEdge1->SetPairEdge(*pairEdge2); + pairEdge2->SetPairEdge(*pairEdge1); + return true; } else { CHECK_FATAL(rhs->GetMeOp() == kMeOpVar || rhs->GetMeOp() == kMeOpConst, "must be"); ESSAVarNode *lhsNode = inequalityGraph->GetOrCreateVarNode(*lhs); @@ -1157,8 +1162,8 @@ void MeABC::AddUseDef(MeExpr &meExpr) { void MeABC::CollectCareInsns() { for (auto pair : arrayChecks) { MeStmt *meStmt = pair.first; - for (size_t iii = 0; iii < meStmt->NumMeStmtOpnds(); ++iii) { - ABCCollectArrayExpr(*meStmt, *(meStmt->GetOpnd(iii)), true); + for (size_t i = 0; i < meStmt->NumMeStmtOpnds(); ++i) { + ABCCollectArrayExpr(*meStmt, *(meStmt->GetOpnd(i)), true); } } CHECK_FATAL(arrayNewChecks.size() == arrayChecks.size(), "must be"); @@ -1179,29 +1184,30 @@ void MeABC::BuildInequalityGraph() { void MeABC::FindRedundantABC(MeStmt &meStmt, NaryMeExpr &naryMeExpr) { MeExpr *opnd1 = naryMeExpr.GetOpnd(0); MeExpr *opnd2 = naryMeExpr.GetOpnd(1); - CHECK_FATAL(opnd1->GetMeOp() == kMeOpVar && opnd1->GetPrimType() == PTY_ref, "must be"); + CHECK_FATAL(opnd1->GetMeOp() == kMeOpVar, "must be"); + CHECK_FATAL(opnd1->GetPrimType() == PTY_ref, "must be"); if (!inequalityGraph->HasNode(*opnd1)) { - if (MeABC::kDebug) { + if (MeABC::isDebug) { LogInfo::MapleLogger() << "Array Node Not Found" << '\n'; meStmt.Dump(irMap); } return; } if (opnd2->GetMeOp() == kMeOpVar && !inequalityGraph->HasNode(*opnd2)) { - if (MeABC::kDebug) { + if (MeABC::isDebug) { LogInfo::MapleLogger() << "Array Index Not Found" << '\n'; meStmt.Dump(irMap); } return; } if (prove->DemandProve(*opnd1, *opnd2)) { - if (MeABC::kDebug) { + if (MeABC::isDebug) { LogInfo::MapleLogger() << "Find One OPT" << '\n'; meStmt.Dump(irMap); } targetMeStmt.insert(&meStmt); } else { - if (MeABC::kDebug) { + if (MeABC::isDebug) { LogInfo::MapleLogger() << "Can not OPT" << '\n'; meStmt.Dump(irMap); } @@ -1222,7 +1228,7 @@ MeExpr *MeABC::ReplaceArrayExpr(MeExpr &rhs, MeExpr &naryMeExpr, MeStmt *ivarStm } CHECK_FATAL(rhs.GetMeOp() == kMeOpIvar, "must be"); MeExpr *newBase = ReplaceArrayExpr(*static_cast(rhs).GetBase(), naryMeExpr, ivarStmt); - CHECK_FATAL(newBase, "must be"); + CHECK_NULL_FATAL(newBase); MeExpr *newIvarExpr = nullptr; if (ivarStmt == nullptr) { auto *oldIvarExpr = static_cast(&rhs); @@ -1302,10 +1308,10 @@ void MeABC::InitNewStartPoint(MeStmt &meStmt, NaryMeExpr &nMeExpr) { CHECK_FATAL(forbidenPi->GetOp() == OP_piassign, "must be"); } -void MeABC::executeABCO() { - MeABC::kDebug = false; +void MeABC::ExecuteABCO() { + MeABC::isDebug = false; if (CollectABC()) { - if (MeABC::kDebug) { + if (MeABC::isDebug) { LogInfo::MapleLogger() << meFunc->GetName() << "\n"; irMap->Dump(); } @@ -1316,7 +1322,7 @@ void MeABC::executeABCO() { for (auto pair : arrayNewChecks) { InitNewStartPoint(*(pair.first), *(static_cast(pair.second))); BuildInequalityGraph(); - if (MeABC::kDebug) { + if (MeABC::isDebug) { meFunc->GetTheCfg()->DumpToFile(meFunc->GetName()); inequalityGraph->DumpDotFile(*irMap, DumpType::kDumpUpperAndNone); inequalityGraph->DumpDotFile(*irMap, DumpType::kDumpLowerAndNone); @@ -1341,7 +1347,7 @@ AnalysisResult *MeDoABCOpt::Run(MeFunction *func, MeFuncResultMgr *frm, ModuleRe CHECK_FATAL(irMap != nullptr, "irMap phase has problem"); MemPool *abcoMemPool = memPoolCtrler.NewMemPool(PhaseName()); MeABC meABC(*func, *dom, *irMap, *abcoMemPool); - meABC.executeABCO(); + meABC.ExecuteABCO(); if (DEBUGFUNC(func)) { LogInfo::MapleLogger() << "\n============== After boundary check optimization =============" << std::endl; irMap->Dump(); diff --git a/src/maple_me/src/me_analyze_rc.cpp b/src/maple_me/src/me_analyze_rc.cpp index 2dad12daf52b2da55df9861f69cbc06423c308a6..7406b2ef96599dee856d982d867c502ec6125c24 100644 --- a/src/maple_me/src/me_analyze_rc.cpp +++ b/src/maple_me/src/me_analyze_rc.cpp @@ -24,7 +24,7 @@ // first definition since entering the function, the decref will be omitted. // // B. At each statement that assigns a new value to a ref pointer, insert an -// incref after the assignment. In cases where the incref has already been +// incref after the assignment. In cases where the incref has already been // performed when the assigned value is computed, it will not insert the incref. // // C. A localrefvar need to be cleaned up before function exit. This clean-up @@ -46,7 +46,7 @@ // Under placementRC, the CLEANUP_LOCALREFVARS intrinsiccall will still be // inserted for the decrefs being inserted before the return statement. // -// When a formal parameters of ref type is ever assigned inside the function, +// When a formal parameter of ref type is ever assigned inside the function, // an incref for it needs to be inserted at function entry. This is done // by the placementRC phase. For such formal parameters, placementRC phase will // also insert decref's to clean them up after their last use. diff --git a/src/maple_me/src/me_bypath_eh.cpp b/src/maple_me/src/me_bypath_eh.cpp index 16d9330465466f6a51e6c27a9bc5ecd45058ba43..24efe1c31edf8e41049d692594b0d7c1f57d30ba 100644 --- a/src/maple_me/src/me_bypath_eh.cpp +++ b/src/maple_me/src/me_bypath_eh.cpp @@ -30,9 +30,9 @@ bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, const Klass *catchC bool transformed = false; while (idx < tryBBV.size()) { BB *bb = tryBBV[idx]; - idx++; + ++idx; // Deal with throw - for (StmtNode *stmt = &bb->GetFirst(); stmt && stmt != bb->GetLast().GetNext(); stmt = stmt->GetNext()) { + for (StmtNode *stmt = &bb->GetFirst(); stmt != nullptr && stmt != bb->GetLast().GetNext(); stmt = stmt->GetNext()) { if (stmt->GetOpCode() == OP_throw) { auto *node = static_cast(stmt); BaseNode *rhExpr = nullptr; @@ -64,12 +64,12 @@ bool MeDoBypathEH::DoBypathException(BB *tryBB, BB *catchBB, const Klass *catchC if (!kh->IsSuperKlass(catchClass, throwClass)) { continue; } - MIRBuilder *mBuilder = func->GetMIRModule().GetMIRBuilder(); - DassignNode *copyStmt = mBuilder->CreateStmtDassign(stIdx, 0, rhExpr); + MIRBuilder *mirBuilder = func->GetMIRModule().GetMIRBuilder(); + DassignNode *copyStmt = mirBuilder->CreateStmtDassign(stIdx, 0, rhExpr); bb->InsertStmtBefore(stmt, copyStmt); - GotoNode *gotoNode = mBuilder->CreateStmtGoto(OP_goto, catchBB->GetBBLabel()); + GotoNode *gotoNode = mirBuilder->CreateStmtGoto(OP_goto, catchBB->GetBBLabel()); bb->ReplaceStmt(stmt, gotoNode); - if (syncExitStmt) { + if (syncExitStmt != nullptr) { bb->InsertStmtBefore(gotoNode, syncExitStmt->CloneTree(func->GetMIRModule().GetCurFuncCodeMPAllocator())); } transformed = true; diff --git a/src/maple_me/src/me_cond_based_opt.cpp b/src/maple_me/src/me_cond_based_opt.cpp index d059b217d79efaae41afd616a38fd3637d898824..1c6ad7dd77721976e0a13298282ed30f002f1bb2 100644 --- a/src/maple_me/src/me_cond_based_opt.cpp +++ b/src/maple_me/src/me_cond_based_opt.cpp @@ -260,15 +260,15 @@ AnalysisResult *MeDoCondBasedRC::Run(MeFunction *func, MeFuncResultMgr *m, Modul continue; } MeStmt *refAssign = stmt.GetNext(); - if (condBasedRC.NullValueFromTestCond(*varMeExpr, *bb, true)) { - bb->RemoveMeStmt(&stmt); // delete the decref - if (refAssign != nullptr) { - refAssign->DisableNeedDecref(); - } else { - break; - } - stmt = *refAssign; // next iteration will process the stmt after refassign + if (!condBasedRC.NullValueFromTestCond(*varMeExpr, *bb, true)) { + continue; + } + bb->RemoveMeStmt(&stmt); // delete the decref + if (refAssign == nullptr) { + break; } + refAssign->DisableNeedDecref(); + stmt = *refAssign; // next iteration will process the stmt after refassign } } return nullptr; diff --git a/src/maple_me/src/me_delegate_rc.cpp b/src/maple_me/src/me_delegate_rc.cpp index 231e097a6aced4ebb77065ae5d088eb144eb5a2c..442c0e7be30c673364f676c2c23b750e1787d04d 100644 --- a/src/maple_me/src/me_delegate_rc.cpp +++ b/src/maple_me/src/me_delegate_rc.cpp @@ -15,6 +15,7 @@ #include "me_delegate_rc.h" #include "mir_builder.h" #include "me_hdse.h" + // This phase finds local ref pointer variables that are delegated and thus can // have their RC omitted. This optimization is done on a per-SSA version basis. // As a result, an overall criterion is that the SSA version must not have @@ -47,8 +48,7 @@ // B2: The RHS of its definition is iread of a final field with this as base or // dread of a static final field. // B3: Within the SSA version's live range, there is no operation that can result -// in decref of any object. (TODO) - +// in decref of any object. namespace { // following intrinsics can throw exception const std::set canThrowIntrinsicsList { @@ -259,7 +259,7 @@ bool DelegateRC::MayThrowException(MeStmt &stmt) { // Traverse backwards from fromstmt to tostmt to see if the single use of rhsvar // in fromstmt is the last use of rhsvar; tostmt is the statement that defines // rhsvar, so it can be assumed that tostmt does not contain any use; this check -// make use of verStUseCounts in its determination. In addition, if it comes +// make use of verStUseCounts in its determination. In addition, if it comes // across any stmt that can raise exception, also return false. bool DelegateRC::ContainAllTheUses(VarMeExpr *rhsVar, const MeStmt &fromStmt, const MeStmt *toStmt) { int32 remainingUses = static_cast(verStUseCounts[rhsVar->GetVstIdx()]) - 1; @@ -468,7 +468,8 @@ void DelegateRC::DelegateRCTemp(MeStmt &stmt) { } break; } - default:; + default: + break; } } @@ -666,7 +667,7 @@ void DelegateRC::SetCantDelegateAndCountUses() { continue; } for (size_t i = 0; i < stmt.NumMeStmtOpnds(); i++) { - CHECK_FATAL(stmt.GetOpnd(i), "null mestmtopnd check"); + CHECK_FATAL(stmt.GetOpnd(i) != nullptr, "null mestmtopnd check"); CollectUsesInfo(*stmt.GetOpnd(i)); } CollectDerefedOrCopied(stmt); @@ -703,7 +704,7 @@ std::set DelegateRC::RenameAndGetLiveLocalRefVar() { continue; } for (size_t i = 0; i < stmt.NumMeStmtOpnds(); ++i) { - CHECK_FATAL(stmt.GetOpnd(i), "null mestmtopnd check"); + CHECK_FATAL(stmt.GetOpnd(i) != nullptr, "null mestmtopnd check"); RenameDelegatedRefVarUses(stmt, stmt.GetOpnd(i)); } // for live_localrefvars diff --git a/src/maple_me/src/me_dse.cpp b/src/maple_me/src/me_dse.cpp index edbe45fd15b92937f8ec924fba1c7b426ed3bcb6..7073089e17567793659d239e739ced6231700d66 100644 --- a/src/maple_me/src/me_dse.cpp +++ b/src/maple_me/src/me_dse.cpp @@ -18,6 +18,7 @@ #include "ver_symbol.h" #include "me_ssa.h" #include "me_cfg.h" + namespace maple { void MeDSE::VerifyPhi() const { auto eIt = func.valid_end(); @@ -37,7 +38,7 @@ void MeDSE::VerifyPhi() const { CHECK_FATAL(!ost->IsSymbolOst() || ost->GetIndirectLev() != 0, "phi is live and non-virtual in bb with zero or one pred"); } else if (pair.second.GetPhiOpnds().size() != predBBNums) { - ASSERT(0, "TODO: phi opnd num is not consistent with pred bb num(need update phi)"); + ASSERT(false, "phi opnd num is not consistent with pred bb num(need update phi)"); } } } diff --git a/src/maple_me/src/me_hdse.cpp b/src/maple_me/src/me_hdse.cpp index 623b1a95416b14798caf1c36cc5259664bb7ea07..b14c3c7cd6a28e44d9ea89f98b0cbb5f25221693 100644 --- a/src/maple_me/src/me_hdse.cpp +++ b/src/maple_me/src/me_hdse.cpp @@ -20,6 +20,7 @@ #include "me_irmap.h" #include "me_ssa.h" #include "hdse.h" + namespace maple { void MeDoHDSE::MakeEmptyTrysUnreachable(MeFunction &func) { auto eIt = func.valid_end(); diff --git a/src/maple_me/src/me_inequality_graph.cpp b/src/maple_me/src/me_inequality_graph.cpp index 26953f67f3e56e3499d462b23547a45351be1094..a230ce2fc1dde700ed6e5117182ae2e14e9f8f41 100644 --- a/src/maple_me/src/me_inequality_graph.cpp +++ b/src/maple_me/src/me_inequality_graph.cpp @@ -357,7 +357,7 @@ namespace maple { tracing.push_back(&bNode); if (&aNode == &bNode) { - if (edge.geq(0)) { + if (edge.GreaterEqual(0)) { tracing.pop_back(); return kTrue; } else { @@ -382,7 +382,7 @@ namespace maple { } if (active.find(&bNode) != active.end()) { - if (active.find(&bNode)->second->leq(edge)) { + if (active.find(&bNode)->second->LessEqual(edge)) { tracing.pop_back(); return kReduced; } else { diff --git a/src/maple_me/src/prop.cpp b/src/maple_me/src/prop.cpp index c76228b3cb5e4d392377110d722b15f8d8f76342..0860d0ab6b2d5cd140779979b93febf04b1560f3 100644 --- a/src/maple_me/src/prop.cpp +++ b/src/maple_me/src/prop.cpp @@ -215,7 +215,7 @@ void Prop::CollectSubVarMeExpr(const MeExpr &meExpr, std::vector // check at the current statement, if the version symbol is consistent with its definition in the top of the stack // for example: -// x1 = a1 + b1; +// x1 <- a1 + b1; // a2 <- // <-x1 // the version of progation of x1 is a1, but the top of the stack of symbol a is a2, so it's not consistent diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp index 224a82a58d66a0869be4ff6b58ee4ae8ea66b597..a6f957acd29d6fee3785fd026fe367052d0b385e 100644 --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -19,11 +19,8 @@ // analysis costs a lot. // // For now, we only use a simple policy to help devirtualize, E.g. -// { -// Base b = new Derived(); -// b.foo(); -// } -// We can devirtual the b.foo to be Derived::foo(). +// Base b is defined as new Derived(), and b.foo() denotes b invokes method foo(). +// We can devirtual the b.foo() to be Derived::foo(). namespace maple { bool SSADevirtual::debug = false; diff --git a/src/maple_util/include/mpl_logging.h b/src/maple_util/include/mpl_logging.h index 25519e41c00fc7baca4108a58d5a767d941c0ba0..736aea7393f72a8b2be5743e0415c746f5d78042 100644 --- a/src/maple_util/include/mpl_logging.h +++ b/src/maple_util/include/mpl_logging.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. @@ -87,28 +87,19 @@ // Since INFO, WARN, ERR and FATAL are for general consumption, each message // should provide an number code under enum LogNumberCode. // -// Following are usage examples for the 10 types of logging actions supported: +// Following are usage of logging actions supported: // -// GDB(LT_MPLME, "symbol %s SSA version %d made required during DSE", -// vers->origsym->name, vers->id); +// GDB,LOG,INFO,WARN,ERR,FATAL can be invoked as method. +// parameters: +// TAG +// formatted string +// variadic list // -// LOG(LT_MPLME, "deleting BB %d because it is unreachable", bb->id_.GetIdx()); -// -// INFO(kLncInfo, "function %s inlined into %s", callee->name, caller->name); -// -// WARN(kLncWarn, "variable %s defined but never used", sym->name); -// -// ERR(kLncErr, "syntax error at file %s line %d", filename, lineno); -// -// FATAL(kLncFatal, "segmentation error"); -// -// CHECK(tyidx < type_table.size(), "%d is not a valid type index", tyidx); -// -// DCHECK(tyidx < type_table.size(), "%d is not a valid type index", tyidx); -// -// CHECK_FATAL(tyidx < type_table.size(), "%d is not a valid type index", tyidx); -// -// ASSERT(tyidx < type_table.size(), "%d is not a valid type index", tyidx); +// CHECK,DCHECK,CHECK_FATAL,ASSERT also can be invoked as method. +// parameters: +// condition +// formatted string +// variadic list // // Each of the above are mapped to one of the following 3 methods in class LogInfo: // diff --git a/src/maple_util/include/utils/ref_vector.h b/src/maple_util/include/utils/ref_vector.h index dac2b00e709078e354701a2b7c556338b588040d..4a1e5da2b6de94225f4adba4017f56601395c0fa 100644 --- a/src/maple_util/include/utils/ref_vector.h +++ b/src/maple_util/include/utils/ref_vector.h @@ -24,29 +24,6 @@ // to check nullptr, it will make the code more confusion and hard to maintain. // Based on that, the ref_vector picks up the meaning of keeping objects' reference, it won't destory any of its // elements or require to check null(Never to be nullptr). -// -// etc. -// `std::vector` -// ``` -// int a = 0, b = 1; -// -// std::vector data; -// data.push_back(&a); -// data.push_back(&b); -// ASSERT_EQ(*data[0], 0); -// ASSERT_EQ(*data[1], 1); -// ``` -// -// `utils::ref_vector` -// ``` -// int a = 0, b = 1; -// -// ref_vector data; -// data.push_back(a); -// data.push_back(b); -// ASSERT_EQ(data[0], 0); -// ASSERT_EQ(data[1], 1); -// ``` namespace maple { namespace utils { class ref_vector_tag; diff --git a/src/mpl2mpl/src/constantfold.cpp b/src/mpl2mpl/src/constantfold.cpp index 682e3b9c32f420c41bbbb3f1695dafdfd0ad134d..b03dda04a148f57428f3d84be83742b6929eb2ca 100644 --- a/src/mpl2mpl/src/constantfold.cpp +++ b/src/mpl2mpl/src/constantfold.cpp @@ -1661,7 +1661,7 @@ std::pair ConstantFold::FoldTernary(TernaryNode *node) { BaseNode *tmpNode = node->Opnd(0); if (node->GetPrimType() != PTY_u1) { tmpNode = mirModule->CurFuncCodeMemPool()->New(OP_cvt, PrimType(node->GetPrimType()), - PTY_u1, node->Opnd(0)); + PTY_u1, node->Opnd(0)); } std::pair pairTemp = DispatchFold(tmpNode); result = PairToExpr(node->GetPrimType(), pairTemp); @@ -1747,8 +1747,8 @@ StmtNode *ConstantFold::SimplifyCondGoto(CondGotoNode *node) { return node; } MIRIntConst *intConst = safe_cast(cst->GetConstVal()); - if ((OP_brtrue == node->GetOpCode() && intConst->GetValueUnderType() != 0) || - (OP_brfalse == node->GetOpCode() && intConst->GetValueUnderType() == 0)) { + if ((node->GetOpCode() == OP_brtrue && intConst->GetValueUnderType() != 0) || + (node->GetOpCode() == OP_brfalse && intConst->GetValueUnderType() == 0)) { GotoNode *gotoNode = mirModule->CurFuncCodeMemPool()->New(OP_goto); gotoNode->SetOffset(node->GetOffset()); return gotoNode; @@ -1894,7 +1894,7 @@ StmtNode *ConstantFold::SimplifyIf(IfStmtNode *node) { return node; } MIRIntConst *intConst = safe_cast(cst->GetConstVal()); - if (0 == intConst->GetValue()) { + if (intConst->GetValue() == 0) { return node->GetElsePart(); } else { return node->GetThenPart();