[LLVMdev] Adding code after compilation

Will Dietz willdtz at gmail.com
Sun Jun 17 13:27:20 PDT 2012


On Sun, Jun 17, 2012 at 6:43 AM,  <Eran.Weiss at emc.com> wrote:
> Hi,
>
> I want to be able add a function to a module after it is (partly) compiled
> in JIT. Let's say we have these functions:
>
> Foo()
> {
> Stuff;
> }
>
> Bar()
> {
> Foo();
> MoreStuff;
> }
>
> I want to have a module with Foo optimized and have a callable pointer to
> Foo. Later, I want to generate Bar, optimize it (so Foo is inlined) and than
> get a callable pointer to Bar.
> Is this possible?
> If so, is there a way to run the optimizer so it will only process Bar,
> taking less time?
>

It's been a while since I've played with LLVM's JIT, but you might want to try:

GlobalValue *FooGV = MyModule->getNamedValue("Foo");
assert(FooGV);
MyExecutionEngine->addGlobalMapping(FooGV, &Foo);

or similar.

In other words, explicitly tell the JIT about the location of various
globals that already exist and it will use that address instead of
trying to emit code for them.

As for inlining it, I'm not sure of the best way to *guarantee* Foo
gets inlined into Bar(); if the JIT isn't doing what you want you
might want to play with the AlwaysInline function attribute or
coercing an InlinerPass instance to do what you want.

Hope this helps and good luck!

~Will



More information about the llvm-dev mailing list