[LLVMdev] AllocaInst issue

John Criswell criswell at illinois.edu
Thu Aug 16 16:23:39 PDT 2012


On 8/16/12 6:19 PM, Iaroslav Markov wrote:
> Hello,
>
> I have the following problem: I need to allocate an array. I know it's size - it's constant (ConstExpr), but my problem is that I know it only during the runtime (i.e for every variable I'm trying to allocate an array equal to size of a variable). As I understand I can't do it, since it's possible to initialize ArrayType only if I know it's size in integer units. Since I'm not able to initialize type, I can't pass it to AllocaInst. Are there any ways to solve this issue?
>
> Of course, I can solve this issue by insertion of a cycle that will allocate an array element-by-element, but it doesn't seems as a good way.

The alloca instruction in LLVM has an optional second operand for the 
number of elements to allocate.  This allows you to allocate arrays on 
the stack when the number of elements isn't known until run-time.

See the LLVM Language Reference Manual for more details.

-- John T.

>
> Best,
> Yaroslav.
> _______________________________________________
> 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