mirror of
https://github.com/verilator/verilator.git
synced 2025-05-03 05:56:53 +00:00
Internals: New Hashed/Graph functions towards msg980.
Signed-off-by: Wilson Snyder <wsnyder@wsnyder.org>
This commit is contained in:
parent
772a3a97eb
commit
f2fb77c15a
@ -140,6 +140,14 @@ V3GraphEdge::V3GraphEdge(V3Graph* graphp,
|
|||||||
inPushBack();
|
inPushBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
V3GraphEdge* V3GraphEdge::relinkFromp(V3GraphVertex* newFromp) {
|
||||||
|
V3GraphEdge *oldNxt = outNextp();
|
||||||
|
m_outs.unlink(m_fromp->m_outs, this);
|
||||||
|
m_fromp = newFromp;
|
||||||
|
outPushBack();
|
||||||
|
return oldNxt;
|
||||||
|
}
|
||||||
|
|
||||||
void V3GraphEdge::unlinkDelete() {
|
void V3GraphEdge::unlinkDelete() {
|
||||||
// Unlink from side
|
// Unlink from side
|
||||||
m_outs.unlink(m_fromp->m_outs, this);
|
m_outs.unlink(m_fromp->m_outs, this);
|
||||||
|
@ -242,6 +242,7 @@ public:
|
|||||||
return top()->sortCmp(rhsp->top());
|
return top()->sortCmp(rhsp->top());
|
||||||
}
|
}
|
||||||
void unlinkDelete();
|
void unlinkDelete();
|
||||||
|
V3GraphEdge* relinkFromp(V3GraphVertex* newFromp);
|
||||||
// ACCESSORS
|
// ACCESSORS
|
||||||
int weight() const { return m_weight; }
|
int weight() const { return m_weight; }
|
||||||
void weight(int weight) { m_weight=weight; }
|
void weight(int weight) { m_weight=weight; }
|
||||||
|
@ -105,12 +105,16 @@ public:
|
|||||||
//######################################################################
|
//######################################################################
|
||||||
// Hashed class functions
|
// Hashed class functions
|
||||||
|
|
||||||
void V3Hashed::hashAndInsert(AstNode* nodep) {
|
V3Hashed::iterator V3Hashed::hashAndInsert(AstNode* nodep) {
|
||||||
|
hash(nodep);
|
||||||
|
return m_hashMmap.insert(make_pair(nodeHash(nodep), nodep));
|
||||||
|
}
|
||||||
|
|
||||||
|
void V3Hashed::hash(AstNode* nodep) {
|
||||||
UINFO(8," hashI "<<nodep<<endl);
|
UINFO(8," hashI "<<nodep<<endl);
|
||||||
if (!nodep->user4p()) {
|
if (!nodep->user4p()) {
|
||||||
HashedVisitor visitor (nodep);
|
HashedVisitor visitor (nodep);
|
||||||
}
|
}
|
||||||
m_hashMmap.insert(make_pair(nodeHash(nodep), nodep));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool V3Hashed::sameNodes(AstNode* node1p, AstNode* node2p) {
|
bool V3Hashed::sameNodes(AstNode* node1p, AstNode* node2p) {
|
||||||
@ -189,3 +193,16 @@ V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) {
|
|||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp) {
|
||||||
|
UINFO(8," findD "<<nodep<<endl);
|
||||||
|
if (!nodep->user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node");
|
||||||
|
pair <HashMmap::iterator,HashMmap::iterator> eqrange = mmap().equal_range(nodeHash(nodep));
|
||||||
|
for (HashMmap::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) {
|
||||||
|
AstNode* node2p = eqit->second;
|
||||||
|
if (nodep != node2p && checkp->check(nodep,node2p) && sameNodes(nodep, node2p)) {
|
||||||
|
return eqit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return end();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,11 @@ public:
|
|||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
|
struct V3HashedUserCheck {
|
||||||
|
// Functor for V3Hashed::findDuplicate
|
||||||
|
virtual bool check(AstNode*,AstNode*) =0;
|
||||||
|
};
|
||||||
|
|
||||||
class V3Hashed : public VHashedBase {
|
class V3Hashed : public VHashedBase {
|
||||||
// NODE STATE
|
// NODE STATE
|
||||||
// AstNode::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal)
|
// AstNode::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||||
@ -70,10 +75,12 @@ public:
|
|||||||
|
|
||||||
// METHODS
|
// METHODS
|
||||||
void clear() { m_hashMmap.clear(); AstNode::user4ClearTree(); }
|
void clear() { m_hashMmap.clear(); AstNode::user4ClearTree(); }
|
||||||
void hashAndInsert(AstNode* nodep); // Hash the node, and insert into map
|
iterator hashAndInsert(AstNode* nodep); // Hash the node, and insert into map. Return iterator to inserted
|
||||||
|
void hash(AstNode* nodep); // Only hash the node
|
||||||
bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical
|
bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical
|
||||||
void erase(iterator it); // Remove node from structures
|
void erase(iterator it); // Remove node from structures
|
||||||
iterator findDuplicate(AstNode* nodep); // Return duplicate in hash, if any
|
iterator findDuplicate(AstNode* nodep); // Return duplicate in hash, if any
|
||||||
|
iterator findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp); // Extra user checks for sameness
|
||||||
AstNode* iteratorNodep(iterator it) { return it->second; }
|
AstNode* iteratorNodep(iterator it) { return it->second; }
|
||||||
void dumpFile(const string& filename, bool tree);
|
void dumpFile(const string& filename, bool tree);
|
||||||
void dumpFilePrefixed(const string& nameComment, bool tree=false);
|
void dumpFilePrefixed(const string& nameComment, bool tree=false);
|
||||||
|
Loading…
Reference in New Issue
Block a user