<div dir="ltr">Hi Andreas,<br><br>Many thanks for the below detailed reply, i will try to follow the below steps and contact you if i have any problems.<br><br>Thanks again.<br><br>BR,<br>Ahmed Raafat.<br><br><div class="gmail_quote">
On Wed, Nov 4, 2009 at 4:20 PM, Andreas Neustifter <span dir="ltr"><<a href="mailto:astifter-llvm@gmx.at">astifter-llvm@gmx.at</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Ahmed!<div class="im"><br>
<br>
Adventure wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>

</blockquote>
<br></div>
(In the following instructions you have to insert your own values for the <...> stuff.)<br>
<br>
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<br>
<br>
$> llvm-gcc -emit-llvm -c <sourcefile> -o <sourcefile>.bc<br>
<br>
and then link them all together<br>
<br>
$> llvm-ld -stats -time-passes -link-as-library -disable-opt *.bc -o <executable>.1.bc<br>
<br>
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.<br>
<br>
<br>
<br>
Now its time to instrument the code, I do this by running<br>
<br>
$> opt -stats -time-passes -insert-optimal-edge-profiling <executable>.1.bc -o <executable>.2.bc<br>
<br>
and add the profiling runtime support<br>
<br>
$> 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<br>
<br>
<br>
<br>
You can then create a native executable by<br>
<br>
$> llc <executable>.3.bc <executable>.s<br>
$> gcc -g <executable>.s -o <executable><br>
<br>
<br>
<br>
When you run this executable (with your parameters) it creates a file called llvmprof.out which contains an edge profiling of your code. With<br>
<br>
$> llvm-prof -print-all-code <executable>.1.bc<br>
<br>
you can dump a bytecode file which is annotated with the recorded profiling information.<br>
<br>
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.<br>
<br>
<br>
<br>
There is a tool in <source tree>/utils/<a href="http://profile.pl" target="_blank">profile.pl</a> 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.<br>

<br>
Andi<br>
</blockquote></div><br></div>