//===- CloneModule.cpp - Clone an entire module ---------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the CloneModule interface which makes a copy of an // entire module. // //===----------------------------------------------------------------------===// #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Module.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/ValueMapper.h" usingnamespacellvm; namespace llvm { class Constant; } static void copyComdat(GlobalObject *Dst, const GlobalObject *Src) { … } /// This is not as easy as it might seem because we have to worry about making /// copies of global variables and functions, and making their (initializers and /// references, respectively) refer to the right globals. /// /// Cloning un-materialized modules is not currently supported, so any /// modules initialized via lazy loading should be materialized before cloning std::unique_ptr<Module> llvm::CloneModule(const Module &M) { … } std::unique_ptr<Module> llvm::CloneModule(const Module &M, ValueToValueMapTy &VMap) { … } std::unique_ptr<Module> llvm::CloneModule( const Module &M, ValueToValueMapTy &VMap, function_ref<bool(const GlobalValue *)> ShouldCloneDefinition) { … } extern "C" { LLVMModuleRef LLVMCloneModule(LLVMModuleRef M) { … } }