JIT compilation with LLVM

Hello LLVM developers,

I am developing a small project using LLVM. The objective is to provide dynamic loading via JIT compilation of C++ code contained in a (TS) module. For this reason, I would like to return an explicitly raw void pointer (resembling libdl’s void *dlsym(void *, char const *); as closely as possible) to the compiled result. The MCJIT class offers the most convenient API for me, but I’m not sure it is intended for public use as it is not in the include path in a LLVM installation, even when built from source (I am building from the git repo); neither is OrcMCJITReplacement.

What is the way that you would suggest to use LLVM’s JIT capabilities? It would already help a lot if I knew which function/class names to look up.

Thank you in advance for your attention,

I am developing a small project using LLVM. The objective is to
provide dynamic loading via JIT compilation of C++ code contained in
a (TS) module. For this reason, I would like to return an explicitly
raw void pointer (resembling libdl's `void *dlsym(void *, char const
*);` as closely as possible) to the compiled result. The MCJIT class
offers the most convenient API for me, but I'm not sure it is
intended for public use as it is not in the include path in a LLVM
installation, even when built from source (I am building from the git
repo); neither is OrcMCJITReplacement. What is the way that you would
suggest to use LLVM's JIT capabilities? It would already help a lot
if I knew which function/class names to look up.

I guess, the best place to start is the tutorial[1]. This one is for
the ORC JIT API. I am not the right person to ask what the prefered API
for new projects is as I'm still quite new to all of this as well.

To get a function pointer, you have to resolve the symbol in the
generated code.

[1] https://llvm.org/docs/tutorial/BuildingAJIT1.html

Hi Daniel, Frank,

MCJIT is an ExecutionEngine implementation. You never get a direct pointer to it, instead you create one using an EngineBuilder and access it via the ExecutionEngine interface.

The LLJIT class (llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h) provides an alternative (non ExecutionEngine based) interface for basic JITing. You can find a usage example in llvm/examples/HowToUseLLJIT.

Finally, as Frank suggested, you can build your own JIT class out of ORC components by following the BuildingAJIT tutorial series. This series is (still) under development, but the initial chapters should be enough to build something with MCJIT’s capabilities.

Cheers,
Lang.