Using JIT compilation for direct execution
Running LLVM IR directly is the first idea that comes to mind when thinking about a JIT compiler. This is what the lli
tool, the LLVM interpreter, and the dynamic compiler do. We will explore the lli
tool in the next section.
Exploring the lli tool
Let’s try the lli
tool with a very simple example. The following LLVM IR can be stored as a file called hello.ll
, which is the equivalent of a C hello world application. This file declares a prototype for the printf()
function from the C library. The hellostr
constant contains the message to be printed. Inside the main()
function, a call to the printf()
function is generated, and this function contains a hellostr
message that will be printed. The application always returns 0
.
The complete source code is as follows:
declare i32 @printf(ptr, ...) @hellostr = private unnamed_addr constant [13 x i8] c"Hello world\0A\00" define dso_local i32 @main(i32 %argc, ptr %argv) {...