Ziqiang Patrick Huang
2015-Feb-27 23:30 UTC
[LLVMdev] Getting basic block address offset from its parent function
Hi, all Is there a way of getting the basic block offset from its parent function ? 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 ... Any suggestion is very much appreciated Patrick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150227/355e96c4/attachment.html>
John Criswell
2015-Feb-28 14:07 UTC
[LLVMdev] Getting basic block address offset from its parent function
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>
Ziqiang Patrick Huang
2015-Feb-28 15:39 UTC
[LLVMdev] Getting basic block address offset from its parent function
Hi John 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 .. Does this sound reasonable ? Thanks, Patrick 2015-02-28 9:07 GMT-05:00 John Criswell <jtcriswel at gmail.com>:> 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 Rochesterhttp://www.cs.rochester.edu/u/criswell > >-- *Ziqiang Huang* *Electrical and Computer Engineering* *Hudson 213c, Duke University* *Tel: 919-491-3677* *Email: ziqiang.huang at duke.edu <ziqiang.huang at duke.edu>* -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150228/91add591/attachment.html>
Possibly Parallel Threads
- [LLVMdev] Getting basic block address offset from its parent function
- [LLVMdev] Getting basic block address offset from its parent function
- [LLVMdev] Getting basic block address offset from its parent function
- [LLVMdev] Tracing values in llvm IR
- [LLVMdev] Tracing values in llvm IR