[LLVMdev] Re: Dependence Analysis

Naftali Schwartz nschwart at cs.nyu.edu
Wed Jul 20 22:09:32 PDT 2005


> LLVM already includes this: the -indvars pass.  It turns things like 
this:
>
> int *P = for (...; ... ; ++P)
>   *P
>
> to:
>
> int *P = ...
> for (int i = 0; ... ; ++i)
>  P[i]
>
> If you're interested in dependence analysis, the next important step is 
to
> start analyzing distance and direction vectors.

Well, specifically, I was thinking of a mechanism to turn this:

int A[100], B[100], C[100], X, Y, Z;

         int *p_a = &A[0];
         int *p_b = &B[0];
         int *p_c = &C[0];

         int i, j, k, f;
         for ( k = 0; k < Z; k++ )
         {
                 p_a = &A[0];
                 for ( i = 0; i < X; i++ )
                 {
                         p_b = &B[k*Y];
                         *p_c = *p_a++ * *p_b++;
                         for ( f = 0; f < Y-2; f++ )
                                 *p_c += *p_a++ * *p_b++;
                         *p_c++ += *p_a++ * *p_b++;
                 }
         }

...into:

int A[100], B[100], C[100], X, Y, Z;

         int i, j, k, f;
         for ( k = 0; k < Z; k++ )
                 for ( i = 0; i < X; i++ )
                 {
                         C[X*k+i] = A[Y*i] * B[Y*k];
                         for (f = 0; f < Y-2; f++ )
                                 C[X*k+i] += A[Y*i+f+1] * B[Y*k+f+1];
                         C[X*k+i] += A[Y*i+Y-1] * B[Y*k+Y-1];
                 }

a la Frank and O'Boyle, which -indvars seems not to be able to handle 
(unless I'm doing something wrong...)

Naftali




More information about the llvm-dev mailing list