<div dir="ltr">I forgot to mention that I'm using LLVM 5.0.<br><br>Is the problem something that was fixed post LLVM 5.0?<div><br></div><div><br></div><div><br></div><div>Thank you.</div><div><br></div><div>Regards,</div><div>Malhar</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 15, 2018 at 5:14 PM, Xinliang David Li <span dir="ltr"><<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span class=""><div dir="ltr">On Wed, Aug 15, 2018 at 1:28 PM Xinliang David Li <<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Aug 15, 2018 at 12:46 PM Malhar Thakkar <<a href="mailto:cs13b1031@iith.ac.in" target="_blank">cs13b1031@iith.ac.in</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you so much for your response.<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 15, 2018 at 3:08 PM, Xinliang David Li <span dir="ltr"><<a href="mailto:xinliangli@gmail.com" target="_blank">xinliangli@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span class="m_-5536552583390144351m_2230248955017055735m_-4117626105924001977gmail-"><div dir="ltr">On Wed, Aug 15, 2018 at 7:36 AM Malhar Thakkar via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hey all,<div><br></div><div>I have a piece of code (written in LLVM 2.8) which uses profiling results produced by ProfileInfo. It essentially computes the number of iterations performed by a loop from the profiling information available. The code snippet in my pass looks something like this.</div><div><br></div><div>



  <span></span>
  
  


<h2></h2>

<div class="m_-5536552583390144351m_2230248955017055735m_-4117626105924001977gmail-m_-7740094245048439705m_-6012055350149373409gmail-highlight" style="background:rgb(248,248,248)"><pre style="line-height:125%">  BasicBlock <span style="color:rgb(102,102,102)">*</span>header <span style="color:rgb(102,102,102)">=</span> loop<span style="color:rgb(102,102,102)">-></span>getHeader();
  ProfileInfo &pi = getAnalysis< ProfileInfo >();
  <span style="color:rgb(0,128,0);font-weight:bold">for</span>(pred_iterator i<span style="color:rgb(102,102,102)">=</span>pred_begin(header), e<span style="color:rgb(102,102,102)">=</span>pred_end(header); i<span style="color:rgb(102,102,102)">!=</span>e; <span style="color:rgb(102,102,102)">++</span>i)
  {
    BasicBlock <span style="color:rgb(102,102,102)">*</span>pred <span style="color:rgb(102,102,102)">=</span> <span style="color:rgb(102,102,102)">*</span>i;

    <span style="color:rgb(0,128,0);font-weight:bold">const</span> <span style="color:rgb(176,0,64)">double</span> edgeCount <span style="color:rgb(102,102,102)">=</span> <b>pi.getEdgeWeight</b>( ProfileInfo<span style="color:rgb(102,102,102)">::</span>Edge(pred,header) );
    <font color="#008000"><b>/* Some code */</b></font>
  }
</pre></div>


Now, since ProfileInfo has been deprecated and we have PGOInstrumentation passes along with BranchProbability and BlockFrequency, I wish to update the above snippet, in particular, obtaining the edge weights (highlighted in the code above) using the new tools.</div><div><br></div><div>In order to do that, I'm first generating edge count profile by the PGOInstrumentationGen pass and then interpreting the edge count profile with PGOInstrumentationUse.</div><div><br></div><div>In the original code, where I had </div><div><font face="monospace, monospace" style="font-weight:bold">au.addRequired< ProfileInfo >(), </font><font face="arial, helvetica, sans-serif">I now have </font><font face="monospace, monospace" style="font-weight:bold"> </font></div><div><font face="monospace, monospace" style="font-weight:bold"><br></font></div><div><font face="monospace, monospace"><b><div>au.addRequired< BlockFrequencyInfoWrapperPass >();</div><div>au.addRequired< BranchProbabilityInfoWrapperPa<wbr>ss >();</div><div><br></div></b></font></div><div>Now, I have the following queries.</div><div><ul><li>How do I use the edge count and branch weights data obtained using PGOInstrumentationUse in my pass and replace the <b><font face="monospace, monospace">getEdgeWeight()</font></b> from ProfileInfo?</li></ul></div></div></blockquote><div><br></div></span><div>You can do</div><div> BPI.getEdgeProbability(Src, Dest).scale(BFI.<wbr>getBlockProfileCount(Src));</div></div></div></blockquote><div><br></div><div>I tried doing this but there are some semantic issues that I'm facing. There is a loop in my program which I know is a hot loop since it is the only loop inside the function main() and essentially, all the computations are performed within this function via function calls. However, when I perform <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">getBlockProfileCount(Src) where Src is the preheader of the said loop, I find that it returns zero and upon further investigation, I found that the entry frequency for the function was 6148904414811 and the block frequency for the aforementioned preheader block was 6148904394768 and after performing udiv, since it is an integer division, getBlockProfileCount(Src) returned zero and hence, my code infers that it is not a hot loop when in fact it clearly is.</span> </div></div></div></div></blockquote></div></div></blockquote><div><br></div></span><div>Easwaran, I think this is a bug that needs to be fixed.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>David</div></font></span><span class=""><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Any suggestions on why this may be happening?</div></div></div></div></blockquote><div><br></div><div>What is function entry's profile count? Note it is different from entry frequency (which is synthetic). You can find the function entry's count from entry's prof meta data. There is also an API to get it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span class="m_-5536552583390144351m_2230248955017055735m_-4117626105924001977gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><ul><li>If I call <b style="font-family:monospace,monospace">getBlockProfileCount() </b><font face="arial, helvetica, sans-serif">from the BlockFrequency pass, will that give me the data read during PGOInstrumentationUse or data based on static analysis? In other words, does the data obtained during PGOInstrumentationUse "propagate" to BlockFrequency and BranchProbability?</font></li></ul><div><font face="arial, helvetica, sans-serif"><br></font></div></div></div></blockquote></span><div>Correct.</div></div></div></blockquote><div>Just to confirm, when you say "correct", do you mean to say that the information in fact does get propagated to BlockFrequency and BranchProbability? If yes, how does the propagation take place?</div></div></div></div></blockquote><div><br></div><div>Branch probability info analysis pass will use the profile meta data (read in from profile data and annotated in the IR) and use that to compute branch probability. The block frequency propagation pass uses BPI info to compute relative block frequencies.   The actual profile count of the function entry is kept, and a block's actual profile count can then be recomputed using Entry Frequency, block frequency, and the entry count data.</div><div><br></div><div>David</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><div><br></div><div>Thank you.</div><div><br></div><div>Regards,</div><div>Malhar</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>David</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_-5536552583390144351m_2230248955017055735m_-4117626105924001977gmail-"><div dir="ltr"><div><div><font face="arial, helvetica, sans-serif"></font></div></div><div><font face="arial, helvetica, sans-serif">Thank you.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Regards,</font></div><div><font face="arial, helvetica, sans-serif">Malhar</font></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=343de676-35f2-4e0e-9a4a-400954a5dfd9"><font color="#ffffff" size="1">ᐧ</font></div></span>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>
</blockquote></div><br></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=e2b1fac8-1e90-4558-a9f1-dcf85ba172dd"><font color="#ffffff" size="1">ᐧ</font></div>
</blockquote></div></div>
</blockquote></span></div></div>
</blockquote></div><br></div></div><div hspace="streak-pt-mark" style="max-height:1px"><img alt="" style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=aY3MxM2IxMDMxQGlpdGguYWMuaW4%3D&type=zerocontent&guid=9618bf2e-03b1-4df4-9ed5-9996d8db13d2"><font color="#ffffff" size="1">ᐧ</font></div>