diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/Transforms/Utils/CloneModule.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'lib/Transforms/Utils/CloneModule.cpp')
-rw-r--r-- | lib/Transforms/Utils/CloneModule.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index 8fee10854229..35c7511a24b9 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -32,33 +32,34 @@ static void copyComdat(GlobalObject *Dst, const GlobalObject *Src) { /// copies of global variables and functions, and making their (initializers and /// references, respectively) refer to the right globals. /// -std::unique_ptr<Module> llvm::CloneModule(const Module *M) { +std::unique_ptr<Module> llvm::CloneModule(const Module &M) { // Create the value map that maps things from the old module over to the new // module. ValueToValueMapTy VMap; return CloneModule(M, VMap); } -std::unique_ptr<Module> llvm::CloneModule(const Module *M, +std::unique_ptr<Module> llvm::CloneModule(const Module &M, ValueToValueMapTy &VMap) { return CloneModule(M, VMap, [](const GlobalValue *GV) { return true; }); } std::unique_ptr<Module> llvm::CloneModule( - const Module *M, ValueToValueMapTy &VMap, + const Module &M, ValueToValueMapTy &VMap, function_ref<bool(const GlobalValue *)> ShouldCloneDefinition) { // First off, we need to create the new module. std::unique_ptr<Module> New = - llvm::make_unique<Module>(M->getModuleIdentifier(), M->getContext()); - New->setDataLayout(M->getDataLayout()); - New->setTargetTriple(M->getTargetTriple()); - New->setModuleInlineAsm(M->getModuleInlineAsm()); - + llvm::make_unique<Module>(M.getModuleIdentifier(), M.getContext()); + New->setSourceFileName(M.getSourceFileName()); + New->setDataLayout(M.getDataLayout()); + New->setTargetTriple(M.getTargetTriple()); + New->setModuleInlineAsm(M.getModuleInlineAsm()); + // Loop over all of the global variables, making corresponding globals in the // new module. Here we add them to the VMap and to the new Module. We // don't worry about attributes or initializers, they will come later. // - for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); + for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { GlobalVariable *GV = new GlobalVariable(*New, I->getValueType(), @@ -72,7 +73,7 @@ std::unique_ptr<Module> llvm::CloneModule( } // Loop over the functions in the module, making external functions as before - for (const Function &I : *M) { + for (const Function &I : M) { Function *NF = Function::Create(cast<FunctionType>(I.getValueType()), I.getLinkage(), I.getName(), New.get()); NF->copyAttributesFrom(&I); @@ -80,7 +81,7 @@ std::unique_ptr<Module> llvm::CloneModule( } // Loop over the aliases in the module - for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); + for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; ++I) { if (!ShouldCloneDefinition(&*I)) { // An alias cannot act as an external reference, so we need to create @@ -114,7 +115,7 @@ std::unique_ptr<Module> llvm::CloneModule( // have been created, loop through and copy the global variable referrers // over... We also set the attributes on the global now. // - for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); + for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { if (I->isDeclaration()) continue; @@ -139,7 +140,7 @@ std::unique_ptr<Module> llvm::CloneModule( // Similarly, copy over function bodies now... // - for (const Function &I : *M) { + for (const Function &I : M) { if (I.isDeclaration()) continue; @@ -169,7 +170,7 @@ std::unique_ptr<Module> llvm::CloneModule( } // And aliases - for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); + for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; ++I) { // We already dealt with undefined aliases above. if (!ShouldCloneDefinition(&*I)) @@ -180,8 +181,9 @@ std::unique_ptr<Module> llvm::CloneModule( } // And named metadata.... - for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), - E = M->named_metadata_end(); I != E; ++I) { + for (Module::const_named_metadata_iterator I = M.named_metadata_begin(), + E = M.named_metadata_end(); + I != E; ++I) { const NamedMDNode &NMD = *I; NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName()); for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i) @@ -194,7 +196,7 @@ std::unique_ptr<Module> llvm::CloneModule( extern "C" { LLVMModuleRef LLVMCloneModule(LLVMModuleRef M) { - return wrap(CloneModule(unwrap(M)).release()); + return wrap(CloneModule(*unwrap(M)).release()); } } |