<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Pankaj,<div><br></div><div>If you want to decorate MachineInstrs then for the end of scope you're not looking at "}" but instead you're looking at _last_ machine instruction in that scope. Now, if you want to find out start and end MachineInstrs for a lexical scope (and corresponding line numbers) then see CodeGen/LexicalScopes pass. It collects lexical scope information and maps MIs to respective lexical scopes.</div><div><br></div><div>-</div><div>Devang</div><div><br><div><div>On Oct 5, 2011, at 3:48 AM, Pankaj Gode wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10pt; position: static; z-index: auto; "><div style="RIGHT: auto"><span style="RIGHT: auto">Hi,</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"></span> </div>
<div style="RIGHT: auto"><span style="RIGHT: auto">The link and the information shared was helpful.</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"></span> </div>
<div style="RIGHT: auto"><span style="RIGHT: auto">I will make my problem definition more clear. </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">While I am "asm printing" target code, I also want to emit scope related information. </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">Scope related information includes, </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">- for each scope, start line, end line, start column, end column</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">and </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">- scope heirarchy. </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">As scope is delimited by "{" and "}" (for an input C/C++ code), hence wanted to collect "endline" for scope. </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">When I went through the ".ll" emitted by llc, i could find the "startline" in metadata. </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"></span> </div>
<div style="RIGHT: auto"><span style="RIGHT: auto">For this I could think of 2 approaches</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">1. Create a pass in llvm, to collect this information from the llvm instructions, by simply traversing them.</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"> Identifying line number for each instruction and checking on the lexical block it points to. Also would maintain the parent/child lexical block relation using metadata information.</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"> My "startline" is least line number associated with lexical block, and "endline" number is max line number associated with lexical block.</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">2. While "asm printing", traverse through the machine instruction and collect the information in similar way as 1. </span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"></span> </div>
<div style="RIGHT: auto"><span style="RIGHT: auto">I am not sure whether I should collect it from Clang AST nodes. <var id="yui-ie-cursor"></var></span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto"></span> </div>
<div style="RIGHT: auto"><span style="RIGHT: auto">Regards,</span></div>
<div style="RIGHT: auto"><span style="RIGHT: auto">Pankaj</span></div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto"> </div>
<div style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 10pt">
<div style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><font size="2" face="Arial">
<div style="BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid; PADDING-BOTTOM: 0px; LINE-HEIGHT: 0; MARGIN: 5px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; HEIGHT: 0px; FONT-SIZE: 0px; BORDER-TOP: #ccc 1px solid; BORDER-RIGHT: #ccc 1px solid; PADDING-TOP: 0px" class="hr" contenteditable="false" readonly="true"></div><b><span style="FONT-WEIGHT: bold">From:</span></b> Devang Patel <<a href="mailto:dpatel@apple.com">dpatel@apple.com</a>><br><b><span style="FONT-WEIGHT: bold">To:</span></b> Pankaj Gode <<a href="mailto:godepankaj@yahoo.com">godepankaj@yahoo.com</a>><br><b><span style="FONT-WEIGHT: bold">Cc:</span></b> "<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>" <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><br><b><span style="FONT-WEIGHT: bold">Sent:</span></b> Tuesday, October 4, 2011 10:08 PM<br><b><span style="FONT-WEIGHT: bold">Subject:</span></b> Re: [LLVMdev] collect end line number for scope<br></font><br>
<div style="RIGHT: auto" id="yiv809494079">
<div style="RIGHT: auto">Pankaj,
<div style="RIGHT: auto"><br style="RIGHT: auto">
<div style="RIGHT: auto">
<div style="RIGHT: auto">On Oct 3, 2011, at 4:36 AM, Pankaj Gode wrote:</div><br class="yiv809494079Apple-interchange-newline">
<blockquote style="RIGHT: auto" type="cite">
<div style="RIGHT: auto">
<div style="BACKGROUND-COLOR: rgb(255,255,255); FONT-FAMILY: courier, monaco, monospace, sans-serif; COLOR: rgb(0,0,0); FONT-SIZE: 10pt">
<div style="RIGHT: auto">Hi All,</div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">int global;</div>
<div style="RIGHT: auto">int func( int t)</div>
<div style="RIGHT: auto">{ </div>
<div style="RIGHT: auto"> //scope 1</div>
<div style="RIGHT: auto"> {</div>
<div style="RIGHT: auto"> ....</div>
<div> } <-----</div>
<div style="RIGHT: auto"> return x;</div>
<div style="RIGHT: auto">} <var id="yiv809494079yui-ie-cursor"></var></div>
<div style="RIGHT: auto"> </div>
<div style="RIGHT: auto">For the above code, i want to collect endline (indicated by <---) for the scope. Can we get this information from the Dwarf Information in llvm 2.9 ? </div>
<div> </div></div></div></blockquote></div><br>
<div style="RIGHT: auto">If there is no code generated for a source line with just "}", so you are not going to get that line number in debug info (because there is not any llvm instruction). You can access the line number for the last statement/expression in the scope. See <a href="http://llvm.org/docs/SourceLevelDebugging.html#ccxx_compile_units">http://llvm.org/docs/SourceLevelDebugging.html#ccxx_compile_units</a> for a code snippet on how to get line number from an llvm instruction.</div>
<div style="RIGHT: auto"><br style="RIGHT: auto"></div>
<div style="RIGHT: auto">What exactly are you trying to do? Depending on your needs, you may be able to access clang AST nodes to get exact line and column number information for "}" irrespective of debug info.</div>
<div style="RIGHT: auto"><br style="RIGHT: auto"></div>
<div style="RIGHT: auto">-</div>
<div style="RIGHT: auto">Devang</div></div></div></div><br><br></div></div></div></div></blockquote></div><br></div></body></html>