summaryrefslogtreecommitdiff
path: root/include/llvm/Metadata.h
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-07-29 00:33:07 +0000
committerDevang Patel <dpatel@apple.com>2009-07-29 00:33:07 +0000
commitf457d1316dec017cf204b54524878310c356bf64 (patch)
treea921c6c3407ebbc31d5b1d12623da5b7feb935ec /include/llvm/Metadata.h
parentade025c65c12503aba161a4fa399fd97414abaff (diff)
downloadllvm-f457d1316dec017cf204b54524878310c356bf64.tar.gz
llvm-f457d1316dec017cf204b54524878310c356bf64.tar.bz2
llvm-f457d1316dec017cf204b54524878310c356bf64.tar.xz
Add NamedMDNode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77409 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Metadata.h')
-rw-r--r--include/llvm/Metadata.h107
1 files changed, 103 insertions, 4 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index baa9cb8d71..9ee9b43eb7 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -26,7 +26,7 @@
namespace llvm {
//===----------------------------------------------------------------------===//
-// MetadataBase - A base class for MDNode and MDString.
+// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
class MetadataBase : public Value {
protected:
MetadataBase(const Type *Ty, unsigned scid)
@@ -49,14 +49,15 @@ public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MDString *) { return true; }
static bool classof(const Value *V) {
- return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal;
+ return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal
+ || V->getValueID() == NamedMDNodeVal;
}
};
//===----------------------------------------------------------------------===//
/// MDString - a single uniqued string.
/// These are used to efficiently contain a byte sequence for metadata.
-///
+/// MDString is always unnamd.
class MDString : public MetadataBase {
MDString(const MDString &); // DO NOT IMPLEMENT
StringRef Str;
@@ -89,7 +90,7 @@ public:
//===----------------------------------------------------------------------===//
/// MDNode - a tuple of other values.
/// These contain a list of the values that represent the metadata.
-///
+/// MDNode is always unnamed.
class MDNode : public MetadataBase, public FoldingSetNode {
MDNode(const MDNode &); // DO NOT IMPLEMENT
@@ -151,6 +152,104 @@ public:
}
};
+//===----------------------------------------------------------------------===//
+/// WeakMetadataVH - a weak value handle for metadata.
+class WeakMetadataVH : public WeakVH {
+public:
+ WeakMetadataVH() : WeakVH() {}
+ WeakMetadataVH(MetadataBase *M) : WeakVH(M) {}
+ WeakMetadataVH(const WeakMetadataVH &RHS) : WeakVH(RHS) {}
+
+ operator Value*() const {
+ llvm_unreachable("WeakMetadataVH only handles Metadata");
+ }
+
+ operator MetadataBase*() const {
+ return cast<MetadataBase>(getValPtr());
+ }
+};
+
+//===----------------------------------------------------------------------===//
+/// NamedMDNode - a tuple of other metadata.
+/// NamedMDNode is always named. All NamedMDNode element has a type of metadata.
+class NamedMDNode : public MetadataBase {
+ NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
+
+ friend class LLVMContextImpl;
+
+ Module *Parent;
+ StringRef Name;
+ SmallVector<WeakMetadataVH, 4> Node;
+ typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
+
+protected:
+ explicit NamedMDNode(const char *N, unsigned NameLength,
+ MetadataBase*const* Vals, unsigned NumVals,
+ Module *M = 0);
+public:
+ static NamedMDNode *Create(const char *N, unsigned NamedLength,
+ MetadataBase*const*MDs, unsigned NumMDs,
+ Module *M = 0) {
+ return new NamedMDNode(N, NamedLength, MDs, NumMDs, M);
+ }
+
+ typedef SmallVectorImpl<WeakMetadataVH>::const_iterator const_elem_iterator;
+
+ StringRef getName() const { return Name; }
+
+ /// getParent - Get the module that holds this named metadata collection.
+ inline Module *getParent() { return Parent; }
+ inline const Module *getParent() const { return Parent; }
+
+ Value *getElement(unsigned i) const {
+ return Node[i];
+ }
+
+ unsigned getNumElements() const {
+ return Node.size();
+ }
+
+ bool elem_empty() const {
+ return Node.empty();
+ }
+
+ const_elem_iterator elem_begin() const {
+ return Node.begin();
+ }
+
+ const_elem_iterator elem_end() const {
+ return Node.end();
+ }
+
+ /// getType() specialization - Type is always MetadataTy.
+ ///
+ inline const Type *getType() const {
+ return Type::MetadataTy;
+ }
+
+ /// isNullValue - Return true if this is the value that would be returned by
+ /// getNullValue. This always returns false because getNullValue will never
+ /// produce metadata.
+ virtual bool isNullValue() const {
+ return false;
+ }
+
+ /// Profile - calculate a unique identifier for this MDNode to collapse
+ /// duplicates
+ void Profile(FoldingSetNodeID &ID) const;
+
+ virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) {
+ llvm_unreachable(
+ "This should never be called because NamedMDNodes have no ops");
+ }
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const NamedMDNode *) { return true; }
+ static bool classof(const Value *V) {
+ return V->getValueID() == NamedMDNodeVal;
+ }
+};
+
} // end llvm namespace
#endif