From a0b6366305de8f451519daf3e9a9329411c2a7dc Mon Sep 17 00:00:00 2001 From: Fred Chow Date: Thu, 17 Jun 2021 19:54:25 -0700 Subject: [PATCH] Fixed some assertions with debug-built compiler --- src/mapleall/maple_me/include/me_ir.h | 1 + src/mapleall/maple_me/include/orig_symbol.h | 1 + src/mapleall/maple_me/src/me_ir.cpp | 14 +++++++++++ src/mapleall/maple_me/src/orig_symbol.cpp | 26 ++++++++++++++------- src/mapleall/mpl2mpl/src/constantfold.cpp | 2 +- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/mapleall/maple_me/include/me_ir.h b/src/mapleall/maple_me/include/me_ir.h index 0793a28f5f..b490c2bb20 100644 --- a/src/mapleall/maple_me/include/me_ir.h +++ b/src/mapleall/maple_me/include/me_ir.h @@ -728,6 +728,7 @@ class AddroflabelMeExpr : public MeExpr { return true; } BaseNode &EmitExpr(SSATab&) override; + MeExpr *GetIdenticalExpr(MeExpr &expr, bool) const override; uint32 GetHashIndex() const override { constexpr uint32 shiftNum = 4; diff --git a/src/mapleall/maple_me/include/orig_symbol.h b/src/mapleall/maple_me/include/orig_symbol.h index bc8e44be35..5bd56dcabb 100644 --- a/src/mapleall/maple_me/include/orig_symbol.h +++ b/src/mapleall/maple_me/include/orig_symbol.h @@ -407,6 +407,7 @@ class OriginalStTable { // mir symbol to original table, this only exists for no-original variables. public: MapleUnorderedMap mirSt2Ost; + MapleUnorderedMap addrofSt2Ost; private: MapleUnorderedMap preg2Ost; // mir type to virtual variables in original table. this only exists for no-original variables. diff --git a/src/mapleall/maple_me/src/me_ir.cpp b/src/mapleall/maple_me/src/me_ir.cpp index 9c7209b8a0..8a1c3d7094 100644 --- a/src/mapleall/maple_me/src/me_ir.cpp +++ b/src/mapleall/maple_me/src/me_ir.cpp @@ -754,6 +754,20 @@ MeExpr *AddroffuncMeExpr::GetIdenticalExpr(MeExpr &expr, bool isConstructor) con return nullptr; } +MeExpr *AddroflabelMeExpr::GetIdenticalExpr(MeExpr &expr, bool isConstructor) const { + (void)isConstructor; + auto *addroflabelExpr = static_cast(&expr); + + while (addroflabelExpr != nullptr) { + if (addroflabelExpr->GetMeOp() == kMeOpAddroflabel && addroflabelExpr->labelIdx == labelIdx) { + return addroflabelExpr; + } + addroflabelExpr = static_cast(addroflabelExpr->GetNext()); + } + + return nullptr; +} + void MePhiNode::Dump(const IRMap *irMap) const { const OriginalSt *ost = lhs->GetOst(); bool isSym = ost->IsSymbolOst(); diff --git a/src/mapleall/maple_me/src/orig_symbol.cpp b/src/mapleall/maple_me/src/orig_symbol.cpp index 19ddeaaf74..b46deb45c2 100644 --- a/src/mapleall/maple_me/src/orig_symbol.cpp +++ b/src/mapleall/maple_me/src/orig_symbol.cpp @@ -55,6 +55,7 @@ OriginalStTable::OriginalStTable(MemPool &memPool, MIRModule &mod) mirModule(mod), originalStVector({ nullptr }, alloc.Adapter()), mirSt2Ost(alloc.Adapter()), + addrofSt2Ost(alloc.Adapter()), preg2Ost(alloc.Adapter()), pType2Ost(std::less(), alloc.Adapter()), malloc2Ost(alloc.Adapter()), @@ -155,15 +156,22 @@ OriginalSt *OriginalStTable::FindOrCreateAddrofSymbolOriginalSt(OriginalSt *ost) if (ost->GetPrevLevelOst() != nullptr) { return ost->GetPrevLevelOst(); } - // create a new node - OriginalSt *prevLevelOst = alloc.GetMemPool()->New( - originalStVector.size(), *ost->GetMIRSymbol(), ost->GetPuIdx(), 0, alloc); - originalStVector.push_back(prevLevelOst); - prevLevelOst->SetIndirectLev(-1); - MIRPtrType pointType(ost->GetMIRSymbol()->GetTyIdx(), PTY_ptr); - TyIdx newTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&pointType); - prevLevelOst->SetTyIdx(newTyIdx); - prevLevelOst->SetFieldID(0); + OriginalSt *prevLevelOst = nullptr; + auto it = addrofSt2Ost.find(ost->GetMIRSymbol()->GetStIndex()); + if (it != addrofSt2Ost.end()) { + prevLevelOst = originalStVector[it->second]; + } else { + // create a new node + prevLevelOst = alloc.GetMemPool()->New( + originalStVector.size(), *ost->GetMIRSymbol(), ost->GetPuIdx(), 0, alloc); + originalStVector.push_back(prevLevelOst); + prevLevelOst->SetIndirectLev(-1); + MIRPtrType pointType(ost->GetMIRSymbol()->GetTyIdx(), PTY_ptr); + TyIdx newTyIdx = GlobalTables::GetTypeTable().GetOrCreateMIRType(&pointType); + prevLevelOst->SetTyIdx(newTyIdx); + prevLevelOst->SetFieldID(0); + addrofSt2Ost[ost->GetMIRSymbol()->GetStIndex()] = prevLevelOst->GetIndex(); + } ost->SetPrevLevelOst(prevLevelOst); prevLevelOst->AddNextLevelOst(ost); return prevLevelOst; diff --git a/src/mapleall/mpl2mpl/src/constantfold.cpp b/src/mapleall/mpl2mpl/src/constantfold.cpp index 0a0267c6f8..d7cc671c72 100644 --- a/src/mapleall/mpl2mpl/src/constantfold.cpp +++ b/src/mapleall/mpl2mpl/src/constantfold.cpp @@ -463,7 +463,7 @@ MIRConst *ConstantFold::FoldIntConstBinaryMIRConst(Opcode opcode, PrimType resul } case OP_mul: { if (useResult64) { - result64 = static_cast(intValueOfConst0 * intValueOfConst1); + result64 = static_cast(intValueOfConst0) * static_cast(intValueOfConst1); } else { result32 = static_cast(intValueOfConst0) * static_cast(intValueOfConst1); } -- Gitee