Label expression in llvm IR code

Sometimes I find that the tag identifier in llvm IR is started with a semicolon ';', for example ; <label> 6 ; <label> 6 however, as I know, a comma is used for comments. So, how can llvm get label information in the comments? Am I missing something?
A simple test. C source file:

 #include <stdio.h> int main() { int a; scanf("%d", &a); if ( a > 3) a *= 2; return 0; } 

llvm IR code generated by http://llvm.org/demo/index.cgi (same as clang -c -emit-llvm main.c):

 ; ModuleID = '/tmp/webcompile/_13654_0.bc' @.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1 define i32 @main() nounwind uwtable { %a = alloca i32, align 4 %1 = call i32 (i8*, ...)* @__isoc99_scanf(i8* getelementptr inbounds ([3 x i8]* @.str, i64 0, i64 0), i32* %a) nounwind %2 = load i32* %a, align 4, !tbaa !0 %3 = icmp sgt i32 %2, 3 br i1 %3, label %4, label %6 ; <label>:4 ; preds = %0 %5 = shl nsw i32 %2, 1 store i32 %5, i32* %a, align 4, !tbaa !0 br label %6 ; <label>:6 ; preds = %4, %0 ret i32 0 } 
+4
source share
3 answers

In LLVM IR, the block does not need an explicit label. The instructions are similar to those that lead to% 1,% 2,% 3. LLVM assigns numbers to unnamed instructions and blocks in ascending order. br i1 %3... completes the first block, and the last used label number is 3, so the next block gets the designation 4. This block ends with the next br command, and the last used number is 5, so the next and last block are marked with 6. First It may seem strange that blocks and instructions share the same namespace, but remember that blocks are also values.

+2
source

Despite the wording, %4 in label %4 NOT a label, it is just a link to a block. You are right, this is very confusing, see this question for discussion.

+1
source

Something you can try is to run an instnamer pass on your IR, which will give an explicit name for everything, so you don't have to worry about finding implicit names.

0
source

Source: https://habr.com/ru/post/1402243/


All Articles