<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:10pt"><div><span>Dear All LLVM Users,</span></div><div><span></span> </div><div><span>I'm new to LLVM environment. I want to perform basic block profiling. I'm using LLVM3.1</span></div><div><span>I tried it with a simple 'c' code to find Max.No,  mentioned below.</span></div><div><span>-----------------------------------------------------------------------------------------------------------------------------------------</span></div><div><span>#include <stdio.h></span></div><div><span>int main()<br>{<br> unsigned int i,temp;<br> <br> unsigned int num[50] = {25,35,66,789,999,23,0,1,24,44,100,20,50,1,37,299,400,900,255,1000,21,26,89,877,666,432,55,58,0,90,95,111,888,94,100,32,56,78,987,90,456,1234,95,45,25,97,99,34,56,23};<br>  <br> i = 0;<br> temp =
 0;<br> while(i<50) {  <span class="tab">    <span class="tab">    <span class="tab">    </span></span></span> /* FIND THE MAX NUM FROM THE ARRAY*/<br>   <span class="tab">    </span>if(num[i] > temp){<br><span class="tab">    <span class="tab">    </span></span>   temp = num[i];<br>  <span class="tab">    </span>}<br>  <span class="tab">    </span>i++;<br> }</span></div><div><span> printf("Max. Num. is : %d\n", temp);</span></div><div><span> return 0;<br>}</span></div><div><span>------------------------------------------------------------------------------------------------------------------------------------------------</span></div><div><span>However when I read llvmprof.out it produces following
 block frequencies.</span></div><div><span></span> </div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span>Top 20 most frequently executed basic blocks:</span></div><div><span> ##      %%  <span class="tab">    </span>Frequency<br>  1. 27.1429%    57/210 <span class="tab">    </span>main() - if.end<br>  2. 24.2857%    51/210 <span class="tab">    </span>main() - while.cond<br>  3. 23.8095%    50/210 <span class="tab">    </span>main() - while.body<br>  4. 20.4762%    43/210 <span class="tab">    </span>main() - while.body.if.end_crit_edge<br>  5. 3.33333%     7/210 <span
 class="tab">    </span>main() - if.then<br>  6. 0.47619%     1/210 <span class="tab">    </span>main() - entry<br>  7. 0.47619%     1/210 <span class="tab">    </span>main() - while.end</span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span>-----------------------------------------------------------------------------------------------------------------------------------------------</span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span></span> </div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color:
 transparent;"><span><strong>The problem is with Basic Block : if.end (first block). Why does it execute 57 times? The i++ is also part of this block. </strong></span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span><strong>This shows an inconsistent profiling information.</strong></span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span><strong></strong></span> </div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span><strong>Please, anyone help me to figure out where I'm doing wrong?</strong></span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif;
 font-size: 13.33px; font-style: normal; background-color: transparent;"><span><span>----------------------------------------------------------------------------------------------------------------------------------------------</span></div></span><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span>Following commands are used for this profiling.</span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span></span> </div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color: transparent;"><span><a href="mailto:rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$">rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$</a> clang -O0
 -emit-llvm -c -otest1.o test1.c<br><a href="mailto:rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$">rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$</a> opt -disable-opt -insert-edge-profiling -o test1.o.inst test1.o<br><a href="mailto:rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$">rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$</a> lli -O0 -fake-argv0 'test1.o' -load /home/rdpatel55/RDPATEL/LLVM3.1/LLVM_INSTALL_ROOT/lib/libprofile_rt.so test1.o.inst<br>Max. Num. is : 1234 (This is the o/p of the program)<br><a href="mailto:rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$">rdpatel55@ubuntu:~/RDPATEL/LLVM3.1/RDSampleCode/test$</a> llvm-prof --print-all-code test1.o.inst > bb_all.txt</span></div><div style="color: rgb(0, 0, 0); font-family: times new roman, new york, times, serif; font-size: 13.33px; font-style: normal; background-color:
 transparent;">---------------------------------------------------------------------------------------------------------------------------------------------------------</div><div>R.D.PATEL<br>Research Scholar,E.C.E. Department<br>MANIT, Bhopal<br>M:(91)8085090402, H:(91)8602677554</div></div></body></html>