Hello everybody, I am a beginner in LLVM and need to know how to use LLVM to instrument a C program and execute this instrumented program with different test cases to determine the branch coverage information for each test case. Any suggestion or help is more than welcomed. Thanks in advance. Ahmed Raafat. -- View this message in context: http://old.nabble.com/Determine-branch-coverage-information-tp26141617p26141617.html Sent from the LLVM - Dev mailing list archive at Nabble.com. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091031/61b0904b/attachment.html>
Hi Ahmed! Adventure wrote:> Hello everybody, I am a beginner in LLVM and need to know how to use > LLVM to instrument a C program and execute this instrumented program > with different test cases to determine the branch coverage information > for each test case. Any suggestion or help is more than welcomed. Thanks > in advance. Ahmed Raafat.(In the following instructions you have to insert your own values for the <...> stuff.) To instrument the C Program you have to compile it into a single bytecode file, I do this by translating each C file to bytecode $> llvm-gcc -emit-llvm -c <sourcefile> -o <sourcefile>.bc and then link them all together $> llvm-ld -stats -time-passes -link-as-library -disable-opt *.bc -o <executable>.1.bc This gives you an unoptimised bytecode file which is preferable in this case since it retains a somewhat 1:1 relation to your code so you can figure out the results afterwards. Now its time to instrument the code, I do this by running $> opt -stats -time-passes -insert-optimal-edge-profiling <executable>.1.bc -o <executable>.2.bc and add the profiling runtime support $> llvm-ld -stats -time-passes -link-as-library -disable-opt <path to llvm install>/lib/libprofile_rt.bca <executable>.2.bc -o <executable>.3.bc You can then create a native executable by $> llc <executable>.3.bc <executable>.s $> gcc -g <executable>.s -o <executable> When you run this executable (with your parameters) it creates a file called llvmprof.out which contains an edge profiling of your code. With $> llvm-prof -print-all-code <executable>.1.bc you can dump a bytecode file which is annotated with the recorded profiling information. If you do several runs of your executable all runs are combined in the single llvmprof.out and the results are accumulated and you can check if every codepath was executed during your tests. There is a tool in <source tree>/utils/profile.pl which takes a single bytecode file and parameters and does all the work of instrumenting, running and executing llvm-prof in one go, but its a little outdated, I attached a newer version, but I guess its easier to write a script that does exactly the steps you need. YMMV. Andi -------------- next part -------------- A non-text attachment was scrubbed... Name: profile.pl Type: application/x-perl Size: 2862 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091104/ea0970e9/attachment.bin>
Hi Andreas, Many thanks for the below detailed reply, i will try to follow the below steps and contact you if i have any problems. Thanks again. BR, Ahmed Raafat. On Wed, Nov 4, 2009 at 4:20 PM, Andreas Neustifter <astifter-llvm at gmx.at>wrote:> Hi Ahmed! > > > Adventure wrote: > >> Hello everybody, I am a beginner in LLVM and need to know how to use LLVM >> to instrument a C program and execute this instrumented program with >> different test cases to determine the branch coverage information for each >> test case. Any suggestion or help is more than welcomed. Thanks in advance. >> Ahmed Raafat. >> > > (In the following instructions you have to insert your own values for the > <...> stuff.) > > To instrument the C Program you have to compile it into a single bytecode > file, I do this by translating each C file to bytecode > > $> llvm-gcc -emit-llvm -c <sourcefile> -o <sourcefile>.bc > > and then link them all together > > $> llvm-ld -stats -time-passes -link-as-library -disable-opt *.bc -o > <executable>.1.bc > > This gives you an unoptimised bytecode file which is preferable in this > case since it retains a somewhat 1:1 relation to your code so you can figure > out the results afterwards. > > > > Now its time to instrument the code, I do this by running > > $> opt -stats -time-passes -insert-optimal-edge-profiling <executable>.1.bc > -o <executable>.2.bc > > and add the profiling runtime support > > $> llvm-ld -stats -time-passes -link-as-library -disable-opt <path to llvm > install>/lib/libprofile_rt.bca <executable>.2.bc -o <executable>.3.bc > > > > You can then create a native executable by > > $> llc <executable>.3.bc <executable>.s > $> gcc -g <executable>.s -o <executable> > > > > When you run this executable (with your parameters) it creates a file > called llvmprof.out which contains an edge profiling of your code. With > > $> llvm-prof -print-all-code <executable>.1.bc > > you can dump a bytecode file which is annotated with the recorded profiling > information. > > If you do several runs of your executable all runs are combined in the > single llvmprof.out and the results are accumulated and you can check if > every codepath was executed during your tests. > > > > There is a tool in <source tree>/utils/profile.pl which takes a single > bytecode file and parameters and does all the work of instrumenting, running > and executing llvm-prof in one go, but its a little outdated, I attached a > newer version, but I guess its easier to write a script that does exactly > the steps you need. YMMV. > > Andi >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091120/e4ab678f/attachment.html>
Maybe Matching Threads
- [LLVMdev] Determine branch coverage information
- [LLVMdev] how to get path profile information ?
- [LLVMdev] how to get path profile information ?
- Trouble implementing ov_callbacks, endless loop calling seek_func
- [LLVMdev] Dynamic Profiling - Instrumentation basic query