From ffd2c5c69e1c381063589a8bc25b2604a90afa1f Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Wed, 15 Apr 2026 13:46:45 +0100 Subject: [PATCH] Optimize temporary insertion in DfgPeephole --- src/V3DfgPeephole.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/V3DfgPeephole.cpp b/src/V3DfgPeephole.cpp index 62ad31269..b44e648da 100644 --- a/src/V3DfgPeephole.cpp +++ b/src/V3DfgPeephole.cpp @@ -208,6 +208,9 @@ class V3DfgPeephole final : public DfgVisitor { size_t m_currentGeneration = 0; // Current generation number size_t m_lastId = 0; // Last unique vertex ID assigned size_t m_nTemps = 0; // Number of temporary variables created + // Scope for transient temporariy variables cerated in this pass. They should all be + // eliminated wihtin this pass, so anything should be ok, pick the top scope as easy to find. + AstScope* const m_tmpScopep = v3Global.rootp()->topScopep()->scopep(); // STATIC STATE static V3DebugBisect s_debugBisect; // Debug aid @@ -1847,10 +1850,9 @@ class V3DfgPeephole final : public DfgVisitor { DfgSplicePacked* const sp = new DfgSplicePacked{m_dfg, flp, vtxp->dtype()}; m_vInfo[sp].m_id = ++m_lastId; sp->addDriver(catp, lsb, flp); - DfgVertex::ScopeCache scopeCache; - AstScope* const scopep = vtxp->scopep(scopeCache, true); const std::string name = m_dfg.makeUniqueName("PeepholeNarrow", m_nTemps++); - DfgVertexVar* const varp = m_dfg.makeNewVar(flp, name, vtxp->dtype(), scopep); + DfgVertexVar* const varp + = m_dfg.makeNewVar(flp, name, vtxp->dtype(), m_tmpScopep); varp->tmpForp(varp->vscp()); m_vInfo[varp].m_id = ++m_lastId; varp->vscp()->varp()->isInternal(true);