From 60fe2c873cc1ad270197b42d751868192f136ff4 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Tue, 2 Dec 2025 12:19:45 +0000 Subject: [PATCH] Optimize trace initialization code size (#6749) --- include/verilated_fst_c.cpp | 3 ++- include/verilated_fst_c.h | 2 +- include/verilated_saif_c.cpp | 3 ++- include/verilated_saif_c.h | 2 +- include/verilated_vcd_c.cpp | 3 ++- include/verilated_vcd_c.h | 2 +- src/V3EmitCModel.cpp | 3 +-- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/verilated_fst_c.cpp b/include/verilated_fst_c.cpp index 8c15533f7..34465d61b 100644 --- a/include/verilated_fst_c.cpp +++ b/include/verilated_fst_c.cpp @@ -149,8 +149,9 @@ static std::pair toFstScopeType(VerilatedTracePrefixType typ } } -void VerilatedFst::pushPrefix(const std::string& name, VerilatedTracePrefixType type) { +void VerilatedFst::pushPrefix(const char* namep, VerilatedTracePrefixType type) { assert(!m_prefixStack.empty()); // Constructor makes an empty entry + const std::string name{namep}; // An empty name means this is the root of a model created with // name()=="". The tools get upset if we try to pass this as empty, so // we put the signals under a new $rootio scope, but the signals diff --git a/include/verilated_fst_c.h b/include/verilated_fst_c.h index adcb96166..64d1c5927 100644 --- a/include/verilated_fst_c.h +++ b/include/verilated_fst_c.h @@ -110,7 +110,7 @@ public: //========================================================================= // Internal interface to Verilator generated code - void pushPrefix(const std::string&, VerilatedTracePrefixType); + void pushPrefix(const char*, VerilatedTracePrefixType); void popPrefix(); void declEvent(uint32_t code, uint32_t fidx, const char* name, int dtypenum, diff --git a/include/verilated_saif_c.cpp b/include/verilated_saif_c.cpp index 326b2571a..e6aa1df13 100644 --- a/include/verilated_saif_c.cpp +++ b/include/verilated_saif_c.cpp @@ -474,8 +474,9 @@ void VerilatedSaif::printIndent() { printStr(std::string(m_indent, ' ')); // Must use () constructor } -void VerilatedSaif::pushPrefix(const std::string& name, VerilatedTracePrefixType type) { +void VerilatedSaif::pushPrefix(const char* namep, VerilatedTracePrefixType type) { assert(!m_prefixStack.empty()); // Constructor makes an empty entry + const std::string name{namep}; // An empty name means this is the root of a model created with // name()=="". The tools get upset if we try to pass this as empty, so // we put the signals under a new $rootio scope, but the signals diff --git a/include/verilated_saif_c.h b/include/verilated_saif_c.h index aab5ddb05..1e8c7f833 100644 --- a/include/verilated_saif_c.h +++ b/include/verilated_saif_c.h @@ -143,7 +143,7 @@ public: //========================================================================= // Internal interface to Verilator generated code - void pushPrefix(const std::string&, VerilatedTracePrefixType); + void pushPrefix(const char*, VerilatedTracePrefixType); void popPrefix(); void declEvent(uint32_t code, uint32_t fidx, const char* name, int dtypenum, diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 8cca02c0e..79da93ff6 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -321,8 +321,9 @@ void VerilatedVcd::printIndent(int level_change) { if (level_change > 0) m_indent += level_change; } -void VerilatedVcd::pushPrefix(const std::string& name, VerilatedTracePrefixType type) { +void VerilatedVcd::pushPrefix(const char* namep, VerilatedTracePrefixType type) { assert(!m_prefixStack.empty()); // Constructor makes an empty entry + const std::string name{namep}; // An empty name means this is the root of a model created with // name()=="". The tools get upset if we try to pass this as empty, so // we put the signals under a new $rootio scope, but the signals diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index 500ec755f..9f48a53e3 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -134,7 +134,7 @@ public: //========================================================================= // Internal interface to Verilator generated code - void pushPrefix(const std::string&, VerilatedTracePrefixType); + void pushPrefix(const char*, VerilatedTracePrefixType); void popPrefix(); void declEvent(uint32_t code, uint32_t fidx, const char* name, int dtypenum, diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index fa6ad3dc3..bcc2b9ecf 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -549,8 +549,7 @@ class EmitCModel final : public EmitCFunc { "0.\");\n"); puts("}\n"); puts("vlSymsp->__Vm_baseCode = code;\n"); - puts("tracep->pushPrefix(std::string{vlSymsp->name()}, " - "VerilatedTracePrefixType::SCOPE_MODULE);\n"); + puts("tracep->pushPrefix(vlSymsp->name(), VerilatedTracePrefixType::SCOPE_MODULE);\n"); puts(topModNameProtected + "__" + protect("trace_decl_types") + "(tracep);\n"); puts(topModNameProtected + "__" + protect("trace_init_top") + "(vlSelf, tracep);\n"); puts("tracep->popPrefix();\n");