[LLVMdev] scalar evolution to determine access functions in arays

Andrew Trick atrick at apple.com
Wed Jul 27 11:01:45 PDT 2011


On Jul 27, 2011, at 7:11 AM, Jimborean Alexandra wrote:

> Hello,
> 
> How can I compute the functions on the loop iterators used as array indices? 
> 
> For example:
> 
> for i = 0, N
>       for j = 0, M
>             A[2*i + j - 10] = ... 
> 
> Can I obtain that this instruction A[2*i + j - 10]= .. always accesses memory using a function       f(i,j)   =   2*i + j - 10 + base_address_of_A
> 
> If I run the scalar evolution pass on this code I obtain:
> 
> %arrayidx = getelementptr inbounds [200 x i32]* @main.A, i32 0, i64 %idxprom
> 
>   -->  ((4 * (sext i32 (-10 + (2 * %tmp6) + %tmp7) to i64)) + @main.A)        
> 
> Could you please offer an insight on how can I obtain the function from the internals of the scalar evolution pass? 
> Thank you.
> 
> Alexandra

Hello Alexandra,

The scalar evolution pass doesn't to anything when it runs except initialize some empty maps. The important one is the Value->SCEV map. SCEV is the class that holds an expression tree. Scalar evolution populates this map on-demand when the client asks for an expression via ScalarEvolution::getSCEV(Value).

IndVarSimplify and LoopStrengthReduce are example SCEV clients.

Just be careful to invalidate SCEV entries when you mutate the IR.

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110727/213a8313/attachment.html>


More information about the llvm-dev mailing list