aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Metadata.h7
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.cpp32
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.h2
-rw-r--r--lib/VMCore/Metadata.cpp2
4 files changed, 28 insertions, 15 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index 87fe17c..4d4e499 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -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;
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>();