<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 28, 2015 at 7:39 AM, Ziqiang Patrick Huang <span dir="ltr"><<a href="mailto:ziqiang.huang1001@gmail.com" target="_blank">ziqiang.huang1001@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">Hi John<div><br></div><div>Thanks for your suggestions, they all sound reasonable to me. The way I'm thinking right now is to write a MachineFuncionPass that iterate through each MachinBasicBlock, for each MBB, adds up the instructions counts of previous MBBs, that number multiply by 4 should be the offset of that MBB from its MachineFunction. In order to correctly count the instructions, this pass should be inserted after the last transform pass ..</div><div><br></div><div>Does this sound reasonable ?</div></div></blockquote><div><br></div><div>I could be wrong, but I'm not sure that's possible - my understanding was that the particular length of a sequence could depend on assembler-level choices of instruction encoding & the like. I believe the right/only way to do this is with label differences that the assembler will resolve/compute for you. But I could quite well be wrong - it's certainly not my area of expertise.<br><br>- David</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><br></div><div>Thanks,</div><div>Patrick<br><div class="gmail_extra"><br><div class="gmail_quote">2015-02-28 9:07 GMT-05:00 John Criswell <span dir="ltr"><<a href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span>:<div><div class="h5"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF"><span>
    <div>On 2/27/15 6:30 PM, Ziqiang Patrick
      Huang wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Hi, all
        <div><br>
        </div>
        <div>Is there a way of getting the basic block offset from its
          parent function ?</div>
      </div>
    </blockquote>
    <br></span>
    At the LLVM IR level, no.  At the code generator layer
    (MachineFunctionPass layer or the MC layer), probably yes.<span><br>
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>What I'm trying to do is to get an execution count of each
          basic blocks, so I need to know the starting address of each
          basic blocks. Obviously we can't get the absolute address
          before linking the program, but the offset relative to parent
          function should be available so I can take it and get the
          function start address from objdump then figure out each basic
          block's absolute address.</div>
        <div><br>
        </div>
        <div>Or is there another way of doing this ...</div>
      </div>
    </blockquote>
    <br></span>
    On way to do it would be to instrument the program so that each
    basic block increments a counter every time it is executed.  This
    would be trivial to do.  To optimize it, you could analyze the CFG
    so that control equivalent basic blocks use a single counter (e.g.,
    the single-entry block and the single-exit block are executed the
    same number of times, so they only need 1 counter).<br>
    <br>
    Another option might be to use the pcmarker intrinsic.  Apparently
    it's used for matching up LLVM IR to machine instructions for use in
    processor simulators, though I have never used it myself.<br>
    <br>
    The Giri project has support for recording the execution of every
    basic block, but it might be more heavy-weight than you need.  I
    also don't recall off-hand from where to download it; search the
    llvmdev archives for emails from Swarup Sahoo to get that
    information.<br>
    <br>
    Hope this helps,<br>
    <br>
    John Criswell<span><font color="#888888"><br>
    <br>
    <pre cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
  </font></span></div>

</blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><b>Ziqiang Huang</b><div><div><b>Electrical and Computer Engineering</b></div><div><b>Hudson 213c, Duke University</b></div></div><div><b>Tel: <a href="tel:919-491-3677" value="+19194913677" target="_blank">919-491-3677</a></b></div><div><b>Email: <a href="mailto:ziqiang.huang@duke.edu" target="_blank">ziqiang.huang@duke.edu</a></b></div></div></div>
</font></span></div></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>