JIT : Does it cache the compiled code of executed functions upon runFunction(..)?

Hello
I have the following scenario, and I am not sure why the performance
is so bad (take 30 minutes to complete with very simple generated
functions):

1. Create module
2. Do something like EE =
EngineBuilder(theModule).setEngineKind(EngineKind::JIT).create();
3. Create a function in the module: theModule->getOrInsertFunction(..)
4. Execute 1000 times the function using EE->runFunction(function,
args) with different args in each round.

My question - Does section 4 above makes the EE recompile the function
1000 times? If no, why is the performance is so bad? what am I doing
wrong ? Maybe I should somehow cache the function's binary code?

llvm-version 2.7
OS: Linux 2.6.31 64 bits (intel dual core, 4GB memory)

Hi Gabi,

I have no idea why your performances is not as expected with such low level of informations.

But, I know that the binary code is cached by the JIT. You can find the code in JIT.cpp to convince yourself :
runFunction → getPointerToFunction ->getPointerToGlobalIfAvailable which returns the native address of the jitted function.

You can even try to measure time needed by each runFunction to run to double-convince yourself. :slight_smile:

Olivier.

Sure, it caches the code for the function you're calling, but because
the JIT doesn't want to get involved in target specific calling
conventions, it codegens a little entry point if your function
prototype is unfamiliar. I think this is NOT cached, which is why you
have slow code. If you statically know your function prototype, I
recommend calling getPointerToFunction and casting the return function
pointer to the right type and calling it directly from your code.
This forces your (static) compiler to generate the right code for the
calling convention.

Reid