Implememting named register intrinsics
[oota-llvm.git] / include / llvm / IR / Metadata.h
index 8c2cfac235d2db466f7a925af92bb89a931a7fb0..7a0ca887201bcb488a0326278ff11cee918f32db 100644 (file)
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ilist_node.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/Value.h"
 
 namespace llvm {
-class Constant;
-class Instruction;
 class LLVMContext;
 class Module;
-template <typename T> class SmallVectorImpl;
 template<typename ValueSubClass, typename ItemParentClass>
   class SymbolTableListTraits;
 
 
+enum LLVMConstants : uint32_t {
+  DEBUG_METADATA_VERSION = 1  // Current debug info version number.
+};
+
 //===----------------------------------------------------------------------===//
 /// MDString - a single uniqued string.
 /// These are used to efficiently contain a byte sequence for metadata.
@@ -139,7 +141,7 @@ public:
   void replaceOperandWith(unsigned i, Value *NewVal);
 
   /// getOperand - Return specified operand.
-  Value *getOperand(unsigned i) const;
+  Value *getOperand(unsigned i) const LLVM_READONLY;
 
   /// getNumOperands - Return number of MDNode operands.
   unsigned getNumOperands() const { return NumOperands; }
@@ -164,6 +166,9 @@ public:
     return V->getValueID() == MDNodeVal;
   }
 
+  /// Check whether MDNode is a vtable access.
+  bool isTBAAVtableAccess() const;
+
   /// Methods for metadata merging.
   static MDNode *getMostGenericTBAA(MDNode *A, MDNode *B);
   static MDNode *getMostGenericFPMath(MDNode *A, MDNode *B);
@@ -203,6 +208,42 @@ class NamedMDNode : public ilist_node<NamedMDNode> {
 
   explicit NamedMDNode(const Twine &N);
 
+  template<class T1, class T2>
+  class op_iterator_impl :
+      public std::iterator<std::bidirectional_iterator_tag, T2> {
+    const NamedMDNode *Node;
+    unsigned Idx;
+    op_iterator_impl(const NamedMDNode *N, unsigned i) : Node(N), Idx(i) { }
+
+    friend class NamedMDNode;
+
+  public:
+    op_iterator_impl() : Node(nullptr), Idx(0) { }
+
+    bool operator==(const op_iterator_impl &o) const { return Idx == o.Idx; }
+    bool operator!=(const op_iterator_impl &o) const { return Idx != o.Idx; }
+    op_iterator_impl &operator++() {
+      ++Idx;
+      return *this;
+    }
+    op_iterator_impl operator++(int) {
+      op_iterator_impl tmp(*this);
+      operator++();
+      return tmp;
+    }
+    op_iterator_impl &operator--() {
+      --Idx;
+      return *this;
+    }
+    op_iterator_impl operator--(int) {
+      op_iterator_impl tmp(*this);
+      operator--();
+      return tmp;
+    }
+
+    T1 operator*() const { return Node->getOperand(Idx); }
+  };
+
 public:
   /// eraseFromParent - Drop all references and remove the node from parent
   /// module.
@@ -231,10 +272,28 @@ public:
   StringRef getName() const;
 
   /// print - Implement operator<< on NamedMDNode.
-  void print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW = 0) const;
+  void print(raw_ostream &ROS) const;
 
   /// dump() - Allow printing of NamedMDNodes from the debugger.
   void dump() const;
+
+  // ---------------------------------------------------------------------------
+  // Operand Iterator interface...
+  //
+  typedef op_iterator_impl<MDNode*, MDNode> op_iterator;
+  op_iterator op_begin() { return op_iterator(this, 0); }
+  op_iterator op_end()   { return op_iterator(this, getNumOperands()); }
+
+  typedef op_iterator_impl<const MDNode*, MDNode> const_op_iterator;
+  const_op_iterator op_begin() const { return const_op_iterator(this, 0); }
+  const_op_iterator op_end()   const { return const_op_iterator(this, getNumOperands()); }
+
+  inline iterator_range<op_iterator>  operands() {
+    return iterator_range<op_iterator>(op_begin(), op_end());
+  }
+  inline iterator_range<const_op_iterator> operands() const {
+    return iterator_range<const_op_iterator>(op_begin(), op_end());
+  }
 };
 
 } // end llvm namespace