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());
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.