From e609328ebbe562bbc7f881c782328778ac2c74c7 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Sat, 4 Jul 2020 17:58:22 +0100 Subject: [PATCH] Ensure VarRef inherits dtype when varp is set. Inlining used to set some VarRefs to point to new Var nodes, without updating the dtype of the VarRef to the dtype of the new Var. AstNode::sameTree does identity comparison on the dtype, so some trees that were semantically the same did not compare as such with sameTree because of the dtype. This in turn results in some missed opportunities for combining equivalent SenTree sensitivities when the clock came from outside. --- src/V3Ast.h | 14 ++++++-------- src/V3Inst.cpp | 1 - 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index a810a9b01..6df65c72f 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2269,29 +2269,26 @@ private: string m_name; // Name of variable string m_hiername; // Scope converted into name-> for emitting bool m_hierThis; // Hiername points to "this" function - void init(); public: AstNodeVarRef(AstType t, FileLine* fl, const string& name, bool lvalue) : AstNodeMath(t, fl) , m_lvalue(lvalue) - , m_varp(NULL) , m_varScopep(NULL) , m_packagep(NULL) , m_name(name) , m_hierThis(false) { - init(); + this->varp(NULL); } AstNodeVarRef(AstType t, FileLine* fl, const string& name, AstVar* varp, bool lvalue) : AstNodeMath(t, fl) , m_lvalue(lvalue) - , m_varp(varp) , m_varScopep(NULL) , m_packagep(NULL) , m_name(name) , m_hierThis(false) { // May have varp==NULL - init(); + this->varp(varp); } ASTNODE_BASE_FUNCS(NodeVarRef) virtual bool hasDType() const { return true; } @@ -2303,7 +2300,7 @@ public: bool lvalue() const { return m_lvalue; } void lvalue(bool lval) { m_lvalue = lval; } // Avoid using this; Set in constructor AstVar* varp() const { return m_varp; } // [After Link] Pointer to variable - void varp(AstVar* varp) { m_varp = varp; } + void varp(AstVar* varp); AstVarScope* varScopep() const { return m_varScopep; } void varScopep(AstVarScope* varscp) { m_varScopep = varscp; } string hiername() const { return m_hiername; } @@ -2943,8 +2940,9 @@ inline bool AstNode::sameGateTree(const AstNode* node2p) const { return sameTreeIter(this, node2p, true, true); } -inline void AstNodeVarRef::init() { - if (m_varp) dtypep(m_varp->dtypep()); +inline void AstNodeVarRef::varp(AstVar* varp) { + m_varp = varp; + dtypeFrom(varp); } inline bool AstNodeDType::isFourstate() const { return basicp()->isFourstate(); } diff --git a/src/V3Inst.cpp b/src/V3Inst.cpp index c42234ff7..1fb8467cb 100644 --- a/src/V3Inst.cpp +++ b/src/V3Inst.cpp @@ -443,7 +443,6 @@ private: string newname = varrefp->name() + "__BRA__" + cvtToStr(i + offset) + "__KET__"; AstVarXRef* newVarXRefp = new AstVarXRef(nodep->fileline(), newname, "", true); newVarXRefp->varp(newp->modVarp()); - newVarXRefp->dtypep(newp->modVarp()->dtypep()); newp->exprp()->unlinkFrBack()->deleteTree(); newp->exprp(newVarXRefp); if (!prevPinp) {