2006-08-26 11:35:28 +00:00
|
|
|
//*************************************************************************
|
|
|
|
// DESCRIPTION: Verilator: Combine common code into functions
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2008-01-15 14:29:08 +00:00
|
|
|
// Copyright 2003-2008 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.
|
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
// V3Combine's Transformations:
|
2008-06-10 01:25:10 +00:00
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
// For every function that we spit out
|
|
|
|
// Examine code to find largest common blocks
|
|
|
|
// Hash each node depth first
|
|
|
|
// Hash includes varp name and operator type, and constants
|
|
|
|
// Form lookup table based on hash of each statement w/ nodep and next nodep
|
|
|
|
// GO through table
|
|
|
|
// Lookup in hash, while next of each statement match, grow that common block
|
|
|
|
// Foreach common block
|
|
|
|
// If common block large enough (> 20 statements) & used 2x or more
|
|
|
|
// Make new function
|
|
|
|
// Move common block to function
|
|
|
|
// Replace each common block ref with funccall
|
2008-06-10 01:25:10 +00:00
|
|
|
//
|
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 <map>
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
#include "V3Combine.h"
|
|
|
|
#include "V3Hashed.h"
|
|
|
|
#include "V3Stats.h"
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
#define COMBINE_MIN_STATEMENTS 50 // Min # of statements to be worth making a function
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
class CombBaseVisitor : public AstNVisitor {
|
|
|
|
protected:
|
|
|
|
// STATE
|
|
|
|
//int debug() { return 9; }
|
|
|
|
// METHODS
|
|
|
|
virtual ~CombBaseVisitor() {}
|
|
|
|
|
|
|
|
//***** optimization levels
|
|
|
|
bool emptyFunctionDeletion() { return true; }
|
|
|
|
bool duplicateFunctionCombine() { return true; }
|
|
|
|
bool statementCombine() { return false && duplicateFunctionCombine(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Combine replacement function
|
|
|
|
|
|
|
|
class CombCallVisitor : CombBaseVisitor {
|
|
|
|
// Find all CCALLS of each CFUNC, so that we can later rename them
|
|
|
|
private:
|
|
|
|
// NODE STATE
|
|
|
|
bool m_find; // Find mode vs. delete mode
|
|
|
|
typedef multimap<AstCFunc*,AstCCall*> CallMmap;
|
|
|
|
CallMmap m_callMmap; // Associative array of {function}{call}
|
|
|
|
// METHODS
|
|
|
|
public:
|
|
|
|
void replaceFunc (AstCFunc* oldfuncp, AstCFunc* newfuncp) {
|
|
|
|
if (oldfuncp==newfuncp) return;
|
|
|
|
if (newfuncp) {
|
|
|
|
UINFO(4, " Replace "<<oldfuncp<<" -WITH-> "<<newfuncp<<endl);
|
|
|
|
} else UINFO(4, " Remove "<<oldfuncp<<endl);
|
|
|
|
pair <CallMmap::iterator,CallMmap::iterator> eqrange = m_callMmap.equal_range(oldfuncp);
|
|
|
|
for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
|
|
|
|
CallMmap::iterator eqit = nextit++;
|
|
|
|
AstCCall* callp = eqit->second;
|
|
|
|
if (!callp->user3()) { // !already done
|
|
|
|
UINFO(4, " Called "<<callp<<endl);
|
|
|
|
if (callp->funcp() != oldfuncp) callp->v3fatalSrc("Call list broken, points to call w/different func");
|
|
|
|
if (newfuncp) {
|
|
|
|
AstCCall* newp = new AstCCall(callp, newfuncp);
|
2006-08-30 21:07:55 +00:00
|
|
|
newp->argTypes(callp->argTypes());
|
2006-08-26 11:35:28 +00:00
|
|
|
callp->replaceWith(newp);
|
|
|
|
addCall(newp); // Fix the table
|
|
|
|
} else { // Just deleting empty function
|
|
|
|
callp->unlinkFrBack();
|
|
|
|
}
|
|
|
|
callp->user3(true); // Dead now
|
|
|
|
pushDeletep(callp); callp=NULL;
|
|
|
|
m_callMmap.erase(eqit); // Fix the table
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// METHODS
|
|
|
|
void addCall(AstCCall* nodep) {
|
|
|
|
m_callMmap.insert(make_pair(nodep->funcp(), nodep));
|
|
|
|
}
|
|
|
|
void deleteCall(AstCCall* nodep) {
|
|
|
|
pair <CallMmap::iterator,CallMmap::iterator> eqrange = m_callMmap.equal_range(nodep->funcp());
|
|
|
|
for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
|
|
|
|
CallMmap::iterator eqit = nextit++;
|
|
|
|
AstCCall* callp = eqit->second;
|
|
|
|
if (callp==nodep) {
|
|
|
|
m_callMmap.erase(eqit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nodep->v3fatalSrc("deleteCall node not found in table");
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// VISITORS
|
|
|
|
virtual void visit(AstCCall* nodep, AstNUser*) {
|
|
|
|
addCall(nodep);
|
|
|
|
}
|
|
|
|
// Speed things up
|
|
|
|
virtual void visit(AstNodeAssign* nodep, AstNUser*) {}
|
|
|
|
virtual void visit(AstNodeMath* nodep, AstNUser*) {}
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
|
|
|
CombCallVisitor() {}
|
|
|
|
virtual ~CombCallVisitor() {}
|
|
|
|
void main(AstNetlist* nodep) {
|
|
|
|
nodep->accept(*this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Combine marking function
|
|
|
|
|
|
|
|
class CombMarkVisitor : CombBaseVisitor {
|
|
|
|
// Mark all nodes under specified one.
|
|
|
|
private:
|
|
|
|
// OUTPUT:
|
|
|
|
// AstNode::user3() -> bool. True to indicate duplicated
|
|
|
|
// VISITORS
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
nodep->user3(true);
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
// CONSTRUCTORS
|
|
|
|
CombMarkVisitor(AstNode* nodep) {
|
|
|
|
nodep->accept(*this);
|
|
|
|
}
|
|
|
|
virtual ~CombMarkVisitor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Combine state, as a visitor of each AstNode
|
|
|
|
|
|
|
|
class CombineVisitor : CombBaseVisitor {
|
|
|
|
private:
|
|
|
|
// NODE STATE
|
|
|
|
// Entire netlist:
|
|
|
|
// AstNodeStmt::user() -> bool. True if iterated already
|
|
|
|
// AstCFunc::user3p() -> AstCFunc*, If set, replace ccalls to this func with new func
|
|
|
|
// AstNodeStmt::user3() -> AstNode*. True if to ignore this cell
|
|
|
|
// AstNodeStmt::user4() -> V3Hashed::V3Hash. Hash value of this node (hash of 0 is illegal)
|
|
|
|
|
|
|
|
// STATE
|
|
|
|
typedef enum {STATE_IDLE, STATE_HASH, STATE_DUP} CombineState;
|
|
|
|
V3Double0 m_statCombs; // Statistic tracking
|
|
|
|
CombineState m_state; // Major state
|
|
|
|
AstModule* m_modp; // Current module
|
|
|
|
AstCFunc* m_funcp; // Current function
|
|
|
|
V3Hash m_lowerHash; // Hash of the statement we're building
|
|
|
|
CombCallVisitor m_call; // Tracking of function call users
|
|
|
|
int m_modNFuncs; // Number of functions made
|
|
|
|
AstNode* m_walkLast1p; // Final node that is the same in duplicate list
|
|
|
|
AstNode* m_walkLast2p; // Final node that is the same in duplicate list
|
|
|
|
V3Hashed m_hashed; // Hash for every node
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
void hashStatement(AstNode* nodep) {
|
|
|
|
// Compute hash on entire tree of this statement
|
|
|
|
m_hashed.hashAndInsert(nodep);
|
|
|
|
//UINFO(9," stmthash "<<hex<<nodep->user4()<<" "<<nodep<<endl);
|
|
|
|
}
|
|
|
|
void hashFunctions(AstCFunc* nodep) {
|
|
|
|
// Compute hash of all statement trees in the function
|
|
|
|
CombineState oldState = m_state;
|
|
|
|
{
|
|
|
|
m_state = STATE_HASH;
|
|
|
|
nodep->accept(*this);
|
|
|
|
}
|
|
|
|
m_state = oldState;
|
|
|
|
}
|
|
|
|
void walkEmptyFuncs() {
|
|
|
|
for (V3Hashed::iterator it = m_hashed.begin(); it != m_hashed.end(); ++it) {
|
|
|
|
AstNode* node1p = it->second;
|
|
|
|
AstCFunc* oldfuncp = node1p->castCFunc();
|
|
|
|
if (oldfuncp
|
|
|
|
&& oldfuncp->emptyBody()
|
|
|
|
&& !oldfuncp->dontCombine()) {
|
|
|
|
UINFO(5," EmptyFunc "<<hex<<V3Hash(oldfuncp->user4p())<<" "<<oldfuncp<<endl);
|
|
|
|
// Mark user3p on entire old tree, so we don't process it more
|
|
|
|
CombMarkVisitor visitor(oldfuncp);
|
|
|
|
m_call.replaceFunc(oldfuncp, NULL);
|
|
|
|
oldfuncp->unlinkFrBack();
|
|
|
|
pushDeletep(oldfuncp); oldfuncp=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void walkDupFuncs() {
|
|
|
|
for (V3Hashed::iterator it = m_hashed.begin(); it != m_hashed.end(); ++it) {
|
|
|
|
V3Hash hashval = it->first;
|
|
|
|
AstNode* node1p = it->second;
|
|
|
|
if (!node1p->castCFunc()) continue;
|
|
|
|
if (hashval.isIllegal()) node1p->v3fatalSrc("Illegal (unhashed) nodes\n");
|
|
|
|
for (V3Hashed::iterator eqit = it; eqit != m_hashed.end(); ++eqit) {
|
|
|
|
AstNode* node2p = eqit->second;
|
|
|
|
if (!(eqit->first == hashval)) break;
|
|
|
|
if (node1p==node2p) continue; // Identical iterator
|
|
|
|
if (node1p->user3p() || node2p->user3p()) continue; // Already merged
|
|
|
|
if (node1p->sameTree(node2p)) { // walk of tree has same comparison
|
|
|
|
// Replace AstCCall's that point here
|
|
|
|
replaceFuncWFunc(node2p->castCFunc(), node1p->castCFunc());
|
|
|
|
// Replacement may promote a slow routine to fast path
|
|
|
|
if (!node2p->castCFunc()->slow()) node1p->castCFunc()->slow(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void replaceFuncWFunc(AstCFunc* oldfuncp, AstCFunc* newfuncp) {
|
|
|
|
UINFO(5," DupFunc "<<hex<<V3Hash(newfuncp->user4p())<<" "<<newfuncp<<endl);
|
|
|
|
UINFO(5," and "<<hex<<V3Hash(oldfuncp->user4p())<<" "<<oldfuncp<<endl);
|
|
|
|
// Mark user3p on entire old tree, so we don't process it more
|
|
|
|
m_statCombs++;
|
|
|
|
CombMarkVisitor visitor(oldfuncp);
|
|
|
|
m_call.replaceFunc(oldfuncp, newfuncp);
|
|
|
|
oldfuncp->unlinkFrBack();
|
|
|
|
pushDeletep(oldfuncp); oldfuncp=NULL;
|
|
|
|
}
|
|
|
|
void replaceOnlyCallFunc(AstCCall* nodep) {
|
|
|
|
if (AstCFunc* oldfuncp = nodep->backp()->castCFunc()) {
|
|
|
|
//oldfuncp->dumpTree(cout,"MAYDEL: ");
|
|
|
|
if (nodep->nextp()==NULL
|
|
|
|
&& oldfuncp->initsp()==NULL
|
|
|
|
&& oldfuncp->stmtsp()==nodep
|
|
|
|
&& oldfuncp->finalsp()==NULL) {
|
|
|
|
UINFO(9," Function only has call "<<oldfuncp<<endl);
|
|
|
|
m_call.deleteCall(nodep);
|
|
|
|
CombMarkVisitor visitor(oldfuncp);
|
|
|
|
replaceFuncWFunc(oldfuncp, nodep->funcp()); nodep=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void walkDupCodeStart(AstNode* node1p) {
|
|
|
|
V3Hash hashval (node1p->user4p());
|
|
|
|
//UINFO(4," STMT "<<hashval<<" "<<node1p<<endl);
|
|
|
|
//
|
|
|
|
int bestDepth = 0; // Best substitution found in the search
|
|
|
|
AstNode* bestNode2p = NULL;
|
|
|
|
AstNode* bestLast1p = NULL;
|
|
|
|
AstNode* bestLast2p = NULL;
|
|
|
|
//
|
|
|
|
pair <V3Hashed::iterator,V3Hashed::iterator> eqrange = m_hashed.mmap().equal_range(hashval);
|
|
|
|
for (V3Hashed::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) {
|
|
|
|
AstNode* node2p = eqit->second;
|
|
|
|
if (node1p==node2p) continue;
|
|
|
|
//
|
|
|
|
// We need to mark iteration to prevent matching code inside code (abab matching in ababab)
|
|
|
|
AstNode::userClearTree(); // userp() used on entire tree
|
|
|
|
m_walkLast1p = NULL;
|
|
|
|
m_walkLast2p = NULL;
|
|
|
|
int depth = walkDupCodeNext(node1p, node2p, 1);
|
|
|
|
if (depth>COMBINE_MIN_STATEMENTS
|
|
|
|
&& depth>bestDepth) {
|
|
|
|
bestDepth = depth;
|
|
|
|
bestNode2p = node2p;
|
|
|
|
bestLast1p = m_walkLast1p;
|
|
|
|
bestLast2p = m_walkLast2p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bestDepth) {
|
|
|
|
// Found a replacement
|
|
|
|
UINFO(5," Duplicate of depth "<<bestDepth<<endl);
|
|
|
|
UINFO(5," DupFunc "<<" "<<node1p<<endl);
|
|
|
|
UINFO(5," and "<<" "<<bestNode2p<<endl);
|
|
|
|
UINFO(5," Through "<<" "<<bestLast1p<<endl);
|
|
|
|
UINFO(5," and "<<" "<<bestLast2p<<endl);
|
|
|
|
//
|
|
|
|
walkReplace(node1p, bestNode2p, bestLast1p, bestLast2p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int walkDupCodeNext(AstNode* node1p, AstNode* node2p, int level) {
|
|
|
|
// Find number of common statements between the two node1p_nextp's...
|
|
|
|
if (node1p->userp() || node2p->userp()) return 0; // Already iterated
|
|
|
|
if (node1p->user3p() || node2p->user3p()) return 0; // Already merged
|
|
|
|
if (!m_hashed.sameNodes(node1p,node2p)) return 0; // walk of tree has same comparison
|
|
|
|
V3Hash hashval(node1p->user4p());
|
|
|
|
//UINFO(9," wdup1 "<<level<<" "<<V3Hash(node1p->user4p())<<" "<<node1p<<endl);
|
|
|
|
//UINFO(9," wdup2 "<<level<<" "<<V3Hash(node2p->user4p())<<" "<<node2p<<endl);
|
|
|
|
m_walkLast1p = node1p;
|
|
|
|
m_walkLast2p = node2p;
|
|
|
|
node1p->user(true);
|
|
|
|
node2p->user(true);
|
|
|
|
if (node1p->nextp() && node2p->nextp()) {
|
|
|
|
return hashval.depth()+walkDupCodeNext(node1p->nextp(), node2p->nextp(), level+1);
|
|
|
|
}
|
|
|
|
return hashval.depth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void walkReplace(AstNode* node1p, AstNode* node2p,
|
|
|
|
AstNode* last1p, AstNode* last2p) { // Final node in linked list, maybe null if all statements to be grabbed
|
|
|
|
// Make new function
|
|
|
|
string oldname = m_funcp->name();
|
|
|
|
string::size_type pos;
|
|
|
|
if ((pos=oldname.find("_common")) != string::npos) {
|
|
|
|
oldname.erase(pos);
|
|
|
|
}
|
|
|
|
if ((pos=oldname.find("__")) != string::npos) {
|
|
|
|
oldname.erase(pos);
|
|
|
|
}
|
|
|
|
AstCFunc* newfuncp = new AstCFunc(node1p->fileline(),
|
|
|
|
oldname+"_common"+cvtToStr(++m_modNFuncs),
|
|
|
|
NULL);
|
|
|
|
m_modp->addStmtp(newfuncp);
|
|
|
|
// Create calls
|
|
|
|
AstCCall* call1p = new AstCCall(node1p->fileline(), newfuncp);
|
|
|
|
AstCCall* call2p = new AstCCall(node2p->fileline(), newfuncp);
|
|
|
|
// Grab statement bodies
|
|
|
|
AstNRelinker relink1Handle;
|
|
|
|
AstNRelinker relink2Handle;
|
|
|
|
for (AstNode* nextp, *walkp = node1p; 1; walkp = nextp) {
|
|
|
|
nextp = walkp->nextp();
|
|
|
|
if (walkp==node1p) walkp->unlinkFrBack(&relink1Handle);
|
|
|
|
else { walkp->unlinkFrBack(); node1p->addNext(walkp); }
|
|
|
|
if (walkp==last1p) break;
|
|
|
|
}
|
|
|
|
for (AstNode* nextp, *walkp = node2p; 1; walkp = nextp) {
|
|
|
|
nextp = walkp->nextp();
|
|
|
|
if (walkp==node2p) walkp->unlinkFrBack(&relink2Handle);
|
|
|
|
else { walkp->unlinkFrBack(); node2p->addNext(walkp); }
|
|
|
|
if (walkp==last2p) break;
|
|
|
|
}
|
|
|
|
// Move node1 statements to new function
|
|
|
|
newfuncp->addStmtsp(node1p);
|
|
|
|
//newfuncp->dumpTree(cout," newfunctree: ");
|
|
|
|
// Mark node2 statements as dead
|
|
|
|
CombMarkVisitor visitor(node2p);
|
|
|
|
pushDeletep(node2p); // Delete later
|
|
|
|
// Link in new function
|
|
|
|
relink1Handle.relink(call1p);
|
|
|
|
relink2Handle.relink(call2p);
|
|
|
|
// Hash the new function
|
|
|
|
hashFunctions(newfuncp);
|
|
|
|
m_call.addCall(call1p);
|
|
|
|
m_call.addCall(call2p);
|
|
|
|
// If either new statement makes a func with only a single call, replace
|
|
|
|
// the above callers to call it directly
|
|
|
|
replaceOnlyCallFunc(call1p); call1p=NULL;
|
|
|
|
replaceOnlyCallFunc(call2p); call2p=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// VISITORS
|
|
|
|
virtual void visit(AstNetlist* nodep, AstNUser*) {
|
|
|
|
// Track all callers of each function
|
|
|
|
m_call.main(nodep);
|
|
|
|
//
|
|
|
|
AstNode::user3ClearTree(); // userp() used on entire tree
|
|
|
|
//In V3Hashed AstNode::user4ClearTree(); // userp() used on entire tree
|
|
|
|
// Iterate modules backwards, in bottom-up order.
|
|
|
|
// Required so that a module instantiating another can benefit from collapsing.
|
|
|
|
nodep->iterateChildrenBackwards(*this);
|
|
|
|
}
|
|
|
|
virtual void visit(AstModule* nodep, AstNUser*) {
|
|
|
|
UINFO(4," MOD "<<nodep<<endl);
|
|
|
|
m_modp = nodep;
|
|
|
|
m_modNFuncs = 0;
|
|
|
|
m_hashed.clear();
|
|
|
|
// Compute hash of all statement trees in the function
|
|
|
|
m_state = STATE_HASH;
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
m_state = STATE_IDLE;
|
|
|
|
// Walk the hashes removing empty functions
|
|
|
|
if (emptyFunctionDeletion()) {
|
|
|
|
walkEmptyFuncs();
|
|
|
|
}
|
|
|
|
// Walk the hashes looking for duplicate functions
|
|
|
|
if (duplicateFunctionCombine()) {
|
|
|
|
walkDupFuncs();
|
|
|
|
}
|
|
|
|
// Walk the statements looking for large replicated code sections
|
|
|
|
if (statementCombine()) {
|
|
|
|
m_state = STATE_DUP;
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
m_state = STATE_IDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual void visit(AstCFunc* nodep, AstNUser*) {
|
|
|
|
m_funcp = nodep;
|
|
|
|
if (!nodep->dontCombine()) {
|
|
|
|
if (m_state == STATE_HASH) {
|
|
|
|
hashStatement(nodep); // Hash the entire function - it might be identical
|
|
|
|
} else if (m_state == STATE_DUP) {
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_funcp = NULL;
|
|
|
|
}
|
|
|
|
virtual void visit(AstNodeStmt* nodep, AstNUser*) {
|
|
|
|
if (m_state == STATE_HASH && m_funcp) {
|
|
|
|
hashStatement(nodep);
|
|
|
|
}
|
|
|
|
else if (m_state == STATE_DUP && m_funcp) {
|
|
|
|
walkDupCodeStart(nodep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------
|
|
|
|
// Default: Just iterate
|
|
|
|
virtual void visit(AstVar*, AstNUser*) {}
|
|
|
|
virtual void visit(AstTraceDecl*, AstNUser*) {}
|
|
|
|
virtual void visit(AstTraceInc*, AstNUser*) {}
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
// CONSTUCTORS
|
|
|
|
CombineVisitor(AstNetlist* nodep) {
|
|
|
|
m_modp=NULL;
|
|
|
|
m_funcp = NULL;
|
|
|
|
m_state = STATE_IDLE;
|
|
|
|
nodep->accept(*this);
|
|
|
|
}
|
|
|
|
virtual ~CombineVisitor() {
|
|
|
|
V3Stats::addStat("Optimizations, Combined CFuncs", m_statCombs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
// Combine class functions
|
|
|
|
|
|
|
|
void V3Combine::combineAll(AstNetlist* nodep) {
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
CombineVisitor visitor (nodep);
|
|
|
|
}
|