This tool performs 3 things:
- Basic execution information including the number of LLVM instructions, basic blocks etc.
- Expensive instruction information like the number of memory operations, multiplications and branches since they are most likely to affect execution time.
- Function call information: the number of times each function is called.
Build:
$ cd llvm_profiling
$ mkdir build
$ cd build
$ cmake ..
$ make
$ cd ..
Run:
$ clang -S -emit-llvm -Xclang -disable-O0-optnone foo.c
The -Xclang -disable-O0-optnone
flag ensures that Clang will allow later optimizations even when initially compiling without any.
The line above will generate foo.ll
LLVM IR. We'll run our LLVM profiling pass on this IR and generate foo2.ll
using the line below:
$ opt -load build/skeleton/libSkeletonPass.* -skeleton -S foo.ll > foo2.ll
Now that we have the transformed IR we can go ahead and compile and run it using clang:
$ clang foo2.ll
$ ./a.out