<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 2, 2015 at 12:43 PM, Jim Grosbach <span dir="ltr"><<a href="mailto:grosbach@apple.com" target="_blank">grosbach@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Feb 28, 2015, at 6:29 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 28, 2015 at 7:39 AM, Ziqiang Patrick Huang<span> </span><span dir="ltr"><<a href="mailto:ziqiang.huang1001@gmail.com" target="_blank">ziqiang.huang1001@gmail.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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></div></div></div></div></div></blockquote><div><br></div></span><div>It depends on the specific target. What’s being described is basically what the ARM constant islands pass does. With the rather large caveat that there will always be some conservative assumptions baked in (inline assembly is “awesome”).</div></div></div></blockquote><div><br>Ah, fair enough - I was vaguely wondering how the constant island pass dealt with it. I guess there's less encoding length ambiguity in a RISC architecture like ARM which makes this a bit more viable.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Jim</div></font></span><div><div class="h5"><br><blockquote type="cite"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_extra"><div class="gmail_quote"><div>- David</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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> </span><span dir="ltr"><<a href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span>:<div><div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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><font color="#888888"><br><br clear="all"><div><br></div>--<span> </span><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:<span> </span><a href="tel:919-491-3677" value="+19194913677" target="_blank">919-491-3677</a></b></div><div><b>Email:<span> </span><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" target="_blank">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><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">LLVM Developers mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:LLVMdev@cs.uiuc.edu" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">LLVMdev@cs.uiuc.edu</a><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>        </span><a href="http://llvm.cs.uiuc.edu/" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://llvm.cs.uiuc.edu</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div>