[LLVMdev] Implicit basic block labels?

Paul Sokolovsky pmiscml at gmail.com
Thu May 16 16:37:10 PDT 2013


On Tue, 14 May 2013 00:51:42 -0600
Sean Silva <silvas at purdue.edu> wrote:

> On Mon, May 13, 2013 at 5:31 PM, Paul Sokolovsky <pmiscml at gmail.com>
> > ; <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

> >
> 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.
> Printing a comment there is pretty useless. It's probably historical.
> 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.
> 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.

Ok, so I assume this indeed warrants a bug, submitted 
http://llvm.org/bugs/show_bug.cgi?id=16043 . I'll try to submit patches
for docs, and the look into code (so far I tested that just adding
explicit labels to test code I reported leads to parsing errors, so
indeed, there should be smarter logic - if explicit label is numeric
and number corresponds to current counter value, the counter should be

Another question is about phi syntax. Looking at this:

%.0 = phi i32 [ %4, %3 ], [ %6, %5 ]

it's unlikely that human new to LLVM (but knowing what phi is) will
understand what it means. What about being consistent with other
instructions which accept label arguments - specify type explicitly:

%.0 = phi i32 [ %4, label %3 ], [ %6, label %5 ]

It's of course understood why 1st form is used - because phi argument
list may become rather long. But well, it's not the only instruction in
LLVM which can get long - function call is such, and a typical call
will beat typical phi easily I guess. So, readability and
self-description of syntax might be of higher priority than saving few
horizontal positions.

> -- Sean Silva

Best regards,
 Paul                          mailto:pmiscml at gmail.com

More information about the llvm-dev mailing list