+/// EnumerateNamedMetadata - Insert all of the values referenced by
+/// named metadata in the specified module.
+void ValueEnumerator::EnumerateNamedMetadata(const Module *M) {
+ for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
+ E = M->named_metadata_end(); I != E; ++I)
+ EnumerateNamedMDNode(I);
+}
+
+void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) {
+ for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i)
+ if (MDNode *E = MD->getOperand(i))
+ EnumerateValue(E);
+}
+
+void ValueEnumerator::EnumerateMetadata(const Value *MD) {
+ assert((isa<MDNode>(MD) || isa<MDString>(MD)) && "Invalid metadata kind");
+ // 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());
+
+ if (const MDNode *N = dyn_cast<MDNode>(MD)) {
+ MDValues.push_back(std::make_pair(MD, 1U));
+ MDValueMap[MD] = MDValues.size();
+ MDValueID = MDValues.size();
+ for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
+ if (Value *V = N->getOperand(i))
+ EnumerateValue(V);
+ else
+ EnumerateType(Type::getVoidTy(MD->getContext()));
+ }
+ if (N->isFunctionLocal() && N->getFunction())
+ FunctionLocalMDs.push_back(N);
+ return;
+ }