Adding code after compilation


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:



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");
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!