2009-05-10 20:57:05 +00:00
|
|
|
//===-- llvm/Metadata.h - Constant class subclass definitions ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// @file
|
|
|
|
/// This file contains the declarations for the subclasses of Constant,
|
|
|
|
/// which represent the different flavors of constant values that live in LLVM.
|
|
|
|
/// Note that Constants are immutable (once created they never change) and are
|
|
|
|
/// fully shared by structural equivalence. This means that two structurally
|
|
|
|
/// equivalent constants will always have the same address. Constant's are
|
|
|
|
/// created on demand as needed and never deleted: thus clients don't have to
|
|
|
|
/// worry about the lifetime of the objects.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MDNODE_H
|
|
|
|
#define LLVM_MDNODE_H
|
|
|
|
|
|
|
|
#include "llvm/Constant.h"
|
2009-05-10 23:27:41 +00:00
|
|
|
#include "llvm/Type.h"
|
2009-05-10 20:57:05 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
|
|
|
#include "llvm/ADT/SmallVector.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-22 17:43:22 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// MetadataBase - A base class for MDNode and MDString.
|
|
|
|
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:
|
|
|
|
static inline bool classof(const MDString *) { return true; }
|
|
|
|
static bool classof(const Value *V) {
|
2009-07-23 01:07:34 +00:00
|
|
|
return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal;
|
2009-07-22 17:43:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// MDString - a single uniqued string.
|
|
|
|
/// These are used to efficiently contain a byte sequence for metadata.
|
|
|
|
///
|
|
|
|
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
|
|
|
friend class LLVMContextImpl;
|
|
|
|
|
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-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-05-10 20:57:05 +00:00
|
|
|
///
|
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-16 23:44:30 +00:00
|
|
|
friend class LLVMContextImpl;
|
|
|
|
|
2009-05-10 20:57:05 +00:00
|
|
|
void replaceElement(Value *From, Value *To);
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|