From 1a3378e0f5aac0a7c1af7796480d63fb6ed9ef55 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 20 Dec 2014 08:28:31 -0500 Subject: [PATCH] Add --stats-vars, bug851. --- Changes | 2 ++ bin/verilator | 7 +++++++ src/V3Options.cpp | 2 ++ src/V3Options.h | 2 ++ src/V3Stats.cpp | 28 +++++++++++++++++++++++++--- test_regress/t/t_flag_stats.pl | 21 +++++++++++++++++++++ test_regress/t/t_flag_stats.v | 13 +++++++++++++ 7 files changed, 72 insertions(+), 3 deletions(-) create mode 100755 test_regress/t/t_flag_stats.pl create mode 100644 test_regress/t/t_flag_stats.v diff --git a/Changes b/Changes index c71683f74..701c3410c 100644 --- a/Changes +++ b/Changes @@ -21,6 +21,8 @@ indicates the contributor was also the author of the fix; Thanks! Note that SystemC traces will no longer show the signals in the wrapper, they can be seen one level further down. +**** Add --stats-vars, bug851. [Jeremy Bennett] + **** Fix bare generates in interfaces, bug789. [Bob Newgard] **** Fix underscores in real literals, bug863. [Jonathon Donaldson] diff --git a/bin/verilator b/bin/verilator index 6fcea3a1f..04a827879 100755 --- a/bin/verilator +++ b/bin/verilator @@ -309,6 +309,7 @@ descriptions in the next sections for more information. --savable Enable model save-restore --sc Create SystemC output --stats Create statistics file + --stats-vars Provide statistics on variables -sv Enable SystemVerilog parsing +systemverilogext+ Synonym for +1800-2012ext+ --top-module Name of top level input module @@ -966,6 +967,12 @@ Specifies SystemC output mode; see also --cc. Creates a dump file with statistics on the design in {prefix}__stats.txt. +=item --stats-vars + +Creates more detailed statistics including a list of all the variables by +size (plain --stats just gives a count). See --stats, which is implied by +this. + =item -sv Specifies SystemVerilog language features should be enabled; equivalent to diff --git a/src/V3Options.cpp b/src/V3Options.cpp index ee1c0d0f5..3f81aebd9 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -761,6 +761,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( onoff (sw, "-skip-identical", flag/*ref*/) ) { m_skipIdentical = flag; } else if ( !strcmp (sw, "-sp-deprecated") ) { m_outFormatOk = true; m_systemC = true; m_systemPerl = true; } // Undocumented, old else if ( onoff (sw, "-stats", flag/*ref*/) ) { m_stats = flag; } + else if ( onoff (sw, "-stats-vars", flag/*ref*/) ) { m_statsVars = flag; m_stats |= flag; } else if ( !strcmp (sw, "-sv") ) { m_defaultLanguage = V3LangCode::L1800_2005; } else if ( onoff (sw, "-trace", flag/*ref*/) ) { m_trace = flag; } else if ( onoff (sw, "-trace-dups", flag/*ref*/) ) { m_traceDups = flag; } @@ -1228,6 +1229,7 @@ V3Options::V3Options() { m_savable = false; m_skipIdentical = true; m_stats = false; + m_statsVars = false; m_systemC = false; m_systemPerl = false; m_trace = false; diff --git a/src/V3Options.h b/src/V3Options.h index 30208b935..6eb220009 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -87,6 +87,7 @@ class V3Options { bool m_skipIdentical;// main switch: --skip-identical bool m_systemPerl; // main switch: --sp: System Perl instead of SystemC (m_systemC also set) bool m_stats; // main switch: --stats + bool m_statsVars; // main switch: --stats-vars bool m_trace; // main switch: --trace bool m_traceDups; // main switch: --trace-dups bool m_traceParams; // main switch: --trace-params @@ -202,6 +203,7 @@ class V3Options { bool savable() const { return m_savable; } bool skipIdentical() const { return m_skipIdentical; } bool stats() const { return m_stats; } + bool statsVars() const { return m_statsVars; } bool assertOn() const { return m_assert; } // assertOn as __FILE__ may be defined bool autoflush() const { return m_autoflush; } bool bboxSys() const { return m_bboxSys; } diff --git a/src/V3Stats.cpp b/src/V3Stats.cpp index 5299bc052..ab36974a5 100644 --- a/src/V3Stats.cpp +++ b/src/V3Stats.cpp @@ -40,6 +40,9 @@ class StatsVisitor : public AstNVisitor { private: // NODE STATE/TYPES + + typedef map NameMap; // Number of times a name appears + // STATE string m_stage; // Name of the stage we are scanning bool m_fast; // Counting only fastpath @@ -54,7 +57,8 @@ private: V3Double0 m_statPred[AstBranchPred::_ENUM_END]; // Nodes of given type V3Double0 m_statInstr; // Instruction count V3Double0 m_statInstrFast; // Instruction count - vector m_statVarWidths; // Variables of given type + vector m_statVarWidths; // Variables of given width + vector m_statVarWidthNames; // Var names of given width V3Double0 m_statVarArray; // Statistic tracking V3Double0 m_statVarBytes; // Statistic tracking V3Double0 m_statVarClock; // Statistic tracking @@ -100,8 +104,18 @@ private: else m_statVarBytes += nodep->dtypeSkipRefp()->widthTotalBytes(); if (int(m_statVarWidths.size()) <= nodep->width()) { m_statVarWidths.resize(nodep->width()+5); + if (v3Global.opt.statsVars()) m_statVarWidthNames.resize(nodep->width()+5); } ++ m_statVarWidths.at(nodep->width()); + string pn = nodep->prettyName(); + if (v3Global.opt.statsVars()) { + NameMap& nameMapr = m_statVarWidthNames.at(nodep->width()); + if (nameMapr.find(pn) != nameMapr.end()) { + nameMapr[pn]++; + } else { + nameMapr[pn]=1; + } + } } } virtual void visit(AstVarScope* nodep, AstNUser*) { @@ -208,8 +222,16 @@ public: } for (unsigned i=0; ifirst; + V3Stats::addStat(m_stage, os.str(), it->second); + } + } else { + ostringstream os; os<<"Vars, width "<{vlt} or $Self->skip("Verilator only test"); + +compile ( + verilator_flags2 => ["--stats --stats-vars"], + ); + +execute ( + check_finished=>1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_flag_stats.v b/test_regress/t/t_flag_stats.v new file mode 100644 index 000000000..2bd129e5d --- /dev/null +++ b/test_regress/t/t_flag_stats.v @@ -0,0 +1,13 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2014 by Wilson Snyder. + +module t (b); + output reg [31:0] b; + initial begin + b = 22; + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule