Add a CloneModule call that exposes the mapping of values from the old module
authorChris Lattner <sabre@nondot.org>
Wed, 17 May 2006 18:05:35 +0000 (18:05 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 17 May 2006 18:05:35 +0000 (18:05 +0000)
to the new module.  Patch provided by Nick Lewycky!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28349 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Utils/Cloning.h
lib/Transforms/Utils/CloneModule.cpp

index f721ea900d7e9b2d0be2fb52e398e4c2f5da23c1..4560c7286273e82b6c2b56740ec57e8720a3ce58 100644 (file)
@@ -37,6 +37,7 @@ class CallGraph;
 /// CloneModule - Return an exact copy of the specified module
 ///
 Module *CloneModule(const Module *M);
+Module *CloneModule(const Module *M, std::map<const Value*, Value*> &ValueMap);
 
 /// ClonedCodeInfo - This struct can be used to capture information about code
 /// being cloned, while it is being cloned.
index a872551eeae364c61a6bd6d6a198f90f634e058d..229debf19801b932527b48277aac37eb1468bcf6 100644 (file)
@@ -26,6 +26,14 @@ using namespace llvm;
 /// respectively) refer to the right globals.
 ///
 Module *llvm::CloneModule(const Module *M) {
+  // Create the value map that maps things from the old module over to the new
+  // module.
+  std::map<const Value*, Value*> ValueMap;
+
+  return CloneModule(M, ValueMap);
+}
+
+Module *llvm::CloneModule(const Module *M, std::map<const Value*, Value*> &ValueMap) {
   // First off, we need to create the new module...
   Module *New = new Module(M->getModuleIdentifier());
   New->setEndianness(M->getEndianness());
@@ -44,10 +52,6 @@ Module *llvm::CloneModule(const Module *M) {
   for (Module::lib_iterator I = M->lib_begin(), E = M->lib_end(); I != E; ++I)
     New->addLibrary(*I);
 
-  // Create the value map that maps things from the old module over to the new
-  // module.
-  std::map<const Value*, Value*> ValueMap;
-
   // Loop over all of the global variables, making corresponding globals in the
   // new module.  Here we add them to the ValueMap and to the new Module.  We
   // don't worry about attributes or initializers, they will come later.