From 9da012568c3a1dfe9625f5beb00a52b49fc754c5 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 26 Sep 2022 14:21:05 +0100 Subject: [PATCH] Ensure DFG stats are consistent --- src/V3DfgAstToDfg.cpp | 7 ++++++- src/V3DfgPasses.cpp | 7 +++++++ src/V3DfgPasses.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/V3DfgAstToDfg.cpp b/src/V3DfgAstToDfg.cpp index bae5e7a33..251561bca 100644 --- a/src/V3DfgAstToDfg.cpp +++ b/src/V3DfgAstToDfg.cpp @@ -85,6 +85,7 @@ class AstToDfgVisitor final : public VNVisitor { V3DfgOptimizationContext& m_ctx; // The optimization context for stats bool m_foundUnhandled = false; // Found node not implemented as DFG or not implemented 'visit' std::vector m_uncommittedVertices; // Vertices that we might decide to revert + bool m_converting = false; // We are trying to convert some logic at the moment // METHODS void markReferenced(AstNode* nodep) { @@ -141,8 +142,8 @@ class AstToDfgVisitor final : public VNVisitor { // VISITORS void visit(AstNode* nodep) override { // Conservatively treat this node as unhandled + if (!m_foundUnhandled && m_converting) ++m_ctx.m_nonRepUnknown; m_foundUnhandled = true; - ++m_ctx.m_nonRepUnknown; markReferenced(nodep); } void visit(AstCell* nodep) override { markReferenced(nodep); } @@ -158,6 +159,10 @@ class AstToDfgVisitor final : public VNVisitor { } void visit(AstAssignW* nodep) override { + VL_RESTORER(m_converting); + m_converting = true; + ++m_ctx.m_inputEquations; + // Cannot handle assignment with timing control yet if (nodep->timingControlp()) { markReferenced(nodep); diff --git a/src/V3DfgPasses.cpp b/src/V3DfgPasses.cpp index a2c998025..2a164feb0 100644 --- a/src/V3DfgPasses.cpp +++ b/src/V3DfgPasses.cpp @@ -53,6 +53,7 @@ V3DfgOptimizationContext::V3DfgOptimizationContext(const std::string& label) V3DfgOptimizationContext::~V3DfgOptimizationContext() { const string prefix = "Optimizations, DFG " + m_label + " "; V3Stats::addStat(prefix + "General, modules", m_modules); + V3Stats::addStat(prefix + "Ast2Dfg, input equations", m_inputEquations); V3Stats::addStat(prefix + "Ast2Dfg, representable", m_representable); V3Stats::addStat(prefix + "Ast2Dfg, non-representable (dtype)", m_nonRepDType); V3Stats::addStat(prefix + "Ast2Dfg, non-representable (impure)", m_nonRepImpure); @@ -65,6 +66,12 @@ V3DfgOptimizationContext::~V3DfgOptimizationContext() { V3Stats::addStat(prefix + "Dfg2Ast, intermediate variables", m_intermediateVars); V3Stats::addStat(prefix + "Dfg2Ast, replaced variables", m_replacedVars); V3Stats::addStat(prefix + "Dfg2Ast, result equations", m_resultEquations); + + // Check the stats are consistent + UASSERT(m_inputEquations + == m_representable + m_nonRepDType + m_nonRepImpure + m_nonRepTiming + m_nonRepLhs + + m_nonRepNode + m_nonRepUnknown + m_nonRepVarRef + m_nonRepWidth, + "Inconsistent statistics"); } // 'Inline' DfgVar nodes with known drivers diff --git a/src/V3DfgPasses.h b/src/V3DfgPasses.h index 20adfd201..8ca377cc1 100644 --- a/src/V3DfgPasses.h +++ b/src/V3DfgPasses.h @@ -54,6 +54,7 @@ class V3DfgOptimizationContext final { public: VDouble0 m_modules; // Number of modules optimized + VDouble0 m_inputEquations; // Number of input combinational equations VDouble0 m_representable; // Number of combinational equations representable VDouble0 m_nonRepDType; // Equations non-representable due to data type VDouble0 m_nonRepImpure; // Equations non-representable due to impure node