[LLVMdev] Clang removes Label name

Jeremy Lakeman
Sat, 07 Jun 2014 02:25:40 -0000

In LLVM, every block must explicitly specify how control flows out of that
block, the order that blocks are printed to text / bitcode has no effect on
the control flow whatsoever.
The label forces the creation of a second block, so the first one must end
with a branch to it. Since there's only one code path, LLVM will later
merge the two blocks together.


On Fri, Jun 6, 2014 at 11:32 PM, Rouxel Benjamin <benjamin.rouxel at
inria.fr>
wrote:

> Hi,
>
> So finally I found where the label was evicted. In case it's useful for
> someone, i needed to add:
"Dest.getBlock()->setName(D->getName());" in
> CGStmt.cpp:360.
>
> About the creation of the BasicBlock, It's in the same method, but as
> expected it's removed with optimization (O1,O2,O3) and the label name
is
> kept trough CFG optimizations.
>
> Cheers,
> Benjamin Rouxel
>
> Le Fri, 6 Jun 2014 10:23:21 +0200,
> Rouxel Benjamin <benjamin.rouxel at inria.fr> a écrit :
>
> > Hi,
> >
> > I have some troubles to figure out why clang is removing my label
name.
> As the simple example below shows the label "MLB" is removed and
replaced
> by an integer as an "unnamed value".
> > Plus, I can see that an unconditional jump is added, as the label
seems
> to be interpreted as the beginning of a BasicBlock. I am compiling without
> any optimizations (for now), what leave the produced code slower than the
> input one.
> >
> > Anyway, the important thinks to me is to keep label name, but I
can't
> figure out where in the code this transformation is done. My guess is,
it's
> done by Clang while parsing, or just after. Could someone gives me some
> clue about the class/method where this "feature" is ?
> >
> > Input:
> > int main() {
> >     int i=0;
> > MLB:
> >     return i;
> > }
> >
> > Result:
> > define i32 @main() #0 {
> >   %1 = alloca i32, align 4
> >   %i = alloca i32, align 4
> >   store i32 0, i32* %1
> >   store i32 0, i32* %i, align 4
> >   br label %2
> >
> > ; :2 ; preds = %0
> >   %3 = load i32* %i, align 4
> >   ret i32 %3
> > }
> >
> > ---------------------------------------------------
> > % clang --version
> > clang version 3.4 (branches/release_34)
> > Target: x86_64-unknown-linux-gnu
> > Thread model: posix
> >
> > % clang -O0 -emit-llvm -mllvm -debug-pass=Structure -S -c -o
/dev/stdout
> main.c
> >
> > Thanks for you help
> > Benjamin Rouxel
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20140607/a0137653/attachment.html>