Make NamedMDNode not be a subclass of Value, and simplify the interface
[oota-llvm.git] / lib / Transforms / Utils / CloneModule.cpp
index cdc9b46979fbfea4c6c731708502c419cc7066db..1b9bb89057e5dc28f2ee7f2a89c2d67c8e0cd326 100644 (file)
@@ -28,12 +28,12 @@ using namespace llvm;
 Module *llvm::CloneModule(const Module *M) {
   // Create the value map that maps things from the old module over to the new
   // module.
-  DenseMap<const Value*, Value*> VMap;
+  ValueToValueMapTy VMap;
   return CloneModule(M, VMap);
 }
 
 Module *llvm::CloneModule(const Module *M,
-                          DenseMap<const Value*, Value*> &VMap) {
+                          ValueToValueMapTy &VMap) {
   // First off, we need to create the new module...
   Module *New = new Module(M->getModuleIdentifier(), M->getContext());
   New->setDataLayout(M->getDataLayout());
@@ -127,11 +127,9 @@ Module *llvm::CloneModule(const Module *M,
   for (Module::const_named_metadata_iterator I = M->named_metadata_begin(),
          E = M->named_metadata_end(); I != E; ++I) {
     const NamedMDNode &NMD = *I;
-    SmallVector<MDNode*, 4> MDs;
+    NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
     for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
-      MDs.push_back(cast<MDNode>(MapValue(NMD.getOperand(i), VMap)));
-    NamedMDNode::Create(New->getContext(), NMD.getName(),
-                        MDs.data(), MDs.size(), New);
+      NewNMD->addOperand(cast<MDNode>(MapValue(NMD.getOperand(i), VMap)));
   }
 
   // Update metadata attach with instructions.