[llvm-dev] How to make the induction variable local when extracting a loop into a function ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] How to make the induction variable local when extracting a loop into a function ?

Tim Northover via llvm-dev
Hi all,

I have a C++ code with the following loop nest
for (int i = 0; i < ni; i++) {
     for (int j = 0; j < nj; j++) {
         A[i] *= j;
     }
}
and I want to extract each of these two loops into a separate function
with LLVM.
What I would like is an outerloop function doing the loop over i and
calls to innerloop function, and an innerloop function doing the loop
over j.

I tried to do this using CodeExtractor, but I encountered an issue : it
creates functions taking the induction variables i and j as parameters.
define private void @outer_loop(i32* %i, i32* %ni, i32* %j, i32* %nj,
double** %A)
define private void @inner_loop(i32* %j, i32* %nj, i32* %i, double** %A)

The problem here is that j is passed by address to both functions when I
expect it to be local to the inner_loop function, or at least be passed
by value.
i.e. I want the functions to look like this :
define private void @outer_loop(i32* %ni, i32* %nj, double** %A){
newFuncRoot:
   %i = alloca i32
   br label %for.cond
...
}
define private void @inner_loop(i32* %nj, i32* %i, double** %A){
newFuncRoot:
   %j = alloca i32
   br label %for.cond
...
}

This is very problematic for me as I want to execute chunks of the outer
loop in parallel, and this will lead to errors since I will get a race
condition on j.

Is there a way to make the induction variable local when extracting a
Loop into a Function ?

Maxime

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev