[llvm-dev] Find loops in LLVM bytecode
Michael Kruse via llvm-dev
llvm-dev at lists.llvm.org
Thu Sep 24 06:07:12 PDT 2015
Hi,
another suggestion is to look at Polly (http://polly.llvm.org/) for
loop analysis. It would extract high-level information such as:
$ cat ml.c
int foo() {
int sum = 0;
for (int i=0; i<1000; i++)
sum += (float)i;
return sum;
}
$ bin\clang.exe ml.c -mllvm -polly -O3 -mllvm
-polly-detect-unprofitable -mllvm -debug -mllvm
-debug-only=polly-scops -c
Function: foo
Region: %for.inc---%for.end
Max Loop Depth: 1
Context:
{ : }
Assumed Context:
{ : }
Boundary Context:
{ : }
Arrays {
i32 MemRef_sum_04__phi[*] // Element size 4
i32 MemRef_conv2[*] // Element size 4
}
Arrays (Bounds as pw_affs) {
i32 MemRef_sum_04__phi[*] // Element size 4
i32 MemRef_conv2[*] // Element size 4
}
Alias Groups (0):
n/a
Statements {
Stmt_for_inc
Domain :=
{ Stmt_for_inc[i0] : i0 <= 999 and i0 >= 0 };
Schedule :=
{ Stmt_for_inc[i0] -> [i0] };
MustWriteAccess := [Reduction Type: NONE] [Scalar: 1]
{ Stmt_for_inc[i0] -> MemRef_sum_04__phi[] };
ReadAccess := [Reduction Type: NONE] [Scalar: 1]
{ Stmt_for_inc[i0] -> MemRef_sum_04__phi[] };
MustWriteAccess := [Reduction Type: NONE] [Scalar: 1]
{ Stmt_for_inc[i0] -> MemRef_conv2[] };
}
(The cast to float is there because otherwise LLVM would just compute
the constant result)
The interesting information for you would be the Domain {
Stmt_for_inc[i0] : i0 <= 999 and i0 >= 0 } of the loop body
(Stmt_for_inc). The loop body content itself is not printed here.
Michael
More information about the llvm-dev
mailing list