[LLVMbugs] [Bug 16043] New: Implicit basic block labels are undocumented and confusing
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu May 16 16:23:00 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=16043
Bug ID: 16043
Summary: Implicit basic block labels are undocumented and
confusing
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: pmiscml at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Running "clang -x c -emit-llvm -S -O2 test.c" on:
---------
int bar(int a);
int foo(int a, int b)
{
if (bar(a))
return a + b;
else
return a * b;
}
---------
Leads to following LLVM asm output:
---------
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
; <label>:5 ; preds = %0
%6 = mul nsw i32 %b, %a
br label %7
; <label>:7 ; preds = %5, %3
%.0 = phi i32 [ %4, %3 ], [ %6, %5 ]
ret i32 %.0
}
declare i32 @bar(i32)
---------
Lack of explicit %3, %5, %7 labels looks rather confusing.
http://llvm.org/docs/LangRef.html gives very vague hint: "Each basic block may
optionally start with a label", it doesn't describe how handled a case when
label is not given. Googling with terms like "llvm implicit basic block labels"
and "llvm basic block without labels" didn't provide any useful hits.
After some consideration, and based on previous experience with LLVM internal
structures, I was abel to understand how implicit labels handled, the algorithm
for assigning names to unnamed entities within a function appears to be:
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.
However, all this matters got to be very confusing for novices, and thus reduce
adoption of LLVM technology.
Suggestions for resolution:
1. Definitely describe implicit label behavior in LangRef and probably, FAQ.
2. Consider always outputting explicit labels. Still support implicit labels
for parsing.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130516/358828f0/attachment.html>
More information about the llvm-bugs
mailing list