From 5447ed26293aced38ee97c8b190b4fb913b0e512 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 12 Aug 2023 10:41:44 -0400 Subject: [PATCH] Fix multple function definitions in V3Sched (#4416). --- Changes | 1 + src/V3Sched.cpp | 36 +++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index a688968f4..8b0bb6653 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ Verilator 5.015 devel **Minor:** +* Fix multple function definitions in V3Sched (#4416). [Hennadii Chernyshchyk] Verilator 5.014 2023-08-06 diff --git a/src/V3Sched.cpp b/src/V3Sched.cpp index 28c561c95..8948730bf 100644 --- a/src/V3Sched.cpp +++ b/src/V3Sched.cpp @@ -119,29 +119,29 @@ void invertAndMergeSenTreeMap( //============================================================================ // Split large function according to --output-split-cfuncs +std::map s_funcNums; // What split number to attach to a function + +AstCFunc* splitCheckCreateNewSubFunc(AstCFunc* ofuncp) { + auto funcNumItMatch = s_funcNums.emplace(std::make_pair(ofuncp, 0)); + AstCFunc* const subFuncp = new AstCFunc{ + ofuncp->fileline(), ofuncp->name() + "__" + cvtToStr(funcNumItMatch.first->second++), + ofuncp->scopep()}; + subFuncp->dontCombine(true); + subFuncp->isStatic(false); + subFuncp->isLoose(true); + subFuncp->slow(ofuncp->slow()); + subFuncp->declPrivate(ofuncp->declPrivate()); + return subFuncp; +}; + void splitCheck(AstCFunc* ofuncp) { if (!v3Global.opt.outputSplitCFuncs() || !ofuncp->stmtsp()) return; if (ofuncp->nodeCount() < v3Global.opt.outputSplitCFuncs()) return; - int funcnum = 0; int func_stmts = 0; const bool is_ofuncp_coroutine = ofuncp->isCoroutine(); AstCFunc* funcp = nullptr; - const auto createNewSubFuncp = [&]() { - AstCFunc* const subFuncp = new AstCFunc{ - ofuncp->fileline(), ofuncp->name() + "__" + cvtToStr(funcnum++), ofuncp->scopep()}; - subFuncp->dontCombine(true); - subFuncp->isStatic(false); - subFuncp->isLoose(true); - subFuncp->slow(ofuncp->slow()); - subFuncp->declPrivate(ofuncp->declPrivate()); - - func_stmts = 0; - - return subFuncp; - }; - const auto finishSubFuncp = [&](AstCFunc* subFuncp) { ofuncp->scopep()->addBlocksp(subFuncp); AstCCall* const callp = new AstCCall{subFuncp->fileline(), subFuncp}; @@ -160,7 +160,8 @@ void splitCheck(AstCFunc* ofuncp) { } }; - funcp = createNewSubFuncp(); + funcp = splitCheckCreateNewSubFunc(ofuncp); + func_stmts = 0; // Unlink all statements, then add item by item to new sub-functions AstBegin* const tempp = new AstBegin{ofuncp->fileline(), "[EditWrapper]", @@ -173,7 +174,8 @@ void splitCheck(AstCFunc* ofuncp) { if ((func_stmts + stmts) > v3Global.opt.outputSplitCFuncs()) { finishSubFuncp(funcp); - funcp = createNewSubFuncp(); + funcp = splitCheckCreateNewSubFunc(ofuncp); + func_stmts = 0; } funcp->addStmtsp(itemp);