From: Devang Patel Date: Wed, 16 Sep 2009 20:21:17 +0000 (+0000) Subject: Print debug info attached with an instruction. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=43215788d5d79a0a336ca85442d7c8a45552dd7a Print debug info attached with an instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82075 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 66a10a87e11..a2394beb400 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -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 MDPairTy; typedef SmallVector MDMapTy; + +private: typedef DenseMap MDStoreTy; /// MetadataStore - Collection of metadata used in this context. @@ -324,7 +326,6 @@ private: StringMap 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); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index a61f8fb2315..12436523b16 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -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(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(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 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(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); } diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 062fb96e5bf..2c80a60a8cf 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -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) {