mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Internals: Dump Ast expression pattern statistics like Dfg (#7818)
Remove the expression combination counts from the default stats file, and add a new `--dump-ast-patterns` option, which will dump new `*_ast_patterns_*.txt` files. These contain the expression combinations in a similar S-expression format as Dfg already produces with `--dump-dfg-stats`. These dumps are not produced by just `--stats` as they are fairly expensive to compute. Currently the new option will dump at two points: just before we change to C types via widthMin usage, and just before emit.
This commit is contained in:
@@ -35,15 +35,12 @@ class StatsVisitor final : public VNVisitorConst {
|
||||
struct Counters final {
|
||||
// Nodes of given type
|
||||
std::array<uint64_t, VNType::NUM_TYPES()> m_statTypeCount{};
|
||||
// Nodes of given type with given type immediate child
|
||||
std::array<std::array<uint64_t, VNType::NUM_TYPES()>, VNType::NUM_TYPES()> m_statAbove{};
|
||||
// Prediction of given type
|
||||
std::array<uint64_t, VBranchPred::_ENUM_END> m_statPred{};
|
||||
};
|
||||
|
||||
// STATE
|
||||
const bool m_fastOnly; // When true, consider only fast functions
|
||||
const AstNodeExpr* m_parentExprp = nullptr; // Parent expression
|
||||
Counters m_counters; // The actual counts we will display
|
||||
Counters m_dumpster; // Alternate buffer to make discarding parts of the tree easier
|
||||
Counters* m_accump; // The currently active accumulator
|
||||
@@ -75,14 +72,6 @@ class StatsVisitor final : public VNVisitorConst {
|
||||
countThenIterateChildren(nodep);
|
||||
}
|
||||
|
||||
void visit(AstNodeExpr* nodep) override {
|
||||
// Count expression combinations
|
||||
if (m_parentExprp) ++m_accump->m_statAbove[m_parentExprp->type()][nodep->type()];
|
||||
VL_RESTORER(m_parentExprp);
|
||||
m_parentExprp = nodep;
|
||||
countThenIterateChildren(nodep);
|
||||
}
|
||||
|
||||
void visit(AstNodeIf* nodep) override {
|
||||
// Track prediction
|
||||
++m_accump->m_statPred[nodep->branchPred()];
|
||||
@@ -148,15 +137,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Expression combinations
|
||||
for (size_t t1 = 0; t1 < VNType::NUM_TYPES(); ++t1) {
|
||||
for (size_t t2 = 0; t2 < VNType::NUM_TYPES(); ++t2) {
|
||||
if (const uint64_t c = m_counters.m_statAbove[t1][t2]) {
|
||||
addStat("Expr combination, " + typeName(t1) + " over " + typeName(t2), c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Branch predictions
|
||||
for (int t = 0; t < VBranchPred::_ENUM_END; ++t) {
|
||||
if (const uint64_t c = m_counters.m_statPred[t]) {
|
||||
|
||||
Reference in New Issue
Block a user