<div dir="ltr">Thank you very much Jevin for the suggestion!<div><br></div><div>But how I can use blockaddress function? Do I have to write a pass in order to use it?</div><div>As I told you I am new in llvm. Could you provide me a guide or an example?</div>
<div><br></div><div>Thank you very much,</div><div>Thanasis</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 28, 2014 at 8:27 PM, Jevin Sweval <span dir="ltr"><<a href="mailto:jevinsweval@gmail.com" target="_blank">jevinsweval@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Fri, Mar 28, 2014 at 1:15 PM, Petsas Athanasios <<a href="mailto:petsas@ics.forth.gr">petsas@ics.forth.gr</a>> wrote:<br>

> Dear all,<br>
><br>
> I use the clang frontend to produce the control flow graph of a C program<br>
> through<br>
> this command:<br>
> clang -Xclang -analyze -Xclang -analyzer-checker=debug.DumpCFG test.c<br>
><br>
> The produced information contains all the basic blocks identified by labels,<br>
> e.g. B1, B2, etc. along with their predecessors and successors.<br>
><br>
> Is there a way to get the starting address of each of these basic block?<br>
> I would like to map the basic block labels produced by CFG  with the actual<br>
> corresponding basic block starting addresses.<br>
><br>
> Could I use llvm to do this? From what I understand this issued is<br>
> unrelevant with<br>
> IR. Maybe I could get something from the machine code (MC). Perhaps<br>
> I have to write a pass for llvm backend. Maybe I could get this information<br>
> from<br>
> BranchFolder and IfConverter machine function passes:<br>
> <a href="http://llvm.org/docs/WritingAnLLVMBackend.html#branch-folding-and-if-conversion" target="_blank">http://llvm.org/docs/WritingAnLLVMBackend.html#branch-folding-and-if-conversion</a><br>
> but I am not sure.<br>
><br>
> I am new to llvm so I need some help,<br>
><br>
> Thank you,<br>
><br>
<br>
</div>Check out blockaddress(@function, %block) as documented in:<br>
<a href="http://llvm.org/docs/LangRef.html#addresses-of-basic-blocks" target="_blank">http://llvm.org/docs/LangRef.html#addresses-of-basic-blocks</a><br>
<br>
The documentation says it only has defined behavior when used with<br>
indirectbr, but I have been able to store the block address in a<br>
global variable that survives lowering and is the correct address.<br>
<br>
      GlobalVariable *GV = new GlobalVariable(M, bbPtr, /*isConstant=*/true,<br>
                                   GlobalValue::ExternalLinkage,<br>
                                   BlockAddress::get(bb), name);<br>
<br>
Beware, the IR BB may be optimized away when lowering to assembly. You<br>
can detect this case when blockaddress() returns 1.<br>
<br>
Cheers,<br>
Jevin<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><font color="#888888"><font face="Helvetica, Verdana, Arial"><span style="font-size:11pt"><font color="#888888"><span>Thanasis</span> <span>Petsas</span><div>
Distributed Computing Systems (<span>DCS</span>)<br>
Institute of Computer Science (ICS/FORTH)<br>
Heraklion, Crete<br>
<span>Greece</span> (GR)<br><br><font color="#888888"><font face="Helvetica, Verdana, Arial"><span style="font-size:11pt"><font color="#888888"><a href="http://www.thanasispetsas.com/" target="_blank">http://www.thanasispetsas.com/</a></font></span></font></font><br>
</div></font></span></font></font>
</div>