[LLVMdev] How to get more details from storeInst ?

Duncan Sands baldrick at free.fr
Fri Jan 18 01:02:56 PST 2013

Hi Cheng,

On 18/01/13 03:00, Cheng Liu wrote:
> I have a loop fully unrolled and got the following store instruction.
> store i32 %add.3, i32* getelementptr inbounds ([20 x [20 x i32]]* @c, i32 0,
> i32 0, i32 0), align 4
> I want to know exactly which element of the array that is going to be
> stored, which help me to transform the high level language to hardware. Take
> the instruction above as an example, I know the data is stored into c[0][0].
> It is just that I don't how to get c, 0, 0 from the instruction.

this bit
   i32* getelementptr inbounds ([20 x [20 x i32]]* @c, i32 0, i32 0, i32 0)
is a constant expression (ConstantExpr class), not an instruction (you can
tell because it is printed inline).

If SI is your store instruction (with type StoreInst*) then using
you get the stored to pointer.  Call the result Ptr.

You can cast that to a ConstantExpr* using
This will assert if Ptr isn't a constant expression.  You can use dyn_cast
instead which will return null if it isn't a constant expression.  At this
point you can rummage around inside the constant expression.  It is probably
simpler though to #include the Operator.h header, and cast Ptr to the
GEPOperator class instead.

Ciao, Duncan.

> At the moment, I use the method getNumOperands() and getOperand( int i) to
> check all the operands of the instruction. However, I can only get two
> operands. One of them is the data %add.s, and the other is the pointer. The
> pointer has no name and it is not a constant.

Yes, it is a constant (Constant class).

  I couldn't move further into
> the pointer to get the index of the element.
> Anyone could give me some suggestions on this?
> --
> View this message in context: http://llvm.1065342.n5.nabble.com/How-to-get-more-details-from-storeInst-tp53841.html
> Sent from the LLVM - Dev mailing list archive at Nabble.com.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list