mirror of
https://github.com/verilator/verilator.git
synced 2026-09-08 02:28:43 +02:00
Add isolate_assignments meta comment
git-svn-id: file://localhost/svn/verilator/trunk/verilator@871 77ca24e4-aefa-0310-84f0-b9a241c72d87
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
// $Id$
|
||||
//*************************************************************************
|
||||
// DESCRIPTION: Verilator: Break always into separate statements to reduce temps
|
||||
//
|
||||
// Code available from: http://www.veripool.com/verilator
|
||||
//
|
||||
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
||||
//
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2003-2007 by Wilson Snyder. This program is free software; you can
|
||||
// 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.
|
||||
//
|
||||
//*************************************************************************
|
||||
// V3SplitAs's Transformations:
|
||||
//
|
||||
// Search each ALWAYS for a VARREF lvalue with a /*isolate_asignments*/ attribute
|
||||
// If found, color statements with both, assignment to that varref, or other assignments.
|
||||
// Replicate the Always, and remove mis-colored duplicate code.
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
#include "config_build.h"
|
||||
#include "verilatedos.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "V3Global.h"
|
||||
#include "V3SplitAs.h"
|
||||
#include "V3Stats.h"
|
||||
#include "V3Ast.h"
|
||||
|
||||
//######################################################################
|
||||
|
||||
class SplitAsBaseVisitor : public AstNVisitor {
|
||||
public:
|
||||
// METHODS
|
||||
//int debug() { return 9; }
|
||||
};
|
||||
|
||||
//######################################################################
|
||||
// Find all split variables in a block
|
||||
|
||||
class SplitAsFindVisitor : public SplitAsBaseVisitor {
|
||||
private:
|
||||
// STATE
|
||||
AstVarScope* m_splitVscp; // Variable we want to split
|
||||
|
||||
// METHODS
|
||||
virtual void visit(AstVarRef* nodep, AstNUser*) {
|
||||
if (nodep->lvalue() && !m_splitVscp
|
||||
&& nodep->varp()->attrIsolateAssign()) {
|
||||
m_splitVscp = nodep->varScopep();
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNode* nodep, AstNUser*) {
|
||||
nodep->iterateChildren(*this);
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
SplitAsFindVisitor(AstAlways* nodep) {
|
||||
m_splitVscp = NULL;
|
||||
nodep->accept(*this);
|
||||
}
|
||||
virtual ~SplitAsFindVisitor() {}
|
||||
// METHODS
|
||||
AstVarScope* splitVscp() const { return m_splitVscp; }
|
||||
};
|
||||
|
||||
//######################################################################
|
||||
// Remove nodes not containing proper references
|
||||
|
||||
class SplitAsCleanVisitor : public SplitAsBaseVisitor {
|
||||
private:
|
||||
// STATE
|
||||
AstVarScope* m_splitVscp; // Variable we want to split
|
||||
bool m_modeMatch; // Remove matching Vscp, else non-matching
|
||||
bool m_keepStmt; // Current Statement must be preserved
|
||||
bool m_matches; // Statement below has matching lvalue reference
|
||||
|
||||
// METHODS
|
||||
virtual void visit(AstVarRef* nodep, AstNUser*) {
|
||||
if (nodep->lvalue()) {
|
||||
if (nodep->varScopep()==m_splitVscp) {
|
||||
UINFO(6," CL VAR "<<nodep<<endl);
|
||||
m_matches = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeStmt* nodep, AstNUser*) {
|
||||
UINFO(6," CL STMT "<<nodep<<endl);
|
||||
bool oldKeep = m_keepStmt;
|
||||
{
|
||||
m_matches = false;
|
||||
m_keepStmt = false;
|
||||
|
||||
nodep->iterateChildren(*this);
|
||||
|
||||
if (m_keepStmt
|
||||
|| (m_modeMatch ? m_matches : !m_matches)) {
|
||||
UINFO(6," Keep STMT "<<nodep<<endl);
|
||||
m_keepStmt = true;
|
||||
} else {
|
||||
UINFO(6," Delete STMT "<<nodep<<endl);
|
||||
nodep->unlinkFrBack(); pushDeletep(nodep);
|
||||
}
|
||||
}
|
||||
// If something below matches, the upper statement remains too.
|
||||
m_keepStmt = oldKeep || m_keepStmt;
|
||||
UINFO(9," upKeep="<<m_keepStmt<<" STMT "<<nodep<<endl);
|
||||
}
|
||||
virtual void visit(AstNode* nodep, AstNUser*) {
|
||||
nodep->iterateChildren(*this);
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
SplitAsCleanVisitor(AstAlways* nodep, AstVarScope* vscp, bool modeMatch) {
|
||||
m_splitVscp = vscp;
|
||||
m_modeMatch = modeMatch;
|
||||
nodep->accept(*this);
|
||||
}
|
||||
virtual ~SplitAsCleanVisitor() {}
|
||||
};
|
||||
|
||||
//######################################################################
|
||||
// SplitAs class functions
|
||||
|
||||
class SplitAsVisitor : public SplitAsBaseVisitor {
|
||||
private:
|
||||
// NODE STATE
|
||||
// AstAlways::user() -> bool. True if already processed
|
||||
|
||||
// STATE
|
||||
V3Double0 m_statSplits; // Statistic tracking
|
||||
AstVarScope* m_splitVscp; // Variable we want to split
|
||||
|
||||
// METHODS
|
||||
void splitAlways(AstAlways* nodep) {
|
||||
UINFO(3,"Split "<<nodep<<endl);
|
||||
UINFO(3," For "<<m_splitVscp<<endl);
|
||||
if (debug()>=9) nodep->dumpTree(cout,"-in : ");
|
||||
// Duplicate it and link in
|
||||
AstAlways* newp = nodep->cloneTree(false)->castAlways();
|
||||
newp->user(true); // So we don't clone it again
|
||||
nodep->addNextHere(newp);
|
||||
{ // Delete stuff we don't want in old
|
||||
SplitAsCleanVisitor visitor (nodep, m_splitVscp, false);
|
||||
if (debug()>=9) nodep->dumpTree(cout,"-out0: ");
|
||||
}
|
||||
{ // Delete stuff we don't want in new
|
||||
SplitAsCleanVisitor visitor (newp, m_splitVscp, true);
|
||||
if (debug()>=9) newp->dumpTree(cout,"-out1: ");
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(AstAlways* nodep, AstNUser*) {
|
||||
// Are there any lvalue references below this?
|
||||
// There could be more then one. So, we process the first one found first.
|
||||
if (!nodep->user()) {
|
||||
SplitAsFindVisitor visitor (nodep);
|
||||
m_splitVscp = visitor.splitVscp();
|
||||
if (m_splitVscp) {
|
||||
splitAlways(nodep);
|
||||
m_statSplits++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Speedup; no always under math
|
||||
virtual void visit(AstNodeMath* nodep, AstNUser*) {}
|
||||
|
||||
virtual void visit(AstNode* nodep, AstNUser*) {
|
||||
nodep->iterateChildren(*this);
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
SplitAsVisitor(AstNetlist* nodep) {
|
||||
m_splitVscp = NULL;
|
||||
AstNode::userClearTree(); // userp() used on entire tree
|
||||
nodep->accept(*this);
|
||||
}
|
||||
virtual ~SplitAsVisitor() {
|
||||
V3Stats::addStat("Optimizations, isolate_assignments blocks", m_statSplits);
|
||||
}
|
||||
};
|
||||
|
||||
//######################################################################
|
||||
// SplitAs class functions
|
||||
|
||||
void V3SplitAs::splitAsAll(AstNetlist* nodep) {
|
||||
UINFO(2,__FUNCTION__<<": "<<endl);
|
||||
SplitAsVisitor visitor (nodep);
|
||||
}
|
||||
Reference in New Issue
Block a user