diff options
author | Devang Patel <dpatel@apple.com> | 2010-01-09 00:30:14 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-01-09 00:30:14 +0000 |
commit | 8fba578be72dc98497508dec053e966858571f6a (patch) | |
tree | ae6580b90b2edd97b6cf943ec47874da9e629c34 /lib | |
parent | 54e146b935123d3d325e8eb30c2e1f2eca3377ac (diff) | |
download | external_llvm-8fba578be72dc98497508dec053e966858571f6a.zip external_llvm-8fba578be72dc98497508dec053e966858571f6a.tar.gz external_llvm-8fba578be72dc98497508dec053e966858571f6a.tar.bz2 |
Derive NamedMDNode from Value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93032 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 32 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.h | 2 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 2 |
3 files changed, 25 insertions, 11 deletions
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 54bf84d..f2b289d 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -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]; diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index a1b188e..c50fe9c 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -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); diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 6cc1e1b..87ffaff 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -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>(); |