Getting the symbolic expression for an address calculation

Hi all,

What is the best way to get the symbolic expression for an address calculation in llvm specially when memory addresses are calculated within a loop.

Use case: I want to know what loop induction variables are used for a particular address calculation and in what symbolic context. Thereby, I want to identify which stores and loads will be contiguous in memory if I unroll each of the loops.

Thanks

ScalarEvolution works with pointers as well as integers; if you call getSCEV on an address based on an induction variable, you'll get a SCEVAddRecExpr.

-Eli

How do you generate a SCEVAddRecExpr from a SCEV? It tried dyn_casting and it seems like that the SCEV returned by getSCEV is not a SCEVAddRecExpr.

Thanks

You can dyn_cast if it's actually an AddRec... but not all expressions can be represented as an AddRec.

SCEV has a dump() method which can be helpful for debugging. What does E->dump() on the SCEV in question look like? What does the IR look like?

-Eli

(((15 + %add144.sink230.i) * (%blocksize /u %bytesoftype)) + {%_dest,+,16}<%for.cond1.preheader.i59>)

Is there a way to manipulate SCEVs? It seems like it is an opaque pointer. This would be useful since I am trying to learn the structure of them.

Thanks

This is a SCEVAddExpr with two operands. The first is a SCEVMulExpr, the second is a SCEVAddRecExpr. You're ending up with an expression like this because one of "%add144.sink230.i", "%blocksize", or "%bytesoftype" isn't loop-invariant. Maybe a load wasn't hoisted where you expected it to be.

If you're confused about what kind of expression you're looking at, you can use the getSCEVType() method on a SCEV, which returns a member of the SCEVTypes enum.

-Eli