removed ensureEntry

This commit is contained in:
em2machine 2025-12-21 21:37:51 +01:00
parent fd60e349ee
commit 7a49fdf9f3
3 changed files with 37 additions and 35 deletions

View File

@ -568,14 +568,7 @@ class UndrivenVisitor final : public VNVisitorConst {
iterateChildrenConst(nodep); iterateChildrenConst(nodep);
if (nodep->keyword() == VAlwaysKwd::ALWAYS_COMB) UINFO(9, " Done " << nodep); if (nodep->keyword() == VAlwaysKwd::ALWAYS_COMB) UINFO(9, " Done " << nodep);
} }
// EOM
/*
void visit(AstNodeFTaskRef* nodep) override {
VL_RESTORER(m_inFTaskRef);
m_inFTaskRef = true;
iterateChildrenConst(nodep);
}
*/
void visit(AstNodeFTaskRef* nodep) override { void visit(AstNodeFTaskRef* nodep) override {
VL_RESTORER(m_inFTaskRef); VL_RESTORER(m_inFTaskRef);
m_inFTaskRef = true; m_inFTaskRef = true;
@ -584,11 +577,18 @@ class UndrivenVisitor final : public VNVisitorConst {
if (!m_enableWriteSummary || !m_capturep) return; if (!m_enableWriteSummary || !m_capturep) return;
// EOM
// If writeSummary is enabled, task/function definitions are treated as non-executed. // If writeSummary is enabled, task/function definitions are treated as non-executed.
// Do not apply writeSummary at calls inside a task definition, or they will look like // Do not apply writeSummary at calls inside a task definition, or they will look like independent drivers (phantom MULTIDRIVEN).
// independent drivers (phantom MULTIDRIVEN). // did the lambda on purpose - lessen chance of screwup in future edits.
if (m_taskp && !m_alwaysp && !m_inContAssign && !m_inInitialStatic && !m_inBBox) { //const auto inExecutedContext = [this]() const {
// return !(m_taskp && !m_alwaysp && !m_inContAssign && !m_inInitialStatic && !m_inBBox);
//};
const auto inExecutedContext = [this]() {
return !(m_taskp && !m_alwaysp && !m_inContAssign && !m_inInitialStatic && !m_inBBox);
};
if (!inExecutedContext()) {
return; return;
} }
@ -654,12 +654,12 @@ public:
void V3Undriven::undrivenAll(AstNetlist* nodep) { void V3Undriven::undrivenAll(AstNetlist* nodep) {
UINFO(2, __FUNCTION__ << ":"); UINFO(2, __FUNCTION__ << ":");
// EOM // EOM
//{ UndrivenVisitor{nodep}; } const bool enable = V3UndrivenCapture::enableWriteSummary;
if (V3UndrivenCapture::enableWriteSummary) { if (enable) {
V3UndrivenCapture capture{nodep}; V3UndrivenCapture capture{nodep};
{ UndrivenVisitor{nodep, &capture, V3UndrivenCapture::enableWriteSummary}; } { UndrivenVisitor{nodep, &capture, enable}; }
} else { } else {
{ UndrivenVisitor{nodep, nullptr, V3UndrivenCapture::enableWriteSummary}; } { UndrivenVisitor{nodep, nullptr, enable}; }
} }
if (v3Global.opt.stats()) V3Stats::statsStage("undriven"); if (v3Global.opt.stats()) V3Stats::statsStage("undriven");
} }

View File

@ -46,14 +46,6 @@ class CaptureVisitor final : public VNVisitorConst {
for (AstNode* np = nodep; np; np = np->nextp()) np->accept(v); for (AstNode* np = nodep; np; np = np->nextp()) np->accept(v);
} }
/*
V3UndrivenCapture::FTaskInfo& infoFor(const AstNodeFTask* taskp) {
// Ensure entry exists
return m_cap.writeSummary(taskp), const_cast<V3UndrivenCapture::FTaskInfo&>(
*m_cap.find(taskp)); // not used; see below
}
*/
public: public:
explicit CaptureVisitor(V3UndrivenCapture& cap, AstNetlist* netlistp) explicit CaptureVisitor(V3UndrivenCapture& cap, AstNetlist* netlistp)
: m_cap{cap} { : m_cap{cap} {
@ -67,7 +59,8 @@ private:
m_curTaskp = nodep; m_curTaskp = nodep;
++g_stats.ftasks; ++g_stats.ftasks;
UINFO(DBG, "UndrivenCapture: enter ftask " << nodep << " " << nodep->prettyNameQ()); UINFO(DBG, "UndrivenCapture: enter ftask " << nodep << " " << nodep->prettyNameQ());
(void)m_cap.ensureEntry(nodep); // ensure map entry exists //(void)m_cap.ensureEntry(nodep); // ensure map entry exists
m_cap.info(nodep);
iterateListConst(*this, nodep->stmtsp()); iterateListConst(*this, nodep->stmtsp());
} }
@ -76,10 +69,11 @@ private:
++g_stats.varWrites; ++g_stats.varWrites;
UINFO(DBG, "UndrivenCapture: direct write in " << taskNameQ(m_curTaskp) << " var=" << nodep->varp()->prettyNameQ() << " at " << nodep->fileline()); UINFO(DBG, "UndrivenCapture: direct write in " << taskNameQ(m_curTaskp) << " var=" << nodep->varp()->prettyNameQ() << " at " << nodep->fileline());
// Ensure entry exists // Ensure entry exists
(void)m_cap.ensureEntry(m_curTaskp); //(void)m_cap.ensureEntry(m_curTaskp);
// Safe: find() must succeed after writeSummary() creates entry // Safe: find() must succeed after writeSummary() creates entry
auto* const infop = const_cast<V3UndrivenCapture::FTaskInfo*>(m_cap.find(m_curTaskp)); //auto* const infop = const_cast<V3UndrivenCapture::FTaskInfo*>(m_cap.find(m_curTaskp));
if (infop) infop->directWrites.push_back(nodep->varp()); //if (infop) infop->directWrites.push_back(nodep->varp());
m_cap.info(m_curTaskp).directWrites.push_back(nodep->varp());
} }
iterateChildrenConst(nodep); iterateChildrenConst(nodep);
} }
@ -90,11 +84,14 @@ private:
if (AstNodeFTask* const calleep = nodep->taskp()) { if (AstNodeFTask* const calleep = nodep->taskp()) {
++g_stats.callEdges; ++g_stats.callEdges;
UINFO(DBG, "UndrivenCapture: call edge " << taskNameQ(m_curTaskp) << " -> " << taskNameQ(calleep)); UINFO(DBG, "UndrivenCapture: call edge " << taskNameQ(m_curTaskp) << " -> " << taskNameQ(calleep));
(void)m_cap.ensureEntry(m_curTaskp); //(void)m_cap.ensureEntry(m_curTaskp);
(void)m_cap.ensureEntry(calleep); //(void)m_cap.ensureEntry(calleep);
auto* const infop //auto* const infop
= const_cast<V3UndrivenCapture::FTaskInfo*>(m_cap.find(m_curTaskp)); // = const_cast<V3UndrivenCapture::FTaskInfo*>(m_cap.find(m_curTaskp));
if (infop) infop->callees.push_back(calleep); //if (infop) infop->callees.push_back(calleep);
m_cap.info(m_curTaskp).callees.push_back(calleep);
m_cap.info(calleep); // ensure entry exists for callee too (optional but keeps map complete)
} else { } else {
UINFO(DBG, "UndrivenCapture: unresolved call in " << taskNameQ(m_curTaskp) << " name=" << nodep->name()); UINFO(DBG, "UndrivenCapture: unresolved call in " << taskNameQ(m_curTaskp) << " name=" << nodep->name());
} }
@ -202,4 +199,6 @@ void V3UndrivenCapture::debugDumpTask(FTask taskp, int level) const {
<< " writeSummary=" << infop->writeSummary.size()); << " writeSummary=" << infop->writeSummary.size());
} }
void V3UndrivenCapture::ensureEntry(FTask taskp) { (void)m_info[taskp]; } //void V3UndrivenCapture::ensureEntry(FTask taskp) { (void)m_info[taskp]; }
V3UndrivenCapture::FTaskInfo& V3UndrivenCapture::info(FTask taskp) { return m_info[taskp]; }

View File

@ -47,6 +47,9 @@ public:
static bool enableWriteSummary; static bool enableWriteSummary;
// Get (and create if needed) mutable info entry for a task/function.
FTaskInfo& info(FTask taskp);
private: private:
// Per-task/function capture info keyed by resolved AstNodeFTask* identity. // Per-task/function capture info keyed by resolved AstNodeFTask* identity.
std::unordered_map<FTask, FTaskInfo> m_info; std::unordered_map<FTask, FTaskInfo> m_info;
@ -71,7 +74,7 @@ public:
const std::vector<Var>& writeSummary(FTask taskp); const std::vector<Var>& writeSummary(FTask taskp);
// Ensure an entry exists for a task/function without computing its writeSummary. // Ensure an entry exists for a task/function without computing its writeSummary.
void ensureEntry(FTask taskp); //void ensureEntry(FTask taskp);
// Optional: dump one task's summary (for debug bring-up). You can omit if you prefer. // Optional: dump one task's summary (for debug bring-up). You can omit if you prefer.
void debugDumpTask(FTask taskp, int level = 9) const; void debugDumpTask(FTask taskp, int level = 9) const;