[LLVMdev] Implicit basic block labels?
Paul Sokolovsky
pmiscml at gmail.com
Mon May 13 16:31:39 PDT 2013
Hello,
I only recently started to look at LLVM assembly generated by Clang,
and one of the first thing I saw was like:
define i32 @foo(i32 %a, i32 %b) nounwind {
%1 = tail call i32 @bar(i32 %a) nounwind
%2 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
; <label>:3 ; preds = %0
%4 = add nsw i32 %b, %a
br label %7
I wondered what "; <label>:3" would mean and how absent label relates
to the language syntax. http://llvm.org/docs/LangRef.html says "Each
basic block may optionally start with a label", that's all. I googled
around and scratched my head for half an hour, still found nothing
(used terms like "llvm implicit basic block labels" and "llvm implicit
basic block labels"), but after peering into that dump long enough and
applying induction on temporary var naming in API (where there's no
naming at all, it's all just external representation), I finally was
able to understand logic of it:
1. For each function, "unnamed entity" counter is initialized with 0.
2. Whenever unnamed tmp var is seen, it's assigned name as counter++
value.
3. Whenever unlabeled block is seen, it's assigned label as counter++
value.
Still, the questions are:
1. Where is this documented, and why http://llvm.org/docs/LangRef.html
doesn't have it? (I didn't re-read it completely on this occasion,
but grepped for all occurrences of "label" - none was relevant).
2. Why label is not rendered explicitly? Putting instead comment like
"; <label>:3" is as helpful and non-confusing as dumping tmp var names
as:
/* temporary 1 */ = tail call i32 @bar(i32 %a)
(assuming LLVM syntax would have stream-type comments besides line-type
";").
Thanks,
Paul mailto:pmiscml at gmail.com
More information about the llvm-dev
mailing list