From 3bf001835431ef83c1e4d33f259723cccb039db6 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 12 Sep 2026 14:36:45 -0400 Subject: [PATCH] Optimize away __Vconfigure if empty function --- src/V3EmitCHeaders.cpp | 4 +++- src/V3EmitCImp.cpp | 6 +++--- src/V3EmitCSyms.cpp | 20 +++++++++++--------- test_regress/t/t_protect_ids_key.out | 1 - 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/V3EmitCHeaders.cpp b/src/V3EmitCHeaders.cpp index a071e4a0b..08e8d6a0c 100644 --- a/src/V3EmitCHeaders.cpp +++ b/src/V3EmitCHeaders.cpp @@ -209,7 +209,9 @@ class EmitCHeader final : public EmitCConstInit { if (!VN_IS(modp, Class)) { decorateFirst(first, section); - puts("void " + protect("__Vconfigure") + "(bool first);\n"); + if (v3Global.opt.coverage()) { + puts("void " + protect("__Vconfigure") + "(bool first);\n"); + } } else { decorateFirst(first, section); const std::string name = V3OutFormatter::quoteNameControls( diff --git a/src/V3EmitCImp.cpp b/src/V3EmitCImp.cpp index 0f968d486..e56677f7d 100644 --- a/src/V3EmitCImp.cpp +++ b/src/V3EmitCImp.cpp @@ -163,12 +163,12 @@ class EmitCImp final : public EmitCFunc { "(" + modName + "* vlSelf, bool first);"); } - puts("\nvoid " + modName + "::" + protect("__Vconfigure") + "(bool first) {\n"); - puts("(void)first; // Prevent unused variable warning\n"); if (v3Global.opt.coverage()) { + puts("\nvoid " + modName + "::" + protect("__Vconfigure") + "(bool first) {\n"); + puts("(void)first; // Prevent unused variable warning\n"); puts(modName + "__" + protect("_configure_coverage") + "(this, first);\n"); + puts("}\n"); } - puts("}\n"); } void emitCoverageImp() { // Rather than putting out VL_COVER_INSERT calls directly, we do it via this diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index bf20e0f71..6490a911c 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -1277,15 +1277,17 @@ std::vector EmitCSyms::getSymCtorStmts() { add(stmt); } - add("// Setup each module's pointer back to symbol table (for public functions)"); - for (const ScopeModPair& i : m_scopes) { - const AstScope* const scopep = i.first; - AstNodeModule* const modp = i.second; - // first is used by AstCoverDecl's call to __vlCoverInsert - const bool first = !modp->user1(); - modp->user1(true); - add(VIdProtect::protectIf(scopep->nameDotless(), scopep->protect()) + "." - + protect("__Vconfigure") + "(" + (first ? "true" : "false") + ");"); + if (v3Global.opt.coverage()) { + add("// Setup each module's pointer back to symbol table (for public functions)"); + for (const ScopeModPair& i : m_scopes) { + const AstScope* const scopep = i.first; + AstNodeModule* const modp = i.second; + // first is used by AstCoverDecl's call to __vlCoverInsert + const bool first = !modp->user1(); + modp->user1(true); + add(VIdProtect::protectIf(scopep->nameDotless(), scopep->protect()) + "." + + protect("__Vconfigure") + "(" + (first ? "true" : "false") + ");"); + } } // Every scope has the same construction shape, so all fold into one table with no diff --git a/test_regress/t/t_protect_ids_key.out b/test_regress/t/t_protect_ids_key.out index ef4f013ca..6417d1d28 100644 --- a/test_regress/t/t_protect_ids_key.out +++ b/test_regress/t/t_protect_ids_key.out @@ -12,7 +12,6 @@ -