The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. The LLVM Core libraries provide a modern source- and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones). Hypercalls are a way to transfer execution from the program being executed to the LLVM infrastructure to perform re-compilation. But currently, there is no methodology to perform hypercalls into LLVM. The goal of this project is to cleanly integrate an API into the LLVM code/execution engine to create custom callbacks.

Please find a detailed overview here.

How to add a new Custom Callback into LLI? Here are the steps needed to be taken:

  • Suppose, I want to register a function named Callback1 which takes two integers as its parameters. In lli.cpp in main(), define the function Callback1 and register it as follows:

EE->registerCustomCallback(“Callback1?, (reinterpret_cast<void*(*)()>(&Callback1)));

  • The user programs have to include the header file of the dummy library to get the PerformCustomCallback symbol. To make a hypercall to “Callback1?, do the following:

struct arg {
int arg1;
int arg2;
}Arg;
Arg.arg1 = 10;
Arg.arg2 = 20;
PerformCustomCallback(“Callback1″, &Arg);

  • Compile the user program (test.cc) using clang as follows:

# clang -c -emit-llvm `llvm-config –cppflags` -o test test.cc `llvm-config –libs` `llvm-config –ldflags` -lLLVMCustomCallback.

When the bitcode generated is run using lli, the Callback1() will be called.

Please find the diffs for LLVM3.3 LLVM_trunk.