From 90447d54d17935ed6a26a89215b8967b6873318b Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Fri, 7 Oct 2022 15:44:14 +0100 Subject: [PATCH] Make DfgConst hold V3Number directly Remove intermediary AstConst. No functional change intended. --- src/V3Dfg.cpp | 8 ++++---- src/V3DfgAstToDfg.cpp | 2 +- src/V3DfgDfgToAst.cpp | 2 +- src/V3DfgPeephole.cpp | 14 ++++---------- src/V3DfgVertices.h | 17 +++++++++-------- src/V3Number.h | 6 ++++++ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/V3Dfg.cpp b/src/V3Dfg.cpp index 0a12fc8c7..9aac9209d 100644 --- a/src/V3Dfg.cpp +++ b/src/V3Dfg.cpp @@ -592,7 +592,7 @@ static void dumpDotVertex(std::ostream& os, const DfgVertex& vtx) { } if (const DfgConst* const constVtxp = vtx.cast()) { - const V3Number& num = constVtxp->constp()->num(); + const V3Number& num = constVtxp->num(); os << toDotId(vtx); os << " [label=\""; @@ -915,10 +915,10 @@ void DfgVertex::replaceWith(DfgVertex* newSorucep) { // DfgConst ---------- bool DfgConst::selfEquals(const DfgVertex& that) const { - return constp()->sameTree(that.as()->constp()); + return num().isCaseEq(that.as()->num()); } -V3Hash DfgConst::selfHash() const { return m_constp->num().toHash(); } +V3Hash DfgConst::selfHash() const { return num().toHash(); } // DfgSel ---------- @@ -930,7 +930,7 @@ V3Hash DfgSel::selfHash() const { return V3Hash{lsb()}; } bool DfgVertexVar::selfEquals(const DfgVertex& that) const { UASSERT_OBJ(varp() != that.as()->varp(), this, - "There should only be one DfgVarPacked for a given AstVar"); + "There should only be one DfgVertexVar for a given AstVar"); return false; } diff --git a/src/V3DfgAstToDfg.cpp b/src/V3DfgAstToDfg.cpp index 98d114a67..93dc09186 100644 --- a/src/V3DfgAstToDfg.cpp +++ b/src/V3DfgAstToDfg.cpp @@ -458,7 +458,7 @@ class AstToDfgVisitor final : public VNVisitor { void visit(AstConst* nodep) override { UASSERT_OBJ(!nodep->user1p(), nodep, "Already has Dfg vertex"); if (unhandled(nodep)) return; - DfgVertex* const vtxp = new DfgConst{*m_dfgp, nodep->cloneTree(false)}; + DfgVertex* const vtxp = new DfgConst{*m_dfgp, nodep->fileline(), nodep->num()}; m_uncommittedVertices.push_back(vtxp); nodep->user1p(vtxp); } diff --git a/src/V3DfgDfgToAst.cpp b/src/V3DfgDfgToAst.cpp index b41660bbf..e30a31ae8 100644 --- a/src/V3DfgDfgToAst.cpp +++ b/src/V3DfgDfgToAst.cpp @@ -329,7 +329,7 @@ class DfgToAstVisitor final : DfgVisitor { } void visit(DfgConst* vtxp) override { // - m_resultp = vtxp->constp()->cloneTree(false); + m_resultp = new AstConst{vtxp->fileline(), vtxp->num()}; } void visit(DfgSel* vtxp) override { diff --git a/src/V3DfgPeephole.cpp b/src/V3DfgPeephole.cpp index 40a45dbf7..254bcde4b 100644 --- a/src/V3DfgPeephole.cpp +++ b/src/V3DfgPeephole.cpp @@ -154,17 +154,11 @@ class V3DfgPeephole final : public DfgVisitor { // Shorthand static AstNodeDType* dtypeForWidth(uint32_t width) { return DfgVertex::dtypeForWidth(width); } - // Create a new DfgConst vertex with the given width and value - DfgConst* makeConst(FileLine* flp, uint32_t width, uint32_t value) { - const int widthInt = static_cast(width); - return new DfgConst{m_dfg, new AstConst{flp, AstConst::WidthedValue{}, widthInt, value}}; - } + // Create a 32-bit DfgConst vertex + DfgConst* makeI32(FileLine* flp, uint32_t val) { return new DfgConst{m_dfg, flp, 32, val}; } - // Create a new 32-bit DfgConst vertex - DfgConst* makeI32(FileLine* flp, uint32_t value) { return makeConst(flp, 32, value); } - - // Create a new DfgConst vertex with the given width and value zero - DfgConst* makeZero(FileLine* flp, uint32_t width) { return makeConst(flp, width, 0); } + // Create a DfgConst vertex with the given width and value zero + DfgConst* makeZero(FileLine* flp, uint32_t width) { return new DfgConst{m_dfg, flp, width}; } // Constant fold unary vertex, return true if folded template diff --git a/src/V3DfgVertices.h b/src/V3DfgVertices.h index 5dccc1c27..c67a7e6fd 100644 --- a/src/V3DfgVertices.h +++ b/src/V3DfgVertices.h @@ -79,21 +79,22 @@ class DfgConst final : public DfgVertex { friend class DfgVertex; friend class DfgVisitor; - AstConst* const m_constp; // The AstConst associated with this vertex (owned by this vertex) + V3Number m_num; // Constant value bool selfEquals(const DfgVertex& that) const override; V3Hash selfHash() const override; public: - DfgConst(DfgGraph& dfg, AstConst* constp) - : DfgVertex{dfg, dfgType(), constp->fileline(), dtypeFor(constp)} - , m_constp{constp} {} + DfgConst(DfgGraph& dfg, FileLine* flp, const V3Number& num) + : DfgVertex{dfg, dfgType(), flp, dtypeForWidth(num.width())} + , m_num{num} {} + DfgConst(DfgGraph& dfg, FileLine* flp, uint32_t width, uint32_t value = 0) + : DfgVertex{dfg, dfgType(), flp, dtypeForWidth(width)} + , m_num{flp, static_cast(width), value} {} ASTGEN_MEMBERS_DfgConst; - ~DfgConst() override { VL_DO_DANGLING(m_constp->deleteTree(), m_constp); } - - AstConst* constp() const { return m_constp; } - V3Number& num() const { return m_constp->num(); } + V3Number& num() { return m_num; } + const V3Number& num() const { return m_num; } uint32_t toU32() const { return num().toUInt(); } int32_t toI32() const { return num().toSInt(); } diff --git a/src/V3Number.h b/src/V3Number.h index 7e4ec09c1..a419e9a0e 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -472,6 +472,12 @@ public: m_data.num()[0].m_value = value; opCleanThis(); } + V3Number(FileLine* flp, int width, uint32_t value) { + init(nullptr, width, true); + m_fileline = flp; + m_data.num()[0].m_value = value; + opCleanThis(); + } // Create from a verilog 32'hxxxx number. V3Number(AstNode* nodep, const char* sourcep) { create(nodep, sourcep); } V3Number(FileLine* flp, const char* sourcep) { create(flp, sourcep); }