From 1f9f891a8f88c715847f5744fabc65c0310a15ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Chmiel?= Date: Fri, 20 Dec 2024 10:06:31 +0100 Subject: [PATCH] Avoid double prof exec init in hier childs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bartłomiej Chmiel --- bin/verilator_gantt | 1 + src/V3EmitCModel.cpp | 3 ++- src/V3Order.cpp | 4 ++-- src/V3Sched.cpp | 18 ++++++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/verilator_gantt b/bin/verilator_gantt index 40450d2992f..c2291cd0d75 100755 --- a/bin/verilator_gantt +++ b/bin/verilator_gantt @@ -324,6 +324,7 @@ def report_sections(): scope = scope[1].setdefault(item, [0, {}, 0]) scope[2] += 1 dt = time - prevTime + assert dt > 0 scope = sectionTree for item in prevStack: scope = scope[1].setdefault(item, [0, {}, 0]) diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index d31dc8ca60c..bba4545579c 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -432,7 +432,8 @@ class EmitCModel final : public EmitCFunc { puts(topModNameProtected + "__" + protect("_eval_settle") + "(&(vlSymsp->TOP));\n"); puts("}\n"); - if (v3Global.opt.profExec()) puts("vlSymsp->__Vm_executionProfilerp->configure();\n"); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + puts("vlSymsp->__Vm_executionProfilerp->configure();\n"); puts("VL_DEBUG_IF(VL_DBG_MSGF(\"+ Eval\\n\"););\n"); puts(topModNameProtected + "__" + protect("_eval") + "(&(vlSymsp->TOP));\n"); diff --git a/src/V3Order.cpp b/src/V3Order.cpp index 431a5f95679..0a9d7862ccf 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -122,7 +122,7 @@ AstCFunc* V3Order::order(AstNetlist* netlistp, // return resp; }(); - if (v3Global.opt.profExec()) { + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) { funcp->addStmtsp(new AstCStmt{flp, "VL_EXEC_TRACE_ADD_RECORD(vlSymsp).sectionPush(\"func " + tag + "\");\n"}); } @@ -152,7 +152,7 @@ AstCFunc* V3Order::order(AstNetlist* netlistp, // // Dispose of the remnants of the inputs for (auto* const lbsp : logic) lbsp->deleteActives(); - if (v3Global.opt.profExec()) { + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) { funcp->addStmtsp(new AstCStmt{flp, "VL_EXEC_TRACE_ADD_RECORD(vlSymsp).sectionPop();\n"}); } diff --git a/src/V3Sched.cpp b/src/V3Sched.cpp index d85cf93b866..86df189cc5b 100644 --- a/src/V3Sched.cpp +++ b/src/V3Sched.cpp @@ -226,7 +226,8 @@ EvalLoop createEvalLoop( AstNodeStmt* stmtps = nullptr; // Prof-exec section push - if (v3Global.opt.profExec()) stmtps = profExecSectionPush(flp, "loop " + tag); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + stmtps = profExecSectionPush(flp, "loop " + tag); const auto addVar = [&](const std::string& name, int width, uint32_t initVal) { AstVarScope* const vscp = scopeTopp->createTemp("__V" + tag + name, width); @@ -273,7 +274,8 @@ EvalLoop createEvalLoop( } // Prof-exec section pop - if (v3Global.opt.profExec()) stmtps->addNext(profExecSectionPop(flp)); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + stmtps->addNext(profExecSectionPop(flp)); return {firstIterFlagp, stmtps}; } @@ -630,7 +632,8 @@ const TriggerKit createTriggers(AstNetlist* netlistp, AstCFunc* const initFuncp, // Create the trigger computation function AstCFunc* const funcp = makeSubFunction(netlistp, "_eval_triggers__" + name, slow); - if (v3Global.opt.profExec()) funcp->addStmtsp(profExecSectionPush(flp, "trig " + name)); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + funcp->addStmtsp(profExecSectionPush(flp, "trig " + name)); // Create the trigger dump function (for debugging, always 'slow') AstCFunc* const dumpp = makeSubFunction(netlistp, "_dump_triggers__" + name, true); @@ -781,7 +784,8 @@ const TriggerKit createTriggers(AstNetlist* netlistp, AstCFunc* const initFuncp, add("#endif\n"); } - if (v3Global.opt.profExec()) funcp->addStmtsp(profExecSectionPop(flp)); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + funcp->addStmtsp(profExecSectionPop(flp)); // The debug code might leak signal names, so simply delete it when using --protect-ids if (v3Global.opt.protectIds()) dumpp->stmtsp()->unlinkFrBackWithNext()->deleteTree(); @@ -1110,7 +1114,8 @@ void createEval(AstNetlist* netlistp, // AstCFunc* const funcp = makeTopFunction(netlistp, "_eval", false); netlistp->evalp(funcp); - if (v3Global.opt.profExec()) funcp->addStmtsp(profExecSectionPush(flp, "eval")); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + funcp->addStmtsp(profExecSectionPush(flp, "eval")); // Start with the ico loop, if any if (icoLoop) funcp->addStmtsp(icoLoop); @@ -1121,7 +1126,8 @@ void createEval(AstNetlist* netlistp, // // Add the Postponed eval call if (postponedFuncp) funcp->addStmtsp(callVoidFunc(postponedFuncp)); - if (v3Global.opt.profExec()) funcp->addStmtsp(profExecSectionPop(flp)); + if (v3Global.opt.profExec() && !v3Global.opt.hierChild()) + funcp->addStmtsp(profExecSectionPop(flp)); } } // namespace