[LLVMdev] array index access

Duncan Sands baldrick at free.fr
Mon Mar 28 01:32:19 PDT 2011


Hi George,

>    I am trying to get the first index into this two-dimensional array, that is *5.*

not sure what you mean, but if you think of your array as being a 10 x 20 matrix
then to get a pointer to element M,N you would do:
   getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 %M, i32 %N

>
> %4 = getelementptr inbounds [10 x [20 x i32]]* %3, i32 0, i32 *5*
> *
> *
> I can iterate over the GEP and get the types of the operands but not the values.
>
> How do I get the value (5)?

getelementptr only does pointer arithmetic, i.e. using it you can get a pointer
to an array element.  But to get the element itself you need to use a load
instruction to load the value pointed to by the pointer.

Ciao, Duncan.



More information about the llvm-dev mailing list