I’m using llvm 3.3,which was built with the options below:
…/llvm-3.3.src/configure --prefix=/home/admin/jianzhang.zj/llvm/llvm-install-2/ --with-gcc-toolchain=/home/admin/jianzhang.zj/gcc-4.8.2-install/ --enable-optimized --enable-debug-runtime --enable-debug-symbols --disable-assertions --with-oprofile=/home/admin/jianzhang.zj/oprofile-0.9.9-install/ --enable-profiling --with-intel-jitevents
The oprofile’s version is 0.99
I’m using the following Makefile to build the Fibonacci examples in the llvm source code:
LLVM_CONFIG=/home/admin/jianzhang.zj/llvm/llvm-install-2/bin/llvm-config
CLANG=/home/admin/jianzhang.zj/llvm/llvm-install-2/bin/clang
SRC_IDR=$(PWD)
LLVM_FLAGS=$(shell $(LLVM_CONFIG) --cxxflags --cppflags --ldflags --ldflags --libs )
COMMON_FLAGS= -DTEST -DMCJIT -g -rdynamic -O3 -lpthread -ldl
SRC_DIR = .
INCLUDE = -I/home/admin/jianzhang.zj/llvm/llvm-install-2/include/
CXX=g++
PROGRAM= fibonacci
all: clean output
output: $(PROGRAM)
$(PROGRAM):
$(CXX) $@.cpp $(INCLUDE) -o $@ $(COMMON_FLAGS) $(LLVM_FLAGS) -fexceptions
clean:
rm -f $(PROGRAM) *.o LOG
then I use the operf command to sampling:
$ /home/admin/jianzhang.zj/oprofile-0.9.9-install/bin/operf ./fibonacci 40
operf: Profiler started
verifying… OK
We just constructed this LLVM module:; ModuleID = ‘test’
define i32 @fib(i32 %AnArg) {
EntryBlock:
%cond = icmp sle i32 %AnArg, 2
br i1 %cond, label %return, label %recurse
return: ; preds = %EntryBlock
ret i32 1
recurse: ; preds = %EntryBlock
%arg = sub i32 %AnArg, 1
%fibx1 = tail call i32 @fib(i32 %arg)
%arg1 = sub i32 %AnArg, 2
%fibx2 = tail call i32 @fib(i32 %arg1)
%addresult = add i32 %fibx1, %fibx2
ret i32 %addresult
}starting fibonacci(40) with JIT…
Result: 102334155
Profiling done.
then use opreport:
$ /home/admin/jianzhang.zj/oprofile-0.9.9-install/bin/opreport
Using /apsarapangu/disk8/jianzhang.zj/llvm/llvm-3.3.src/examples/Fibonacci/oprofile_data/samples/ for samples directory.
CPU: Intel Sandy Bridge microarchitecture, speed 2199.75 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
CPU_CLK_UNHALT…|
samples> % 16252 100.000 fibonacci CPU_CLK_UNHALT… samples> %
15368 94.5607 anon (tgid:60546 range:0x7faa17b40000-0x7faa17bbffff)
656 4.0364 no-vmlinux
139 0.8553 libc-2.5.so
54 0.3323 fibonacci
33 0.2031 ld-2.5.so
2 0.0123 libstdc++.so.6.0.8
here the ‘anon (tgid:60546 range:0x7faa17b40000-0x7faa17bbffff)’ isn’t the result I expected, so I think there must be something wrong and I use the ldd command to check the dependencies:
$ ldd fibonacci
linux-vdso.so.1 => (0x00007fffcd1ba000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00000031edc00000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000031ed800000)
libz.so.1 => /lib64/libz.so.1 (0x00000031ee400000)
librt.so.1 => /lib64/librt.so.1 (0x00000031ef000000)
libopagent.so.1 => /home/admin/jianzhang.zj/oprofile-0.9.9-install//lib/oprofile/libopagent.so.1 (0x00007fb835b86000)
libm.so.6 => /lib64/libm.so.6 (0x00000031ee000000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000031f3000000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00000031f0800000)
libc.so.6 => /lib64/libc.so.6 (0x00000031ed400000)
/lib64/ld-linux-x86-64.so.2 (0x00000031ed000000)
libbfd-2.24.so => /home/admin/jianzhang.zj/binutils-2.24-install/lib/libbfd-2.24.so (0x00007fb83587b000)
libiberty.so => /home/admin/jianzhang.zj/binutils-2.24-install/lib/libiberty.so (0x00007fb83563e000)$ ldd -u fibonacci
Unused direct dependencies:/lib64/libdl.so.2
/lib64/libz.so.1
/lib64/librt.so.1
/home/admin/jianzhang.zj/oprofile-0.9.9-install//lib/oprofile/libopagent.so.1
can anyone tell me how to profile the llvm JITed code or which step was wrong ?
thanks very much.