Internals: merge V3Hashed cleanups. No functional change intended
This commit is contained in:
parent
1601b3b6b0
commit
cc1adf9b38
11
src/V3Ast.h
11
src/V3Ast.h
|
|
@ -693,11 +693,14 @@ public:
|
|||
// Creating from raw data (sameHash functions)
|
||||
V3Hash() { setBoth(1,0); }
|
||||
V3Hash(uint32_t val) { setBoth(1,val); }
|
||||
V3Hash(void* vp) { setBoth(1,cvtToHash(vp)); }
|
||||
V3Hash(const void* vp) { setBoth(1,cvtToHash(vp)); }
|
||||
V3Hash(const string& name);
|
||||
V3Hash(V3Hash lh, V3Hash rh) {
|
||||
setBoth(1,lh.hshval()*31+rh.hshval());
|
||||
}
|
||||
V3Hash(V3Hash h1, V3Hash h2) {
|
||||
setBoth(1,h1.hshval()*31+h2.hshval()); }
|
||||
V3Hash(V3Hash h1, V3Hash h2, V3Hash h3) {
|
||||
setBoth(1,(h1.hshval()*31+h2.hshval())*31+h3.hshval()); }
|
||||
V3Hash(V3Hash h1, V3Hash h2, V3Hash h3, V3Hash h4) {
|
||||
setBoth(1,((h1.hshval()*31+h2.hshval())*31+h3.hshval())*31+h4.hshval()); }
|
||||
};
|
||||
ostream& operator<<(ostream& os, V3Hash rhs);
|
||||
|
||||
|
|
|
|||
|
|
@ -244,10 +244,10 @@ template< class T> std::string cvtToStr (const T& t) {
|
|||
ostringstream os; os<<t; return os.str();
|
||||
}
|
||||
|
||||
inline uint32_t cvtToHash(void* vp) {
|
||||
inline uint32_t cvtToHash(const void* vp) {
|
||||
// We can shove a 64 bit pointer into a 32 bit bucket
|
||||
// On 32 bit systems, lower is always 0, but who cares?
|
||||
union { void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
|
||||
union { const void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
|
||||
u.l.upper=0; u.l.lower=0; u.up=vp;
|
||||
return u.l.upper^u.l.lower;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ private:
|
|||
}
|
||||
|
||||
// METHODS
|
||||
void hashNodeIterate(AstNode* nodep) {
|
||||
void nodeHashIterate(AstNode* nodep) {
|
||||
if (!nodep->user4()) {
|
||||
if (nodep->backp()->castCFunc()
|
||||
&& !(nodep->castNodeStmt() || nodep->castCFunc())) {
|
||||
|
|
@ -83,21 +83,21 @@ private:
|
|||
m_lowerHash = oldHash;
|
||||
}
|
||||
// Update what will become the above node's hash
|
||||
m_lowerHash += V3Hash(nodep->user4p());
|
||||
m_lowerHash += V3Hashed::nodeHash(nodep);
|
||||
}
|
||||
|
||||
//--------------------
|
||||
// Default: Just iterate
|
||||
virtual void visit(AstVar*, AstNUser*) {}
|
||||
virtual void visit(AstNode* nodep, AstNUser*) {
|
||||
hashNodeIterate(nodep);
|
||||
nodeHashIterate(nodep);
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
HashedVisitor(AstNode* nodep) {
|
||||
hashNodeIterate(nodep);
|
||||
//UINFO(9," stmthash "<<hex<<nodep->user4()<<" "<<nodep<<endl);
|
||||
nodeHashIterate(nodep);
|
||||
//UINFO(9," stmthash "<<hex<<V3Hashed::nodeHash(nodep)<<" "<<nodep<<endl);
|
||||
}
|
||||
virtual ~HashedVisitor() {}
|
||||
};
|
||||
|
|
@ -105,16 +105,12 @@ public:
|
|||
//######################################################################
|
||||
// Hashed class functions
|
||||
|
||||
V3Hashed::V3Hashed() {
|
||||
AstNode::user4ClearTree(); // user4p() used on entire tree
|
||||
}
|
||||
|
||||
void V3Hashed::hashAndInsert(AstNode* nodep) {
|
||||
UINFO(8," hashI "<<nodep<<endl);
|
||||
if (!nodep->user4p()) {
|
||||
HashedVisitor visitor (nodep);
|
||||
}
|
||||
m_hashMmap.insert(make_pair(V3Hash(nodep->user4p()), nodep));
|
||||
m_hashMmap.insert(make_pair(nodeHash(nodep), nodep));
|
||||
}
|
||||
|
||||
bool V3Hashed::sameNodes(AstNode* node1p, AstNode* node2p) {
|
||||
|
|
@ -183,7 +179,7 @@ void V3Hashed::dumpFile(const string& filename, bool tree) {
|
|||
V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) {
|
||||
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(V3Hash(nodep->user4p()));
|
||||
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 && sameNodes(nodep, node2p)) {
|
||||
|
|
|
|||
|
|
@ -46,12 +46,13 @@ private:
|
|||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
V3Hashed();
|
||||
V3Hashed() { clear(); }
|
||||
~V3Hashed() {}
|
||||
|
||||
// ACCESSORS
|
||||
HashMmap& mmap() { return m_hashMmap; } // Return map for iteration
|
||||
HashMmap::iterator begin() { return m_hashMmap.begin(); }
|
||||
HashMmap::iterator end() { return m_hashMmap.end(); }
|
||||
iterator begin() { return m_hashMmap.begin(); }
|
||||
iterator end() { return m_hashMmap.end(); }
|
||||
|
||||
// METHODS
|
||||
static int debug() {
|
||||
|
|
@ -59,7 +60,7 @@ public:
|
|||
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
|
||||
return level;
|
||||
}
|
||||
void clear() { m_hashMmap.clear(); }
|
||||
void clear() { m_hashMmap.clear(); AstNode::user4ClearTree(); }
|
||||
void hashAndInsert(AstNode* nodep); // Hash the node, and insert into map
|
||||
bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical
|
||||
void erase(iterator it); // Remove node from structures
|
||||
|
|
@ -67,6 +68,7 @@ public:
|
|||
AstNode* iteratorNodep(iterator it) { return it->second; }
|
||||
void dumpFile(const string& filename, bool tree);
|
||||
void dumpFilePrefixed(const string& nameComment, bool tree=false);
|
||||
static V3Hash nodeHash(AstNode* nodep) { return V3Hash(nodep->user4p()); }
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ private:
|
|||
AstUser3InUse m_inuser3;
|
||||
|
||||
// Checking:
|
||||
// AstVarScope::user1() -> VarUsage. Set true to indicate tracking as lvalue/rvalue
|
||||
// AstVar(Scope)::user1() -> VarUsage. Set true to indicate tracking as lvalue/rvalue
|
||||
// Simulating:
|
||||
// AstVarScope::user3() -> V3Number*. Input value of variable or node (and output for non-delayed assignments)
|
||||
// AstVarScope::user2() -> V3Number*. Output value of variable (delayed assignments)
|
||||
// AstVar(Scope)::user3() -> V3Number*. Input value of variable or node (and output for non-delayed assignments)
|
||||
// AstVar(Scope)::user2() -> V3Number*. Output value of variable (delayed assignments)
|
||||
|
||||
enum VarUsage { VU_NONE=0, VU_LV=1, VU_RV=2, VU_LVDLY=4 };
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ private:
|
|||
if (nodep->valuep()) {
|
||||
if (nodep->valuep()->backp() != nodep) nodep->v3fatalSrc("Trace duplicate back needs consistency, so we can map duplicates back to TRACEINCs");
|
||||
hashed.hashAndInsert(nodep->valuep());
|
||||
UINFO(8, " Hashed "<<hex<<nodep->valuep()->user4()<<" "<<nodep<<endl);
|
||||
UINFO(8, " Hashed "<<hex<<hashed.nodeHash(nodep->valuep())<<" "<<nodep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ private:
|
|||
}
|
||||
}
|
||||
}
|
||||
AstNode::user4ClearTree();
|
||||
hashed.clear();
|
||||
}
|
||||
|
||||
void graphSimplify() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue