Accessing Loop Variables

Hi,
      How do I access the loop variables in a loop.

for(i = 0; i < N; i++)
      for(j = 0; j < M; j++)
            A[i][j+k] = i + j;

Is there anyway for me to know that in A[i][j+k], i & j are loop variables
whereas k is not!

Regards,

Prasenjit Chakraborty
Performance Modeling and Analysis
IBM Systems & Technology Lab

Hi,

You can use the getInductionVariable() on each loop,and maintain a smallvect of all induction variables that you have come across.
Also remember to run some passes to hoist loop independent entities out of the loop.

Cheers

Dhruv

The ScalarEvolution analysis can help here. If you've already identified
i, j, and k yourself, you can call getSCEV on them and use the
isLoopInvariant and hasComputableLoopEvolution member functions.

ScalarEvolution doesn't yet help in identifying the indices used in
each dimension of a multi-dimensional array reference in the way that a
traditional dependence analysis would want to see them, though that's
a future goal.

Dan

I have not identified i, j or k. The whole point is I want to know that
there are variables i & j which are loop variables.

Calling getInductionVariab;le() returns NULL, reason being I don't see any
PHINode in the loop.

Regards,

Prasenjit Chakraborty
Performance Modeling and Analysis
IBM Systems & Technology Lab

             Dan Gohman
             <gohman@apple.com
             > To
                                       Prasenjit
             10/12/2009 11:13 Chakraborty/India/IBM@IBMIN
             PM cc
                                       llvmdev@cs.uiuc.edu
                                                                   Subject
                                       Re: [LLVMdev] Accessing Loop
                                       Variables
                                                                           

Hi,
     How do I access the loop variables in a loop.

for(i = 0; i < N; i++)
     for(j = 0; j < M; j++)
           A[i][j+k] = i + j;

Is there anyway for me to know that in A[i][j+k], i & j are loop
variables
whereas k is not!

The ScalarEvolution analysis can help here. If you've already identified
i, j, and k yourself, you can call getSCEV on them and use the
isLoopInvariant and hasComputableLoopEvolution member functions.

ScalarEvolution doesn't yet help in identifying the indices used in
each dimension of a multi-dimensional array reference in the way that a
traditional dependence analysis would want to see them, though that's
a future goal.

Dan