'LLVM getelementptr indices use/meaning
I just started learning LLVM and I am wondering why we have two indices in getelementptr? what are the first and second indices (0 and 0) used for?
@tmp = global [18 x i8] c"Hello world!: %d\0A\00"
declare i32 @printf(i8* %0, ...)
define i32 @fact(i32 %x) {
0:
%1 = icmp sle i32 %x, 0
br i1 %1, label %2, label %3
2:
ret i32 1
3:
%4 = sub i32 %x, 1
%5 = call i32 @fact(i32 %4)
%6 = mul i32 %x, %5
ret i32 %6
}
define i32 @main() {
entry:
%0 = getelementptr [18 x i8], [18 x i8]* @tmp, i32 0, i32 0 ; <---- HERE
%1 = call i32 @fact(i32 23)
%2 = call i32 (i8*, ...) @printf(i8* %0, i32 %1)
ret i32 1
}
enter code here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
