From 3bf329f49512e633df430c097bfd5bdaa122ba55 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 22 Jun 2010 22:50:42 +0000 Subject: [PATCH] While cloning a module, clone metadata attached with instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106591 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/CloneModule.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index 1809bbb3201..38c5877657a 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -133,6 +133,21 @@ Module *llvm::CloneModule(const Module *M, NamedMDNode::Create(New->getContext(), NMD.getName(), MDs.data(), MDs.size(), New); } - + + // Update metadata attach with instructions. + for (Module::iterator MI = New->begin(), ME = New->end(); MI != ME; ++MI) + for (Function::iterator FI = MI->begin(), FE = MI->end(); + FI != FE; ++FI) + for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); + BI != BE; ++BI) { + SmallVector, 4 > MDs; + BI->getAllMetadata(MDs); + for (SmallVector, 4>::iterator + MDI = MDs.begin(), MDE = MDs.end(); MDI != MDE; ++MDI) { + Value *MappedValue = MapValue(MDI->second, ValueMap); + if (MDI->second != MappedValue && MappedValue) + BI->setMetadata(MDI->first, cast(MappedValue)); + } + } return New; }