ValueEnumerator - debug dump().

llvm-svn: 146070
This commit is contained in:
Chad Rosier 2011-12-07 20:44:46 +00:00
parent b170dc0eff
commit cbfc33c233
2 changed files with 43 additions and 1 deletions

View File

@ -19,6 +19,8 @@
#include "llvm/Module.h"
#include "llvm/ValueSymbolTable.h"
#include "llvm/Instructions.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
@ -107,7 +109,6 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
OptimizeConstants(FirstConstant, Values.size());
}
unsigned ValueEnumerator::getInstructionID(const Instruction *Inst) const {
InstructionMapType::const_iterator I = InstructionMap.find(Inst);
assert(I != InstructionMap.end() && "Instruction is not mapped!");
@ -130,6 +131,43 @@ unsigned ValueEnumerator::getValueID(const Value *V) const {
return I->second-1;
}
void ValueEnumerator::dump() const {
print(dbgs(), ValueMap, "Default");
dbgs() << '\n';
print(dbgs(), MDValueMap, "MetaData");
dbgs() << '\n';
}
void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
const char *Name) const {
OS << "Map Name: " << Name << "\n";
OS << "Size: " << Map.size() << "\n";
for (ValueMapType::const_iterator I = Map.begin(),
E = Map.end(); I != E; ++I) {
const Value *V = I->first;
if (V->hasName())
OS << "Value: " << V->getName();
else
OS << "Value: [null]\n";
V->dump();
OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):";
for (Value::const_use_iterator UI = V->use_begin(), UE = V->use_end();
UI != UE; ++UI) {
if (UI != V->use_begin())
OS << ",";
if((*UI)->hasName())
OS << " " << (*UI)->getName();
else
OS << " [null]";
}
OS << "\n\n";
}
}
// Optimize constant ordering.
namespace {
struct CstSortPredicate {

View File

@ -32,6 +32,7 @@ class NamedMDNode;
class AttrListPtr;
class ValueSymbolTable;
class MDSymbolTable;
class raw_ostream;
class ValueEnumerator {
public:
@ -83,6 +84,9 @@ private:
public:
ValueEnumerator(const Module *M);
void dump() const;
void print(raw_ostream &OS, const ValueMapType &Map, const char *Name) const;
unsigned getValueID(const Value *V) const;
unsigned getTypeID(Type *T) const {