From 9670dabcfee97b4b4712cd033c6de6bec1f57e65 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 22 Jun 2026 10:04:42 +0100 Subject: [PATCH] Internals: Keep separate stats for constant pool variables --- src/V3Stats.cpp | 54 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/src/V3Stats.cpp b/src/V3Stats.cpp index dfa27b99e..a1ad5edb2 100644 --- a/src/V3Stats.cpp +++ b/src/V3Stats.cpp @@ -46,6 +46,9 @@ class StatsVisitor final : public VNVisitorConst { Counters m_dumpster; // Alternate buffer to make discarding parts of the tree easier Counters* m_accump; // The currently active accumulator std::vector m_statVarWidths; // Variables of given width + std::vector m_constPoolConsts; // Constant pool constants of given width + // Constant pool tables of given width and depth + std::map, uint64_t> m_constPoolTables; std::vector> m_statVarWidthNames; // Var names of given width @@ -59,15 +62,30 @@ class StatsVisitor final : public VNVisitorConst { // VISITORS void visit(AstVar* nodep) override { if (nodep->dtypep()) { - if (m_statVarWidths.size() <= static_cast(nodep->width())) { - m_statVarWidths.resize(nodep->width() + 5); - if (v3Global.opt.statsVars()) { // - m_statVarWidthNames.resize(nodep->width() + 5); + if (nodep->constPoolEntry()) { + // Count constant pool entries + if (AstUnpackArrayDType* const uatp = VN_CAST(nodep->dtypep(), UnpackArrayDType)) { + const int width = uatp->subDTypep()->width(); + const int depth = uatp->elementsConst(); + ++m_constPoolTables[{width, depth}]; + } else { + if (m_constPoolConsts.size() <= static_cast(nodep->width())) { + m_constPoolConsts.resize(nodep->width() + 5); + } + ++m_constPoolConsts.at(nodep->width()); + } + } else { + // Count proper variables + if (m_statVarWidths.size() <= static_cast(nodep->width())) { + m_statVarWidths.resize(nodep->width() + 5); + if (v3Global.opt.statsVars()) { // + m_statVarWidthNames.resize(nodep->width() + 5); + } + } + ++m_statVarWidths.at(nodep->width()); + if (v3Global.opt.statsVars()) { + ++m_statVarWidthNames.at(nodep->width())[nodep->prettyName()]; } - } - ++m_statVarWidths.at(nodep->width()); - if (v3Global.opt.statsVars()) { - ++m_statVarWidthNames.at(nodep->width())[nodep->prettyName()]; } } @@ -118,6 +136,26 @@ public: } } + // Constant pool constants + for (size_t i = 0; i < m_constPoolConsts.size(); ++i) { + const uint64_t count = m_constPoolConsts.at(i); + if (!count) continue; + std::stringstream ss; + ss << "Vars Const, width " << std::setw(5) << std::dec << i; + addStat(ss.str(), count); + } + + // Constant pool tables + for (const auto& it : m_constPoolTables) { + const int depth = it.first.second; + const int width = it.first.first; + const int count = it.second; + std::ostringstream ss; + ss << "Vars Table, width " << std::setw(5) << std::dec << width // + << " x " << std::setw(5) << std::dec << depth; + addStat(ss.str(), count); + } + // Node types (also total memory usage) const auto typeName = [](size_t t) { return std::string{VNType{static_cast(t)}.ascii()}; };