2009-07-28 21:49:47 +00:00
|
|
|
//===-- llvm/Metadata.h - Metadata definitions ------------------*- C++ -*-===//
|
2009-05-10 20:57:05 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// @file
|
2009-07-28 21:49:47 +00:00
|
|
|
/// This file contains the declarations for metadata subclasses.
|
|
|
|
/// They represent the different flavors of metadata that live in LLVM.
|
2009-05-10 20:57:05 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MDNODE_H
|
|
|
|
#define LLVM_MDNODE_H
|
|
|
|
|
2009-07-29 15:24:54 +00:00
|
|
|
#include "llvm/Value.h"
|
2009-05-10 23:27:41 +00:00
|
|
|
#include "llvm/Type.h"
|
2009-07-29 17:16:17 +00:00
|
|
|
#include "llvm/OperandTraits.h"
|
2009-05-10 20:57:05 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-07-29 17:16:17 +00:00
|
|
|
#include "llvm/ADT/ilist_node.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-05-10 20:57:05 +00:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2009-07-29 15:24:54 +00:00
|
|
|
class Constant;
|
2009-07-31 21:35:40 +00:00
|
|
|
class LLVMContext;
|
2009-05-10 20:57:05 +00:00
|
|
|
|
2009-07-22 17:43:22 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-29 00:33:07 +00:00
|
|
|
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
|
2009-07-22 17:43:22 +00:00
|
|
|
class MetadataBase : public Value {
|
2009-07-23 01:19:53 +00:00
|
|
|
protected:
|
2009-07-22 17:43:22 +00:00
|
|
|
MetadataBase(const Type *Ty, unsigned scid)
|
|
|
|
: Value(Ty, scid) {}
|
|
|
|
|
2009-07-23 01:19:53 +00:00
|
|
|
public:
|
2009-07-22 17:43:22 +00:00
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2009-07-30 18:45:09 +00:00
|
|
|
static inline bool classof(const MetadataBase *) { return true; }
|
2009-07-22 17:43:22 +00:00
|
|
|
static bool classof(const Value *V) {
|
2009-07-29 00:33:07 +00:00
|
|
|
return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal
|
|
|
|
|| V->getValueID() == NamedMDNodeVal;
|
2009-07-22 17:43:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// MDString - a single uniqued string.
|
|
|
|
/// These are used to efficiently contain a byte sequence for metadata.
|
2009-07-29 00:33:07 +00:00
|
|
|
/// MDString is always unnamd.
|
2009-07-22 17:43:22 +00:00
|
|
|
class MDString : public MetadataBase {
|
|
|
|
MDString(const MDString &); // DO NOT IMPLEMENT
|
2009-07-25 23:55:21 +00:00
|
|
|
StringRef Str;
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2009-07-23 01:19:53 +00:00
|
|
|
protected:
|
2009-07-23 02:00:51 +00:00
|
|
|
explicit MDString(const char *begin, unsigned l)
|
2009-07-25 23:55:21 +00:00
|
|
|
: MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
|
2009-07-22 17:43:22 +00:00
|
|
|
|
2009-07-23 01:19:53 +00:00
|
|
|
public:
|
2009-07-31 21:35:40 +00:00
|
|
|
static MDString *get(LLVMContext &Context, const StringRef &Str);
|
|
|
|
|
2009-07-25 23:55:21 +00:00
|
|
|
StringRef getString() const { return Str; }
|
|
|
|
|
|
|
|
unsigned length() const { return Str.size(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
|
|
|
/// begin() - Pointer to the first byte of the string.
|
|
|
|
///
|
2009-07-25 23:55:21 +00:00
|
|
|
const char *begin() const { return Str.begin(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
|
|
|
/// end() - Pointer to one byte past the end of the string.
|
|
|
|
///
|
2009-07-25 23:55:21 +00:00
|
|
|
const char *end() const { return Str.end(); }
|
2009-07-22 17:43:22 +00:00
|
|
|
|
|
|
|
/// 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// MDNode - a tuple of other values.
|
2009-07-23 01:07:34 +00:00
|
|
|
/// These contain a list of the values that represent the metadata.
|
2009-07-29 00:33:07 +00:00
|
|
|
/// MDNode is always unnamed.
|
2009-07-23 01:07:34 +00:00
|
|
|
class MDNode : public MetadataBase, public FoldingSetNode {
|
2009-05-10 20:57:05 +00:00
|
|
|
MDNode(const MDNode &); // DO NOT IMPLEMENT
|
|
|
|
|
2009-07-23 01:07:34 +00:00
|
|
|
SmallVector<WeakVH, 4> Node;
|
|
|
|
typedef SmallVectorImpl<WeakVH>::iterator elem_iterator;
|
2009-07-16 23:44:30 +00:00
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
protected:
|
|
|
|
explicit MDNode(Value*const* Vals, unsigned NumVals);
|
|
|
|
public:
|
2009-07-31 21:35:40 +00:00
|
|
|
static MDNode *get(LLVMContext &Context,
|
|
|
|
Value* const* Vals, unsigned NumVals);
|
|
|
|
|
2009-07-23 01:07:34 +00:00
|
|
|
typedef SmallVectorImpl<WeakVH>::const_iterator const_elem_iterator;
|
2009-05-10 20:57:05 +00:00
|
|
|
|
|
|
|
Value *getElement(unsigned i) const {
|
|
|
|
return Node[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumElements() const {
|
|
|
|
return Node.size();
|
|
|
|
}
|
|
|
|
|
2009-05-30 05:06:04 +00:00
|
|
|
bool elem_empty() const {
|
|
|
|
return Node.empty();
|
|
|
|
}
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
const_elem_iterator elem_begin() const {
|
|
|
|
return Node.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
const_elem_iterator elem_end() const {
|
|
|
|
return Node.end();
|
|
|
|
}
|
|
|
|
|
2009-05-30 05:06:04 +00:00
|
|
|
/// getType() specialization - Type is always MetadataTy.
|
2009-05-10 20:57:05 +00:00
|
|
|
///
|
|
|
|
inline const Type *getType() const {
|
2009-05-30 05:06:04 +00:00
|
|
|
return Type::MetadataTy;
|
2009-05-10 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("This should never be called because MDNodes have no ops");
|
2009-05-10 20:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const MDNode *) { return true; }
|
|
|
|
static bool classof(const Value *V) {
|
|
|
|
return V->getValueID() == MDNodeVal;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// 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 {
|
2009-07-30 01:02:04 +00:00
|
|
|
return dyn_cast_or_null<MetadataBase>(getValPtr());
|
2009-07-29 00:33:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// NamedMDNode - a tuple of other metadata.
|
|
|
|
/// NamedMDNode is always named. All NamedMDNode element has a type of metadata.
|
2009-07-29 17:16:17 +00:00
|
|
|
template<typename ValueSubClass, typename ItemParentClass>
|
|
|
|
class SymbolTableListTraits;
|
|
|
|
|
|
|
|
class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
|
|
|
|
friend class SymbolTableListTraits<NamedMDNode, Module>;
|
2009-07-29 00:33:07 +00:00
|
|
|
NamedMDNode(const NamedMDNode &); // DO NOT IMPLEMENT
|
|
|
|
|
|
|
|
friend class LLVMContextImpl;
|
|
|
|
|
|
|
|
Module *Parent;
|
|
|
|
SmallVector<WeakMetadataVH, 4> Node;
|
|
|
|
typedef SmallVectorImpl<WeakMetadataVH>::iterator elem_iterator;
|
|
|
|
|
|
|
|
protected:
|
2009-07-29 21:58:56 +00:00
|
|
|
explicit NamedMDNode(const Twine &N, MetadataBase*const* Vals,
|
|
|
|
unsigned NumVals, Module *M = 0);
|
2009-07-29 00:33:07 +00:00
|
|
|
public:
|
2009-07-29 21:58:56 +00:00
|
|
|
static NamedMDNode *Create(const Twine &N, MetadataBase*const*MDs,
|
|
|
|
unsigned NumMDs, Module *M = 0) {
|
|
|
|
return new NamedMDNode(N, MDs, NumMDs, M);
|
2009-07-29 00:33:07 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 06:19:01 +00:00
|
|
|
/// eraseFromParent - Drop all references and remove the node from parent
|
|
|
|
/// module.
|
|
|
|
void eraseFromParent();
|
|
|
|
|
|
|
|
/// dropAllReferences - Remove all uses and clear node vector.
|
|
|
|
void dropAllReferences();
|
|
|
|
|
|
|
|
~NamedMDNode();
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
typedef SmallVectorImpl<WeakMetadataVH>::const_iterator const_elem_iterator;
|
|
|
|
|
|
|
|
/// getParent - Get the module that holds this named metadata collection.
|
|
|
|
inline Module *getParent() { return Parent; }
|
|
|
|
inline const Module *getParent() const { return Parent; }
|
2009-07-29 17:16:17 +00:00
|
|
|
void setParent(Module *M) { Parent = M; }
|
2009-07-29 00:33:07 +00:00
|
|
|
|
2009-07-29 21:58:56 +00:00
|
|
|
MetadataBase *getElement(unsigned i) const {
|
2009-07-29 00:33:07 +00:00
|
|
|
return Node[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumElements() const {
|
|
|
|
return Node.size();
|
|
|
|
}
|
|
|
|
|
2009-07-30 23:57:23 +00:00
|
|
|
/// addElement - Add metadata element.
|
|
|
|
void addElement(MetadataBase *M) {
|
|
|
|
Node.push_back(WeakMetadataVH(M));
|
|
|
|
}
|
|
|
|
|
2009-07-29 00:33:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|