[LLVMdev] Incrementing a pointer to array element?
Eli Friedman
eli.friedman at gmail.com
Wed Oct 17 17:30:53 PDT 2012
On Wed, Oct 17, 2012 at 5:19 PM, Paul J. Lucas <paul at lucasmail.org> wrote:
> Using the LLVM C++ API, if I want to create an array via an Alloca instruction like:
>
> Value *a = ir_builder.CreateAlloca( my_type, my_size );
>
> and then I want to initialize each element of the array with values computed elsewhere like:
>
> for ( vector<Value*>::const_iterator i = v.begin(); i != v.end(); ++i ) {
> builder.CreateStore( *i, a );
> // How do I increment 'a' to point to the next element?
> }
>
> how do I increment 'a' to point to the next element (taking the size of my_type into account) so that each store instruction stores in successive elements?
for ( vector<Value*>::const_iterator i = v.begin(); i != v.end(); ++i ) {
builder.CreateStore( *i, a );
a = builder.CreateGEP(a, Builder.getInt64(1));
}
-Eli
More information about the llvm-dev
mailing list