[llvm-commits] [llvm] r82075 - in /llvm/trunk: include/llvm/Metadata.h lib/VMCore/AsmWriter.cpp lib/VMCore/Metadata.cpp

Chris Lattner clattner at apple.com
Sun Sep 27 15:38:11 PDT 2009


On Sep 16, 2009, at 1:21 PM, Devang Patel wrote:

> Author: dpatel
> Date: Wed Sep 16 15:21:17 2009
> New Revision: 82075
>
> URL: http://llvm.org/viewvc/llvm-project?rev=82075&view=rev
> Log:
> Print debug info attached with an instruction.

Again, debug info should not be special here.  Instead of the name  
'dbg' being hard coded, this should just iterate over all metadata  
attached to an instruction, and ask the "Metadata" class (which still  
really needs to be renamed) what the spelling of the MDKind is.

-Chris

>
> Modified:
>    llvm/trunk/include/llvm/Metadata.h
>    llvm/trunk/lib/VMCore/AsmWriter.cpp
>    llvm/trunk/lib/VMCore/Metadata.cpp
>
> Modified: llvm/trunk/include/llvm/Metadata.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Metadata.h?rev=82075&r1=82074&r2=82075&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/include/llvm/Metadata.h (original)
> +++ llvm/trunk/include/llvm/Metadata.h Wed Sep 16 15:21:17 2009
> @@ -312,9 +312,11 @@
> /// 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 @@
>   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 @@
>   /// 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);
>
>
> Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=82075&r1=82074&r2=82075&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
> +++ llvm/trunk/lib/VMCore/AsmWriter.cpp Wed Sep 16 15:21:17 2009
> @@ -678,6 +678,8 @@
>
>   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 @@
>       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 @@
>   // 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 @@
>     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);
> }
>
>
> Modified: llvm/trunk/lib/VMCore/Metadata.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=82075&r1=82074&r2=82075&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/VMCore/Metadata.cpp (original)
> +++ llvm/trunk/lib/VMCore/Metadata.cpp Wed Sep 16 15:21:17 2009
> @@ -308,6 +308,15 @@
>   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) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list