Two ExecutionEngines from one Module

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

Two ExecutionEngines from one Module

Chuck Rose III
Hello everybody,

I'm pretty new to LLVM programming, so if this answer is pretty simple,
I apologize in advance.  We are working with the released LLVM 1.9.

Say you have a class called CompiledProgram which is designed to contain
our Module and (potentially) our ExecutionEngine(s).  In particular, I
would like to have an ExecutionEngine for running our program natively
and another for running via the interpreter.  It is the ability to have
both flavors of execution that is causing me grief.  Given a Module
pointer, module, here's the scenario:

        CompiledProgram* program = new CompiledProgram(module);

Inside our CompiledProgram object, we might want to do this:

        this->interpretedEE =
llvm::ExecutionEngine::create(this->module,true);

Ownership of the module will transfer to the interpretedEE at this
point.  Fair enough because we've got this all buttoned up in a class
and we can handle the various orders of takedown.

Later, I'd like to make a native one:

        this->nativeEE = llvm::ExecutionEngine::create(???,false);

and at this point I'm in a seeming catch-22.  I can't use the same
module (I believe) to construct the second ExecutionEngine since
ownership of the module is already in the first one.  Zooming around the
class hierarchy didn't seem to yield a good way to do a deep copy on a
Module, which I could have done before constructing any given
ExecutionEngine and thus sidestep the ownership issue.  There doesn't
seem to be a way to release a module from an ExecutionEngine once it's
there, which would also give me a solution.  

I figure it's time to ask and say hi to my fellow LLVMers.  Do you have
any advice on how to handle this situation?

Thanks,
Chuck.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Two ExecutionEngines from one Module

Chris Lattner
On Fri, 30 Mar 2007, Chuck Rose III wrote:
> and at this point I'm in a seeming catch-22.  I can't use the same
> module (I believe) to construct the second ExecutionEngine since
> ownership of the module is already in the first one.

Right, the LLVM ExecutionEngine stuff has been designed with the
assumption you'd only need one :)

> Zooming around the
> class hierarchy didn't seem to yield a good way to do a deep copy on a
> Module, which I could have done before constructing any given
> ExecutionEngine and thus sidestep the ownership issue.

If copying the module is acceptable, check out
llvm/Transforms/Utils/Cloning.h

CloneModule(M);

Which does a deep copy of the module.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev