Remove unused method.
[oota-llvm.git] / include / llvm / Metadata.h
1 //===-- llvm/Metadata.h - Metadata definitions ------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// This file contains the declarations for metadata subclasses.
12 /// They represent the different flavors of metadata that live in LLVM.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_MDNODE_H
17 #define LLVM_MDNODE_H
18
19 #include "llvm/Constant.h"
20 #include "llvm/Type.h"
21 #include "llvm/ADT/FoldingSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/ValueHandle.h"
25
26 namespace llvm {
27
28 //===----------------------------------------------------------------------===//
29 // MetadataBase  - A base class for MDNode and MDString.
30 class MetadataBase : public Value {
31 protected:
32   MetadataBase(const Type *Ty, unsigned scid)
33     : Value(Ty, scid) {}
34
35 public:
36   /// getType() specialization - Type is always MetadataTy.
37   ///
38   inline const Type *getType() const {
39     return Type::MetadataTy;
40   }
41
42   /// isNullValue - Return true if this is the value that would be returned by
43   /// getNullValue.  This always returns false because getNullValue will never
44   /// produce metadata.
45   virtual bool isNullValue() const {
46     return false;
47   }
48
49   /// Methods for support type inquiry through isa, cast, and dyn_cast:
50   static inline bool classof(const MDString *) { return true; }
51   static bool classof(const Value *V) {
52     return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal;
53   }
54 };
55
56 //===----------------------------------------------------------------------===//
57 /// MDString - a single uniqued string.
58 /// These are used to efficiently contain a byte sequence for metadata.
59 ///
60 class MDString : public MetadataBase {
61   MDString(const MDString &);            // DO NOT IMPLEMENT
62   StringRef Str;
63   friend class LLVMContextImpl;
64
65 protected:
66   explicit MDString(const char *begin, unsigned l)
67     : MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
68
69 public:
70   StringRef getString() const { return Str; }
71
72   unsigned length() const { return Str.size(); }
73
74   /// begin() - Pointer to the first byte of the string.
75   ///
76   const char *begin() const { return Str.begin(); }
77
78   /// end() - Pointer to one byte past the end of the string.
79   ///
80   const char *end() const { return Str.end(); }
81
82   /// Methods for support type inquiry through isa, cast, and dyn_cast:
83   static inline bool classof(const MDString *) { return true; }
84   static bool classof(const Value *V) {
85     return V->getValueID() == MDStringVal;
86   }
87 };
88
89 //===----------------------------------------------------------------------===//
90 /// MDNode - a tuple of other values.
91 /// These contain a list of the values that represent the metadata. 
92 ///
93 class MDNode : public MetadataBase, public FoldingSetNode {
94   MDNode(const MDNode &);      // DO NOT IMPLEMENT
95
96   friend class LLVMContextImpl;
97
98   SmallVector<WeakVH, 4> Node;
99   typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
100
101 protected:
102   explicit MDNode(Value*const* Vals, unsigned NumVals);
103 public:
104   typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
105
106   Value *getElement(unsigned i) const {
107     return Node[i];
108   }
109
110   unsigned getNumElements() const {
111     return Node.size();
112   }
113
114   bool elem_empty() const {
115     return Node.empty();
116   }
117
118   const_elem_iterator elem_begin() const {
119     return Node.begin();
120   }
121
122   const_elem_iterator elem_end() const {
123     return Node.end();
124   }
125
126   /// getType() specialization - Type is always MetadataTy.
127   ///
128   inline const Type *getType() const {
129     return Type::MetadataTy;
130   }
131
132   /// isNullValue - Return true if this is the value that would be returned by
133   /// getNullValue.  This always returns false because getNullValue will never
134   /// produce metadata.
135   virtual bool isNullValue() const {
136     return false;
137   }
138
139   /// Profile - calculate a unique identifier for this MDNode to collapse
140   /// duplicates
141   void Profile(FoldingSetNodeID &ID) const;
142
143   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
144     llvm_unreachable("This should never be called because MDNodes have no ops");
145   }
146
147   /// Methods for support type inquiry through isa, cast, and dyn_cast:
148   static inline bool classof(const MDNode *) { return true; }
149   static bool classof(const Value *V) {
150     return V->getValueID() == MDNodeVal;
151   }
152 };
153
154 } // end llvm namespace
155
156 #endif