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? - Paul
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
Maybe Matching Threads
- How to optimize store of constant arrays
- Fwd: I cannot change value of global variable in LLVM IR using IRBuilder
- Fwd: I cannot change value of global variable in LLVM IR using IRBuilder
- [LLVMdev] Storing values in global variables
- Bug in replaceUsesOfWith: does not keep addrspace consistent in GEP