This is an archive of the discontinued LLVM Phabricator instance.

CloneModule: add an option for a custom LLVMContext
AbandonedPublic

Authored by AlexDenisov on Mar 15 2017, 2:40 PM.

Details

Reviewers
pcc
Summary

The patch adds another parameter to the CloneModule family so that one can create a clone of a module using custom context.

Here is a bit of motivation and our use case: we create hundreds (sometimes thousands) of clones during program execution. If we create them using the context of an original module, then all those clones reside in memory until the very end of a program (when the 'global' context destructed).

Diff Detail

Event Timeline

AlexDenisov created this revision.Mar 15 2017, 2:40 PM
pcc edited edge metadata.Mar 15 2017, 2:45 PM

Does this really work? I believe that with this the original and the cloned module will share things like types, which is a violation of the invariant that LLVM IR objects must not be shared between contexts.

When I needed to clone a module into another LLVMContext, I could not see a better way to do it than to serialize it to bitcode and deserialize it into the new LLVMContext (see http://llvm-cs.pcc.me.uk/lib/CodeGen/ParallelCG.cpp).

Does this really work? I believe that with this the original and the cloned module will share things like types, which is a violation of the invariant that LLVM IR objects must not be shared between contexts.

Well, it works in our case, but now I see that it may have a problem in other cases.

When I needed to clone a module into another LLVMContext, I could not see a better way to do it than to serialize it to bitcode and deserialize it into the new LLVMContext (see http://llvm-cs.pcc.me.uk/lib/CodeGen/ParallelCG.cpp).

This is a good idea. I think we must go the same way.

Thank you for your hint and the fast response :)

AlexDenisov abandoned this revision.Mar 15 2017, 2:58 PM