Fix cell scoping performance (#6059).

This commit is contained in:
Wilson Snyder 2025-09-06 08:35:07 -04:00
parent 0d1f036f17
commit aa28a8d1e1
3 changed files with 22 additions and 16 deletions

View File

@ -17,6 +17,7 @@ Verilator 5.041 devel
* Improve automatic selection of logic for DFG synthesis (#6370). [Geza Lore]
* Improve `covergroup with function sample` handling (#6387). [Jakub Wasilewski]
* Optimize dead functions without references (#6380). [Artur Bieniek, Antmicro Ltd.]
* Fix cell scoping performance (#6059). [Jerry Tianchen]
* Fix while loop hang on timing-delayed assignment (#6343) (#6354). [Krzysztof Bieganski, Antmicro Ltd.]
* Fix driver analysis of partially assigned variables (#6364) (#6378). [Geza Lore]
* Fix V3Hash MacOS ambiguity (#6350). [Lan Zongwei]

View File

@ -428,6 +428,7 @@ Terpstra
Thiede
Thierry
Thyer
Tianchen
Tianrui
Tichelaar
Timi

View File

@ -115,23 +115,27 @@ class ScopeVisitor final : public VNVisitor {
nodep, scopename, m_aboveScopep, m_aboveCellp};
if (VN_IS(nodep, Package)) m_packageScopes.emplace(nodep, m_scopep);
// Now for each child cell, iterate the module this cell points to
// Get list of cells before we edit, to avoid excess visits (issue #6059)
std::deque<AstCell*> cells;
for (AstNode* cellnextp = nodep->stmtsp(); cellnextp; cellnextp = cellnextp->nextp()) {
if (AstCell* const cellp = VN_CAST(cellnextp, Cell)) {
VL_RESTORER(m_scopep); // Protects m_scopep set in called module
// which is "above" in this code, but later in code execution order
VL_RESTORER(m_aboveCellp);
VL_RESTORER(m_aboveScopep);
{
m_aboveCellp = cellp;
m_aboveScopep = m_scopep;
AstNodeModule* const modp = cellp->modp();
UASSERT_OBJ(modp, cellp, "Unlinked mod");
iterate(modp); // Recursive call to visit(AstNodeModule)
if (VN_IS(modp, Iface)) {
// Remember newly created scope
cellp->user2p(m_scopep);
}
if (AstCell* const cellp = VN_CAST(cellnextp, Cell)) cells.push_back(cellp);
}
// Now for each child cell, iterate the module this cell points to
for (AstCell* const cellp : cells) {
VL_RESTORER(m_scopep); // Protects m_scopep set in called module
// which is "above" in this code, but later in code execution order
VL_RESTORER(m_aboveCellp);
VL_RESTORER(m_aboveScopep);
{
m_aboveCellp = cellp;
m_aboveScopep = m_scopep;
AstNodeModule* const modp = cellp->modp();
UASSERT_OBJ(modp, cellp, "Unlinked mod");
iterate(modp); // Recursive call to visit(AstNodeModule)
if (VN_IS(modp, Iface)) {
// Remember newly created scope
cellp->user2p(m_scopep);
}
}
}