<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 2/27/15 6:30 PM, Ziqiang Patrick
Huang wrote:<br>
</div>
<blockquote
cite="mid:CA+rCrmBZjpCdaVwr5kBUstG7vMu92Kv6x-KzYMXJ+cM32aXL3g@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
<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>
At the LLVM IR level, no. At the code generator layer
(MachineFunctionPass layer or the MC layer), probably yes.<br>
<br>
<blockquote
cite="mid:CA+rCrmBZjpCdaVwr5kBUstG7vMu92Kv6x-KzYMXJ+cM32aXL3g@mail.gmail.com"
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>
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<br>
<br>
<pre class="moz-signature" cols="72">--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
</body>
</html>