Print debug info attached with an instruction.

llvm-svn: 82075
This commit is contained in:
Devang Patel 2009-09-16 20:21:17 +00:00
parent 5d8cfb217c
commit dec23fd825
3 changed files with 32 additions and 3 deletions

View File

@ -312,9 +312,11 @@ public:
/// ID values are 1 or higher. This ID is set by RegisterMDKind.
typedef unsigned MDKindID;
class Metadata {
private:
public:
typedef std::pair<MDKindID, WeakVH> MDPairTy;
typedef SmallVector<MDPairTy, 2> MDMapTy;
private:
typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
/// MetadataStore - Collection of metadata used in this context.
@ -324,7 +326,6 @@ private:
StringMap<unsigned> MDHandlerNames;
public:
/// RegisterMDKind - Register a new metadata kind and return its ID.
/// A metadata kind can be registered only once.
MDKindID RegisterMDKind(const char *Name);
@ -337,6 +338,9 @@ public:
/// If the metadata is not found then return 0.
MDNode *getMD(MDKindID Kind, const Instruction *Inst);
/// getMDs - Get the metadata attached with an Instruction.
const MDMapTy *getMDs(const Instruction *Inst);
/// setMD - Attach the metadata of given kind with an Instruction.
void setMD(MDKindID Kind, MDNode *Node, Instruction *Inst);

View File

@ -678,6 +678,8 @@ void SlotTracker::processFunction() {
ST_DEBUG("Inserting Instructions:\n");
Metadata &TheMetadata = TheFunction->getContext().getMetadata();
// Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(),
E = TheFunction->end(); BB != E; ++BB) {
@ -691,9 +693,17 @@ void SlotTracker::processFunction() {
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
CreateMetadataSlot(N);
// Process metadata attached with this instruction.
const Metadata::MDMapTy *MDs = TheMetadata.getMDs(I);
if (MDs)
for (Metadata::MDMapTy::const_iterator MI = MDs->begin(),
ME = MDs->end(); MI != ME; ++MI)
if (MDNode *MDN = dyn_cast_or_null<MDNode>(MI->second))
CreateMetadataSlot(MDN);
}
}
FunctionProcessed = true;
ST_DEBUG("end processFunction!\n");
@ -1255,6 +1265,7 @@ class AssemblyWriter {
// Each MDNode is assigned unique MetadataIDNo.
std::map<const MDNode *, unsigned> MDNodes;
unsigned MetadataIDNo;
public:
inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M,
@ -1979,6 +1990,11 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Out << ", align " << cast<StoreInst>(I).getAlignment();
}
// Print DebugInfo
Metadata &TheMetadata = I.getContext().getMetadata();
unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
if (const MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &I))
Out << ", dbg !" << Machine.getMetadataSlot(Dbg);
printInfoComment(I);
}

View File

@ -308,6 +308,15 @@ MDNode *Metadata::getMD(MDKindID MDKind, const Instruction *Inst) {
return Node;
}
/// getMDs - Get the metadata attached with an Instruction.
const Metadata::MDMapTy *Metadata::getMDs(const Instruction *Inst) {
MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end())
return NULL;
return &(I->second);
}
/// ValueIsDeleted - This handler is used to update metadata store
/// when a value is deleted.
void Metadata::ValueIsDeleted(const Instruction *Inst) {