[LLVMdev] How to extract the starting address of each basic block with llvm?
petsas at ics.forth.gr
Fri Mar 28 13:04:37 PDT 2014
Thank you very much Jevin for the suggestion!
But how I can use blockaddress function? Do I have to write a pass in order
to use it?
As I told you I am new in llvm. Could you provide me a guide or an example?
Thank you very much,
On Fri, Mar 28, 2014 at 8:27 PM, Jevin Sweval <jevinsweval at gmail.com> wrote:
> On Fri, Mar 28, 2014 at 1:15 PM, Petsas Athanasios <petsas at ics.forth.gr>
> > Dear all,
> > I use the clang frontend to produce the control flow graph of a C program
> > through
> > this command:
> > clang -Xclang -analyze -Xclang -analyzer-checker=debug.DumpCFG test.c
> > The produced information contains all the basic blocks identified by
> > e.g. B1, B2, etc. along with their predecessors and successors.
> > Is there a way to get the starting address of each of these basic block?
> > I would like to map the basic block labels produced by CFG with the
> > corresponding basic block starting addresses.
> > Could I use llvm to do this? From what I understand this issued is
> > unrelevant with
> > IR. Maybe I could get something from the machine code (MC). Perhaps
> > I have to write a pass for llvm backend. Maybe I could get this
> > from
> > BranchFolder and IfConverter machine function passes:
> > but I am not sure.
> > I am new to llvm so I need some help,
> > Thank you,
> Check out blockaddress(@function, %block) as documented in:
> The documentation says it only has defined behavior when used with
> indirectbr, but I have been able to store the block address in a
> global variable that survives lowering and is the correct address.
> GlobalVariable *GV = new GlobalVariable(M, bbPtr,
> BlockAddress::get(bb), name);
> Beware, the IR BB may be optimized away when lowering to assembly. You
> can detect this case when blockaddress() returns 1.
Distributed Computing Systems (DCS)
Institute of Computer Science (ICS/FORTH)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev