<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 13, 2013 at 5:31 PM, Paul Sokolovsky <span dir="ltr"><<a href="mailto:pmiscml@gmail.com" target="_blank">pmiscml@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello,<br>
<br>
I only recently started to look at LLVM assembly generated by Clang,<br>
and one of the first thing I saw was like:<br>
<br>
define i32 @foo(i32 %a, i32 %b) nounwind {<br>
%1 = tail call i32 @bar(i32 %a) nounwind<br>
%2 = icmp eq i32 %1, 0<br>
br i1 %2, label %5, label %3<br>
<br>
; <label>:3 ; preds = %0<br>
%4 = add nsw i32 %b, %a<br>
br label %7<br>
<br>
I wondered what "; <label>:3" would mean and how absent label relates<br>
to the language syntax. <a href="http://llvm.org/docs/LangRef.html" target="_blank">http://llvm.org/docs/LangRef.html</a> says "Each<br>
basic block may optionally start with a label", that's all. I googled<br>
around and scratched my head for half an hour, still found nothing<br>
(used terms like "llvm implicit basic block labels" and "llvm implicit<br>
basic block labels"), but after peering into that dump long enough and<br>
applying induction on temporary var naming in API (where there's no<br>
naming at all, it's all just external representation), I finally was<br>
able to understand logic of it:<br>
<br>
1. For each function, "unnamed entity" counter is initialized with 0.<br>
2. Whenever unnamed tmp var is seen, it's assigned name as counter++<br>
value.<br>
3. Whenever unlabeled block is seen, it's assigned label as counter++<br>
value.<br>
<br>
<br>
Still, the questions are:<br>
<br>
1. Where is this documented, and why <a href="http://llvm.org/docs/LangRef.html" target="_blank">http://llvm.org/docs/LangRef.html</a><br>
doesn't have it? (I didn't re-read it completely on this occasion,<br>
but grepped for all occurrences of "label" - none was relevant).<br>
<br></blockquote><div><br></div><div style>The closest it gets to talking about it I think is that itsays "Unnamed temporaries are numbered sequentially", although it says it in a context where the implication is that this applies to the results of instructions, with no mention of BB names.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2. Why label is not rendered explicitly? Putting instead comment like<br>
"; <label>:3" is as helpful and non-confusing as dumping tmp var names<br>
as:<br>
<br>
/* temporary 1 */ = tail call i32 @bar(i32 %a)<br>
<br>
(assuming LLVM syntax would have stream-type comments besides line-type<br>
";").<br>
<br></blockquote><div><br></div><div style>Printing a comment there is pretty useless. It's probably historical.</div><div style><br></div><div style>It should be pretty easy to change AssemblyWriter::printBasicBlock in lib/IR/AsmWriter.cpp to print out a "unnamed" name for the BB, but the hard part will be to ensure that the new policy will properly round-trip (i.e., can be parsed back; even in the presence of user-defined names). Also, we like to keep the textual IR as compatible as possible, so the change would have to be fully backward compatible.</div>
<div style><br></div><div style>Alternatively, you could use the experience from your wild goose chase to choose a good location to document this strange behavior (in LangRef) so that another person will be likely to find it.</div>
<div style><br></div><div style>-- Sean Silva</div></div></div></div>