diff --git a/src/V3Ast.h b/src/V3Ast.h index 8c62828761..2bc4fe06d9 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1773,6 +1773,9 @@ class AstNode VL_NOT_FINAL { UASSERT_STATIC(s_cloneCntGbl, "Rollover"); } + // Use instead isSame(), this is for each Ast* class, and assumes node is of same type + virtual bool same(const AstNode*) const { return true; } + public: // ACCESSORS VNType type() const VL_MT_SAFE { return m_type; } @@ -2137,7 +2140,10 @@ class AstNode VL_NOT_FINAL { // statement is unlikely to be taken virtual bool isUnlikely() const { return false; } virtual int instrCount() const { return 0; } - virtual bool same(const AstNode*) const { return true; } + // Iff node is identical to anouther node + virtual bool isSame(const AstNode* samep) const { + return type() == samep->type() && same(samep); + } // Iff has a data type; dtype() must be non null virtual bool hasDType() const VL_MT_SAFE { return false; } // Iff has a non-null childDTypep(), as generic node function diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 5af783789f..bddc62d9d7 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -1701,7 +1701,7 @@ AstNodeUOrStructDType* AstMemberDType::getChildStructp() const { bool AstMemberSel::same(const AstNode* samep) const { const AstMemberSel* const sp = VN_DBG_AS(samep, MemberSel); - return sp != nullptr && access() == sp->access() && fromp()->same(sp->fromp()) + return sp != nullptr && access() == sp->access() && fromp()->isSame(sp->fromp()) && name() == sp->name() && varp()->same(sp->varp()); } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index d42bb07b09..1e3685e5bc 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -1434,7 +1434,7 @@ class ConstVisitor final : public VNVisitor { // Avoid comparing widthMin's, which results in lost optimization attempts // If cleanup sameGateTree to be smarter, this can be restored. // return node1p->sameGateTree(node2p); - return node1p->same(node2p); + return node1p->isSame(node2p); } else { return false; } diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index 0f0bb61cc9..a641b1e9f2 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -1000,7 +1000,7 @@ static void eliminate(AstNode* logicp, // Substitute in the new tree UASSERT_OBJ(nodep->access().isReadOnly(), nodep, "Can't replace lvalue assignments with const var"); - UASSERT_OBJ(!(VN_IS(substp, NodeVarRef) && nodep->same(substp)), + UASSERT_OBJ(!(VN_IS(substp, NodeVarRef) && nodep->isSame(substp)), // Prevent an infinite loop... substp, "Replacing node with itself; perhaps circular logic?"); // The replacement diff --git a/src/V3Reloop.cpp b/src/V3Reloop.cpp index 55f07fe352..9700bce27e 100644 --- a/src/V3Reloop.cpp +++ b/src/V3Reloop.cpp @@ -207,10 +207,10 @@ class ReloopVisitor final : public VNVisitor { if (m_mgSelLp) { // Old merge if (m_mgCfuncp == m_cfuncp // In same function && m_mgNextp == nodep // Consecutive node - && m_mgVarrefLp->same(lvarrefp) // Same array on left hand side + && m_mgVarrefLp->isSame(lvarrefp) // Same array on left hand side && (m_mgConstRp // On the right hand side either ... - ? (rconstp && m_mgConstRp->same(rconstp)) // ... same constant - : (rselp && m_mgVarrefRp->same(rvarrefp))) // ... or same array + ? (rconstp && m_mgConstRp->isSame(rconstp)) // ... same constant + : (rselp && m_mgVarrefRp->isSame(rvarrefp))) // ... or same array && (lindex == m_mgIndexLo - 1 || lindex == m_mgIndexHi + 1) // Left index +/- 1 && (m_mgConstRp || lindex == rindex + m_mgOffset) // Same right index offset ) { diff --git a/src/V3Slice.cpp b/src/V3Slice.cpp index 0076094e08..cc479b95c3 100644 --- a/src/V3Slice.cpp +++ b/src/V3Slice.cpp @@ -135,7 +135,7 @@ class SliceVisitor final : public VNVisitor { const AstUnpackArrayDType* const itemDTypep = VN_CAST(itemRawDTypep, UnpackArrayDType); if (!itemDTypep - || !expectedItemDTypep->same(itemDTypep->subDTypep()->skipRefp())) { + || !expectedItemDTypep->isSame(itemDTypep->subDTypep()->skipRefp())) { if (!m_assignError) { itemp->v3error("Item is incompatible with the array type."); }