Derive NamedMDNode from Value.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93032 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2010-01-09 00:30:14 +00:00
parent 54e146b935
commit 8fba578be7
4 changed files with 28 additions and 15 deletions

View File

@ -31,7 +31,7 @@ template<typename ValueSubClass, typename ItemParentClass>
//===----------------------------------------------------------------------===//
// MetadataBase - A base class for MDNode, MDString and NamedMDNode.
// MetadataBase - A base class for MDNode and MDString.
class MetadataBase : public Value {
protected:
MetadataBase(const Type *Ty, unsigned scid)
@ -42,8 +42,7 @@ public:
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MetadataBase *) { return true; }
static bool classof(const Value *V) {
return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal
|| V->getValueID() == NamedMDNodeVal;
return V->getValueID() == MDStringVal || V->getValueID() == MDNodeVal;
}
};
@ -169,7 +168,7 @@ private:
//===----------------------------------------------------------------------===//
/// NamedMDNode - a tuple of MDNodes.
/// NamedMDNode is always named. All NamedMDNode operand has a type of metadata.
class NamedMDNode : public MetadataBase, public ilist_node<NamedMDNode> {
class NamedMDNode : public Value, public ilist_node<NamedMDNode> {
friend class SymbolTableListTraits<NamedMDNode, Module>;
friend class LLVMContextImpl;

View File

@ -135,7 +135,7 @@ void ValueEnumerator::setInstructionID(const Instruction *I) {
}
unsigned ValueEnumerator::getValueID(const Value *V) const {
if (isa<MetadataBase>(V)) {
if (isa<MetadataBase>(V) || isa<NamedMDNode>(V)) {
ValueMapType::const_iterator I = MDValueMap.find(V);
assert(I != MDValueMap.end() && "Value not in slotcalculator!");
return I->second-1;
@ -205,6 +205,25 @@ void ValueEnumerator::EnumerateMDSymbolTable(const MDSymbolTable &MST) {
EnumerateValue(MI->getValue());
}
void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
// Check to see if it's already in!
unsigned &MDValueID = MDValueMap[MD];
if (MDValueID) {
// Increment use count.
MDValues[MDValueID-1].second++;
return;
}
// Enumerate the type of this value.
EnumerateType(MD->getType());
for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
if (MDNode *E = MD->getOperand(i))
EnumerateValue(E);
MDValues.push_back(std::make_pair(MD, 1U));
MDValueMap[MD] = Values.size();
}
void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
// Check to see if it's already in!
unsigned &MDValueID = MDValueMap[MD];
@ -230,15 +249,6 @@ void ValueEnumerator::EnumerateMetadata(const MetadataBase *MD) {
return;
}
if (const NamedMDNode *N = dyn_cast<NamedMDNode>(MD)) {
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
if (MDNode *E = N->getOperand(i))
EnumerateValue(E);
MDValues.push_back(std::make_pair(MD, 1U));
MDValueMap[MD] = Values.size();
return;
}
// Add the value.
assert(isa<MDString>(MD) && "Unknown metadata kind");
MDValues.push_back(std::make_pair(MD, 1U));
@ -249,6 +259,8 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
assert(!V->getType()->isVoidTy() && "Can't insert void values!");
if (const MetadataBase *MB = dyn_cast<MetadataBase>(V))
return EnumerateMetadata(MB);
else if (const NamedMDNode *NMD = dyn_cast<NamedMDNode>(V))
return EnumerateNamedMDNode(NMD);
// Check to see if it's already in!
unsigned &ValueID = ValueMap[V];

View File

@ -27,6 +27,7 @@ class BasicBlock;
class Function;
class Module;
class MetadataBase;
class NamedMDNode;
class AttrListPtr;
class TypeSymbolTable;
class ValueSymbolTable;
@ -127,6 +128,7 @@ private:
void OptimizeConstants(unsigned CstStart, unsigned CstEnd);
void EnumerateMetadata(const MetadataBase *MD);
void EnumerateNamedMDNode(const NamedMDNode *NMD);
void EnumerateValue(const Value *V);
void EnumerateType(const Type *T);
void EnumerateOperandType(const Value *V);

View File

@ -217,7 +217,7 @@ static SmallVector<WeakVH, 4> &getNMDOps(void *Operands) {
NamedMDNode::NamedMDNode(LLVMContext &C, StringRef N,
MDNode *const *MDs,
unsigned NumMDs, Module *ParentModule)
: MetadataBase(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
: Value(Type::getMetadataTy(C), Value::NamedMDNodeVal), Parent(0) {
setName(N);
Operands = new SmallVector<WeakVH, 4>();