JIT, FFI

Hello, I’m new to LLVM and I had a question about it: when we call the JIT::runFunction, since llvm doesn’t has a full FFI, there are some cases in which the JIT needs to codegen a stub function to call the function we are interested, my question is: this stub function will remains in the module until when ? What are the most efficient way to remove it from the module and memory ? For a little quantity of calls this doesn’t matter, but when I call a function using “runFunction” let’s say 100 times with differente arguments, it will create 100 function stubs.

Thank you !

Ouch, I see what you mean. It seems this bug can be fixed by freeing
the stub function and it's associated machine code before returning
from runFunction. You should file a PR about it.

Reid

You're right, that probably won't have very good performance. What we
(unladen-swallow) do is to call getPointerToFunction which gives a
function pointer of type (void*)(void*) which we then cast to the
appropriate function type and then call from C/C++. That way the
C/C++ compiler for your application can codegen the function call once
instead having the JIT do it many times.

Reid