2006-08-26 11:35:28 +00:00
|
|
|
|
// $Id$
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Substitute constants and expressions in expr temp's
|
|
|
|
|
//
|
|
|
|
|
// Code available from: http://www.veripool.com/verilator
|
|
|
|
|
//
|
|
|
|
|
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2007-01-02 22:06:40 +00:00
|
|
|
|
// Copyright 2004-2007 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
|
|
|
|
// General Public License or the Perl Artistic License.
|
|
|
|
|
//
|
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Subst's Transformations:
|
2006-10-11 15:34:50 +00:00
|
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Each module:
|
|
|
|
|
// Search all ASSIGN(WORDSEL(...)) and build what it's assigned to
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// Later usages of that word may then be replaced as long as
|
|
|
|
|
// the RHS hasn't changed value.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Subst.h"
|
|
|
|
|
#include "V3Const.h"
|
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Common debugging baseclass
|
|
|
|
|
|
|
|
|
|
class SubstBaseVisitor : public AstNVisitor {
|
|
|
|
|
public:
|
2006-10-11 15:34:50 +00:00
|
|
|
|
static int debug() { return V3Error::debugDefault(); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// static int debug() { return 9; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
2006-10-11 14:13:37 +00:00
|
|
|
|
// Class for each word of a multi-word variable
|
|
|
|
|
|
|
|
|
|
class SubstVarWord {
|
2006-10-11 15:34:50 +00:00
|
|
|
|
protected:
|
|
|
|
|
// MEMBERS
|
2006-10-11 14:13:37 +00:00
|
|
|
|
AstNodeAssign* m_assignp; // Last assignment to each word of this var
|
2006-10-11 15:34:50 +00:00
|
|
|
|
int m_step; // Step number of last assignment
|
2006-10-11 14:13:37 +00:00
|
|
|
|
bool m_use; // True if each word was consumed
|
|
|
|
|
bool m_complex; // True if each word is complex
|
|
|
|
|
friend class SubstVarEntry;
|
|
|
|
|
// METHODS
|
|
|
|
|
void clear() {
|
|
|
|
|
m_assignp = NULL;
|
2006-10-11 15:34:50 +00:00
|
|
|
|
m_step = 0;
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_use = false;
|
|
|
|
|
m_complex = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Class for every variable we may process
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
class SubstVarEntry {
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// MEMBERS
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstVar* m_varp; // Variable this tracks
|
|
|
|
|
bool m_wordAssign; // True if any word assignments
|
|
|
|
|
bool m_wordUse; // True if any individual word usage
|
2006-10-11 14:13:37 +00:00
|
|
|
|
SubstVarWord m_whole; // Data for whole vector used at once
|
|
|
|
|
vector<SubstVarWord> m_words; // Data for every word, if multi word variable
|
2006-08-26 11:35:28 +00:00
|
|
|
|
int debug() { return SubstBaseVisitor::debug(); }
|
|
|
|
|
public:
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// CONSTRUCTORS
|
2006-08-26 11:35:28 +00:00
|
|
|
|
SubstVarEntry (AstVar* varp) { // Construction for when a var is used
|
|
|
|
|
m_varp = varp;
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_whole.m_use = false;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_wordAssign = false;
|
|
|
|
|
m_wordUse = false;
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_words.resize(varp->widthWords());
|
|
|
|
|
m_whole.clear();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
for (int i=0; i<varp->widthWords(); i++) {
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_words[i].clear();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-11 14:13:37 +00:00
|
|
|
|
~SubstVarEntry() {}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
private:
|
|
|
|
|
// METHODS
|
|
|
|
|
bool wordNumOk(int word) const {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
return word < m_varp->widthWords();
|
|
|
|
|
}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
AstNodeAssign* getWordAssignp(int word) const {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!wordNumOk(word)) return NULL;
|
2006-10-11 14:13:37 +00:00
|
|
|
|
else return m_words[word].m_assignp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
public:
|
|
|
|
|
void assignWhole (int step, AstNodeAssign* assp) {
|
2006-10-11 14:13:37 +00:00
|
|
|
|
if (m_whole.m_assignp) m_whole.m_complex = true;
|
|
|
|
|
m_whole.m_assignp = assp;
|
2006-10-11 15:34:50 +00:00
|
|
|
|
m_whole.m_step = step;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
void assignWord (int step, int word, AstNodeAssign* assp) {
|
2006-10-11 14:13:37 +00:00
|
|
|
|
if (!wordNumOk(word) || getWordAssignp(word) || m_words[word].m_complex) m_whole.m_complex = true;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_wordAssign = true;
|
2006-10-11 15:34:50 +00:00
|
|
|
|
if (wordNumOk(word)) {
|
|
|
|
|
m_words[word].m_assignp = assp;
|
|
|
|
|
m_words[word].m_step = step;
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
void assignWordComplex (int step, int word) {
|
2006-10-11 14:13:37 +00:00
|
|
|
|
if (!wordNumOk(word) || getWordAssignp(word) || m_words[word].m_complex) m_whole.m_complex = true;
|
|
|
|
|
m_words[word].m_complex = true;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
void assignComplex(int step) {
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_whole.m_complex = true;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void consumeWhole() { //==consumeComplex as we don't know the difference
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_whole.m_use = true;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
void consumeWord(int word) {
|
2006-10-11 14:13:37 +00:00
|
|
|
|
m_words[word].m_use = true;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_wordUse = true;
|
|
|
|
|
}
|
|
|
|
|
// ACCESSORS
|
|
|
|
|
AstNode* substWhole(AstNode* errp) {
|
|
|
|
|
if (!m_varp->isWide()
|
2006-10-11 14:13:37 +00:00
|
|
|
|
&& !m_whole.m_complex && m_whole.m_assignp && !m_wordAssign) {
|
|
|
|
|
AstNodeAssign* assp = m_whole.m_assignp;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (!assp) errp->v3fatalSrc("Reading whole that was never assigned");
|
|
|
|
|
return (assp->rhsp());
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AstNode* substWord(AstNode* errp, int word) { // Return what to substitute given word number for
|
2006-10-11 14:13:37 +00:00
|
|
|
|
if (!m_whole.m_complex && !m_whole.m_assignp && !m_words[word].m_complex) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
AstNodeAssign* assp = getWordAssignp(word);
|
|
|
|
|
if (!assp) errp->v3fatalSrc("Reading a word that was never assigned, or bad word #");
|
|
|
|
|
return (assp->rhsp());
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
int getWholeStep() const {
|
|
|
|
|
return m_whole.m_step;
|
|
|
|
|
}
|
|
|
|
|
int getWordStep(int word) const {
|
|
|
|
|
if (!wordNumOk(word)) return 0; else return m_words[word].m_step;
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
void deleteAssign (AstNodeAssign* nodep) {
|
|
|
|
|
UINFO(5, "Delete "<<nodep<<endl);
|
|
|
|
|
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
|
|
|
|
|
}
|
|
|
|
|
void deleteUnusedAssign() {
|
|
|
|
|
// If there are unused assignments in this var, kill them
|
2006-10-11 14:13:37 +00:00
|
|
|
|
if (!m_whole.m_use && !m_wordUse && m_whole.m_assignp) {
|
|
|
|
|
deleteAssign (m_whole.m_assignp); m_whole.m_assignp=NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2006-10-11 14:13:37 +00:00
|
|
|
|
for (unsigned i=0; i<m_words.size(); i++) {
|
|
|
|
|
if (!m_whole.m_use && !m_words[i].m_use && m_words[i].m_assignp && !m_words[i].m_complex) {
|
|
|
|
|
deleteAssign (m_words[i].m_assignp); m_words[i].m_assignp=NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2006-10-11 15:34:50 +00:00
|
|
|
|
//######################################################################
|
|
|
|
|
// See if any variables have changed value since we determined subst value, as a visitor of each AstNode
|
|
|
|
|
|
|
|
|
|
class SubstUseVisitor : public SubstBaseVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE
|
|
|
|
|
// See SubstVisitor
|
|
|
|
|
//
|
|
|
|
|
// STATE
|
|
|
|
|
int m_origStep; // Step number where subst was recorded
|
|
|
|
|
bool m_ok; // No misassignments found
|
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
SubstVarEntry* findEntryp(AstVarRef* nodep) {
|
|
|
|
|
return (SubstVarEntry*)(nodep->varp()->userp()); // Might be NULL
|
|
|
|
|
}
|
|
|
|
|
// VISITORS
|
|
|
|
|
virtual void visit(AstVarRef* nodep, AstNUser*) {
|
|
|
|
|
SubstVarEntry* entryp = findEntryp (nodep);
|
|
|
|
|
if (entryp) {
|
|
|
|
|
// Don't sweat it. We assign a new temp variable for every new assignment,
|
|
|
|
|
// so there's no way we'd ever replace a old value.
|
|
|
|
|
} else {
|
|
|
|
|
// A simple variable; needs checking.
|
|
|
|
|
if (m_origStep < nodep->varp()->user2()) {
|
|
|
|
|
if (m_ok) UINFO(9," RHS variable changed since subst recorded: "<<nodep<<endl);
|
|
|
|
|
m_ok = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstConst* nodep, AstNUser*) {} // Accelerate
|
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
|
|
|
|
SubstUseVisitor(AstNode* nodep, int origStep) {
|
|
|
|
|
UINFO(9, " SubstUseVisitor "<<origStep<<" "<<nodep<<endl);
|
|
|
|
|
m_ok = true;
|
|
|
|
|
m_origStep = origStep;
|
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
virtual ~SubstUseVisitor() {}
|
|
|
|
|
// METHODS
|
|
|
|
|
bool ok() const { return m_ok; }
|
|
|
|
|
};
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//######################################################################
|
2006-10-11 14:13:37 +00:00
|
|
|
|
// Subst state, as a visitor of each AstNode
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
class SubstVisitor : public SubstBaseVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// NODE STATE
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// Passed to SubstUseVisitor
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// AstVar::userp -> SubstVar* for usage var, 0=not set yet
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// AstVar::user2 -> int step number for last assignment, 0=not set yet
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// STATE
|
|
|
|
|
vector<SubstVarEntry*> m_entryps; // Nodes to delete when we are finished
|
|
|
|
|
int m_ops; // Number of operators on assign rhs
|
2006-10-11 15:34:50 +00:00
|
|
|
|
int m_assignStep; // Assignment number to determine var lifetime
|
2006-08-26 11:35:28 +00:00
|
|
|
|
V3Double0 m_statSubsts; // Statistic tracking
|
|
|
|
|
|
|
|
|
|
enum { SUBST_MAX_OPS_SUBST = 30, // Maximum number of ops to substitute in
|
|
|
|
|
SUBST_MAX_OPS_NA = 9999 }; // Not allowed to substitute
|
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
SubstVarEntry* getEntryp(AstVarRef* nodep) {
|
|
|
|
|
if (!nodep->varp()->userp()) {
|
|
|
|
|
SubstVarEntry* entryp = new SubstVarEntry (nodep->varp());
|
|
|
|
|
m_entryps.push_back(entryp);
|
|
|
|
|
nodep->varp()->userp(entryp);
|
|
|
|
|
return entryp;
|
|
|
|
|
} else {
|
|
|
|
|
SubstVarEntry* entryp = (SubstVarEntry*)(nodep->varp()->userp());
|
|
|
|
|
return entryp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// VISITORS
|
|
|
|
|
virtual void visit(AstNodeAssign* nodep, AstNUser*) {
|
|
|
|
|
m_ops = 0;
|
2006-10-11 15:34:50 +00:00
|
|
|
|
m_assignStep++;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->rhsp()->iterateAndNext(*this);
|
|
|
|
|
bool hit=false;
|
|
|
|
|
if (AstVarRef* varrefp = nodep->lhsp()->castVarRef()) {
|
|
|
|
|
if (varrefp->varp()->isStatementTemp()) {
|
|
|
|
|
SubstVarEntry* entryp = getEntryp(varrefp);
|
|
|
|
|
hit = true;
|
|
|
|
|
if (m_ops > SUBST_MAX_OPS_SUBST) {
|
|
|
|
|
UINFO(8," ASSIGNtooDeep "<<varrefp<<endl);
|
2006-10-11 15:34:50 +00:00
|
|
|
|
entryp->assignComplex(m_assignStep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
UINFO(8," ASSIGNwhole "<<varrefp<<endl);
|
2006-10-11 15:34:50 +00:00
|
|
|
|
entryp->assignWhole(m_assignStep, nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (AstWordSel* wordp = nodep->lhsp()->castWordSel()) {
|
|
|
|
|
if (AstVarRef* varrefp = wordp->lhsp()->castVarRef()) {
|
|
|
|
|
if (wordp->rhsp()->castConst()
|
|
|
|
|
&& varrefp->varp()->isStatementTemp()) {
|
|
|
|
|
int word = wordp->rhsp()->castConst()->asInt();
|
|
|
|
|
SubstVarEntry* entryp = getEntryp(varrefp);
|
|
|
|
|
hit = true;
|
|
|
|
|
if (m_ops > SUBST_MAX_OPS_SUBST) {
|
|
|
|
|
UINFO(8," ASSIGNtooDeep "<<varrefp<<endl);
|
2006-10-11 15:34:50 +00:00
|
|
|
|
entryp->assignWordComplex(m_assignStep, word);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
UINFO(8," ASSIGNword"<<word<<" "<<varrefp<<endl);
|
2006-10-11 15:34:50 +00:00
|
|
|
|
entryp->assignWord(m_assignStep, word, nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!hit) {
|
|
|
|
|
nodep->lhsp()->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void replaceSubstEtc(AstNode* nodep, AstNode* substp) {
|
|
|
|
|
if (debug()>5) nodep->dumpTree(cout," substw_old: ");
|
|
|
|
|
AstNode* newp = substp->cloneTree(true);
|
|
|
|
|
if (!nodep->isQuad() && newp->isQuad()) {
|
|
|
|
|
newp = new AstCast (newp->fileline(), newp, nodep);
|
|
|
|
|
}
|
|
|
|
|
if (debug()>5) newp->dumpTree(cout," w_new: ");
|
|
|
|
|
nodep->replaceWith(newp);
|
|
|
|
|
pushDeletep(nodep); nodep=NULL;
|
|
|
|
|
m_statSubsts++;
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstWordSel* nodep, AstNUser*) {
|
|
|
|
|
nodep->rhsp()->accept(*this);
|
|
|
|
|
AstVarRef* varrefp = nodep->lhsp()->castVarRef();
|
|
|
|
|
AstConst* constp = nodep->rhsp()->castConst();
|
|
|
|
|
if (varrefp && varrefp->varp()->isStatementTemp()
|
|
|
|
|
&& !varrefp->lvalue()
|
|
|
|
|
&& constp) {
|
|
|
|
|
// Nicely formed lvalues handled in NodeAssign
|
|
|
|
|
// Other lvalues handled as unknown mess in AstVarRef
|
|
|
|
|
int word = constp->asInt();
|
|
|
|
|
UINFO(8," USEword"<<word<<" "<<varrefp<<endl);
|
|
|
|
|
SubstVarEntry* entryp = getEntryp(varrefp);
|
|
|
|
|
if (AstNode* substp = entryp->substWord (nodep, word)) {
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// Check that the RHS hasn't changed value since we recorded it.
|
|
|
|
|
SubstUseVisitor visitor (substp, entryp->getWordStep(word));
|
|
|
|
|
if (visitor.ok()) {
|
|
|
|
|
replaceSubstEtc(nodep, substp); nodep=NULL;
|
|
|
|
|
} else {
|
|
|
|
|
entryp->consumeWord(word);
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
entryp->consumeWord(word);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
nodep->lhsp()->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstVarRef* nodep, AstNUser*) {
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// Any variable
|
|
|
|
|
if (nodep->lvalue()) {
|
|
|
|
|
m_assignStep++;
|
|
|
|
|
nodep->varp()->user2(m_assignStep);
|
|
|
|
|
UINFO(9, " ASSIGNstep u2="<<nodep->varp()->user2()<<" "<<nodep<<endl);
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (nodep->varp()->isStatementTemp()) {
|
|
|
|
|
SubstVarEntry* entryp = getEntryp (nodep);
|
|
|
|
|
if (nodep->lvalue()) {
|
|
|
|
|
UINFO(8," ASSIGNcpx "<<nodep<<endl);
|
2006-10-11 15:34:50 +00:00
|
|
|
|
entryp->assignComplex(m_assignStep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else if (AstNode* substp = entryp->substWhole(nodep)) {
|
2006-10-11 15:34:50 +00:00
|
|
|
|
// Check that the RHS hasn't changed value since we recorded it.
|
|
|
|
|
SubstUseVisitor visitor (substp, entryp->getWholeStep());
|
|
|
|
|
if (visitor.ok()) {
|
|
|
|
|
UINFO(8," USEwhole "<<nodep<<endl);
|
|
|
|
|
replaceSubstEtc(nodep, substp); nodep=NULL;
|
|
|
|
|
} else {
|
|
|
|
|
UINFO(8," USEwholeButChg "<<nodep<<endl);
|
|
|
|
|
entryp->consumeWhole();
|
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
} else { // Consumed w/o substitute
|
|
|
|
|
UINFO(8," USEwtf "<<nodep<<endl);
|
|
|
|
|
entryp->consumeWhole();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstVar* nodep, AstNUser*) {}
|
2006-10-11 15:34:50 +00:00
|
|
|
|
virtual void visit(AstConst* nodep, AstNUser*) {}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
|
m_ops++;
|
|
|
|
|
if (!nodep->isSubstOptimizable()) {
|
|
|
|
|
m_ops = SUBST_MAX_OPS_NA;
|
|
|
|
|
}
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
|
|
|
|
SubstVisitor(AstNode* nodep) {
|
|
|
|
|
AstNode::userClearTree(); // userp() used on entire tree
|
2006-10-11 15:34:50 +00:00
|
|
|
|
AstNode::user2ClearTree(); // user2p() used on entire tree
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_ops = 0;
|
2006-10-11 15:34:50 +00:00
|
|
|
|
m_assignStep = 0;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
virtual ~SubstVisitor() {
|
|
|
|
|
V3Stats::addStat("Optimizations, Substituted temps", m_statSubsts);
|
|
|
|
|
for (vector<SubstVarEntry*>::iterator it = m_entryps.begin(); it != m_entryps.end(); ++it) {
|
|
|
|
|
(*it)->deleteUnusedAssign();
|
|
|
|
|
delete (*it);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Subst class functions
|
|
|
|
|
|
|
|
|
|
void V3Subst::substituteAll(AstNetlist* nodep) {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
|
SubstVisitor visitor (nodep);
|
|
|
|
|
}
|