[LLVMdev] Getting basic block address offset from its parent function
John Criswell
jtcriswel at gmail.com
Sat Feb 28 06:07:59 PST 2015
On 2/27/15 6:30 PM, Ziqiang Patrick Huang wrote:
> Hi, all
>
> Is there a way of getting the basic block offset from its parent
> function ?
At the LLVM IR level, no. At the code generator layer
(MachineFunctionPass layer or the MC layer), probably yes.
>
> 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.
>
> Or is there another way of doing this ...
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).
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.
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.
Hope this helps,
John Criswell
--
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150228/a054ec03/attachment.html>
More information about the llvm-dev
mailing list