LLVM JIT Compilation

ok i have managed to compile using lli (jit) as follows: but i dont get assembly file?

my sum-main.c file is:

#include <stdio.h>
#include<stdlib.h>
int sum(int a, int b) {
return a + b;
}
int main(int argc, char** argv) {
printf(“sum: %d\n”, sum(atoi(argv[1]), atoi(argv[2])) + sum(atoi(argv[1]), atoi(argv[2])));
return 0;
}

and i used the following steps to compile.
clang -S -emit-llvm sum-main.c -o sum-main.ll

lli sum-main.ll 5 2

it gives 7. i believe that it is compiling at run time.

now how to obtain assembly file generated at run time. and do a detailed debugging of this code.

please help.

ok i have managed to compile using lli (jit) as follows: but i dont get
assembly file?

lli doesn't produce assembly files, that's llc's job. lli creates an
object file in memory and runs a function from it.

now how to obtain assembly file generated at run time. and do a detailed
debugging of this code.

To debug it I'd put a breakpoint where lli.cpp actually starts
executing the code (looks like a call to "runFunctionAsMain") and keep
going from there.

Cheers.

Tim.

Adding llvm-dev back...

Isnt there any way to check the assembly. Like if my opt does loop
vectorization, then backend should emit avx instructions. So those
instructions generation / mapping procedure is same as llc for lli as well?

There's a -debug option that'll print out the instructions in some
form. But printing its output isn't what lli is designed for, that's
llc's job.

Means does lli also use same x86registerinfo.td, x86 instructioninfo.td, and
x86 isellowering.cpp files for code emission? Also does it follow the same
complete backend chain containing instruction selection, register
allocation, instruction scheduling and code emission respectively?

Yes to both of those.

Cheers.

Tim.

Hi Harmeeza

On 16 August 2017 at 12:05, hameeza ahmed via llvm-dev

now how to obtain assembly file generated at run time. and do a detailed
debugging of this code.

Debugging JITed code can be hairy. I think atm it's only supported for
ELF object files on Linux. If you really want to do that, you could
follow this guide:
https://llvm.org/docs/DebuggingJITedCode.html

It should work if you pass -jit-kind=mcjit (the guide mentions the old
flag -use-mcjit) to use the "old" monolithic MCJIT.
For an ORC-based JIT you need to implement the GDB JIT Interface
yourself. I have an example for this on GitHub:
https://github.com/weliveindetail/JitFromScratch/tree/jit-debug/gdb-interface

There is also another example that shows how to implement your own
optimization chain in a ORC-Jit and dump raw vs. optimized IR code:
https://github.com/weliveindetail/JitFromScratch/tree/jit-optimization

Cheers
Stefan

Thanks alot. i need to use JIT to perform operations on user input file supplied at run time using vector instructions. is it possible and achievable through JIT?

please help.