[LLVMdev] Using GetElementPtr to traverse large arrays

Gabi bugspynet at gmail.com
Fri Mar 26 03:29:19 PDT 2010


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



More information about the llvm-dev mailing list