2012-04-13 03:08:20 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Break always into sensitivity block domains
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2020-01-07 00:05:53 +01:00
|
|
|
// Copyright 2003-2020 by Wilson Snyder. This program is free software; you can
|
2006-08-26 13:35:28 +02:00
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Block's Transformations:
|
2008-06-10 03:25:10 +02:00
|
|
|
//
|
2006-08-26 13:35:28 +02:00
|
|
|
// Note this can be called multiple times.
|
|
|
|
|
// Create a IBLOCK(initial), SBLOCK(combo)
|
2019-05-19 22:13:13 +02:00
|
|
|
// ALWAYS: Remove any-edges from sense list
|
|
|
|
|
// If no POS/NEG in senselist, Fold into SBLOCK(combo)
|
|
|
|
|
// Else fold into SBLOCK(sequent).
|
|
|
|
|
// OPTIMIZE: When support async clocks, fold into that block if possible
|
|
|
|
|
// INITIAL: Move into IBLOCK
|
|
|
|
|
// WIRE: Move into SBLOCK(combo)
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
#ifndef _V3SENTREE_H_
|
|
|
|
|
#define _V3SENTREE_H_
|
|
|
|
|
|
2006-12-18 20:20:45 +01:00
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3Hashed.h"
|
|
|
|
|
|
2008-06-30 19:11:25 +02:00
|
|
|
#include <cstdarg>
|
2006-08-26 13:35:28 +02:00
|
|
|
#include <map>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <vector>
|
2018-06-12 04:05:45 +02:00
|
|
|
#include VL_INCLUDE_UNORDERED_SET
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Collect SenTrees under the entire scope
|
|
|
|
|
// And provide functions to find/add a new one
|
|
|
|
|
|
2018-06-12 04:05:45 +02:00
|
|
|
class SenTreeSet {
|
|
|
|
|
// Hash table of sensitive blocks.
|
|
|
|
|
private:
|
|
|
|
|
// TYPES
|
|
|
|
|
class HashSenTree {
|
|
|
|
|
public:
|
|
|
|
|
HashSenTree() {}
|
|
|
|
|
size_t operator() (const AstSenTree* kp) const {
|
|
|
|
|
return V3Hashed::uncachedHash(kp).fullValue();
|
|
|
|
|
}
|
2019-05-19 22:13:13 +02:00
|
|
|
// Copying required for OSX's libc++
|
2018-06-12 04:05:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class EqSenTree {
|
|
|
|
|
public:
|
|
|
|
|
EqSenTree() {}
|
|
|
|
|
bool operator() (const AstSenTree* ap, const AstSenTree* bp) const {
|
|
|
|
|
return ap->sameTree(bp);
|
|
|
|
|
}
|
2019-05-19 22:13:13 +02:00
|
|
|
// Copying required for OSX's libc++
|
2018-06-12 04:05:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// MEMBERS
|
|
|
|
|
typedef vl_unordered_set<AstSenTree*, HashSenTree, EqSenTree> Set;
|
|
|
|
|
Set m_trees; // Set of sensitive blocks, for folding.
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
|
SenTreeSet() {}
|
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
void add(AstSenTree* nodep) { m_trees.insert(nodep); }
|
|
|
|
|
AstSenTree* find(AstSenTree* likep) {
|
|
|
|
|
AstSenTree* resultp = NULL;
|
|
|
|
|
Set::iterator it = m_trees.find(likep);
|
|
|
|
|
if (it != m_trees.end()) {
|
|
|
|
|
resultp = *it;
|
|
|
|
|
}
|
|
|
|
|
return resultp;
|
|
|
|
|
}
|
|
|
|
|
void clear() { m_trees.clear(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
VL_UNCOPYABLE(SenTreeSet);
|
|
|
|
|
};
|
|
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
class SenTreeFinder : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// STATE
|
2019-05-19 22:13:13 +02:00
|
|
|
AstTopScope* m_topscopep; // Top scope to add statement to
|
2018-06-12 04:05:45 +02:00
|
|
|
SenTreeSet m_trees; // Set of sensitive blocks, for folding
|
2009-01-21 22:56:50 +01:00
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
// VISITORS
|
2018-05-14 12:50:47 +02:00
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
2009-01-21 22:56:50 +01:00
|
|
|
|
2016-11-27 14:11:38 +01:00
|
|
|
virtual void visit(AstNodeModule* nodep) {
|
2019-05-19 22:13:13 +02:00
|
|
|
// Only do the top
|
|
|
|
|
if (nodep->isTop()) {
|
2018-05-11 02:55:37 +02:00
|
|
|
iterateChildren(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2016-11-27 14:11:38 +01:00
|
|
|
virtual void visit(AstTopScope* nodep) {
|
2019-05-19 22:13:13 +02:00
|
|
|
m_topscopep = nodep;
|
2018-05-11 02:55:37 +02:00
|
|
|
iterateChildren(nodep);
|
2019-05-19 22:13:13 +02:00
|
|
|
// Don't clear topscopep, the namer persists beyond this visit
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2016-11-27 14:11:38 +01:00
|
|
|
virtual void visit(AstScope* nodep) {
|
2019-05-19 22:13:13 +02:00
|
|
|
// But no SenTrees under TopScope's scope
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
// Memorize existing block names
|
2016-11-27 14:11:38 +01:00
|
|
|
virtual void visit(AstActive* nodep) {
|
2019-05-19 22:13:13 +02:00
|
|
|
// Don't grab SenTrees under Actives, only those that are global (under Scope directly)
|
2018-05-11 02:55:37 +02:00
|
|
|
iterateChildren(nodep);
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2018-06-12 04:05:45 +02:00
|
|
|
virtual void visit(AstSenTree* nodep) { m_trees.add(nodep); }
|
2006-08-26 13:35:28 +02:00
|
|
|
// Empty visitors, speed things up
|
2016-11-27 14:11:38 +01:00
|
|
|
virtual void visit(AstNodeStmt* nodep) { }
|
|
|
|
|
virtual void visit(AstNode* nodep) {
|
2018-05-11 02:55:37 +02:00
|
|
|
iterateChildren(nodep);
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
// METHODS
|
|
|
|
|
public:
|
|
|
|
|
void clear() {
|
2019-05-19 22:13:13 +02:00
|
|
|
m_topscopep = NULL;
|
2018-06-12 04:05:45 +02:00
|
|
|
m_trees.clear();
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
AstSenTree* getSenTree(FileLine* fl, AstSenTree* sensesp) {
|
2019-05-19 22:13:13 +02:00
|
|
|
// Return a global sentree that matches given sense list.
|
2018-06-12 04:05:45 +02:00
|
|
|
AstSenTree* treep = m_trees.find(sensesp);
|
2019-05-19 22:13:13 +02:00
|
|
|
// Not found, form a new one
|
|
|
|
|
if (!treep) {
|
|
|
|
|
UASSERT(m_topscopep, "Never called main()");
|
|
|
|
|
treep = sensesp->cloneTree(false);
|
|
|
|
|
m_topscopep->addStmtsp(treep);
|
|
|
|
|
UINFO(8," New SENTREE "<<treep<<endl);
|
2018-06-12 04:05:45 +02:00
|
|
|
m_trees.add(treep);
|
2019-05-19 22:13:13 +02:00
|
|
|
// Note blocks may have also been added above in the Active visitor
|
|
|
|
|
}
|
|
|
|
|
return treep;
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
public:
|
2019-09-12 13:22:22 +02:00
|
|
|
// CONSTRUCTORS
|
2006-08-26 13:35:28 +02:00
|
|
|
SenTreeFinder() {
|
2019-05-19 22:13:13 +02:00
|
|
|
clear();
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
virtual ~SenTreeFinder() {}
|
|
|
|
|
void main(AstTopScope* nodep) {
|
2018-05-11 02:55:37 +02:00
|
|
|
iterate(nodep);
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-19 22:13:13 +02:00
|
|
|
#endif // Guard
|