Internals: Fix same() called outside of sameTree (#4561).

This commit is contained in:
Wilson Snyder 2023-10-18 17:36:09 -04:00
parent 8720841c48
commit b7233d063f
6 changed files with 14 additions and 8 deletions

View File

@ -1773,6 +1773,9 @@ protected:
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 @@ public:
// 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

View File

@ -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());
}

View File

@ -1434,7 +1434,7 @@ private:
// 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;
}

View File

@ -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

View File

@ -207,10 +207,10 @@ private:
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
) {

View File

@ -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.");
}