<div dir="ltr">Hi David, <br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Broader: Why do you want to know the relative order of calls in IR? That property isn't especially meaningful - for instance if the calls are in different basic blocks, then it's /really/ arbitrary, as the order of basic blocks shouldn't be significant.</blockquote><div><br></div><div>Upon re-examining, I think what I really need is the order in which calls take place in the original source code - even if those calls are inlined. I see the DILocation has an <font face="monospace">InlinedAt</font><font face="arial, sans-serif"> field, which seems to be giving me the proper ordering for the code I'm looking at. I'll play around a bit more with it but I think that should give me what I need. Thanks for your help!<br><br>Best, <br>Shishir Jessu</font></div></div><img src="https://my-email-signature.link/signature.gif?u=452460&e=103526549&v=56c0beb25488764ae1e1fca2bab2d03c18610647c99e48109ef5e696bcbd23cb" style="width:2px;max-height:0;overflow:hidden"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 8, 2020 at 3:08 PM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 8, 2020 at 12:57 PM Shishir V Jessu <<a href="mailto:shishir.jessu@utexas.edu" target="_blank">shishir.jessu@utexas.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi David, <br><br>Thanks for the quick response! I see now what's going on. <br><br>My main issue here is that I want to sort a few CallInst objects by the order in which they appear in the IR. </div></blockquote><div><br>Once you're dealing with LLVM IR in-memory (llvm::Module and associated classes) - I don't think that information exists, really? I guess it exists in some sense, because when the IR is dumped, it's printed in some order - I guess you'd find that order by iterating over basic blocks and instructions and you could "number" instructions that way (make a map from Instruction* to order number) and then sort via that table?<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">But here, I have a CallInst with !dbg=69 and line number 61, and a CallInst appearing further down in the program with !dbg=87, but its line number is 50. <br></div></blockquote><div><br>Yeah, that line number doesn't have anything to do with the order of instructions in the IR - it's the source line from the original code (probably C++ from Clang, for instance).<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thus, my attempt to sort by line number isn't working, although as far as I can tell, the code hasn't actually been rearranged. This is compiled on -O2 with some inlining taking place, however, which may be leading to problems.<br></div></blockquote><div><br>Yep. eg:<br><br>1: void f1();<br>2: void f2() {<br>3: f1();<br>4: }<br>5: void f3() {<br>6: f1();<br>7: f2();<br>8: }<br><br>if f2 is inlined into f3, then you'll have two calls to f1, the first call is from line 6, the second is from line 3.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Is there any way you know of to sort these in the order in which they appear in the IR? Thanks for your help!<br></div></blockquote><div><br>Broader: Why do you want to know the relative order of calls in IR? That property isn't especially meaningful - for instance if the calls are in different basic blocks, then it's /really/ arbitrary, as the order of basic blocks shouldn't be significant.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br>Best, <br>Shishir</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 8, 2020 at 1:30 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">The !69 and !29 refer to metadata (look further down in the LLVM IR dump) that looks something like this:<br><br>
<p style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">!10 = !DILocation(line: 3, column: 3, scope: !7)<br><br>Which is where the 'line' value is stored (so the line is not 69 or 29).<br><br>When you extract the function, only the referenced metadata is brought with it, so it gets renumbered - but the semantics remain the same - the line/column/scope is preserved. It's just there's fewer metadata nodes, so the metadata node number is smaller.</span></p></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 8, 2020 at 11:23 AM Shishir V Jessu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hello, <br><br>I am compiling a program with debugging information, and am attempting to extract !dbg numbers from function calls in LLVM IR. However, I've found a few inconsistencies. For example, this call exists in my module: <br><font face="monospace"><br>%1 = tail call i1 @llvm.type.test(i8* bitcast (i32 (i32)* @_Z5otheri to i8*), metadata !"_ZTSFiiE") #5, <b>!dbg !69</b>, !nosanitize !2</font><br><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">I would like to extract the 69 from this line in my LLVM pass, but when I </font><font face="monospace">dump()</font><font face="arial, sans-serif"> the corresponding </font><font face="monospace">CallInst</font><font face="arial, sans-serif">, I see the following: <br><br></font><font face="monospace">%1 = tail call i1 @llvm.type.test(i8* bitcast (i32 (i32)* @_Z5otheri to i8*), metadata !"_ZTSFiiE") #5, <b>!dbg !29</b>, !nosanitize !2<br></font><br>And finally, the line <b>CallInst -> getDebugLoc() -> getLine()</b> returns <b>61</b> for this call, not 69 or 29.<div></div></div><div><br></div><div>Am I misunderstanding the purpose of getDebugLoc() for a CallInst? Is there any way I can extract the correct !dbg for a given line? Thanks for your help!<br><br>Best, <br>Shishir Jessu</div></div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div></div>
</blockquote></div>