<div dir="ltr">BB labels are implicitly assigned based on their position in the function.<div><br></div><div>This has come up before <<a href="http://thread.gmane.org/gmane.comp.compilers.llvm.devel/62194/">http://thread.gmane.org/gmane.comp.compilers.llvm.devel/62194/</a>>, <<a href="http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/145768/">http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/145768/</a>>, r182332.<div>
<br></div><div>IIRC the only reason the label is in comments is that syntactically it's not possible to put a numeric label name there. Otherwise just change AssemblyWriter::printBasicBlock (in lib/IR/AsmWriter.cpp) to print out a proper numeric label name instead of putting it in a comment.</div>
<div><br></div><div>-- Sean Silva</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 1, 2013 at 3:39 PM, Preston Briggs <span dir="ltr"><<a href="mailto:preston.briggs@gmail.com" target="_blank">preston.briggs@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 dir="ltr">I happened to try building LLVM without assertions today,<div>and it changed the form of the LLVM IR that gets generated.</div>
<div>Typically, I do something like</div><div><br></div><div>    clang -O -emit-llvm -S Test.c</div>
<div><br></div><div>For source like</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="courier new, monospace">typedef struct node {</font></div><div><font face="courier new, monospace">  struct node *left;</font></div>

<div><font face="courier new, monospace">  struct node *right;</font></div><div><font face="courier new, monospace">  int key;</font></div><div><font face="courier new, monospace">} Tree;</font></div><div><font face="courier new, monospace"><br>

</font></div><div><font face="courier new, monospace">int sum(Tree *p) {</font></div><div><font face="courier new, monospace">  int s = 0;</font></div><div><font face="courier new, monospace">  if (p) {</font></div><div>
<font face="courier new, monospace">    s += sum(p->left);</font></div>
<div><font face="courier new, monospace">    s += sum(p->right);</font></div><div><font face="courier new, monospace">    s += p->key;</font></div><div><font face="courier new, monospace">  }</font></div><div><font face="courier new, monospace">  return s;</font></div>

<div><font face="courier new, monospace">}</font></div><div><br></div></blockquote><div>The resulting Test.s looks like</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="courier new, monospace">define i32 @sum(%struct.node* %p) #0 {</font></div>

</div><div><div><font face="courier new, monospace">  %1 = icmp eq %struct.node* %p, null</font></div></div><div><div><font face="courier new, monospace">  br i1 %1, label %13, label %2</font></div></div><div><div><font face="courier new, monospace"><br>

</font></div></div><div><div><font face="courier new, monospace">; <label>:2                                       ; preds = %0</font></div></div><div><div><font face="courier new, monospace">  %3 = getelementptr inbounds %struct.node* %p, i64 0, i32 0</font></div>

</div><div><div><font face="courier new, monospace">  %4 = load %struct.node** %3, align 8, !tbaa !0</font></div></div><div><div><font face="courier new, monospace">  %5 = tail call i32 @sum(%struct.node* %4)</font></div>

</div><div><div><font face="courier new, monospace">  %6 = getelementptr inbounds %struct.node* %p, i64 0, i32 1</font></div></div><div><div><font face="courier new, monospace">  %7 = load %struct.node** %6, align 8, !tbaa !0</font></div>

</div><div><div><font face="courier new, monospace">  %8 = tail call i32 @sum(%struct.node* %7)</font></div></div><div><div><font face="courier new, monospace">  %9 = add nsw i32 %8, %5</font></div></div><div><div><font face="courier new, monospace">  %10 = getelementptr inbounds %struct.node* %p, i64 0, i32 2</font></div>

</div><div><div><font face="courier new, monospace">  %11 = load i32* %10, align 4, !tbaa !3</font></div></div><div><div><font face="courier new, monospace">  %12 = add nsw i32 %9, %11</font></div></div><div><div><font face="courier new, monospace">  ret i32 %12</font></div>

</div><div><div><font face="courier new, monospace"><br></font></div></div><div><div><font face="courier new, monospace">; <label>:13                                      ; preds = %0</font></div></div><div><div><font face="courier new, monospace">  ret i32 0</font></div>

</div><div><div><font face="courier new, monospace">}</font></div></div></blockquote><div><br></div><div>Note that labels %2 and %13 are not actually defined, though they're both referred to by the first branch and in comments.</div>

<div><br></div><div>What's the deal?</div><div><br></div><div>Thanks,</div><div>Preston</div><div><br></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>