[llvm-dev] Cloning a function from one module to another module

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Cloning a function from one module to another module

Sam McCall via llvm-dev
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
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Cloning a function from one module to another module

Sam McCall via llvm-dev
On Wed, Jun 13, 2018 at 10:31:59AM +0100, James Courtier-Dutton via llvm-dev wrote:

> 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.

You can probably use llvm::Linker::linkInModule to do the merging,it
takes care of the types and deps and such.
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev