Cloning a function from one module to another module

Hi,

Say I have loaded two .bc files into memory so that I have 2 modules.
How could I clone a function from one module into the other module.

I have looked at:
Function *CloneFunction(Function *F, ValueToValueMapTy &VMap,
  ClonedCodeInfo *CodeInfo = nullptr);

But I think that only clones within the same Module, not between modules.
I believe the clone between modules will take more effort, because all
the associated types will need to also be cloned if they are not
already in the destination module.

I can implement this myself, but I wished to check that it had not
already been done before.

Kind Regards

James

You can probably use llvm::Linker::linkInModule to do the merging,it
takes care of the types and deps and such.