[LLVMdev] Clang removes Label name

Rouxel Benjamin
Fri, 06 Jun 2014 14:02:55 -0000

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