I have written a simple code in c using for loop.
void foo(int a, int n){
int i;
for (i=0;i<n;i = i+1){
a = a+i;
}
return;
}
it will give the llvm ir like
define dso_local void @foo(i32 %0, i32 %1) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i32, align 4
store i32 %0, i32* %3, align 4
store i32 %1, i32* %4, align 4
store i32 0, i32* %5, align 4
br label %6
6: ; preds = %14, %2
%7 = load i32, i32* %5, align 4
%8 = load i32, i32* %4, align 4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i32, i32* %3, align 4
%12 = load i32, i32* %5, align 4
%13 = add nsw i32 %11, %12
store i32 %13, i32* %3, align 4
br label %14
14: ; preds = %10
%15 = load i32, i32* %5, align 4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5, align 4
br label %6
17: ; preds = %6
ret void
}
I want to write a module pass which will take LLVM IR as input and from llvm IR it will check if there is any loop present or not , if present then what are those initializations, conditions and increments and what are the body of that loop etc.