Print debug info attached with an instruction.
authorDevang Patel <dpatel@apple.com>
Wed, 16 Sep 2009 20:21:17 +0000 (20:21 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 16 Sep 2009 20:21:17 +0000 (20:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82075 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Metadata.h
lib/VMCore/AsmWriter.cpp
lib/VMCore/Metadata.cpp

index 66a10a87e1151be501ad4196343e1539bd46b2f6..a2394beb400a256bfd6f1be7eadf8feb35707e89 100644 (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);
   
index a61f8fb2315af78113c783251c37ef8fbdac4295..12436523b1632766b5fb63e2893205ff0f128139 100644 (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);
 }
 
index 062fb96e5bf996dc3aaca6a1c76f0f9edb2130fe..2c80a60a8cf707b2421d8b4489d2d6c1a14d53c3 100644 (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) {