<div dir="ltr">you would need to build with debug info (-g) or similar (there are a few other options that enable the same source location info) to produce the debuglocs that will tell you about that<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 11, 2016 at 9:40 PM, Shail Dave via cfe-users <span dir="ltr"><<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)">Hi,<br><br><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;line-height:19.5px">I am working with LLVM 3.4 and want to obtain the line number information of source file from IR. The IR is generated from simple c code with Clang. <strong style="margin:0px;padding:0px;border:0px">I want to obtain the line number in source c file from the line in IR body.</strong></p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;line-height:19.5px">I tried this -</p><ol style="margin:0px 0px 1em 30px;padding:0px;border:0px;font-size:15px;color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;line-height:19.5px"><li style="margin:0px 0px 0.5em;padding:0px;border:0px;word-wrap:break-word">For Instruction BI, unsigned Line = Line = BI->getDebugLoc().getLine();</li><li style="margin:0px;padding:0px;border:0px;word-wrap:break-word">For Loop L, std::cout << L->getStartLoc().getLine();</li></ol><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;line-height:19.5px">But, the result stored/printed is always 0. I don't know how to obtain line number in the source from LLVM IR.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;line-height:19.5px">My Source C file is -</p></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0)">​<span style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;white-space:inherit;font-size:13px;margin:0px;padding:0px;border:0px;color:rgb(133,140,147);background-color:rgb(239,240,241)">#include</span><span style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;white-space:inherit;font-size:13px;margin:0px;padding:0px;border:0px;color:rgb(48,51,54);background-color:rgb(239,240,241)"> </span><span style="font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;white-space:inherit;font-size:13px;margin:0px;padding:0px;border:0px;color:rgb(125,39,39);background-color:rgb(239,240,241)"><stdio.h></span></div><pre style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;color:rgb(57,51,24);word-wrap:normal;background-color:rgb(239,240,241)"><code style="margin:0px;padding:0px;border:0px;font-family:Consolas,Menlo,Monaco,"Lucida Console","Liberation Mono","DejaVu Sans Mono","Bitstream Vera Sans Mono","Courier New",monospace,sans-serif;white-space:inherit"><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">int</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> main</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">()</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">{</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">

 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">int</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">

 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">int</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">100</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">];</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">int</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> outbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">100</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">];</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">

 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">for</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">0</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> i </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"><</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">100</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">++</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">        
        inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">^=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> outbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">];</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">

 inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">1</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">+=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">402</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
 inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">6</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">+=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">107</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
 inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">97</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">+=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">231</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">

 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">for</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">0</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> i </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"><</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">100</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">++</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">)</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">       
 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">{</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
         inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">+=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> outbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">];</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">}</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">

 inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">47</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">+=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">312</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">  

    </span><span style="margin:0px;padding:0px;border:0px;color:rgb(133,140,147)">//print-statements </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
 </span><span style="margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">for</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">=</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">0</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"><</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">100</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">++)</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">{</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
        printf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">(</span><span style="margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">"inbuf[%d] = %d\n"</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">,</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">inbuf</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">[</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">i</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">]);</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">              
</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">}</span><span style="margin:0px;padding:0px;border:0px;color:rgb(48,51,54)">
</span></code><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(16,16,148)">return</span><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(48,51,54)"> </span><span style="white-space:inherit;margin:0px;padding:0px;border:0px;color:rgb(125,39,39)">0;
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);display:inline">​}​</div></span></pre><div class="gmail_default"><br><font color="#000000" face="arial, helvetica, sans-serif"> </font><strong style="color:rgb(36,39,41);font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;margin:0px;padding:0px;border:0px;font-size:15px;line-height:19.5px">Command Used-</strong><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"> ~/llvm/build/Release+Asserts/bin/clang -O3 -fno-unroll-loops -fno-vectorize -fno-slp-vectorize -S -emit-llvm sample.c -o sample.ll<br></span></font><br><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">I have working pass which can detect and analyze the loops and instructions. I am using it inside function - runOnLoop(Loop *L, LPPassManager &LPM) <br></span></font><br><font color="#242729" face="Arial, Helvetica Neue, Helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">I have also tried with -O0 and  -fstandalone-debug option in the compile line. But, it is still printing 0. <br><br>The following is also not working out. <br><br><div class="gmail_default">if (MDNode *N = I->getMetadata("dbg")) {  // Here I is an LLVM instruction</div><div class="gmail_default">   DILocation Loc(N);                      // DILocation is in DebugInfo.h</div><div class="gmail_default">   unsigned Line = Loc.getLineNumber();</div><div class="gmail_default"> }</div><br>It would be great if anybody can kindly help me for the same. Thanks!</span></font></div></div><br><div data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><p style="margin-bottom:0.0001pt;text-align:justify"><span style="font-size:14.6667px;font-family:Calibri,sans-serif;text-align:start">Best,<br></span><span style="font-size:14.6667px;font-family:Calibri,sans-serif;text-align:start">Shail</span><br></p></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div><div hspace="streak-pt-mark" style="max-height:1px"><img style="width:0px;max-height:0px;overflow:hidden" src="https://mailfoogae.appspot.com/t?sender=ac2pkYXZlQGFzdS5lZHU%3D&type=zerocontent&guid=fe00f6e3-6ae8-45db-b22f-c91bb41bd83a"><font color="#ffffff" size="1">ᐧ</font></div>
<br>_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org">cfe-users@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
<br></blockquote></div><br></div>