Fix multple function definitions in V3Sched (#4416).

This commit is contained in:
Wilson Snyder 2023-08-12 10:41:44 -04:00
parent 9eba61018a
commit 5447ed2629
2 changed files with 20 additions and 17 deletions

View File

@ -13,6 +13,7 @@ Verilator 5.015 devel
**Minor:**
* Fix multple function definitions in V3Sched (#4416). [Hennadii Chernyshchyk]
Verilator 5.014 2023-08-06

View File

@ -119,29 +119,29 @@ void invertAndMergeSenTreeMap(
//============================================================================
// Split large function according to --output-split-cfuncs
void splitCheck(AstCFunc* ofuncp) {
if (!v3Global.opt.outputSplitCFuncs() || !ofuncp->stmtsp()) return;
if (ofuncp->nodeCount() < v3Global.opt.outputSplitCFuncs()) return;
std::map<AstCFunc*, int> s_funcNums; // What split number to attach to a function
int funcnum = 0;
int func_stmts = 0;
const bool is_ofuncp_coroutine = ofuncp->isCoroutine();
AstCFunc* funcp = nullptr;
const auto createNewSubFuncp = [&]() {
AstCFunc* splitCheckCreateNewSubFunc(AstCFunc* ofuncp) {
auto funcNumItMatch = s_funcNums.emplace(std::make_pair(ofuncp, 0));
AstCFunc* const subFuncp = new AstCFunc{
ofuncp->fileline(), ofuncp->name() + "__" + cvtToStr(funcnum++), ofuncp->scopep()};
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());
func_stmts = 0;
return subFuncp;
};
void splitCheck(AstCFunc* ofuncp) {
if (!v3Global.opt.outputSplitCFuncs() || !ofuncp->stmtsp()) return;
if (ofuncp->nodeCount() < v3Global.opt.outputSplitCFuncs()) return;
int func_stmts = 0;
const bool is_ofuncp_coroutine = ofuncp->isCoroutine();
AstCFunc* funcp = nullptr;
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);