Optimize repeated function call during symbol table init (#6665)

This commit is contained in:
Geza Lore 2025-11-08 21:48:00 +00:00 committed by GitHub
parent c493982511
commit 107776f324
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 8 deletions

View File

@ -3454,12 +3454,12 @@ void* VerilatedVarProps::datapAdjustIndex(void* datap, int dim, int indx) const
//====================================================================== //======================================================================
// VerilatedScope:: Methods // VerilatedScope:: Methods
VerilatedScope::VerilatedScope(VerilatedSyms* symsp, const char* prefixp, const char* suffixp, VerilatedScope::VerilatedScope(VerilatedSyms* symsp, const char* suffixp, const char* identifier,
const char* identifier, const char* defnamep, int8_t timeunit, const char* defnamep, int8_t timeunit, Type type)
Type type)
: m_symsp{symsp} : m_symsp{symsp}
, m_namep{[prefixp, suffixp]() { , m_namep{[symsp, suffixp]() {
// We don't want the space and reference-count access overhead of strings. // We don't want the space and reference-count access overhead of strings.
const char* prefixp = symsp->name();
char* const namep = new char[std::strlen(prefixp) + std::strlen(suffixp) + 2]; char* const namep = new char[std::strlen(prefixp) + std::strlen(suffixp) + 2];
char* dp = namep; char* dp = namep;
for (const char* sp = prefixp; *sp;) *dp++ = *sp++; for (const char* sp = prefixp; *sp;) *dp++ = *sp++;

View File

@ -680,6 +680,8 @@ public: // But for internal use only
explicit VerilatedSyms(VerilatedContext* contextp); // Pass null for default context explicit VerilatedSyms(VerilatedContext* contextp); // Pass null for default context
~VerilatedSyms(); ~VerilatedSyms();
VL_UNCOPYABLE(VerilatedSyms); VL_UNCOPYABLE(VerilatedSyms);
virtual const char* name() const = 0;
}; };
//=========================================================================== //===========================================================================
@ -707,8 +709,8 @@ private:
const Type m_type; // Type of the scope const Type m_type; // Type of the scope
public: // But internals only - called from verilated modules, VerilatedSyms public: // But internals only - called from verilated modules, VerilatedSyms
VerilatedScope(VerilatedSyms* symsp, const char* prefixp, const char* suffixp, VerilatedScope(VerilatedSyms* symsp, const char* suffixp, const char* identifier,
const char* identifier, const char* defnamep, int8_t timeunit, Type type); const char* defnamep, int8_t timeunit, Type type);
~VerilatedScope(); ~VerilatedScope();
void exportInsert(int finalize, const char* namep, void* cb) VL_MT_UNSAFE; void exportInsert(int finalize, const char* namep, void* cb) VL_MT_UNSAFE;

View File

@ -552,7 +552,7 @@ void EmitCSyms::emitSymHdr() {
for (const std::string& funcName : m_splitFuncNames) { puts("void " + funcName + "();\n"); } for (const std::string& funcName : m_splitFuncNames) { puts("void " + funcName + "();\n"); }
puts("\n// METHODS\n"); puts("\n// METHODS\n");
puts("const char* name() { return TOP.vlNamep; }\n"); puts("const char* name() const { return TOP.vlNamep; }\n");
if (v3Global.hasEvents()) { if (v3Global.hasEvents()) {
if (v3Global.assignsEvents()) { if (v3Global.assignsEvents()) {
@ -736,7 +736,7 @@ std::vector<std::string> EmitCSyms::getSymCtorStmts() {
for (const auto& itpair : m_scopeNames) { for (const auto& itpair : m_scopeNames) {
const ScopeData& sd = itpair.second; const ScopeData& sd = itpair.second;
std::string stmt; std::string stmt;
stmt += protect("__Vscopep_" + sd.m_symName) + " = new VerilatedScope{this, name(), \""; stmt += protect("__Vscopep_" + sd.m_symName) + " = new VerilatedScope{this, \"";
stmt += V3OutFormatter::quoteNameControls( stmt += V3OutFormatter::quoteNameControls(
VIdProtect::protectWordsIf(sd.m_prettyName, true)); VIdProtect::protectWordsIf(sd.m_prettyName, true));
stmt += "\", \""; stmt += "\", \"";