void mergeEnd() { if (!m_mgAssignps.empty()) { uint32_t items = m_mgIndexHi - m_mgIndexLo + 1; UINFO(9, "End merge iter="<<items<<" "<<m_mgIndexHi<<":"<<m_mgIndexLo <<" "<<m_mgAssignps[0]<<endl); if (items >= RELOOP_MIN_ITERS) { UINFO(6, "Reloop merging items="<<items<<" "<<m_mgIndexHi<<":"<<m_mgIndexLo <<" "<<m_mgAssignps[0]<<endl); ++m_statReloops; m_statReItems += items; // Transform first assign into for loop body AstNodeAssign* bodyp = m_mgAssignps.front(); if (bodyp->lhsp() != m_mgSelLp) bodyp->v3fatalSrc("Corrupt queue/state"); FileLine* fl = bodyp->fileline(); AstVar* itp = findCreateVarTemp(fl, m_mgCfuncp); AstNode* initp = new AstAssign(fl, new AstVarRef(fl, itp, true), new AstConst(fl, m_mgIndexLo)); AstNode* condp = new AstLte(fl, new AstVarRef(fl, itp, false), new AstConst(fl, m_mgIndexHi)); AstNode* incp = new AstAssign(fl, new AstVarRef(fl, itp, true), new AstAdd(fl, new AstConst(fl, 1), new AstVarRef(fl, itp, false))); AstWhile* whilep = new AstWhile(fl, condp, NULL, incp); initp->addNext(whilep); bodyp->replaceWith(initp); whilep->addBodysp(bodyp); // Replace constant index with new loop index AstNode* lbitp = m_mgSelLp->bitp(); lbitp->replaceWith(new AstVarRef(fl, itp, false)); lbitp->deleteTree(); VL_DANGLING(lbitp); if (m_mgSelRp) { // else constant and no replace AstNode* rbitp = m_mgSelRp->bitp(); rbitp->replaceWith(new AstVarRef(fl, itp, false)); rbitp->deleteTree(); VL_DANGLING(lbitp); } if (debug()>=9) initp->dumpTree(cout, "-new: "); if (debug()>=9) whilep->dumpTree(cout, "-new: "); // Remove remaining assigns for (AssVec::iterator it=m_mgAssignps.begin(); it!=m_mgAssignps.end(); ++it) { AstNodeAssign* assp = *it; if (assp != bodyp) { assp->unlinkFrBack()->deleteTree(); VL_DANGLING(assp); } } } // Setup for next merge m_mgAssignps.clear(); m_mgSelLp = NULL; m_mgSelRp = NULL; m_mgVarrefLp = NULL; m_mgVarrefRp = NULL; m_mgConstRp = NULL; } }
void deadCheckVar() { // Delete any unused varscopes for (vector<AstVarScope*>::iterator it = m_vscsp.begin(); it!=m_vscsp.end(); ++it) { AstVarScope* vscp = *it; if (vscp->user1() == 0) { UINFO(4," Dead "<<vscp<<endl); pair <AssignMap::iterator,AssignMap::iterator> eqrange = m_assignMap.equal_range(vscp); for (AssignMap::iterator it = eqrange.first; it != eqrange.second; ++it) { AstNodeAssign* assp = it->second; UINFO(4," Dead assign "<<assp<<endl); assp->unlinkFrBack()->deleteTree(); VL_DANGLING(assp); } vscp->unlinkFrBack()->deleteTree(); VL_DANGLING(vscp); } } for (vector<AstNode*>::iterator it = m_varEtcsp.begin(); it!=m_varEtcsp.end(); ++it) { if ((*it)->user1() == 0) { UINFO(4," Dead "<<(*it)<<endl); (*it)->unlinkFrBack()->deleteTree(); (*it)=NULL; } } }