Skip to content

Commit

Permalink
Fix multple function definitions in V3Sched (verilator#4416).
Browse files Browse the repository at this point in the history
  • Loading branch information
wsnyder committed Aug 12, 2023
1 parent 9eba610 commit 5447ed2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Verilator 5.015 devel

**Minor:**

* Fix multple function definitions in V3Sched (#4416). [Hennadii Chernyshchyk]


Verilator 5.014 2023-08-06
Expand Down
36 changes: 19 additions & 17 deletions src/V3Sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,29 @@ void invertAndMergeSenTreeMap(
//============================================================================
// Split large function according to --output-split-cfuncs

std::map<AstCFunc*, int> 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};
Expand All @@ -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]",
Expand All @@ -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);
Expand Down

0 comments on commit 5447ed2

Please sign in to comment.