[LLVMdev] Accessing Loop Variables

Prasenjit Chakraborty cprasenj at in.ibm.com
Mon Oct 12 11:40:10 PDT 2009


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 at apple.com                                             
             >                                                          To 
                                       Prasenjit                           
             10/12/2009 11:13          Chakraborty/India/IBM at IBMIN         
             PM                                                         cc 
                                       llvmdev at cs.uiuc.edu                 
                                                                   Subject 
                                       Re: [LLVMdev] Accessing Loop        
                                       Variables                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           





On Oct 12, 2009, at 3:46 AM, Prasenjit Chakraborty wrote:

>
> 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






More information about the llvm-dev mailing list