diff --git a/src/mapleall/maple_be/include/cg/operand.h b/src/mapleall/maple_be/include/cg/operand.h index 6061cb40153b1f355231f3f126f1f9f1125f87dd..7b9d68bea7402dac52556a7a01cb5824d931100e 100644 --- a/src/mapleall/maple_be/include/cg/operand.h +++ b/src/mapleall/maple_be/include/cg/operand.h @@ -730,28 +730,13 @@ class ListOperand : public OperandVisitable { opndList(allocator.Adapter()) {} ~ListOperand() override = default; - using OperandVisitable::OperandVisitable; - - void PopOpnd() { - opndList.pop_back(); - } - void PopFrontOpnd() { - opndList.pop_front(); - } + using OperandVisitable::OperandVisitable; void PushOpnd(RegOperand &opnd) { opndList.push_back(&opnd); } - void PushFront(RegOperand &opnd) { - opndList.push_front(&opnd); - } - - void RemoveOpnd(RegOperand &opnd) { - opndList.remove(&opnd); - } - MapleList &GetOperands() { return opndList; } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 07a8168ec5fdfee881710cdb3b200faeb24dc363..989cf73c8397e31d8f22c656b63550a0aea68c5b 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -5476,12 +5476,19 @@ void AArch64CGFunc::ReplaceOpndInInsn(RegOperand ®Dest, RegOperand ®Src, I Operand &opnd = insn.GetOperand(i); if (opnd.IsList()) { std::list tempRegStore; - for (auto regOpnd : static_cast(opnd).GetOperands()) { + auto& opndList = static_cast(opnd).GetOperands(); + + for (auto it = opndList.begin(), end = opndList.end(); it != end;) { + auto *regOpnd = *it; + if (regOpnd->Equals(regDest)) { tempRegStore.push_back(®Src); - static_cast(opnd).RemoveOpnd(*regOpnd); + it = opndList.erase(it); + } else { + ++it; } } + for (auto newOpnd : tempRegStore) { static_cast(opnd).PushOpnd(*newOpnd); } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_phi_elimination.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_phi_elimination.cpp index d3c243032f22bfb26ca37d3cb100a6ea41deb2e8..b49a95a8e2040ca0965f7bb855d66dd8601f71ad 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_phi_elimination.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_phi_elimination.cpp @@ -170,14 +170,19 @@ void A64OperandPhiElmVisitor::Visit(RegOperand *v) { void A64OperandPhiElmVisitor::Visit(ListOperand *v) { std::list tempRegStore; - for (auto *regOpnd : v->GetOperands()) { + auto& opndList = v->GetOperands(); + + while (!opndList.empty()) { + auto *regOpnd = opndList.front(); + opndList.pop_front(); + if (regOpnd->IsSSAForm()) { tempRegStore.push_back(&a64PhiEliminator->GetCGVirtualOpearnd(*regOpnd, *insn)); } else { tempRegStore.push_back(regOpnd); } - v->RemoveOpnd(*regOpnd); } + ASSERT(v->GetOperands().empty(), "need to clean list"); v->GetOperands().assign(tempRegStore.begin(), tempRegStore.end()); } diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp index 803a172caa69c06b0335433ee1314c78a7c3f189..562d72ddc01e82d6a3c10e91dc087e5716e67efe 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_ssa.cpp @@ -167,14 +167,19 @@ void A64SSAOperandRenameVisitor::Visit(ListOperand *v) { bool isAsm = insn->GetMachineOpcode() == MOP_asm; /* record the orignal list order */ std::list tempList; - for (auto *op : a64ListOpnd->GetOperands()) { + auto& opndList = a64ListOpnd->GetOperands(); + + while (!opndList.empty()) { + auto* op = opndList.front(); + opndList.pop_front(); + if (op->IsSSAForm() || !op->IsVirtualRegister()) { - a64ListOpnd->RemoveOpnd(*op); tempList.push_back(op); continue; } - a64ListOpnd->RemoveOpnd(*op); - bool isDef = isAsm ? idx == kAsmClobberListOpnd || idx == kAsmOutputListOpnd : false; + + bool isDef = + isAsm && (idx == kAsmClobberListOpnd || idx == kAsmOutputListOpnd); RegOperand *renameOpnd = ssaInfo->GetRenamedOperand(*op, isDef, *insn, idx); tempList.push_back(renameOpnd); } diff --git a/src/mapleall/maple_ipa/include/prop_parameter_type.h b/src/mapleall/maple_ipa/include/prop_parameter_type.h index 5abcac7b9bbefa235c57e8504503e64f09e904eb..5cc9be1a0f52f32f96629ea5d5a6a9bef03ada60 100644 --- a/src/mapleall/maple_ipa/include/prop_parameter_type.h +++ b/src/mapleall/maple_ipa/include/prop_parameter_type.h @@ -36,7 +36,7 @@ class PropParamType { virtual ~PropParamType() = default; bool CheckOpndZero(MeExpr *expr); void ResolveCallStmt(MeStmt &meStmt); - void InsertNullCheck(const CallMeStmt &callStmt, const std::string &funcName, uint32 index, MeExpr &receiver); + void InsertNullCheck(CallMeStmt &callStmt, const std::string &funcName, uint32 index, MeExpr &receiver); bool CheckCondtionStmt(const MeStmt &meStmt); void ResolveIreadExpr(MeExpr &expr); void TraversalMeStmt(MeStmt &meStmt); diff --git a/src/mapleall/maple_ipa/src/prop_parameter_type.cpp b/src/mapleall/maple_ipa/src/prop_parameter_type.cpp index e999e0c76d44294c2cd439a2048a00e21c9d5372..c126466ec8a36bf553cd24d6cc4e63ba4cdcba06 100644 --- a/src/mapleall/maple_ipa/src/prop_parameter_type.cpp +++ b/src/mapleall/maple_ipa/src/prop_parameter_type.cpp @@ -68,7 +68,7 @@ void PropParamType::ResolveIreadExpr(MeExpr &expr) { } } -void PropParamType::InsertNullCheck(const CallMeStmt &callStmt, const std::string &funcName, +void PropParamType::InsertNullCheck(CallMeStmt &callStmt, const std::string &funcName, uint32 index, MeExpr &receiver) { auto *irMap = curFunc->GetMeFunc()->GetIRMap(); GStrIdx stridx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(funcName); diff --git a/src/mapleall/maple_me/include/bb.h b/src/mapleall/maple_me/include/bb.h index d12b44b74d5d31e2462dad202028482082865968..a07f4ecef6ee41273d34932df138e43ed538c761 100644 --- a/src/mapleall/maple_me/include/bb.h +++ b/src/mapleall/maple_me/include/bb.h @@ -225,7 +225,9 @@ class BB { void SetFirstMe(MeStmt *stmt); void SetLastMe(MeStmt *stmt); MeStmt *GetLastMe(); + const MeStmt *GetLastMe() const; MeStmt *GetFirstMe(); + const MeStmt *GetFirstMe() const; bool IsPredBB(const BB &bb) const { // if this is a pred of bb return true; // otherwise return false; @@ -299,13 +301,13 @@ class BB { const PhiNode *PhiofVerStInserted(const VersionSt &versionSt) const; void InsertPhi(MapleAllocator *alloc, VersionSt *versionSt); void PrependMeStmt(MeStmt *meStmt); - void RemoveMeStmt(const MeStmt *meStmt); + void RemoveMeStmt(MeStmt *meStmt); void AddMeStmtFirst(MeStmt *meStmt); void AddMeStmtLast(MeStmt *meStmt); void InsertMeStmtBefore(const MeStmt *meStmt, MeStmt *inStmt); void InsertMeStmtAfter(const MeStmt *meStmt, MeStmt *inStmt); void InsertMeStmtLastBr(MeStmt *inStmt); - void ReplaceMeStmt(const MeStmt *stmt, MeStmt *newStmt); + void ReplaceMeStmt(MeStmt *stmt, MeStmt *newStmt); void RemoveLastMeStmt(); void DumpMePhiList(const IRMap *irMap); void DumpMeVarPiList(const IRMap *irMap); diff --git a/src/mapleall/maple_me/include/irmap.h b/src/mapleall/maple_me/include/irmap.h index 11b4e7228d0554413d5474af17949dd8580f45e5..2c91597b0fba8cab9952195b38a9dd5d869beb03 100644 --- a/src/mapleall/maple_me/include/irmap.h +++ b/src/mapleall/maple_me/include/irmap.h @@ -266,7 +266,7 @@ class IRMap : public AnalysisResult { bool ReplaceMeExprStmtOpnd(uint32, MeStmt&, const MeExpr&, MeExpr&); void PutToBucket(uint32, MeExpr&); - BB *GetFalseBrBB(const CondGotoMeStmt&); + const BB *GetFalseBrBB(const CondGotoMeStmt&); MeExpr *ReplaceMeExprExpr(MeExpr &origExpr, MeExpr &newExpr, size_t opndsSize, const MeExpr &meExpr, MeExpr &repExpr); MeExpr *SimplifyCompareSameExpr(OpMeExpr *opmeexpr); bool IfMeExprIsU1Type(const MeExpr *expr) const; diff --git a/src/mapleall/maple_me/include/me_cfg_opt.h b/src/mapleall/maple_me/include/me_cfg_opt.h index a322c49986fbfed3e639627ae6d59dea7f12773a..72fe8aa1f668a72d8b0ac26ed50f99859ed9614c 100644 --- a/src/mapleall/maple_me/include/me_cfg_opt.h +++ b/src/mapleall/maple_me/include/me_cfg_opt.h @@ -48,7 +48,7 @@ class MeCfgOpt { } bool HasFloatCmp(const MeExpr &meExpr) const; - const MeStmt *GetCondBrStmtFromBB(const BB &bb) const; + MeStmt *GetCondBrStmtFromBB(BB &bb) const; MeStmt *GetTheOnlyMeStmtFromBB(BB &bb) const; MeStmt *GetTheOnlyMeStmtWithGotoFromBB(BB &bb) const; MeIRMap *meIrMap; diff --git a/src/mapleall/maple_me/include/me_gc_lowering.h b/src/mapleall/maple_me/include/me_gc_lowering.h index 32faa6214f74c59c6ac60dc3ef52b879dbcef86e..4d110e2e3df60a76e6e3362956f69465beae924f 100644 --- a/src/mapleall/maple_me/include/me_gc_lowering.h +++ b/src/mapleall/maple_me/include/me_gc_lowering.h @@ -45,7 +45,7 @@ class GCLowering { MeExpr *GetBase(IvarMeExpr &ivar); MIRIntrinsicID SelectWriteBarrier(MeStmt&); MIRIntrinsicID PrepareVolatileCall(const MeStmt&, MIRIntrinsicID); - void HandleWriteReferent(const IassignMeStmt&); + void HandleWriteReferent(IassignMeStmt&); void CheckRefs(); void ParseCheckFlag(); void CheckFormals(); diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index 4ba9790bff534be1abcc6ccd58bfb61b8ef04cf4..a9e62336b21c9b48d8a32382efe0ed650f06a631 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -1362,9 +1362,8 @@ class MeStmt { prev = node; } - BB *GetBB() const { - return bb; - } + const BB *GetBB() const { return bb; } + BB *GetBB() { return bb; } void SetBB(BB *curBB) { bb = curBB; diff --git a/src/mapleall/maple_me/include/me_placement_rc.h b/src/mapleall/maple_me/include/me_placement_rc.h index 2c2d719a1b185c70a64bdf934a37c59aefdfb89a..18c93f0177151433e15ec5676171491044f4e891 100644 --- a/src/mapleall/maple_me/include/me_placement_rc.h +++ b/src/mapleall/maple_me/include/me_placement_rc.h @@ -47,13 +47,13 @@ class PlacementRC : public MeSSUPre { void ResetHasReal(); void UpdateHasRealWithRealOccs(const MapleVector &realOccs); void SetFormalParamsAttr(MIRFunction &mirFunc) const; - void DeleteEntryIncref(SRealOcc &realOcc, const UnaryMeStmt *entryIncref) const; + void DeleteEntryIncref(SRealOcc &realOcc, UnaryMeStmt *entryIncref) const; void UpdateCatchBlocks2Insert(const BB &lastUseBB); void ReplaceOpndWithReg(MeExpr &opnd, BB &lastUseBB, const SRealOcc &realOcc, uint32 idx) const; void HandleCanInsertAfterStmt(const SRealOcc &realOcc, UnaryMeStmt &decrefStmt, BB &lastUseBB); void HandleCannotInsertAfterStmt(const SRealOcc &realOcc, UnaryMeStmt &decrefStmt, BB &lastUseBB); void CodeMotionForSLambdares(SLambdaResOcc &lambdaResOcc); - void CodeMotionForReal(SOcc &occ, const UnaryMeStmt *entryIncref); + void CodeMotionForReal(SOcc &occ, UnaryMeStmt *entryIncref); void SetNeedIncref(MeStmt &stmt) const; void ReplaceRHSWithPregForDassign(MeStmt &stmt, BB &bb) const; bool DoesDassignInsertedForCallAssigned(MeStmt &stmt, BB &bb) const; diff --git a/src/mapleall/maple_me/include/me_rc_lowering.h b/src/mapleall/maple_me/include/me_rc_lowering.h index 27ea2014935f23dc5af8ad331dc9d652d5d4b265..eea13f525b3a524d82f4e35bf47c577c006b4335 100644 --- a/src/mapleall/maple_me/include/me_rc_lowering.h +++ b/src/mapleall/maple_me/include/me_rc_lowering.h @@ -60,10 +60,10 @@ class RCLowering { void CreateCleanupIntrinsics(); void HandleArguments(); void CompactRC(BB &bb); - void CompactIncAndDec(const MeStmt &incStmt, const MeStmt &decStmt); - void CompactIncAndDecReset(const MeStmt &incStmt, const MeStmt &resetStmt); - void ReplaceDecResetWithDec(MeStmt &prevStmt, const MeStmt &stmt); - void CompactAdjacentDecReset(const MeStmt &prevStmt, const MeStmt &stmt); + void CompactIncAndDec(MeStmt &incStmt, MeStmt &decStmt); + void CompactIncAndDecReset(MeStmt &incStmt, MeStmt &resetStmt); + void ReplaceDecResetWithDec(MeStmt &prevStmt, MeStmt &stmt); + void CompactAdjacentDecReset(MeStmt &prevStmt, MeStmt &stmt); // create new symbol from name and return its ost OriginalSt *RetrieveOSt(const std::string &name, bool isLocalrefvar) const; // create new symbol from temp name and return its VarMeExpr @@ -77,14 +77,14 @@ class RCLowering { MIRIntrinsicID PrepareVolatileCall(const MeStmt &stmt, MIRIntrinsicID index = INTRN_UNDEFINED); IntrinsiccallMeStmt *CreateRCIntrinsic(MIRIntrinsicID intrnID, const MeStmt &stmt, std::vector &opnds, bool assigned = false); - MeExpr *HandleIncRefAndDecRefStmt(const MeStmt &stmt); + MeExpr *HandleIncRefAndDecRefStmt(MeStmt &stmt); void InitializedObjectFields(MeStmt &stmt); bool IsInitialized(IvarMeExpr &ivar); void PreprocessAssignMeStmt(MeStmt &stmt); void HandleAssignMeStmtRHS(MeStmt &stmt); - void HandleAssignMeStmtRegLHS(const MeStmt &stmt); - void HandleAssignToGlobalVar(const MeStmt &stmt); - void HandleAssignToLocalVar(const MeStmt &stmt, MeExpr *pendingDec); + void HandleAssignMeStmtRegLHS(MeStmt &stmt); + void HandleAssignToGlobalVar(MeStmt &stmt); + void HandleAssignToLocalVar(MeStmt &stmt, MeExpr *pendingDec); void HandleAssignMeStmtVarLHS(MeStmt &stmt, MeExpr *pendingDec); void HandleAssignMeStmtIvarLHS(MeStmt &stmt); void HandleCallAssignedMeStmt(MeStmt &stmt, MeExpr *pendingDec); @@ -92,7 +92,7 @@ class RCLowering { void HandleRetOfCallAssignedMeStmt(MeStmt &stmt, MeExpr &pendingDec); void HandleReturnVar(RetMeStmt &ret); void HandleReturnGlobal(RetMeStmt &ret); - void HandleReturnRegread(const RetMeStmt &ret); + void HandleReturnRegread(RetMeStmt &ret); void HandleReturnFormal(RetMeStmt &ret); void HandleReturnIvar(RetMeStmt &ret); void HandleReturnReg(RetMeStmt &ret); @@ -104,12 +104,12 @@ class RCLowering { bool HasCallOrBranch(const MeStmt &from, const MeStmt &to); MIRIntrinsicID SelectWriteBarrier(const MeStmt &stmt); MIRType *GetArrayNodeType(const VarMeExpr &var); - void CheckArrayStore(const IntrinsiccallMeStmt &writeRefCall); + void CheckArrayStore(IntrinsiccallMeStmt &writeRefCall); void FastLowerThrowStmt(MeStmt &stmt, MapleMap &exceptionAllocsites); void FastLowerRetStmt(MeStmt &stmt); void FastLowerRetVar(RetMeStmt &stmt); void FastLowerRetIvar(RetMeStmt &stmt); - void FastLowerRetReg(const RetMeStmt &stmt); + void FastLowerRetReg(RetMeStmt &stmt); void FastLowerAssignToVar(MeStmt &stmt, MapleMap &exceptionAllocsites); void FastLowerAssignToIvar(MeStmt &stmt); void FastLowerCallAssignedStmt(MeStmt &stmt); diff --git a/src/mapleall/maple_me/include/meexpr_use_info.h b/src/mapleall/maple_me/include/meexpr_use_info.h index e5fe651db9a6bba1b6d46db9e0cc7c0048637bea..e85ef14292ec561fd66a7114da8728b1a2d070c3 100644 --- a/src/mapleall/maple_me/include/meexpr_use_info.h +++ b/src/mapleall/maple_me/include/meexpr_use_info.h @@ -18,65 +18,56 @@ #include "me_ir.h" #include "me_function.h" +#include + namespace maple { -enum UseType { - kUseByStmt, - kUseByPhi, -}; class UseItem final { - public: - explicit UseItem(MeStmt *useStmt) : useType(kUseByStmt) { - useNode.stmt = useStmt; - } - - explicit UseItem(MePhiNode *phi) : useType(kUseByPhi) { - useNode.phi = phi; - } - ~UseItem() = default; - - BB *GetUseBB() const { - if (useType == kUseByStmt) { - return useNode.stmt->GetBB(); - } - ASSERT(useType == kUseByPhi, "must used in phi"); - return useNode.phi->GetDefBB(); +public: + explicit UseItem(MeStmt *useStmt) : useNode(useStmt) {} + explicit UseItem(MePhiNode *phi) : useNode(phi) {} + + const BB *GetUseBB() const { + return std::visit( + [this](auto &&arg) { + using T = std::decay_t; + if constexpr (std::is_same_v) { + return Get()->GetBB(); + } else { + return Get()->GetDefBB(); + } + }, + useNode); } bool IsUseByPhi() const { - return useType == kUseByPhi; + return std::holds_alternative(useNode); } - bool IsUseByStmt() const { - return useType == kUseByStmt; - } + bool IsUseByStmt() const { return std::holds_alternative(useNode); } - MeStmt *GetStmt() const { - return useNode.stmt; - } + const MeStmt *GetStmt() const { return Get(); } + MeStmt *GetStmt() { return Get(); } - MePhiNode *GetPhi() const { - return useNode.phi; - } + const MePhiNode *GetPhi() const { return Get(); } + MePhiNode *GetPhi() { return Get(); } - bool SameUseItem(const MeStmt *stmt) const { - return stmt == useNode.stmt; + bool operator==(const UseItem &other) const { + return useNode == other.useNode; } + bool operator!=(const UseItem &other) const { return !(*this == other); } - bool SameUseItem(const MePhiNode *phi) const { - return phi == useNode.phi; +private: + template const T *Get() const { + assert(std::holds_alternative(useNode) && "Invalid use type."); + return std::get(useNode); } - - bool operator==(const UseItem &other) const { - return useType == other.useType && useNode.stmt == other.useNode.stmt; + template T *Get() { + assert(std::holds_alternative(useNode) && "Invalid use type."); + return std::get(useNode); } - private: - UseType useType; - union UseSite { - MeStmt *stmt; - MePhiNode *phi; - } useNode; + std::variant useNode; }; enum MeExprUseInfoState { @@ -103,8 +94,6 @@ class MeExprUseInfo final { template void AddUseSiteOfExpr(MeExpr *expr, T *useSite); - template - void RemoveUseSiteOfExpr(const MeExpr *expr, T *useSite); void CollectUseInfoInExpr(MeExpr *expr, MeStmt *stmt); void CollectUseInfoInStmt(MeStmt *stmt); diff --git a/src/mapleall/maple_me/include/ssa_devirtual.h b/src/mapleall/maple_me/include/ssa_devirtual.h index 96f8c3553865465e0dddfff698a27c509cc2b2e8..6161895e56d22d3b092c5f097d2e7eafcd594a2f 100644 --- a/src/mapleall/maple_me/include/ssa_devirtual.h +++ b/src/mapleall/maple_me/include/ssa_devirtual.h @@ -69,7 +69,7 @@ class SSADevirtual { void PropIvarInferredType(IvarMeExpr&) const; void ReturnTyIdxInferring(const RetMeStmt&); bool NeedNullCheck(const MeExpr&) const; - void InsertNullCheck(const CallMeStmt&, MeExpr&) const; + void InsertNullCheck(CallMeStmt&, MeExpr&) const; bool DevirtualizeCall(CallMeStmt&); void SSADevirtualize(CallNode &stmt); void ReplaceCall(CallMeStmt&, const MIRFunction&); diff --git a/src/mapleall/maple_me/src/bb.cpp b/src/mapleall/maple_me/src/bb.cpp index ce7b788508fef3248cd89f34f92b7a9a61ecf97b..6e2442fd8837e4542b9d247ed9ea7f07dd4651f9 100644 --- a/src/mapleall/maple_me/src/bb.cpp +++ b/src/mapleall/maple_me/src/bb.cpp @@ -359,20 +359,26 @@ void BB::SetLastMe(MeStmt *stmt) { } MeStmt *BB::GetFirstMe() { - if (meStmtList.empty()) return nullptr; - return &meStmtList.front(); + return meStmtList.empty() ? nullptr : &meStmtList.front(); +} + +const MeStmt *BB::GetFirstMe() const { + return meStmtList.empty() ? nullptr : &meStmtList.front(); } MeStmt *BB::GetLastMe() { - if (meStmtList.empty()) return nullptr; - return &meStmtList.back(); + return meStmtList.empty() ? nullptr : &meStmtList.back(); +} + +const MeStmt *BB::GetLastMe() const { + return meStmtList.empty() ? nullptr : &meStmtList.back(); } void BB::RemoveLastMeStmt() { meStmtList.pop_back(); } -void BB::RemoveMeStmt(const MeStmt *meStmt) { +void BB::RemoveMeStmt(MeStmt *meStmt) { CHECK_FATAL(meStmt != nullptr, "null ptr check"); meStmtList.erase(meStmt); } @@ -417,7 +423,7 @@ void BB::InsertMeStmtLastBr(MeStmt *inStmt) { } } -void BB::ReplaceMeStmt(const MeStmt *stmt, MeStmt *newStmt) { +void BB::ReplaceMeStmt(MeStmt *stmt, MeStmt *newStmt) { InsertMeStmtBefore(stmt, newStmt); RemoveMeStmt(stmt); } diff --git a/src/mapleall/maple_me/src/irmap.cpp b/src/mapleall/maple_me/src/irmap.cpp index 7e8246db7011c30e67f749e45f41bf6a3d7bae1a..b0d4f43e06219d91742e3cf1acdf1f7399621dc2 100644 --- a/src/mapleall/maple_me/src/irmap.cpp +++ b/src/mapleall/maple_me/src/irmap.cpp @@ -771,10 +771,10 @@ AssignMeStmt *IRMap::CreateAssignMeStmt(ScalarMeExpr &lhs, MeExpr &rhs, BB &curr // get the false goto bb, if condgoto is brtrue, take the other bb of brture @lable // otherwise, take the bb of @lable -BB *IRMap::GetFalseBrBB(const CondGotoMeStmt &condgoto) { +const BB *IRMap::GetFalseBrBB(const CondGotoMeStmt &condgoto) { LabelIdx lblIdx = (LabelIdx)condgoto.GetOffset(); BB *gotoBB = GetBBForLabIdx(lblIdx); - BB *bb = condgoto.GetBB(); + const BB *bb = condgoto.GetBB(); ASSERT(bb->GetSucc().size() == kBBVectorInitialSize, "array size error"); if (condgoto.GetOp() == OP_brfalse) { return gotoBB; diff --git a/src/mapleall/maple_me/src/me_abco.cpp b/src/mapleall/maple_me/src/me_abco.cpp index 078524bf3fab13595921b51db49dd750926033c6..b4e1007f642137cba36714300d60cc7f7cc9de9b 100644 --- a/src/mapleall/maple_me/src/me_abco.cpp +++ b/src/mapleall/maple_me/src/me_abco.cpp @@ -125,11 +125,11 @@ void MeABC::BuildSoloPiInGraph(const PiassignMeStmt &piMeStmt) { bool MeABC::PiExecuteBeforeCurrentCheck(const PiassignMeStmt &piMeStmt) { BB *currentCheckBB = currentCheck->GetBB(); - BB *piBB = piMeStmt.GetBB(); + const BB *piBB = piMeStmt.GetBB(); if (currentCheckBB != piBB) { return dom->Dominate(*piBB, *currentCheckBB); } - MeStmt *lastMeStmt = piBB->GetLastMe(); + const MeStmt *lastMeStmt = piBB->GetLastMe(); CHECK_FATAL(lastMeStmt->GetNextMeStmt() == nullptr, "must be"); MeStmt *tmpMeStmt = piMeStmt.GetNextMeStmt(); while (tmpMeStmt != nullptr) { diff --git a/src/mapleall/maple_me/src/me_cfg_opt.cpp b/src/mapleall/maple_me/src/me_cfg_opt.cpp index bbeeeaae86bd24bf281d291adcf5b656bb833d99..a4fecceed296ec59a02498bde9205e4a7ccdcd23 100644 --- a/src/mapleall/maple_me/src/me_cfg_opt.cpp +++ b/src/mapleall/maple_me/src/me_cfg_opt.cpp @@ -125,9 +125,9 @@ bool MeCfgOpt::IsExpensiveOp(Opcode op) { } } -const MeStmt *MeCfgOpt::GetCondBrStmtFromBB(const BB &bb) const { +MeStmt *MeCfgOpt::GetCondBrStmtFromBB(BB &bb) const { CHECK_FATAL(bb.GetKind() == kBBCondGoto, "must be cond goto"); - const MeStmt *meStmt = to_ptr(bb.GetMeStmts().rbegin()); + MeStmt *meStmt = to_ptr(bb.GetMeStmts().rbegin()); if (meStmt->IsCondBr()) { return meStmt; } @@ -245,7 +245,7 @@ bool MeCfgOpt::Run(MeCFG &cfg) { auto *bb = *bIt; constexpr uint32 numOfSuccs = 2; if (bb->GetKind() == kBBCondGoto && bb->GetSucc().size() == numOfSuccs) { - const MeStmt *condMeStmt = GetCondBrStmtFromBB(*bb); + MeStmt *condMeStmt = GetCondBrStmtFromBB(*bb); if (condMeStmt == nullptr || !condMeStmt->IsCondBr()) { continue; } diff --git a/src/mapleall/maple_me/src/me_gc_lowering.cpp b/src/mapleall/maple_me/src/me_gc_lowering.cpp index 5cdeb610936d9f836c3af892e7e3a448f18e8600..b9102ad28a78925960382e293172bd07a8c3bd82 100644 --- a/src/mapleall/maple_me/src/me_gc_lowering.cpp +++ b/src/mapleall/maple_me/src/me_gc_lowering.cpp @@ -104,7 +104,7 @@ MIRIntrinsicID GCLowering::SelectWriteBarrier(MeStmt &stmt) { return meOp == kMeOpVar ? INTRN_MCCWriteS : INTRN_MCCWrite; } -static inline void CheckRemove(const MeStmt *stmt, Opcode op) { +static void CheckRemove(MeStmt *stmt, Opcode op) { if (stmt != nullptr && stmt->GetOp() == op) { stmt->GetBB()->RemoveMeStmt(stmt); } @@ -163,7 +163,7 @@ MeExpr *GCLowering::GetBase(IvarMeExpr &ivar) { return base; } -void GCLowering::HandleWriteReferent(const IassignMeStmt &stmt) { +void GCLowering::HandleWriteReferent(IassignMeStmt &stmt) { if (!isReferent) { return; } diff --git a/src/mapleall/maple_me/src/me_gc_write_barrier_opt.cpp b/src/mapleall/maple_me/src/me_gc_write_barrier_opt.cpp index 16fe1edb68da483518f55666dc0513fdb4daca5b..98277833dcddf087596f6b850e7ab2dc82c0b376 100644 --- a/src/mapleall/maple_me/src/me_gc_write_barrier_opt.cpp +++ b/src/mapleall/maple_me/src/me_gc_write_barrier_opt.cpp @@ -147,8 +147,8 @@ bool GCWriteBarrierOpt::IsCall(const MeStmt &stmt) { } bool GCWriteBarrierOpt::HasYieldPoint(const MeStmt &start, const MeStmt &end) { - BB *startBB = start.GetBB(); - BB *endBB = end.GetBB(); + const BB *startBB = start.GetBB(); + const BB *endBB = end.GetBB(); if (startBB == endBB) { return HasCallBetweenStmt(start, end); } diff --git a/src/mapleall/maple_me/src/me_placement_rc.cpp b/src/mapleall/maple_me/src/me_placement_rc.cpp index e0c1bbdbbe770f854b8d20b105a3eeff4da5fc39..68dd9776b505228d8c44b9b0ab90b65046d43c23 100644 --- a/src/mapleall/maple_me/src/me_placement_rc.cpp +++ b/src/mapleall/maple_me/src/me_placement_rc.cpp @@ -229,7 +229,7 @@ static bool CannotInsertAfterStmt(const MeStmt &occStmt, OStIdx ostIdx, bool rea if (occStmt.GetOp() == OP_return || occStmt.GetOp() == OP_throw) { return true; } - BB *lastUseBB = occStmt.GetBB(); + const BB *lastUseBB = occStmt.GetBB(); if (&occStmt == to_ptr(lastUseBB->GetMeStmts().rbegin()) && lastUseBB->GetKind() != kBBFallthru) { return true; } @@ -449,7 +449,7 @@ void PlacementRC::SetFormalParamsAttr(MIRFunction &mirFunc) const { } } -void PlacementRC::DeleteEntryIncref(SRealOcc &realOcc, const UnaryMeStmt *entryIncref) const { +void PlacementRC::DeleteEntryIncref(SRealOcc &realOcc, UnaryMeStmt *entryIncref) const { CHECK_NULL_FATAL(entryIncref); CHECK_FATAL(workCand->GetOst()->IsFormal(), "PlacementRC::CodeMotion: realOcc->meStmt cannot be null"); @@ -559,7 +559,7 @@ void PlacementRC::CodeMotionForSLambdares(SLambdaResOcc &lambdaResOcc) { CheckAndInsert(lambdaResOcc.GetBB(), lambdaRealOcc); } -void PlacementRC::CodeMotionForReal(SOcc &occ, const UnaryMeStmt *entryIncref) { +void PlacementRC::CodeMotionForReal(SOcc &occ, UnaryMeStmt *entryIncref) { SRealOcc &realOcc = static_cast(occ); if (realOcc.GetRedundant()) { return; diff --git a/src/mapleall/maple_me/src/me_rc_lowering.cpp b/src/mapleall/maple_me/src/me_rc_lowering.cpp index d9d6cec1e8e1fecd57bc3f7e45743cf5c6c90129..7be2af8a1d0f034da5cfe43591c5f47d5978e45c 100644 --- a/src/mapleall/maple_me/src/me_rc_lowering.cpp +++ b/src/mapleall/maple_me/src/me_rc_lowering.cpp @@ -32,7 +32,7 @@ static inline bool CheckOp(const MeStmt *stmt, Opcode op) { return stmt != nullptr && stmt->GetOp() == op; } -static inline void CheckRemove(const MeStmt *stmt, Opcode op) { +static inline void CheckRemove(MeStmt *stmt, Opcode op) { if (CheckOp(stmt, op)) { stmt->GetBB()->RemoveMeStmt(stmt); } @@ -463,7 +463,7 @@ void RCLowering::PreprocessAssignMeStmt(MeStmt &stmt) { } } -void RCLowering::HandleAssignMeStmtRegLHS(const MeStmt &stmt) { +void RCLowering::HandleAssignMeStmtRegLHS(MeStmt &stmt) { if (!stmt.NeedIncref()) { return; } @@ -509,7 +509,7 @@ MIRType *RCLowering::GetArrayNodeType(const VarMeExpr &var) { return arrayElemType; } -void RCLowering::CheckArrayStore(const IntrinsiccallMeStmt &writeRefCall) { +void RCLowering::CheckArrayStore(IntrinsiccallMeStmt &writeRefCall) { if (!Options::checkArrayStore) { return; } @@ -547,7 +547,7 @@ void RCLowering::CheckArrayStore(const IntrinsiccallMeStmt &writeRefCall) { writeRefCall.GetBB()->InsertMeStmtBefore(&writeRefCall, checkStmt); } -void RCLowering::HandleAssignToGlobalVar(const MeStmt &stmt) { +void RCLowering::HandleAssignToGlobalVar(MeStmt &stmt) { MeExpr *lhs = stmt.GetLHS(); CHECK_FATAL(lhs != nullptr, "null ptr check"); MeExpr *rhs = stmt.GetRHS(); @@ -561,7 +561,7 @@ void RCLowering::HandleAssignToGlobalVar(const MeStmt &stmt) { CheckArrayStore(*writeRefCall); } -void RCLowering::HandleAssignToLocalVar(const MeStmt &stmt, MeExpr *pendingDec) { +void RCLowering::HandleAssignToLocalVar(MeStmt &stmt, MeExpr *pendingDec) { MeExpr *lhs = stmt.GetLHS(); CHECK_FATAL(lhs != nullptr, "null ptr check"); MeExpr *rhs = stmt.GetRHS(); @@ -784,7 +784,7 @@ void RCLowering::RCLower() { } } -MeExpr *RCLowering::HandleIncRefAndDecRefStmt(const MeStmt &stmt) { +MeExpr *RCLowering::HandleIncRefAndDecRefStmt(MeStmt &stmt) { Opcode opCode = stmt.GetOp(); if (opCode == OP_decref) { stmt.GetBB()->RemoveMeStmt(&stmt); @@ -872,8 +872,8 @@ void RCLowering::BBLower(BB &bb) { } } -IntrinsiccallMeStmt *FindCleanupIntrinsic(const MeStmt &ret) { - auto &meStmts = ret.GetBB()->GetMeStmts(); +IntrinsiccallMeStmt *FindCleanupIntrinsic(BB &bb) { + auto &meStmts = bb.GetMeStmts(); for (auto iter = meStmts.rbegin(); iter != meStmts.rend(); ++iter) { if (CheckOp(to_ptr(iter), OP_intrinsiccall)) { auto *intrinsicCall = static_cast(to_ptr(iter)); @@ -963,12 +963,12 @@ void RCLowering::HandleReturnGlobal(RetMeStmt &ret) { } } -void RCLowering::HandleReturnRegread(const RetMeStmt &ret) { +void RCLowering::HandleReturnRegread(RetMeStmt &ret) { BB *bb = ret.GetBB(); CHECK_FATAL(bb != nullptr, "bb null ptr check"); auto *retVar = static_cast(ret.GetOpnd(0)); CHECK_FATAL(retVar != nullptr, "retVal null ptr check"); - IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(ret); + IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(*bb); if (cleanup == nullptr) { std::vector opnds = { retVar }; IntrinsiccallMeStmt *incCall = CreateRCIntrinsic(INTRN_MCCIncRef, ret, opnds); @@ -999,7 +999,7 @@ void RCLowering::HandleReturnFormal(RetMeStmt &ret) { std::vector opnds = { retVar }; IntrinsiccallMeStmt *incRefStmt = CreateRCIntrinsic(INTRN_MCCIncRef, ret, opnds, true); ret.SetOpnd(0, incRefStmt->GetMustDefList()->front().GetLHS()); - IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(ret); + IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(*bb); if (cleanup == nullptr) { bb->InsertMeStmtBefore(&ret, incRefStmt); } else { @@ -1056,7 +1056,7 @@ void RCLowering::HandleReturnReg(RetMeStmt &ret) { void RCLowering::HandleReturnWithCleanup() { for (auto *stmt : rets) { auto *ret = static_cast(stmt); - IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(*ret); + IntrinsiccallMeStmt *cleanup = FindCleanupIntrinsic(*ret->GetBB()); if (cleanup != nullptr && !tmpLocalRefVars.empty()) { // new localrefvar introduced in this phase for (auto tmpVar : tmpLocalRefVars) { cleanup->PushBackOpnd(tmpVar); @@ -1327,7 +1327,7 @@ void RCLowering::CompactRC(BB &bb) { } } -void RCLowering::CompactIncAndDec(const MeStmt &incStmt, const MeStmt &decStmt) { +void RCLowering::CompactIncAndDec(MeStmt &incStmt, MeStmt &decStmt) { BB *bb = incStmt.GetBB(); CHECK_FATAL(bb != nullptr, "bb nullptr check"); MeExpr *incOpnd = incStmt.GetOpnd(0); @@ -1342,7 +1342,7 @@ void RCLowering::CompactIncAndDec(const MeStmt &incStmt, const MeStmt &decStmt) bb->RemoveMeStmt(&decStmt); } -void RCLowering::CompactIncAndDecReset(const MeStmt &incStmt, const MeStmt &resetStmt) { +void RCLowering::CompactIncAndDecReset(MeStmt &incStmt, MeStmt &resetStmt) { BB *bb = incStmt.GetBB(); CHECK_FATAL(bb != nullptr, "bb nullptr check"); MeExpr *incOpnd = incStmt.GetOpnd(0); @@ -1357,7 +1357,7 @@ void RCLowering::CompactIncAndDecReset(const MeStmt &incStmt, const MeStmt &rese bb->RemoveMeStmt(&incStmt); } -void RCLowering::ReplaceDecResetWithDec(MeStmt &prevStmt, const MeStmt &stmt) { +void RCLowering::ReplaceDecResetWithDec(MeStmt &prevStmt, MeStmt &stmt) { auto *addrofMeExpr = static_cast(stmt.GetOpnd(0)); ASSERT_NOT_NULL(addrofMeExpr); auto *dass = static_cast(&prevStmt); @@ -1372,7 +1372,7 @@ void RCLowering::ReplaceDecResetWithDec(MeStmt &prevStmt, const MeStmt &stmt) { bb->RemoveMeStmt(&prevStmt); } -void RCLowering::CompactAdjacentDecReset(const MeStmt &prevStmt, const MeStmt &stmt) { +void RCLowering::CompactAdjacentDecReset(MeStmt &prevStmt, MeStmt &stmt) { MeExpr *prevOpnd = prevStmt.GetOpnd(0); MeExpr *curOpnd = stmt.GetOpnd(0); BB *bb = stmt.GetBB(); @@ -1521,7 +1521,7 @@ void RCLowering::FastLowerRetIvar(RetMeStmt &stmt) { stmt.SetOpnd(0, tmpRet->GetLHS()); } -void RCLowering::FastLowerRetReg(const RetMeStmt &stmt) { +void RCLowering::FastLowerRetReg(RetMeStmt &stmt) { auto *regRet = static_cast(stmt.GetOpnd(0)); if (regRet->GetDefBy() == kDefByStmt && CheckOp(regRet->GetDefStmt(), OP_regassign)) { MeExpr *rhs = regRet->GetDefStmt()->GetRHS(); diff --git a/src/mapleall/maple_me/src/me_safety_warning.cpp b/src/mapleall/maple_me/src/me_safety_warning.cpp index 77de63e6462c38b933f6fa8c86876b029ad0cc2f..53144d20eb88ab00fbb0ef8225704a8f79e75fcb 100755 --- a/src/mapleall/maple_me/src/me_safety_warning.cpp +++ b/src/mapleall/maple_me/src/me_safety_warning.cpp @@ -298,7 +298,7 @@ bool MESafetyWarning::PhaseRun(MeFunction &meFunction) { auto *dom = GET_ANALYSIS(MEDominance, meFunction); auto &mod = meFunction.GetMIRModule(); auto fileInfos = mod.GetSrcFileInfo(); - MapleVector removeStmts(mod.GetMPAllocator().Adapter()); + MapleVector removeStmts(mod.GetMPAllocator().Adapter()); for (auto *bb : dom->GetReversePostOrder()) { for (auto &stmt : bb->GetMeStmts()) { auto *handle = FindHandler(stmt.GetOp()); diff --git a/src/mapleall/maple_me/src/me_sink.cpp b/src/mapleall/maple_me/src/me_sink.cpp index 61e07eeac071df4a03ffdeef705f030de7dbc25b..db06f6000da1100e8f5b00dffa8dc3a78583874a 100644 --- a/src/mapleall/maple_me/src/me_sink.cpp +++ b/src/mapleall/maple_me/src/me_sink.cpp @@ -39,8 +39,8 @@ class MeSink { bool OpndOfExprRedefined(const MeExpr *expr) const; bool ScalarOnlyUsedInCurStmt(const ScalarMeExpr *scalar, const MeStmt *stmt, std::set &visitedScalars) const; - void RecordStmtSinkToHeaderOfTargetBB(MeStmt *defStmt, BB *targetBB); - void RecordStmtSinkToBottomOfTargetBB(MeStmt *defStmt, BB *targetBB); + void RecordStmtSinkToHeaderOfTargetBB(MeStmt *defStmt, const BB *targetBB); + void RecordStmtSinkToBottomOfTargetBB(MeStmt *defStmt, const BB *targetBB); bool MeExprSinkable(MeExpr *expr) const; bool DefStmtSinkable(MeStmt *defStmt) const; @@ -51,7 +51,7 @@ class MeSink { bool MergeAssignStmtWithCallAssign(AssignMeStmt *assign, MeStmt *callAssign); DefUseInfoOfPhi DefAndUseInfoOfPhiOpnds(MePhiNode *phi, std::map &defStmts); DefUseInfoOfPhi DefAndUseInfoOfPhiOpnds(MePhiNode *phi, std::map &defStmts, - std::set &processedPhi, std::set &phisUseCurrPhiOpnds); + std::set &processedPhi, std::set &phisUseCurrPhiOpnds); void ReplacePhiWithNewDataFlow(MePhiNode *phi, ScalarMeExpr *scalar); bool PhiCanBeReplacedWithDataFlowOfScalar(ScalarMeExpr *scalar, const BB *defBBOfScalar, MePhiNode *phi, std::map &defStmtsOfPhiOpnds); @@ -66,9 +66,9 @@ class MeSink { void ProcessPhiList(BB *bb); void SinkStmtsInBB(BB *bb); - BB *BestSinkBB(BB *fromBB, BB *toBB); - std::pair CalCandSinkBBForUseSites(const ScalarMeExpr *scalar, const UseSitesType &useList); - BB *CalSinkSiteOfScalarDefStmt(const ScalarMeExpr *scalar); + const BB *BestSinkBB(const BB *fromBB, const BB *toBB); + std::pair CalCandSinkBBForUseSites(const ScalarMeExpr *scalar, const UseSitesType &useList); + const BB *CalSinkSiteOfScalarDefStmt(const ScalarMeExpr *scalar); void CalSinkSites(); void Run(); @@ -272,7 +272,7 @@ bool MeSink::MergeAssignStmtWithCallAssign(AssignMeStmt *assign, MeStmt *callAss DefUseInfoOfPhi MeSink::DefAndUseInfoOfPhiOpnds(MePhiNode *phi, std::map &defStmts, std::set &processedPhi, - std::set &phisUseCurrPhiOpnds) { + std::set &phisUseCurrPhiOpnds) { DefUseInfoOfPhi defInfo{true, true, true, true, nullptr}; auto &opnds = phi->GetOpnds(); for (auto *opnd : opnds) { @@ -336,7 +336,7 @@ DefUseInfoOfPhi MeSink::DefAndUseInfoOfPhiOpnds(MePhiNode *phi, std::map &defStmts) { std::set processedPhi{phi}; - std::set phisUseCurrPhiOpnds{phi}; + std::set phisUseCurrPhiOpnds{phi}; auto defUseInfo = DefAndUseInfoOfPhiOpnds(phi, defStmts, processedPhi, phisUseCurrPhiOpnds); defUseInfo.opndsOnlyFlowIntoTargetPhi = (phisUseCurrPhiOpnds.size() <= processedPhi.size()); return defUseInfo; @@ -1024,7 +1024,7 @@ static bool BBIsEmptyOrContainsSingleGoto(const BB *bb) { // we should not sink stmt from non-loop BB into loop BB or from outter loop into inner loop. // if toBB is in a different loop with fromBB, return a dominator of toBB which is in the same loop with fromBB. -BB *MeSink::BestSinkBB(BB *fromBB, BB *toBB) { +const BB *MeSink::BestSinkBB(const BB *fromBB, const BB *toBB) { CHECK_FATAL(domTree->Dominate(*fromBB, *toBB), "fromBB must dom toBB"); if (fromBB == toBB) { return toBB; @@ -1044,26 +1044,26 @@ BB *MeSink::BestSinkBB(BB *fromBB, BB *toBB) { return toBB; } -void MeSink::RecordStmtSinkToHeaderOfTargetBB(MeStmt *defStmt, BB *targetBB) { +void MeSink::RecordStmtSinkToHeaderOfTargetBB(MeStmt *defStmt, const BB *targetBB) { if (defStmtsSinkToHeader[targetBB->GetBBId()] == nullptr) { defStmtsSinkToHeader[targetBB->GetBBId()] = std::make_unique>(); } defStmtsSinkToHeader[targetBB->GetBBId()]->push_front(defStmt); } -void MeSink::RecordStmtSinkToBottomOfTargetBB(MeStmt *defStmt, BB *targetBB) { +void MeSink::RecordStmtSinkToBottomOfTargetBB(MeStmt *defStmt, const BB *targetBB) { if (defStmtsSinkToBottom[targetBB->GetBBId()] == nullptr) { defStmtsSinkToBottom[targetBB->GetBBId()] = std::make_unique>(); } defStmtsSinkToBottom[targetBB->GetBBId()]->push_front(defStmt); } -std::pair MeSink::CalCandSinkBBForUseSites(const ScalarMeExpr *scalar, const UseSitesType &useList) { +std::pair MeSink::CalCandSinkBBForUseSites(const ScalarMeExpr *scalar, const UseSitesType &useList) { if (useList.empty()) { return {nullptr, false}; } - BB *candSinkBB = nullptr; + const BB *candSinkBB = nullptr; for (auto it = useList.rbegin(); it != useList.rend(); ++it) { const auto &useItem = *it; if (useItem.IsUseByStmt()) { @@ -1102,7 +1102,7 @@ std::pair MeSink::CalCandSinkBBForUseSites(const ScalarMeExpr *scalar return {candSinkBB, useSitesDomByCandSinkBB}; } -BB *MeSink::CalSinkSiteOfScalarDefStmt(const ScalarMeExpr *scalar) { +const BB *MeSink::CalSinkSiteOfScalarDefStmt(const ScalarMeExpr *scalar) { if (scalar->IsVolatile() || scalar->GetPrimType() == PTY_ref) { return nullptr; } @@ -1136,7 +1136,7 @@ BB *MeSink::CalSinkSiteOfScalarDefStmt(const ScalarMeExpr *scalar) { } const auto &candSinkSite = CalCandSinkBBForUseSites(scalar, *useList); - BB *candSinkBB = candSinkSite.first; + const BB *candSinkBB = candSinkSite.first; if (candSinkBB == nullptr) { // scalar defined without use, the defStmt should be removed return nullptr; diff --git a/src/mapleall/maple_me/src/meexpr_use_info.cpp b/src/mapleall/maple_me/src/meexpr_use_info.cpp index 30fb4788db535ff3cd1bfbf2f93a71ea83822cea..ede4870aca569bed28cf94c67d1d64ffb55e1484 100644 --- a/src/mapleall/maple_me/src/meexpr_use_info.cpp +++ b/src/mapleall/maple_me/src/meexpr_use_info.cpp @@ -35,20 +35,12 @@ void MeExprUseInfo::AddUseSiteOfExpr(MeExpr *expr, T *useSite) { (*useSites)[uintExprID] = {expr, newList}; return; } - if (!(*useSites)[uintExprID].second->front().SameUseItem(useSite)) { - (*useSites)[uintExprID].second->emplace_front(UseItem(useSite)); + UseItem use(useSite); + if ((*useSites)[uintExprID].second->front() != use) { + (*useSites)[uintExprID].second->emplace_front(use); } } -template -void MeExprUseInfo::RemoveUseSiteOfExpr(const MeExpr *expr, T *useSite) { - auto *useSitesOfExpr = GetUseSitesOfExpr(expr); - if (useSitesOfExpr == nullptr) { - return; - } - useSitesOfExpr->remove(UseItem(useSite)); -} - MapleList *MeExprUseInfo::GetUseSitesOfExpr(const MeExpr *expr) const { if (IsInvalid()) { CHECK_FATAL(false, "Expr use info is invalid"); @@ -154,38 +146,49 @@ void MeExprUseInfo::CollectUseInfoInFunc(IRMap *irMap, Dominance *domTree, MeExp bool MeExprUseInfo::ReplaceScalar(IRMap *irMap, const ScalarMeExpr *scalarA, ScalarMeExpr *scalarB) { auto *useList = GetUseSitesOfExpr(scalarA); - if (useList == nullptr || useList->empty()) { + + if (!useList || useList->empty()) { return true; } bool replacedAll = true; - for (auto &useSite : *useList) { + + auto end = useList->end(); + decltype(end) next; + + for (auto it = useList->begin(); it != end; it = next) { + next = std::next(it); + auto &useSite = *it; + if (useSite.IsUseByStmt()) { auto *useStmt = useSite.GetStmt(); - auto replaced = irMap->ReplaceMeExprStmt(*useStmt, *scalarA, *scalarB); - if (replaced) { + + if (irMap->ReplaceMeExprStmt(*useStmt, *scalarA, *scalarB)) { AddUseSiteOfExpr(scalarB, useStmt); - RemoveUseSiteOfExpr(scalarA, useStmt); + useList->erase(it); } - continue; - } + } else { + ASSERT(useSite.IsUseByPhi(), "Invalid use type!"); - if (useSite.IsUseByPhi()) { if (scalarA->GetOst() != scalarB->GetOst()) { replacedAll = false; continue; } + auto *phi = useSite.GetPhi(); + for (size_t id = 0; id < phi->GetOpnds().size(); ++id) { if (phi->GetOpnd(id) != scalarA) { continue; } + phi->GetOpnds()[id] = scalarB; AddUseSiteOfExpr(scalarB, phi); - RemoveUseSiteOfExpr(scalarA, phi); + useList->erase(it); } } } + return replacedAll; } } // namespace maple \ No newline at end of file diff --git a/src/mapleall/maple_me/src/simplifyCFG.cpp b/src/mapleall/maple_me/src/simplifyCFG.cpp index b37d2a0391c998d52b93fa6f3ad8228e5075a387..d85444b6811b882959ce7737b869b3a5ad570ba3 100644 --- a/src/mapleall/maple_me/src/simplifyCFG.cpp +++ b/src/mapleall/maple_me/src/simplifyCFG.cpp @@ -231,7 +231,7 @@ bool IsAllOpndsNotDefByCurrBB(const MeExpr &expr, const BB &currBB, std::set infLoopCheck; if (!IsAllOpndsNotDefByCurrBB(*stmt.GetOpnd(i), *currBB, infLoopCheck)) { diff --git a/src/mapleall/maple_me/src/ssa_devirtual.cpp b/src/mapleall/maple_me/src/ssa_devirtual.cpp index 7d174ebad788f426da1098017a34f0a4819eb080..15a609e42709a778b7a947fc51a9ba0141c22e2d 100644 --- a/src/mapleall/maple_me/src/ssa_devirtual.cpp +++ b/src/mapleall/maple_me/src/ssa_devirtual.cpp @@ -249,7 +249,7 @@ bool SSADevirtual::NeedNullCheck(const MeExpr &receiver) const { // Java requires to throw Null-Pointer-Execption if the receiver of // the virtualcall is null. We insert an eval(iread recevier, 0) // statment perform the null-check. -void SSADevirtual::InsertNullCheck(const CallMeStmt &callStmt, MeExpr &receiver) const { +void SSADevirtual::InsertNullCheck(CallMeStmt &callStmt, MeExpr &receiver) const { UnaryMeStmt *nullCheck = irMap->New(OP_assertnonnull); nullCheck->SetBB(callStmt.GetBB()); nullCheck->SetSrcPos(callStmt.GetSrcPosition()); diff --git a/src/mapleall/maple_me/src/ssa_pre.cpp b/src/mapleall/maple_me/src/ssa_pre.cpp index 1cfccaad45976506dea83f6762cb3bf4099fef24..3401761cdd66c9e7a661768dd43b3c0c238dec8b 100644 --- a/src/mapleall/maple_me/src/ssa_pre.cpp +++ b/src/mapleall/maple_me/src/ssa_pre.cpp @@ -1341,7 +1341,7 @@ bool SSAPre::DefVarDominateOcc(const MeExpr *meExpr, const MeOccur &meOcc) const if (meStmt == nullptr) { return true; // it's a original variable dominate everything } - BB *defBB = meStmt->GetBB(); + const BB *defBB = meStmt->GetBB(); if (occBB == defBB) { return false; }