[llvm] r221023 - IR: MDNode => Value: Add Instruction::getMDNode()

Duncan P. N. Exon Smith dexonsmith at apple.com
Fri Oct 31 16:58:04 PDT 2014


Author: dexonsmith
Date: Fri Oct 31 18:58:04 2014
New Revision: 221023

URL: http://llvm.org/viewvc/llvm-project?rev=221023&view=rev
Log:
IR: MDNode => Value: Add Instruction::getMDNode()

Add `Instruction::getMDNode()` that casts to `MDNode` before changing
`Instruction::getMetadata()` to return `Value`.  This avoids adding
`cast_or_null<MDNode>` boiler-plate throughout the code.

Part of PR21433.

Modified:
    llvm/trunk/include/llvm/IR/Instruction.h
    llvm/trunk/lib/IR/Metadata.cpp

Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=221023&r1=221022&r2=221023&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Fri Oct 31 18:58:04 2014
@@ -153,6 +153,24 @@ public:
     return getMetadataImpl(Kind);
   }
 
+  /// Get the the metadata as an MDNode.
+  ///
+  /// \pre Any KindID metadata is implemented using \a MDNode.
+  MDNode *getMDNode(unsigned KindID) const {
+    if (!hasMetadata())
+      return nullptr;
+    return getMDNodeImpl(KindID);
+  }
+
+  /// Get the the metadata as an MDNode.
+  ///
+  /// \pre Any KindID metadata is implemented using \a MDNode.
+  MDNode *getMDNode(StringRef Kind) const {
+    if (!hasMetadata())
+      return nullptr;
+    return getMDNodeImpl(Kind);
+  }
+
   /// getAllMetadata - Get all metadata attached to this Instruction.  The first
   /// element of each pair returned is the KindID, the second element is the
   /// metadata value.  This list is returned sorted by the KindID.
@@ -273,6 +291,8 @@ private:
   // These are all implemented in Metadata.cpp.
   MDNode *getMetadataImpl(unsigned KindID) const;
   MDNode *getMetadataImpl(StringRef Kind) const;
+  MDNode *getMDNodeImpl(unsigned KindID) const;
+  MDNode *getMDNodeImpl(StringRef Kind) const;
   void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const;
   void getAllMetadataOtherThanDebugLocImpl(SmallVectorImpl<std::pair<unsigned,
                                            MDNode*> > &) const;

Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=221023&r1=221022&r2=221023&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Fri Oct 31 18:58:04 2014
@@ -609,6 +609,14 @@ MDNode *Instruction::getMetadataImpl(Str
   return getMetadataImpl(getContext().getMDKindID(Kind));
 }
 
+MDNode *Instruction::getMDNodeImpl(unsigned KindID) const {
+  return getMetadataImpl(KindID);
+}
+
+MDNode *Instruction::getMDNodeImpl(StringRef Kind) const {
+  return getMetadataImpl(Kind);
+}
+
 void Instruction::dropUnknownMetadata(ArrayRef<unsigned> KnownIDs) {
   SmallSet<unsigned, 5> KnownSet;
   KnownSet.insert(KnownIDs.begin(), KnownIDs.end());





More information about the llvm-commits mailing list