Add debug dumps of V3Hash state

This commit is contained in:
Wilson Snyder 2008-11-16 20:39:49 -05:00
parent d2105ba390
commit 5f70c1aa68
4 changed files with 58 additions and 1 deletions

View File

@ -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_both<rh.m_both; };
// CREATORS
class Illegal {}; // for creator type-overload selection

View File

@ -186,7 +186,7 @@ private:
int m_modNFuncs; // Number of functions made
AstNode* m_walkLast1p; // Final node that is the same in duplicate list
AstNode* m_walkLast2p; // Final node that is the same in duplicate list
V3Hashed m_hashed; // Hash for every node
V3Hashed m_hashed; // Hash for every node in module
// METHODS
void hashStatement(AstNode* nodep) {
@ -393,6 +393,9 @@ private:
m_state = STATE_HASH;
nodep->iterateChildren(*this);
m_state = STATE_IDLE;
if (debug()>=9) {
m_hashed.dumpFilePrefixed("combine");
}
// Walk the hashes removing empty functions
if (emptyFunctionDeletion()) {
walkEmptyFuncs();

View File

@ -31,10 +31,13 @@
#include <cstdarg>
#include <unistd.h>
#include <algorithm>
#include <iomanip>
#include <map>
#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<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename);
map<int,int> 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"<<endl;
*logp<<" #InBucket Occurrences\n";
for (map<int,int>::iterator it=dist.begin(); it!=dist.end(); ++it) {
*logp<<" "<<setw(9)<<it->first<<" "<<setw(12)<<it->second<<endl;
}
*logp <<"\n*** Dump:\n"<<endl;
for (HashMmap::iterator it=begin(); it!=end(); ++it) {
if (lasthash != it->first) {
lasthash = it->first;
*logp <<" "<<it->first<<endl;
}
*logp <<"\t"<<it->second<<endl;
// Dumping the entire tree may make nearly N^2 sized dumps,
// because the nodes under this one may also be in the hash table!
if (tree) it->second->dumpTree(*logp,"\t\t");
}
}
V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) {
UINFO(8," findD "<<nodep<<endl);
if (!nodep->user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node");

View File

@ -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