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
Alastair Lynn
2010-Mar-26 13:21 UTC
[LLVMdev] Using GetElementPtr to traverse large arrays
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
Seemingly Similar Threads
- [LLVMdev] How to cast an integer array to an integer pointer? (user question)
- [LLVMdev] Request for comments: TBAA on call
- [LLVMdev] Request for comments: TBAA on call
- [LLVMdev] JIT : Does it cache the compiled code of executed functions upon runFunction(..)?
- [LLVMdev] Generating GetElementPtr inlined in a function argument list programmatically