[LLVMdev] Using GetElementPtr to traverse large arrays

Alastair Lynn arplynn at gmail.com
Fri Mar 26 06:21:33 PDT 2010


Hi Gabi-

Had you considered simply putting the loop into the IR?

Alastair

On 26 Mar 2010, at 10:29, Gabi wrote:

> Hi all,
> This question was probably asked million times before, but I wasted
> few hours and didn't find the solution..
> What is the best way to traverse a large array (say size of million)
> with GetElementPtr
> The problem with the following code, is that it forces you to create
> million constant index values:
> 
> intVars = new AllocaInst(Type::getInt32Ty(ctx), allocaSize, "intVars",
> someBlock);
> for(int i  = 0; i < 1000000; i++)
> {
>   Value *idx = ConstantInt::get(Type::getInt32Ty(ctx), i);
>   GetElementPtrInst *gep = GetElementPtrInst::Create(intVars, idx,
> "ElemPtr", someBlock);
>  new StoreInst(idx, gep, entryBlock); //Store some value in it
> }
> 
> Apart from the size issue, What is the idiomatic way to traverse small
> arrays ? The above loop ? I tried to use CreateInBounds but got
> totally confused..
> 
> -- 
> Regards,
> Gabi
> 
> http://bugspy.net
> _______________________________________________
> 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