From 510e1a97cce622de4995783aa0c5b71f1bc016ae Mon Sep 17 00:00:00 2001 From: Yi Jiang Date: Thu, 21 May 2020 10:56:27 -0700 Subject: [PATCH] Unify handling RegMeStmt and VarMeStmt to ScalarMeStmt and combine the MeVarPhiNode as well as MeRegPhiNode --- src/maple_me/include/bb.h | 31 +- src/maple_me/include/irmap.h | 3 +- src/maple_me/include/me_abco.h | 28 +- src/maple_me/include/me_cfg.h | 5 +- src/maple_me/include/me_delegate_rc.h | 2 +- src/maple_me/include/me_inequality_graph.h | 6 +- src/maple_me/include/me_ir.h | 313 +++++++++------------ src/maple_me/include/me_ssa_update.h | 2 +- src/maple_me/include/me_ssu_pre.h | 8 +- src/maple_me/include/me_stmt_pre.h | 2 +- src/maple_me/include/occur.h | 16 +- src/maple_me/include/ssa_devirtual.h | 2 +- src/maple_me/src/bb.cpp | 18 +- src/maple_me/src/hdse.cpp | 8 +- src/maple_me/src/irmap.cpp | 18 +- src/maple_me/src/irmap_emit.cpp | 2 +- src/maple_me/src/me_abco.cpp | 51 ++-- src/maple_me/src/me_analyze_rc.cpp | 4 +- src/maple_me/src/me_cfg.cpp | 38 +-- src/maple_me/src/me_cond_based_opt.cpp | 7 +- src/maple_me/src/me_delegate_rc.cpp | 12 +- src/maple_me/src/me_function.cpp | 3 +- src/maple_me/src/me_hdse.cpp | 10 +- src/maple_me/src/me_inequality_graph.cpp | 7 +- src/maple_me/src/me_ir.cpp | 120 ++++---- src/maple_me/src/me_irmap.cpp | 3 +- src/maple_me/src/me_rename2preg.cpp | 23 +- src/maple_me/src/me_ssa_lpre.cpp | 2 +- src/maple_me/src/me_ssa_update.cpp | 32 +-- src/maple_me/src/me_stmt_pre.cpp | 22 +- src/maple_me/src/me_store_pre.cpp | 8 +- src/maple_me/src/occur.cpp | 2 +- src/maple_me/src/preg_renamer.cpp | 12 +- src/maple_me/src/prop.cpp | 15 +- src/maple_me/src/ssa_devirtual.cpp | 19 +- src/maple_me/src/ssa_epre.cpp | 2 +- src/maple_me/src/ssa_pre.cpp | 90 +++--- 37 files changed, 416 insertions(+), 530 deletions(-) mode change 100644 => 100755 src/maple_me/include/bb.h mode change 100644 => 100755 src/maple_me/include/irmap.h mode change 100644 => 100755 src/maple_me/include/me_abco.h mode change 100644 => 100755 src/maple_me/include/me_cfg.h mode change 100644 => 100755 src/maple_me/include/me_delegate_rc.h mode change 100644 => 100755 src/maple_me/include/me_inequality_graph.h mode change 100644 => 100755 src/maple_me/include/me_ir.h mode change 100644 => 100755 src/maple_me/include/me_ssa_update.h mode change 100644 => 100755 src/maple_me/include/me_ssu_pre.h mode change 100644 => 100755 src/maple_me/include/me_stmt_pre.h mode change 100644 => 100755 src/maple_me/include/occur.h mode change 100644 => 100755 src/maple_me/include/ssa_devirtual.h mode change 100644 => 100755 src/maple_me/src/bb.cpp mode change 100644 => 100755 src/maple_me/src/hdse.cpp mode change 100644 => 100755 src/maple_me/src/irmap.cpp mode change 100644 => 100755 src/maple_me/src/irmap_emit.cpp mode change 100644 => 100755 src/maple_me/src/me_abco.cpp mode change 100644 => 100755 src/maple_me/src/me_analyze_rc.cpp mode change 100644 => 100755 src/maple_me/src/me_cfg.cpp mode change 100644 => 100755 src/maple_me/src/me_cond_based_opt.cpp mode change 100644 => 100755 src/maple_me/src/me_delegate_rc.cpp mode change 100644 => 100755 src/maple_me/src/me_function.cpp mode change 100644 => 100755 src/maple_me/src/me_hdse.cpp mode change 100644 => 100755 src/maple_me/src/me_inequality_graph.cpp mode change 100644 => 100755 src/maple_me/src/me_ir.cpp mode change 100644 => 100755 src/maple_me/src/me_irmap.cpp mode change 100644 => 100755 src/maple_me/src/me_rename2preg.cpp mode change 100644 => 100755 src/maple_me/src/me_ssa_lpre.cpp mode change 100644 => 100755 src/maple_me/src/me_ssa_update.cpp mode change 100644 => 100755 src/maple_me/src/me_stmt_pre.cpp mode change 100644 => 100755 src/maple_me/src/me_store_pre.cpp mode change 100644 => 100755 src/maple_me/src/occur.cpp mode change 100644 => 100755 src/maple_me/src/preg_renamer.cpp mode change 100644 => 100755 src/maple_me/src/prop.cpp mode change 100644 => 100755 src/maple_me/src/ssa_devirtual.cpp mode change 100644 => 100755 src/maple_me/src/ssa_epre.cpp mode change 100644 => 100755 src/maple_me/src/ssa_pre.cpp diff --git a/src/maple_me/include/bb.h b/src/maple_me/include/bb.h old mode 100644 new mode 100755 index 50df279479..3e2043c127 --- a/src/maple_me/include/bb.h +++ b/src/maple_me/include/bb.h @@ -23,8 +23,7 @@ namespace maple { class MeStmt; // circular dependency exists, no other choice -class MeVarPhiNode; // circular dependency exists, no other choice -class MeRegPhiNode; // circular dependency exists, no other choice +class MePhiNode; // circular dependency exists, no other choice class PiassignMeStmt; // circular dependency exists, no other choice class IRMap; // circular dependency exists, no other choice enum BBKind { @@ -68,8 +67,7 @@ class BB { succ(kBBVectorInitialSize, nullptr, alloc->Adapter()), succFreq(alloc->Adapter()), phiList(versAlloc->Adapter()), - meVarPhiList(alloc->Adapter()), - meRegPhiList(alloc->Adapter()), + mePhiList(alloc->Adapter()), meVarPiList(alloc->Adapter()), group(this) { pred.pop_back(); @@ -84,8 +82,7 @@ class BB { succ(kBBVectorInitialSize, nullptr, alloc->Adapter()), succFreq(alloc->Adapter()), phiList(versAlloc->Adapter()), - meVarPhiList(alloc->Adapter()), - meRegPhiList(alloc->Adapter()), + mePhiList(alloc->Adapter()), meVarPiList(alloc->Adapter()), stmtNodeList(firstStmt, lastStmt), group(this) { @@ -293,8 +290,7 @@ class BB { void InsertMeStmtAfter(const MeStmt *meStmt, MeStmt *inStmt); void InsertMeStmtLastBr(MeStmt *inStmt); void ReplaceMeStmt(const MeStmt *stmt, MeStmt *newStmt); - void DumpMeVarPhiList(const IRMap *irMap); - void DumpMeRegPhiList(const IRMap *irMap); + void DumpMePhiList(const IRMap *irMap); void DumpMeVarPiList(const IRMap *irMap); StmtNodes &GetStmtNodes() { return stmtNodeList; @@ -393,20 +389,12 @@ class BB { phiList.clear(); } - MapleMap &GetMevarPhiList() { - return meVarPhiList; + MapleMap &GetMePhiList() { + return mePhiList; } - const MapleMap &GetMevarPhiList() const { - return meVarPhiList; - } - - MapleMap &GetMeRegPhiList() { - return meRegPhiList; - } - - const MapleMap &GetMeRegPhiList() const { - return meRegPhiList; + const MapleMap &GetMePhiList() const { + return mePhiList; } uint64 GetEdgeFreq(const BB *bb) const { @@ -462,8 +450,7 @@ class BB { // record the edge freq from curBB to succ BB MapleVector succFreq; MapleMap phiList; - MapleMap meVarPhiList; - MapleMap meRegPhiList; + MapleMap mePhiList; MapleMap> meVarPiList; uint32 frequency = 0; BBKind kind = kBBUnknown; diff --git a/src/maple_me/include/irmap.h b/src/maple_me/include/irmap.h old mode 100644 new mode 100755 index bf3937bedb..ad4d48691c --- a/src/maple_me/include/irmap.h +++ b/src/maple_me/include/irmap.h @@ -92,8 +92,7 @@ class IRMap : public AnalysisResult { IassignMeStmt *CreateIassignMeStmt(TyIdx, IvarMeExpr&, MeExpr&, const MapleMap&); RegassignMeStmt *CreateRegassignMeStmt(MeExpr&, MeExpr&, BB&); void InsertMeStmtBefore(BB&, MeStmt&, MeStmt&); - MeRegPhiNode *CreateMeRegPhi(RegMeExpr&); - MeVarPhiNode *CreateMeVarPhi(VarMeExpr&); + MePhiNode *CreateMePhi(ScalarMeExpr &); virtual void Dump() = 0; virtual void SetCurFunction(const BB&) {} diff --git a/src/maple_me/include/me_abco.h b/src/maple_me/include/me_abco.h old mode 100644 new mode 100755 index 652acd12b7..ed7e20c64f --- a/src/maple_me/include/me_abco.h +++ b/src/maple_me/include/me_abco.h @@ -55,12 +55,12 @@ class CarePoint { return value.meStmt; } - MeVarPhiNode *GetMePhi() { + MePhiNode *GetMePhi() { CHECK_FATAL(careKind == kMePhi, "must be"); return value.phiNode; } - const MeVarPhiNode *GetMePhi() const { + const MePhiNode *GetMePhi() const { CHECK_FATAL(careKind == kMePhi, "must be"); return value.phiNode; } @@ -70,7 +70,7 @@ class CarePoint { value.meStmt = &meStmt; } - void SetMePhi(MeVarPhiNode &phi) { + void SetMePhi(MePhiNode &phi) { CHECK_FATAL(careKind == kMePhi, "must be"); value.phiNode = φ } @@ -79,7 +79,7 @@ class CarePoint { CareKind careKind; union CareStmt { MeStmt *meStmt; - MeVarPhiNode *phiNode; + MePhiNode *phiNode; }; CareStmt value; }; @@ -109,7 +109,7 @@ class DefPoint { return value.pi; } - void SetDefPhi(MeVarPhiNode &s) { + void SetDefPhi(MePhiNode &s) { CHECK_FATAL(defKind == kDefByPhi, "must be"); value.phi = &s; } @@ -131,7 +131,7 @@ class DefPoint { if (defKind == kDefByPi) { return value.pi->GetRHS(); } else { - return value.phi->GetOpnd(0); + return static_cast(value.phi->GetOpnd(0)); } } @@ -139,7 +139,7 @@ class DefPoint { if (defKind == kDefByPi) { return value.pi->GetLHS(); } else { - return value.phi->GetLHS(); + return static_cast(value.phi->GetLHS()); } } @@ -172,7 +172,7 @@ class DefPoint { GetBB()->RemoveMeStmt(value.pi); } } else { - GetBB()->GetMevarPhiList().erase(GetOStIdx()); + GetBB()->GetMePhiList().erase(GetOStIdx()); } } @@ -190,7 +190,7 @@ class DefPoint { DefineKind defKind; union DefStmt { PiassignMeStmt *pi; - MeVarPhiNode *phi; + MePhiNode *phi; }; DefStmt value; }; @@ -237,16 +237,16 @@ class MeABC { bool ReplaceStmtWithNewVar(MeStmt &meStmt, MeExpr &oldVar, MeExpr &newVar, bool update); bool IsVirtualVar(const VarMeExpr &var, const SSATab &ssaTab) const; ESSABaseNode *GetOrCreateRHSNode(MeExpr &expr); - void BuildPhiInGraph(MeVarPhiNode &phi); + void BuildPhiInGraph(MePhiNode &phi); void BuildSoloPiInGraph(const PiassignMeStmt &piMeStmt); bool BuildArrayCheckInGraph(MeStmt &meStmt); bool BuildBrMeStmtInGraph(MeStmt &meStmt); bool BuildAssignInGraph(MeStmt &meStmt); - MeExpr *TryToResolveVar(MeExpr &expr, std::set &visitedPhi, MeExpr &dummyExpr, bool isConst); + MeExpr *TryToResolveVar(MeExpr &expr, std::set &visitedPhi, MeExpr &dummyExpr, bool isConst); bool BuildStmtInGraph(MeStmt &meStmt); void AddUseDef(MeExpr &meExpr); void AddCareInsn(MeStmt &defS); - void AddCarePhi(MeVarPhiNode &defP); + void AddCarePhi(MePhiNode &defP); void BuildInequalityGraph(); void FindRedundantABC(MeStmt &meStmt, NaryMeExpr &naryMeExpr); void InitNewStartPoint(const MeStmt &meStmt, const NaryMeExpr &nMeExpr); @@ -281,13 +281,13 @@ class MeABC { std::map arrayChecks; std::map arrayNewChecks; std::set careMeStmts; - std::set careMePhis; + std::set careMePhis; std::map> containsBB; std::vector newDefPoints; std::vector carePoints; std::map newDef2Old; std::map, MeExpr*, StmtComparator> modifiedStmt; - std::map> modifiedPhi; + std::map> modifiedPhi; std::set visitedBBs; std::set targetMeStmt; }; diff --git a/src/maple_me/include/me_cfg.h b/src/maple_me/include/me_cfg.h old mode 100644 new mode 100755 index 89d9f32658..49e441ef16 --- a/src/maple_me/include/me_cfg.h +++ b/src/maple_me/include/me_cfg.h @@ -54,9 +54,8 @@ class MeCFG { std::string ConstructFileNameToDump(const std::string &prefix) const; void DumpToFileInStrs(std::ofstream &cfgFile) const; void ConvertPhiList2IdentityAssigns(BB &meBB) const; - void ConvertMevarPhiList2IdentityAssigns(BB &meBB) const; - void ConvertMeregphiList2IdentityAssigns(BB &meBB) const; - bool IsStartTryBB(BB &meBB) const; + void ConvertMePhiList2IdentityAssigns(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/include/me_delegate_rc.h b/src/maple_me/include/me_delegate_rc.h old mode 100644 new mode 100755 index 40526cc8f9..a917028414 --- a/src/maple_me/include/me_delegate_rc.h +++ b/src/maple_me/include/me_delegate_rc.h @@ -50,7 +50,7 @@ class DelegateRC { bool ContainAllTheUses(const VarMeExpr &rhsVar, const MeStmt &fromStmt, const MeStmt &toStmt) const; RegMeExpr *RHSTempDelegated(MeExpr &rhs, const MeStmt &useStmt); bool FinalRefNoRC(const MeExpr &expr) const; - void SetCantDelegate(const MapleMap &meVarPhiList); + void SetCantDelegate(const MapleMap &meVarPhiList); void SaveDerefedOrCopiedVst(const MeExpr *expr); void CollectDerefedOrCopied(const MeStmt &stmt); void CollectDerefedOrCopied(const MeExpr &expr); diff --git a/src/maple_me/include/me_inequality_graph.h b/src/maple_me/include/me_inequality_graph.h old mode 100644 new mode 100755 index e24525e538..bc3f6c5436 --- a/src/maple_me/include/me_inequality_graph.h +++ b/src/maple_me/include/me_inequality_graph.h @@ -279,9 +279,9 @@ class ESSAPhiNode : public ESSABaseNode { return phiOpnds; } - void SetPhiOpnds(MapleVector &nodes) { + void SetPhiOpnds(MapleVector &nodes) { for (auto iter = nodes.begin(); iter != nodes.end(); ++iter) { - phiOpnds.push_back(*iter); + phiOpnds.push_back(static_cast(*iter)); } } const std::multimap &GetInPhiEdgeMap() const { @@ -314,7 +314,7 @@ class InequalityGraph { ESSAConstNode *GetOrCreateConstNode(int64 value); ESSAVarNode *GetOrCreateVarNode(MeExpr &meExpr); - ESSAPhiNode *GetOrCreatePhiNode(MeVarPhiNode &phiNode); + ESSAPhiNode *GetOrCreatePhiNode(MePhiNode &phiNode); ESSAArrayNode *GetOrCreateArrayNode(MeExpr &meExpr); InequalEdge *AddEdge(ESSABaseNode &from, ESSABaseNode &to, int64 value, EdgeType type); void AddPhiEdge(ESSABaseNode &from, ESSABaseNode &to, EdgeType type); diff --git a/src/maple_me/include/me_ir.h b/src/maple_me/include/me_ir.h old mode 100644 new mode 100755 index fc2682d174..642540ccb3 --- a/src/maple_me/include/me_ir.h +++ b/src/maple_me/include/me_ir.h @@ -194,44 +194,52 @@ class ChiMeNode; // circular dependency exists, no other choice class MustDefMeNode; // circular dependency exists, no other choice class IassignMeStmt; // circular dependency exists, no other choice -// represant dread -class VarMeExpr final : public MeExpr { +// base class for VarMeExpr and RegMeExpr +class ScalarMeExpr : public MeExpr { public: - VarMeExpr(MapleAllocator *alloc, int32 exprid, OStIdx oidx, size_t vidx) - : MeExpr(exprid, kMeOpVar), - ostIdx(oidx), - vstIdx(vidx), - inferredTypeCandidates(alloc->Adapter()) {} + ScalarMeExpr(int32 exprid, OStIdx oidx, uint32 vidx, MeExprOp meop) + : MeExpr(exprid, meop), + ostIdx(oidx), + vstIdx(vidx), + defBy(kDefByNo) { + def.defStmt = nullptr; + } - ~VarMeExpr() = default; + ~ScalarMeExpr() = default; - void Dump(const IRMap*, int32 indent = 0) const override; + bool IsIdentical(MeExpr &meexpr) { + CHECK_FATAL(false, "ScalarMeExpr::IsIdentical() should not be called"); + return true; + } bool IsUseSameSymbol(const MeExpr&) const override; - BaseNode &EmitExpr(SSATab&) override; - bool IsValidVerIdx(const SSATab &ssaTab) const; - void SetDefByStmt(MeStmt &defStmt) override { + + void SetDefByStmt(MeStmt &defStmt) override { defBy = kDefByStmt; def.defStmt = &defStmt; } - - MeVarPhiNode *GetMeVarPhiDef() const { + + MePhiNode *GetMePhiDef() const { return IsDefByPhi() ? def.defPhi : nullptr; } - BB *DefByBB(); - bool IsVolatile(const SSATab&) const override; - // indicate if the variable is local variable but not a function formal variable - bool IsPureLocal(const SSATab&, const MIRFunction&) const; - bool IsZeroVersion(const SSATab&) const; - BB *GetDefByBBMeStmt(const Dominance&, MeStmtPtr&) const; - bool IsSameVariableValue(const VarMeExpr&) const override; - VarMeExpr &ResolveVarMeValue(); - bool PointsToStringLiteral(); + bool IsDefByNo() const { + return defBy == kDefByNo; + } + + bool IsDefByPhi() const { + return defBy == kDefByPhi; + } + + BB *DefByBB() const; const OStIdx &GetOStIdx() const { return ostIdx; } + OStIdx GetOstIdx() const { + return ostIdx; + } + size_t GetVstIdx() const { return vstIdx; } @@ -240,34 +248,6 @@ class VarMeExpr final : public MeExpr { vstIdx = vstIdxVal; } - FieldID GetFieldID() const { - return fieldID; - } - - void SetFieldID(FieldID fieldIDVal) { - fieldID = fieldIDVal; - } - - TyIdx GetInferredTyIdx() const { - return inferredTyIdx; - } - - void SetInferredTyIdx(TyIdx inferredTyIdxVal) { - inferredTyIdx = inferredTyIdxVal; - } - - const MapleVector &GetInferredTypeCandidates() const { - return inferredTypeCandidates; - } - - void AddInferredTypeCandidate(TyIdx idx) { - inferredTypeCandidates.push_back(idx); - } - - void ClearInferredTypeCandidates() { - inferredTypeCandidates.clear(); - } - MeDefBy GetDefBy() const { return defBy; } @@ -276,22 +256,6 @@ class VarMeExpr final : public MeExpr { defBy = defByVal; } - bool GetMaybeNull() const { - return maybeNull; - } - - void SetMaybeNull(bool maybeNullVal) { - maybeNull = maybeNullVal; - } - - bool GetNoDelegateRC() const { - return noDelegateRC; - } - - void SetNoDelegateRC(bool noDelegateRCVal) { - noDelegateRC = noDelegateRCVal; - } - MeStmt *GetDefStmt() const { return def.defStmt; } @@ -300,15 +264,15 @@ class VarMeExpr final : public MeExpr { def.defStmt = defStmt; } - MeVarPhiNode &GetDefPhi() { + MePhiNode &GetDefPhi() { return *def.defPhi; } - const MeVarPhiNode &GetDefPhi() const { + const MePhiNode &GetDefPhi() const { return *def.defPhi; } - void SetDefPhi(MeVarPhiNode &defPhi) { + void SetDefPhi(MePhiNode &defPhi) { def.defPhi = &defPhi; } @@ -337,64 +301,131 @@ class VarMeExpr final : public MeExpr { } private: - bool IsDefByPhi() const { - return defBy == kDefByPhi; - } - bool noDelegateRC = false; // true if this cannot be optimized by delegaterc + OStIdx ostIdx; // the index in MEOptimizer's OriginalStTable; + uint32 vstIdx; // the index in MEOptimizer's VersionStTable, 0 if not in VersionStTable + MeDefBy defBy : 3; union { - MeStmt *defStmt = nullptr; // definition stmt of this var - MeVarPhiNode *defPhi; + MeStmt *defStmt; // definition stmt of this var + MePhiNode *defPhi; ChiMeNode *defChi; // definition node by Chi MustDefMeNode *defMustDef; // definition by callassigned - } def; + } def; +}; + - OStIdx ostIdx; // the index in MEOptimizer's OriginalStTable; - size_t vstIdx; // the index in MEOptimizer's VersionStTable, 0 if not in VersionStTable + + +// represant dread +class VarMeExpr final : public ScalarMeExpr { + public: + VarMeExpr(MapleAllocator *alloc, int32 exprid, OStIdx oidx, size_t vidx) + : ScalarMeExpr(exprid, oidx, vidx, kMeOpVar), + inferredTypeCandidates(alloc->Adapter()) {} + + ~VarMeExpr() = default; + + void Dump(const IRMap*, int32 indent = 0) const override; + BaseNode &EmitExpr(SSATab&) override; + bool IsValidVerIdx(const SSATab &ssaTab) const; + + bool IsVolatile(const SSATab&) const override; + // indicate if the variable is local variable but not a function formal variable + bool IsPureLocal(const SSATab&, const MIRFunction&) const; + bool IsZeroVersion(const SSATab&) const; + bool IsSameVariableValue(const VarMeExpr&) const override; + VarMeExpr &ResolveVarMeValue(); + bool PointsToStringLiteral(); + + FieldID GetFieldID() const { + return fieldID; + } + + void SetFieldID(FieldID fieldIDVal) { + fieldID = fieldIDVal; + } + + TyIdx GetInferredTyIdx() const { + return inferredTyIdx; + } + + void SetInferredTyIdx(TyIdx inferredTyIdxVal) { + inferredTyIdx = inferredTyIdxVal; + } + + const MapleVector &GetInferredTypeCandidates() const { + return inferredTypeCandidates; + } + + void AddInferredTypeCandidate(TyIdx idx) { + inferredTypeCandidates.push_back(idx); + } + + void ClearInferredTypeCandidates() { + inferredTypeCandidates.clear(); + } + + bool GetMaybeNull() const { + return maybeNull; + } + + void SetMaybeNull(bool maybeNullVal) { + maybeNull = maybeNullVal; + } + + bool GetNoDelegateRC() const { + return noDelegateRC; + } + + void SetNoDelegateRC(bool noDelegateRCVal) { + noDelegateRC = noDelegateRCVal; + } + + private: + bool noDelegateRC = false; // true if this cannot be optimized by delegaterc FieldID fieldID = 0; TyIdx inferredTyIdx{ 0 }; /* Non zero if it has a known type (allocation type is seen). */ MapleVector inferredTypeCandidates; - MeDefBy defBy = kDefByNo; bool maybeNull = true; // false if definitely not null }; -class MeVarPhiNode { +class MePhiNode { public: - explicit MeVarPhiNode(MapleAllocator *alloc) + explicit MePhiNode(MapleAllocator *alloc) : opnds(kOperandNumBinary, nullptr, alloc->Adapter()) { opnds.pop_back(); opnds.pop_back(); } - MeVarPhiNode(VarMeExpr *var, MapleAllocator *alloc) - : lhs(var), opnds(kOperandNumBinary, nullptr, alloc->Adapter()) { - var->SetDefPhi(*this); - var->SetDefBy(kDefByPhi); + MePhiNode(ScalarMeExpr *expr, MapleAllocator *alloc) + : lhs(expr), opnds(kOperandNumBinary, nullptr, alloc->Adapter()) { + expr->SetDefPhi(*this); + expr->SetDefBy(kDefByPhi); opnds.pop_back(); opnds.pop_back(); } - ~MeVarPhiNode() = default; + ~MePhiNode() = default; - void UpdateLHS(VarMeExpr &var) { - lhs = &var; - var.SetDefBy(kDefByPhi); - var.SetDefPhi(*this); + void UpdateLHS(ScalarMeExpr &expr) { + lhs = &expr; + expr.SetDefBy(kDefByPhi); + expr.SetDefPhi(*this); } bool IsPureLocal(const SSATab &ssaTab, const MIRFunction &mirFunc); void Dump(const IRMap *irMap) const; - VarMeExpr *GetOpnd(size_t idx) const { - ASSERT(idx < opnds.size(), "out of range in MeVarPhiNode::GetOpnd"); + ScalarMeExpr *GetOpnd(size_t idx) const { + ASSERT(idx < opnds.size(), "out of range in MePhiNode::GetOpnd"); return opnds.at(idx); } - void SetOpnd(size_t idx, VarMeExpr *opnd) { - CHECK_FATAL(idx < opnds.size(), "out of range in MeVarPhiNode::SetOpnd"); + void SetOpnd(size_t idx, ScalarMeExpr *opnd) { + CHECK_FATAL(idx < opnds.size(), "out of range in MePhiNode::SetOpnd"); opnds[idx] = opnd; } - MapleVector &GetOpnds() { + MapleVector &GetOpnds() { return opnds; } @@ -418,11 +449,11 @@ class MeVarPhiNode { return defBB; } - VarMeExpr *GetLHS() { + ScalarMeExpr *GetLHS() { return lhs; } - void SetLHS(VarMeExpr *value) { + void SetLHS(ScalarMeExpr *value) { lhs = value; } @@ -435,44 +466,26 @@ class MeVarPhiNode { } private: - VarMeExpr *lhs = nullptr; - MapleVector opnds; + ScalarMeExpr *lhs = nullptr; + MapleVector opnds; bool isLive = true; BB *defBB = nullptr; // the bb that defines this phi bool isPiAdded = false; }; -class RegMeExpr : public MeExpr { +class RegMeExpr : public ScalarMeExpr { public: RegMeExpr(MapleAllocator *alloc, int32 exprid, PregIdx preg, PUIdx pidx, OStIdx oidx, uint32 vidx) - : MeExpr(exprid, kMeOpReg), + : ScalarMeExpr(exprid, oidx, vidx, kMeOpReg), regIdx(preg), puIdx(pidx), - ostIdx(oidx), - vstIdx(vidx), - phiUseSet(std::less(), alloc->Adapter()) {} + phiUseSet(std::less(), alloc->Adapter()) {} ~RegMeExpr() = default; void Dump(const IRMap*, int32 indent = 0) const override; BaseNode &EmitExpr(SSATab&) override; - void SetDefByStmt(MeStmt &defStmt) override { - defBy = kDefByStmt; - def.defStmt = &defStmt; - } - - bool IsDefByPhi() const { - return defBy == kDefByPhi; - } - - MeRegPhiNode *GetMeRegPhiDef() const { - return IsDefByPhi() ? def.defPhi : nullptr; - } - bool IsSameVariableValue(const VarMeExpr&) const override; - - bool IsUseSameSymbol(const MeExpr&) const override; - BB *DefByBB(); RegMeExpr *FindDefByStmt(std::set &visited); PregIdx16 GetRegIdx() const { @@ -483,77 +496,26 @@ class RegMeExpr : public MeExpr { regIdx = regIdxVal; } - MeDefBy GetDefBy() const { - return defBy; - } - - void SetDefBy(MeDefBy defByVal) { - defBy = defByVal; - } - PUIdx GetPuIdx() const { return puIdx; } - OStIdx GetOstIdx() const { - return ostIdx; - } - - MapleSet &GetPhiUseSet() { + MapleSet &GetPhiUseSet() { return phiUseSet; } - MeStmt *GetDefStmt() const { - return def.defStmt; - } - - MeRegPhiNode &GetDefPhi() { - return *def.defPhi; - } - - const MeRegPhiNode &GetDefPhi() const { - return *def.defPhi; - } - - MustDefMeNode &GetDefMustDef() { - return *def.defMustDef; - } - - const MustDefMeNode &GetDefMustDef() const { - return *def.defMustDef; - } - - void SetDefStmt(MeStmt *defStmtVal) { - def.defStmt = defStmtVal; - } - - void SetDefPhi(MeRegPhiNode &defPhiVal) { - def.defPhi = &defPhiVal; - } - - void SetDefMustDef(MustDefMeNode &defMustDefVal) { - def.defMustDef = &defMustDefVal; - } - bool IsNormalReg() const { return regIdx >= 0; } private: - union { - MeStmt *defStmt = nullptr; - MeRegPhiNode *defPhi; - MustDefMeNode *defMustDef; // definition by callassigned - } def; PregIdx16 regIdx; - MeDefBy defBy = kDefByNo; bool recursivePtr = false; // if pointer to recursive data structures; PUIdx puIdx; - OStIdx ostIdx; // the index in MEOptimizer's OriginalStTable; - uint32 vstIdx; // the index in MEOptimizer's VersionStTable, 0 if not in VersionStTable - MapleSet phiUseSet; // the use set of this reg node, used by preg renamer + MapleSet phiUseSet; // the use set of this reg node, used by preg renamer }; +#if 0 class MeRegPhiNode { public: explicit MeRegPhiNode(MapleAllocator *alloc) @@ -616,6 +578,7 @@ class MeRegPhiNode { bool isLive = true; BB *defBB = nullptr; // the bb that defines this phi }; +#endif class ConstMeExpr : public MeExpr { public: diff --git a/src/maple_me/include/me_ssa_update.h b/src/maple_me/include/me_ssa_update.h old mode 100644 new mode 100755 index 7379d40373..135e2ef650 --- a/src/maple_me/include/me_ssa_update.h +++ b/src/maple_me/include/me_ssa_update.h @@ -52,7 +52,7 @@ class MeSSAUpdate { MemPool &ssaUpdateMp; MapleAllocator ssaUpdateAlloc; MapleMap*> &updateCands; - MapleMap*> renameStacks; + MapleMap*> renameStacks; }; } // namespace maple #endif // MAPLE_ME_INCLUDE_ME_SSA_UPDATE_H diff --git a/src/maple_me/include/me_ssu_pre.h b/src/maple_me/include/me_ssu_pre.h old mode 100644 new mode 100755 index 34c0431bb9..2bd94d5746 --- a/src/maple_me/include/me_ssu_pre.h +++ b/src/maple_me/include/me_ssu_pre.h @@ -251,15 +251,15 @@ class SUseOcc : public SOcc { class SPhiOcc : public SOcc { public: - SPhiOcc(BB &bb, MeVarPhiNode &p, VarMeExpr &v) : SOcc(kSOccPhi, bb), phi(&p), vMeExpr(&v) {}; + SPhiOcc(BB &bb, MePhiNode &p, VarMeExpr &v) : SOcc(kSOccPhi, bb), phi(&p), vMeExpr(&v) {}; virtual ~SPhiOcc() = default; - MeVarPhiNode *GetPhiNode() { + MePhiNode *GetPhiNode() { return phi; } - const MeVarPhiNode *GetPhiNode() const { + const MePhiNode *GetPhiNode() const { return phi; } @@ -276,7 +276,7 @@ class SPhiOcc : public SOcc { } private: - MeVarPhiNode *phi; // the phinode of this real occurrence; + MePhiNode *phi; // the phinode of this real occurrence; VarMeExpr *vMeExpr; // the varmeexpr of this real occurrence }; diff --git a/src/maple_me/include/me_stmt_pre.h b/src/maple_me/include/me_stmt_pre.h old mode 100644 new mode 100755 index e51d86863f..76494f0dd4 --- a/src/maple_me/include/me_stmt_pre.h +++ b/src/maple_me/include/me_stmt_pre.h @@ -44,7 +44,7 @@ class MeStmtPre : public SSAEPre { protected: MapleMap*> candsForSSAUpdate; MeFunction *func; - MapleVector*> versionStackVec; // top of stack gives last version during BuildWorkList() + MapleVector*> versionStackVec; // top of stack gives last version during BuildWorkList() MapleMap*> useOccurMap; // give the set of BBs (in dfn) that contain uses of the symbol private: diff --git a/src/maple_me/include/occur.h b/src/maple_me/include/occur.h old mode 100644 new mode 100755 index bb4f4f0f16..42e4e6d041 --- a/src/maple_me/include/occur.h +++ b/src/maple_me/include/occur.h @@ -447,27 +447,27 @@ class MePhiOcc : public MeOccur { phiOpnds.push_back(&opnd); } - const MeRegPhiNode *GetRegPhi() const { + const MePhiNode *GetRegPhi() const { return regPhi; } - MeRegPhiNode *GetRegPhi() { + MePhiNode *GetRegPhi() { return regPhi; } - void SetRegPhi(MeRegPhiNode &phi) { + void SetRegPhi(MePhiNode &phi) { regPhi = φ } - const MeVarPhiNode *GetVarPhi() const { + const MePhiNode *GetVarPhi() const { return varPhi; } - MeVarPhiNode *GetVarPhi() { + MePhiNode *GetVarPhi() { return varPhi; } - void SetVarPhi(MeVarPhiNode &phi) { + void SetVarPhi(MePhiNode &phi) { varPhi = φ } @@ -482,8 +482,8 @@ class MePhiOcc : public MeOccur { bool isExtraneous; bool isRemoved; // during finalize2, marked this phiocc is removed or not MapleVector phiOpnds; - MeRegPhiNode *regPhi; // the reg phi being inserted, maybe can delete it later - MeVarPhiNode *varPhi; // the Var phi being inserted, maybe can delete it later + MePhiNode *regPhi; // the reg phi being inserted, maybe can delete it later + MePhiNode *varPhi; // the Var phi being inserted, maybe can delete it later }; // each singly linked list repersents each bucket in workCandHashTable diff --git a/src/maple_me/include/ssa_devirtual.h b/src/maple_me/include/ssa_devirtual.h old mode 100644 new mode 100755 index f453ef994a..affb5f301a --- a/src/maple_me/include/ssa_devirtual.h +++ b/src/maple_me/include/ssa_devirtual.h @@ -62,7 +62,7 @@ class SSADevirtual { virtual BB *GetBB(BBId id) const = 0; void TraversalBB(BB*); void TraversalMeStmt(MeStmt &Stmt); - void VisitVarPhiNode(MeVarPhiNode&) const; + void VisitVarPhiNode(MePhiNode&) const; void VisitMeExpr(MeExpr*) const; void PropVarInferredType(VarMeExpr&) const; void PropIvarInferredType(IvarMeExpr&) const; diff --git a/src/maple_me/src/bb.cpp b/src/maple_me/src/bb.cpp old mode 100644 new mode 100755 index 74088e86c1..6207c0722d --- a/src/maple_me/src/bb.cpp +++ b/src/maple_me/src/bb.cpp @@ -154,11 +154,7 @@ void BB::RemovePhiOpnd(int index) { ASSERT(phi.second.GetPhiOpnds().size() > index, "index out of range in BB::RemovePhiOpnd"); phi.second.GetPhiOpnds().erase(phi.second.GetPhiOpnds().cbegin() + index); } - for (auto &phi : meVarPhiList) { - ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemovePhiOpnd"); - phi.second->GetOpnds().erase(phi.second->GetOpnds().cbegin() + index); - } - for (auto &phi : meRegPhiList) { + for (auto &phi : mePhiList) { ASSERT(phi.second->GetOpnds().size() > index, "index out of range in BB::RemovePhiOpnd"); phi.second->GetOpnds().erase(phi.second->GetOpnds().cbegin() + index); } @@ -368,21 +364,15 @@ void BB::DumpMeVarPiList(const IRMap *irMap) { std::cout << "<<<<<<<<<<<<<< PI Node End >>>>>>>>>>>>>>>>>>>>\n"; } -void BB::DumpMeVarPhiList(const IRMap *irMap) { +void BB::DumpMePhiList(const IRMap *irMap) { int count = 0; - for (const auto &phi : meVarPhiList) { + for (const auto &phi : mePhiList) { phi.second->Dump(irMap); int dumpVsyNum = DumpOptions::GetDumpVsyNum(); if (dumpVsyNum > 0 && ++count >= dumpVsyNum) { break; } - ASSERT(count >= 0, "meVarPhiList too large"); - } -} - -void BB::DumpMeRegPhiList(const IRMap *irMap) { - for (const auto &phi : meRegPhiList) { - phi.second->Dump(irMap); + ASSERT(count >= 0, "mePhiList too large"); } } diff --git a/src/maple_me/src/hdse.cpp b/src/maple_me/src/hdse.cpp old mode 100644 new mode 100755 index dd89a0c616..bebac82d41 --- a/src/maple_me/src/hdse.cpp +++ b/src/maple_me/src/hdse.cpp @@ -520,12 +520,10 @@ void HDSE::DseInit() { continue; } // mark phi nodes dead - for (std::pair varPhiPair : bb->GetMevarPhiList()) { - varPhiPair.second->SetIsLive(false); - } - for (std::pair regPhiPair : bb->GetMeRegPhiList()) { - regPhiPair.second->SetIsLive(false); + for (std::pair phiPair : bb->GetMePhiList()) { + phiPair.second->SetIsLive(false); } + for (auto &stmt : bb->GetMeStmts()) { // mark stmt dead stmt.SetIsLive(false); diff --git a/src/maple_me/src/irmap.cpp b/src/maple_me/src/irmap.cpp old mode 100644 new mode 100755 index c85e5e1a9c..bbab3d0d81 --- a/src/maple_me/src/irmap.cpp +++ b/src/maple_me/src/irmap.cpp @@ -54,7 +54,7 @@ void IRMap::BuildPhiMeNode(BB &bb) { const OriginalSt *oSt = phi.first; VersionSt *vSt = phi.second.GetResult(); if (oSt->IsPregOst()) { - auto *phiMeNode = NewInPool(); + auto *phiMeNode = NewInPool(); RegMeExpr *meDef = GetOrCreateRegFromVerSt(*vSt); phiMeNode->UpdateLHS(*meDef); phiMeNode->SetDefBB(&bb); @@ -62,9 +62,9 @@ void IRMap::BuildPhiMeNode(BB &bb) { for (VersionSt *opnd : phi.second.GetPhiOpnds()) { phiMeNode->GetOpnds().push_back(GetOrCreateRegFromVerSt(*opnd)); } - bb.GetMeRegPhiList().insert(std::make_pair(meDef->GetOstIdx(), phiMeNode)); + bb.GetMePhiList().insert(std::make_pair(meDef->GetOstIdx(), phiMeNode)); } else { - auto *phiMeNode = NewInPool(); + auto *phiMeNode = NewInPool(); VarMeExpr *meDef = GetOrCreateVarFromVerSt(*vSt); phiMeNode->UpdateLHS(*meDef); phiMeNode->SetDefBB(&bb); @@ -72,7 +72,7 @@ void IRMap::BuildPhiMeNode(BB &bb) { for (VersionSt *opnd : phi.second.GetPhiOpnds()) { phiMeNode->GetOpnds().push_back(GetOrCreateVarFromVerSt(*opnd)); } - bb.GetMevarPhiList().insert(std::make_pair(meDef->GetOStIdx(), phiMeNode)); + bb.GetMePhiList().insert(std::make_pair(meDef->GetOStIdx(), phiMeNode)); } } } @@ -803,14 +803,8 @@ bool IRMap::ReplaceMeExprStmt(MeStmt &meStmt, const MeExpr &meExpr, MeExpr &repe return isReplaced; } -MeRegPhiNode *IRMap::CreateMeRegPhi(RegMeExpr &meVar) { - auto *phiMeReg = NewInPool(); - phiMeReg->UpdateLHS(meVar); - return phiMeReg; -} - -MeVarPhiNode *IRMap::CreateMeVarPhi(VarMeExpr &meVar) { - auto *phiMeVar = NewInPool(); +MePhiNode *IRMap::CreateMePhi(ScalarMeExpr &meVar) { + auto *phiMeVar = NewInPool(); phiMeVar->UpdateLHS(meVar); return phiMeVar; } diff --git a/src/maple_me/src/irmap_emit.cpp b/src/maple_me/src/irmap_emit.cpp old mode 100644 new mode 100755 index 36eaaa40f6..ff5a0314c6 --- a/src/maple_me/src/irmap_emit.cpp +++ b/src/maple_me/src/irmap_emit.cpp @@ -20,7 +20,7 @@ namespace maple { bool VarMeExpr::IsValidVerIdx(const SSATab &ssaTab) const { - const OriginalSt *ost = ssaTab.GetOriginalStFromID(ostIdx); + const OriginalSt *ost = ssaTab.GetOriginalStFromID(GetOStIdx()); if (ost == nullptr || !ost->IsSymbolOst()) { return false; } diff --git a/src/maple_me/src/me_abco.cpp b/src/maple_me/src/me_abco.cpp old mode 100644 new mode 100755 index 68829714dc..f37044ed49 --- a/src/maple_me/src/me_abco.cpp +++ b/src/maple_me/src/me_abco.cpp @@ -183,7 +183,7 @@ bool MeABC::CollectABC() { } bool MeABC::ExistedPhiNode(BB &bb, VarMeExpr &rhs) { - return bb.GetMevarPhiList().find(rhs.GetOStIdx()) != bb.GetMevarPhiList().end(); + return bb.GetMePhiList().find(rhs.GetOStIdx()) != bb.GetMePhiList().end(); } bool MeABC::ExistedPiNode(BB &bb, BB &parentBB, const VarMeExpr &rhs) { @@ -211,11 +211,11 @@ bool MeABC::ExistedPiNode(BB &bb, BB &parentBB, const VarMeExpr &rhs) { void MeABC::CreatePhi(VarMeExpr &rhs, BB &dfBB) { VarMeExpr *phiNewLHS = CreateNewPiExpr(rhs); ASSERT_NOT_NULL(phiNewLHS); - MeVarPhiNode *newPhi = GetMemPool()->New(phiNewLHS, &GetAllocator()); + MePhiNode *newPhi = GetMemPool()->New(phiNewLHS, &GetAllocator()); newPhi->SetDefBB(&dfBB); newPhi->GetOpnds().resize(dfBB.GetPred().size(), &rhs); newPhi->SetPiAdded(); - dfBB.GetMevarPhiList().insert(std::make_pair(phiNewLHS->GetOStIdx(), newPhi)); + dfBB.GetMePhiList().insert(std::make_pair(phiNewLHS->GetOStIdx(), newPhi)); DefPoint *newDef = GetMemPool()->New(DefPoint::DefineKind::kDefByPhi); newDef->SetDefPhi(*newPhi); newDefPoints.push_back(newDef); @@ -266,7 +266,7 @@ void MeABC::RenameStartPiBr(DefPoint &newDefPoint) { RenameStartPhi(newDefPoint); return; } - MeVarPhiNode* phi = newDefBB->GetMevarPhiList()[ostIdx]; + MePhiNode* phi = newDefBB->GetMePhiList()[ostIdx]; BB *genByBB = newDefPoint.GetGeneratedByBB(); size_t index = 0; while (index < newDefBB->GetPred().size()) { @@ -276,11 +276,11 @@ void MeABC::RenameStartPiBr(DefPoint &newDefPoint) { ++index; } CHECK_FATAL(index < newDefBB->GetPred().size(), "must be"); - VarMeExpr *oldVar = phi->GetOpnd(index); + ScalarMeExpr*oldVar = phi->GetOpnd(index); phi->SetOpnd(index, newDefPoint.GetLHS()); if (!phi->IsPiAdded()) { if (modifiedPhi.find(phi) == modifiedPhi.end()) { - modifiedPhi[phi] = std::vector(phi->GetOpnds().size(), nullptr); + modifiedPhi[phi] = std::vector(phi->GetOpnds().size(), nullptr); } if (modifiedPhi[phi][index] == nullptr) { modifiedPhi[phi][index] = oldVar; @@ -349,15 +349,15 @@ void MeABC::ReplacePiPhiInSuccs(BB &bb, VarMeExpr &newVar) { ++index; } CHECK_FATAL(index < succBB->GetPred().size(), "must be"); - MapleMap &phiList = succBB->GetMevarPhiList(); + MapleMap &phiList = succBB->GetMePhiList(); auto it2 = phiList.find(newVar.GetOStIdx()); if (it2 != phiList.end()) { - MeVarPhiNode *phi = it2->second; - VarMeExpr *oldVar = phi->GetOpnd(index); + MePhiNode *phi = it2->second; + ScalarMeExpr*oldVar = phi->GetOpnd(index); phi->SetOpnd(index, &newVar); if (!phi->IsPiAdded()) { if (modifiedPhi.find(phi) == modifiedPhi.end()) { - modifiedPhi[phi] = std::vector(phi->GetOpnds().size(), nullptr); + modifiedPhi[phi] = std::vector(phi->GetOpnds().size(), nullptr); } if (modifiedPhi[phi][index] == nullptr) { modifiedPhi[phi][index] = oldVar; @@ -587,10 +587,10 @@ void MeABC::RemoveExtraNodes() { CHECK_FATAL(replaced, "must be"); } for (auto pair : modifiedPhi) { - MeVarPhiNode *phi = pair.first; + MePhiNode *phi = pair.first; for (size_t i = 0; i < pair.second.size(); ++i) { size_t index = i; - VarMeExpr *oldVar = pair.second[i]; + ScalarMeExpr*oldVar = pair.second[i]; if (oldVar != nullptr) { phi->SetOpnd(index, oldVar); } @@ -610,16 +610,16 @@ ESSABaseNode *MeABC::GetOrCreateRHSNode(MeExpr &expr) { if (rhs.GetDefBy() != kDefByPhi) { result = inequalityGraph->GetOrCreateVarNode(rhs); } else { - MeVarPhiNode *defPhi = &(rhs.GetDefPhi()); + MePhiNode *defPhi = &(rhs.GetDefPhi()); result = inequalityGraph->GetOrCreatePhiNode(*defPhi); } return result; } -void MeABC::BuildPhiInGraph(MeVarPhiNode &phi) { +void MeABC::BuildPhiInGraph(MePhiNode &phi) { if (!IsPrimitivePureScalar(phi.GetLHS()->GetPrimType())) { MeExpr *varExpr = phi.GetLHS(); - std::set visitedPhi; + std::set visitedPhi; ConstMeExpr dummyExpr(kInvalidExprID, nullptr); varExpr = TryToResolveVar(*varExpr, visitedPhi, dummyExpr, false); if (varExpr != nullptr && varExpr != &dummyExpr) { @@ -632,10 +632,11 @@ void MeABC::BuildPhiInGraph(MeVarPhiNode &phi) { } return; } - if (IsVirtualVar(*(phi.GetLHS()), irMap->GetSSATab())) { + VarMeExpr *lhsExpr = static_cast(phi.GetLHS()); + if (lhsExpr !=nullptr && IsVirtualVar(*lhsExpr, irMap->GetSSATab())) { return; } - for (VarMeExpr *phiRHS : phi.GetOpnds()) { + for (ScalarMeExpr *phiRHS : phi.GetOpnds()) { AddUseDef(*phiRHS); } } @@ -794,7 +795,7 @@ bool MeABC::BuildBrMeStmtInGraph(MeStmt &meStmt) { return true; } -MeExpr *MeABC::TryToResolveVar(MeExpr &expr, std::set &visitedPhi, MeExpr &dummyExpr, bool isConst) { +MeExpr *MeABC::TryToResolveVar(MeExpr &expr, std::set &visitedPhi, MeExpr &dummyExpr, bool isConst) { CHECK_FATAL(expr.GetMeOp() == kMeOpVar, "must be"); auto *var = static_cast(&expr); @@ -818,13 +819,13 @@ MeExpr *MeABC::TryToResolveVar(MeExpr &expr, std::set &visitedPhi } if (var->GetDefBy() == kDefByPhi) { - MeVarPhiNode *phi = &(var->GetDefPhi()); + MePhiNode *phi = &(var->GetDefPhi()); if (visitedPhi.find(phi) != visitedPhi.end()) { return &dummyExpr; } visitedPhi.insert(phi); std::set res; - for (VarMeExpr *phiOpnd : phi->GetOpnds()) { + for (ScalarMeExpr *phiOpnd : phi->GetOpnds()) { MeExpr *tmp = TryToResolveVar(*phiOpnd, visitedPhi, dummyExpr, isConst); if (tmp == nullptr) { return nullptr; @@ -870,7 +871,7 @@ bool MeABC::BuildAssignInGraph(MeStmt &meStmt) { AddUseDef(*(opMeExpr->GetOpnd(0))); // Try to resolve Var is assigned from Const MeExpr *varExpr = opMeExpr->GetOpnd(0); - std::set visitedPhi; + std::set visitedPhi; ConstMeExpr dummyExpr(kInvalidExprID, nullptr); varExpr = TryToResolveVar(*varExpr, visitedPhi, dummyExpr, true); if (varExpr != nullptr && varExpr != &dummyExpr) { @@ -920,7 +921,7 @@ bool MeABC::BuildAssignInGraph(MeStmt &meStmt) { } } else if (opnd1->GetMeOp() == kMeOpVar && opnd2->GetMeOp() == kMeOpVar) { // Try to resolve Var is assigned from Const - std::set visitedPhi; + std::set visitedPhi; ConstMeExpr dummyExpr(kInvalidExprID, nullptr); opnd2 = TryToResolveVar(*opnd2, visitedPhi, dummyExpr, true); if (opnd2 == nullptr || opnd2 == &dummyExpr) { @@ -1122,8 +1123,8 @@ void MeABC::AddCareInsn(MeStmt &defS) { careMeStmts.insert(defStmt); } } -void MeABC::AddCarePhi(MeVarPhiNode &defP) { - MeVarPhiNode *defPhi = &defP; +void MeABC::AddCarePhi(MePhiNode &defP) { + MePhiNode *defPhi = &defP; if (careMePhis.find(defPhi) == careMePhis.end()) { CarePoint *carePoint = GetMemPool()->New(CarePoint::CareKind::kMePhi); carePoint->SetMePhi(*defPhi); @@ -1153,7 +1154,7 @@ void MeABC::AddUseDef(MeExpr &meExpr) { break; } case kDefByPhi: { - MeVarPhiNode *defPhi = &varOpnd1->GetDefPhi(); + MePhiNode *defPhi = &varOpnd1->GetDefPhi(); AddCarePhi(*defPhi); break; } diff --git a/src/maple_me/src/me_analyze_rc.cpp b/src/maple_me/src/me_analyze_rc.cpp old mode 100644 new mode 100755 index 19bdbf8a9e..5adbd999b2 --- a/src/maple_me/src/me_analyze_rc.cpp +++ b/src/maple_me/src/me_analyze_rc.cpp @@ -249,8 +249,8 @@ void AnalyzeRC::RenameRefPtrs(BB *bb) { // record stack size savedStacksize[rcItem] = rcItem->versionStack.size(); // if there is a phi, push stack - auto phiIt = bb->GetMevarPhiList().find(mapItem.second->ost.GetIndex()); - if (phiIt != bb->GetMevarPhiList().end()) { + auto phiIt = bb->GetMePhiList().find(mapItem.second->ost.GetIndex()); + if (phiIt != bb->GetMePhiList().end()) { rcItem->versionStack.push((*phiIt).second->GetLHS()); } } diff --git a/src/maple_me/src/me_cfg.cpp b/src/maple_me/src/me_cfg.cpp old mode 100644 new mode 100755 index f5dd09577c..9842270b7b --- a/src/maple_me/src/me_cfg.cpp +++ b/src/maple_me/src/me_cfg.cpp @@ -556,42 +556,23 @@ void MeCFG::ConvertPhiList2IdentityAssigns(BB &meBB) const { meBB.ClearPhiList(); // delete all the phis } -void MeCFG::ConvertMevarPhiList2IdentityAssigns(BB &meBB) const { - auto varPhiIt = meBB.GetMevarPhiList().begin(); - while (varPhiIt != meBB.GetMevarPhiList().end()) { +void MeCFG::ConvertMePhiList2IdentityAssigns(BB &meBB) const { + auto PhiIt = meBB.GetMePhiList().begin(); + while (PhiIt != meBB.GetMePhiList().end()) { // replace phi with identify assignment as it only has 1 opnd - const OriginalSt *ost = func.GetMeSSATab()->GetOriginalStFromID(varPhiIt->first); + const OriginalSt *ost = func.GetMeSSATab()->GetOriginalStFromID(PhiIt->first); if (ost->IsSymbolOst() && ost->GetIndirectLev() == 0) { auto *dassign = func.GetIRMap()->NewInPool(); - MeVarPhiNode *varPhi = varPhiIt->second; - dassign->SetLHS(varPhi->GetLHS()); + MePhiNode *varPhi = PhiIt->second; + dassign->SetLHS(static_cast(varPhi->GetLHS())); dassign->SetRHS(varPhi->GetOpnd(0)); dassign->SetBB(varPhi->GetDefBB()); dassign->SetIsLive(varPhi->GetIsLive()); meBB.PrependMeStmt(dassign); } - ++varPhiIt; + ++PhiIt; } - meBB.GetMevarPhiList().clear(); // delete all the phis -} - -void MeCFG::ConvertMeregphiList2IdentityAssigns(BB &meBB) const { - auto regPhiIt = meBB.GetMeRegPhiList().begin(); - while (regPhiIt != meBB.GetMeRegPhiList().end()) { - // replace phi with identify assignment as it only has 1 opnd - const OriginalSt *ost = func.GetMeSSATab()->GetOriginalStFromID(regPhiIt->first); - if (ost->IsSymbolOst() && ost->GetIndirectLev() == 0) { - auto *regAss = func.GetIRMap()->New(); - MeRegPhiNode *regPhi = regPhiIt->second; - regAss->SetLHS(regPhi->GetLHS()); - regAss->SetRHS(regPhi->GetOpnd(0)); - regAss->SetBB(regPhi->GetDefBB()); - regAss->SetIsLive(regPhi->GetIsLive()); - meBB.PrependMeStmt(regAss); - } - ++regPhiIt; - } - meBB.GetMeRegPhiList().clear(); // delete all the phis + meBB.GetMePhiList().clear(); // delete all the phis } // used only after DSE because it looks at live field of VersionSt @@ -600,8 +581,7 @@ void MeCFG::ConvertPhis2IdentityAssigns(BB &meBB) const { return; } ConvertPhiList2IdentityAssigns(meBB); - ConvertMevarPhiList2IdentityAssigns(meBB); - ConvertMeregphiList2IdentityAssigns(meBB); + ConvertMePhiList2IdentityAssigns(meBB); } // analyse the CFG to find the BBs that will not reach any function exit; these diff --git a/src/maple_me/src/me_cond_based_opt.cpp b/src/maple_me/src/me_cond_based_opt.cpp old mode 100644 new mode 100755 index 4f6d46ab6d..3dd1f4f507 --- a/src/maple_me/src/me_cond_based_opt.cpp +++ b/src/maple_me/src/me_cond_based_opt.cpp @@ -149,7 +149,12 @@ bool MeCondBased::PointerWasDereferencedBefore(const VarMeExpr &var, const Unary // Search backward along the path in the dominator tree from BBy to BBx. // If it sees an iread or iassign whose base is var, then the assertnonnull can be deleted. MeStmt *defMeStmt = nullptr; - BB *bbx = var.GetDefByBBMeStmt(*dominance, defMeStmt); + BB *bbx = nullptr; + if (var.IsDefByNo()) + bbx = &dominance->GetCommonEntryBB(); + else + bbx = var.DefByBB(); + if (bbx == nullptr) { return false; } diff --git a/src/maple_me/src/me_delegate_rc.cpp b/src/maple_me/src/me_delegate_rc.cpp old mode 100644 new mode 100755 index 52463980fa..417f5d4879 --- a/src/maple_me/src/me_delegate_rc.cpp +++ b/src/maple_me/src/me_delegate_rc.cpp @@ -80,17 +80,17 @@ static bool IsVarDecRefStmt(const MeStmt &stmt) { CheckOp(stmt, OP_decrefreset); } -void DelegateRC::SetCantDelegate(const MapleMap &meVarPhiList) { +void DelegateRC::SetCantDelegate(const MapleMap &meVarPhiList) { for (auto it = meVarPhiList.begin(); it != meVarPhiList.end(); ++it) { const OriginalSt *ost = ssaTab.GetOriginalStFromID(it->first); if (!ost->IsSymbolOst() || ost->GetIndirectLev() != 0) { continue; } - MeVarPhiNode *mePhi = it->second; + MePhiNode *mePhi = it->second; if (!mePhi->GetIsLive()) { continue; } - for (VarMeExpr *phiOpnd : mePhi->GetOpnds()) { + for (ScalarMeExpr *phiOpnd : mePhi->GetOpnds()) { verStCantDelegate[phiOpnd->GetVstIdx()] = true; } } @@ -147,8 +147,8 @@ void DelegateRC::CollectDerefedOrCopied(const MeExpr &expr) { SaveDerefedOrCopiedVst(defStmt->GetRHS()->GetOpnd(0)); } } else if (baseVar->GetDefBy() == kDefByPhi) { - MeVarPhiNode &defPhi = baseVar->GetDefPhi(); - for (VarMeExpr *phiOpnd : defPhi.GetOpnds()) { + MePhiNode &defPhi = baseVar->GetDefPhi(); + for (ScalarMeExpr *phiOpnd : defPhi.GetOpnds()) { if (phiOpnd->GetDefBy() == kDefByStmt) { MeStmt *defStmt = phiOpnd->GetDefStmt(); if (defStmt->GetOp() == OP_dassign && defStmt->GetRHS() != nullptr && @@ -657,7 +657,7 @@ void DelegateRC::SetCantDelegateAndCountUses() { auto eIt = func.valid_end(); for (auto bIt = func.valid_begin(); bIt != eIt; ++bIt) { auto &bb = **bIt; - SetCantDelegate(bb.GetMevarPhiList()); + SetCantDelegate(bb.GetMePhiList()); for (auto &stmt : bb.GetMeStmts()) { // do not count decref operands if (IsVarDecRefStmt(stmt)) { diff --git a/src/maple_me/src/me_function.cpp b/src/maple_me/src/me_function.cpp old mode 100644 new mode 100755 index c8158680ff..f90c50fff3 --- a/src/maple_me/src/me_function.cpp +++ b/src/maple_me/src/me_function.cpp @@ -56,8 +56,7 @@ void MeFunction::Dump(bool DumpSimpIr) const { for (auto bIt = valid_begin(); bIt != eIt; ++bIt) { auto *bb = *bIt; bb->DumpHeader(&mirModule); - bb->DumpMeVarPhiList(irmap); - bb->DumpMeRegPhiList(irmap); + bb->DumpMePhiList(irmap); for (auto &meStmt : bb->GetMeStmts()) { meStmt.Dump(irmap); } diff --git a/src/maple_me/src/me_hdse.cpp b/src/maple_me/src/me_hdse.cpp old mode 100644 new mode 100755 index 2c2aa69dcd..cdb7ea4883 --- a/src/maple_me/src/me_hdse.cpp +++ b/src/maple_me/src/me_hdse.cpp @@ -34,8 +34,8 @@ void MeDoHDSE::MakeEmptyTrysUnreachable(MeFunction &func) { BB *endTry = *endTryIt; auto &meStmts = tryBB->GetMeStmts(); if (tryBB->GetAttributes(kBBAttrIsTry) && !meStmts.empty() && - meStmts.front().GetOp() == OP_try && tryBB->GetMevarPhiList().empty() && - tryBB->GetMeRegPhiList().empty() && endTry->GetAttributes(kBBAttrIsTryEnd) && endTry->IsMeStmtEmpty()) { + meStmts.front().GetOp() == OP_try && tryBB->GetMePhiList().empty() && + endTry->GetAttributes(kBBAttrIsTryEnd) && endTry->IsMeStmtEmpty()) { // we found a try BB followed by an empty endtry BB BB *targetBB = endTry->GetSucc(0); for (auto *tryPred : tryBB->GetPred()) { @@ -45,9 +45,9 @@ void MeDoHDSE::MakeEmptyTrysUnreachable(MeFunction &func) { for (size_t k = 0; k < targetBB->GetPred().size(); ++k) { if (targetBB->GetPred(k) == endTry) { // push additional phi operand for each phi at targetbb - auto phiIter = targetBB->GetMevarPhiList().begin(); - for (; phiIter != targetBB->GetMevarPhiList().end(); ++phiIter) { - MeVarPhiNode *meVarPhi = phiIter->second; + auto phiIter = targetBB->GetMePhiList().begin(); + for (; phiIter != targetBB->GetMePhiList().end(); ++phiIter) { + MePhiNode *meVarPhi = phiIter->second; meVarPhi->GetOpnds().push_back(meVarPhi->GetOpnds()[k]); } } diff --git a/src/maple_me/src/me_inequality_graph.cpp b/src/maple_me/src/me_inequality_graph.cpp old mode 100644 new mode 100755 index 7e11677faa..cf03aa81ee --- a/src/maple_me/src/me_inequality_graph.cpp +++ b/src/maple_me/src/me_inequality_graph.cpp @@ -43,7 +43,7 @@ ESSAVarNode *InequalityGraph::GetOrCreateVarNode(MeExpr &meExpr) { return newVar; } -ESSAPhiNode *InequalityGraph::GetOrCreatePhiNode(MeVarPhiNode &phiNode) { +ESSAPhiNode *InequalityGraph::GetOrCreatePhiNode(MePhiNode &phiNode) { MeExpr *expr = phiNode.GetLHS(); CHECK_FATAL(expr != nullptr, "meExpr phiNode must has lhs"); if (HasNode(*expr)) { @@ -55,12 +55,13 @@ ESSAPhiNode *InequalityGraph::GetOrCreatePhiNode(MeVarPhiNode &phiNode) { newPhiNode->SetPhiOpnds(phiNode.GetOpnds()); ESSAPhiNode *newPhi = newPhiNode.get(); varNodes[expr->GetExprID()] = std::move(newPhiNode); - for (VarMeExpr *phiRHS : phiNode.GetOpnds()) { + for (ScalarMeExpr *phit : phiNode.GetOpnds()) { + VarMeExpr *phiRHS = static_cast(phit); ESSABaseNode *rhs = nullptr; if (phiRHS->GetDefBy() != kDefByPhi) { rhs = GetOrCreateVarNode(*phiRHS); } else { - MeVarPhiNode *defPhi = &(phiRHS->GetDefPhi()); + MePhiNode *defPhi = &(phiRHS->GetDefPhi()); rhs = GetOrCreatePhiNode(*defPhi); } AddPhiEdge(*rhs, *newPhi, EdgeType::kUpper); diff --git a/src/maple_me/src/me_ir.cpp b/src/maple_me/src/me_ir.cpp old mode 100644 new mode 100755 index f59f28ba30..3970ec6577 --- a/src/maple_me/src/me_ir.cpp +++ b/src/maple_me/src/me_ir.cpp @@ -135,11 +135,11 @@ bool RegMeExpr::IsSameVariableValue(const VarMeExpr &expr) const { VarMeExpr &VarMeExpr::ResolveVarMeValue() { VarMeExpr *cmpop0 = this; while (true) { - if (cmpop0->defBy != kDefByStmt) { + if (cmpop0->GetDefBy() != kDefByStmt) { break; } - auto *defStmt = static_cast(cmpop0->def.defStmt); + auto *defStmt = static_cast(cmpop0->GetDefStmt()); MeExpr *expr = defStmt->GetRHS(); if (expr->GetMeOp() != kMeOpVar) { break; @@ -199,9 +199,9 @@ RegMeExpr *RegMeExpr::FindDefByStmt(std::set &visited) { return this; } if (GetDefBy() == kDefByPhi) { - MeRegPhiNode &phiReg = GetDefPhi(); - for (RegMeExpr *phiOpnd : phiReg.GetOpnds()) { - RegMeExpr *res = phiOpnd->FindDefByStmt(visited); + MePhiNode &phiReg = GetDefPhi(); + for (ScalarMeExpr *phiOpnd : phiReg.GetOpnds()) { + RegMeExpr *res = static_cast(phiOpnd)->FindDefByStmt(visited); if (res != nullptr) { return res; } @@ -442,54 +442,12 @@ MeExpr *IvarMeExpr::GetIdenticalExpr(MeExpr &expr) const { return nullptr; } -BB *VarMeExpr::GetDefByBBMeStmt(const Dominance &dominance, MeStmtPtr &defMeStmt) const { - switch (defBy) { - case kDefByNo: - return &dominance.GetCommonEntryBB(); - case kDefByStmt: - defMeStmt = def.defStmt; - return defMeStmt->GetBB(); - case kDefByMustDef: - defMeStmt = def.defMustDef->GetBase(); - return defMeStmt->GetBB(); - case kDefByChi: - defMeStmt = def.defChi->GetBase(); - return defMeStmt->GetBB(); - case kDefByPhi: - return def.defPhi->GetDefBB(); - default: - return nullptr; - } -} - -bool VarMeExpr::IsUseSameSymbol(const MeExpr &expr) const { - if (expr.GetMeOp() != kMeOpVar) { - return false; - } - auto &varMeExpr = static_cast(expr); +bool ScalarMeExpr::IsUseSameSymbol(const MeExpr &expr) const { + auto &varMeExpr = static_cast(expr); return ostIdx == varMeExpr.ostIdx; } -bool VarMeExpr::IsPureLocal(const SSATab &tab, const MIRFunction &irFunc) const { - const MIRSymbol *st = tab.GetMIRSymbolFromID(ostIdx); - return st->IsLocal() && !irFunc.IsAFormal(st); -} - -bool VarMeExpr::IsZeroVersion(const SSATab &ssatab) const { - ASSERT(vstIdx != 0, "VarMeExpr::IsZeroVersion: cannot determine because vstIdx is 0"); - const OriginalSt *ost = ssatab.GetOriginalStFromID(ostIdx); - return ost->GetZeroVersionIndex() == vstIdx; -} - -bool RegMeExpr::IsUseSameSymbol(const MeExpr &expr) const { - if (expr.GetMeOp() != kMeOpReg) { - return false; - } - auto ®MeExpr = static_cast(expr); - return ostIdx == regMeExpr.ostIdx; -} - -BB *RegMeExpr::DefByBB() { +BB *ScalarMeExpr::DefByBB() const{ switch (defBy) { case kDefByNo: return nullptr; @@ -499,16 +457,33 @@ BB *RegMeExpr::DefByBB() { case kDefByPhi: ASSERT(def.defPhi, "VarMeExpr::DefByBB: defPhi cannot be nullptr"); return def.defPhi->GetDefBB(); - case kDefByMustDef: + case kDefByChi: { + ASSERT(def.defChi, "VarMeExpr::DefByBB: defChi cannot be nullptr"); + ASSERT(def.defChi->GetBase(), "VarMeExpr::DefByBB: defChi->base cannot be nullptr"); + return def.defChi->GetBase()->GetBB(); + } + case kDefByMustDef: { ASSERT(def.defMustDef, "VarMeExpr::DefByBB: defMustDef cannot be nullptr"); ASSERT(def.defMustDef->GetBase(), "VarMeExpr::DefByBB: defMustDef->base cannot be nullptr"); return def.defMustDef->GetBase()->GetBB(); + } default: - ASSERT(false, "reg define unknown"); + ASSERT(false, "var define unknown"); return nullptr; } } +bool VarMeExpr::IsPureLocal(const SSATab &tab, const MIRFunction &irFunc) const { + const MIRSymbol *st = tab.GetMIRSymbolFromID(GetOStIdx()); + return st->IsLocal() && !irFunc.IsAFormal(st); +} + +bool VarMeExpr::IsZeroVersion(const SSATab &ssatab) const { + ASSERT(GetVstIdx() != 0, "VarMeExpr::IsZeroVersion: cannot determine because vstIdx is 0"); + const OriginalSt *ost = ssatab.GetOriginalStFromID(GetOStIdx()); + return ost->GetZeroVersionIndex() == GetVstIdx(); +} + bool AddrofMeExpr::IsUseSameSymbol(const MeExpr &expr) const { if (expr.GetMeOp() != kMeOpAddrof) { return false; @@ -697,13 +672,26 @@ MeExpr *AddroffuncMeExpr::GetIdenticalExpr(MeExpr &expr) const { return nullptr; } -void MeVarPhiNode::Dump(const IRMap *irMap) const { - if (isPiAdded) { - LogInfo::MapleLogger() << "PI_ADD VAR:"; +void MePhiNode::Dump(const IRMap *irMap) const { + const OriginalSt *ost = irMap->GetSSATab().GetOriginalStFromID(lhs->GetOStIdx()); + bool isSym = ost->IsSymbolOst(); + CHECK_FATAL(lhs != nullptr, "lsh is null"); + if (isSym) { + if (isPiAdded) { + LogInfo::MapleLogger() << "PI_ADD VAR:"; + } + LogInfo::MapleLogger() << "VAR:"; + irMap->GetSSATab().GetOriginalStFromID(lhs->GetOStIdx())->Dump(); + } else { + PregIdx16 regId = static_cast(lhs)->GetRegIdx(); + LogInfo::MapleLogger() << "REGVAR: " << regId; + LogInfo::MapleLogger() << "(%" + << irMap->GetMIRModule().CurFunction() + ->GetPregTab() + ->PregFromPregIdx(static_cast(regId)) + ->GetPregNo() + << ")"; } - LogInfo::MapleLogger() << "VAR:"; - CHECK_FATAL(lhs != nullptr, "lsh is null"); - irMap->GetSSATab().GetOriginalStFromID(lhs->GetOStIdx())->Dump(); LogInfo::MapleLogger() << " mx" << lhs->GetExprID(); LogInfo::MapleLogger() << " = MEPHI{"; for (size_t i = 0; i < opnds.size(); ++i) { @@ -719,6 +707,7 @@ void MeVarPhiNode::Dump(const IRMap *irMap) const { LogInfo::MapleLogger() << '\n'; } +#if 0 void MeRegPhiNode::Dump(const IRMap *irMap) const { CHECK_FATAL(lhs != nullptr, "lhs is null"); LogInfo::MapleLogger() << "REGVAR: " << lhs->GetRegIdx(); @@ -738,11 +727,12 @@ void MeRegPhiNode::Dump(const IRMap *irMap) const { } LogInfo::MapleLogger() << "}" << '\n'; } +#endif void VarMeExpr::Dump(const IRMap *irMap, int32) const { CHECK_NULL_FATAL(irMap); LogInfo::MapleLogger() << "VAR "; - irMap->GetSSATab().GetOriginalStFromID(ostIdx)->Dump(); + irMap->GetSSATab().GetOriginalStFromID(GetOStIdx())->Dump(); LogInfo::MapleLogger() << " (field)" << fieldID; LogInfo::MapleLogger() << " mx" << GetExprID(); if (IsZeroVersion(irMap->GetSSATab())) { @@ -1323,7 +1313,7 @@ void AssertMeStmt::Dump(const IRMap *irMap) const { opnds[1]->Dump(irMap, kDefaultPrintIndentNum); LogInfo::MapleLogger() << '\n'; } - +#if 0 BB *VarMeExpr::DefByBB() { switch (defBy) { case kDefByNo: @@ -1349,9 +1339,9 @@ BB *VarMeExpr::DefByBB() { return nullptr; } } - +#endif bool VarMeExpr::IsVolatile(const SSATab &ssatab) const { - const OriginalSt *ost = ssatab.GetOriginalStFromID(ostIdx); + const OriginalSt *ost = ssatab.GetOriginalStFromID(GetOStIdx()); if (!ost->IsSymbolOst()) { return false; } @@ -1446,10 +1436,10 @@ MapleMap *GenericGetChiListFromVarMeExprInner(VarMeExpr &exp } visited.insert(&expr); if (expr.GetDefBy() == kDefByPhi) { - MeVarPhiNode &phiMe = expr.GetDefPhi(); - MapleVector &phiOpnds = phiMe.GetOpnds(); + MePhiNode &phiMe = expr.GetDefPhi(); + MapleVector &phiOpnds = phiMe.GetOpnds(); for (auto it = phiOpnds.begin(); it != phiOpnds.end(); ++it) { - VarMeExpr *meExpr = *it; + VarMeExpr *meExpr = static_cast(*it); MapleMap *chiList = GenericGetChiListFromVarMeExprInner(*meExpr, visited); if (chiList != nullptr) { return chiList; diff --git a/src/maple_me/src/me_irmap.cpp b/src/maple_me/src/me_irmap.cpp old mode 100644 new mode 100755 index 6ffa3b927d..4ba6536be3 --- a/src/maple_me/src/me_irmap.cpp +++ b/src/maple_me/src/me_irmap.cpp @@ -40,8 +40,7 @@ void MeIRMap::Dump() { bb->DumpHeader(&GetMIRModule()); LogInfo::MapleLogger() << "frequency : " << bb->GetFrequency() << "\n"; bb->DumpMeVarPiList(this); - bb->DumpMeVarPhiList(this); - bb->DumpMeRegPhiList(this); + bb->DumpMePhiList(this); int i = 0; for (auto &meStmt : bb->GetMeStmts()) { if (GetDumpStmtNum()) { diff --git a/src/maple_me/src/me_rename2preg.cpp b/src/maple_me/src/me_rename2preg.cpp old mode 100644 new mode 100755 index dcdb597226..c26cd5efe9 --- a/src/maple_me/src/me_rename2preg.cpp +++ b/src/maple_me/src/me_rename2preg.cpp @@ -205,8 +205,8 @@ class SSARename2Preg { if (enabledDebug) { LogInfo::MapleLogger() << " working on phi part of BB" << bb.GetBBId() << '\n'; } - for (auto &varPhi : bb.GetMevarPhiList()) { - Rename2PregPhi(aliasClass, utils::ToRef(varPhi.second), irMap); + for (auto &phiList : bb.GetMePhiList()) { + Rename2PregPhi(aliasClass, utils::ToRef(phiList.second), irMap); } if (enabledDebug) { @@ -325,24 +325,29 @@ class SSARename2Preg { } } - void Rename2PregPhi(const AliasClass &aliasClass, MeVarPhiNode &varPhiNode, MeIRMap &irMap) { - VarMeExpr &varExpr = utils::ToRef(varPhiNode.GetLHS()); + void Rename2PregPhi(const AliasClass &aliasClass, MePhiNode &varPhiNode, MeIRMap &irMap) { + VarMeExpr *lhs = static_cast(varPhiNode.GetLHS()); + if (lhs == nullptr) { + return; + } + + VarMeExpr &varExpr =(utils::ToRef(lhs)); RegMeExpr *pRegExpr = RenameVar(aliasClass, varExpr); if (pRegExpr == nullptr) { return; } RegMeExpr ®Expr = *pRegExpr; - MeRegPhiNode ®PhiNode = utils::ToRef(irMap.CreateMeRegPhi(regExpr)); + MePhiNode ®PhiNode = utils::ToRef(irMap.CreateMePhi(regExpr)); regPhiNode.SetDefBB(varPhiNode.GetDefBB()); UpdateRegPhi(regExpr, varPhiNode.GetOpnds(), regPhiNode); } // update regphinode operands - void UpdateRegPhi(const RegMeExpr &curRegExpr, const MapleVector &phiNodeOpnds, - MeRegPhiNode ®PhiNode) const { + void UpdateRegPhi(const RegMeExpr &curRegExpr, const MapleVector &phiNodeOpnds, + MePhiNode ®PhiNode) const { PregCache &pregCache = cacheProxy.Preg(); - for (VarMeExpr *phiOpnd : phiNodeOpnds) { - const VarMeExpr &varExpr = utils::ToRef(phiOpnd); + for (ScalarMeExpr *phiOpnd : phiNodeOpnds) { + const VarMeExpr&varExpr = utils::ToRef(static_cast(phiOpnd)); RegMeExpr ®Expr = pregCache.CloneRegExprIfNotExist(varExpr, [&curRegExpr](MeIRMap &irMap) { return irMap.CreateRegMeExprVersion(curRegExpr); }); diff --git a/src/maple_me/src/me_ssa_lpre.cpp b/src/maple_me/src/me_ssa_lpre.cpp old mode 100644 new mode 100755 index 42352995df..603872d12d --- a/src/maple_me/src/me_ssa_lpre.cpp +++ b/src/maple_me/src/me_ssa_lpre.cpp @@ -105,7 +105,7 @@ void MeSSALPre::GenerateReloadRealOcc(MeRealOcc &realOcc) { regOrVar = defRealOcc->GetSavedExpr(); } else if (defOcc->GetOccType() == kOccPhiocc) { auto *defPhiOcc = static_cast(defOcc); - MeRegPhiNode *regPhi = defPhiOcc->GetRegPhi(); + MePhiNode *regPhi = defPhiOcc->GetRegPhi(); regOrVar = regPhi->GetLHS(); } else if (defOcc->GetOccType() == kOccInserted) { auto *defInsertedOcc = static_cast(defOcc); diff --git a/src/maple_me/src/me_ssa_update.cpp b/src/maple_me/src/me_ssa_update.cpp old mode 100644 new mode 100755 index 83d0685b1e..28636a66d4 --- a/src/maple_me/src/me_ssa_update.cpp +++ b/src/maple_me/src/me_ssa_update.cpp @@ -48,29 +48,29 @@ void MeSSAUpdate::InsertPhis() { // insert a phi node BB *bb = func.GetBBFromID(bbId); ASSERT_NOT_NULL(bb); - auto phiListIt = bb->GetMevarPhiList().find(it->first); - if (phiListIt != bb->GetMevarPhiList().end()) { + auto phiListIt = bb->GetMePhiList().find(it->first); + if (phiListIt != bb->GetMePhiList().end()) { phiListIt->second->SetIsLive(true); continue; } - auto *phiMeNode = irMap.NewInPool(); + auto *phiMeNode = irMap.NewInPool(); phiMeNode->SetDefBB(bb); phiMeNode->GetOpnds().resize(bb->GetPred().size()); - bb->GetMevarPhiList().insert(std::make_pair(it->first, phiMeNode)); + bb->GetMePhiList().insert(std::make_pair(it->first, phiMeNode)); } // initialize its rename stack - renameStacks[it->first] = ssaUpdateMp.New>(ssaUpdateAlloc.Adapter()); + renameStacks[it->first] = ssaUpdateMp.New>(ssaUpdateAlloc.Adapter()); } } void MeSSAUpdate::RenamePhi(const BB &bb) { for (auto it1 = renameStacks.begin(); it1 != renameStacks.end(); ++it1) { - auto it2 = bb.GetMevarPhiList().find(it1->first); - if (it2 == bb.GetMevarPhiList().end()) { + auto it2 = bb.GetMePhiList().find(it1->first); + if (it2 == bb.GetMePhiList().end()) { continue; } // if there is existing phi result node - MeVarPhiNode *phi = it2->second; + MePhiNode *phi = it2->second; phi->SetIsLive(true); // always make it live, for correctness if (phi->GetLHS() == nullptr) { // create a new VarMeExpr defined by this phi @@ -93,8 +93,8 @@ MeExpr *MeSSAUpdate::RenameExpr(MeExpr &meExpr, bool &changed) { if (it == renameStacks.end()) { return &meExpr; } - MapleStack *renameStack = it->second; - VarMeExpr *curVar = renameStack->top(); + MapleStack *renameStack = it->second; + ScalarMeExpr *curVar = renameStack->top(); if (&varExpr == curVar) { return &meExpr; } @@ -227,13 +227,13 @@ void MeSSAUpdate::RenamePhiOpndsInSucc(const BB &bb) { } CHECK_FATAL(index < succ->GetPred().size(), "RenamePhiOpndsinSucc: cannot find corresponding pred"); for (auto it1 = renameStacks.begin(); it1 != renameStacks.end(); ++it1) { - auto it2 = succ->GetMevarPhiList().find(it1->first); - if (it2 == succ->GetMevarPhiList().end()) { + auto it2 = succ->GetMePhiList().find(it1->first); + if (it2 == succ->GetMePhiList().end()) { continue; } - MeVarPhiNode *phi = it2->second; - MapleStack *renameStack = it1->second; - VarMeExpr *curVar = renameStack->top(); + MePhiNode *phi = it2->second; + MapleStack *renameStack = it1->second; + ScalarMeExpr *curVar = renameStack->top(); if (phi->GetOpnd(index) != curVar) { phi->SetOpnd(index, curVar); } @@ -270,7 +270,7 @@ void MeSSAUpdate::Run() { for (auto it = renameStacks.begin(); it != renameStacks.end(); ++it) { const OriginalSt *ost = ssaTab.GetSymbolOriginalStFromID(it->first); VarMeExpr *zeroVersVar = irMap.GetOrCreateZeroVersionVarMeExpr(*ost); - MapleStack *renameStack = it->second; + MapleStack *renameStack = it->second; renameStack->push(zeroVersVar); } // recurse down dominator tree in pre-order traversal diff --git a/src/maple_me/src/me_stmt_pre.cpp b/src/maple_me/src/me_stmt_pre.cpp old mode 100644 new mode 100755 index c9cdb698ef..a448752aa2 --- a/src/maple_me/src/me_stmt_pre.cpp +++ b/src/maple_me/src/me_stmt_pre.cpp @@ -766,7 +766,7 @@ PreStmtWorkCand *MeStmtPre::CreateStmtRealOcc(MeStmt &meStmt, int seqStmt) { } MeExpr *meExpr = nullptr; if ((meStmt.GetOp() == OP_dassign || meStmt.GetOp() == OP_callassigned) && meStmt.GetVarLHS() != nullptr) { - MapleStack *pStack = versionStackVec.at(meStmt.GetVarLHS()->GetOStIdx()); + MapleStack *pStack = versionStackVec.at(meStmt.GetVarLHS()->GetOStIdx()); meExpr = pStack->top(); } MeRealOcc *newOcc = ssaPreMemPool->New(&meStmt, seqStmt, meExpr); @@ -791,7 +791,7 @@ void MeStmtPre::VersionStackChiListUpdate(const MapleMap &ch if (!ost->IsSymbolOst() || ost->GetIndirectLev() != 0) { continue; } - MapleStack *pStack = versionStackVec.at(it->second->GetLHS()->GetOStIdx()); + MapleStack *pStack = versionStackVec.at(it->second->GetLHS()->GetOStIdx()); pStack->push(it->second->GetLHS()); } } @@ -823,14 +823,14 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { curStackSizeVec[i] = versionStackVec[i]->size(); } // traverse var phi nodes to update versionStack - MapleMap &meVarPhiList = bb->GetMevarPhiList(); - for (auto it = meVarPhiList.begin(); it != meVarPhiList.end(); ++it) { - MeVarPhiNode *phiMeNode = it->second; + MapleMap &mePhiList = bb->GetMePhiList(); + for (auto it = mePhiList.begin(); it != mePhiList.end(); ++it) { + MePhiNode *phiMeNode = it->second; const OriginalSt *ost = ssaTab->GetOriginalStFromID(phiMeNode->GetLHS()->GetOStIdx()); if (!ost->IsSymbolOst() || ost->GetIndirectLev() != 0) { continue; } - MapleStack *pStack = versionStackVec.at(phiMeNode->GetLHS()->GetOStIdx()); + MapleStack *pStack = versionStackVec.at(phiMeNode->GetLHS()->GetOStIdx()); pStack->push(phiMeNode->GetLHS()); } // traverse statements @@ -931,7 +931,7 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { (dassMeStmt.GetRHS()->GetOp() == OP_regread && static_cast(dassMeStmt.GetRHS())->GetRegIdx() == -kSregThrownval)) { // update version stacks - MapleStack *pStack = versionStackVec.at(dassMeStmt.GetVarLHS()->GetOStIdx()); + MapleStack *pStack = versionStackVec.at(dassMeStmt.GetVarLHS()->GetOStIdx()); pStack->push(dassMeStmt.GetVarLHS()); VersionStackChiListUpdate(*dassMeStmt.GetChiList()); break; @@ -949,7 +949,7 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { RemoveUnnecessaryDassign(dassMeStmt); } // update version stacks - MapleStack *pStack = versionStackVec.at(dassMeStmt.GetVarLHS()->GetOStIdx()); + MapleStack *pStack = versionStackVec.at(dassMeStmt.GetVarLHS()->GetOStIdx()); pStack->push(dassMeStmt.GetVarLHS()); VersionStackChiListUpdate(*dassMeStmt.GetChiList()); break; @@ -1000,7 +1000,7 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { MeExpr *meLHS = mustDefList->front().GetLHS(); if (meLHS->GetMeOp() == kMeOpVar) { auto *lhsVar = static_cast(meLHS); - MapleStack *pStack = versionStackVec.at(lhsVar->GetOStIdx()); + MapleStack *pStack = versionStackVec.at(lhsVar->GetOStIdx()); pStack->push(lhsVar); } } @@ -1017,7 +1017,7 @@ void MeStmtPre::BuildWorkListBB(BB *bb) { } // pop the stacks back to their levels on entry for (size_t i = 1; i < versionStackVec.size(); ++i) { - MapleStack *pStack = versionStackVec[i]; + MapleStack *pStack = versionStackVec[i]; if (pStack == nullptr) { continue; } @@ -1036,7 +1036,7 @@ void MeStmtPre::BuildWorkList() { if (!ost->IsSymbolOst() || ost->GetIndirectLev() != 0) { continue; } - MapleStack *varStack = ssaPreMemPool->New>(ssaPreAllocator.Adapter()); + MapleStack *varStack = ssaPreMemPool->New>(ssaPreAllocator.Adapter()); varStack->push(static_cast(irMap->GetOrCreateZeroVersionVarMeExpr(*ost))); versionStackVec[ost->GetIndex()] = varStack; } diff --git a/src/maple_me/src/me_store_pre.cpp b/src/maple_me/src/me_store_pre.cpp old mode 100644 new mode 100755 index ff89e7fbb8..281ab57dfa --- a/src/maple_me/src/me_store_pre.cpp +++ b/src/maple_me/src/me_store_pre.cpp @@ -99,15 +99,15 @@ RegMeExpr *MeStorePre::EnsureRHSInCurTemp(BB &bb) { } } // check if there is def by phi - auto phiIt = bb.GetMevarPhiList().find(workCand->GetOst()->GetIndex()); - if (phiIt != bb.GetMevarPhiList().end()) { + auto phiIt = bb.GetMePhiList().find(workCand->GetOst()->GetIndex()); + if (phiIt != bb.GetMePhiList().end()) { if (enabledDebug) { LogInfo::MapleLogger() << "EnsureRHSInCurTemp: found def-by-phi at BB" << bb.GetBBId() << '\n'; } RegMeExpr *lhsReg = irMap->CreateRegMeExprVersion(*curTemp); bbCurTempMap[&bb] = lhsReg; // form a new phi for the temp - MeRegPhiNode *regPhi = irMap->NewInPool(); + MePhiNode *regPhi = irMap->NewInPool(); regPhi->SetLHS(lhsReg); regPhi->SetDefBB(&bb); // call recursively for each varPhi operands @@ -118,7 +118,7 @@ RegMeExpr *MeStorePre::EnsureRHSInCurTemp(BB &bb) { (void)regPhiOpnd->GetPhiUseSet().insert(regPhi); } // insert the regPhi - (void)bb.GetMeRegPhiList().insert(std::make_pair(lhsReg->GetOstIdx(), regPhi)); + (void)bb.GetMePhiList().insert(std::make_pair(lhsReg->GetOstIdx(), regPhi)); return lhsReg; } // continue at immediate dominator diff --git a/src/maple_me/src/occur.cpp b/src/maple_me/src/occur.cpp old mode 100644 new mode 100755 index ea9759a245..01ff790e7c --- a/src/maple_me/src/occur.cpp +++ b/src/maple_me/src/occur.cpp @@ -92,7 +92,7 @@ MeExpr *MeOccur::GetSavedExpr() { return static_cast(this)->GetSavedExpr(); case kOccPhiocc: { auto *phiOcc = static_cast(this); - MeRegPhiNode *regPhi = phiOcc->GetRegPhi(); + MePhiNode *regPhi = phiOcc->GetRegPhi(); if (regPhi != nullptr) { return regPhi->GetLHS(); } else { diff --git a/src/maple_me/src/preg_renamer.cpp b/src/maple_me/src/preg_renamer.cpp old mode 100644 new mode 100755 index 4d33506d37..33bf57f33d --- a/src/maple_me/src/preg_renamer.cpp +++ b/src/maple_me/src/preg_renamer.cpp @@ -22,9 +22,9 @@ void PregRenamer::EnqueDefUses(std::list &qu, RegMeExpr *node, std:: CHECK_NULL_FATAL(node); // get its define if (node->GetDefBy() == kDefByPhi) { - MeRegPhiNode &defPhi = node->GetDefPhi(); + MePhiNode &defPhi = node->GetDefPhi(); for (auto it : defPhi.GetOpnds()) { - RegMeExpr *neibNode = it; // node's connected register node + RegMeExpr *neibNode = static_cast(it); // node's connected register node if (neibNode != node && curVisited.find(neibNode) == curVisited.end()) { qu.push_back(neibNode); (void)curVisited.insert(neibNode); @@ -32,16 +32,16 @@ void PregRenamer::EnqueDefUses(std::list &qu, RegMeExpr *node, std:: } } // get the phi which uses node as an operand - MapleSet &phiUseSet = node->GetPhiUseSet(); + MapleSet &phiUseSet = node->GetPhiUseSet(); for (auto setIt : phiUseSet) { - MeRegPhiNode *meRegPhi = setIt; - RegMeExpr *lhsReg = meRegPhi->GetLHS(); + MePhiNode *meRegPhi = setIt; + RegMeExpr *lhsReg = static_cast(meRegPhi->GetLHS()); if (lhsReg != node && curVisited.find(lhsReg) == curVisited.end()) { qu.push_back(lhsReg); (void)curVisited.insert(lhsReg); } for (auto opdIt : meRegPhi->GetOpnds()) { - RegMeExpr *opndReg = opdIt; + RegMeExpr *opndReg = static_cast(opdIt); if (opndReg != node && curVisited.find(opndReg) == curVisited.end()) { qu.push_back(opndReg); (void)curVisited.insert(opndReg); diff --git a/src/maple_me/src/prop.cpp b/src/maple_me/src/prop.cpp old mode 100644 new mode 100755 index 7091c5ea7f..e0db536cdd --- a/src/maple_me/src/prop.cpp +++ b/src/maple_me/src/prop.cpp @@ -373,8 +373,8 @@ MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) const { return varMeExpr; } } else if (checkPhi && varMeExpr.GetDefBy() == kDefByPhi && config.propagateAtPhi) { - MeVarPhiNode &defPhi = varMeExpr.GetDefPhi(); - VarMeExpr *phiOpndLast = defPhi.GetOpnds().back(); + MePhiNode &defPhi = varMeExpr.GetDefPhi(); + VarMeExpr* phiOpndLast = static_cast(defPhi.GetOpnds().back()); MeExpr *opndLastProp = &PropVar(utils::ToRef(phiOpndLast), atParm, false); if (opndLastProp != &varMeExpr && opndLastProp != phiOpndLast && opndLastProp->GetMeOp() == kMeOpVar) { // one more call @@ -383,9 +383,9 @@ MeExpr &Prop::PropVar(VarMeExpr &varMeExpr, bool atParm, bool checkPhi) const { if (opndLastProp == &varMeExpr) { return varMeExpr; } - MapleVector opndsVec = defPhi.GetOpnds(); + MapleVector opndsVec = defPhi.GetOpnds(); for (auto it = opndsVec.rbegin() + 1; it != opndsVec.rend(); ++it) { - VarMeExpr *phiOpnd = *it; + VarMeExpr *phiOpnd = static_cast(*it); MeExpr &opndProp = PropVar(utils::ToRef(phiOpnd), atParm, false); if (&opndProp != opndLastProp) { return varMeExpr; @@ -604,12 +604,7 @@ void Prop::TraversalBB(BB &bb) { } // update var phi nodes - for (auto it = bb.GetMevarPhiList().begin(); it != bb.GetMevarPhiList().end(); ++it) { - PropUpdateDef(utils::ToRef(it->second->GetLHS())); - } - - // update reg phi nodes - for (auto it = bb.GetMeRegPhiList().begin(); it != bb.GetMeRegPhiList().end(); ++it) { + for (auto it = bb.GetMePhiList().begin(); it != bb.GetMePhiList().end(); ++it) { PropUpdateDef(utils::ToRef(it->second->GetLHS())); } diff --git a/src/maple_me/src/ssa_devirtual.cpp b/src/maple_me/src/ssa_devirtual.cpp old mode 100644 new mode 100755 index 8809cf573c..9a20f7259d --- a/src/maple_me/src/ssa_devirtual.cpp +++ b/src/maple_me/src/ssa_devirtual.cpp @@ -328,12 +328,17 @@ void SSADevirtual::PropIvarInferredType(IvarMeExpr &ivar) const { } } -void SSADevirtual::VisitVarPhiNode(MeVarPhiNode &varPhi) const { - MapleVector opnds = varPhi.GetOpnds(); - auto *lhs = varPhi.GetLHS(); +void SSADevirtual::VisitVarPhiNode(MePhiNode &varPhi) const { + MapleVector opnds = varPhi.GetOpnds(); + VarMeExpr *lhs = static_cast(varPhi.GetLHS()); + + // RegPhiNode cases NYI + if (lhs == nullptr) + return; + const MapleVector &inferredTypeCandidates = lhs->GetInferredTypeCandidates(); for (size_t i = 0; i < opnds.size(); ++i) { - VarMeExpr *opnd = opnds[i]; + VarMeExpr *opnd = static_cast(opnds[i]); PropVarInferredType(*opnd); if (opnd->GetInferredTyIdx() != 0u) { size_t j = 0; @@ -598,9 +603,9 @@ void SSADevirtual::TraversalBB(BB *bb) { } bbVisited[bb->GetBBId()] = true; // traversal var phi nodes - MapleMap &meVarPhiList = bb->GetMevarPhiList(); - for (auto it = meVarPhiList.begin(); it != meVarPhiList.end(); ++it) { - MeVarPhiNode *phiMeNode = it->second; + MapleMap &mePhiList = bb->GetMePhiList(); + for (auto it = mePhiList.begin(); it != mePhiList.end(); ++it) { + MePhiNode *phiMeNode = it->second; VisitVarPhiNode(*phiMeNode); } // traversal reg phi nodes (NYI) diff --git a/src/maple_me/src/ssa_epre.cpp b/src/maple_me/src/ssa_epre.cpp old mode 100644 new mode 100755 index db9f42d954..e1e814f0d6 --- a/src/maple_me/src/ssa_epre.cpp +++ b/src/maple_me/src/ssa_epre.cpp @@ -136,7 +136,7 @@ void SSAEPre::GenerateReloadRealOcc(MeRealOcc &realOcc) { regOrVar = defRealOcc->GetSavedExpr(); } else if (defOcc->GetOccType() == kOccPhiocc) { auto *defPhiOcc = static_cast(defOcc); - MeRegPhiNode *regPhi = defPhiOcc->GetRegPhi(); + MePhiNode *regPhi = defPhiOcc->GetRegPhi(); if (regPhi != nullptr) { regOrVar = regPhi->GetLHS(); } else { diff --git a/src/maple_me/src/ssa_pre.cpp b/src/maple_me/src/ssa_pre.cpp old mode 100644 new mode 100755 index 9346fa647e..c1494591c0 --- a/src/maple_me/src/ssa_pre.cpp +++ b/src/maple_me/src/ssa_pre.cpp @@ -146,16 +146,16 @@ void SSAPre::GenerateSavePhiOcc(MePhiOcc &phiOcc) { "GenerateSavePhiOcc: inconsistent puIdx"); MeExpr *regOrVar = CreateNewCurTemp(*workCand->GetTheMeExpr()); CHECK_NULL_FATAL(regOrVar); + MePhiNode *phiNode = irMap->CreateMePhi(static_cast(*regOrVar)); + phiNode->SetDefBB(phiOcc.GetBB()); + if (instance_of(regOrVar)) { // create a reg phi - MeRegPhiNode *phiReg = irMap->CreateMeRegPhi(static_cast(*regOrVar)); - phiReg->SetDefBB(phiOcc.GetBB()); - phiOcc.SetRegPhi(*phiReg); + phiOcc.SetRegPhi(*phiNode); } else { - MeVarPhiNode *phiVar = irMap->CreateMeVarPhi(static_cast(*regOrVar)); - CHECK_NULL_FATAL(phiVar); - phiVar->SetDefBB(phiOcc.GetBB()); - phiOcc.SetVarPhi(*phiVar); + CHECK_NULL_FATAL(phiNode); + phiNode->SetDefBB(phiOcc.GetBB()); + phiOcc.SetVarPhi(*phiNode); } // update the phi opnds later ASSERT_NOT_NULL(workCand); @@ -163,7 +163,7 @@ void SSAPre::GenerateSavePhiOcc(MePhiOcc &phiOcc) { VarMeExpr *localRefVar = CreateNewCurLocalRefVar(); temp2LocalRefVarMap[static_cast(regOrVar)] = localRefVar; // create a var phi - MeVarPhiNode *phiVar = irMap->CreateMeVarPhi(*localRefVar); + MePhiNode *phiVar = irMap->CreateMePhi(*localRefVar); phiVar->SetDefBB(phiOcc.GetBB()); phiOcc.SetVarPhi(*phiVar); // update the phi opnds later @@ -178,7 +178,7 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { continue; } if (phiOcc->GetRegPhi()) { - MeRegPhiNode *phiReg = phiOcc->GetRegPhi(); + MePhiNode *phiReg = phiOcc->GetRegPhi(); for (MePhiOpndOcc *phiOpnd : phiOcc->GetPhiOpnds()) { auto *regOpnd = static_cast(phiOpnd->GetDef()->GetSavedExpr()); if (regOpnd == nullptr) { @@ -189,9 +189,9 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { phiReg->GetOpnds().push_back(regOpnd); (void)regOpnd->GetPhiUseSet().insert(phiReg); // record all the uses phi node for preg renaming } - (void)phiOcc->GetBB()->GetMeRegPhiList().insert(std::make_pair(phiReg->GetOpnd(0)->GetOstIdx(), phiReg)); + (void)phiOcc->GetBB()->GetMePhiList().insert(std::make_pair(phiReg->GetOpnd(0)->GetOstIdx(), phiReg)); if (workCand->NeedLocalRefVar() && phiOcc->GetVarPhi() != nullptr) { - MeVarPhiNode *phiVar = phiOcc->GetVarPhi(); + MePhiNode *phiVar = phiOcc->GetVarPhi(); for (MePhiOpndOcc *phiOpnd : phiOcc->GetPhiOpnds()) { auto *regOpnd = static_cast(phiOpnd->GetDef()->GetSavedExpr()); VarMeExpr *localRefVarOpnd = nullptr; @@ -212,10 +212,10 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { } phiVar->GetOpnds().push_back(localRefVarOpnd); } - (void)phiOcc->GetBB()->GetMevarPhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); + (void)phiOcc->GetBB()->GetMePhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); } } else { - MeVarPhiNode *phiVar = phiOcc->GetVarPhi(); + MePhiNode *phiVar = phiOcc->GetVarPhi(); for (MePhiOpndOcc *phiOpnd : phiOcc->GetPhiOpnds()) { auto *varOpnd = static_cast(phiOpnd->GetDef()->GetSavedExpr()); if (varOpnd == nullptr) { @@ -224,7 +224,7 @@ void SSAPre::UpdateInsertedPhiOccOpnd() { } phiVar->GetOpnds().push_back(varOpnd); } - (void)phiOcc->GetBB()->GetMevarPhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); + (void)phiOcc->GetBB()->GetMePhiList().insert(std::make_pair(phiVar->GetOpnd(0)->GetOStIdx(), phiVar)); } } } @@ -860,24 +860,15 @@ MeExpr *SSAPre::GetReplaceMeExpr(const MeExpr &opnd, const BB &ePhiBB, size_t j) return nullptr; } MeExpr *retExpr = nullptr; - if (opnd.GetMeOp() == kMeOpVar) { - MeVarPhiNode *defPhi = static_cast(&opnd)->GetMeVarPhiDef(); - if (defPhi != nullptr) { - if (ePhiBB.GetBBId() == defPhi->GetDefBB()->GetBBId()) { - ASSERT(defPhi->GetOpnds()[j]->GetMeOp() == opnd.GetMeOp(), "invalid defPhi"); - retExpr = defPhi->GetOpnds()[j]; - } - } - } else { - MeRegPhiNode *defPhi = static_cast(&opnd)->GetMeRegPhiDef(); - if (defPhi != nullptr) { - if (ePhiBB.GetBBId() == defPhi->GetDefBB()->GetBBId()) { - ASSERT(j < defPhi->GetOpnds().size(), "index out of range in SSAPre::GetReplaceMeExpr"); - ASSERT(defPhi->GetOpnds()[j]->GetMeOp() == opnd.GetMeOp(), "invalid defPhi"); - retExpr = defPhi->GetOpnds()[j]; - } + MePhiNode *defPhi = static_cast(&opnd)->GetMePhiDef(); + if (defPhi != nullptr) { + if (ePhiBB.GetBBId() == defPhi->GetDefBB()->GetBBId()) { + ASSERT(j < defPhi->GetOpnds().size(), "index out of range in SSAPre::GetReplaceMeExpr"); + ASSERT(defPhi->GetOpnds()[j]->GetMeOp() == opnd.GetMeOp(), "invalid defPhi"); + retExpr = defPhi->GetOpnds()[j]; } } + if (retExpr != nullptr && retExpr->GetPrimType() == kPtyInvalid) { ASSERT_NOT_NULL(workCand); retExpr->SetPtyp(workCand->GetPrimType()); @@ -974,30 +965,15 @@ void SSAPre::SetVarPhis(const MeExpr &meExpr) { if (meOp != kMeOpVar && meOp != kMeOpReg) { return; } - if (meOp == kMeOpVar) { - MeVarPhiNode *phiMeNode = static_cast(&meExpr)->GetMeVarPhiDef(); - if (phiMeNode != nullptr) { - BBId defBBId = phiMeNode->GetDefBB()->GetBBId(); - if (varPhiDfns.find(dom->GetDtDfnItem(defBBId)) == varPhiDfns.end() && ScreenPhiBB(defBBId)) { - (void)varPhiDfns.insert(dom->GetDtDfnItem(defBBId)); - for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); ++opndIt) { - VarMeExpr *opnd = *opndIt; - SetVarPhis(*opnd); - } - } - } - } else { - MeRegPhiNode *phiMeNode = static_cast(&meExpr)->GetMeRegPhiDef(); - if (phiMeNode != nullptr) { - BBId defBbId = phiMeNode->GetDefBB()->GetBBId(); - CHECK(defBbId < dom->GetDtDfnSize(), "defBbId.idx out of range in SSAPre::SetVarPhis"); - if (varPhiDfns.find(dom->GetDtDfnItem(defBbId)) == varPhiDfns.end() && ScreenPhiBB(defBbId)) { - (void)varPhiDfns.insert(dom->GetDtDfnItem(defBbId)); - for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); - ++opndIt) { - RegMeExpr *opnd = *opndIt; - SetVarPhis(*opnd); - } + MePhiNode *phiMeNode = static_cast(&meExpr)->GetMePhiDef(); + if (phiMeNode != nullptr) { + BBId defBBId = phiMeNode->GetDefBB()->GetBBId(); + CHECK(defBBId < dom->GetDtDfnSize(), "defBBId.idx out of range in SSAPre::SetVarPhis"); + if (varPhiDfns.find(dom->GetDtDfnItem(defBBId)) == varPhiDfns.end() && ScreenPhiBB(defBBId)) { + (void)varPhiDfns.insert(dom->GetDtDfnItem(defBBId)); + for (auto opndIt = phiMeNode->GetOpnds().begin(); opndIt != phiMeNode->GetOpnds().end(); ++opndIt) { + ScalarMeExpr *opnd = *opndIt; + SetVarPhis(*opnd); } } } @@ -1206,7 +1182,7 @@ bool SSAPre::DefVarDominateOcc(const MeExpr *meExpr, const MeOccur &meOcc) const return dom->Dominate(*defBB, *occBB); } case kDefByPhi: { - const MeVarPhiNode &phiMeNode = varMeExpr->GetDefPhi(); + const MePhiNode &phiMeNode = varMeExpr->GetDefPhi(); const BB *defBB = phiMeNode.GetDefBB(); if (defBB->GetBBId() == occBB->GetBBId()) { return true; @@ -1254,8 +1230,8 @@ bool SSAPre::DefVarDominateOcc(const MeExpr *meExpr, const MeOccur &meOcc) const return dom->Dominate(*defBB, *occBB); } case kDefByPhi: { - const MeRegPhiNode &phiMeNode = regMeExpr->GetDefPhi(); - BB *defBB = phiMeNode.GetDefBB(); + const MePhiNode &phiMeNode = regMeExpr->GetDefPhi(); + const BB *defBB = phiMeNode.GetDefBB(); if (defBB->GetBBId() == occBB->GetBBId()) { return true; } -- Gitee