From 5f70c1aa682c700e390fae6eaf1cea2525b12870 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 16 Nov 2008 20:39:49 -0500 Subject: [PATCH] Add debug dumps of V3Hash state --- src/V3Ast.h | 1 + src/V3Combine.cpp | 5 ++++- src/V3Hashed.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++ src/V3Hashed.h | 2 ++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index d1d851ad6..73a036f2b 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -422,6 +422,7 @@ public: uint32_t hshval() const { return m_both & M24; } // OPERATORS inline bool operator== (const V3Hash& rh) const { return m_both==rh.m_both; }; + inline bool operator!= (const V3Hash& rh) const { return m_both!=rh.m_both; }; inline bool operator< (const V3Hash& rh) const { return m_bothiterateChildren(*this); m_state = STATE_IDLE; + if (debug()>=9) { + m_hashed.dumpFilePrefixed("combine"); + } // Walk the hashes removing empty functions if (emptyFunctionDeletion()) { walkEmptyFuncs(); diff --git a/src/V3Hashed.cpp b/src/V3Hashed.cpp index dfeaed8e0..9c174b380 100644 --- a/src/V3Hashed.cpp +++ b/src/V3Hashed.cpp @@ -31,10 +31,13 @@ #include #include #include +#include +#include #include "V3Global.h" #include "V3Hashed.h" #include "V3Ast.h" +#include "V3File.h" //###################################################################### // Hashed state, as a visitor of each AstNode @@ -122,6 +125,54 @@ void V3Hashed::erase(iterator it) { nodep->user4p(NULL); // So we don't allow removeNode again } +void V3Hashed::dumpFilePrefixed(const string& nameComment, bool tree) { + if (v3Global.opt.dumpTree()) { + dumpFile(v3Global.debugFilename(nameComment)+".hash", tree); + } +} + +void V3Hashed::dumpFile(const string& filename, bool tree) { + const auto_ptr logp (V3File::new_ofstream(filename)); + if (logp->fail()) v3fatalSrc("Can't write "< dist; + + V3Hash lasthash; + int num_in_bucket = 0; + for (HashMmap::iterator it=begin(); 1; ++it) { + if (lasthash != it->first || it==end()) { + if (it!=end()) lasthash = it->first; + if (num_in_bucket) { + if (dist.find(num_in_bucket)==dist.end()) { + dist.insert(make_pair(num_in_bucket,1)); + } else { + ++dist[num_in_bucket]; + } + } + num_in_bucket = 0; + } + if (it==end()) break; + num_in_bucket++; + } + *logp <<"\n*** STATS:\n"<::iterator it=dist.begin(); it!=dist.end(); ++it) { + *logp<<" "<first<<" "<second<first) { + lasthash = it->first; + *logp <<" "<first<second<second->dumpTree(*logp,"\t\t"); + } +} + V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) { UINFO(8," findD "<user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node"); diff --git a/src/V3Hashed.h b/src/V3Hashed.h index b845b5463..d6bbb9864 100644 --- a/src/V3Hashed.h +++ b/src/V3Hashed.h @@ -57,6 +57,8 @@ public: void erase(iterator it); // Remove node from structures iterator findDuplicate(AstNode* nodep); // Return duplicate in hash, if any AstNode* iteratorNodep(iterator it) { return it->second; } + void dumpFile(const string& filename, bool tree); + void dumpFilePrefixed(const string& nameComment, bool tree=false); }; #endif // Guard